From d37a38c359a88baf75fe944f52ece99da9c55a75 Mon Sep 17 00:00:00 2001 From: Keith Kanios Date: Tue, 14 Jul 2009 21:00:40 -0500 Subject: [PATCH] pptok: change %rimacro to %irmacro preproc: change PP_RIMACRO to PP_IRMACRO nasmdoc: add entries for %[i]deftok and %[i]rmacro --- doc/nasmdoc.src | 31 +++++++++++++++++++++++++++++++ pptok.dat | 2 +- preproc.c | 10 +++++----- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 8ce3e3fa..272d5b23 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -2262,6 +2262,21 @@ This can be used, for example, with the \c{%!} construct (see \c %defstr PATH %!PATH ; The operating system PATH variable +\S{deftok} Defining Tokens: \I\c{%ideftok}\i\c{%deftok} + +\c{%deftok}, and its case-insensitive counterpart \c{%ideftok}, define +or redefine a single-line macro without parameters but converts the +second parameter, after string conversion, to a sequence of tokens. + +For example: + +\c %deftok test 'TEST' + +is equivalent to + +\c %define test TEST + + \H{strlen} \i{String Manipulation in Macros} It's often useful to be able to handle strings in macros. NASM @@ -2386,6 +2401,22 @@ things like \c silly {13,10}, crlf ; crlf: db 13,10 +\S{mlrmacro} \i{Recursive Multi-Line Macros}: \I\c{%irmacro}\i\c{%rmacro} + +A multi-line macro cannot be referenced within itself, in order to +prevent accidental infinite recursion. + +Recursive multi-line macros allow for self-referencing, with the +caveat that the user is aware of the existence, use and purpose of +recursive multi-line macros. There is also a generous, but sane, upper +limit to the number of recursions, in order to prevent run-away memory +consumption in case of accidental infinite recursion. + +As with non-recursive multi-line macros, recursive multi-line macros are +\i{case-sensitive}, unless you define them using the alternative +directive \c{%irmacro}. + + \S{mlmacover} Overloading Multi-Line Macros\I{overloading, multi-line macros} As with single-line macros, multi-line macros can be overloaded by diff --git a/pptok.dat b/pptok.dat index c7dd9550..76ca3609 100644 --- a/pptok.dat +++ b/pptok.dat @@ -69,6 +69,7 @@ %ideftok %if* %imacro +%irmacro %include %ixdefine %line @@ -79,7 +80,6 @@ %push %rep %repl -%rimacro %rmacro %rotate %stacksize diff --git a/preproc.c b/preproc.c index d92b4bf8..2cffd56f 100644 --- a/preproc.c +++ b/preproc.c @@ -2094,7 +2094,7 @@ static int do_directive(Token * tline) * If we're in a %rep block, another %rep nests, so should be let through. */ if (defining && i != PP_MACRO && i != PP_IMACRO && - i != PP_RMACRO && i != PP_RIMACRO && + i != PP_RMACRO && i != PP_IRMACRO && i != PP_ENDMACRO && i != PP_ENDM && (defining->name || (i != PP_ENDREP && i != PP_REP))) { return NO_DIRECTIVE_FOUND; @@ -2102,7 +2102,7 @@ static int do_directive(Token * tline) if (defining) { if (i == PP_MACRO || i == PP_IMACRO || - i == PP_RMACRO || i == PP_RIMACRO) { + i == PP_RMACRO || i == PP_IRMACRO) { nested_mac_count++; return NO_DIRECTIVE_FOUND; } else if (nested_mac_count > 0) { @@ -2615,7 +2615,7 @@ static int do_directive(Token * tline) return DIRECTIVE_FOUND; case PP_RMACRO: - case PP_RIMACRO: + case PP_IRMACRO: case PP_MACRO: case PP_IMACRO: if (defining) { @@ -2623,11 +2623,11 @@ static int do_directive(Token * tline) "`%%%smacro': already defining a macro", (i == PP_IMACRO ? "i" : i == PP_RMACRO ? "r" : - i == PP_RIMACRO ? "ri" : "")); + i == PP_IRMACRO ? "ri" : "")); return DIRECTIVE_FOUND; } defining = nasm_malloc(sizeof(MMacro)); - defining->max_depth = (((i == PP_RMACRO) || (i == PP_RIMACRO)) + defining->max_depth = (((i == PP_RMACRO) || (i == PP_IRMACRO)) ? (DEADMAN_LIMIT) : 0); defining->casesense = ((i == PP_MACRO) || (i == PP_RMACRO)); if (!parse_mmacro_spec(tline, defining, pp_directives[i])) { -- 2.11.4.GIT