flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg] Catching nested includes

Author
Thread Post new topic Reply to topic
Calanor



Joined: 19 Jul 2015
Posts: 35
Location: Sweden
Calanor
Back when I was coding in fasm 1, I wrote some code that would catch references to the include directive and store the path and filename in a list in order to handle redundant includes. When I migrated to fasmg, I pretty much ported that code, but now after coming back from a coding break I realise that the code's not working as intended. It cannot handle nested includes, yet fasmg still includes the files. I've tried a number of different approaches, to no avail.

What really surprised me is that even ?! doesn't seem to work, for instance when this little test is concerned:
Code:
calminstruction ?! line&
        local cmd
        match =include? arg, line
        jno nah
                arrange cmd, =display "INCLUDE: ", arg, 13, 10
                assemble cmd
nah:
        assemble line
end calminstruction    

That code will only catch includes that are found at the current level. What am I missing here?
Post 21 Jan 2022, 06:31
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7990
Location: Kraków, Poland
Tomasz Grysztar
To catch the nested ones, you need a recursive macro:
Code:
macro include: path
        display "INCLUDE: ",`path,13,10
        INCLUDE path
end macro    
This doesn't work with "?!", because the interceptor macro cannot be made recursive.

In the above snippet I used case-sensitivity to distinguish the macro from the original directive (you need an access to both of them in order to break recursion). You could also achieve that with a distinct namespace context, but this requires a little more work, for example:
Code:
define __include__ include      ; symbolic link remembers context

namespace enclosing
postpone
        end namespace
end postpone

match INCLUDE, __include__
        macro include?: path    ; now we can make it case-insensitive
                display "INCLUDE: ",`path,13,10
                INCLUDE path
        end macro
end match    
Post 21 Jan 2022, 08:46
View user's profile Send private message Visit poster's website Reply with quote
Calanor



Joined: 19 Jul 2015
Posts: 35
Location: Sweden
Calanor
Thanks for the - as always - quick reply! I'll try out your suggestions - however, wouldn't mvmacro work instead of using case-sensitivity?
Post 21 Jan 2022, 09:41
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7990
Location: Kraków, Poland
Tomasz Grysztar
Calanor wrote:
Thanks for the - as always - quick reply! I'll try out your suggestions - however, wouldn't mvmacro work instead of using case-sensitivity?
MVMACRO operates on variable symbols, and variable symbols are not allowed to be recursive.
Post 21 Jan 2022, 10:24
View user's profile Send private message Visit poster's website Reply with quote
Calanor



Joined: 19 Jul 2015
Posts: 35
Location: Sweden
Calanor
Aha, got it! Thanks, Tomasz!
Post 21 Jan 2022, 12:05
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 GitHub, YouTube, Twitter.

Website powered by rwasa.