namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using System.Collections.Generic; using Attributes; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions; using Interpreter; using Stack; [StorableClass] public abstract class ShoveExpression : StatelessExpression { protected ShoveExpression() { } [StorableConstructor] protected ShoveExpression(bool deserializing) : base(deserializing) { } protected void Eval(IPushStack stack, IPushStack integerStack) { var index = integerStack.Pop().AsInt(stack.Count); var item = stack.Pop(); stack.Insert(index, item); } } [PushExpression( StackTypes.Integer, "INTEGER.SHOVE", "Moves the top INTEGER item to a specific stack index, whereby the index is taken from the INTEGER stack.")] [StorableClass] public class IntegerShoveExpression : ShoveExpression { public IntegerShoveExpression() { } [StorableConstructor] protected IntegerShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.Count < 3; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.Float, "FLOAT.SHOVE", "Moves the top FLOAT item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class FloatShoveExpression : ShoveExpression { public FloatShoveExpression() { } [StorableConstructor] protected FloatShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.FloatStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.Boolean, "BOOLEAN.SHOVE", "Moves the top BOOLEAN item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class BooleanShoveExpression : ShoveExpression { public BooleanShoveExpression() { } [StorableConstructor] protected BooleanShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.BooleanStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.Name, "NAME.SHOVE", "Moves the top NAME item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class NameShoveExpression : ShoveExpression { public NameShoveExpression() { } [StorableConstructor] protected NameShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.NameStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.NameStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.Exec, "EXEC.SHOVE", "Moves the top EXEC item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer, requiredBlockCount: 1)] [StorableClass] public class ExecShoveExpression : ShoveExpression { public ExecShoveExpression() { } [StorableConstructor] protected ExecShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.ExecStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.ExecStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.Code, "CODE.SHOVE", "Moves the top CODE item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class CodeShoveExpression : ShoveExpression { public CodeShoveExpression() { } [StorableConstructor] protected CodeShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.CodeStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CodeStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.Char, "CHAR.SHOVE", "Moves the top CHAR item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class CharShoveExpression : ShoveExpression { public CharShoveExpression() { } [StorableConstructor] protected CharShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.CharStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CharStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.String, "STRING.SHOVE", "Moves the top STRING item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class StringShoveExpression : ShoveExpression { public StringShoveExpression() { } [StorableConstructor] protected StringShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.StringStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.IntegerVector, "INTEGER[].SHOVE", "Moves the top INTEGER[] item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class IntegerVectorShoveExpression : ShoveExpression> { public IntegerVectorShoveExpression() { } [StorableConstructor] protected IntegerVectorShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.IntegerVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.FloatVector, "FLOAT[].SHOVE", "Moves the top FLOAT[] item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class FloatVectorShoveExpression : ShoveExpression> { public FloatVectorShoveExpression() { } [StorableConstructor] protected FloatVectorShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.FloatVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatVectorStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.BooleanVector, "BOOLEAN[].SHOVE", "Moves the top BOOLEAN[] item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class BooleanVectorShoveExpression : ShoveExpression> { public BooleanVectorShoveExpression() { } [StorableConstructor] protected BooleanVectorShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.BooleanVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack); } } [PushExpression( StackTypes.StringVector, "STRING[].SHOVE", "Moves the top STRING[] item to a specific stack index, whereby the index is taken from the INTEGER stack.", StackTypes.Integer)] [StorableClass] public class StringVectorShoveExpression : ShoveExpression> { public StringVectorShoveExpression() { } [StorableConstructor] protected StringVectorShoveExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty || interpreter.StringVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack, interpreter.IntegerStack); } } }