namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using System.Collections.Generic; using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; /// /// Duplicates the top item on the INTEGER stack. Does not pop its argument /// (which, if it did, would negate the effect of the duplication!). /// /// Stacktype public abstract class DuplicateExpression : StatelessExpression { protected bool Eval(IPushStack stack) { if (stack.Count == 0) return false; stack.Push(stack.Top); return true; } } [PushExpression(StackTypes.Integer, "INTEGER.DUP")] public class IntegerDuplicateExpression : DuplicateExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.IntegerStack); } } [PushExpression(StackTypes.Float, "FLOAT.DUP")] public class FloatDuplicateExpression : DuplicateExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.FloatStack); } } [PushExpression(StackTypes.Boolean, "BOOLEAN.DUP")] public class BooleanDuplicateExpression : DuplicateExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.BooleanStack); } } [PushExpression(StackTypes.Name, "NAME.DUP")] public class NameDuplicateExpression : DuplicateExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.NameStack); } } [PushExpression(StackTypes.Exec, "EXEC.DUP")] public class ExecDuplicateExpression : DuplicateExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.ExecStack); } } [PushExpression(StackTypes.Code, "CODE.DUP")] public class CodeDuplicateExpression : DuplicateExpression { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.CodeStack); } } [PushExpression(StackTypes.IntegerVector, "INTEGER[].DUP")] public class IntegerVectorDuplicateExpression : DuplicateExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.IntegerVectorStack); } } [PushExpression(StackTypes.FloatVector, "FLOAT[].DUP")] public class FloatVectorDuplicateExpression : DuplicateExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.FloatVectorStack); } } [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].DUP")] public class BooleanVectorDuplicateExpression : DuplicateExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.BooleanVectorStack); } } [PushExpression(StackTypes.StringVector, "STRING[].DUP")] public class StringVectorDuplicateExpression : DuplicateExpression> { public override bool Eval(IInternalPushInterpreter interpreter) { return this.Eval(interpreter.StringVectorStack); } } }