using System.Collections.Generic; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.ProgramSynthesis { /// /// Conj's an item onto the type stack. /// [StorableClass] public abstract class VectorConjExpression : StatelessExpression { protected VectorConjExpression() { } [StorableConstructor] protected VectorConjExpression(bool deserializing) : base(deserializing) { } protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack> vectorStack, IPushStack literalStack) { return vectorStack.IsEmpty || literalStack.IsEmpty || vectorStack.Top.Count + 1 > interpreter.Configuration.MaxVectorLength; } protected void Eval(IInternalPushInterpreter interpreter, IPushStack> vectorStack, IPushStack literalStack) { var literal = literalStack.Pop(); vectorStack.Top = new List(vectorStack.Top) { literal }; } } [StorableClass] [PushExpression( StackTypes.IntegerVector, "INTEGER[].CONJ", "Conj's the top INTEGER onto the top item of the INTEGER[] stack.", StackTypes.Integer)] public class IntegerVectorConjExpression : VectorConjExpression { public IntegerVectorConjExpression() { } [StorableConstructor] protected IntegerVectorConjExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.FloatVector, "FLOAT[].CONJ", "Conj's the top FLOAT onto the top item of the FLOAT[] stack.", StackTypes.Float)] public class FloatVectorConjExpression : VectorConjExpression { public FloatVectorConjExpression() { } [StorableConstructor] protected FloatVectorConjExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack); } } [StorableClass] [PushExpression( StackTypes.StringVector, "STRING[].CONJ", "Conj's the top STRING onto the top item of the STRING[] stack.", StackTypes.String)] public class StringVectorConjExpression : VectorConjExpression { public StringVectorConjExpression() { } [StorableConstructor] protected StringVectorConjExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter, interpreter.StringVectorStack, interpreter.StringStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack); } } [StorableClass] [PushExpression( StackTypes.BooleanVector, "BOOLEAN[].CONJ", "Conj's the top BOOLEAN onto the top item of the BOOLEAN[] stack.", StackTypes.Boolean)] public class BooleanVectorConjExpression : VectorConjExpression { public BooleanVectorConjExpression() { } [StorableConstructor] protected BooleanVectorConjExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack); } } }