diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-17 20:41:47 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-17 20:41:47 -0400 |
| commit | 7c222f25d4b2d9f3b149d880f0e1acf8d673e4f5 (patch) | |
| tree | a07cd6b07522d9ffe24a82c5a1a487d307875561 /dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java | |
| parent | d9437c1d328ccc2b26bd0aae19c2aff7140e466b (diff) | |
Fixed a bug with arithmetic operators
Diffstat (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java')
| -rw-r--r-- | dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java | 22 |
1 files changed, 13 insertions, 9 deletions
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 5ad0a0f..5c00fe2 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java @@ -16,8 +16,7 @@ import bjc.utils.funcdata.Tree; * @author ben * */ -final class ArithmeticCollapser - implements IOperatorCollapser { +final class ArithmeticCollapser implements IOperatorCollapser { private OperatorDiceNode type; private BinaryOperator<Integer> valueOp; @@ -35,12 +34,18 @@ final class ArithmeticCollapser new Pair<>(0, new Tree<>(type)); BinaryOperator<IPair<Integer, ITree<IDiceASTNode>>> reducer = - (accumulatedState, currentState) -> { - return reduceStates(accumulatedState, - currentState); + (currentState, accumulatedState) -> { + // Force evaluation of accumulated state to prevent + // certain bugs from occuring + accumulatedState.merge((l, r) -> null); + + return reduceStates(accumulatedState, currentState); }; - return nodes.reduceAux(initState, reducer, (state) -> state); + IPair<Integer, ITree<IDiceASTNode>> reducedState = + nodes.reduceAux(initState, reducer, (state) -> state); + + return reducedState; } private IPair<Integer, ITree<IDiceASTNode>> reduceStates( @@ -52,9 +57,8 @@ final class ArithmeticCollapser .bind((currentValue, currentTree) -> { accumulatedTree.addChild(currentTree); - Integer combinedValue = - valueOp.apply(accumulatedValue, - currentValue); + Integer combinedValue = valueOp.apply( + accumulatedValue, currentValue); return new Pair<>(combinedValue, accumulatedTree); |
