Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DuplicateExpressions.cs @ 14733

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

#2665 Storable problem data, Renamings due to typos, Removed GP from class names

File size: 2.3 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
3  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
5
6  /// <summary>
7  ///     Duplicates the top item on the INTEGER stack. Does not pop its argument
8  ///     (which, if it did, would negate the effect of the duplication!).
9  /// </summary>
10  /// <typeparam name="T">Stacktype</typeparam>
11  public abstract class DuplicateExpression<T> : StatelessExpression {
12    protected void Eval(IStack<T> stack) {
13      if (stack.Count == 0) return;
14
15      stack.Push(stack.Top);
16    }
17
18    protected void Eval(IStack<Expression> stack) {
19      if (stack.Count == 0) return;
20
21      var top = stack.Top;
22
23      stack.Push(top);
24    }
25  }
26
27  [PushExpression(StackType.Integer, "INTEGER.DUP")]
28  public class IntegerDuplicateExpression : DuplicateExpression<long> {
29    public override void Eval(IPushInterpreter interpreter) {
30      this.Eval(interpreter.IntegerStack);
31    }
32  }
33
34  [PushExpression(StackType.Float, "FLOAT.DUP")]
35  public class FloatDuplicateExpression : DuplicateExpression<double> {
36    public override void Eval(IPushInterpreter interpreter) {
37      this.Eval(interpreter.FloatStack);
38    }
39  }
40
41  [PushExpression(StackType.Boolean, "BOOLEAN.DUP")]
42  public class BooleanDuplicateExpression : DuplicateExpression<bool> {
43    public override void Eval(IPushInterpreter interpreter) {
44      this.Eval(interpreter.BooleanStack);
45    }
46  }
47
48  [PushExpression(StackType.Name, "NAME.DUP")]
49  public class NameDuplicateExpression : DuplicateExpression<string> {
50    public override void Eval(IPushInterpreter interpreter) {
51      this.Eval(interpreter.NameStack);
52    }
53  }
54
55  [PushExpression(StackType.Exec, "EXEC.DUP")]
56  public class ExecDuplicateExpression : DuplicateExpression<Expression> {
57    public override void Eval(IPushInterpreter interpreter) {
58      this.Eval(interpreter.ExecStack);
59    }
60  }
61
62  [PushExpression(StackType.Code, "CODE.DUP")]
63  public class CodeDuplicateExpression : DuplicateExpression<Expression> {
64    public override void Eval(IPushInterpreter interpreter) {
65      this.Eval(interpreter.CodeStack);
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.