flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [SUG] Extended syntax for 'match' directive

Author
Thread Post new topic Reply to topic
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 05 Jul 2013, 07:18
It's not a rare occasion that sequence of match directives emulates if/else chain using some tricks. Probably match could be modified to accept the following syntax (as an example I took fragment of Win32AX.Inc pushd macro):
Code:
match {; pattern and matching sequence are both absent, that indicates alternative behavior
  =addr var,value \{; here they go
    if +var relativeto 0 | +var relativeto $
      push var
    else
      lea edx,[var]
      push edx
    end if \}
  =double [var],value \{; this will be tried only if previous pair doesn't match
    push dword [var+4]
    push dword [var] \}
  =double =ptr var,value \{; next match to try
    push dword [var+4]
    push dword [var] \}
  =double num,value \{ \local ..high,..low; you've probably got the idea
    virtual at 0
      dq num
      load ..low dword from 0
      load ..high dword from 4
    end virtual
    push ..high
    push ..low \}
  \{ \local ..continue; brace alone means final 'else'
    if value eqtype ''
      call ..continue
      db value,0
    ..continue:
    else
      push value
    end if \}
}    
As a shortcut for single if/else I think about something like this (from Win32A.Inc):
Code:
struc TCHAR [val] { common match any, val \{ . db val \} \{ . db ? \} }
; That was only to show my suggestion, I know that using default argument value, it could be reduced to
struc TCHAR [val=?] { common . db val }    
I'll research into that; meanwhile, your comments are welcome.
Post 05 Jul 2013, 07:18
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 05 Jul 2013, 08:36
I've been thinking about some kind of elsematch directive ever since I introduced match. But I never decided on a good name for it... and since it was possible to manage (though not as elegantly) with match alone, I repeatedly dropped it from my "to do" list.

What I had in mind would look a bit like this:
Code:
match =addr var,value {
; ...
} elsematch =double [var],value {
; ...
}    
Post 05 Jul 2013, 08:36
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.