using System.Collections.Generic; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.ProgramSynthesis { /// /// Duplicates the top item on the T stack. Does not pop its argument /// (which, if it did, would negate the effect of the duplication!). /// /// Stacktype [StorableClass] public abstract class DuplicateExpression : StatelessExpression { protected DuplicateExpression() { } [StorableConstructor] protected DuplicateExpression(bool deserializing) : base(deserializing) { } protected void Eval(IPushStack stack) { stack.Push(stack.Top); } } [StorableClass] [PushExpression(StackTypes.Integer, "INTEGER.DUP", "Duplicates the top item on the INTEGER stack.")] public class IntegerDuplicateExpression : DuplicateExpression { public IntegerDuplicateExpression() { } [StorableConstructor] protected IntegerDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerStack); } } [StorableClass] [PushExpression(StackTypes.Float, "FLOAT.DUP", "Duplicates the top item on the FLOAT stack.")] public class FloatDuplicateExpression : DuplicateExpression { public FloatDuplicateExpression() { } [StorableConstructor] protected FloatDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.FloatStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatStack); } } [StorableClass] [PushExpression(StackTypes.Boolean, "BOOLEAN.DUP", "Duplicates the top item on the BOOLEAN stack.")] public class BooleanDuplicateExpression : DuplicateExpression { public BooleanDuplicateExpression() { } [StorableConstructor] protected BooleanDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.BooleanStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanStack); } } [StorableClass] [PushExpression(StackTypes.Name, "NAME.DUP", "Duplicates the top item on the NAME stack.")] public class NameDuplicateExpression : DuplicateExpression { public NameDuplicateExpression() { } [StorableConstructor] protected NameDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.NameStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.NameStack); } } [StorableClass] [PushExpression(StackTypes.Exec, "EXEC.DUP", "Duplicates the top item on the EXEC stack.", requiredBlockCount: 1)] public class ExecDuplicateExpression : DuplicateExpression { public ExecDuplicateExpression() { } [StorableConstructor] protected ExecDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.ExecStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.ExecStack); } } [StorableClass] [PushExpression(StackTypes.Code, "CODE.DUP", "Duplicates the top item on the CODE stack.")] public class CodeDuplicateExpression : DuplicateExpression { public CodeDuplicateExpression() { } [StorableConstructor] protected CodeDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.CodeStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CodeStack); } } [StorableClass] [PushExpression(StackTypes.Char, "CHAR.DUP", "Duplicates the top item on the CHAR stack.")] public class CharDuplicateExpression : DuplicateExpression { public CharDuplicateExpression() { } [StorableConstructor] protected CharDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.CharStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CharStack); } } [StorableClass] [PushExpression(StackTypes.String, "STRING.DUP", "Duplicates the top item on the STRING stack.")] public class StringDuplicateExpression : DuplicateExpression { public StringDuplicateExpression() { } [StorableConstructor] protected StringDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.StringStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringStack); } } [StorableClass] [PushExpression(StackTypes.IntegerVector, "INTEGER[].DUP", "Duplicates the top item on the INTEGER[] stack.")] public class IntegerVectorDuplicateExpression : DuplicateExpression> { public IntegerVectorDuplicateExpression() { } [StorableConstructor] protected IntegerVectorDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerVectorStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerVectorStack); } } [StorableClass] [PushExpression(StackTypes.FloatVector, "FLOAT[].DUP", "Duplicates the top item on the FLOAT[] stack.")] public class FloatVectorDuplicateExpression : DuplicateExpression> { public FloatVectorDuplicateExpression() { } [StorableConstructor] protected FloatVectorDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.FloatVectorStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatVectorStack); } } [StorableClass] [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].DUP", "Duplicates the top item on the BOOLEAN[] stack.")] public class BooleanVectorDuplicateExpression : DuplicateExpression> { public BooleanVectorDuplicateExpression() { } [StorableConstructor] protected BooleanVectorDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.BooleanVectorStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanVectorStack); } } [StorableClass] [PushExpression(StackTypes.StringVector, "STRING[].DUP", "Duplicates the top item on the STRING[] stack.")] public class StringVectorDuplicateExpression : DuplicateExpression> { public StringVectorDuplicateExpression() { } [StorableConstructor] protected StringVectorDuplicateExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.StringVectorStack.IsEmpty; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack); } } }