flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > virtual in macro & struc offsets

Author
Thread Post new topic Reply to topic
Blank



Joined: 28 Feb 2012
Posts: 13
Location: Ukraine
Blank
I create macro(it creates array with description of each member of struct) with virtual block which used to define offsets of some struct.
When I invoke this macro after struct definition - all OK, but when before - error.
As I saw in fasmpre output instance of struc in virtual block not expanded in few labels as should be.

Is there any way work around this limitation?
Post 13 Mar 2012, 16:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
Show your code please. At least give us an example of what you are trying to do.
Post 13 Mar 2012, 21:53
View user's profile Send private message Visit poster's website Reply with quote
Blank



Joined: 28 Feb 2012
Posts: 13
Location: Ukraine
Blank
It's not complete code listing but, here collected all declarations needed by 'py_members'.
Code:

struc PyMemberDef name, type, offset, flags, doc {
    .name   dd name ; char*
     .type   dd type ; int
       .offset dd offset ; Py_ssize_t
      .flags  dd flags ; int
      .doc    dd doc ; char*
}

macro py_members obj,[name,type,field,flags,doc] {
common
   local i
     virtual at 0
                i obj
       end virtual
forward
      offset=i#\.#field
  local UNIQUE
        .member#UNIQUE PyMemberDef name,type,offset,flags,doc
common
     local UNIQUE
        .member#UNIQUE PyMemberDef 0,0,0,0,0
}

T_SHORT = 0
T_INT = 1
T_LONGLONG = 17

struc GUID {
  .data1 dd ?
 .data2 dw ?
 .data3 dw ?
 .data4 rb 8
}

data1_label db 'data1',0
data2_label db 'data2',0
data3_label db 'data3',0
data4_label db 'data4',0


py_members GUID_PyObject,\
    data1_label, T_INT,     guid.data1, 0, 0,\
 data2_label, T_SHORT, guid.data2, 0, 0,\
   data3_label, T_SHORT, guid.data3, 0, 0,\
   data4_label, T_LONGLONG, guid.data4, 0, 0


struc GUID_PyObject {
     .ob_refcnt dd 0
    .ob_type dd 0
        .guid GUID
}

ob GUID_PyObject
    
Post 14 Mar 2012, 08:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
The preprocessor is not multi-pass and cannot reference definitions before they are defined. That means you can't forward reference any macros, equs or strucs.

Simple rule with preprocessor related stuff: Define first, then use.
Post 14 Mar 2012, 08:40
View user's profile Send private message Visit poster's website Reply with quote
Blank



Joined: 28 Feb 2012
Posts: 13
Location: Ukraine
Blank
Is there no tricky way to define in py_members another macro which would be expanded when preprocessor got to know what is GUID_PyObject?
Post 14 Mar 2012, 08:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
Blank wrote:
Is there no tricky way to define in py_members another macro which would be expanded when preprocessor got to know what is GUID_PyObject?
Not that I know of. The virtual block can be used to give values to labels but it can't be used to give names to labels. Only the preprocessor can define the names, and only the assembler can assign the values.

Just remember that the preprocessor is not multi-pass. That should guide your coding of such things.
Post 14 Mar 2012, 09:01
View user's profile Send private message Visit poster's website Reply with quote
Blank



Joined: 28 Feb 2012
Posts: 13
Location: Ukraine
Blank
If preprocessor is not multi-pass, so sub-...-macro's expanded by one pass?
Post 14 Mar 2012, 09:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
Blank wrote:
If preprocessor is not multi-pass, so sub-...-macro's expanded by one pass?
Yes.
Post 14 Mar 2012, 09:06
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 GitHub, YouTube, Twitter.

Website powered by rwasa.