[14727] | 1 | namespace 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 the logical AND of the top two BOOLEANs.
|
---|
| 8 | /// </summary>
|
---|
| 9 | [PushExpression(StackType.Boolean, "BOOLEAN.AND")]
|
---|
| 10 | public class BooleanAndExpression : PushResultExpression<bool> {
|
---|
[14733] | 11 | public override void Eval(IPushInterpreter interpreter) {
|
---|
[14727] | 12 | this.Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]);
|
---|
| 13 | }
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | /// <summary>
|
---|
| 17 | /// Pushes the logical OR of the top two BOOLEANs.
|
---|
| 18 | /// </summary>
|
---|
| 19 | [PushExpression(StackType.Boolean, "BOOLEAN.OR")]
|
---|
| 20 | public class BooleanOrExpression : PushResultExpression<bool> {
|
---|
[14733] | 21 | public override void Eval(IPushInterpreter interpreter) {
|
---|
[14727] | 22 | this.Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
|
---|
| 23 | }
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | /// <summary>
|
---|
| 27 | /// Pushes the logical NOT of the top BOOLEAN.
|
---|
| 28 | /// </summary>
|
---|
| 29 | [PushExpression(StackType.Boolean, "BOOLEAN.NOT")]
|
---|
| 30 | public class BooleanNotExpression : PushResultExpression<bool> {
|
---|
[14733] | 31 | public override void Eval(IPushInterpreter interpreter) {
|
---|
[14727] | 32 | this.Eval(interpreter.BooleanStack, 1, values => !values[0]);
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | /// <summary>
|
---|
| 37 | /// Pushes FALSE if the top FLOAT is 0.0, or TRUE otherwise.
|
---|
| 38 | /// </summary>
|
---|
| 39 | [PushExpression(StackType.Boolean, "BOOLEAN.FROMFLOAT")]
|
---|
| 40 | public class BooleanFromFloatExpression : StatelessExpression {
|
---|
[14733] | 41 | public override void Eval(IPushInterpreter interpreter) {
|
---|
[14727] | 42 | if (interpreter.FloatStack.Count == 0) return;
|
---|
| 43 |
|
---|
| 44 | var value = interpreter.FloatStack.Pop() != 0.0;
|
---|
| 45 |
|
---|
| 46 | interpreter.BooleanStack.Push(value);
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | /// <summary>
|
---|
| 51 | /// Pushes FALSE if the top INTEGER is 0, or TRUE otherwise.
|
---|
| 52 | /// </summary>
|
---|
| 53 | [PushExpression(StackType.Boolean, "BOOLEAN.FROMINTEGER")]
|
---|
| 54 | public class BooleanFromIntegerExpression : StatelessExpression {
|
---|
[14733] | 55 | public override void Eval(IPushInterpreter interpreter) {
|
---|
[14727] | 56 | if (interpreter.IntegerStack.Count == 0) return;
|
---|
| 57 |
|
---|
| 58 | var value = interpreter.IntegerStack.Pop() != 0;
|
---|
| 59 |
|
---|
| 60 | interpreter.BooleanStack.Push(value);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | } |
---|