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 PopExpression<T> : StatelessExpression {
|
---|
8 | public bool Eval(IStack<T> stack) {
|
---|
9 | if (stack.Count == 0) return false;
|
---|
10 |
|
---|
11 | stack.Pop();
|
---|
12 | return true;
|
---|
13 | }
|
---|
14 | }
|
---|
15 |
|
---|
16 | [PushExpression(StackTypes.Integer, "INTEGER.POP")]
|
---|
17 | public class IntegerPopExpression : PopExpression<long> {
|
---|
18 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
19 | return Eval(interpreter.IntegerStack);
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | [PushExpression(StackTypes.Float, "FLOAT.POP")]
|
---|
24 | public class FloatPopExpression : PopExpression<double> {
|
---|
25 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
26 | return Eval(interpreter.FloatStack);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | [PushExpression(StackTypes.Boolean, "BOOLEAN.POP")]
|
---|
31 | public class BooleanPopExpression : PopExpression<bool> {
|
---|
32 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
33 | return Eval(interpreter.BooleanStack);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | [PushExpression(StackTypes.Name, "NAME.POP")]
|
---|
38 | public class NamePopExpression : PopExpression<string> {
|
---|
39 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
40 | return Eval(interpreter.NameStack);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | [PushExpression(StackTypes.Exec, "EXEC.POP")]
|
---|
45 | public class ExecPopExpression : PopExpression<Expression> {
|
---|
46 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
47 | return Eval(interpreter.ExecStack);
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | [PushExpression(StackTypes.Code, "CODE.POP")]
|
---|
52 | public class CodePopExpression : PopExpression<Expression> {
|
---|
53 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
54 | return Eval(interpreter.CodeStack);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | [PushExpression(StackTypes.Char, "CHAR.POP")]
|
---|
59 | public class CharPopExpression : PopExpression<char> {
|
---|
60 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
61 | return Eval(interpreter.CharStack);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | [PushExpression(StackTypes.String, "STRING.POP")]
|
---|
66 | public class StringPopExpression : PopExpression<string> {
|
---|
67 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
68 | return Eval(interpreter.StringStack);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | } |
---|