Implement .if .. .else .. .endif
boeckmann opened this issue · comments
This is implemented by e1ad8da.
The condition in the if directive may NOT evaluate to an undefined value in pass 1. So the following will not work if PET is not defined.
.if PET
.endif
The following will work:
PET = 0
.if PET
.endif
Nested if statements are supported.
Further, labels may not preceed conditional statemens, because they are handled differently than normal statements.
The lines excluded by conditional assembly are marked with an exclamation mark in the listings instead of the colon after the line numbers:
3: .if C64
4: .echo "Assembling for the Commodore 64"
5: SCREEN_WIDTH = 40
6: .else
7! .echo "Assembling for the Commodore PET series"
8! SCREEN_WIDTH = 80
9: .endif
Puh, there are a few traps if you allow this. How do you prevent something like this:
.ifdef SIZE
.fill SIZE
.endif
SIZE = 100
Would lead to a phase mismatch between pass 1 and 2. Have you implemented some means to detect this?
In my implementation, I still have one problem: .ifndef FOO FOO = 100 .endif This works, of course, but: in the listing, it will show the "FOO =" line as excluded, because by the time we get to pass 2, the symbol (FOO) is defined... GAK!
…
Yes, if it gets defined via the conditional in the first pass your programm in fact behaves correctly if the listing is generated in pass 2. I don't know if its the right term, but this is what I would call a "phase mismatch". Have to think about it how this can be solved.