1 | using System.Collections.Generic;
|
---|
2 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
5 | /// <summary>
|
---|
6 | /// Gets the first item from the type stack
|
---|
7 | /// </summary>
|
---|
8 | /// <typeparam name="T"></typeparam>
|
---|
9 | [StorableClass]
|
---|
10 | public abstract class VectorFirstExpression<T> : StatelessExpression {
|
---|
11 | protected VectorFirstExpression() { }
|
---|
12 | [StorableConstructor]
|
---|
13 | protected VectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
14 |
|
---|
15 | protected bool IsNoop(IPushStack<IReadOnlyList<T>> vectorStack) {
|
---|
16 | return vectorStack.IsEmpty || vectorStack.Top.Count == 0;
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
|
---|
20 | var vector = vectorStack.Pop();
|
---|
21 | literalStack.Push(vector[0]);
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | [StorableClass]
|
---|
26 | [PushExpression(
|
---|
27 | StackTypes.IntegerVector,
|
---|
28 | "INTEGER[].FIRST",
|
---|
29 | "Pushes the first INTEGER of the top INTEGER[].",
|
---|
30 | StackTypes.Integer)]
|
---|
31 | public class IntegerVectorFirstExpression : VectorFirstExpression<long> {
|
---|
32 | public IntegerVectorFirstExpression() { }
|
---|
33 | [StorableConstructor]
|
---|
34 | protected IntegerVectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
35 |
|
---|
36 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
37 | return IsNoop(interpreter.IntegerVectorStack);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
41 | Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [StorableClass]
|
---|
46 | [PushExpression(
|
---|
47 | StackTypes.FloatVector,
|
---|
48 | "FLOAT[].FIRST",
|
---|
49 | "Pushes the first FLOAT of the top FLOAT[].",
|
---|
50 | StackTypes.Float)]
|
---|
51 | public class FloatVectorFirstExpression : VectorFirstExpression<double> {
|
---|
52 | public FloatVectorFirstExpression() { }
|
---|
53 | [StorableConstructor]
|
---|
54 | protected FloatVectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
55 |
|
---|
56 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
57 | return IsNoop(interpreter.FloatVectorStack);
|
---|
58 | }
|
---|
59 |
|
---|
60 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
61 | Eval(interpreter.FloatVectorStack, interpreter.FloatStack);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | [StorableClass]
|
---|
66 | [PushExpression(
|
---|
67 | StackTypes.BooleanVector,
|
---|
68 | "BOOLEAN[].FIRST",
|
---|
69 | "Pushes the first BOOLEAN of the top BOOLEAN[].",
|
---|
70 | StackTypes.Boolean)]
|
---|
71 | public class BooleanVectorFirstExpression : VectorFirstExpression<bool> {
|
---|
72 | public BooleanVectorFirstExpression() { }
|
---|
73 | [StorableConstructor]
|
---|
74 | protected BooleanVectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
75 |
|
---|
76 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
77 | return IsNoop(interpreter.BooleanVectorStack);
|
---|
78 | }
|
---|
79 |
|
---|
80 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
81 | Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | [StorableClass]
|
---|
86 | [PushExpression(
|
---|
87 | StackTypes.StringVector,
|
---|
88 | "STRING[].FIRST",
|
---|
89 | "Pushes the first BOOLEAN of the top BOOLEAN[].",
|
---|
90 | StackTypes.String)]
|
---|
91 | public class StringVectorFirstExpression : VectorFirstExpression<string> {
|
---|
92 | public StringVectorFirstExpression() { }
|
---|
93 | [StorableConstructor]
|
---|
94 | protected StringVectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
95 |
|
---|
96 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
97 | return IsNoop(interpreter.StringVectorStack);
|
---|
98 | }
|
---|
99 |
|
---|
100 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
101 | Eval(interpreter.StringVectorStack, interpreter.StringStack);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|