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