Open nippur72 opened 1 year ago
I had this in my mind for a while but I haven't yet found a good way to implement it.
The easy implementation would be to simply have the machine that you compile on (your PC) evaluate the expression. Well, it will evaluate it differently than the target machine (your Commodore) because of the differences in the architectures and the underlying math libraries.
In your example, the compiler would evaluate the expression as SIZE = 528
but according to XC=BASIC runtime rules, the result should be SIZE = 16
. (read why: https://xc-basic.net/doku.php?id=v3:expressions)
I think users would be confused by the fact that they get different expression results in compile time and run time.
The better approach would be to emulate the entire XC=BASIC (runtime) math library in the compiler itself. This way you'd get the same results in compile time. Implementing this is quite substantial, and unfortunately, my schedule doesn't allow me the necessary time to tackle it currently.
I understand that this is a design choice, but I would be happy if source code constant expressions were folded at compile time to literals without complying with runtime rules.
somewhat related to #63,
CONST
should accept any expression that evaluates to a constant value (the same way as DASM does).E.g.