source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EmptyExpresssions.cs @ 14777

Last change on this file since 14777 was 14777, checked in by pkimmesw, 3 years ago

#2665 simplifier, push solution results view, performance improvements, small bug fixes, ui fixes

File size: 2.5 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
3  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
4
5  using Stack;
6
7  /// <summary>
8  /// Tells whether that stack is empty.
9  /// </summary>
10  public abstract class EmptyExpresssions<T> : StatelessExpression {
11    public bool Eval(IStack<T> stack, IStack<bool> booleanStack) {
12      booleanStack.Push(stack.IsEmpty);
13
14      return true;
15    }
16  }
17
18  [PushExpression(StackTypes.Exec, "EXEC.EMPTY", StackTypes.Boolean)]
19  public class ExecEmptyExpression : EmptyExpresssions<Expression> {
20    public override bool Eval(IPushInterpreter interpreter) {
21      return Eval(interpreter.ExecStack, interpreter.BooleanStack);
22    }
23  }
24
25  [PushExpression(StackTypes.Code, "CODE.EMPTY", StackTypes.Boolean)]
26  public class CodeEmptyExpression : EmptyExpresssions<Expression> {
27    public override bool Eval(IPushInterpreter interpreter) {
28      return Eval(interpreter.CodeStack, interpreter.BooleanStack);
29    }
30  }
31
32  [PushExpression(StackTypes.Integer, "INTEGER.EMPTY", StackTypes.Boolean)]
33  public class IntegerEmptyExpression : EmptyExpresssions<long> {
34    public override bool Eval(IPushInterpreter interpreter) {
35      return Eval(interpreter.IntegerStack, interpreter.BooleanStack);
36    }
37  }
38
39  [PushExpression(StackTypes.Float, "FLOAT.EMPTY", StackTypes.Boolean)]
40  public class FloatEmptyExpression : EmptyExpresssions<double> {
41    public override bool Eval(IPushInterpreter interpreter) {
42      return Eval(interpreter.FloatStack, interpreter.BooleanStack);
43    }
44  }
45
46  [PushExpression(StackTypes.Boolean, "BOOLEAN.EMPTY", StackTypes.Boolean)]
47  public class BooleanEmptyExpression : EmptyExpresssions<bool> {
48    public override bool Eval(IPushInterpreter interpreter) {
49      return Eval(interpreter.BooleanStack, interpreter.BooleanStack);
50    }
51  }
52
53  [PushExpression(StackTypes.Char, "CHAR.EMPTY", StackTypes.Boolean)]
54  public class CharEmptyExpression : EmptyExpresssions<char> {
55    public override bool Eval(IPushInterpreter interpreter) {
56      return Eval(interpreter.CharStack, interpreter.BooleanStack);
57    }
58  }
59
60  [PushExpression(StackTypes.String, "STRING.EMPTY", StackTypes.Boolean)]
61  public class StringEmptyExpression : EmptyExpresssions<string> {
62    public override bool Eval(IPushInterpreter interpreter) {
63      return Eval(interpreter.StringStack, interpreter.BooleanStack);
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.