Code: Select all
enum .macro ...
.pt = .PARAMTYPE(@1)
.endm
;
*=0
;
enum "123" ;invoke macro with a string...the local symbol .pt will be set to 2, indicating the argument to the macro invocation is a character string.
Code: Select all
enum .macro ...
.pt = .PARAMTYPE(@1)
.endm
;
*=0
;
enum 123 ;invoke macro with a numberThe above will set .pt to 1, indicating the argument to be numeric.
A reason I am looking at .PARAMTYPE() is I have been trying to create a macro that is an analog of C’s enum. My enum would be invoked as...
Code: Select all
enum "a1","a2","a3"...with a variable number of arguments, minimum of 2. The idea is enum would loop over the arguments and execute a1 = 0, a2 = 1, a3 = 2, etc., for how many arguments were passed.
So I concocted the following...
Code: Select all
enum .macro ...
.if @0 < 2 ;number of args
.error ""+@0$+": 2 or more args must be specified"
.endif
.e .set 0 ;enumeration index (0,1,2 ...)
.rept @0 ;repeat for each arg
.if .paramtype(@{.e+1})==2 ;if arg is a string...
@{.e+1}$ = .e ;enumerate it <—— won’t work
.e .= .e+1 ;enum index ++
.else
.error ""+@0$+": arguments must be strings"
.endif
.endr
.endmUnfortunately, the above won’t work, the sticking point being the line highlighted with the left-arrow. You’d think that parsing of the arguments would insert, for example, "a1 = .e" into the code flow, setting a1 to whatever .e happens to be. Evidently, @{.e+1}$ does not get expanded to whatever that particular argument holds, resulting in error.
The general takeaway is there is no way to dynamically define global symbols in a macro. So much for my enum macro.