1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
5 | using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
|
---|
6 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
7 |
|
---|
8 | /// <summary>
|
---|
9 | /// Takes the rest of the top item on the type stack.
|
---|
10 | /// </summary>
|
---|
11 | /// <typeparam name="T"></typeparam>
|
---|
12 | public abstract class VectorRestExpression<T> : StatelessExpression {
|
---|
13 | protected bool Eval(IPushStack<List<T>> vectorStack) {
|
---|
14 | if (vectorStack.IsEmpty || vectorStack.Top.Count < 2)
|
---|
15 | return false;
|
---|
16 |
|
---|
17 | var result = vectorStack.Top.GetRange(1, vectorStack.Top.Count - 1);
|
---|
18 | vectorStack.SetTop(result);
|
---|
19 | return true;
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].REST")]
|
---|
24 | public class IntegerVectorRestExpression : VectorRestExpression<long> {
|
---|
25 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
26 | return Eval(interpreter.IntegerVectorStack);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | [PushExpression(StackTypes.FloatVector, "FLOAT[].REST")]
|
---|
31 | public class FloatVectorRestExpression : VectorRestExpression<double> {
|
---|
32 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
33 | return Eval(interpreter.FloatVectorStack);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].REST")]
|
---|
38 | public class BooleanVectorRestExpression : VectorRestExpression<bool> {
|
---|
39 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
40 | return Eval(interpreter.BooleanVectorStack);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | [PushExpression(StackTypes.StringVector, "STRING[].REST")]
|
---|
45 | public class StringVectorRestExpression : VectorRestExpression<string> {
|
---|
46 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
47 | return Eval(interpreter.StringVectorStack);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|