namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; using Interpreter; using Stack; /// /// Pushes the stack depth onto the INTEGER stack (thereby increasing it!). /// /// Stacktype public abstract class StackdepthExpression : StatelessExpression { public bool Eval(IStack stack, IStack integerStack, bool incremental = false) { var count = stack.Count; if (incremental) count += 1; integerStack.Push(count); return true; } } [PushExpression(StackType.Integer, "INTEGER.STACKDEPTH")] public class IntegerStackdepthExpression : StackdepthExpression { public override bool Eval(IPushInterpreter interpreter) { return Eval(interpreter.IntegerStack, interpreter.IntegerStack, true); } } [PushExpression(StackType.Float, "FLOAT.STACKDEPTH")] public class FloatStackdepthExpression : StackdepthExpression { public override bool Eval(IPushInterpreter interpreter) { return Eval(interpreter.FloatStack, interpreter.IntegerStack); } } [PushExpression(StackType.Boolean, "BOOLEAN.STACKDEPTH")] public class BooleanStackdepthExpression : StackdepthExpression { public override bool Eval(IPushInterpreter interpreter) { return Eval(interpreter.BooleanStack, interpreter.IntegerStack); } } [PushExpression(StackType.Name, "NAME.STACKDEPTH")] public class NameStackdepthExpression : StackdepthExpression { public override bool Eval(IPushInterpreter interpreter) { return Eval(interpreter.NameStack, interpreter.IntegerStack); } } [PushExpression(StackType.Exec, "EXEC.STACKDEPTH")] public class ExecStackdepthExpression : StackdepthExpression { public override bool Eval(IPushInterpreter interpreter) { return Eval(interpreter.ExecStack, interpreter.IntegerStack); } } [PushExpression(StackType.Code, "CODE.STACKDEPTH")] public class CodeStackdepthExpression : StackdepthExpression { public override bool Eval(IPushInterpreter interpreter) { return Eval(interpreter.CodeStack, interpreter.IntegerStack); } } }