flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Cannot local,inside macro nested in macro definition

Author
Thread Post new topic Reply to topic
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 03 Sep 2008, 10:49
[Compiler internals ?]
Hallo all,
I wonder wheather is there a way to create an
unique local scoped label in a macro which is
inner and nested in an outer, during its definition stage.
It is to say:
if i write:

Code:
macro external val,prefix,arg {
 local ..tmp
 val equ prefix#..tmp#arg

 display `prefix#`..tmp#`arg
 display 13,10
 ;<---- it displays id@outer?Pj..tmp?Pk1a
 ;<---- and then    id@outer?Pj..tmp?Pl1a
}

macro outer {
 local id@outer
 retval equ
   
macro inner arg,userlabel \{
  external retval,id@outer,arg
  retval:            ;<- no "symbol already defined" error
    nop                   ;isnt it not strange ?
  jmp retval
  userlabel equ retval
  \}
}
  outer
   inner a,lab1_a
   inner a,lab2_a
                       
   jmp lab1_a
   jmp lab2_a
    


output code:
Code:
0x402000: 90     NOP          
0x402001: EBFD   JMP 0x402000 
0x402003: 90     NOP          
0x402004: EBFD   JMP 0x402003 
0x402006: EBF8   JMP 0x402000 
0x402008: EBF9   JMP 0x402003 
    


I obtain almost the desired code.
But, if i write
Code:

macro outer {
 local id@outer
   
 macro inner userlabel \{
  local retval
   display \`retval    ;it display always the same name
   display 13,10    ;i.e. retval?Pk

;  ;----decommenting the following line....
;  ;retval:
;  ;----causes "symbol already defined" error

  retval equ $  ;<- but this line would act as it was "define retval $"
   nop
   nop
 jmp retval
 userlabel equ retval
 \}
}
    


In this last way of writing...
(impossible to compile without error)
Code:

macro outer {
 local id@outer
   
 macro inner userlabel \{
  local val     ;<-- i would like to write this line without let raising an error... 
  val:          ;... in order to obtain an UNIQUE+LOCALSCOPED label
   nop
   nop
  userlabel equ val
 \}
}
  outer
   inner lab1
   inner lab2
    jump lab1
    jump lab2

    


Please,follow me now in this little logik...

1- "id@outer", local, is visible in the macro inner. "val" is invisible for "outer".
and normally invisible in not-nested macro, where it has unicity and limited scope.

2- but "val" is not completely local here, because it lacks of unicity everytime i invoke
the macro "inner" after, and only after, invoking once "outer".

3- last but not least, i cannot "purge inner" outside his definition, after but always during the definition
of "outer" to force creation of an unique "val" everytime and after the invoked "inner".


Why so ?
How can i get a fully qualified local label (i.e. unic and scope-limited) during
the definition of a macro inside a macro ?
Post 03 Sep 2008, 10:49
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 03 Sep 2008, 11:19
I think you need to escape local inside the macro with a backslash.

Try this:
Code:
macro outer {
 local id@outer
   
 macro inner userlabel \{
  \local retval  ;<-- it is now escaped
   display \`retval     ;it display always the same name
   display 13,10        ;i.e. retval?Pk

;  ;----decommenting the following line....
;  ;retval:
;  ;----causes "symbol already defined" error

  retval equ $  ;<- but this line would act as it was "define retval $"
   nop
   nop
 jmp retval
 userlabel equ retval
 \}
}    
Post 03 Sep 2008, 11:19
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 03 Sep 2008, 12:30
Yes!!!!!!
It works !!!
How can i be so sleepy ? Embarassed
Should i not reinvent the Art of Modern Spleeping ?
..AMS Art of Modern Sleeping...
..AMSOS Art of Modern Sleeping Operating System
...
i owe you thousand thanx,revolution,
for the quick and precise answer...
hopcode[mrk]
Post 03 Sep 2008, 12:30
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 03 Sep 2008, 13:20
I'll send you the bill in the mail Wink
Post 03 Sep 2008, 13:20
View user's profile Send private message Visit poster's website 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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.