From 8212af7c70d1603013da32e0501969ed98431caf Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 11 May 2016 21:10:53 -0400 Subject: Adapt to upstream changes --- .../java/bjc/dicelang/DiceExpressionParser.java | 4 +-- .../java/bjc/dicelang/ast/ArithmeticCollapser.java | 22 ++++++------- .../main/java/bjc/dicelang/ast/ArrayResult.java | 8 ++--- .../java/bjc/dicelang/ast/DiceASTEvaluator.java | 36 +++++++++++----------- .../main/java/bjc/dicelang/ast/DiceASTInliner.java | 18 +++++------ .../java/bjc/dicelang/ast/DiceASTOptimizer.java | 8 ++--- .../main/java/bjc/dicelang/ast/DiceASTParser.java | 25 +++++++-------- .../dicelang/ast/DiceASTReferenceSanitizer.java | 8 ++--- .../java/bjc/dicelang/ast/IOperatorCollapser.java | 4 +-- .../ast/optimization/ArithmeticCollapser.java | 4 +-- .../ast/optimization/ConstantCollapser.java | 4 +-- .../ast/optimization/IOptimizationPass.java | 4 +-- 12 files changed, 73 insertions(+), 72 deletions(-) (limited to 'dice-lang/src/main/java') diff --git a/dice-lang/src/main/java/bjc/dicelang/DiceExpressionParser.java b/dice-lang/src/main/java/bjc/dicelang/DiceExpressionParser.java index 0926147..0b20934 100644 --- a/dice-lang/src/main/java/bjc/dicelang/DiceExpressionParser.java +++ b/dice-lang/src/main/java/bjc/dicelang/DiceExpressionParser.java @@ -4,7 +4,7 @@ import java.util.Map; import java.util.Stack; import bjc.utils.funcdata.FunctionalStringTokenizer; -import bjc.utils.funcdata.IFunctionalList; +import bjc.utils.funcdata.IList; import bjc.utils.parserutils.ShuntingYard; import org.apache.commons.lang3.StringUtils; @@ -51,7 +51,7 @@ public class DiceExpressionParser { /* * Shunt the expression to postfix form */ - IFunctionalList list = yard.postfix(tokenizer.toList(), + IList list = yard.postfix(tokenizer.toList(), s -> s); /* 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 c97471d..ac53c81 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java @@ -4,7 +4,7 @@ import java.util.function.BinaryOperator; import bjc.utils.data.IPair; import bjc.utils.data.Pair; -import bjc.utils.funcdata.IFunctionalList; +import bjc.utils.funcdata.IList; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; @@ -30,7 +30,7 @@ final class ArithmeticCollapser implements IOperatorCollapser { @Override public IPair> apply( - IFunctionalList>> nodes) { + IList>> nodes) { IPair> initState = new Pair<>( new IntegerResult(0), new Tree<>(type)); @@ -49,11 +49,11 @@ final class ArithmeticCollapser implements IOperatorCollapser { return reducedState; } - private IFunctionalList combineArrayResults( + private IList combineArrayResults( IResult accumulatedValue, IResult currentValue) { - IFunctionalList currentList = ((ArrayResult) currentValue) + IList currentList = ((ArrayResult) currentValue) .getValue(); - IFunctionalList accumulatedList = ((ArrayResult) accumulatedValue) + IList accumulatedList = ((ArrayResult) accumulatedValue) .getValue(); if (currentList.getSize() != accumulatedList.getSize()) { @@ -61,7 +61,7 @@ final class ArithmeticCollapser implements IOperatorCollapser { "Can only apply operations to equal-length arrays"); } - IFunctionalList resultList = currentList.combineWith( + IList resultList = currentList.combineWith( accumulatedList, (currentNode, accumulatedNode) -> { boolean currentNotInt = currentNode .getType() != ResultType.INTEGER; @@ -95,21 +95,21 @@ final class ArithmeticCollapser implements IOperatorCollapser { if (!currentIsInt) { if (!accumulatedIsInt) { - IFunctionalList resultList = combineArrayResults( + IList resultList = combineArrayResults( accumulatedValue, currentValue); return new Pair<>(new ArrayResult(resultList), accumulatedTree); } - IFunctionalList resultList = halfCombineLists( + IList resultList = halfCombineLists( ((ArrayResult) currentValue).getValue(), accumulatedValue, true); return new Pair<>(new ArrayResult(resultList), accumulatedTree); } else if (!accumulatedIsInt) { - IFunctionalList resultList = halfCombineLists( + IList resultList = halfCombineLists( ((ArrayResult) accumulatedValue).getValue(), currentValue, false); @@ -126,8 +126,8 @@ final class ArithmeticCollapser implements IOperatorCollapser { accumulatedTree); } - private IFunctionalList halfCombineLists( - IFunctionalList list, IResult scalar, + private IList halfCombineLists( + IList list, IResult scalar, boolean scalarLeft) { if (scalar.getType() != ResultType.INTEGER) { throw new UnsupportedOperationException( diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/ArrayResult.java b/dice-lang/src/main/java/bjc/dicelang/ast/ArrayResult.java index 1bd0940..ac78287 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/ArrayResult.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/ArrayResult.java @@ -1,6 +1,6 @@ package bjc.dicelang.ast; -import bjc.utils.funcdata.IFunctionalList; +import bjc.utils.funcdata.IList; /** * Represents a result that is an array of other results @@ -10,7 +10,7 @@ import bjc.utils.funcdata.IFunctionalList; * TODO finish implementing me */ public class ArrayResult implements IResult { - private IFunctionalList arrayContents; + private IList arrayContents; /** * Create a new array-valued result @@ -18,7 +18,7 @@ public class ArrayResult implements IResult { * @param results * The results in the array */ - public ArrayResult(IFunctionalList results) { + public ArrayResult(IList results) { this.arrayContents = results; } @@ -32,7 +32,7 @@ public class ArrayResult implements IResult { * * @return The value of this result */ - public IFunctionalList getValue() { + public IList getValue() { return arrayContents; } 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 4e7d6fb..d2c127f 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTEvaluator.java @@ -9,8 +9,8 @@ import bjc.utils.data.LazyPair; import bjc.utils.data.Pair; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.FunctionalMap; -import bjc.utils.funcdata.IFunctionalList; -import bjc.utils.funcdata.IFunctionalMap; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.IMap; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; @@ -32,7 +32,7 @@ import bjc.dicelang.ast.nodes.VariableDiceNode; */ public class DiceASTEvaluator { private static IResult bindLiteralValue(IDiceASTNode leafNode, - IFunctionalMap> enviroment) { + IMap> enviroment) { String variableName = ((VariableDiceNode) leafNode).getVariable(); if (enviroment.containsKey(variableName)) { @@ -53,9 +53,9 @@ public class DiceASTEvaluator { * The enviroment to evaluate bindings and such against * @return The operations to use when collapsing the AST */ - private static IFunctionalMap buildOperations( - IFunctionalMap> enviroment) { - IFunctionalMap operatorCollapsers = new FunctionalMap<>(); + private static IMap buildOperations( + IMap> enviroment) { + IMap operatorCollapsers = new FunctionalMap<>(); operatorCollapsers.put(OperatorDiceNode.ADD, new ArithmeticCollapser(OperatorDiceNode.ADD, @@ -95,7 +95,7 @@ public class DiceASTEvaluator { // This is so that arrays respect lazy results properly Supplier resultSupplier = () -> { - IFunctionalList resultList = new FunctionalList<>(); + IList resultList = new FunctionalList<>(); nodes.forEach((node) -> { resultList.add(node.getLeft()); @@ -122,7 +122,7 @@ public class DiceASTEvaluator { } private static void doArrayAssign( - IFunctionalMap> enviroment, + IMap> enviroment, IPair> nameNode, ITree nameTree, ITree valueTree, IHolder childCount, ITree child) { @@ -151,8 +151,8 @@ public class DiceASTEvaluator { * @return The integer value of the expression */ public static IResult evaluateAST(ITree expression, - IFunctionalMap> enviroment) { - IFunctionalMap collapsers = buildOperations( + IMap> enviroment) { + IMap collapsers = buildOperations( enviroment); return expression.collapse( @@ -162,7 +162,7 @@ public class DiceASTEvaluator { private static IPair> evaluateLeaf( IDiceASTNode leafNode, - IFunctionalMap> enviroment) { + IMap> enviroment) { ITree returnedAST = new Tree<>(leafNode); switch (leafNode.getType()) { @@ -203,8 +203,8 @@ public class DiceASTEvaluator { } private static IPair> parseBinding( - IFunctionalMap> enviroment, - IFunctionalList>> nodes) { + IMap> enviroment, + IList>> nodes) { if (nodes.getSize() != 2) { throw new UnsupportedOperationException( "Can only bind nodes with two children. Problem children are " @@ -265,7 +265,7 @@ public class DiceASTEvaluator { } private static IPair> parseGroup( - IFunctionalList>> nodes) { + IList>> nodes) { if (nodes.getSize() != 2) { throw new UnsupportedOperationException( "Can only form a group from two dice"); @@ -290,8 +290,8 @@ public class DiceASTEvaluator { } private static IPair> parseLet( - IFunctionalMap> enviroment, - IFunctionalList>> nodes) { + IMap> enviroment, + IList>> nodes) { if (nodes.getSize() != 2) { throw new UnsupportedOperationException( "Can only use let with two expressions."); @@ -301,13 +301,13 @@ public class DiceASTEvaluator { ITree expressionTree = nodes.getByIndex(1) .getRight(); - IFunctionalMap> letEnviroment = enviroment + IMap> letEnviroment = enviroment .extend(); evaluateAST(bindTree, letEnviroment); IResult exprResult = evaluateAST(expressionTree, letEnviroment); - IFunctionalList> childrn = nodes + IList> childrn = nodes .map((pair) -> pair.getRight()); return new Pair<>(exprResult, diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java index 5032dc4..ea5a844 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java @@ -1,8 +1,8 @@ package bjc.dicelang.ast; import bjc.utils.funcdata.FunctionalList; -import bjc.utils.funcdata.IFunctionalList; -import bjc.utils.funcdata.IFunctionalMap; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.IMap; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; @@ -27,16 +27,16 @@ public class DiceASTInliner { * @return The inlined AST */ public static ITree inlineAll(ITree ast, - IFunctionalMap> enviroment) { + IMap> enviroment) { // Tell the compiler that the null is for the entire varargs // parameter, not a single one with a null value return selectiveInline(ast, enviroment, (String[]) null); } private static ITree inlineNode(IDiceASTNode node, - IFunctionalMap> enviroment, + IMap> enviroment, boolean specificInline, - IFunctionalList variableNames) { + IList variableNames) { if (node.getType() != DiceASTType.VARIABLE) { return new Tree<>(node); } @@ -79,8 +79,8 @@ public class DiceASTInliner { */ public static ITree selectiveInline( ITree ast, - IFunctionalMap> enviroment, - IFunctionalList variables) { + IMap> enviroment, + IList variables) { return selectiveInline(ast, enviroment, variables.toArray(new String[0])); } @@ -98,10 +98,10 @@ public class DiceASTInliner { */ public static ITree selectiveInline( ITree ast, - IFunctionalMap> enviroment, + IMap> enviroment, String... variables) { if (variables != null && variables.length > 0) { - IFunctionalList variableNames = new FunctionalList<>( + IList variableNames = new FunctionalList<>( variables); return ast.flatMapTree((node) -> { diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTOptimizer.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTOptimizer.java index e96c620..d7fc23c 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTOptimizer.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTOptimizer.java @@ -1,8 +1,8 @@ package bjc.dicelang.ast; import bjc.utils.funcdata.FunctionalList; -import bjc.utils.funcdata.IFunctionalList; -import bjc.utils.funcdata.IFunctionalMap; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.IMap; import bjc.utils.funcdata.ITree; import bjc.dicelang.ast.nodes.IDiceASTNode; @@ -15,7 +15,7 @@ import bjc.dicelang.ast.optimization.IOptimizationPass; * */ public class DiceASTOptimizer { - private IFunctionalList passes; + private IList passes; /** * Create a new optimizer @@ -44,7 +44,7 @@ public class DiceASTOptimizer { * @return The optimized tree */ public ITree optimizeTree(ITree ast, - IFunctionalMap> enviroment) { + IMap> enviroment) { ITree optimizedTree = passes.reduceAux(ast, (currentPass, currentTree) -> { return currentTree.collapse(currentPass::optimizeLeaf, diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTParser.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTParser.java index f14df74..c149c0a 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTParser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTParser.java @@ -7,8 +7,8 @@ import java.util.function.Predicate; import bjc.utils.funcdata.FunctionalList; import bjc.utils.funcdata.FunctionalMap; -import bjc.utils.funcdata.IFunctionalList; -import bjc.utils.funcdata.IFunctionalMap; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.IMap; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; import bjc.utils.funcutils.StringUtils; @@ -31,8 +31,8 @@ import bjc.dicelang.ast.nodes.VariableDiceNode; */ public class DiceASTParser { private static IDiceASTNode convertLeafNode(String leafNode) { - DiceLiteralType literalType = ILiteralDiceNode - .getLiteralType(leafNode); + DiceLiteralType literalType = + ILiteralDiceNode.getLiteralType(leafNode); if (literalType != null) { switch (literalType) { @@ -73,7 +73,7 @@ public class DiceASTParser { * @return An AST built from the tokens */ public static ITree createFromString( - IFunctionalList tokens) { + IList tokens) { Predicate specialPicker = (operator) -> { if (StringUtils.containsOnly(operator, "\\[")) { return true; @@ -84,7 +84,8 @@ public class DiceASTParser { return false; }; - IFunctionalMap>, ITree>> operators = new FunctionalMap<>(); + IMap>, ITree>> operators = + new FunctionalMap<>(); operators.put("[", (queuedTrees) -> { Tree openTree = new Tree<>("["); @@ -96,14 +97,14 @@ public class DiceASTParser { return parseCloseArray(queuedTrees); }); - ITree rawTokens = TreeConstructor.constructTree(tokens, - (token) -> { + ITree rawTokens = + TreeConstructor.constructTree(tokens, (token) -> { return isOperatorNode(token); }, specialPicker, operators::get); - ITree tokenizedTree = rawTokens.rebuildTree( - DiceASTParser::convertLeafNode, - DiceASTParser::convertOperatorNode); + ITree tokenizedTree = + rawTokens.rebuildTree(DiceASTParser::convertLeafNode, + DiceASTParser::convertOperatorNode); return tokenizedTree; } @@ -131,7 +132,7 @@ public class DiceASTParser { private static ITree parseCloseArray( Deque> queuedTrees) { - IFunctionalList> children = new FunctionalList<>(); + IList> children = new FunctionalList<>(); while (shouldContinuePopping(queuedTrees)) { children.add(queuedTrees.pop()); diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceSanitizer.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceSanitizer.java index 082c94a..a862602 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceSanitizer.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceSanitizer.java @@ -2,7 +2,7 @@ package bjc.dicelang.ast; import bjc.utils.data.IHolder; import bjc.utils.data.Identity; -import bjc.utils.funcdata.IFunctionalMap; +import bjc.utils.funcdata.IMap; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.TopDownTransformResult; import bjc.utils.funcdata.Tree; @@ -21,7 +21,7 @@ import bjc.dicelang.ast.nodes.VariableDiceNode; */ public class DiceASTReferenceSanitizer { private static ITree doSanitize(ITree ast, - IFunctionalMap> enviroment) { + IMap> enviroment) { if (ast.getChildrenCount() != 2) { throw new UnsupportedOperationException( "Assignment must have two arguments."); @@ -134,7 +134,7 @@ public class DiceASTReferenceSanitizer { private static ITree doSingleSanitize( ITree ast, - IFunctionalMap> enviroment, + IMap> enviroment, ITree nameTree, ITree valueTree, String variableName) { if (enviroment.containsKey(variableName)) { @@ -169,7 +169,7 @@ public class DiceASTReferenceSanitizer { * @return The sanitized AST */ public static ITree sanitize(ITree ast, - IFunctionalMap> enviroment) { + IMap> enviroment) { return ast.topDownTransform( DiceASTReferenceSanitizer::shouldSanitize, (subTree) -> { return doSanitize(subTree, enviroment); diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/IOperatorCollapser.java b/dice-lang/src/main/java/bjc/dicelang/ast/IOperatorCollapser.java index a3050a1..0efaca9 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/IOperatorCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/IOperatorCollapser.java @@ -3,7 +3,7 @@ package bjc.dicelang.ast; import java.util.function.Function; import bjc.utils.data.IPair; -import bjc.utils.funcdata.IFunctionalList; +import bjc.utils.funcdata.IList; import bjc.utils.funcdata.ITree; import bjc.dicelang.ast.nodes.IDiceASTNode; @@ -15,6 +15,6 @@ import bjc.dicelang.ast.nodes.IDiceASTNode; * */ public interface IOperatorCollapser extends - Function>>, IPair>> { + Function>>, IPair>> { // Just an alias } diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ArithmeticCollapser.java b/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ArithmeticCollapser.java index 2b2a9ad..70e518e 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ArithmeticCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/optimization/ArithmeticCollapser.java @@ -2,7 +2,7 @@ package bjc.dicelang.ast.optimization; import java.util.function.BinaryOperator; -import bjc.utils.funcdata.IFunctionalList; +import bjc.utils.funcdata.IList; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; @@ -24,7 +24,7 @@ class ArithmeticCollapser { } public ITree collapse( - IFunctionalList> children) { + IList> children) { boolean allConstant = children.allMatch((subtree) -> { return subtree.transformHead((node) -> { if (node.getType() == DiceASTType.LITERAL) { 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 63c9037..3b43ff6 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 @@ -1,6 +1,6 @@ package bjc.dicelang.ast.optimization; -import bjc.utils.funcdata.IFunctionalList; +import bjc.utils.funcdata.IList; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; @@ -42,7 +42,7 @@ public class ConstantCollapser implements IOptimizationPass { @Override public ITree optimizeOperator(IDiceASTNode operator, - IFunctionalList> children) { + IList> children) { if (!operator.isOperator()) { return new Tree<>(operator, children); } diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/optimization/IOptimizationPass.java b/dice-lang/src/main/java/bjc/dicelang/ast/optimization/IOptimizationPass.java index 7dbea18..36b03f1 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/optimization/IOptimizationPass.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/optimization/IOptimizationPass.java @@ -1,6 +1,6 @@ package bjc.dicelang.ast.optimization; -import bjc.utils.funcdata.IFunctionalList; +import bjc.utils.funcdata.IList; import bjc.utils.funcdata.ITree; import bjc.dicelang.ast.nodes.IDiceASTNode; @@ -31,5 +31,5 @@ public interface IOptimizationPass { * @return The optimized node */ public ITree optimizeOperator(IDiceASTNode operator, - IFunctionalList> children); + IList> children); } -- cgit v1.2.3