diff options
| author | bjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu> | 2017-02-24 10:50:53 -0500 |
|---|---|---|
| committer | bjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu> | 2017-02-24 10:50:53 -0500 |
| commit | 07d8b9547a654021d8c56021779f4cdaa5f03f1b (patch) | |
| tree | d80330d7fe4d308469acc006563b9ab5c905d213 /dice-lang/src/bjc/dicelang/v2/EvaluatorResult.java | |
| parent | 73371535e723f84db048abbc4837c8b32facf6a7 (diff) | |
Update
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v2/EvaluatorResult.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/v2/EvaluatorResult.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/dice-lang/src/bjc/dicelang/v2/EvaluatorResult.java b/dice-lang/src/bjc/dicelang/v2/EvaluatorResult.java new file mode 100644 index 0000000..510d5e9 --- /dev/null +++ b/dice-lang/src/bjc/dicelang/v2/EvaluatorResult.java @@ -0,0 +1,94 @@ +package bjc.dicelang.v2;
+
+import bjc.utils.data.ITree;
+import bjc.utils.data.Tree;
+
+public class EvaluatorResult {
+ public static enum Type {
+ FAILURE,
+ INT, FLOAT, DICE, STRING
+ }
+
+ public final EvaluatorResult.Type type;
+
+ // These may or may not have values based
+ // off of the result type
+ public long intVal;
+ public double floatVal;
+ public DiceBox.DieExpression diceVal;
+ public String stringVal;
+
+ // Original node data
+ public ITree<Node> origVal;
+
+ public EvaluatorResult(EvaluatorResult.Type typ) {
+ type = typ;
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, ITree<Node> orig) {
+ this(typ);
+
+ origVal = orig;
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, Node orig) {
+ this(typ, new Tree<>(orig));
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, EvaluatorResult orig) {
+ this(typ, new Node(Node.Type.RESULT, orig));
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, long iVal) {
+ this(typ);
+
+ intVal = iVal;
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, double dVal) {
+ this(typ);
+
+ floatVal = dVal;
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, DiceBox.DieExpression dVal) {
+ this(typ);
+
+ diceVal = dVal;
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, DiceBox.Die dVal) {
+ this(typ);
+
+ diceVal = new DiceBox.DieExpression(dVal);
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, DiceBox.DieList dVal) {
+ this(typ);
+
+ diceVal = new DiceBox.DieExpression(dVal);
+ }
+
+ public EvaluatorResult(EvaluatorResult.Type typ, String strang) {
+ this(typ);
+
+ stringVal = strang;
+ }
+
+ public String toString() {
+ switch(type) {
+ case INT:
+ return type.toString() + "(" + intVal + ")";
+ case FLOAT:
+ return type.toString() + "(" + floatVal + ")";
+ case DICE:
+ return type.toString() + "(" + diceVal + ")";
+ case STRING:
+ return type.toString() + "(" + stringVal + ")";
+ case FAILURE:
+ return type.toString();
+ default:
+ return "Unknown result type " + type.toString();
+ }
+ }
+}
\ No newline at end of file |
