TRSE icon indicating copy to clipboard operation
TRSE copied to clipboard

Constants in a calculation resolved at runtime instead of compile time

Open AndyHOvine opened this issue 3 years ago • 3 comments

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?

AndyHOvine avatar Feb 10 '22 18:02 AndyHOvine

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

leuat avatar Feb 10 '22 20:02 leuat

did we fix this one?

leuat avatar Mar 24 '22 13:03 leuat

No, this one still occurs.

AndyHOvine avatar Mar 24 '22 19:03 AndyHOvine

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".

leuat avatar Nov 29 '22 20:11 leuat

Excellent, thank you and that makes sense

AndyHOvine avatar Nov 29 '22 21:11 AndyHOvine