One of the SciTech changes is to, on expansion,
look up preprocessor variables and single-line
macros in any outer context(s).
This is done because user code might contain a
context-local definition, followed by a macro
invocation which creates another context, fol-
lowed by an attempt to reference the original
context-local definition.
For example, take the IF and ENDIF macros from
the NASM manual:
%push c
%assign %$a 11h
IF nc ; does a %push
mov ax,%$$a ; correct but non-intuitive
mov ax,%$a ; incorrect but intuitive
ENDIF ; does a %pop
%pop
Currently the aforementioned functionality is
broken: see SF #704736.
However, once that other bug has been fixed,
there is yet another problem.
While preproc.c's get_ctx() does look through
any outer context(s), in an attempt to find
a definition that matches "name", if fails to
take the parameter count into account. (Why?
Because expand_smacro() invokes get_ctx() be-
fore it establishes that count.)
As a result, the following code fails:
%push c
%define %$df0 0
%define %$df1(x) x
%push cc
%define %$df0(x) x
%define %$df1 0
%push ccc
mov ax,%$df0 ; [1]
mov ax,%$df0(1) ; ok -- found in cc
mov ax,%$df1 ; ok -- found in cc
mov ax,%$df1(1) ; [2]
%pop
%pop
%pop
[1] %$df0 is found in cc, but later fails to
match in cc due to nparam -- so it gets
converted to ..@<number>.df0, which then
fails, because that label isn't defined
[2] %$df1 is found in cc, but later fails to
match in cc due to nparam -- so it gets
expanded to mov ax,0(1), which fails
This should be fixed.
Logged In: YES
user_id=804543
In my local forked version I have added the %RELAX
preprocessor directive, which controls whether such
outer context lookups are performed or not. As its
argument it expects a numeric value, which may con-
tain an expression. A value of 0 disables the "re-
laxed" lookups; non-zero values enable them. (The
default is "disabled", i.e. pre-SciTech behavior.)
Logged In: YES
user_id=804543
In my local forked version I have documented that a
suitable outer context is located without taking the
parameter count into consideration, while subsequent
expansion attempts do take it into consideration. I
have also added a note, stating that future versions
of NASM might implement this differently, i.e. that
the user should avoid outer context lookups on any
single-line macro (definition or invocation) with
parameters.
Logged In: YES
user_id=806493
It would not be hard to implement 'smart' context searching,
which will handle number of params. Just we should remove
all outer context lookup logic from get_ctx and move it in
expand_smacro after it knows number of params - this also
would be a good design solution, as there is a macro search
already located in that place.