1 | using System.Collections.Generic;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; |
---|
4 | |
---|
5 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
6 | /// <summary>
|
---|
7 | /// Takes the rest of the top item on the type stack.
|
---|
8 | /// </summary>
|
---|
9 | /// <typeparam name="T"></typeparam>
|
---|
10 | [StorableClass]
|
---|
11 | public abstract class VectorButLastExpression<T> : StatelessExpression {
|
---|
12 | protected VectorButLastExpression() { }
|
---|
13 | [StorableConstructor]
|
---|
14 | protected VectorButLastExpression(bool deserializing) : base(deserializing) { }
|
---|
15 |
|
---|
16 | protected bool IsNoop(IPushStack<IReadOnlyList<T>> vectorStack) {
|
---|
17 | return vectorStack.IsEmpty || vectorStack.Top.Count < 2;
|
---|
18 | }
|
---|
19 |
|
---|
20 | protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack) {
|
---|
21 | vectorStack.Top = vectorStack.Top
|
---|
22 | .Take(vectorStack.Top.Count - 1)
|
---|
23 | .ToList();
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | [StorableClass]
|
---|
28 | [PushExpression(
|
---|
29 | StackTypes.IntegerVector,
|
---|
30 | "INTEGER[].BUTLAST",
|
---|
31 | "Takes the rest of the top item on the INTEGER[] stack.")]
|
---|
32 | public class IntegerVectorButLastExpression : VectorButLastExpression<long> {
|
---|
33 | public IntegerVectorButLastExpression() { }
|
---|
34 | [StorableConstructor]
|
---|
35 | protected IntegerVectorButLastExpression(bool deserializing) : base(deserializing) { }
|
---|
36 |
|
---|
37 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
38 | return IsNoop(interpreter.IntegerVectorStack);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
42 | Eval(interpreter.IntegerVectorStack);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | [StorableClass]
|
---|
47 | [PushExpression(
|
---|
48 | StackTypes.FloatVector,
|
---|
49 | "FLOAT[].BUTLAST",
|
---|
50 | "Takes the rest of the top item on the FLOAT[] stack.")]
|
---|
51 | public class FloatVectorButLastExpression : VectorButLastExpression<double> {
|
---|
52 | public FloatVectorButLastExpression() { }
|
---|
53 | [StorableConstructor]
|
---|
54 | protected FloatVectorButLastExpression(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);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | [StorableClass]
|
---|
66 | [PushExpression(
|
---|
67 | StackTypes.BooleanVector,
|
---|
68 | "BOOLEAN[].BUTLAST",
|
---|
69 | "Takes the rest of the top item on the BOOLEAN[] stack.")]
|
---|
70 | public class BooleanVectorButLastExpression : VectorButLastExpression<bool> {
|
---|
71 | public BooleanVectorButLastExpression() { }
|
---|
72 | [StorableConstructor]
|
---|
73 | protected BooleanVectorButLastExpression(bool deserializing) : base(deserializing) { }
|
---|
74 |
|
---|
75 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
76 | return IsNoop(interpreter.BooleanVectorStack);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
80 | Eval(interpreter.BooleanVectorStack);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | [StorableClass]
|
---|
85 | [PushExpression(
|
---|
86 | StackTypes.StringVector,
|
---|
87 | "STRING[].BUTLAST",
|
---|
88 | "Takes the rest of the top item on the STRING[] stack.")]
|
---|
89 | public class StringVectorButLastExpression : VectorButLastExpression<string> {
|
---|
90 | public StringVectorButLastExpression() { }
|
---|
91 | [StorableConstructor]
|
---|
92 | protected StringVectorButLastExpression(bool deserializing) : base(deserializing) { }
|
---|
93 |
|
---|
94 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
95 | return IsNoop(interpreter.StringVectorStack);
|
---|
96 | }
|
---|
97 |
|
---|
98 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
99 | Eval(interpreter.StringVectorStack);
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|