flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Nested macro silliness bug:

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
The following code silently errors:
Code:
macro T [A] {
  macro T [B] \{
    macro T [C] \\{
      macro T [D] \\\{
        display \\\`D
      \\\}
      irp X,C \\\{ T X \\\}
    \\}
    irp Y,B \\{ T Y \\}
  \}
  irp Z,A \{ T Z \}
}

T 0,<1,0>,<2,<0,1>>,<3,<<1,0>,2>>    
Code:
01020131    
Whereas this code works as expected:
Code:
macro T [A] {
  macro T [B] \{
    macro T [C] \\{
      irp X,C \\\{
        display \\\`X
      \\\}
    \\}
    irp Y,B \\{ T Y \\}
  \}
  irp Z,A \{ T Z \}
}

T 0,<1,0>,<2,<0,1>>,<3,<<1,0>,2>>    
Code:
0102013102    
Maybe it's running out of stack space and isn't catching it?

I'm only figuring this because nesting another level does report a stack error.

_________________
¯\(°_o)/¯ unlicense.org
Post 05 Jul 2013, 10:25
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
bitRAKE
Quote:
The following code silently errors:

There's no error there. The example is a little convoluted, so I assume you outsmarted yourself.

Basically, you're running irp for each argument (because no common directive is used). With the very last argument the most outer irp is called like this:
Code:
irp Z,3,<<1,0>,2>{T Z}    

With the first iteration you invoke on the same level redefined T macro. But because the macro redefines itself, when invoked, the second iteration uses the most internal T macro, which contains the display directive only. Thus the second (and therefore the last) iteration of the last irp invokes the most inner redefinition:
T<1,0>,2 =>
display '1',0
display '2'
As you terminated the output with non-stringified 0, no further output is displayed.

_________________
Faith is a superposition of knowledge and fallacy
Post 05 Jul 2013, 14:37
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
l_inc wrote:
The example is a little convoluted, so I assume you outsmarted yourself.
Thank you, by renaming the internal macros - it also fixes the stack overflow, when I increase the nesting. (Suppose I should be using purge, too.)

_________________
¯\(°_o)/¯ unlicense.org
Post 05 Jul 2013, 16:35
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.