summaryrefslogtreecommitdiff
path: root/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-07-27 22:45:03 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-07-27 22:45:03 -0400
commitf62abec2577d3745475581a19eff71dbb8c0494e (patch)
tree2793192a9d393302b56783399dbc58fe5e220d4e /dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java
parent67fee39e6dd22fce8dfaa800f0a5ddbe0ede0be3 (diff)
Some minor cleanliness, and beginning work on a language description.
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.java11
1 files changed, 8 insertions, 3 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 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<Integer> valueOp;
+ private int initialValue;
+
public ArithmeticCollapser(OperatorDiceNode type,
- BinaryOperator<Integer> valueOp) {
+ BinaryOperator<Integer> valueOp, int initVal) {
this.type = type;
this.valueOp = valueOp;
+ this.initialValue = initVal;
}
@Override
public IPair<IResult, ITree<IDiceASTNode>> apply(
IList<IPair<IResult, ITree<IDiceASTNode>>> nodes) {
IPair<IResult, ITree<IDiceASTNode>> initialState = new Pair<>(
- new IntegerResult(0), new Tree<>(type));
+ new IntegerResult(initialValue), new Tree<>(type));
BinaryOperator<IPair<IResult, ITree<IDiceASTNode>>> 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;