From a6a205c4c0e50f7403fb926565360faf23655f79 Mon Sep 17 00:00:00 2001 From: otya128 Date: Fri, 2 Dec 2016 21:56:28 +0900 Subject: [PATCH] fix constant folding --- SMILEBASIC/parser.d | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/SMILEBASIC/parser.d b/SMILEBASIC/parser.d index 5e42faa..2fc66cf 100644 --- a/SMILEBASIC/parser.d +++ b/SMILEBASIC/parser.d @@ -1705,14 +1705,18 @@ class Parser if (op.item1.type == NodeType.Constant && op.item2.type == NodeType.Constant) { double result; - if (constcalc((cast(Constant)op.item1).value, (cast(Constant)op.item2).value, op.operator, result)) + Constant leftconst = (cast(Constant)op.item1), rightconst = (cast(Constant)op.item2); + if (rightconst.value.isNumber && leftconst.value.isNumber) { - auto l = new Constant(Value(result), lex.location); - constexpr = true; - if(order != getOPRank(token.type)) - return l; - op = new BinaryOperator(l, lex.location); - continue; + if (constcalc(leftconst.value, rightconst.value, op.operator, result)) + { + auto l = new Constant(Value(result), lex.location); + constexpr = true; + if(order != getOPRank(token.type)) + return l; + op = new BinaryOperator(l, lex.location); + continue; + } } } version(none)