Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/SwapExpressions.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: 1.9 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
3
4  using Interpreter;
5  using Stack;
6
7  /// <summary>
8  ///     Swaps the top two values.
9  /// </summary>
10  /// <typeparam name="T">Stacktype</typeparam>
11  public abstract class SwapExpression<T> : StatelessExpression {
12    public bool Eval(IStack<T> stack) {
13      if (stack.Count < 2)
14        return false;
15
16      stack.Swap(2);
17      return true;
18    }
19  }
20
21  [PushExpression(StackType.Integer, "INTEGER.SWAP")]
22  public class IntegerSwapExpression : SwapExpression<long> {
23    public override bool Eval(IPushInterpreter interpreter) {
24      return Eval(interpreter.IntegerStack);
25    }
26  }
27
28  [PushExpression(StackType.Float, "FLOAT.SWAP")]
29  public class FloatSwapExpression : SwapExpression<double> {
30    public override bool Eval(IPushInterpreter interpreter) {
31      return Eval(interpreter.FloatStack);
32    }
33  }
34
35  [PushExpression(StackType.Boolean, "BOOLEAN.SWAP")]
36  public class BooleanSwapExpression : SwapExpression<bool> {
37    public override bool Eval(IPushInterpreter interpreter) {
38      return Eval(interpreter.BooleanStack);
39    }
40  }
41
42  [PushExpression(StackType.Name, "NAME.SWAP")]
43  public class NameSwapExpression : SwapExpression<string> {
44    public override bool Eval(IPushInterpreter interpreter) {
45      return Eval(interpreter.NameStack);
46    }
47  }
48
49  [PushExpression(StackType.Exec, "EXEC.SWAP")]
50  public class ExecSwapExpression : SwapExpression<Expression> {
51    public override bool Eval(IPushInterpreter interpreter) {
52      return Eval(interpreter.ExecStack);
53    }
54  }
55
56  [PushExpression(StackType.Code, "CODE.SWAP")]
57  public class CodeSwapExpression : SwapExpression<Expression> {
58    public override bool Eval(IPushInterpreter interpreter) {
59      return Eval(interpreter.CodeStack);
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.