1 | using System.Collections.Generic;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
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 | /// Gets the first item from the type stack
|
---|
11 | /// </summary>
|
---|
12 | /// <typeparam name="T"></typeparam>
|
---|
13 | [StorableClass]
|
---|
14 | public abstract class VectorFirstExpression<T> : StatelessExpression {
|
---|
15 | protected VectorFirstExpression() { }
|
---|
16 | [StorableConstructor]
|
---|
17 | protected VectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
18 |
|
---|
19 | protected bool IsNoop(IPushStack<List<T>> vectorStack) {
|
---|
20 | return vectorStack.IsEmpty || vectorStack.Top.Count == 0;
|
---|
21 | }
|
---|
22 |
|
---|
23 | protected void Eval(IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
|
---|
24 | var vector = vectorStack.Pop();
|
---|
25 | literalStack.Push(vector[0]);
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | [StorableClass]
|
---|
30 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].FIRST", 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(StackTypes.FloatVector, "FLOAT[].FIRST", StackTypes.Float)]
|
---|
47 | public class FloatVectorFirstExpression : VectorFirstExpression<double> {
|
---|
48 | public FloatVectorFirstExpression() { }
|
---|
49 | [StorableConstructor]
|
---|
50 | protected FloatVectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
51 |
|
---|
52 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
53 | return IsNoop(interpreter.FloatVectorStack);
|
---|
54 | }
|
---|
55 |
|
---|
56 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
57 | Eval(interpreter.FloatVectorStack, interpreter.FloatStack);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | [StorableClass]
|
---|
62 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].FIRST", StackTypes.Boolean)]
|
---|
63 | public class BooleanVectorFirstExpression : VectorFirstExpression<bool> {
|
---|
64 | public BooleanVectorFirstExpression() { }
|
---|
65 | [StorableConstructor]
|
---|
66 | protected BooleanVectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
67 |
|
---|
68 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
69 | return IsNoop(interpreter.BooleanVectorStack);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
73 | Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | [StorableClass]
|
---|
78 | [PushExpression(StackTypes.StringVector, "STRING[].FIRST", StackTypes.String)]
|
---|
79 | public class StringVectorFirstExpression : VectorFirstExpression<string> {
|
---|
80 | public StringVectorFirstExpression() { }
|
---|
81 | [StorableConstructor]
|
---|
82 | protected StringVectorFirstExpression(bool deserializing) : base(deserializing) { }
|
---|
83 |
|
---|
84 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
85 | return IsNoop(interpreter.StringVectorStack);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
89 | Eval(interpreter.StringVectorStack, interpreter.StringStack);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|