flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [solved] Macro ?! / esc instruction |
Author |
|
Tomasz Grysztar 08 May 2019, 09:09
Once you started the macro definition, it is not possible to define or call the "invoker" macro, because these lines then become part of the body of the macro that is being defined. When you are using a strong interceptor ("macro ?!") you cannot simply let all lines pass through, you have to process the syntax manually. It might look for example like this:
Code: define macroBuilder? macroBuilder.ACTIVE = 0 macro macroBuilder? declaration& macro macroBuilder?.definition esc macro declaration end macro macroBuilder?.ACTIVE = 1 end macro macro macroBuilder?.line? content& macro macroBuilder?.definition macroBuilder?.definition content end macro end macro macro macroBuilder?.end? macroBuilder?.definition esc end macro macroBuilder?.ACTIVE = 0 end macro macro lineInvoker? ln& ln end macro macro ?! ln& match =macro? declaration, ln macroBuilder declaration else match =end? =macro?, ln macroBuilder.end else if macroBuilder?.ACTIVE macroBuilder.line ln else lineInvoker ln end if end macro macro _test msg:'OK!' display msg end macro _test Important note: the "lineInvoker" as an additional layer of encapsulation is really needed here. If you just let "line" be placed into your main macro, it would lead to situations like: Code: else ln end if Code: else macro _test end if Keep in mind that ESC would not help here, since it would be processed out at the time when the outer macro is defined, therefore it would not make any difference. ________________________________________________________________________________ Alternatively, you may try disabling your preprocessor for the duration of macro definition: Code: macro Preprocessor_ON macro ?! line& macro invoker esc line end macro match =macro? declaration, line Preprocessor_OFF macro end?.macro?! esc end macro purge end?.macro? Preprocessor_ON end macro end match invoker end macro end macro macro Preprocessor_OFF purge ? end macro Preprocessor_ON macro _test msg:'OK!' display msg end macro _test |
|||
08 May 2019, 09:09 |
|
Tomasz Grysztar 08 May 2019, 09:55
MaoKo wrote: Also I don't understand why this code seem to be an infinite loop on my system (...) Without "local _" there is not infinite loop witch is pretty weird. Code: struc ?!
_expand
end struc
macro _expand?
macro ?! line&
line
end macro
end macro
x
x
Code: macro _expand?
macro ?! line&
_expand
end macro
end macro
Code: C:\asm\fasmglab>fasmg a.asm -r8 flat assembler version g.ije6q a.asm [12]: macro ? [2] macro ? [2] macro ? [2] macro ? [2] macro ? [1] macro ? [2] macro _expand [3]: _expand Processed: _expand Error: exceeded the maximum allowed depth of stack. C:\asm\fasmglab>fasmg a.asm -r9 flat assembler version g.ije6q a.asm [12]: macro ? [2] macro ? [2] macro ? [2] macro ? [2] macro ? [2] macro ? [1] macro ? [2] macro _expand [3]: _expand Processed: _expand Error: exceeded the maximum allowed depth of stack. C:\asm\fasmglab>fasmg a.asm -r10 flat assembler version g.ije6q a.asm [12]: macro ? [2] macro ? [2] macro ? [2] macro ? [2] macro ? [2] macro ? [2] macro ? [1] macro ? [2] macro _expand [3]: _expand Processed: _expand Error: exceeded the maximum allowed depth of stack. Applying unconditional interceptors globally is like playing with fire, please use them carefully and sparingly. |
|||
08 May 2019, 09:55 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.