Macros can contain definitions of location labels that must not duplicate when expanding a macro multiple times. To define a number of location labels in local scope of a macro, you can define local symbols for them using the lines of code like these:
lu0 ldef u##__UNIQUE__ lu1 ldef u##__UNIQUE__ lu2 ldef u##__UNIQUE__
The above directives define the symbols lu0, lu1, and lu2 with values that have the form ui, where i is an increasing integer number.
When expanding the macro the first time, the symbols lu0, lu1, and lu2 take the values u1, u2, u3 (if there are no definitions of other symbols using the predefined symbol ‘__UNIQUE__’).
When expanding the macro the second time, the symbols lu0, lu1, and lu2 take the values u4, u5, u6, and so on.
Thus, values of the symbols lu0, lu1, and lu2 are always unique, and you can use them for location labels within macros expanded multiple times.
The following example of a macro illustrates this:
emit_ch macro lu0 ldef u##__UNIQUE__ lu1 ldef u##__UNIQUE__ lu2 ldef u##__UNIQUE__
choice
case 0.33, lu0
case 0.33, lu1
end choice
emit "A"
jmp lu2
lu0: emit "B"
jmp lu2
lu1: emit "C" lu2: emit_ch end macro
This macro emits the character ‘A’, ‘B’, or ‘C’ by the corresponding user instruction emit.
You can safely expand the macro an arbitrary number of times—location labels are unique in every expansion.
For example, to emit a sequence of two characters, expand the macro twice:
...
emit_ch
emit_ch
...
This sequence of two calls to the macro emit_ch expands to the following source text (for clarity, the text does not contain ‘line’ directives):
choice
case 0.33, u1
case 0.33, u2
end choice
emit "A"
jmp u3
u1: emit "B"
jmp u3
u2: emit "C"
u3:
choice
case 0.33, u4
case 0.33, u5
end choice
emit "A"
jmp u6
u4: emit "B"
jmp u6
u5: emit "C"
u6: