1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
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>
|
---|
12 | [StorableClass]
|
---|
13 | public abstract class VectorConjExpression<T> : StatelessExpression {
|
---|
14 | protected VectorConjExpression() { }
|
---|
15 | [StorableConstructor]
|
---|
16 | protected VectorConjExpression(bool deserializing) : base(deserializing) { }
|
---|
17 |
|
---|
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) {
|
---|
25 | var literal = literalStack.Pop();
|
---|
26 | vectorStack.Top.Add(literal);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | [StorableClass]
|
---|
31 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].CONJ", StackTypes.Integer)]
|
---|
32 | public class IntegerVectorConjExpression : VectorConjExpression<long> {
|
---|
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);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
42 | Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | [StorableClass]
|
---|
47 | [PushExpression(StackTypes.FloatVector, "FLOAT[].CONJ", StackTypes.Float)]
|
---|
48 | public class FloatVectorConjExpression : VectorConjExpression<double> {
|
---|
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);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
58 | Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | [StorableClass]
|
---|
63 | [PushExpression(StackTypes.StringVector, "STRING[].CONJ", StackTypes.String)]
|
---|
64 | public class StringVectorConjExpression : VectorConjExpression<string> {
|
---|
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);
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
74 | Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | [StorableClass]
|
---|
79 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].CONJ", StackTypes.Boolean)]
|
---|
80 | public class BooleanVectorConjExpression : VectorConjExpression<bool> {
|
---|
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);
|
---|
87 | }
|
---|
88 |
|
---|
89 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
90 | Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | } |
---|