Last change
on this file since 14328 was
14328,
checked in by pkimmesw, 8 years ago
|
#2665 Set .NET version to 4.5, C# version to 5.0, Added expression templates and factory
|
File size:
1.6 KB
|
Line | |
---|
1 | using HeuristicLab.Algorithms.PushGP.Interpreter;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Algorithms.PushGP.Expressions.Exec
|
---|
4 | {
|
---|
5 | public class ExecDoRangeExpression : Expression
|
---|
6 | {
|
---|
7 | public override bool IsCodeOp { get { return false; } }
|
---|
8 |
|
---|
9 | public override void Eval(IInterpreter interpreter)
|
---|
10 | {
|
---|
11 | // not enough arguments on stack
|
---|
12 | if (interpreter.IntegerStack.Count < 2 ||
|
---|
13 | interpreter.ExecStack.Count == 0)
|
---|
14 | return;
|
---|
15 |
|
---|
16 | var destinationIndex = interpreter.IntegerStack.Pop();
|
---|
17 | var currentIndex = interpreter.IntegerStack.Pop();
|
---|
18 | var loopBody = interpreter.ExecStack.Pop();
|
---|
19 |
|
---|
20 | if (destinationIndex == currentIndex)
|
---|
21 | {
|
---|
22 | interpreter.IntegerStack.Push(currentIndex);
|
---|
23 | interpreter.ExecStack.Push(loopBody);
|
---|
24 | }
|
---|
25 | else
|
---|
26 | {
|
---|
27 | var nextIndex = destinationIndex < currentIndex
|
---|
28 | ? currentIndex - 1
|
---|
29 | : currentIndex + 1;
|
---|
30 |
|
---|
31 | interpreter.IntegerStack.Push(currentIndex);
|
---|
32 | interpreter.IntegerStack.Push(nextIndex);
|
---|
33 | interpreter.IntegerStack.Push(destinationIndex);
|
---|
34 |
|
---|
35 | var expression = new ExecDoRangeExpression();
|
---|
36 | interpreter.ExecStack.Push(loopBody);
|
---|
37 | interpreter.ExecStack.Push(loopBody);
|
---|
38 | interpreter.ExecStack.Push(expression);
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override string ToString()
|
---|
43 | {
|
---|
44 | return Symbols.ExecDoXRange;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.