Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EqualsExpressions.cs @ 14744

Last change on this file since 14744 was 14744, checked in by pkimmesw, 7 years ago

#2665 Renamings due to typos, ManagedPool tests, Skip Noops in Debugger

File size: 2.3 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
3  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
5
6  /// <summary>
7  ///     Pushes TRUE onto the BOOLEAN stack if the top two items are equal, or FALSE otherwise
8  /// </summary>
9  /// <typeparam name="T">Stacktype</typeparam>
10  public abstract class EqualsExpression<T> : StatelessExpression {
11    public bool Eval(IStack<T> stack, IStack<bool> booleanStack) {
12      if (stack.Count < 2) return false;
13
14      var items = stack.Pop(2);
15
16      booleanStack.Push(items[0].Equals(items[1]));
17
18      return true;
19    }
20  }
21
22  [PushExpression(StackType.Integer, "INTEGER.=")]
23  public class IntegerEqualsExpression : EqualsExpression<long> {
24    public override bool Eval(IPushInterpreter interpreter) {
25      return Eval(interpreter.IntegerStack, interpreter.BooleanStack);
26    }
27  }
28
29  [PushExpression(StackType.Float, "FLOAT.=")]
30  public class FloatEqualsExpression : EqualsExpression<double> {
31    public override bool Eval(IPushInterpreter interpreter) {
32      return Eval(interpreter.FloatStack, interpreter.BooleanStack);
33    }
34  }
35
36  [PushExpression(StackType.Boolean, "BOOLEAN.=")]
37  public class BooleanEqualsExpression : EqualsExpression<bool> {
38    public override bool Eval(IPushInterpreter interpreter) {
39      return Eval(interpreter.BooleanStack, interpreter.BooleanStack);
40    }
41  }
42
43  [PushExpression(StackType.Name, "NAME.=")]
44  public class NameEqualsExpression : EqualsExpression<string> {
45    public override bool Eval(IPushInterpreter interpreter) {
46      return Eval(interpreter.NameStack, interpreter.BooleanStack);
47    }
48  }
49
50  [PushExpression(StackType.Exec, "EXEC.=")]
51  public class ExecEqualsExpression : EqualsExpression<Expression> {
52    public override bool Eval(IPushInterpreter interpreter) {
53      return Eval(interpreter.ExecStack, interpreter.BooleanStack);
54    }
55  }
56
57  [PushExpression(StackType.Code, "CODE.=")]
58  public class CodeEqualsExpression : EqualsExpression<Expression> {
59    public override bool Eval(IPushInterpreter interpreter) {
60      return Eval(interpreter.CodeStack, interpreter.BooleanStack);
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.