Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File size: 2.7 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
5
6  using Interpreter;
7  using Stack;
8
9  /// <summary>
10  ///     Swaps the top two values.
11  /// </summary>
12  /// <typeparam name="T">Stacktype</typeparam>
13  public abstract class SwapExpression<T> : StatelessExpression {
14    public bool Eval(IPushStack<T> stack) {
15      if (stack.Count < 2)
16        return false;
17
18      stack.Swap(2);
19      return true;
20    }
21  }
22
23  [PushExpression(StackTypes.Integer, "INTEGER.SWAP")]
24  public class IntegerSwapExpression : SwapExpression<long> {
25    public override bool Eval(IInternalPushInterpreter interpreter) {
26      return Eval(interpreter.IntegerStack);
27    }
28  }
29
30  [PushExpression(StackTypes.Float, "FLOAT.SWAP")]
31  public class FloatSwapExpression : SwapExpression<double> {
32    public override bool Eval(IInternalPushInterpreter interpreter) {
33      return Eval(interpreter.FloatStack);
34    }
35  }
36
37  [PushExpression(StackTypes.Boolean, "BOOLEAN.SWAP")]
38  public class BooleanSwapExpression : SwapExpression<bool> {
39    public override bool Eval(IInternalPushInterpreter interpreter) {
40      return Eval(interpreter.BooleanStack);
41    }
42  }
43
44  [PushExpression(StackTypes.Name, "NAME.SWAP")]
45  public class NameSwapExpression : SwapExpression<string> {
46    public override bool Eval(IInternalPushInterpreter interpreter) {
47      return Eval(interpreter.NameStack);
48    }
49  }
50
51  [PushExpression(StackTypes.Exec, "EXEC.SWAP")]
52  public class ExecSwapExpression : SwapExpression<Expression> {
53    public override bool Eval(IInternalPushInterpreter interpreter) {
54      return Eval(interpreter.ExecStack);
55    }
56  }
57
58  [PushExpression(StackTypes.Code, "CODE.SWAP")]
59  public class CodeSwapExpression : SwapExpression<Expression> {
60    public override bool Eval(IInternalPushInterpreter interpreter) {
61      return Eval(interpreter.CodeStack);
62    }
63  }
64
65  [PushExpression(StackTypes.Char, "CHAR.SWAP")]
66  public class CharSwapExpression : SwapExpression<char> {
67    public override bool Eval(IInternalPushInterpreter interpreter) {
68      return Eval(interpreter.CharStack);
69    }
70  }
71
72  [PushExpression(StackTypes.String, "STRING.SWAP")]
73  public class StringSwapExpression : SwapExpression<string> {
74    public override bool Eval(IInternalPushInterpreter interpreter) {
75      return Eval(interpreter.StringStack);
76    }
77  }
78
79  [PushExpression(StackTypes.IntegerVector, "INTEGER[].SWAP")]
80  public class IntegerVectorSwapExpression : SwapExpression<List<long>> {
81    public override bool Eval(IInternalPushInterpreter interpreter) {
82      return Eval(interpreter.IntegerVectorStack);
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.