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 | /// Empties the given stack.
|
---|
9 | /// </summary>
|
---|
10 | /// <typeparam name="T">Stacktype</typeparam>
|
---|
11 | public abstract class FlushExpression<T> : StatelessExpression {
|
---|
12 | public bool Eval(IStack<T> stack) {
|
---|
13 | stack.Clear();
|
---|
14 | return true;
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | [PushExpression(StackType.Integer, "INTEGER.FLUSH")]
|
---|
19 | public class IntegerFlushExpression : FlushExpression<long> {
|
---|
20 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
21 | return Eval(interpreter.IntegerStack);
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | [PushExpression(StackType.Float, "FLOAT.FLUSH")]
|
---|
26 | public class FloatFlushExpression : FlushExpression<double> {
|
---|
27 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
28 | return Eval(interpreter.FloatStack);
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | [PushExpression(StackType.Boolean, "BOOLEAN.FLUSH")]
|
---|
33 | public class BooleanFlushExpression : FlushExpression<bool> {
|
---|
34 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
35 | return Eval(interpreter.BooleanStack);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | [PushExpression(StackType.Name, "NAME.FLUSH")]
|
---|
40 | public class NameFlushExpression : FlushExpression<string> {
|
---|
41 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
42 | return Eval(interpreter.NameStack);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | [PushExpression(StackType.Exec, "EXEC.FLUSH")]
|
---|
47 | public class ExecFlushExpression : FlushExpression<Expression> {
|
---|
48 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
49 | return Eval(interpreter.ExecStack);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | [PushExpression(StackType.Code, "CODE.FLUSH")]
|
---|
54 | public class CodeFlushExpression : FlushExpression<Expression> {
|
---|
55 | public override bool Eval(IPushInterpreter interpreter) {
|
---|
56 | return Eval(interpreter.CodeStack);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | } |
---|