Line | |
---|
1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using System;
|
---|
3 |
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
5 |
|
---|
6 | public abstract class PushResultExpression<T> : StatelessExpression {
|
---|
7 | protected void Eval(IStack<T> stack, int count, Func<T[], T> templateFunc) {
|
---|
8 | if (stack.Count < count) return;
|
---|
9 |
|
---|
10 | stack.PushResult(count, templateFunc);
|
---|
11 | }
|
---|
12 |
|
---|
13 | protected void Eval(IStack<T> stack, int count, Func<T[], T> templateFunc, T ignoreValue) {
|
---|
14 | if ((stack.Count < count) || stack.Top.Equals(ignoreValue)) return;
|
---|
15 |
|
---|
16 | stack.PushResult(count, templateFunc);
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected void Eval<R>(IStack<T> stack, IStack<R> resultStack, int count, Func<T[], R> templateFunc) {
|
---|
20 | if (stack.Count < count) return;
|
---|
21 |
|
---|
22 | var items = stack.Pop(count);
|
---|
23 | var result = templateFunc(items);
|
---|
24 |
|
---|
25 | resultStack.Push(result);
|
---|
26 | }
|
---|
27 | }
|
---|
28 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.