flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > COM revisited

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 31 Oct 2010, 13:20
Note: I'm not suggesting a replacement for the COM??.INC macros in the distribution. This macro only implements a small sub-set of the functionality present in the distribution macro.

While using COM this silly desire to have the syntax more closely match the relationship between interfaces resulted in the following macro:
Code:
macro Interface name,base,[method] { common
  match ,base \{
    ...#name equ method
  \}
  match A,base \{
    match B,...#base \\{
      ...#name equ B,method
    \\}
  \}

  match B,...#name \{
    ; INSTANCE USAGE:
    ;   Instance <name>                 ; object pointer in data section
    ;   mov rcx,[Instance]              ; get object pointer
    ;   mov rax,[rcx]                   ; get vector table
    ;   call [rax + Instance.method]    ; invoke method routine
    struc name \\{
      . dq ?
      virtual at 0
        irp A,B \\\{
          .\\\#A dq ?
        \\\}
      end virtual
    \\}

    ; VIRTUAL USAGE:
    ;   mov rax,[rcx]                   ; get vector table
    ;   call [rax + name.method]        ; invoke method routine
    virtual at 0
      irp A,B \\{
        name#.\\#A dq ?
      \\}
    end virtual
  \}
}    
So, now every interface can have a single base which it extends:
Code:
Interface IUnknown,,QueryInterface,AddRef,Release ; no base interface
Interface ITaskBarList, IUnknown, HrInit,AddTab,DeleteTab,ActivateTab,SetActiveAlt    
...and this will work in a nested fashion.
Code:
Interface IDXGIObject,          IUnknown,             SetPrivateData,\
                                                      SetPrivateDataInterface,\
                                                      GetPrivateData,\
                                                      GetParent
Interface IDXGIDeviceSubObject, IDXGIObject,          GetDevice
Interface IDXGISurface,         IDXGIDeviceSubObject, GetDesc,\
                                                      Map,\
                                                      Unmap
Interface IDXGISurface1,        IDXGISurface,         GetDC,\
                                                      ReleaseDC    
...and now my code looks pretty. Very Happy

Maybe, someone else will find this pattern convenient.


[SIDEBAR]
Although I don't use COM64.INC, there appears to be a possible error in "com.interface.#name = $ shr 2"? If this value is meant to be the number of methods in the vector table then the shift should be by three. The only internal use of the value just checks for it being defined.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup


Last edited by bitRAKE on 31 Oct 2010, 13:47; edited 1 time in total
Post 31 Oct 2010, 13:20
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 31 Oct 2010, 13:44
Hah, and I was just thinking of how you could use inheritance with interfaces!

This made me think if there were some better solution:

Code:
IDirectSoundBuffer interface GetCaps,GetCurrentPosition,GetFormat,GetVolume,GetPan,GetFrequency,\
                             GetStatus,Initialize,Lock,Play,SetCurrentPosition,SetFormat,\
                             SetVolume,SetPan,SetFrequency,Stop,Unlock,Restore
IDirectSoundBuffer8 interface GetCaps,GetCurrentPosition,GetFormat,GetVolume,GetPan,GetFrequency,\
                              GetStatus,Initialize,Lock,Play,SetCurrentPosition,SetFormat,\
                              SetVolume,SetPan,SetFrequency,Stop,Unlock,Restore,SetFX,\
                              AcquireResources,GetObjectInPath       


Code:
struc interface [methods]
{
   common
      label .
      virtual at 0
      .#\.#QueryInterface rd 1
      .#\.#AddRef rd 1
      .#\.#Release rd 1
   forward
      .#\.#methods rd 1
   common
      end virtual
      rd 1
}    

_________________
This is a block of text that can be added to posts you make.
Post 31 Oct 2010, 13:44
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 31 Oct 2010, 15:00
Code:
Is it possible to do something like this?

struct IUnknown
   label .
   .QueryInterface rd 1
   .AddRef rd 1
   .Release rd 1
ends

struct IDirectSoundBuffer
   . IUnknown
   irp methods,GetCaps,GetCurrentPosition,GetFormat,GetVolume,GetPan,GetFrequency,\
               GetStatus,Initialize,Lock,Play,SetCurrentPosition,SetFormat,\
               SetVolume,SetPan,SetFrequency,Stop,Unlock,Restore
   {
      .#\.#methods rd 1
   }
ends

struct IDirectSoundBuffer8
   . IDirectSoundBuffer
   irp methods,SetFX,AcquireResources,GetObjectInPath
   {
      .#\.#methods rd 1
   }
ends

ids8            IDirectSound8
idsb            IDirectSoundBuffer
idsb8           IDirectSoundBuffer8    

_________________
This is a block of text that can be added to posts you make.
Post 31 Oct 2010, 15:00
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 31 Oct 2010, 15:11
mindcooler: why the second dot?
Post 31 Oct 2010, 15:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 31 Oct 2010, 15:12
Which second dot?

edit:

You mean .#\.#methods rd 1 ?

. for name, \. for "."

name.method
Post 31 Oct 2010, 15:12
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 31 Oct 2010, 16:50
mindcooler,

Inheritance can be done like this:
Code:
macro struct [args] {
common
  local !
  ! equ ?
  match derived:base, args \{
    restore !
    struct derived
      base
  \}
  match =?, ! \{
    restore !
    struct args
  \}
}    
You can irp through base for multiple inheritance.
Post 31 Oct 2010, 16:50
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 31 Oct 2010, 17:22
I don't understand much what's going on in either macro, so perhaps it's best for me to cut'n'paste instead Razz

Can't even get this to work:

Code:
struct IDirectSoundBuffer
   irp methods,QueryInterface,AddRef,CreateSoundBuffer,GetCaps,\
               GetCurrentPosition,GetFormat,GetVolume,GetPan,GetFrequency,\
               GetStatus,Initialize,Lock,Play,SetCurrentPosition,SetFormat,\
               SetVolume,SetPan,SetFrequency,Stop,Unlock,Restore
   {methods rd 1}   <--- Error: extra characters on line?
ends    

_________________
This is a block of text that can be added to posts you make.
Post 31 Oct 2010, 17:22
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 31 Oct 2010, 17:33
mindcooler,

restore is a reserved word.
Post 31 Oct 2010, 17:33
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 31 Oct 2010, 17:44
So I can't even make hardcoded structs..
Post 31 Oct 2010, 17:44
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 31 Oct 2010, 19:03
mindcooler,

Probably Tomasz will bother to make those reserved words to be context-sensitive, not reserved anyway.
Post 31 Oct 2010, 19:03
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 31 Oct 2010, 21:29
I think I'll keep my interface macro until my macro-fu is up to par.
Post 31 Oct 2010, 21:29
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 31 Oct 2010, 22:19
baldr wrote:
mindcooler,

Probably Tomasz will bother to make those reserved words to be context-sensitive, not reserved anyway.
They are.
Code:
label restore
jmp restore    
Post 31 Oct 2010, 22:19
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.