flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Extrange behavior with match inside a macro

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I'm not really sure if this is a bug but is very extrange for me.

Code:
foo@bar = 0



; This doesn't work (wrongly report "a1.a2 doesn't exists" without replacing a1 and a2 with their actual names)
macro matchTest arg
{
forward
  ok = 0
  match a1 =@ a2, arg
  \{
  if ~defined a1 # @ # a2
    display `a1, ".", `a2, " doesn't exists"
    err
  end if

    a1 = 1      ; Here preprocesor changes this by "foo = 1"
    a2 = 2      ; Here preprocesor changes this by "bar = 1"

    ok = 1      ; Indicates arg match as an argument
  \}
  if ~ok
    display "Invalid argument"
    err
  end if
}

matchTest foo @ bar

; This works

  match a1 =@ a2, foo @ bar
  {
  if ~defined a1 # @ # a2
    display `a1, ".", `a2, " doesn't exists"
    err
  end if

    a1 = 1
    a2 = 2

    ok = 1      ; Indicates arg match as an argument
  }


;This works too

macro testArg a1, a2
{
  if ~defined a1 # @ # a2
    display `a1, ".", `a2, " doesn't exists"
    err
  end if
}

macro matchTest arg
{
forward
  ok = 0
  match a1 =@ a2, arg
  \{
    testArg a1, a2

    a1 = 1
    a2 = 2

    ok = 1      ; Indicates arg match as an argument
  \}
  if ~ok
    display "Invalid argument"
    err
  end if
}

matchTest foo @ bar    
Preprocesing:
Code:
foo@bar=0




;macro matchTest arg
;{
; forward
; ok=0
; match a1=@ a2,arg
; \{
; if~defined a1#@#a2
; display`a1,'.',`a2,' doesn''t exists'
; err
; end if
;
; a1=1
; a2=2
;
; ok=1
; \}
; if~ok
; display 'Invalid argument'
; err
; end if
;}

;matchTest foo @ bar
        
        
        
        ok=0
        ;match a1=@ a2,foo @ bar
        ;{
        ; if~defined a1@a2
        ; display 'a1','.','a2',' doesn''t exists'
        ; err
        ; end if
        ;
        ; a1=1
        ; a2=2
        ;
        ; ok=1
        ;}
        
        if~defined a1@a2
        display 'a1','.','a2',' doesn''t exists'
        err
        end if
        
        foo=1
        bar=2
        
        ok=1
        
        if~ok
        display 'Invalid argument'
        err
        end if
        



;match a1=@ a2,foo @ bar
;{
; if~defined a1#@#a2
; display`a1,'.',`a2,' doesn''t exists'
; err
; end if
;
; a1=1
; a2=2
;
; ok=1
;}

if~defined foo@bar
display 'foo','.','bar',' doesn''t exists'
err
end if

foo=1
bar=2

ok=1





;macro testArg a1,a2
;{
; if~defined a1#@#a2
; display`a1,'.',`a2,' doesn''t exists'
; err
; end if
;}

;macro matchTest arg
;{
; forward
; ok=0
; match a1=@ a2,arg
; \{
; testArg a1,a2
;
; a1=1
; a2=2
;
; ok=1
; \}
; if~ok
; display 'Invalid argument'
; err
; end if
;}

;matchTest foo @ bar
        
        
        
        ok=0
        ;match a1=@ a2,foo @ bar
        ;{
        ; testArg a1,a2
        ;
        ; a1=1
        ; a2=2
        ;
        ; ok=1
        ;}
        
        ;testArg foo,bar
                
                if~defined foo@bar
                display 'foo','.','bar',' doesn''t exists'
                err
                end if
                
        
        foo=1
        bar=2
        
        ok=1
        
        if~ok
        display 'Invalid argument'
        err
        end if    
Note that only the first match testing methods doesn't replace a1 and a2 but the others works fine.

Regards,
LocoDelAssembly

PS: Thanks for the preprocesing tool, is very usefull!!! Very Happy
Post 08 Dec 2005, 13:55
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
You should escape the macro operators inside "match":
Code:
if~defined a1\#@\#a2 
display \`a1, ".", \`a2, " doesn't exists"    

otherwise they get processed by the outer macro, before the "match" is interpreted - as you can see in the preprocessed source.
Post 08 Dec 2005, 14:24
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Ups sorry, I forgot that

Well I suppose this thread must be moved to another section (or deleted)

Thanks for the reply!!
Post 08 Dec 2005, 14:41
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.