[14834] | 1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
[14952] | 4 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[14834] | 5 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
| 6 | using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
|
---|
| 7 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
| 8 |
|
---|
| 9 | /// <summary>
|
---|
| 10 | /// Conj's an item onto the type stack.
|
---|
| 11 | /// </summary>
|
---|
[14952] | 12 | [StorableClass]
|
---|
[14834] | 13 | public abstract class VectorConjExpression<T> : StatelessExpression {
|
---|
[14952] | 14 | protected VectorConjExpression() { }
|
---|
| 15 | [StorableConstructor]
|
---|
| 16 | protected VectorConjExpression(bool deserializing) : base(deserializing) { }
|
---|
[14834] | 17 |
|
---|
[14952] | 18 | protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
|
---|
| 19 | return vectorStack.IsEmpty ||
|
---|
| 20 | literalStack.IsEmpty ||
|
---|
| 21 | vectorStack.Top.Count + 1 > interpreter.Configuration.MaxVectorLength;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | protected void Eval(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
|
---|
[14834] | 25 | var literal = literalStack.Pop();
|
---|
| 26 | vectorStack.Top.Add(literal);
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[14952] | 30 | [StorableClass]
|
---|
[14834] | 31 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].CONJ", StackTypes.Integer)]
|
---|
| 32 | public class IntegerVectorConjExpression : VectorConjExpression<long> {
|
---|
[14952] | 33 | public IntegerVectorConjExpression() { }
|
---|
| 34 | [StorableConstructor]
|
---|
| 35 | protected IntegerVectorConjExpression(bool deserializing) : base(deserializing) { }
|
---|
| 36 |
|
---|
| 37 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 38 | return IsNoop(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
[14834] | 39 | }
|
---|
[14952] | 40 |
|
---|
| 41 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 42 | Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
| 43 | }
|
---|
[14834] | 44 | }
|
---|
| 45 |
|
---|
[14952] | 46 | [StorableClass]
|
---|
[14834] | 47 | [PushExpression(StackTypes.FloatVector, "FLOAT[].CONJ", StackTypes.Float)]
|
---|
| 48 | public class FloatVectorConjExpression : VectorConjExpression<double> {
|
---|
[14952] | 49 | public FloatVectorConjExpression() { }
|
---|
| 50 | [StorableConstructor]
|
---|
| 51 | protected FloatVectorConjExpression(bool deserializing) : base(deserializing) { }
|
---|
| 52 |
|
---|
| 53 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 54 | return IsNoop(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
|
---|
[14834] | 55 | }
|
---|
[14952] | 56 |
|
---|
| 57 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 58 | Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
|
---|
| 59 | }
|
---|
[14834] | 60 | }
|
---|
| 61 |
|
---|
[14952] | 62 | [StorableClass]
|
---|
[14834] | 63 | [PushExpression(StackTypes.StringVector, "STRING[].CONJ", StackTypes.String)]
|
---|
| 64 | public class StringVectorConjExpression : VectorConjExpression<string> {
|
---|
[14952] | 65 | public StringVectorConjExpression() { }
|
---|
| 66 | [StorableConstructor]
|
---|
| 67 | protected StringVectorConjExpression(bool deserializing) : base(deserializing) { }
|
---|
| 68 |
|
---|
| 69 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 70 | return IsNoop(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
|
---|
[14834] | 71 | }
|
---|
[14952] | 72 |
|
---|
| 73 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 74 | Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
|
---|
| 75 | }
|
---|
[14834] | 76 | }
|
---|
| 77 |
|
---|
[14952] | 78 | [StorableClass]
|
---|
[14834] | 79 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].CONJ", StackTypes.Boolean)]
|
---|
| 80 | public class BooleanVectorConjExpression : VectorConjExpression<bool> {
|
---|
[14952] | 81 | public BooleanVectorConjExpression() { }
|
---|
| 82 | [StorableConstructor]
|
---|
| 83 | protected BooleanVectorConjExpression(bool deserializing) : base(deserializing) { }
|
---|
| 84 |
|
---|
| 85 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 86 | return IsNoop(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
[14834] | 87 | }
|
---|
[14952] | 88 |
|
---|
| 89 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 90 | Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
| 91 | }
|
---|
[14834] | 92 | }
|
---|
| 93 | } |
---|