Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/DoTimesExpressions.cs @ 14513

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

#2665 Added Problem.ProgramSynthesis Project, Fixed Expression Issues, Fixed Code Generation

File size: 2.5 KB
Line 
1namespace HeuristicLab.Algorithms.PushGP.Expressions {
2  using HeuristicLab.Algorithms.PushGP.Interpreter;
3  using HeuristicLab.Algorithms.PushGP.Stack;
4
5  public abstract class DoTimesExpression : LoopExpression {
6    protected override bool HasInsufficientArguments(IPushGpInterpreter interpreter, IStack<Expression> sourceStack) {
7      return (interpreter.IntegerStack.Count < 1) || (sourceStack.Count == 0) || (interpreter.IntegerStack.Top <= 0);
8    }
9
10    protected override void InitState(IPushGpInterpreter interpreter, IStack<Expression> sourceStack) {
11      this.State.Body = sourceStack.Pop();
12      this.State.DestinationIndex = interpreter.IntegerStack.Pop();
13      this.State.CurrentIndex = 1;
14      this.State.Incrementor = 1;
15    }
16
17    protected override void PushIteration(IPushGpInterpreter interpreter) {
18      interpreter.ExecStack.Push(this, this.State.Body);
19    }
20
21    protected override void PushLastIteration(IPushGpInterpreter interpreter) {
22      interpreter.ExecStack.Push(this.State.Body);
23    }
24  }
25
26  /// <summary>
27  ///     Like CODE.DO*COUNT but does not push the loop counter.
28  ///     This should be implemented as a macro that expands into CODE.DO*RANGE, similarly to the implementation
29  ///     of CODE.DO*COUNT, except that a call to INTEGER.POP should be tacked on to the front of the loop body code
30  ///     in the call to CODE.DO*RANGE.
31  /// </summary>
32  public class CodeDoTimesExpression : DoTimesExpression {
33    protected override string InitStringRepresentation() {
34      return "CODE.DO*TIMES";
35    }
36
37    public override void Eval(IPushGpInterpreter interpreter) {
38      this.Eval(interpreter, interpreter.CodeStack);
39    }
40  }
41
42  /// <summary>
43  ///     Like EXEC.DO*COUNT but does not push the loop counter. This should be implemented as a macro that expands into
44  ///     EXEC.DO*RANGE,
45  ///     similarly to the implementation of EXEC.DO*COUNT, except that a call to INTEGER.POP should be tacked on to the
46  ///     front of the
47  ///     loop body code in the call to EXEC.DO*RANGE. This call to INTEGER.POP will remove the loop counter, which will have
48  ///     been
49  ///     pushed by EXEC.DO*RANGE, prior to the execution of the loop body.
50  /// </summary>
51  public class ExecDoTimesExpression : DoTimesExpression {
52    protected override string InitStringRepresentation() {
53      return "EXEC.DO*TIMES";
54    }
55
56    public override void Eval(IPushGpInterpreter interpreter) {
57      this.Eval(interpreter, interpreter.ExecStack);
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.