Closed tingtron closed 9 years ago
The cause seems to be that in const
and initialization, only the first operator term is evaluated and the rest of the expression is ignored.
Workaround: break expression into single operator terms.
const S1 = N*14
const S2 = S1/25
const S = S2+15
But it would still be good to have the ability to evaluate more complex expressions at compile time.
You caught me being lazy! As you found out, My const evaluation only uses two operands. I should do a full evaluation, but it adds a great deal of code, or I should extend the expression evaluator to return a flag if the expression results in a constant. I will leave this as a bug so I will remember to return to it. Thanks for all you interest in PLASMA.
Dave...
On Jan 10, 2015, at 3:07 AM, Ting Tron notifications@github.com wrote:
The cause seems to be that in const and initialization, only the first operator term is evaluated and the rest of the expression is ignored.
Workaround: break expression into single operator terms.
const S1 = N*14 const S2 = S1/25 const S = S2+15 But it would still be good to have the ability to evaluate more complex expressions at compile time.
— Reply to this email directly or view it on GitHub.
I did later take a look at the code, in sandbox, and saw the separate simplified const evaluator. I was also expecting that for the const, the same parser as for expressions be used. I didn't look closely at the expression parser. Does it per-calculate constant branches of an expression? E.g. given 2*3 + Var*5
to emit the equivalent of 6 + Var*5
. It seems that a "const" flag/return vaue would help in that regard, and simultaneously be useful in calculating a complete const / initialization expression.
Implement full constant expression evaluation.
Also verified to be working. Thank you for quick turn-around.
Expressions in
const
and initialized variable declaration evaluate arithmetic expression incorrectly. In contrast, the same expression in assignment statement is evaluated correctly.Example, program
DIGERR.PLA
Result:
Expected: