namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using System.Collections.Generic; using System.Linq; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; /// /// Pushes every item from the first vector onto the appropriate stack in reversed order. /// /// [StorableClass] public abstract class VectorPushAllExpression : StatelessExpression { protected VectorPushAllExpression() { } [StorableConstructor] protected VectorPushAllExpression(bool deserializing) : base(deserializing) { } protected bool IsNoop(IPushStack> vectorStack) { return vectorStack.IsEmpty; } protected void Eval(IPushStack> vectorStack, IPushStack literalStack) { var vector = vectorStack.Pop().Reverse().ToList(); literalStack.Push(vector); } } [StorableClass] [PushExpression( StackTypes.IntegerVector, "INTEGER[].PUSHALL", "Pushes every item from the top INTEGER[] onto the INTEGER stack in reversed order.", StackTypes.Integer)] public class IntegerVectorPushAllExpression : VectorPushAllExpression { public IntegerVectorPushAllExpression() { } [StorableConstructor] protected IntegerVectorPushAllExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.IntegerVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.FloatVector, "FLOAT[].PUSHALL", "Pushes every item from the top FLOAT[] onto the FLOAT stack in reversed order.", StackTypes.Float)] public class FloatVectorPushAllExpression : VectorPushAllExpression { public FloatVectorPushAllExpression() { } [StorableConstructor] protected FloatVectorPushAllExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.FloatVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatVectorStack, interpreter.FloatStack); } } [StorableClass] [PushExpression( StackTypes.BooleanVector, "BOOLEAN[].PUSHALL", "Pushes every item from the top BOOLEAN[] onto the BOOLEAN stack in reversed order.", StackTypes.Boolean)] public class BooleanVectorPushAllExpression : VectorPushAllExpression { public BooleanVectorPushAllExpression() { } [StorableConstructor] protected BooleanVectorPushAllExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.BooleanVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.StringVector, "STRING[].PUSHALL", "Pushes every item from the top STRING[] onto the STRING stack in reversed order.", StackTypes.String)] public class StringVectorPushAllExpression : VectorPushAllExpression { public StringVectorPushAllExpression() { } [StorableConstructor] protected StringVectorPushAllExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.StringVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack, interpreter.StringStack); } } }