Re: [cc65] Macros in ca65

From: Björn Spruck <bjoern1spruck.net>
Date: 2011-12-08 10:51:10
Am 07.12.2011 22:18, schrieb Ullrich von Bassewitz:
>
> You cannot undefine a symbol, but you can introduce another counter that gets
> incremented on each _IFNE or _IFEQ but never decremented. If you add this to
> your labels, they become unique. It's probably difficult to combine this with
> nesting, but I think it's possible to come up with a solution.
>
A simple solution would be a stack, -> push and pop

counter         .set    0

.macro  _IFNE
        counter .set    counter +1
        beq     .ident (.sprintf ("else%04d", counter))
	.push counter
 .endmacro

.macro  _IFEQ
        counter .set    counter +1
        bne     .ident (.sprintf ("else%04d", counter))
	.push counter
.endmacro

.macro  _ELSE
        bra     .ident (.sprintf ("endif%04d", counter))
        .ident  (.sprintf ("else%04d", counter)) := *
.endmacro

.macro  _ENDIF
	.pop counter
        .if     .not .defined( .ident (.sprintf ("else%04d", counter)))
        .ident  (.sprintf ("else%04d", counter)) := *
        .endif
        .ident  (.sprintf ("endif%04d", counter)) := *
        counter .set    counter - 1
.endmacro

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Dec 8 10:51:20 2011

This archive was generated by hypermail 2.1.8 : 2011-12-08 10:51:24 CET