namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using System; using System.Collections.Generic; using Attributes; using Interpreter; using Stack; public abstract class ShoveExpression : StatelessExpression { protected bool Eval(IPushStack stack, IPushStack integerStack) { if ((stack == integerStack && integerStack.Count < 3) || (stack != integerStack && (integerStack.IsEmpty || stack.Count < 2))) return false; var index = (int)Math.Abs(integerStack.Pop() % stack.Count); var item = stack.Pop(); stack.Insert(index, item); return true; } } [PushExpression(StackTypes.Integer, "INTEGER.SHOVE")] public class IntegerShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.IntegerStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.Float, "FLOAT.SHOVE", StackTypes.Integer)] public class FloatShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.FloatStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.Boolean, "BOOLEAN.SHOVE", StackTypes.Integer)] public class BooleanShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.BooleanStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.Name, "NAME.SHOVE", StackTypes.Integer)] public class NameShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.NameStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.Exec, "EXEC.SHOVE", StackTypes.Integer)] public class ExecShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.ExecStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.Code, "CODE.SHOVE", StackTypes.Integer)] public class CodeShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.CodeStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.Char, "CHAR.SHOVE", StackTypes.Integer)] public class CharShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.CharStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.String, "STRING.SHOVE", StackTypes.Integer)] public class StringShoveExpression : ShoveExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.StringStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.IntegerVector, "INTEGER[].SHOVE", StackTypes.Integer)] public class IntegerVectorShoveExpression : ShoveExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.FloatVector, "FLOAT[].SHOVE", StackTypes.Integer)] public class FloatVectorShoveExpression : ShoveExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.FloatVectorStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].SHOVE", StackTypes.Integer)] public class BooleanVectorShoveExpression : ShoveExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack); } } [PushExpression(StackTypes.StringVector, "STRING[].SHOVE", StackTypes.Integer)] public class StringVectorShoveExpression : ShoveExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return Eval(interpreter.StringVectorStack, interpreter.IntegerStack); } } }