flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > struggling with fasmg again... defining custom calm |
Author |
|
Tomasz Grysztar 13 Dec 2023, 22:46
Yes, I suspect you have problems caused by the namespace context, because when lines that you collect become arguments of a macro, fasmg attaches the context to their text, and this context is not your intended one (of the inside of defined CALM instruction) because this definition has not been actually started yet - as you are just collecting lines to generate the full definition later.
My current solutions are way too convoluted - you could exploit the fact that the text intercepted while a definition of a macro is started is considered contextless, but this would require passing all the lines through twice (first, with a dummy macro definition, to gather the contextless text of all the lines, and then the second pass, no longer inside a macro definition, to filter which lines are to be passed to the collection). I think the correct solution would be to add a syntactic option for any instruction definition, to specify that some macros should not add context information to the text of their arguments. The same exception that now applies to arguments of an unconditional macro executed during a definition of another macro, would then apply to any macro defined with this additional attribute. I should look into this. Oh, and one more thing: you can remove all the context information from any text with RAWMATCH, or by passing it through STRINGIFY and EVAL, but this is not the same thing as not adding the context in the first place. Because the line may already contain snippets of text that have context inherited from elsewhere, and when adding the context information, it is only applied to the areas of text that did not have their own context information in the first place. Clearing all the context from the text would remove both, that's why it is not really a correct solution to the problem. I'm aware that this is a very convoluted issue. If what I wrote appears incomprehensible, I could perhaps show it step by step on some examples... |
|||
13 Dec 2023, 22:46 |
|
fabbel 14 Dec 2023, 09:23
Hi Tomasz, thanks for feedback. Indeed, would be keen on seeing some step by step examples to clarify / demonstrate this topic.
|
|||
14 Dec 2023, 09:23 |
|
fabbel 14 Dec 2023, 09:43
On my side, I tried different variations of the snippet presented above ...
.. one of which was to capture arguments and locals during 'xcalm' lines collection, to later 'preprocess' thoses lines before assembling them, by prefixing all arguments & locals with '#', trying to enforce uniform 'local-ized' context in this way (i.e. uniform context, local to resulting calm instruction definition) : typ. any local variable defined as ' _var' in xcalm block, would be assembled as '#_var' inside resulting calm instruction body (same for arguments). ... it kinda worked ... ... until I tried defining some xcalm using typ. 'arrange' cmd : bec. as I see, typ. in the pattern (2nd arg. to arrange cmd), '#_var' is not interpreted as a single identifier, but split as litteral '#', followed by identifier '_var', which destroyed the purpose leading me to the question : wud being able to somehow enforce 'coalescence' of '#' & '_var' into 'local-ized' identifier '_var' help in solving this, or am I just plain misguided and the idea should be simply dropped dead. Happy to see your view there as well thx |
|||
14 Dec 2023, 09:43 |
|
Tomasz Grysztar 14 Dec 2023, 10:33
I'm just going to add the feature I mentioned above. I should have done that ages ago.
|
|||
14 Dec 2023, 10:33 |
|
fabbel 14 Dec 2023, 10:36
ok, many thx then !
|
|||
14 Dec 2023, 10:36 |
|
Tomasz Grysztar 14 Dec 2023, 12:37
The new feature is up, with k9u0 release (I'm going to make a dedicated thread with more information about it). The name of a macro argument can now use a "&" prefix to make it carry the text without adding context information, so that the text may become reinterpreted when put into new context.
In your example, it should be enough to change Code: macro ?! line& Code: macro ?! &line& Code: calminstruction __xcalm.collect_xcalm def& Code: calminstruction __xcalm.collect_xcalm &def& |
|||
14 Dec 2023, 12:37 |
|
Tomasz Grysztar 14 Dec 2023, 12:51
Also, here's my attempt to implement the same thing simpler:
Code: macro xcalm declaration& local head define head calminstruction declaration calminstruction ? &line& local buffer, collection match =purge ?, line jyes commit take collection, line exit commit: take buffer, collection jyes commit assemble line assemble head out: take line, buffer jno done assemble line jump out done: end calminstruction end macro macro end?.xcalm! end calminstruction purge ? end macro Code: FLAG = 1 xcalm test arg display 'test' display 13 display 10 if FLAG display arg end if end xcalm test 'arg' |
|||
14 Dec 2023, 12:51 |
|
fabbel 14 Dec 2023, 12:58
That was quick !
Will update to new release and look into this ! Tx ! |
|||
14 Dec 2023, 12:58 |
|
fabbel 14 Dec 2023, 15:45
getting Error with arrange cmd ...
... I mean changing prev. simple test to : Code: FLAG = 1 define REMEMBER_ARG xcalm test arg display 'test' display 13 display 10 if FLAG stringify arg display arg end if arrange REMEMBER_ARG, arg end xcalm test 'arg' yields Quote:
|
|||
14 Dec 2023, 15:45 |
|
Tomasz Grysztar 14 Dec 2023, 16:29
That's because STRINGIFY made a byte string value, which ARRANGE does not support.
|
|||
14 Dec 2023, 16:29 |
|
fabbel 14 Dec 2023, 16:33
of course ! ... dumb me sry... missing the obvious ...
|
|||
14 Dec 2023, 16:33 |
|
fabbel 18 Dec 2023, 15:07
Hi
Can u pls have a look at the below - using irpv directive (using 'xcalm' exactly as per your above implementation) Code: calminstruction local locls& ; to prevent unconditional interception of 'local' inx end calminstruction define __STACK__ first define __STACK__ second xcalm test arg local _tmp display 'test :' display 13 display 10 irpv __val, __STACK__ arrange _tmp, =__val arg stringify _tmp display _tmp display 13 display 10 end irpv end xcalm purge local test try I get : Quote:
Quote:
... looks like (global) context is added to the arg symbol inside irpv block ... maybe some interference due to the '=__val' part in the arrange line (arrange _tmp, =__val arg) ? |
|||
18 Dec 2023, 15:07 |
|
fabbel 18 Dec 2023, 15:15
... typ. it works fine if I replace
Code: arrange _tmp, =__val arg with Code: arrange _tmp, =__val =try => output : Quote:
|
|||
18 Dec 2023, 15:15 |
|
Tomasz Grysztar 18 Dec 2023, 16:04
It seems I overlooked one place that also needed adjustment to the new feature. Should be fixed now (version "k9zk").
|
|||
18 Dec 2023, 16:04 |
|
fabbel 18 Dec 2023, 16:06
Will (re)try, thx !
|
|||
18 Dec 2023, 16:06 |
|
fabbel 18 Dec 2023, 16:15
Works fine now. Tx !
|
|||
18 Dec 2023, 16:15 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.