flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > 2 if-statements in one macro / error

Author
Thread Post new topic Reply to topic
derPENGUIN



Joined: 09 Jul 2006
Posts: 5
derPENGUIN
Hi,
at first I have to say, I am a newbie in asm and macro coding, so answer please as simple as possible Wink

OK, I have a macro with two if statements, but it dos not work. Here is the code:
Code:
macro kxNew type,name {
; This is the base structur,
; all widgets will inhertit from it.
; Do not use it directly
; ------------------------------------------------
    struct kxWidget
      dtype         dd         ?
      caption       dd         ?
      xsize         dd         ?
      ysize         dd         ?
      xpos          dd         ?
      ypos          dd         ?
      bcolor        dd         ?
    ends


; Window, kxType 1
; inherits from kxWidget
  if type eq kxWindow
    struct kxWindow kxWidget
      gcolor        dd         ?        ; grab bar color
      fcolor        dd         ?        ; frame color
    ends
; define initial values
    name kxWindow 1, 20,40,70,60,,0,0,0
  end if

; Button,kxtype 10,  atm expands only id
; inherits from kxWidget
  if type eq kxButton
    struct kxButton kxWidget
      id            dd         ?
    ends
; define initial values
    name kxButton 10,,20,40,70,60,,0
;  else
;    mcall 4,<20,60>,0,name,3
  end if
}    


It compiles with error "unexspected instruction" at the second "end if". But I cannot see any mistake.

I use fasm for MenuetOS on kolibri 0.5.3, the used MACROS.INC is this one from Mario79/xtree (size 12.641).

pls can you help me?
Post 09 Jul 2006, 13:01
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
You should not put the structure definitions inside the macro, leave only the structure declarations (the actual instances of the given stuctures) inside it. The structure definition ("struct"-"ends") itself is a kind of macro definition.
Post 09 Jul 2006, 16:54
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
that's why i prefer not overloading "{" and "}", like "idata \{ ... \}" instead of "idata ... endg". of course it's not always possible
Post 09 Jul 2006, 20:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
The official "struct" macro doesn't overload braces. I haven't checked what kind of macros were applied here, though.
Post 09 Jul 2006, 20:31
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Actually the macro from the first post works with standard 'struct' even in this weird variant. The problem arises when the macro is used second time, no matter whether structures are defined inside or outside. This seems to be some other problem...
Post 09 Jul 2006, 20:38
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
OK, found it out: when type is kxButton, this line:
Code:
  if type eq kxWindow     

becomes:
Code:
 if kxButton eq kxWindow    

and thus is interpreted by preprocessor (for which IF has no meaning) as a declaration of structure.

Thus the solution is:
1) Move structure definitions outside of the macro, so then won't get defined more than once
2) Replace the lines like:
Code:
if type eq kxButton    

with lines like:
Code:
if <type> eq <kxButton>    

(or even better it would be to use MATCH).
Post 09 Jul 2006, 20:45
View user's profile Send private message Visit poster's website Reply with quote
derPENGUIN



Joined: 09 Jul 2006
Posts: 5
derPENGUIN
Thank you, Tomasz, it works now with widget-struct outside the macro and "if <type>..."

Great job!
Post 10 Jul 2006, 04:31
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.