using System.Collections.Generic; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.ProgramSynthesis { /// /// Pushes the stack depth onto the INTEGER stack (thereby increasing it!). /// /// Stacktype [StorableClass] public abstract class StackdepthExpression : StatelessExpression { protected StackdepthExpression() { } [StorableConstructor] protected StackdepthExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return false; } protected void Eval(IPushStack stack, IPushStack integerStack, bool incremental = false) { var count = stack.Count; if (incremental) count += 1; integerStack.Push(count); } } [StorableClass] [PushExpression( StackTypes.Integer, "INTEGER.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.")] public class IntegerStackdepthExpression : StackdepthExpression { public IntegerStackdepthExpression() { } [StorableConstructor] protected IntegerStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerStack, interpreter.IntegerStack, true); } } [StorableClass] [PushExpression( StackTypes.Float, "FLOAT.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class FloatStackdepthExpression : StackdepthExpression { public FloatStackdepthExpression() { } [StorableConstructor] protected FloatStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.Boolean, "BOOLEAN.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class BooleanStackdepthExpression : StackdepthExpression { public BooleanStackdepthExpression() { } [StorableConstructor] protected BooleanStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.Name, "NAME.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class NameStackdepthExpression : StackdepthExpression { public NameStackdepthExpression() { } [StorableConstructor] protected NameStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.NameStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.Exec, "EXEC.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class ExecStackdepthExpression : StackdepthExpression { public ExecStackdepthExpression() { } [StorableConstructor] protected ExecStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.ExecStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.Code, "CODE.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class CodeStackdepthExpression : StackdepthExpression { public CodeStackdepthExpression() { } [StorableConstructor] protected CodeStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CodeStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.Char, "CHAR.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class CharStackdepthExpression : StackdepthExpression { public CharStackdepthExpression() { } [StorableConstructor] protected CharStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CharStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.String, "STRING.STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class StringStackdepthExpression : StackdepthExpression { public StringStackdepthExpression() { } [StorableConstructor] protected StringStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.IntegerVector, "INTEGER[].STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class IntegerVectorStackdepthExpression : StackdepthExpression> { public IntegerVectorStackdepthExpression() { } [StorableConstructor] protected IntegerVectorStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.FloatVector, "FLOAT[].STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class FloatVectorStackdepthExpression : StackdepthExpression> { public FloatVectorStackdepthExpression() { } [StorableConstructor] protected FloatVectorStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatVectorStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.BooleanVector, "BOOLEAN[].STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class BooleanVectorStackdepthExpression : StackdepthExpression> { public BooleanVectorStackdepthExpression() { } [StorableConstructor] protected BooleanVectorStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack); } } [StorableClass] [PushExpression( StackTypes.StringVector, "STRING[].STACKDEPTH", "Pushes the stack depth onto the INTEGER stack.", StackTypes.Integer)] public class StringVectorStackdepthExpression : StackdepthExpression> { public StringVectorStackdepthExpression() { } [StorableConstructor] protected StringVectorStackdepthExpression(bool deserializing) : base(deserializing) { } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack, interpreter.IntegerStack); } } }