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(StackTypes.Integer, "INTEGER.SHOVE")]
|
---|
26 | [StorableClass]
|
---|
27 | public class IntegerShoveExpression : ShoveExpression<long> {
|
---|
28 | public IntegerShoveExpression() { }
|
---|
29 | [StorableConstructor]
|
---|
30 | protected IntegerShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
31 |
|
---|
32 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
33 | return interpreter.IntegerStack.Count < 3;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
37 | Eval(interpreter.IntegerStack, interpreter.IntegerStack);
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | [PushExpression(StackTypes.Float, "FLOAT.SHOVE", StackTypes.Integer)]
|
---|
42 | [StorableClass]
|
---|
43 | public class FloatShoveExpression : ShoveExpression<double> {
|
---|
44 | public FloatShoveExpression() { }
|
---|
45 | [StorableConstructor]
|
---|
46 | protected FloatShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
47 |
|
---|
48 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
49 | return interpreter.IntegerStack.IsEmpty || interpreter.FloatStack.Count < 2;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
53 | Eval(interpreter.FloatStack, interpreter.IntegerStack);
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | [PushExpression(StackTypes.Boolean, "BOOLEAN.SHOVE", StackTypes.Integer)]
|
---|
58 | [StorableClass]
|
---|
59 | public class BooleanShoveExpression : ShoveExpression<bool> {
|
---|
60 | public BooleanShoveExpression() { }
|
---|
61 | [StorableConstructor]
|
---|
62 | protected BooleanShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
63 |
|
---|
64 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
65 | return interpreter.IntegerStack.IsEmpty || interpreter.BooleanStack.Count < 2;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
69 | Eval(interpreter.BooleanStack, interpreter.IntegerStack);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | [PushExpression(StackTypes.Name, "NAME.SHOVE", StackTypes.Integer)]
|
---|
74 | [StorableClass]
|
---|
75 | public class NameShoveExpression : ShoveExpression<string> {
|
---|
76 | public NameShoveExpression() { }
|
---|
77 | [StorableConstructor]
|
---|
78 | protected NameShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
79 |
|
---|
80 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
81 | return interpreter.IntegerStack.IsEmpty || interpreter.NameStack.Count < 2;
|
---|
82 | }
|
---|
83 |
|
---|
84 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
85 | Eval(interpreter.NameStack, interpreter.IntegerStack);
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | [PushExpression(StackTypes.Exec, "EXEC.SHOVE", StackTypes.Integer, execIn: 1)]
|
---|
90 | [StorableClass]
|
---|
91 | public class ExecShoveExpression : ShoveExpression<Expression> {
|
---|
92 | public ExecShoveExpression() { }
|
---|
93 | [StorableConstructor]
|
---|
94 | protected ExecShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
95 |
|
---|
96 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
97 | return interpreter.IntegerStack.IsEmpty || interpreter.ExecStack.Count < 2;
|
---|
98 | }
|
---|
99 |
|
---|
100 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
101 | Eval(interpreter.ExecStack, interpreter.IntegerStack);
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | [PushExpression(StackTypes.Code, "CODE.SHOVE", StackTypes.Integer)]
|
---|
106 | [StorableClass]
|
---|
107 | public class CodeShoveExpression : ShoveExpression<Expression> {
|
---|
108 | public CodeShoveExpression() { }
|
---|
109 | [StorableConstructor]
|
---|
110 | protected CodeShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
111 |
|
---|
112 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
113 | return interpreter.IntegerStack.IsEmpty || interpreter.CodeStack.Count < 2;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
117 | Eval(interpreter.CodeStack, interpreter.IntegerStack);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | [PushExpression(StackTypes.Char, "CHAR.SHOVE", StackTypes.Integer)]
|
---|
122 | [StorableClass]
|
---|
123 | public class CharShoveExpression : ShoveExpression<char> {
|
---|
124 | public CharShoveExpression() { }
|
---|
125 | [StorableConstructor]
|
---|
126 | protected CharShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
127 |
|
---|
128 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
129 | return interpreter.IntegerStack.IsEmpty || interpreter.CharStack.Count < 2;
|
---|
130 | }
|
---|
131 |
|
---|
132 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
133 | Eval(interpreter.CharStack, interpreter.IntegerStack);
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | [PushExpression(StackTypes.String, "STRING.SHOVE", StackTypes.Integer)]
|
---|
138 | [StorableClass]
|
---|
139 | public class StringShoveExpression : ShoveExpression<string> {
|
---|
140 | public StringShoveExpression() { }
|
---|
141 | [StorableConstructor]
|
---|
142 | protected StringShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
143 |
|
---|
144 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
145 | return interpreter.IntegerStack.IsEmpty || interpreter.StringStack.Count < 2;
|
---|
146 | }
|
---|
147 |
|
---|
148 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
149 | Eval(interpreter.StringStack, interpreter.IntegerStack);
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].SHOVE", StackTypes.Integer)]
|
---|
154 | [StorableClass]
|
---|
155 | public class IntegerVectorShoveExpression : ShoveExpression<IReadOnlyList<long>> {
|
---|
156 | public IntegerVectorShoveExpression() { }
|
---|
157 | [StorableConstructor]
|
---|
158 | protected IntegerVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
159 |
|
---|
160 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
161 | return interpreter.IntegerStack.IsEmpty || interpreter.IntegerVectorStack.Count < 2;
|
---|
162 | }
|
---|
163 |
|
---|
164 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
165 | Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | [PushExpression(StackTypes.FloatVector, "FLOAT[].SHOVE", StackTypes.Integer)]
|
---|
170 | [StorableClass]
|
---|
171 | public class FloatVectorShoveExpression : ShoveExpression<IReadOnlyList<double>> {
|
---|
172 | public FloatVectorShoveExpression() { }
|
---|
173 | [StorableConstructor]
|
---|
174 | protected FloatVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
175 |
|
---|
176 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
177 | return interpreter.IntegerStack.IsEmpty || interpreter.FloatVectorStack.Count < 2;
|
---|
178 | }
|
---|
179 |
|
---|
180 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
181 | Eval(interpreter.FloatVectorStack, interpreter.IntegerStack);
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].SHOVE", StackTypes.Integer)]
|
---|
186 | [StorableClass]
|
---|
187 | public class BooleanVectorShoveExpression : ShoveExpression<IReadOnlyList<bool>> {
|
---|
188 | public BooleanVectorShoveExpression() { }
|
---|
189 | [StorableConstructor]
|
---|
190 | protected BooleanVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
191 |
|
---|
192 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
193 | return interpreter.IntegerStack.IsEmpty || interpreter.BooleanVectorStack.Count < 2;
|
---|
194 | }
|
---|
195 |
|
---|
196 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
197 | Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack);
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | [PushExpression(StackTypes.StringVector, "STRING[].SHOVE", StackTypes.Integer)]
|
---|
202 | [StorableClass]
|
---|
203 | public class StringVectorShoveExpression : ShoveExpression<IReadOnlyList<string>> {
|
---|
204 | public StringVectorShoveExpression() { }
|
---|
205 | [StorableConstructor]
|
---|
206 | protected StringVectorShoveExpression(bool deserializing) : base(deserializing) { }
|
---|
207 |
|
---|
208 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
209 | return interpreter.IntegerStack.IsEmpty || interpreter.StringVectorStack.Count < 2;
|
---|
210 | }
|
---|
211 |
|
---|
212 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
213 | Eval(interpreter.StringVectorStack, interpreter.IntegerStack);
|
---|
214 | }
|
---|
215 | }
|
---|
216 | } |
---|