flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [fasmg] outscope persistent |
Author |
|
Tomasz Grysztar 27 Oct 2019, 18:46
I believe that the interaction of OUTSCOPE with macro nesting was not implemented properly. Even the example from the manual was not behaving well.
I therefore tried correcting the implementation, please try this with the new "ipyd0" release: Code: macro _iterate_string?! parameter?*, text?* local char, start, iterator ;must_string (text) start = $00 iterator equ parameter match it =: begin, parameter ;must_numeric (begin) start = begin iterator equ it end match repeat (lengthof (text) - start), i:start char =: string (((text) shr ($08 * i)) and $FF) end repeat match it, iterator macro invoker?! esc outscope irpv it, char end macro end match outscope invoker end macro macro end?._iterate_string?! end irpv end macro Anyway, this still does not solve problems with using it inside an IF $00 block, because END IRPV is not paired correctly then. But I believe this can be easily corrected, and it even simplifies the macro a little: Code: macro _iterate_string?! parameter?*, text?* local char, start, iterator ;must_string (text) start = $00 iterator equ parameter match it =: begin, parameter ;must_numeric (begin) start = begin iterator equ it end match repeat (lengthof (text) - start), i:start char =: string (((text) shr ($08 * i)) and $FF) end repeat match it, iterator outscope irpv it, char end macro macro end?._iterate_string?! end irpv end match end macro |
|||
27 Oct 2019, 18:46 |
|
MaoKo 27 Oct 2019, 19:08
Ty very much Tomasz. It's help me a lot because I duplicate several macro to bypass this.
|
|||
27 Oct 2019, 19:08 |
|
Tomasz Grysztar 27 Oct 2019, 19:21
Thank you for pointing this out! This was also affecting my IRPS macro, which I obviously have not been using enough myself.
|
|||
27 Oct 2019, 19:21 |
|
MaoKo 29 Oct 2019, 21:41
Hi!. I just figure out that in my first example it's only need "esc" before macro defined with ! to get's work in macro def body. I'm sorry, I didn't known about this "esc" usage.
And also why the outscope get vanish in inner macro def ??? Have a good day Last edited by MaoKo on 29 Oct 2019, 22:17; edited 1 time in total |
|||
29 Oct 2019, 21:41 |
|
Tomasz Grysztar 29 Oct 2019, 22:08
MaoKo wrote: Hi!. I just figure out that in my first example it's only need "esc" before macro defined with ! to get's work in macro def body. I'm sorry, I didn't about this "esc" usage. And ESC in general allows to ensure that something becomes part of the text of a macro. It also handles respects nesting, so as long you have an inner macro completely enclosed in an outer one, you do not need to use constructions like ESC ESC (unlike the backslashing in fasm 1, for example). Some of the nuances may be not documented properly yet, this is because I keep experimenting with some corner cases and I only define them in the manual after I'm sure I arrived at a good design. |
|||
29 Oct 2019, 22:08 |
|
Tomasz Grysztar 30 Oct 2019, 15:32
After giving this some more thought I found another solution.
This is a simple trick that allows to handle nesting properly without making the main macro unconditional. Because it is much safer to not have it unconditional and only unroll it when the arguments really require processing. Unconditional macros are tricky and may cause many kinds of unwanted interactions, so it is better to reduce them to minimum. I updated my IRPS macro to use the new trick: Code: macro irps_as_irpv parameter*, text& local buffer,symbol define buffer text while 1 match car cdr, buffer define symbol car define buffer cdr else match any, buffer define symbol any end match break end match end while outscope irpv parameter, symbol end macro macro irps?! arguments& macro irpv! purge irpv end macro irpv outscope irps_as_irpv arguments end macro macro end?.irps?! end irpv end macro When the directive is in skipped code, the IRPV line is seen and is counted for END IRPV pairing. When the directive is in processed code, the macro gets defined and subsequent IRPV line ends up calling that macro (which just purges itself), and then the main conditional macro parses the arguments and opens the actual IRPV block. I recommend this method, it should be more reliable. |
|||
30 Oct 2019, 15:32 |
|
MaoKo 30 Oct 2019, 16:48
Haha yeah, you are right. I find this pretty funny . It's interesting to note that the argument doesn't matter for pairing.
|
|||
30 Oct 2019, 16:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.