namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using System.Collections.Generic; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; using Interpreter; using Stack; /// /// Swaps the top two values. /// /// Stacktype [StorableClass] public abstract class SwapExpression : StatelessExpression { protected SwapExpression() { } [StorableConstructor] protected SwapExpression(bool deserializing) : base(deserializing) { } protected void Eval(IPushStack stack) { stack.Swap(2); } } [StorableClass] [PushExpression( StackTypes.Integer, "INTEGER.SWAP", "Swaps the top two items on the stack.")] public class IntegerSwapExpression : SwapExpression { public IntegerSwapExpression() { } [StorableConstructor] protected IntegerSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.Float, "FLOAT.SWAP", "Swaps the top two items on the stack.")] public class FloatSwapExpression : SwapExpression { public FloatSwapExpression() { } [StorableConstructor] protected FloatSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.FloatStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatStack); } } [StorableClass] [PushExpression( StackTypes.Boolean, "BOOLEAN.SWAP", "Swaps the top two items on the stack.")] public class BooleanSwapExpression : SwapExpression { public BooleanSwapExpression() { } [StorableConstructor] protected BooleanSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.BooleanStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.Name, "NAME.SWAP", "Swaps the top two items on the stack.")] public class NameSwapExpression : SwapExpression { public NameSwapExpression() { } [StorableConstructor] protected NameSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.NameStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.NameStack); } } [StorableClass] [PushExpression( StackTypes.Exec, "EXEC.SWAP", "Swaps the top two items on the stack.", requiredBlockCount: 2)] public class ExecSwapExpression : SwapExpression { public ExecSwapExpression() { } [StorableConstructor] protected ExecSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.ExecStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.ExecStack); } } [StorableClass] [PushExpression( StackTypes.Code, "CODE.SWAP", "Swaps the top two items on the stack.")] public class CodeSwapExpression : SwapExpression { public CodeSwapExpression() { } [StorableConstructor] protected CodeSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.CodeStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CodeStack); } } [StorableClass] [PushExpression( StackTypes.Char, "CHAR.SWAP", "Swaps the top two items on the stack.")] public class CharSwapExpression : SwapExpression { public CharSwapExpression() { } [StorableConstructor] protected CharSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.CharStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CharStack); } } [StorableClass] [PushExpression( StackTypes.String, "STRING.SWAP", "Swaps the top two items on the stack.")] public class StringSwapExpression : SwapExpression { public StringSwapExpression() { } [StorableConstructor] protected StringSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.StringStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringStack); } } [StorableClass] [PushExpression( StackTypes.IntegerVector, "INTEGER[].SWAP", "Swaps the top two items on the stack.")] public class IntegerVectorSwapExpression : SwapExpression> { public IntegerVectorSwapExpression() { } [StorableConstructor] protected IntegerVectorSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerVectorStack); } } [StorableClass] [PushExpression( StackTypes.FloatVector, "FLOAT[].SWAP", "Swaps the top two items on the stack.")] public class FloatVectorSwapExpression : SwapExpression> { public FloatVectorSwapExpression() { } [StorableConstructor] protected FloatVectorSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.FloatVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatVectorStack); } } [StorableClass] [PushExpression( StackTypes.BooleanVector, "BOOLEAN[].SWAP", "Swaps the top two items on the stack.")] public class BooleanVectorSwapExpression : SwapExpression> { public BooleanVectorSwapExpression() { } [StorableConstructor] protected BooleanVectorSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.BooleanVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanVectorStack); } } [StorableClass] [PushExpression( StackTypes.StringVector, "STRING[].SWAP", "Swaps the top two items on the stack.")] public class StringVectorSwapExpression : SwapExpression> { public StringVectorSwapExpression() { } [StorableConstructor] protected StringVectorSwapExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.StringVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack); } } }