flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Recursive macro usage details.

Author
Thread Post new topic Reply to topic
Siberian



Joined: 09 Mar 2010
Posts: 14
Siberian 09 Mar 2010, 11:44
Hello, everybody!

Maybe someone can clarify a couple of details concerning recursive macro usage.
After searching through forum I have found an excellent explanation of recursive macro fasm architecture from vid here.
So based on that example I was able to design recursive macros for my own purpose.
However, there are couple of things which are still not very clear for me.
First of all, have I understood correctly, that mentioned example is only declaring recursive macro, but to actually use it I need to specifically call "Parse"?
Secondly, I couldn't find the way to purge this macro after I have used it. If I purge Parse - this has no effect on compilation - I'm still able to call Parse macro, but if I purge Define_Parse, then calling Parse produces an error which says, that Define_Parse is illegal instruction. While this is an expected behaviour, I need to make it work an opposite way - I need to have Define_Parse macro available while Parse is not available until I call Define_Parse (basically I need to restore the situation before first call of Define_Parse). Is there any way to do that?

As I understand, this issue is caused by recursive definition of Parse macro, in order to remove this macro I need to do purge it as many times as macro called itself in recursion. I'm not 100% sure of the reason, but even if it is exactly that, I doubt that I would be able to produce the solution for this issue the same elegant way as vid did with base example. So if anyone could help me with that?
Post 09 Mar 2010, 11:44
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Mar 2010, 13:40
Siberian,

You may use purge Parse inside it's body.
Code:
macro A { display "Simon says: " }

macro def_A {
  macro A [arg] \{
    \common
    def_A
    \local matched
    define matched FALSE
    match a=,b, arg \\{
      display \\`a, ", "
      A b
      define matched TRUE
    \\}
    match =FALSE a b,matched arg \\{
      display \\`a, " "
      A b
      define matched TRUE
    \\}
    match =FALSE a, matched arg \\{
      display \\`a, ".", 13, 10
    \\}
    restore matched
    purge A
  \}
}

A; non-recursive

def_A

A Hello, cruel world; recursive

purge A

A; non-recursive again

display "Well done!", 13, 10    
Post 09 Mar 2010, 13:40
View user's profile Send private message Reply with quote
Siberian



Joined: 09 Mar 2010
Posts: 14
Siberian 10 Mar 2010, 07:52
This is even more than I asked for, so many thanks, baldr Smile
Post 10 Mar 2010, 07:52
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.