1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
5 |
|
---|
6 | using Interpreter;
|
---|
7 | using Stack;
|
---|
8 |
|
---|
9 | /// <summary>
|
---|
10 | /// Empties the given stack.
|
---|
11 | /// </summary>
|
---|
12 | /// <typeparam name="T">Stacktype</typeparam>
|
---|
13 | public abstract class FlushExpression<T> : StatelessExpression {
|
---|
14 | public bool Eval(IPushStack<T> stack) {
|
---|
15 | stack.Clear();
|
---|
16 | return true;
|
---|
17 | }
|
---|
18 | }
|
---|
19 |
|
---|
20 | [PushExpression(StackTypes.Integer, "INTEGER.FLUSH")]
|
---|
21 | public class IntegerFlushExpression : FlushExpression<long> {
|
---|
22 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
23 | return Eval(interpreter.IntegerStack);
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | [PushExpression(StackTypes.Float, "FLOAT.FLUSH")]
|
---|
28 | public class FloatFlushExpression : FlushExpression<double> {
|
---|
29 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
30 | return Eval(interpreter.FloatStack);
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | [PushExpression(StackTypes.Boolean, "BOOLEAN.FLUSH")]
|
---|
35 | public class BooleanFlushExpression : FlushExpression<bool> {
|
---|
36 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
37 | return Eval(interpreter.BooleanStack);
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | [PushExpression(StackTypes.Name, "NAME.FLUSH")]
|
---|
42 | public class NameFlushExpression : FlushExpression<string> {
|
---|
43 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
44 | return Eval(interpreter.NameStack);
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | [PushExpression(StackTypes.Exec, "EXEC.FLUSH")]
|
---|
49 | public class ExecFlushExpression : FlushExpression<Expression> {
|
---|
50 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
51 | return Eval(interpreter.ExecStack);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | [PushExpression(StackTypes.Code, "CODE.FLUSH")]
|
---|
56 | public class CodeFlushExpression : FlushExpression<Expression> {
|
---|
57 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
58 | return Eval(interpreter.CodeStack);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | [PushExpression(StackTypes.Char, "CHAR.FLUSH")]
|
---|
63 | public class CharFlushExpression : FlushExpression<char> {
|
---|
64 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
65 | return Eval(interpreter.CharStack);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | [PushExpression(StackTypes.String, "STRING.FLUSH")]
|
---|
70 | public class StringFlushExpression : FlushExpression<string> {
|
---|
71 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
72 | return Eval(interpreter.StringStack);
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | [PushExpression(StackTypes.IntegerVector, "INTEGER[].FLUSH")]
|
---|
77 | public class IntegerVectorFlushExpression : FlushExpression<List<long>> {
|
---|
78 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
79 | return Eval(interpreter.IntegerVectorStack);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | } |
---|