Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DuplicateExpressions.cs @ 14875

Last change on this file since 14875 was 14875, checked in by pkimmesw, 8 years ago

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File size: 3.4 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
5  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
6  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
7
8  /// <summary>
9  ///     Duplicates the top item on the INTEGER stack. Does not pop its argument
10  ///     (which, if it did, would negate the effect of the duplication!).
11  /// </summary>
12  /// <typeparam name="T">Stacktype</typeparam>
13  public abstract class DuplicateExpression<T> : StatelessExpression {
14    protected bool Eval(IPushStack<T> stack) {
15      if (stack.Count == 0) return false;
16
17      stack.Push(stack.Top);
18
19      return true;
20    }
21  }
22
23  [PushExpression(StackTypes.Integer, "INTEGER.DUP")]
24  public class IntegerDuplicateExpression : DuplicateExpression<long> {
25    public override bool Eval(IInternalPushInterpreter interpreter) {
26      return this.Eval(interpreter.IntegerStack);
27    }
28  }
29
30  [PushExpression(StackTypes.Float, "FLOAT.DUP")]
31  public class FloatDuplicateExpression : DuplicateExpression<double> {
32    public override bool Eval(IInternalPushInterpreter interpreter) {
33      return this.Eval(interpreter.FloatStack);
34    }
35  }
36
37  [PushExpression(StackTypes.Boolean, "BOOLEAN.DUP")]
38  public class BooleanDuplicateExpression : DuplicateExpression<bool> {
39    public override bool Eval(IInternalPushInterpreter interpreter) {
40      return this.Eval(interpreter.BooleanStack);
41    }
42  }
43
44  [PushExpression(StackTypes.Name, "NAME.DUP")]
45  public class NameDuplicateExpression : DuplicateExpression<string> {
46    public override bool Eval(IInternalPushInterpreter interpreter) {
47      return this.Eval(interpreter.NameStack);
48    }
49  }
50
51  [PushExpression(StackTypes.Exec, "EXEC.DUP")]
52  public class ExecDuplicateExpression : DuplicateExpression<Expression> {
53    public override bool Eval(IInternalPushInterpreter interpreter) {
54      return this.Eval(interpreter.ExecStack);
55    }
56  }
57
58  [PushExpression(StackTypes.Code, "CODE.DUP")]
59  public class CodeDuplicateExpression : DuplicateExpression<Expression> {
60    public override bool Eval(IInternalPushInterpreter interpreter) {
61      return this.Eval(interpreter.CodeStack);
62    }
63  }
64
65  [PushExpression(StackTypes.IntegerVector, "INTEGER[].DUP")]
66  public class IntegerVectorDuplicateExpression : DuplicateExpression<List<long>> {
67    public override bool Eval(IInternalPushInterpreter interpreter) {
68      return this.Eval(interpreter.IntegerVectorStack);
69    }
70  }
71
72  [PushExpression(StackTypes.FloatVector, "FLOAT[].DUP")]
73  public class FloatVectorDuplicateExpression : DuplicateExpression<List<double>> {
74    public override bool Eval(IInternalPushInterpreter interpreter) {
75      return this.Eval(interpreter.FloatVectorStack);
76    }
77  }
78
79  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].DUP")]
80  public class BooleanVectorDuplicateExpression : DuplicateExpression<List<bool>> {
81    public override bool Eval(IInternalPushInterpreter interpreter) {
82      return this.Eval(interpreter.BooleanVectorStack);
83    }
84  }
85
86  [PushExpression(StackTypes.StringVector, "STRING[].DUP")]
87  public class StringVectorDuplicateExpression : DuplicateExpression<List<string>> {
88    public override bool Eval(IInternalPushInterpreter interpreter) {
89      return this.Eval(interpreter.StringVectorStack);
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.