Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PopExpressions.cs @ 15341

Last change on this file since 15341 was 15334, checked in by pkimmesw, 7 years ago

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

File size: 7.4 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
5  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
6
7  using Interpreter;
8  using Stack;
9
10  [StorableClass]
11  public abstract class PopExpression<T> : StatelessExpression {
12    protected PopExpression() { }
13    [StorableConstructor]
14    protected PopExpression(bool deserializing) : base(deserializing) { }
15
16    protected void Eval(IPushStack<T> stack) {
17      stack.Pop();
18    }
19  }
20
21  [StorableClass]
22  [PushExpression(StackTypes.Integer, "INTEGER.POP", "Pops the top INTEGER item.")]
23  public class IntegerPopExpression : PopExpression<long> {
24    public IntegerPopExpression() { }
25    [StorableConstructor]
26    protected IntegerPopExpression(bool deserializing) : base(deserializing) { }
27
28    public override bool IsNoop(IInternalPushInterpreter interpreter) {
29      return interpreter.IntegerStack.IsEmpty;
30    }
31
32    public override void Eval(IInternalPushInterpreter interpreter) {
33      Eval(interpreter.IntegerStack);
34    }
35  }
36
37  [StorableClass]
38  [PushExpression(StackTypes.Float, "FLOAT.POP", "Pops the top FLOAT item.")]
39  public class FloatPopExpression : PopExpression<double> {
40    public FloatPopExpression() { }
41    [StorableConstructor]
42    protected FloatPopExpression(bool deserializing) : base(deserializing) { }
43
44    public override bool IsNoop(IInternalPushInterpreter interpreter) {
45      return interpreter.FloatStack.IsEmpty;
46    }
47
48    public override void Eval(IInternalPushInterpreter interpreter) {
49      Eval(interpreter.FloatStack);
50    }
51  }
52
53  [StorableClass]
54  [PushExpression(StackTypes.Boolean, "BOOLEAN.POP", "Pops the top BOOLEAN item.")]
55  public class BooleanPopExpression : PopExpression<bool> {
56    public BooleanPopExpression() { }
57    [StorableConstructor]
58    protected BooleanPopExpression(bool deserializing) : base(deserializing) { }
59
60    public override bool IsNoop(IInternalPushInterpreter interpreter) {
61      return interpreter.BooleanStack.IsEmpty;
62    }
63
64    public override void Eval(IInternalPushInterpreter interpreter) {
65      Eval(interpreter.BooleanStack);
66    }
67  }
68
69  [StorableClass]
70  [PushExpression(StackTypes.Name, "NAME.POP", "Pops the top NAME item.")]
71  public class NamePopExpression : PopExpression<string> {
72    public NamePopExpression() { }
73    [StorableConstructor]
74    protected NamePopExpression(bool deserializing) : base(deserializing) { }
75
76    public override bool IsNoop(IInternalPushInterpreter interpreter) {
77      return interpreter.NameStack.IsEmpty;
78    }
79
80    public override void Eval(IInternalPushInterpreter interpreter) {
81      Eval(interpreter.NameStack);
82    }
83  }
84
85  [StorableClass]
86  [PushExpression(StackTypes.Exec, "EXEC.POP", "Pops the top EXEC item.", requiredBlockCount: 1)]
87  public class ExecPopExpression : PopExpression<Expression> {
88    public ExecPopExpression() { }
89    [StorableConstructor]
90    protected ExecPopExpression(bool deserializing) : base(deserializing) { }
91
92    public override bool IsNoop(IInternalPushInterpreter interpreter) {
93      return interpreter.ExecStack.IsEmpty;
94    }
95
96    public override void Eval(IInternalPushInterpreter interpreter) {
97      Eval(interpreter.ExecStack);
98    }
99  }
100
101  [StorableClass]
102  [PushExpression(StackTypes.Code, "CODE.POP", "Pops the top CODE item.")]
103  public class CodePopExpression : PopExpression<Expression> {
104    public CodePopExpression() { }
105    [StorableConstructor]
106    protected CodePopExpression(bool deserializing) : base(deserializing) { }
107
108    public override bool IsNoop(IInternalPushInterpreter interpreter) {
109      return interpreter.CodeStack.IsEmpty;
110    }
111
112    public override void Eval(IInternalPushInterpreter interpreter) {
113      Eval(interpreter.CodeStack);
114    }
115  }
116
117  [StorableClass]
118  [PushExpression(StackTypes.Char, "CHAR.POP", "Pops the top CHAR item.")]
119  public class CharPopExpression : PopExpression<char> {
120    public CharPopExpression() { }
121    [StorableConstructor]
122    protected CharPopExpression(bool deserializing) : base(deserializing) { }
123
124    public override bool IsNoop(IInternalPushInterpreter interpreter) {
125      return interpreter.CharStack.IsEmpty;
126    }
127
128    public override void Eval(IInternalPushInterpreter interpreter) {
129      Eval(interpreter.CharStack);
130    }
131  }
132
133  [StorableClass]
134  [PushExpression(StackTypes.String, "STRING.POP", "Pops the top STRING item.")]
135  public class StringPopExpression : PopExpression<string> {
136    public StringPopExpression() { }
137    [StorableConstructor]
138    protected StringPopExpression(bool deserializing) : base(deserializing) { }
139
140    public override bool IsNoop(IInternalPushInterpreter interpreter) {
141      return interpreter.StringStack.IsEmpty;
142    }
143
144    public override void Eval(IInternalPushInterpreter interpreter) {
145      Eval(interpreter.StringStack);
146    }
147  }
148
149  [StorableClass]
150  [PushExpression(StackTypes.IntegerVector, "INTEGER[].POP", "Pops the top INTEGER[] item.")]
151  public class IntegerVectorPopExpression : PopExpression<IReadOnlyList<long>> {
152    public IntegerVectorPopExpression() { }
153    [StorableConstructor]
154    protected IntegerVectorPopExpression(bool deserializing) : base(deserializing) { }
155
156    public override bool IsNoop(IInternalPushInterpreter interpreter) {
157      return interpreter.IntegerVectorStack.IsEmpty;
158    }
159
160    public override void Eval(IInternalPushInterpreter interpreter) {
161      Eval(interpreter.IntegerVectorStack);
162    }
163  }
164
165  [StorableClass]
166  [PushExpression(StackTypes.FloatVector, "FLOAT[].POP", "Pops the top FLOAT[] item.")]
167  public class FloatVectorPopExpression : PopExpression<IReadOnlyList<double>> {
168    public FloatVectorPopExpression() { }
169    [StorableConstructor]
170    protected FloatVectorPopExpression(bool deserializing) : base(deserializing) { }
171
172    public override bool IsNoop(IInternalPushInterpreter interpreter) {
173      return interpreter.FloatVectorStack.IsEmpty;
174    }
175
176    public override void Eval(IInternalPushInterpreter interpreter) {
177      Eval(interpreter.FloatVectorStack);
178    }
179  }
180
181  [StorableClass]
182  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].POP", "Pops the top BOOLEAN[] item.")]
183  public class BooleanVectorPopExpression : PopExpression<IReadOnlyList<bool>> {
184    public BooleanVectorPopExpression() { }
185    [StorableConstructor]
186    protected BooleanVectorPopExpression(bool deserializing) : base(deserializing) { }
187
188    public override bool IsNoop(IInternalPushInterpreter interpreter) {
189      return interpreter.BooleanVectorStack.IsEmpty;
190    }
191
192    public override void Eval(IInternalPushInterpreter interpreter) {
193      Eval(interpreter.BooleanVectorStack);
194    }
195  }
196
197  [StorableClass]
198  [PushExpression(StackTypes.StringVector, "STRING[].POP", "Pops the top STRING[] item.")]
199  public class StringVectorPopExpression : PopExpression<IReadOnlyList<string>> {
200    public StringVectorPopExpression() { }
201    [StorableConstructor]
202    protected StringVectorPopExpression(bool deserializing) : base(deserializing) { }
203
204    public override bool IsNoop(IInternalPushInterpreter interpreter) {
205      return interpreter.StringVectorStack.IsEmpty;
206    }
207
208    public override void Eval(IInternalPushInterpreter interpreter) {
209      Eval(interpreter.StringVectorStack);
210    }
211  }
212}
Note: See TracBrowser for help on using the repository browser.