1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
5 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
6 | using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
|
---|
7 |
|
---|
8 | using Stack;
|
---|
9 |
|
---|
10 | /// <summary>
|
---|
11 | /// Tells whether that stack is empty.
|
---|
12 | /// </summary>
|
---|
13 | [StorableClass]
|
---|
14 | public abstract class EmptyExpression<T> : StatelessExpression {
|
---|
15 | protected EmptyExpression() { }
|
---|
16 | [StorableConstructor]
|
---|
17 | protected EmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
18 |
|
---|
19 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
20 | return false;
|
---|
21 | }
|
---|
22 |
|
---|
23 | public void Eval(IPushStack<T> stack, IPushStack<bool> booleanStack) {
|
---|
24 | booleanStack.Push(stack.IsEmpty);
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | [StorableClass]
|
---|
29 | [PushExpression(
|
---|
30 | StackTypes.Exec,
|
---|
31 | "EXEC.EMPTY",
|
---|
32 | "Pushes TRUE onto the BOOLEAN stack if the EXEC stack is empty, otherwise FALSE.",
|
---|
33 | StackTypes.Boolean)]
|
---|
34 | public class ExecEmptyExpression : EmptyExpression<Expression> {
|
---|
35 | public ExecEmptyExpression() { }
|
---|
36 | [StorableConstructor]
|
---|
37 | protected ExecEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
38 |
|
---|
39 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
40 | Eval(interpreter.ExecStack, interpreter.BooleanStack);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | [StorableClass]
|
---|
45 | [PushExpression(
|
---|
46 | StackTypes.Code,
|
---|
47 | "CODE.EMPTY",
|
---|
48 | "Pushes TRUE onto the BOOLEAN stack if the CODE stack is empty, otherwise FALSE.",
|
---|
49 | StackTypes.Boolean)]
|
---|
50 | public class CodeEmptyExpression : EmptyExpression<Expression> {
|
---|
51 | public CodeEmptyExpression() { }
|
---|
52 | [StorableConstructor]
|
---|
53 | protected CodeEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
54 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
55 | Eval(interpreter.CodeStack, interpreter.BooleanStack);
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | [StorableClass]
|
---|
60 | [PushExpression(
|
---|
61 | StackTypes.Integer,
|
---|
62 | "INTEGER.EMPTY",
|
---|
63 | "Pushes TRUE onto the BOOLEAN stack if the INTEGER stack is empty, otherwise FALSE.",
|
---|
64 | StackTypes.Boolean)]
|
---|
65 | public class IntegerEmptyExpression : EmptyExpression<long> {
|
---|
66 | public IntegerEmptyExpression() { }
|
---|
67 | [StorableConstructor]
|
---|
68 | protected IntegerEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
69 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
70 | Eval(interpreter.IntegerStack, interpreter.BooleanStack);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | [StorableClass]
|
---|
75 | [PushExpression(
|
---|
76 | StackTypes.Float,
|
---|
77 | "FLOAT.EMPTY", "Pushes TRUE onto the BOOLEAN stack if the FLOAT stack is empty, otherwise FALSE.",
|
---|
78 | StackTypes.Boolean)]
|
---|
79 | public class FloatEmptyExpression : EmptyExpression<double> {
|
---|
80 | public FloatEmptyExpression() { }
|
---|
81 | [StorableConstructor]
|
---|
82 | protected FloatEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
83 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
84 | Eval(interpreter.FloatStack, interpreter.BooleanStack);
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | [StorableClass]
|
---|
89 | [PushExpression(
|
---|
90 | StackTypes.Boolean,
|
---|
91 | "BOOLEAN.EMPTY",
|
---|
92 | "Pushes TRUE onto the BOOLEAN stack if the BOOLEAN stack is empty, otherwise FALSE.")]
|
---|
93 | public class BooleanEmptyExpression : EmptyExpression<bool> {
|
---|
94 | public BooleanEmptyExpression() { }
|
---|
95 | [StorableConstructor]
|
---|
96 | protected BooleanEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
97 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
98 | Eval(interpreter.BooleanStack, interpreter.BooleanStack);
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | [StorableClass]
|
---|
103 | [PushExpression(
|
---|
104 | StackTypes.Char,
|
---|
105 | "CHAR.EMPTY",
|
---|
106 | "Pushes TRUE onto the BOOLEAN stack if the CHAR stack is empty, otherwise FALSE.",
|
---|
107 | StackTypes.Boolean)]
|
---|
108 | public class CharEmptyExpression : EmptyExpression<char> {
|
---|
109 | public CharEmptyExpression() { }
|
---|
110 | [StorableConstructor]
|
---|
111 | protected CharEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
112 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
113 | Eval(interpreter.CharStack, interpreter.BooleanStack);
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | [StorableClass]
|
---|
118 | [PushExpression(
|
---|
119 | StackTypes.String,
|
---|
120 | "STRING.EMPTY",
|
---|
121 | "Pushes TRUE onto the BOOLEAN stack if the STRING stack is empty, otherwise FALSE.",
|
---|
122 | StackTypes.Boolean)]
|
---|
123 | public class StringEmptyExpression : EmptyExpression<string> {
|
---|
124 | public StringEmptyExpression() { }
|
---|
125 | [StorableConstructor]
|
---|
126 | protected StringEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
127 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
128 | Eval(interpreter.StringStack, interpreter.BooleanStack);
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | [StorableClass]
|
---|
133 | [PushExpression(
|
---|
134 | StackTypes.IntegerVector,
|
---|
135 | "INTEGER[].EMPTY",
|
---|
136 | "Pushes TRUE onto the BOOLEAN stack if the INTEGER[] stack is empty, otherwise FALSE.",
|
---|
137 | StackTypes.Boolean)]
|
---|
138 | public class IntegerVectorEmptyExpression : EmptyExpression<IReadOnlyList<long>> {
|
---|
139 | public IntegerVectorEmptyExpression() { }
|
---|
140 | [StorableConstructor]
|
---|
141 | protected IntegerVectorEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
142 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
143 | Eval(interpreter.IntegerVectorStack, interpreter.BooleanStack);
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | [StorableClass]
|
---|
148 | [PushExpression(
|
---|
149 | StackTypes.FloatVector,
|
---|
150 | "FLOAT[].EMPTY",
|
---|
151 | "Pushes TRUE onto the BOOLEAN stack if the FLOAT[] stack is empty, otherwise FALSE.",
|
---|
152 | StackTypes.Boolean)]
|
---|
153 | public class FloatVectorEmptyExpression : EmptyExpression<IReadOnlyList<double>> {
|
---|
154 | public FloatVectorEmptyExpression() { }
|
---|
155 | [StorableConstructor]
|
---|
156 | protected FloatVectorEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
157 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
158 | Eval(interpreter.FloatVectorStack, interpreter.BooleanStack);
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | [StorableClass]
|
---|
163 | [PushExpression(
|
---|
164 | StackTypes.BooleanVector,
|
---|
165 | "BOOLEAN[].EMPTY",
|
---|
166 | "Pushes TRUE onto the BOOLEAN stack if the BOOLEAN[] stack is empty, otherwise FALSE.",
|
---|
167 | StackTypes.Boolean)]
|
---|
168 | public class BooleanVectorEmptyExpression : EmptyExpression<IReadOnlyList<bool>> {
|
---|
169 | public BooleanVectorEmptyExpression() { }
|
---|
170 | [StorableConstructor]
|
---|
171 | protected BooleanVectorEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
172 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
173 | Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | [StorableClass]
|
---|
178 | [PushExpression(
|
---|
179 | StackTypes.StringVector,
|
---|
180 | "STRING[].EMPTY",
|
---|
181 | "Pushes TRUE onto the BOOLEAN stack if the STRING[] stack is empty, otherwise FALSE.",
|
---|
182 | StackTypes.Boolean)]
|
---|
183 | public class StringVectorEmptyExpression : EmptyExpression<IReadOnlyList<string>> {
|
---|
184 | public StringVectorEmptyExpression() { }
|
---|
185 | [StorableConstructor]
|
---|
186 | protected StringVectorEmptyExpression(bool deserializing) : base(deserializing) { }
|
---|
187 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
188 | Eval(interpreter.StringVectorStack, interpreter.BooleanStack);
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|