From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-11-22 03:06:18
Hi!
On Sat, Nov 22, 2003 at 12:56:07AM +0100, Stephan Lesch wrote:
> I would like to write a macro that takes a string OR a number as
> an argument and distinguishes the types, like
[...]
> Is there a way to do this?
Yes. The .MATCH function is your friend:
----------------------------------------------------------------------------
.macro print arg
.if .match (arg, "")
.pushseg
.segment "STRINGS"
.local txt
txt: .asciiz arg
.popseg
.word txt
.else
.word arg
.endif
.endmacro
----------------------------------------------------------------------------
One trick used here is to check explicitly only for strings, otherwise an
expression that includes more than just a number won't get recognized. If you
just want to accept strings and numeric literals, you can use the following
version with improved error detection:
----------------------------------------------------------------------------
.macro print arg
.if .tcount (arg) <> 1
.error "Invalid argument for macro print"
.elseif .match (arg, "")
.pushseg
.segment "STRINGS"
.local txt
txt: .asciiz arg
.popseg
.word txt
.elseif .match (arg, 0)
.word arg
.else
.error "Invalid argument type for macro print"
.endif
.endmacro
----------------------------------------------------------------------------
Note that this second version will no longer accept things like
print 12+13
Regards
Uz
--
Ullrich von Bassewitz uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-11-22 03:06:49 CET