Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PopExpressions.cs @ 16724

Last change on this file since 16724 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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