Declare a CLASS:


CLASS CEmbed
VIRTUAL METHOD Dtor
VAR I:DWORD
CLASS END

METHOD CEmbed::Dtor
PrintText "Dtor of CEmbed"
ret
METHOD END

CLASS CBase
VAR I:DWORD
METHOD Ctor
METHOD Dtor
VAR E:CEmbed
VIRTUAL METHOD Show
CLASS END

METHOD CBase::Ctor
PrintText "Ctor of CBase"
push edi
VIA lpTHIS, edi
mov lpTHIS_I, 100
pop edi
ret
METHOD END

METHOD CBase::Dtor
PrintText "Dtor of CBase"
ret
METHOD END

METHOD CBase::Show
PrintText "Show of CBase"
ret
METHOD END

CLASS CDerive:CBase
VIRTUAL METHOD Show
CLASS END

METHOD CDerive::Show
PrintText "Show of CDerive"
push edi
VIA lpTHIS, edi
PrintDec lpTHIS_I
pop edi
ret
METHOD END
Using a CLASS:


TestProc Proc uses edi esi
VAR pCBase:PTR CBase
NEW pCBase, CDerive
VIA pCBase, edi, esi
invoke pCBase_Show
DESTROY pCBase
ret

TestProc endp

Have a look at it , you will get something interesting:alright:
Posted on 2003-05-24 03:49:26 by taowen2002
MOOP
-Macro based OOP model
First of all, I want to say It's a under construction project, and need your advice and help. My E-mail address is mo2mo@163.com, and other approaches to get in touch with me are listed below:
E-mail: mo2mo@163.com
QQ: 81711382(not ICQ, I didn't have a icq number)
Address: 100081, 07120202 BIT Beijing China
Phone: 010-68920851

I am not a professional programmer, just code for fun. The MOOP is a experimental project to test the power of MACRO, and how to build a system of OOP. Now, the partial result has come out that the power of MACRO is so powerful that a very complete OOP model can be implement. Many people doubt the meaning of this project for serval reasonable reason. I thought I just started it for fun, and continued the development for the rare experience and adventure. Maybe the MOOP can finally help the asm coder to organize their code better by the power of abstract. Or the MOOP may help asm coder to facilitate the component constructed upon COM. But just some idea about the future usage, now, it is just a experimental project. But I believe, at least, you can see what OOP really is by the asm level implemention, and evaluate the overhead and benefit brought by the OOP better.

The principle of the original design is "the syntax should be as comprehensive as possible, and no unnecessary overhead should be introduced". Although the syntax of MACRO itself limited some aspect of the design, but in general, I nearly achieved the goal. Before this model, many people have tried OOP model using MACRO function provided by various language, especially I have seen many good example written in MASM. And in fact, I started this project from a small modification of Nan and Thomas's OOP model. They works quite well, but still with many things to be improved(this is true for my model, it needs to be improved). Some syntax was not quite clear, some is just to complex, some needs lacks some importent feature(such as non-virtual function). I am not to say that my model is the best, no, that is surely no true. But with some effort, I achieved some good feature.

I learned the basic tool from the Nan and Thomas's work. They showed me how powerful macro can be, and how asm may faciilitate the OOP. Especially the agent example made a deep impression in my mind. MACRO serves as a preprocessor before assemble. The MACRO in MOOP just translate the statement with OOP feature into normal asm code. The same translation can be done manually, but hard to do. The macro just come to help you do the repetitive work.

I started how to use it by a example:



CLASS CBase
VAR I:DWORD
METHOD Show
CLASS END

METHOD CBase::Show
push edi
VIA lpTHIS, edi
PrintDec lpTHIS_I
pop edi
ret
METOHD END

TestProc Proc uses edi, esi
VAR pCBase:PTR CBase
NEW pCBase, CBase
VIA pCBase, edi, esi
invoke pCBase_Show
DESTROY pCBase
ret
TestProc Endp


The code can be divided up to 3 parts, the declaration of the class, the definition of the member method, using the class by creating a object of the class. I will explain them part by part

1. How to declare a class
using class to begin a declaration and end the declarartion by END
CLASS CBase
CLASS END
the name of the class follow the CLASS, if you inherit from on class, using : between the name. CDerive:CBase for example. I will explain how to use inheritance later.
to declare a member variable, using VAR. VAR can be used to declare a member of class, and used to replace the LOCAL(but more powerful). the name is the left of :, and the type of the var is in the right. the type can be a existing class.
declare a member method using the METHOD. The name of the method immediately follow the METHOD macro, and append the parameter list follow the mname, comma should be used. If the method is virtual, you should use VIRTUAL METHOD to declare the method, and VIRTUAL METHOD also override method if the same name existed in the base class.

2. How to define a member method
METHOD CBase::Show
METHOD END
between METHOD, it is the same content between proc. CBase indicate the method belongs to CBase. Parameter should be written again in the definition, and should be identical to the declaration.

3. How to create a object
before creating a object, you should prepare a pointer to store the pointer of the object. Currently, you can only create a object in heap. Stack based object, or object in data segment may be introduced in the future. The pointer must be declared by VAR in the place which should be LOCAL.
VAR pCBase:PTR CBase
PTR CBase indicates the pCBase is a pointer to CBase.
NEW pCBase, CBase

4. How to use a object
A pointer to instance of CBase will be stored in pCBase. But you can not access the content of the object via ptr conveniently. You should use VIA to ease the use. Without VIA, you have to know so much detailed info of the implemention of object. VIA just specify the register to store the pointer to the object, and pointer to the vtbl of the object. If you do not use virtual function, you can ommit the second reg param, and if you do not use the member variable directly, you can ommit both regs. After calling the VIA, you can access the field of the object by pCBase_Show like syntax. The _ is the equivalence of -> in C++. You must guarantee the content of the register you provide do not be changed during using the object or unexpected result will happen.

5. How to destroy a object
simply use DESTROY following the pointer to the object.

After a quick look at the usage of MOOP, you can see it is quite simliar to C++. I did not intend to implement another C++ object model using MACRO, but just the simple part of it, and some other features brought from other language.
Posted on 2003-05-25 02:35:46 by taowen2002
. .
Posted on 2003-08-23 11:00:41 by NaN
Very helpful , taowen ! very helpful !

btw : the man in pic is your newest pic ?
Posted on 2003-08-26 02:16:25 by dreamweaver