flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Includes by macro - bug, feature or something in-between?

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Following compiles with error: "illegal instruction <<include1 "B.asm">> in "A.asm"

(the code is in the attachment)

File "main.asm":
Code:
macro include1 name { 
  \include name
}

include1 'A.asm'    


File "A.asm":
Code:
include1 'B.asm'    


File "B.asm":
Code:
include1 'C.asm'    


File "C.asm":
Code:
db 1    


In order to be compiled, the macro in main.asm should be:
Code:
macro include1 name {
  macro include1 name2 \{
    macro include1 name3 \\{
      \\include name3
    \\}
    \\include name2
  \}
  \include name
}    


Description:
Download
Filename: include_nesting.zip
Filesize: 468 Bytes
Downloaded: 264 Time(s)


_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 20 Sep 2012, 09:48
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17284
Location: In your JS exploiting you and your system
revolution
This is normal. You can't have a recursive macro unless you define another macro inside the primary macro. See the allow_nesting macro in win32ax.inc for an example. Also see my includeonce macro for another example.
Code:
match =files@included,files@included{

      macro nest_includeonce\{
              macro includeonce path,[instr]\\{\\common
                  file@include equ path
                       match head path tail,files@included\\\{file@include equ\\\}
                 match head path,files@included\\\{file@include equ\\\}
                      match file,file@include\\\{
                         files@included equ files@included path
                              nest_includeonce
                            include file
                                purge includeonce
                           irp i,instr\\\\{i\\\\}
                    \\\}
                \\}
  \}nest_includeonce

        macro show_included\{match x i,files@included\\{irps j,i\\\{display \\\`j,13,10\\\}\\}\}

   files@included equ x

}    
Post 20 Sep 2012, 10:12
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
JohnFound
Or you could have look at my implementation for a yet another one example. Smile
Post 20 Sep 2012, 11:54
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


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.