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 | /// Conj's an item onto the type stack.
|
---|
10 | /// </summary>
|
---|
11 | public abstract class VectorConjExpression<T> : StatelessExpression {
|
---|
12 | protected bool Eval(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
|
---|
13 | if (vectorStack.IsEmpty ||
|
---|
14 | literalStack.IsEmpty ||
|
---|
15 | vectorStack.Top.Count + 1 > interpreter.Configuration.MaxVectorLength)
|
---|
16 | return false;
|
---|
17 |
|
---|
18 | var literal = literalStack.Pop();
|
---|
19 | vectorStack.Top.Add(literal);
|
---|
20 | return true;
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].CONJ", StackTypes.Integer)]
|
---|
25 | public class IntegerVectorConjExpression : VectorConjExpression<long> {
|
---|
26 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
27 | return Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack);
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | [PushExpression(StackTypes.FloatVector, "FLOAT[].CONJ", StackTypes.Float)]
|
---|
32 | public class FloatVectorConjExpression : VectorConjExpression<double> {
|
---|
33 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
34 | return Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | [PushExpression(StackTypes.StringVector, "STRING[].CONJ", StackTypes.String)]
|
---|
39 | public class StringVectorConjExpression : VectorConjExpression<string> {
|
---|
40 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
41 | return Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].CONJ", StackTypes.Boolean)]
|
---|
46 | public class BooleanVectorConjExpression : VectorConjExpression<bool> {
|
---|
47 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
48 | return Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | } |
---|