From f62abec2577d3745475581a19eff71dbb8c0494e Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 27 Jul 2016 22:45:03 -0400 Subject: Some minor cleanliness, and beginning work on a language description. --- .../src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java index e481e5e..44904e5 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java @@ -24,23 +24,27 @@ final class ArithmeticCollapser implements IOperatorCollapser { // The operator to use to collapse operators private BinaryOperator valueOp; + private int initialValue; + public ArithmeticCollapser(OperatorDiceNode type, - BinaryOperator valueOp) { + BinaryOperator valueOp, int initVal) { this.type = type; this.valueOp = valueOp; + this.initialValue = initVal; } @Override public IPair> apply( IList>> nodes) { IPair> initialState = new Pair<>( - new IntegerResult(0), new Tree<>(type)); + new IntegerResult(initialValue), new Tree<>(type)); BinaryOperator>> reducer = ( currentState, accumulatedState) -> { // Force evaluation of accumulated state to prevent // certain bugs from occuring - accumulatedState.merge((l, r) -> null); + // @TODO lets see if some of these bugs are fixed + // accumulatedState.merge((l, r) -> null); return reduceStates(accumulatedState, currentState); }; @@ -142,6 +146,7 @@ final class ArithmeticCollapser implements IOperatorCollapser { throw new UnsupportedOperationException( "Nested array operations not supported"); } + int elementInt = ((IntegerResult) element).getValue(); IResult combinedValue; -- cgit v1.2.3