1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using Attributes;
|
---|
5 |
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions;
|
---|
8 |
|
---|
9 | using Interpreter;
|
---|
10 | using Stack;
|
---|
11 |
|
---|
12 | [StorableClass]
|
---|
13 | public abstract class ShoveExpression<T> : StatelessExpression {
|
---|
14 | protected ShoveExpression() { }
|
---|
15 | [StorableConstructor]
|
---|
16 | protected ShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
17 |
|
---|
18 | protected void Eval(IPushStack<T> stack, IPushStack<long> integerStack) {
|
---|
19 | var index = integerStack.Pop().AsInt(stack.Count);
|
---|
20 | var item = stack.Pop();
|
---|
21 | stack.Insert(index, item);
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | [PushExpression(
|
---|
26 | StackTypes.Integer,
|
---|
27 | "INTEGER.SHOVE",
|
---|
28 | "Moves the top INTEGER item to a specific stack index, whereby the index is taken from the INTEGER stack.")]
|
---|
29 | [StorableClass]
|
---|
30 | public class IntegerShoveExpression : ShoveExpression<long> {
|
---|
31 | public IntegerShoveExpression() { }
|
---|
32 | [StorableConstructor]
|
---|
33 | protected IntegerShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
34 |
|
---|
35 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
36 | return interpreter.IntegerStack.Count < 3;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
40 | Eval(interpreter.IntegerStack, interpreter.IntegerStack);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | [PushExpression(
|
---|
45 | StackTypes.Float,
|
---|
46 | "FLOAT.SHOVE",
|
---|
47 | "Moves the top FLOAT item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
48 | StackTypes.Integer)]
|
---|
49 | [StorableClass]
|
---|
50 | public class FloatShoveExpression : ShoveExpression<double> {
|
---|
51 | public FloatShoveExpression() { }
|
---|
52 | [StorableConstructor]
|
---|
53 | protected FloatShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
54 |
|
---|
55 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
56 | return interpreter.IntegerStack.IsEmpty || interpreter.FloatStack.Count < 2;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
60 | Eval(interpreter.FloatStack, interpreter.IntegerStack);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | [PushExpression(
|
---|
65 | StackTypes.Boolean,
|
---|
66 | "BOOLEAN.SHOVE",
|
---|
67 | "Moves the top BOOLEAN item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
68 | StackTypes.Integer)]
|
---|
69 | [StorableClass]
|
---|
70 | public class BooleanShoveExpression : ShoveExpression<bool> {
|
---|
71 | public BooleanShoveExpression() { }
|
---|
72 | [StorableConstructor]
|
---|
73 | protected BooleanShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
74 |
|
---|
75 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
76 | return interpreter.IntegerStack.IsEmpty || interpreter.BooleanStack.Count < 2;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
80 | Eval(interpreter.BooleanStack, interpreter.IntegerStack);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | [PushExpression(
|
---|
85 | StackTypes.Name,
|
---|
86 | "NAME.SHOVE",
|
---|
87 | "Moves the top NAME item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
88 | StackTypes.Integer)]
|
---|
89 | [StorableClass]
|
---|
90 | public class NameShoveExpression : ShoveExpression<string> {
|
---|
91 | public NameShoveExpression() { }
|
---|
92 | [StorableConstructor]
|
---|
93 | protected NameShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
94 |
|
---|
95 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
96 | return interpreter.IntegerStack.IsEmpty || interpreter.NameStack.Count < 2;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
100 | Eval(interpreter.NameStack, interpreter.IntegerStack);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | [PushExpression(
|
---|
105 | StackTypes.Exec,
|
---|
106 | "EXEC.SHOVE",
|
---|
107 | "Moves the top EXEC item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
108 | StackTypes.Integer,
|
---|
109 | requiredBlockCount: 1)]
|
---|
110 | [StorableClass]
|
---|
111 | public class ExecShoveExpression : ShoveExpression<Expression> {
|
---|
112 | public ExecShoveExpression() { }
|
---|
113 | [StorableConstructor]
|
---|
114 | protected ExecShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
115 |
|
---|
116 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
117 | return interpreter.IntegerStack.IsEmpty || interpreter.ExecStack.Count < 2;
|
---|
118 | }
|
---|
119 |
|
---|
120 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
121 | Eval(interpreter.ExecStack, interpreter.IntegerStack);
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | [PushExpression(
|
---|
126 | StackTypes.Code,
|
---|
127 | "CODE.SHOVE",
|
---|
128 | "Moves the top CODE item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
129 | StackTypes.Integer)]
|
---|
130 | [StorableClass]
|
---|
131 | public class CodeShoveExpression : ShoveExpression<Expression> {
|
---|
132 | public CodeShoveExpression() { }
|
---|
133 | [StorableConstructor]
|
---|
134 | protected CodeShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
135 |
|
---|
136 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
137 | return interpreter.IntegerStack.IsEmpty || interpreter.CodeStack.Count < 2;
|
---|
138 | }
|
---|
139 |
|
---|
140 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
141 | Eval(interpreter.CodeStack, interpreter.IntegerStack);
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | [PushExpression(
|
---|
146 | StackTypes.Char,
|
---|
147 | "CHAR.SHOVE",
|
---|
148 | "Moves the top CHAR item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
149 | StackTypes.Integer)]
|
---|
150 | [StorableClass]
|
---|
151 | public class CharShoveExpression : ShoveExpression<char> {
|
---|
152 | public CharShoveExpression() { }
|
---|
153 | [StorableConstructor]
|
---|
154 | protected CharShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
155 |
|
---|
156 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
157 | return interpreter.IntegerStack.IsEmpty || interpreter.CharStack.Count < 2;
|
---|
158 | }
|
---|
159 |
|
---|
160 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
161 | Eval(interpreter.CharStack, interpreter.IntegerStack);
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | [PushExpression(
|
---|
166 | StackTypes.String,
|
---|
167 | "STRING.SHOVE",
|
---|
168 | "Moves the top STRING item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
169 | StackTypes.Integer)]
|
---|
170 | [StorableClass]
|
---|
171 | public class StringShoveExpression : ShoveExpression<string> {
|
---|
172 | public StringShoveExpression() { }
|
---|
173 | [StorableConstructor]
|
---|
174 | protected StringShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
175 |
|
---|
176 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
177 | return interpreter.IntegerStack.IsEmpty || interpreter.StringStack.Count < 2;
|
---|
178 | }
|
---|
179 |
|
---|
180 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
181 | Eval(interpreter.StringStack, interpreter.IntegerStack);
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | [PushExpression(
|
---|
186 | StackTypes.IntegerVector,
|
---|
187 | "INTEGER[].SHOVE",
|
---|
188 | "Moves the top INTEGER[] item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
189 | StackTypes.Integer)]
|
---|
190 | [StorableClass]
|
---|
191 | public class IntegerVectorShoveExpression : ShoveExpression<IReadOnlyList<long>> {
|
---|
192 | public IntegerVectorShoveExpression() { }
|
---|
193 | [StorableConstructor]
|
---|
194 | protected IntegerVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
195 |
|
---|
196 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
197 | return interpreter.IntegerStack.IsEmpty || interpreter.IntegerVectorStack.Count < 2;
|
---|
198 | }
|
---|
199 |
|
---|
200 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
201 | Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | [PushExpression(
|
---|
206 | StackTypes.FloatVector,
|
---|
207 | "FLOAT[].SHOVE",
|
---|
208 | "Moves the top FLOAT[] item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
209 | StackTypes.Integer)]
|
---|
210 | [StorableClass]
|
---|
211 | public class FloatVectorShoveExpression : ShoveExpression<IReadOnlyList<double>> {
|
---|
212 | public FloatVectorShoveExpression() { }
|
---|
213 | [StorableConstructor]
|
---|
214 | protected FloatVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
215 |
|
---|
216 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
217 | return interpreter.IntegerStack.IsEmpty || interpreter.FloatVectorStack.Count < 2;
|
---|
218 | }
|
---|
219 |
|
---|
220 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
221 | Eval(interpreter.FloatVectorStack, interpreter.IntegerStack);
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | [PushExpression(
|
---|
226 | StackTypes.BooleanVector,
|
---|
227 | "BOOLEAN[].SHOVE",
|
---|
228 | "Moves the top BOOLEAN[] item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
229 | StackTypes.Integer)]
|
---|
230 | [StorableClass]
|
---|
231 | public class BooleanVectorShoveExpression : ShoveExpression<IReadOnlyList<bool>> {
|
---|
232 | public BooleanVectorShoveExpression() { }
|
---|
233 | [StorableConstructor]
|
---|
234 | protected BooleanVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
235 |
|
---|
236 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
237 | return interpreter.IntegerStack.IsEmpty || interpreter.BooleanVectorStack.Count < 2;
|
---|
238 | }
|
---|
239 |
|
---|
240 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
241 | Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack);
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | [PushExpression(
|
---|
246 | StackTypes.StringVector,
|
---|
247 | "STRING[].SHOVE",
|
---|
248 | "Moves the top STRING[] item to a specific stack index, whereby the index is taken from the INTEGER stack.",
|
---|
249 | StackTypes.Integer)]
|
---|
250 | [StorableClass]
|
---|
251 | public class StringVectorShoveExpression : ShoveExpression<IReadOnlyList<string>> {
|
---|
252 | public StringVectorShoveExpression() { }
|
---|
253 | [StorableConstructor]
|
---|
254 | protected StringVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
255 |
|
---|
256 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
257 | return interpreter.IntegerStack.IsEmpty || interpreter.StringVectorStack.Count < 2;
|
---|
258 | }
|
---|
259 |
|
---|
260 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
261 | Eval(interpreter.StringVectorStack, interpreter.IntegerStack);
|
---|
262 | }
|
---|
263 | }
|
---|
264 | } |
---|