1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
5 |
|
---|
6 | using Interpreter;
|
---|
7 | using Stack;
|
---|
8 |
|
---|
9 | public abstract class PopExpression<T> : StatelessExpression {
|
---|
10 | public bool Eval(IPushStack<T> stack) {
|
---|
11 | if (stack.Count == 0) return false;
|
---|
12 |
|
---|
13 | stack.Pop();
|
---|
14 | return true;
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | [PushExpression(StackTypes.Integer, "INTEGER.POP")]
|
---|
19 | public class IntegerPopExpression : PopExpression<long> {
|
---|
20 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
21 | return Eval(interpreter.IntegerStack);
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | [PushExpression(StackTypes.Float, "FLOAT.POP")]
|
---|
26 | public class FloatPopExpression : PopExpression<double> {
|
---|
27 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
28 | return Eval(interpreter.FloatStack);
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | [PushExpression(StackTypes.Boolean, "BOOLEAN.POP")]
|
---|
33 | public class BooleanPopExpression : PopExpression<bool> {
|
---|
34 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
35 | return Eval(interpreter.BooleanStack);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | [PushExpression(StackTypes.Name, "NAME.POP")]
|
---|
40 | public class NamePopExpression : PopExpression<string> {
|
---|
41 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
42 | return Eval(interpreter.NameStack);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | [PushExpression(StackTypes.Exec, "EXEC.POP")]
|
---|
47 | public class ExecPopExpression : PopExpression<Expression> {
|
---|
48 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
49 | return Eval(interpreter.ExecStack);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | [PushExpression(StackTypes.Code, "CODE.POP")]
|
---|
54 | public class CodePopExpression : PopExpression<Expression> {
|
---|
55 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
56 | return Eval(interpreter.CodeStack);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | [PushExpression(StackTypes.Char, "CHAR.POP")]
|
---|
61 | public class CharPopExpression : PopExpression<char> {
|
---|
62 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
63 | return Eval(interpreter.CharStack);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | [PushExpression(StackTypes.String, "STRING.POP")]
|
---|
68 | public class StringPopExpression : PopExpression<string> {
|
---|
69 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
70 | return Eval(interpreter.StringStack);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].POP")]
|
---|
75 | public class IntegerVectorPopExpression : PopExpression<List<long>> {
|
---|
76 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
77 | return Eval(interpreter.IntegerVectorStack);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | } |
---|