nurpax / c64jasm

C64 6502 assembler in TypeScript
51 stars 14 forks source link

[bug] Variables undefined if declared in a !if #75

Closed shazz closed 3 years ago

shazz commented 3 years ago

Example:

let DEBUG = 0

!if (DEBUG == 0) {
    !let data = $2800
}

!if (DEBUG == 1) {
    * = $2000
    data: !byte 12
}

    lda data 

Error:

.asm:13:6: error: Undefined symbol 'data'

Maybe this is because data is a label in one case and a variable in the second one?

nurpax commented 3 years ago

Yeah.. The !if ... {} starts a new anonymous block. Any declarations within the block are not accessible from the outer scope. The scoping rules work more like C scopes, not like preprocessor macros.

Here's how I'd suggest you write it:

!let DEBUG = 0
!let dataptr = $2800

!if (DEBUG == 1) {
    * = $2000
!!dataptr = *
lbl: !byte 12
}

    lda dataptr 
shazz commented 3 years ago

Hum, I did not think to use !!dataptr = *, That works :)