Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 Renamings due to typos, ManagedPool tests, Skip Noops in Debugger

File size: 2.4 KB
RevLine 
[14727]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 {
[14744]12    protected bool Eval(IStack<T> stack) {
13      if (stack.Count == 0) return false;
[14727]14
15      stack.Push(stack.Top);
[14744]16
17      return true;
[14727]18    }
19
[14744]20    protected bool Eval(IStack<Expression> stack) {
21      if (stack.Count == 0) return false;
[14727]22
23      var top = stack.Top;
24
25      stack.Push(top);
[14744]26      return true;
[14727]27    }
28  }
29
30  [PushExpression(StackType.Integer, "INTEGER.DUP")]
31  public class IntegerDuplicateExpression : DuplicateExpression<long> {
[14744]32    public override bool Eval(IPushInterpreter interpreter) {
33      return this.Eval(interpreter.IntegerStack);
[14727]34    }
35  }
36
37  [PushExpression(StackType.Float, "FLOAT.DUP")]
38  public class FloatDuplicateExpression : DuplicateExpression<double> {
[14744]39    public override bool Eval(IPushInterpreter interpreter) {
40      return this.Eval(interpreter.FloatStack);
[14727]41    }
42  }
43
44  [PushExpression(StackType.Boolean, "BOOLEAN.DUP")]
45  public class BooleanDuplicateExpression : DuplicateExpression<bool> {
[14744]46    public override bool Eval(IPushInterpreter interpreter) {
47      return this.Eval(interpreter.BooleanStack);
[14727]48    }
49  }
50
51  [PushExpression(StackType.Name, "NAME.DUP")]
52  public class NameDuplicateExpression : DuplicateExpression<string> {
[14744]53    public override bool Eval(IPushInterpreter interpreter) {
54      return this.Eval(interpreter.NameStack);
[14727]55    }
56  }
57
58  [PushExpression(StackType.Exec, "EXEC.DUP")]
59  public class ExecDuplicateExpression : DuplicateExpression<Expression> {
[14744]60    public override bool Eval(IPushInterpreter interpreter) {
61      return this.Eval(interpreter.ExecStack);
[14727]62    }
63  }
64
65  [PushExpression(StackType.Code, "CODE.DUP")]
66  public class CodeDuplicateExpression : DuplicateExpression<Expression> {
[14744]67    public override bool Eval(IPushInterpreter interpreter) {
68      return this.Eval(interpreter.CodeStack);
[14727]69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.