1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
3 |
|
---|
4 | using Interpreter;
|
---|
5 | using Stack;
|
---|
6 |
|
---|
7 | /// <summary>
|
---|
8 | /// Pushes the stack depth onto the INTEGER stack (thereby increasing it!).
|
---|
9 | /// </summary>
|
---|
10 | /// <typeparam name="T">Stacktype</typeparam>
|
---|
11 | public abstract class StackdepthExpression<T> : StatelessExpression {
|
---|
12 | public bool Eval(IStack<T> stack, IStack<long> integerStack, bool incremental = false) {
|
---|
13 | var count = stack.Count;
|
---|
14 |
|
---|
15 | if (incremental) count += 1;
|
---|
16 |
|
---|
17 | integerStack.Push(count);
|
---|
18 | return true;
|
---|
19 | }
|
---|
20 | }
|
---|
21 |
|
---|
22 | [PushExpression(StackType.Integer, "INTEGER.STACKDEPTH")]
|
---|
23 | public class IntegerStackdepthExpression : StackdepthExpression<long> {
|
---|
24 |
|
---|
25 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
26 | return Eval(interpreter.IntegerStack, interpreter.IntegerStack, true);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | [PushExpression(StackType.Float, "FLOAT.STACKDEPTH")]
|
---|
31 | public class FloatStackdepthExpression : StackdepthExpression<double> {
|
---|
32 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
33 | return Eval(interpreter.FloatStack, interpreter.IntegerStack);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | [PushExpression(StackType.Boolean, "BOOLEAN.STACKDEPTH")]
|
---|
38 | public class BooleanStackdepthExpression : StackdepthExpression<bool> {
|
---|
39 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
40 | return Eval(interpreter.BooleanStack, interpreter.IntegerStack);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | [PushExpression(StackType.Name, "NAME.STACKDEPTH")]
|
---|
45 | public class NameStackdepthExpression : StackdepthExpression<string> {
|
---|
46 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
47 | return Eval(interpreter.NameStack, interpreter.IntegerStack);
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | [PushExpression(StackType.Exec, "EXEC.STACKDEPTH")]
|
---|
52 | public class ExecStackdepthExpression : StackdepthExpression<Expression> {
|
---|
53 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
54 | return Eval(interpreter.ExecStack, interpreter.IntegerStack);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | [PushExpression(StackType.Code, "CODE.STACKDEPTH")]
|
---|
59 | public class CodeStackdepthExpression : StackdepthExpression<Expression> {
|
---|
60 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
61 | return Eval(interpreter.CodeStack, interpreter.IntegerStack);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | } |
---|