claro-lang
claro-lang copied to clipboard
Support Compile-Time-Constant evaluation.
Claro should, at compile-time, evaluate all Expressions as far as possible without input needed at runtime. For example, at the most basic level Claro should be evaluating all constant arithmetic Expressions and replacing them with a constant so that this isn't delayed until runtime.
E.g.
at compile time:
var x = 5 + 4;
should be converted to:
var x = 9;
More importantly however, this is primarily done in order to establish all Types at runtime as much as possible. Particularly for the case of the Tuple-subscript Expr.
E.g.
var t: tuple<int, int, string> = (1, 2, "hello");
# Must be cast to int, and would be valid since indices 0&1 are both integers.
var x = (int) t[randomChoice(0, 1)];
# Shouldn't have to be cast since `0` is a compile-time-constant integer expression.
var y = t[3 - 2]; # or t[1]