[15771] | 1 | using System.Collections.Generic;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; |
---|
| 4 | |
---|
| 5 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
[15017] | 6 |
|
---|
[14727] | 7 | /// <summary>
|
---|
[15032] | 8 | /// Pushes TRUE onto the T stack if the top two items are equal, or FALSE otherwise
|
---|
[14727] | 9 | /// </summary>
|
---|
| 10 | /// <typeparam name="T">Stacktype</typeparam>
|
---|
[14952] | 11 | [StorableClass]
|
---|
[14727] | 12 | public abstract class EqualsExpression<T> : StatelessExpression {
|
---|
[14952] | 13 | protected EqualsExpression() { }
|
---|
| 14 | [StorableConstructor]
|
---|
| 15 | protected EqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
[14727] | 16 |
|
---|
[14952] | 17 | protected void Eval(IPushStack<T> stack, IPushStack<bool> booleanStack) {
|
---|
[14875] | 18 | var first = stack[1];
|
---|
| 19 | var second = stack.Top;
|
---|
| 20 | stack.Remove(2);
|
---|
[14727] | 21 |
|
---|
[15017] | 22 | var equal = first.Equals(second);
|
---|
| 23 | booleanStack.Push(equal);
|
---|
[14727] | 24 | }
|
---|
[15017] | 25 |
|
---|
| 26 | protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<bool> booleanStack) {
|
---|
| 27 | var first = vectorStack[1];
|
---|
| 28 | var second = vectorStack[0];
|
---|
| 29 | vectorStack.Remove(2);
|
---|
| 30 |
|
---|
| 31 | var equal = first.SequenceEqual(second);
|
---|
| 32 | booleanStack.Push(equal);
|
---|
| 33 | }
|
---|
[14727] | 34 | }
|
---|
| 35 |
|
---|
[14952] | 36 | [StorableClass]
|
---|
[15032] | 37 | [PushExpression(
|
---|
| 38 | StackTypes.Integer,
|
---|
| 39 | "INTEGER.=",
|
---|
| 40 | "Pushes TRUE onto the BOOLEAN stack if the top two INTEGER items are equal, or FALSE otherwise.",
|
---|
| 41 | StackTypes.Boolean)]
|
---|
[14727] | 42 | public class IntegerEqualsExpression : EqualsExpression<long> {
|
---|
[14952] | 43 | public IntegerEqualsExpression() { }
|
---|
| 44 | [StorableConstructor]
|
---|
| 45 | protected IntegerEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 46 |
|
---|
| 47 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 48 | return interpreter.IntegerStack.Count < 2;
|
---|
[14727] | 49 | }
|
---|
[14952] | 50 |
|
---|
| 51 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 52 | Eval(interpreter.IntegerStack, interpreter.BooleanStack);
|
---|
| 53 | }
|
---|
[14727] | 54 | }
|
---|
| 55 |
|
---|
[14952] | 56 | [StorableClass]
|
---|
[15032] | 57 | [PushExpression(
|
---|
| 58 | StackTypes.Float,
|
---|
| 59 | "FLOAT.=",
|
---|
| 60 | "Pushes TRUE onto the BOOLEAN stack if the top two FLOAT items are equal, or FALSE otherwise.",
|
---|
| 61 | StackTypes.Boolean)]
|
---|
[14727] | 62 | public class FloatEqualsExpression : EqualsExpression<double> {
|
---|
[14952] | 63 | public FloatEqualsExpression() { }
|
---|
| 64 | [StorableConstructor]
|
---|
| 65 | protected FloatEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
[14834] | 66 |
|
---|
[14952] | 67 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 68 | return interpreter.FloatStack.Count < 2;
|
---|
| 69 | }
|
---|
[14875] | 70 |
|
---|
[14952] | 71 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 72 | Eval(interpreter.FloatStack, interpreter.BooleanStack);
|
---|
[14727] | 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[14952] | 76 | [StorableClass]
|
---|
[15032] | 77 | [PushExpression(
|
---|
| 78 | StackTypes.Boolean,
|
---|
| 79 | "BOOLEAN.=",
|
---|
[15334] | 80 | "Pushes TRUE onto the BOOLEAN stack if the top two BOOLEAN items are equal, or FALSE otherwise.")]
|
---|
[14727] | 81 | public class BooleanEqualsExpression : EqualsExpression<bool> {
|
---|
[14952] | 82 | public BooleanEqualsExpression() { }
|
---|
| 83 | [StorableConstructor]
|
---|
| 84 | protected BooleanEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 85 |
|
---|
| 86 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 87 | return interpreter.BooleanStack.Count < 2;
|
---|
[14727] | 88 | }
|
---|
[14952] | 89 |
|
---|
| 90 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 91 | Eval(interpreter.BooleanStack, interpreter.BooleanStack);
|
---|
| 92 | }
|
---|
[14727] | 93 | }
|
---|
| 94 |
|
---|
[14952] | 95 | [StorableClass]
|
---|
[15032] | 96 | [PushExpression(
|
---|
| 97 | StackTypes.Name,
|
---|
| 98 | "NAME.=",
|
---|
| 99 | "Pushes TRUE onto the BOOLEAN stack if the top two NAME items are equal, or FALSE otherwise.",
|
---|
| 100 | StackTypes.Boolean)]
|
---|
[14727] | 101 | public class NameEqualsExpression : EqualsExpression<string> {
|
---|
[14952] | 102 | public NameEqualsExpression() { }
|
---|
| 103 | [StorableConstructor]
|
---|
| 104 | protected NameEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 105 |
|
---|
| 106 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 107 | return interpreter.NameStack.Count < 2;
|
---|
[14727] | 108 | }
|
---|
[14952] | 109 |
|
---|
| 110 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 111 | Eval(interpreter.NameStack, interpreter.BooleanStack);
|
---|
| 112 | }
|
---|
[14727] | 113 | }
|
---|
| 114 |
|
---|
[14952] | 115 | [StorableClass]
|
---|
[15032] | 116 | [PushExpression(
|
---|
| 117 | StackTypes.Exec,
|
---|
| 118 | "EXEC.=",
|
---|
| 119 | "Pushes TRUE onto the BOOLEAN stack if the top two EXEC items are equal, or FALSE otherwise.",
|
---|
| 120 | StackTypes.Boolean,
|
---|
[15334] | 121 | requiredBlockCount: 0)]
|
---|
[14727] | 122 | public class ExecEqualsExpression : EqualsExpression<Expression> {
|
---|
[14952] | 123 | public ExecEqualsExpression() { }
|
---|
| 124 | [StorableConstructor]
|
---|
| 125 | protected ExecEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 126 |
|
---|
| 127 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 128 | return interpreter.ExecStack.Count < 2;
|
---|
[14727] | 129 | }
|
---|
[14952] | 130 |
|
---|
| 131 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 132 | Eval(interpreter.ExecStack, interpreter.BooleanStack);
|
---|
| 133 | }
|
---|
[14727] | 134 | }
|
---|
| 135 |
|
---|
[14952] | 136 | [StorableClass]
|
---|
[15032] | 137 | [PushExpression(
|
---|
| 138 | StackTypes.Code,
|
---|
| 139 | "CODE.=",
|
---|
| 140 | "Pushes TRUE onto the BOOLEAN stack if the top two CODE items are equal, or FALSE otherwise.",
|
---|
| 141 | StackTypes.Boolean)]
|
---|
[14727] | 142 | public class CodeEqualsExpression : EqualsExpression<Expression> {
|
---|
[14952] | 143 | public CodeEqualsExpression() { }
|
---|
| 144 | [StorableConstructor]
|
---|
| 145 | protected CodeEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 146 |
|
---|
| 147 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 148 | return interpreter.CodeStack.Count < 2;
|
---|
[14727] | 149 | }
|
---|
[14952] | 150 |
|
---|
| 151 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 152 | Eval(interpreter.CodeStack, interpreter.BooleanStack);
|
---|
| 153 | }
|
---|
[14727] | 154 | }
|
---|
[14777] | 155 |
|
---|
[14952] | 156 | [StorableClass]
|
---|
[15032] | 157 | [PushExpression(
|
---|
| 158 | StackTypes.Char,
|
---|
| 159 | "CHAR.=",
|
---|
| 160 | "Pushes TRUE onto the BOOLEAN stack if the top two CHAR items are equal, or FALSE otherwise.",
|
---|
| 161 | StackTypes.Boolean)]
|
---|
[14777] | 162 | public class CharEqualsExpression : EqualsExpression<char> {
|
---|
[14952] | 163 | public CharEqualsExpression() { }
|
---|
| 164 | [StorableConstructor]
|
---|
| 165 | protected CharEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 166 |
|
---|
| 167 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 168 | return interpreter.CharStack.Count < 2;
|
---|
[14777] | 169 | }
|
---|
[14952] | 170 |
|
---|
| 171 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 172 | Eval(interpreter.CharStack, interpreter.BooleanStack);
|
---|
| 173 | }
|
---|
[14777] | 174 | }
|
---|
| 175 |
|
---|
[14952] | 176 | [StorableClass]
|
---|
[15032] | 177 | [PushExpression(
|
---|
| 178 | StackTypes.String,
|
---|
| 179 | "STRING.=",
|
---|
| 180 | "Pushes TRUE onto the BOOLEAN stack if the top two STRING items are equal, or FALSE otherwise.",
|
---|
| 181 | StackTypes.Boolean)]
|
---|
[14777] | 182 | public class StringEqualsExpression : EqualsExpression<string> {
|
---|
[14952] | 183 | public StringEqualsExpression() { }
|
---|
| 184 | [StorableConstructor]
|
---|
| 185 | protected StringEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 186 |
|
---|
| 187 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 188 | return interpreter.StringStack.Count < 2;
|
---|
[14777] | 189 | }
|
---|
[14952] | 190 |
|
---|
| 191 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 192 | Eval(interpreter.StringStack, interpreter.BooleanStack);
|
---|
| 193 | }
|
---|
[14777] | 194 | }
|
---|
[14834] | 195 |
|
---|
[14952] | 196 | [StorableClass]
|
---|
[15032] | 197 | [PushExpression(
|
---|
| 198 | StackTypes.IntegerVector,
|
---|
| 199 | "INTEGER[].=",
|
---|
| 200 | "Pushes TRUE onto the BOOLEAN stack if the top two INTEGER[] items are equal, or FALSE otherwise.",
|
---|
| 201 | StackTypes.Boolean)]
|
---|
[15017] | 202 | public class IntegerVectorEqualsExpression : EqualsExpression<long> {
|
---|
[14952] | 203 | public IntegerVectorEqualsExpression() { }
|
---|
| 204 | [StorableConstructor]
|
---|
| 205 | protected IntegerVectorEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 206 |
|
---|
| 207 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 208 | return interpreter.IntegerVectorStack.Count < 2;
|
---|
[14834] | 209 | }
|
---|
[14952] | 210 |
|
---|
| 211 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 212 | Eval(interpreter.IntegerVectorStack, interpreter.BooleanStack);
|
---|
| 213 | }
|
---|
[14834] | 214 | }
|
---|
[14875] | 215 |
|
---|
[14952] | 216 | [StorableClass]
|
---|
[15032] | 217 | [PushExpression(
|
---|
| 218 | StackTypes.FloatVector,
|
---|
| 219 | "FLOAT[].=",
|
---|
| 220 | "Pushes TRUE onto the BOOLEAN stack if the top two FLOAT[] items are equal, or FALSE otherwise.",
|
---|
| 221 | StackTypes.Boolean)]
|
---|
[15017] | 222 | public class FloatVectorEqualsExpression : EqualsExpression<double> {
|
---|
[14952] | 223 | public FloatVectorEqualsExpression() { }
|
---|
| 224 | [StorableConstructor]
|
---|
| 225 | protected FloatVectorEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 226 |
|
---|
| 227 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 228 | return interpreter.FloatVectorStack.Count < 2;
|
---|
[14875] | 229 | }
|
---|
[14952] | 230 |
|
---|
| 231 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 232 | Eval(interpreter.FloatVectorStack, interpreter.BooleanStack);
|
---|
| 233 | }
|
---|
[14875] | 234 | }
|
---|
| 235 |
|
---|
[14952] | 236 | [StorableClass]
|
---|
[15032] | 237 | [PushExpression(
|
---|
| 238 | StackTypes.BooleanVector,
|
---|
| 239 | "BOOLEAN[].=",
|
---|
| 240 | "Pushes TRUE onto the BOOLEAN stack if the top two BOOLEAN[] items are equal, or FALSE otherwise.",
|
---|
| 241 | StackTypes.Boolean)]
|
---|
[15017] | 242 | public class BooleanVectorEqualsExpression : EqualsExpression<bool> {
|
---|
[14952] | 243 | public BooleanVectorEqualsExpression() { }
|
---|
| 244 | [StorableConstructor]
|
---|
| 245 | protected BooleanVectorEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 246 |
|
---|
| 247 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 248 | return interpreter.BooleanVectorStack.Count < 2;
|
---|
[14875] | 249 | }
|
---|
[14952] | 250 |
|
---|
| 251 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 252 | Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
| 253 | }
|
---|
[14875] | 254 | }
|
---|
| 255 |
|
---|
[14952] | 256 | [StorableClass]
|
---|
[15032] | 257 | [PushExpression(
|
---|
| 258 | StackTypes.StringVector,
|
---|
| 259 | "STRING[].=",
|
---|
| 260 | "Pushes TRUE onto the BOOLEAN stack if the top two STRING[] items are equal, or FALSE otherwise.",
|
---|
| 261 | StackTypes.Boolean)]
|
---|
[15017] | 262 | public class StringVectorEqualsExpression : EqualsExpression<string> {
|
---|
[14952] | 263 | public StringVectorEqualsExpression() { }
|
---|
| 264 | [StorableConstructor]
|
---|
| 265 | protected StringVectorEqualsExpression(bool deserializing) : base(deserializing) { }
|
---|
| 266 |
|
---|
| 267 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 268 | return interpreter.StringVectorStack.Count < 2;
|
---|
[14875] | 269 | }
|
---|
[14952] | 270 |
|
---|
| 271 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 272 | Eval(interpreter.StringVectorStack, interpreter.BooleanStack);
|
---|
| 273 | }
|
---|
[14875] | 274 | }
|
---|
[14727] | 275 | } |
---|