flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > CALM asm macro |
Author |
|
Tomasz Grysztar 14 Apr 2023, 13:58
fabbel wrote: ... why not simply do sthg like Code: arrange cmd, =mvmacro ?, =struct?.=xstruct assemble cmd Code: define cmd100 mvmacro ?, struct?.xstruct calminstruction ; ... ; ... assemble cmd100 The "asm" macro does a similar thing, but puts the contents of the line to assemble in a hidden variable. The compiled instruction is again going to contain just a single ASSEMBLE command, referring to static value of variable, only this time this variable is kept private, and also you define the value in the same place where you call it. So "asm" is not only more convenient, but also produces a minimal CALM code (just a single ASSEMBLE instruction) without any additional overhead (all the things that "calminstruction?.asm?" does, are done while compiling the instruction that uses it). As for the context-related issues you mentioned, this is something that only comes into view when you want the assembled text to refer to symbols that are local to the definition of your CALM instruction. You cannot do that with ARRANGE, because it produces the text at run-time (when your CALM instruction is executed), so this text is then interpreted in the context in which the instruction is invoked. Consider this example: Code: calminstruction test local cmd, v compute v, 'A' arrange cmd, =db =v assemble cmd end calminstruction v = 'B' test ; produces 'B' Code: define cmd db v calminstruction test local v compute v, 'A' assemble cmd end calminstruction v = 'B' test ; again produces 'B' Code: calminstruction calminstruction?.initsym? var*, val& publish var, val end calminstruction Code: calminstruction test local cmd, v compute v, 'A' initsym cmd, db v assemble cmd end calminstruction v = 'B' test ; produces 'A' And now, if we define an "asm" command, the text given to it also has the local context, therefore it too allows to access the symbols local to the definition: Code: calminstruction test local v compute v, 'A' asm db v end calminstruction v = 'B' test ; produces 'A' Code: calminstruction calminstruction?.asm? line& local name, i initsym name, name.0 match name.i, name compute i, i+1 arrange name, name.i publish name:, line arrange line, =assemble name assemble line end calminstruction It also demonstrates how ARRANGE and MATCH work like a mirror of each other. "match name.i, name" splits the text kept in "name" variable into parts, and puts them into "name" and "i" variables. Then "arrange name, name.i" takes the values of these two variables, puts them together and places the composite text into "name" again. The initial value of "name" has been defined as "name.0", but it could use another local prefix, even "i.0" would work. If you follow this through, I believe it should give you some general intuition about CALM. It is important to distinguish what happens at the time of definition, and what at the run-time of the compiled macro. And keep in mind that for instruction like "calminstruction?.asm?" the run-time happens during the definition-time of yet another instruction. |
|||
14 Apr 2023, 13:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.