Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/SwapExpressions.cs @ 14727

Last change on this file since 14727 was 14727, checked in by pkimmesw, 8 years ago

#2665 PushGP HL Integration, Views, Parameters

File size: 1.8 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 void Eval(IStack<T> stack) {
13      if (stack.Count < 2)
14        return;
15
16      stack.Swap(2);
17    }
18  }
19
20  [PushExpression(StackType.Integer, "INTEGER.SWAP")]
21  public class IntegerSwapExpression : SwapExpression<long> {
22    public override void Eval(IPushGpInterpreter interpreter) {
23      Eval(interpreter.IntegerStack);
24    }
25  }
26
27  [PushExpression(StackType.Float, "FLOAT.SWAP")]
28  public class FloatSwapExpression : SwapExpression<double> {
29    public override void Eval(IPushGpInterpreter interpreter) {
30      Eval(interpreter.FloatStack);
31    }
32  }
33
34  [PushExpression(StackType.Boolean, "BOOLEAN.SWAP")]
35  public class BooleanSwapExpression : SwapExpression<bool> {
36    public override void Eval(IPushGpInterpreter interpreter) {
37      Eval(interpreter.BooleanStack);
38    }
39  }
40
41  [PushExpression(StackType.Name, "NAME.SWAP")]
42  public class NameSwapExpression : SwapExpression<string> {
43    public override void Eval(IPushGpInterpreter interpreter) {
44      Eval(interpreter.NameStack);
45    }
46  }
47
48  [PushExpression(StackType.Exec, "EXEC.SWAP")]
49  public class ExecSwapExpression : SwapExpression<Expression> {
50    public override void Eval(IPushGpInterpreter interpreter) {
51      Eval(interpreter.ExecStack);
52    }
53  }
54
55  [PushExpression(StackType.Code, "CODE.SWAP")]
56  public class CodeSwapExpression : SwapExpression<Expression> {
57    public override void Eval(IPushGpInterpreter interpreter) {
58      Eval(interpreter.CodeStack);
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.