Hi Bryant,
Hi Klod, Always good to hear from you man.
I have been playing around with your code sample for the last few days.
C:\NasmEd\Project\NasmObject>mak
Assembling main.asm
MyObject.inc:11: warning: (static:20) CTest_static_data_0_size 4
MyObject.inc:13: warning: (endclass: CTest_total_virtual_methods 1
MyObject.inc:13: warning: (endclass:9) CTest_total_static_methods 2
Assembling myObject.asm
myObject.inc:11: warning: (static:20) CTest_static_data_0_size 4
myObject.inc:13: warning: (endclass: CTest_total_virtual_methods 1
myObject.inc:13: warning: (endclass:9) CTest_total_static_methods 2
I noticed that CTest_total_static_methods = 2, yet there are 3 static methods defined. I assume that ctor is handled different?
That's right. This is because there are two possible ctors. There is an internal ctor which is created for every class %{1}___%{1} and a user defined ctor which only appears when the user wishes to preform some run-time initialization , %{1}_%{1}.
The internal ctor handles setting up all the pointers that the class will be dependent on for invoking methods. The user ctor, although it is a static method, doesn't appear as part of the CTest_total_static_methods definition because it doesn't need to be. The internal constructor uses those symbols (%{$name}_*_static_* and %{$name}_*_virtual_*) to preform the updating of the pointers of the class memory. Because the user ctor is invoked directly, it's not required to be updated as part of this and is not included.
I could not quite figure out how you implemented the class definition so that its members can be inherited by derived classes. I expected similar definitions like for struc definitions. I assume CTest_static_data_0_size (4) and CTest_static_data_N_size to be offsets and _total_static_methods be the upper limit. The parent class had been defined in an other context but it can be inherited by means of the above defines? The Total size of the Class is then the sum of number_of_static_methods, number_of_virtual_methods, number_of_static_members, number_of_virtual_members.
Well, the idea is pretty simple, as you have no doubt figured out, I'm creating a description of the class using these symbols, and when I reach the ENDCLASS macro I use ABSOLUTE directly to create a structure (basically the way STRUC does internally).
For inheritance, I'm keeping a list of what parents, if any, each class has. At the beginning of the definition in the CLASS macro, I loop through all the parents and copy the values of these symbols into the symbols for my current class. This basically extends my class automatically.
%if %0 = 2
%[%{$name}]_has_parent equ 1
%define %[%{$name}]_parent %{2}
%define %$parent %2
%if %{1}_has_parent > 0
%[%{$name}]_parent_count equ (%[%{$parent}]_parent_count + 1)
%else
%[%{$name}]_parent_count equ 1
%endif
%assign %$number_of_virtual_methods %[%{$parent}]_total_virtual_methods
%assign %$number_of_virtual_members %[%{$parent}]_total_virtual_members
%assign %$ii 0
%rep %{$number_of_virtual_methods}
%define %[%{$name}]_virtual_method_%[%{$ii}]_full %[%{$parent}]_virtual_method_%[%{$ii}]_full
%define %[%{$name}]_virtual_method_%[%{$ii}] %[%{$parent}]_virtual_method_%[%{$ii}]
%assign %$ii %{$ii} + 1
%endrep
%assign %$ii 0
%rep %{$number_of_virtual_members}
%define %[%{$name}]_virtual_data_%[%{$ii}]_size %[%{$parent}]_virtual_data_%[%{$ii}]_size
%define %[%{$name}]_virtual_data_%[%{$ii}] %[%{$parent}]_virtual_data_%[%{$ii}]
%assign %$ii %{$ii} + 1
%endrep
%else
%[%{$name}]_has_parent equ 0
%[%{$name}]_parent_count equ 0
%endif
Also take a look at the BUILD_CLASS_STRUCTURE macro which creates the actual memory imprint for the class (and makes use of the inherited symbols). You'll notice in that macro a call to another macro called INHERIT_PARENT_DATA, this ensures that our inherited classes come before our current class data in memory, but our current class's VDT/VMT and Dtor come before our inherited data.
.vmt and vdt would be the first 2 elements (pointers) to their respective tables.
Call %{1}_%{1} call to ctor either default or user defined
I haven't yet build a project using your model but think it is a good start. Waiting to see your next update.
Klod
I'm actually working on something else atm, so an update won't be real soon. This project is something I've been doing off and on for some time now. I just thought since it was showing some form of progress I would post it.