using System.Collections.Generic; namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 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; /// /// Takes the reverse of the top item on the type stack. /// /// /// [StorableClass] public abstract class VectorReverseExpression : StatelessExpression { protected VectorReverseExpression() { } [StorableConstructor] protected VectorReverseExpression(bool deserializing) : base(deserializing) { } protected bool IsNoop(IPushStack> vectorStack) { return vectorStack.IsEmpty || vectorStack.Top.Count < 2; } protected void Eval(IPushStack> vectorStack) { vectorStack.Top = vectorStack.Top.Reverse().ToList(); } } [StorableClass] [PushExpression( StackTypes.IntegerVector, "INTEGER[].REVERSE", "Reverses the top INTEGER[].")] public class IntegerVectorReverseExpression : VectorReverseExpression { public IntegerVectorReverseExpression() { } [StorableConstructor] protected IntegerVectorReverseExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.IntegerVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerVectorStack); } } [StorableClass] [PushExpression( StackTypes.FloatVector, "FLOAT[].REVERSE", "Reverses the top FLOAT[].")] public class FloatVectorReverseExpression : VectorReverseExpression { public FloatVectorReverseExpression() { } [StorableConstructor] protected FloatVectorReverseExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.FloatVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatVectorStack); } } [StorableClass] [PushExpression( StackTypes.BooleanVector, "BOOLEAN[].REVERSE", "Reverses the top BOOLEAN[].")] public class BooleanVectorReverseExpression : VectorReverseExpression { public BooleanVectorReverseExpression() { } [StorableConstructor] protected BooleanVectorReverseExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.BooleanVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanVectorStack); } } [StorableClass] [PushExpression( StackTypes.StringVector, "STRING[].REVERSE", "Reverses the top STRING[].")] public class StringVectorReverseExpression : VectorReverseExpression { public StringVectorReverseExpression() { } [StorableConstructor] protected StringVectorReverseExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.StringVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack); } } }