EgonOlsen71 / basicv2

A Commodore (CBM) BASIC V2 interpreter/compiler written in Java
https://egonolsen71.github.io/basicv2/
The Unlicense
84 stars 15 forks source link

inline .WORD constants #24

Closed nippur72 closed 5 years ago

nippur72 commented 5 years ago

Integer constants are created as .WORD but I guess they can be inlined directly using the 6502 immediate mode (#), saving the bytes and making it a little faster.

E.g. the statement K%=32:

; current
LDY CONST_6
LDA CONST_6+1
; Optimizer rule: INT to FAC, FAC to INT/2
STY VAR_K%
STA VAR_K%+1
; suggested
LDY #32
LDA #0
; Optimizer rule: INT to FAC, FAC to INT/2
STY VAR_K%
STA VAR_K%+1
EgonOlsen71 commented 5 years ago

That's a nice idea, adding it was quite straight forward. However, while being there, I encountered another problem in the initialization of string arrays that was harder to track down. Should be fixed now as well. I also reformatted the whole code, because it was somehow broken for me.