1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
|
---|
5 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
6 |
|
---|
7 | public abstract class PushExpression<T> : StatefulExpression<T> {
|
---|
8 |
|
---|
9 | protected PushExpression(T state) : base(state) { }
|
---|
10 |
|
---|
11 | protected bool Eval(IPushStack<T> stack) {
|
---|
12 | stack.Push(State);
|
---|
13 | return true;
|
---|
14 | }
|
---|
15 |
|
---|
16 | public override string StringRepresentation { get { return State.ToString(); } }
|
---|
17 | }
|
---|
18 |
|
---|
19 | public class IntegerPushExpression : PushExpression<long> {
|
---|
20 | public IntegerPushExpression(long state)
|
---|
21 | : base(state) {
|
---|
22 | }
|
---|
23 |
|
---|
24 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
25 | return Eval(interpreter.IntegerStack);
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public class FloatPushExpression : PushExpression<double> {
|
---|
30 | public FloatPushExpression(double state)
|
---|
31 | : base(state) {
|
---|
32 | }
|
---|
33 |
|
---|
34 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
35 | return Eval(interpreter.FloatStack);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public class BooleanPushExpression : PushExpression<bool> {
|
---|
40 | public BooleanPushExpression(bool state)
|
---|
41 | : base(state) {
|
---|
42 | }
|
---|
43 |
|
---|
44 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
45 | return Eval(interpreter.BooleanStack);
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public class NamePushExpression : PushExpression<string> {
|
---|
50 | public NamePushExpression(string state)
|
---|
51 | : base(state) {
|
---|
52 | }
|
---|
53 |
|
---|
54 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
55 | return Eval(interpreter.NameStack);
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public class ExecPushExpression : PushExpression<Expression> {
|
---|
60 | public ExecPushExpression(Expression state)
|
---|
61 | : base(state) {
|
---|
62 | }
|
---|
63 |
|
---|
64 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
65 | return Eval(interpreter.ExecStack);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | public class CharPushExpression : PushExpression<char> {
|
---|
70 | public CharPushExpression(char state)
|
---|
71 | : base(state) {
|
---|
72 | }
|
---|
73 |
|
---|
74 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
75 | return Eval(interpreter.CharStack);
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | public class StringPushExpression : PushExpression<string> {
|
---|
80 | public StringPushExpression(string state)
|
---|
81 | : base(state) {
|
---|
82 | }
|
---|
83 |
|
---|
84 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
85 | return Eval(interpreter.StringStack);
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | public class IntegerVectorPushExpression : PushExpression<List<long>> {
|
---|
90 | public IntegerVectorPushExpression(List<long> state)
|
---|
91 | : base(state) {
|
---|
92 | }
|
---|
93 |
|
---|
94 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
95 | return Eval(interpreter.IntegerVectorStack);
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | public class FloatVectorPushExpression : PushExpression<List<double>> {
|
---|
100 | public FloatVectorPushExpression(List<double> state)
|
---|
101 | : base(state) {
|
---|
102 | }
|
---|
103 |
|
---|
104 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
105 | return Eval(interpreter.FloatVectorStack);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | public class BooleanVectorPushExpression : PushExpression<List<bool>> {
|
---|
110 | public BooleanVectorPushExpression(List<bool> state)
|
---|
111 | : base(state) {
|
---|
112 | }
|
---|
113 |
|
---|
114 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
115 | return Eval(interpreter.BooleanVectorStack);
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | public class StringVectorPushExpression : PushExpression<List<string>> {
|
---|
120 | public StringVectorPushExpression(List<string> state)
|
---|
121 | : base(state) {
|
---|
122 | }
|
---|
123 |
|
---|
124 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
125 | return Eval(interpreter.StringVectorStack);
|
---|
126 | }
|
---|
127 | }
|
---|
128 | } |
---|