TRSE
TRSE copied to clipboard
Constants in a calculation resolved at runtime instead of compile time
This code:
screenmemory := #$1c00 + 22;
colormemory := #$9400 + 22;
Is generated as:
; INTEGER optimization: a=b+c
lda #<$1C00
clc
adc #$16
sta screenmemory+0
lda #>$1C00
adc #$00
sta screenmemory+1
; LineNumber: 311
; INTEGER optimization: a=b+c
lda #<$9400
clc
adc #$16
sta colormemory+0
lda #>$9400
adc #$00
sta colormemory+1
As these are two constants, is it possible for TRSE to resolve the calculation at compile time instead of creating code at runtime to work it out?
argh this is part of the whole thing I tried to implement yesterday - being able to to things like "myAddress+=3" etc. I probably managed to bork something here, will look at it asap
did we fix this one?
No, this one still occurs.
ah I know why it happens. You've referenced the constant value $2000 - #$2000 doesn't really make any sense (what is the the address of $2000? it's just a constant!), so TRSE will internally treat this as a variable, and write it out at #$2000 in the assembler. This is all completely fine, but since this is now equal to something like
#my_address + 4
TRSE cannot "merge" this as two constants anymore, and will perform the addition run-time.
The solution? I made TRSE stricter by disallowing typing erroneous statements such as "#$2".
Excellent, thank you and that makes sense