flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > who can use my example make a OOP macro?

Author
Thread Post new topic Reply to topic
zjlcc



Joined: 23 Jul 2003
Posts: 32
Location: china
Code:
format PE GUI 4.0

include '%include%/WIN32A.INC'

struc TObj { 
  .F1           db 1 
}
struct TObj
 
struc TBtn1 { 
  .F1           db 1 
  .Draw         db 2 
  virtual at .F1                ;inherit TObj 
    .TObj TObj 
  end virtual                                            
} 
struct TBtn1
 
struc TBtn2 { 
  .F1           db 1 
  ._TBtn1Draw   db 2            ;use '_TBtn1'+'Draw' to hide 'TBtn1.Draw' method 
  .Draw         db 3            ;overlay TBtn1.Draw method 
  virtual at .F1                ;inherit TObj 
    .TObj TObj 
  end virtual                                            
  virtual at .F1                ;inherit TBtn1 
    .TBtn1 TBtn1 
  end virtual                                            
} 
struct TBtn2 
;...more inherit to TBtnX
start:
xor eax,eax 
mov AL,[BTN.F1]                 ;AL=1 
mov AL,[BTN.TBtn1.F1]           ;AL=1 
mov AL,[BTN.TBtn1.TObj.F1]      ;AL=1 
mov AL,[BTN.Draw]               ;AL=3 \ 
mov AL,[BTN.TBtn1.Draw]         ;AL=2 /object`s Polymorphism property 

ret

BTN TBtn2 
    
Post 19 May 2004, 12:31
View user's profile Send private message Reply with quote
zjlcc



Joined: 23 Jul 2003
Posts: 32
Location: china
but can not make "overlay"
Code:
format PE GUI 4.0 

entry start 

include '%include%/WIN32A.INC' 
include 'dbg.INC' 
macro overlay basetype,name
{
  _#basetype#.#name=1
}
macro let basetype,name,[var]
{
   if defined _#basetype#.#name
      if _#basetype#.#name=1
         display 2h
         label name#_
         _#basetype#.#name=0
      else
         label name
      end if
   else
      label name
   end if
   common
    var
}
struc TPoint
{
  .x dd 8
  .y dd 9
}
;====================
macro _kk1{
 label ._b_
 .a dd 1
 .t TPoint
}
struc kk1{
 _kk1
}
struct kk1
;====================
macro _kk2{
 _kk1
 .b dd 2
}
struc kk2{
 _kk2
 virtual at ._b_ 
   .kk1 kk1 
 end virtual                                            
}
struct kk2
;====================
macro _kk3{
 _kk2
 .c dd 3
}
struc kk3{
 _kk3
 virtual at ._b_ 
   .kk2 kk2 
 end virtual                                            
}
struct kk3
;====================
start:

  xor eax,eax
  xor eax,eax
  mov eax,[m.a]         ;1
  mov eax,[m.b]           ;2
  mov eax,[m.kk1.a]       ;1
  mov eax,[m.kk1.t.x]     ;8
  mov eax,[m.t.y] ;9
  nop
  mov eax,[o.a]          ;1
  mov eax,[o.b]           ;2
  mov eax,[o.c]           ;3
  mov eax,[o.kk2.b]       ;2
  mov eax,[o.kk2.kk1.a]   ;1
  nop
  mov eax,[p.a]          ;1
  mov eax,[p.b]           ;2
  mov eax,[p.c]           ;3
  mov eax,[p.kk2.b]       ;2
  mov eax,[p.kk2.kk1.a]   ;1
  
  
ret 

m kk2
o kk3
p kk3

    
Post 22 May 2004, 10:29
View user's profile Send private message Reply with quote
halyavin



Joined: 21 Aug 2004
Posts: 42
What about this? It's my OOP macro library based on another idea.
I think you can easily extend it as you wish.
Code:
;for internal macro use - we can't use # in embedded macros
macro addlabel x,y
{
  x#.#y:
}
macro struct name
 { virtual at 0
   name name
   sizeof.#name = $ - name
   name equ sizeof.#name
   end virtual }
macro fields parent,object,[fields,dir]
{
  common
    macro object#_fields obj
    %_
      parent#_fields obj
    _%
  forward
    macro object#_fields obj
    %_
      object#_fields obj
      addlabel  obj,fields
      dir
    _%
  common
    struc object
    %_
    object#_fields
    _%
    struct object
}
macro tvm_define object,name
{
  dd object#.#name
}
tvm_offset=0
macro tvm parent,object,[method]
{
  common
    macro object#_tvm name ;return value in tvm_offset
    %_
      parent#_tvm name
    _%
    macro object#_tvm_include name
    %_
      parent#_tvm_include name
    _%
  forward
    display 'parameter used',13,10
    parent#_tvm method
    if (tvm_offset < 0)
      display 'case 1',13,10
      ;new method
      macro object#_tvm name
      %_
        if (name eq method)
          object#_tvm .sizeof
        else
          object#_tvm name
        end if
        if (name eq .sizeof)
          object#_tvm .sizeof
          tvm_offset=tvm_offset+4
        end if
      _%
      macro object#_tvm_include name
      %_
        display 'add',13,10
        object#_tvm_include name
        fixtable parent,object,name,method
      _%
    end if
}
macro fixtable parent,object,name,method
{
  parent#_tvm method
  if (tvm_offset < 0)
    tvm_define object,method
  else
    display 'store used',13,10
    store dword object#.#method at name#.tvm+tvm_offset
  end if
}
macro tobject_tvm name
{
  if (name eq .sizeof)
    tvm_offset=0
  else
    tvm_offset=-1
  end if
}
macro tobject_tvm_include name
{
  name#.tvm:
}
;use include 'fix.inc' at the end of macro section
%_ fix {
_% fix }
macro tobject_fields obj
{
  obj#.self:
  rd 1
}
fields tobject,my,x,dd 0x90909090
my_object my
tvm tobject,my,add,sub
my_tvm_include my
my.add:
  nop
  ret
my.sub:
  nop
  ret
fields my,child
my_child_object child
tvm my,child,add,mul
child_tvm_include child
child.add:
  nop
  ret
child.mul:
  nop
  ret    

Use hiew to see result. Cool
Post 21 Aug 2004, 05: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-2019, Tomasz Grysztar.

Powered by rwasa.