Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 simplifier, push solution results view, performance improvements, small bug fixes, ui fixes

File size: 2.4 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(StackTypes.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(StackTypes.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(StackTypes.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(StackTypes.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(StackTypes.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(StackTypes.Code, "CODE.SWAP")]
57  public class CodeSwapExpression : SwapExpression<Expression> {
58    public override bool Eval(IPushInterpreter interpreter) {
59      return Eval(interpreter.CodeStack);
60    }
61  }
62
63  [PushExpression(StackTypes.Char, "CHAR.SWAP")]
64  public class CharSwapExpression : SwapExpression<char> {
65    public override bool Eval(IPushInterpreter interpreter) {
66      return Eval(interpreter.CharStack);
67    }
68  }
69
70  [PushExpression(StackTypes.String, "STRING.SWAP")]
71  public class StringSwapExpression : SwapExpression<string> {
72    public override bool Eval(IPushInterpreter interpreter) {
73      return Eval(interpreter.StringStack);
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.