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 | /// Pushes every item from the first vector onto the appropriate stack in reversed order.
|
---|
10 | /// </summary>
|
---|
11 | /// <typeparam name="T"></typeparam>
|
---|
12 | public abstract class VectorPushAllExpression<T> : StatelessExpression {
|
---|
13 | protected bool Eval(IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
|
---|
14 | if (vectorStack.IsEmpty)
|
---|
15 | return false;
|
---|
16 |
|
---|
17 | var vector = vectorStack.Pop();
|
---|
18 | vector.Reverse();
|
---|
19 | literalStack.Push(vector);
|
---|
20 | return true;
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].PUSHALL", StackTypes.Integer)]
|
---|
25 | public class IntegerVectorPushAllExpression : VectorPushAllExpression<long> {
|
---|
26 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
27 | return Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | [PushExpression(StackTypes.FloatVector, "FLOAT[].PUSHALL", StackTypes.Float)]
|
---|
32 | public class FloatVectorPushAllExpression : VectorPushAllExpression<double> {
|
---|
33 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
34 | return Eval(interpreter.FloatVectorStack, interpreter.FloatStack);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].PUSHALL", StackTypes.Boolean)]
|
---|
39 | public class BooleanVectorPushAllExpression : VectorPushAllExpression<bool> {
|
---|
40 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
41 | return Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [PushExpression(StackTypes.StringVector, "STRING[].PUSHALL", StackTypes.String)]
|
---|
46 | public class StringVectorPushAllExpression : VectorPushAllExpression<string> {
|
---|
47 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
48 | return Eval(interpreter.StringVectorStack, interpreter.StringStack);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|