namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using System.Collections.Generic; using System.Linq; using Attributes; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using Interpreter; using Stack; /// /// Pushes TRUE onto the T stack if the top two items are equal, or FALSE otherwise /// /// Stacktype [StorableClass] public abstract class EqualsExpression : StatelessExpression { protected EqualsExpression() { } [StorableConstructor] protected EqualsExpression(bool deserializing) : base(deserializing) { } protected void Eval(IPushStack stack, IPushStack booleanStack) { var first = stack[1]; var second = stack.Top; stack.Remove(2); var equal = first.Equals(second); booleanStack.Push(equal); } protected void Eval(IPushStack> vectorStack, IPushStack booleanStack) { var first = vectorStack[1]; var second = vectorStack[0]; vectorStack.Remove(2); var equal = first.SequenceEqual(second); booleanStack.Push(equal); } } [StorableClass] [PushExpression( StackTypes.Integer, "INTEGER.=", "Pushes TRUE onto the BOOLEAN stack if the top two INTEGER items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class IntegerEqualsExpression : EqualsExpression { public IntegerEqualsExpression() { } [StorableConstructor] protected IntegerEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.Float, "FLOAT.=", "Pushes TRUE onto the BOOLEAN stack if the top two FLOAT items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class FloatEqualsExpression : EqualsExpression { public FloatEqualsExpression() { } [StorableConstructor] protected FloatEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.FloatStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.Boolean, "BOOLEAN.=", "Pushes TRUE onto the BOOLEAN stack if the top two BOOLEAN items are equal, or FALSE otherwise.")] public class BooleanEqualsExpression : EqualsExpression { public BooleanEqualsExpression() { } [StorableConstructor] protected BooleanEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.BooleanStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.Name, "NAME.=", "Pushes TRUE onto the BOOLEAN stack if the top two NAME items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class NameEqualsExpression : EqualsExpression { public NameEqualsExpression() { } [StorableConstructor] protected NameEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.NameStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.NameStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.Exec, "EXEC.=", "Pushes TRUE onto the BOOLEAN stack if the top two EXEC items are equal, or FALSE otherwise.", StackTypes.Boolean, requiredBlockCount: 0)] public class ExecEqualsExpression : EqualsExpression { public ExecEqualsExpression() { } [StorableConstructor] protected ExecEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.ExecStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.ExecStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.Code, "CODE.=", "Pushes TRUE onto the BOOLEAN stack if the top two CODE items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class CodeEqualsExpression : EqualsExpression { public CodeEqualsExpression() { } [StorableConstructor] protected CodeEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.CodeStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CodeStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.Char, "CHAR.=", "Pushes TRUE onto the BOOLEAN stack if the top two CHAR items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class CharEqualsExpression : EqualsExpression { public CharEqualsExpression() { } [StorableConstructor] protected CharEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.CharStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.CharStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.String, "STRING.=", "Pushes TRUE onto the BOOLEAN stack if the top two STRING items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class StringEqualsExpression : EqualsExpression { public StringEqualsExpression() { } [StorableConstructor] protected StringEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.StringStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.IntegerVector, "INTEGER[].=", "Pushes TRUE onto the BOOLEAN stack if the top two INTEGER[] items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class IntegerVectorEqualsExpression : EqualsExpression { public IntegerVectorEqualsExpression() { } [StorableConstructor] protected IntegerVectorEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.IntegerVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.IntegerVectorStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.FloatVector, "FLOAT[].=", "Pushes TRUE onto the BOOLEAN stack if the top two FLOAT[] items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class FloatVectorEqualsExpression : EqualsExpression { public FloatVectorEqualsExpression() { } [StorableConstructor] protected FloatVectorEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.FloatVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.FloatVectorStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.BooleanVector, "BOOLEAN[].=", "Pushes TRUE onto the BOOLEAN stack if the top two BOOLEAN[] items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class BooleanVectorEqualsExpression : EqualsExpression { public BooleanVectorEqualsExpression() { } [StorableConstructor] protected BooleanVectorEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.BooleanVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack); } } [StorableClass] [PushExpression( StackTypes.StringVector, "STRING[].=", "Pushes TRUE onto the BOOLEAN stack if the top two STRING[] items are equal, or FALSE otherwise.", StackTypes.Boolean)] public class StringVectorEqualsExpression : EqualsExpression { public StringVectorEqualsExpression() { } [StorableConstructor] protected StringVectorEqualsExpression(bool deserializing) : base(deserializing) { } public override bool IsNoop(IInternalPushInterpreter interpreter) { return interpreter.StringVectorStack.Count < 2; } public override void Eval(IInternalPushInterpreter interpreter) { Eval(interpreter.StringVectorStack, interpreter.BooleanStack); } } }