Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 PushGP HL Integration, Views, Parameters

File size: 2.2 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 void Eval(IStack<T> stack, IStack<bool> booleanStack) {
12      if (stack.Count < 2) return;
13
14      var items = stack.Pop(2);
15
16      booleanStack.Push(items[0].Equals(items[1]));
17    }
18  }
19
20  [PushExpression(StackType.Integer, "INTEGER.=")]
21  public class IntegerEqualsExpression : EqualsExpression<long> {
22    public override void Eval(IPushGpInterpreter interpreter) {
23      this.Eval(interpreter.IntegerStack, interpreter.BooleanStack);
24    }
25  }
26
27  [PushExpression(StackType.Float, "FLOAT.=")]
28  public class FloatEqualsExpression : EqualsExpression<double> {
29    public override void Eval(IPushGpInterpreter interpreter) {
30      this.Eval(interpreter.FloatStack, interpreter.BooleanStack);
31    }
32  }
33
34  [PushExpression(StackType.Boolean, "BOOLEAN.=")]
35  public class BooleanEqualsExpression : EqualsExpression<bool> {
36    public override void Eval(IPushGpInterpreter interpreter) {
37      this.Eval(interpreter.BooleanStack, interpreter.BooleanStack);
38    }
39  }
40
41  [PushExpression(StackType.Name, "NAME.=")]
42  public class NameEqualsExpression : EqualsExpression<string> {
43    public override void Eval(IPushGpInterpreter interpreter) {
44      this.Eval(interpreter.NameStack, interpreter.BooleanStack);
45    }
46  }
47
48  [PushExpression(StackType.Exec, "EXEC.=")]
49  public class ExecEqualsExpression : EqualsExpression<Expression> {
50    public override void Eval(IPushGpInterpreter interpreter) {
51      this.Eval(interpreter.ExecStack, interpreter.BooleanStack);
52    }
53  }
54
55  [PushExpression(StackType.Code, "CODE.=")]
56  public class CodeEqualsExpression : EqualsExpression<Expression> {
57    public override void Eval(IPushGpInterpreter interpreter) {
58      this.Eval(interpreter.CodeStack, interpreter.BooleanStack);
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.