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; /// /// Takes the rest of the top item on the type stack. /// /// [StorableClass] public abstract class VectorButLastExpression : StatelessExpression { protected VectorButLastExpression() { } [StorableConstructor] protected VectorButLastExpression(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 .Take(vectorStack.Top.Count - 1) .ToList(); } } [StorableClass] [PushExpression( StackTypes.IntegerVector, "INTEGER[].BUTLAST", "Takes the rest of the top item on the INTEGER[] stack.")] public class IntegerVectorButLastExpression : VectorButLastExpression { public IntegerVectorButLastExpression() { } [StorableConstructor] protected IntegerVectorButLastExpression(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[].BUTLAST", "Takes the rest of the top item on the FLOAT[] stack.")] public class FloatVectorButLastExpression : VectorButLastExpression { public FloatVectorButLastExpression() { } [StorableConstructor] protected FloatVectorButLastExpression(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[].BUTLAST", "Takes the rest of the top item on the BOOLEAN[] stack.")] public class BooleanVectorButLastExpression : VectorButLastExpression { public BooleanVectorButLastExpression() { } [StorableConstructor] protected BooleanVectorButLastExpression(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[].BUTLAST", "Takes the rest of the top item on the STRING[] stack.")] public class StringVectorButLastExpression : VectorButLastExpression { public StringVectorButLastExpression() { } [StorableConstructor] protected StringVectorButLastExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return IsNoop(interpreter.StringVectorStack); } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack); } } }