diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-07-28 16:38:59 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-07-28 16:38:59 -0400 |
| commit | d80f404865656b6d1a8faf41cecdd61343adcd0b (patch) | |
| tree | a00a33e6e6cf2c7e568919e628828da848231027 /dice-lang/src/main/java/bjc | |
| parent | f62abec2577d3745475581a19eff71dbb8c0494e (diff) | |
Fixed an issue with instantiating lazy values.
Also, work on language impl. notes
Diffstat (limited to 'dice-lang/src/main/java/bjc')
5 files changed, 53 insertions, 5 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 44904e5..7537005 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java @@ -43,8 +43,7 @@ final class ArithmeticCollapser implements IOperatorCollapser { currentState, accumulatedState) -> { // Force evaluation of accumulated state to prevent // certain bugs from occuring - // @TODO lets see if some of these bugs are fixed - // accumulatedState.merge((l, r) -> null); + //accumulatedState.merge((l, r) -> null); return reduceStates(accumulatedState, currentState); }; @@ -94,6 +93,18 @@ final class ArithmeticCollapser implements IOperatorCollapser { private IPair<IResult, ITree<IDiceASTNode>> doArithmeticCollapse( IResult accumulatedValue, ITree<IDiceASTNode> accumulatedTree, IResult currentValue) { + if (accumulatedValue.getType() == ResultType.DUMMY + || currentValue.getType() == ResultType.DUMMY) { + DummyResult result = new DummyResult( + "Found dummy result with either accumulated dummy (" + + ((DummyResult) accumulatedValue).getData() + + ") or current dummy (" + + ((DummyResult) currentValue).getData() + + ")."); + + return new Pair<>(result, accumulatedTree); + } + boolean currentIsInt = currentValue .getType() == ResultType.INTEGER; boolean accumulatedIsInt = accumulatedValue diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java index 2ed7adf..cef2e19 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java @@ -42,7 +42,8 @@ public class DiceASTEvaluator { return result; } - throw new UnsupportedOperationException( + // Return a DummyResult to handle lets properly + return new DummyResult( "Attempted to deref unbound variable " + variableName); } @@ -88,6 +89,7 @@ public class DiceASTEvaluator { DiceASTEvaluator::parseGroup); operatorCollapsers.put(OperatorDiceNode.LET, (nodes) -> { + // @TODO Fix lets prematurely evaluating things return parseLet(enviroment, nodes); }); diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DummyResult.java b/dice-lang/src/main/java/bjc/dicelang/ast/DummyResult.java new file mode 100644 index 0000000..eeda874 --- /dev/null +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DummyResult.java @@ -0,0 +1,31 @@ +package bjc.dicelang.ast; + +public class DummyResult implements IResult { + /* + * The reason why this result is a dummy + */ + private String dummyData; + + public DummyResult(String data) { + dummyData = data; + } + + @Override + public ResultType getType() { + return ResultType.DUMMY; + } + + /** + * Get the data in this dummy + * + * @return The reason why this result is a dummy + */ + public String getData() { + return dummyData; + } + + @Override + public String toString() { + return "Dummy with reason " + dummyData; + } +} diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/ResultType.java b/dice-lang/src/main/java/bjc/dicelang/ast/ResultType.java index d5e94b9..9e3b129 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/ResultType.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/ResultType.java @@ -14,5 +14,9 @@ public enum ResultType { /** * Represents a result that is an array */ - ARRAY; + ARRAY, + /** + * Represents something not to poke at + */ + DUMMY } diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ConstantCollapser.java b/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ConstantCollapser.java index 6749cab..35148fa 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ConstantCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ConstantCollapser.java @@ -32,7 +32,7 @@ public class ConstantCollapser implements IOptimizationPass { private static final ArithmeticCollapser compoundCollapser = new ArithmeticCollapser( (left, right) -> Integer.parseInt( Integer.toString(left) + Integer.toString(left)), - OperatorDiceNode.SUBTRACT); + OperatorDiceNode.COMPOUND); @Override public ITree<IDiceASTNode> optimizeLeaf(IDiceASTNode leafNode) { |
