Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 PushGP HL Integration, Views, Parameters

File size: 2.5 KB
Line 
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  ///     Removes an indexed item from "deep" in the stack and pushes it on top of the stack.
8  ///     The index is taken from the INTEGER stack, and the indexing is done after the index is removed.
9  /// </summary>
10  /// <typeparam name="T">Stacktype</typeparam>
11  public abstract class YankExpression<T> : StatelessExpression {
12    public void Eval(IStack<T> stack, IStack<long> integerStack, int count = 1) {
13      if (integerStack.Count == 0) return;
14
15      var index = integerStack.Top;
16
17      if ((index > stack.Count - count) || (index < 0) || (stack.Count < 2)) return;
18
19      integerStack.Pop();
20      stack.Yank((int)index);
21    }
22  }
23
24  [PushExpression(StackType.Integer, "INTEGER.YANK")]
25  public class IntegerYankExpression : YankExpression<long> {
26    public override void Eval(IPushGpInterpreter interpreter) {
27      this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
28    }
29  }
30
31  [PushExpression(StackType.Float, "FLOAT.YANK")]
32  public class FloatYankExpression : YankExpression<double> {
33    public override void Eval(IPushGpInterpreter interpreter) {
34      this.Eval(interpreter.FloatStack, interpreter.IntegerStack);
35    }
36  }
37
38  [PushExpression(StackType.Boolean, "BOOLEAN.YANK")]
39  public class BooleanYankExpression : YankExpression<bool> {
40    public override void Eval(IPushGpInterpreter interpreter) {
41      this.Eval(interpreter.BooleanStack, interpreter.IntegerStack);
42    }
43  }
44
45  [PushExpression(StackType.Name, "NAME.YANK")]
46  public class NameYankExpression : YankExpression<string> {
47    public override void Eval(IPushGpInterpreter interpreter) {
48      this.Eval(interpreter.NameStack, interpreter.IntegerStack);
49    }
50  }
51
52  [PushExpression(StackType.Exec, "EXEC.YANK")]
53  public class ExecYankExpression : YankExpression<Expression> {
54    public override void Eval(IPushGpInterpreter interpreter) {
55      this.Eval(interpreter.ExecStack, interpreter.IntegerStack);
56    }
57  }
58
59  [PushExpression(StackType.Code, "CODE.YANK")]
60  public class CodeYankExpression : YankExpression<Expression> {
61    public override void Eval(IPushGpInterpreter interpreter) {
62      this.Eval(interpreter.CodeStack, interpreter.IntegerStack);
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.