1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
3 |
|
---|
4 | using Interpreter;
|
---|
5 | using Stack;
|
---|
6 |
|
---|
7 | public abstract class RotateExpression<T> : StatelessExpression {
|
---|
8 | public bool Eval(IStack<T> stack) {
|
---|
9 | if (stack.Count < 3) return false;
|
---|
10 |
|
---|
11 | stack.Swap(3);
|
---|
12 | return true;
|
---|
13 | }
|
---|
14 | }
|
---|
15 |
|
---|
16 |
|
---|
17 | [PushExpression(StackType.Integer, "INTEGER.ROT")]
|
---|
18 | public class IntegerRotateExpression : RotateExpression<long> {
|
---|
19 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
20 | return Eval(interpreter.IntegerStack);
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | [PushExpression(StackType.Float, "FLOAT.ROT")]
|
---|
25 | public class FloatRotateExpression : RotateExpression<double> {
|
---|
26 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
27 | return Eval(interpreter.FloatStack);
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | [PushExpression(StackType.Boolean, "BOOLEAN.ROT")]
|
---|
32 | public class BooleanRotateExpression : RotateExpression<bool> {
|
---|
33 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
34 | return Eval(interpreter.BooleanStack);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | [PushExpression(StackType.Name, "NAME.ROT")]
|
---|
39 | public class NameRotateExpression : RotateExpression<string> {
|
---|
40 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
41 | return Eval(interpreter.NameStack);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [PushExpression(StackType.Exec, "EXEC.ROT")]
|
---|
46 | public class ExecRotateExpression : RotateExpression<Expression> {
|
---|
47 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
48 | return Eval(interpreter.ExecStack);
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | [PushExpression(StackType.Code, "CODE.ROT")]
|
---|
53 | public class CodeRotateExpression : RotateExpression<Expression> {
|
---|
54 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
55 | return Eval(interpreter.CodeStack);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | } |
---|