flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Escaping inside of a macro

Author
Thread Post new topic Reply to topic
yoshimitsu



Joined: 07 Jul 2011
Posts: 96

Escaping inside of a macro

Hi there.
I kind of don't understand when one has to escape inside of his macro.

The documentation says:

Quote:
If some directives specific to macroinstructions, like local or common are needed inside some macro embedded this way, they can be escaped in the same way. Escaping the symbol with more than one backslash is also allowed, which allows multiple levels of nesting the macroinstruction definitions.


I find this one a little briefly described. Also there's only a small example macro which defines another macro and therefore needs to escape the curly braces.

But when I wrote the following macro:

Code:
macro data directory 
 { done@data equ 
   match =3,directory 
   \{ local l_infos,_info,_end 
      l_infos equ 
      align 4 
      match list,l_handlers 
      \\{ 
         irp _handler,list 
         \\\{ local rva$ 
            rva$ = rva $ 
            enqueue l_infos,rva$ 
            db 19h,0,0,0 
            dd _handler,0 
         \\\} 
      \\} 
      ;...


I would have never guessed on my own that you need to escape the local rva$ inside of the irp-instruction.
Although the documentation mentions local I somehow thought it'd only be important if you define another actual macro.

Another example:

Code:
macro foo x
{
 match a:b,x
 \{
  db \`b
 \}
}

foo hello:bye



If I hadn't seen some example code in the forum, I probably would have never came to the conclusion that you have to escape it..
Post 16 Feb 2012, 04:57
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15818
Location: Misner space

The outer macro is looking for things to process. If you don't escape something then the outer macro will attempt to make sense of it. If you do escape it then the outer macro will simply pass it on unhandled and untouched to the inner macro(s) and strip one level of escape backslashes.

[edit] Strictly speaking the opening curly bracket does not need to be escaped since the macro processor cannot make any sense of it. But I still do escape them just to remind myself, and make it clear to myself, both the number of escape levels currently entered and that the following block is a new inner macro.
Post 16 Feb 2012, 05:05
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881

yoshimitsu
You can escape any symbol (see section 1.2.1, second paragraph for description of what a symbol is) in any macroblock (macro, struc, match, rept, irp, irps). Every symbol is either interpreted according to the current context, or unescaped by removing a single leading backslash from the character sequence, while a macroblock is expanded. That's all, you need to know about escaping. What symbols and with how many slashes you escape them depends on the moment you want those symbols to be interpreted.

Consider the following example for training:

Code:
struc asComputationDestination { macro . [\.] \{ common match ==\\.,\. \\{ irps \\\.,\\. \\\{ display \\\`\\\. \\\} \\} \} }
x asComputationDestination
x = 20*10/20+1


(the macro does not compute anything. It just displays the expression)
Post 16 Feb 2012, 13:22
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.