News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Blocks and Bricks: A light OOP System

Started by HSE, November 10, 2023, 01:09:25 AM

Previous topic - Next topic

HSE

Hi all!

  Something ugly of OOP programation is big size of binaries because all Object code is included in binaries, even if never used.

  A basic Object is just an structure in memory. There is a couple of pages about objects in Assembly from Randy Hyde in 1989 or so, but I can't find now (If somebody have at hand, I will preciate that).

  More usefull Object store addresses of related procedures. Then procedure code must be in binary.

  The idea of this elemental system is to have related procedures but not to store that addresses, instead macros must to know Structure-Procedure relation.

    Because initially this is thought like an auxiliary system, I can name things like object, method, etc. If there are better non-conflicting names for that, also I will preciate :biggrin:  :
    Block prueba
        Def_item dato1, dword, 10
        Def_item dato2, dword, 20
    BlockEnd

    Brick print1, xsi
        SaveRegs
        SetBlock xsi
        conout str$(dword ptr [xsi].prueba.dato1),lf,lf
        RestoreRegs
    BrickEnd

Obviously, Block is the object and Brick is the method (a procedure writed "Brick name, uses, pointer, arguments).

Main point of objects is to build a new object from a previous one:
    Block pocomas, prueba
        Def_item dato3, dword, 55
    BlockEnd

    Brick print3, xdi
        SaveRegs
        SetBlock xdi
        conout str$(dword ptr [xdi].pocomas.dato3),lf,lf
        RestoreRegs
    BrickEnd

This Block have to be loaded to memory like any object, and referenced by addresses. To deal with inheritance BCall must be used for methods (BCall object, method, pointer, arguments):
    SystemBlockInit

    NewBlock prueba
    mov item1, xax
       
    NewBlock pocomas
    mov item2, xax

    BCall pocomas, print1, item2
    BCall pocomas, print3, item2

    DestroyBlock item1
    DestroyBlock item2

Ideas are welcome  :thumbsup:

Regards, HSE.
Equations in Assembly: SmplMath

TimoVJL

conditionally compiled / assembled code can remove useless code with stubs.
May the source be with you

HSE

Quote from: TimoVJL on November 10, 2023, 11:54:56 PMconditionally compiled / assembled code can remove useless code with stubs.

:thumbsup:

The problem is that you can have hundreds of methods/procedures, and I fail to think a razonable way to do the conditionality.

Previously I forget to mention that test can be build with ML/Masm32 SDK and ML64/Masm64 SDK.
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on November 11, 2023, 12:32:03 AMthat test can be built with ML/Masm32 SDK and ML64/Masm64 SDK

It works :thumbsup:

When will you post the English version? :biggrin:

HSE

Quote from: jj2007 on November 11, 2023, 03:51:56 AMIt works :thumbsup:

Thanks for report :thumbsup:

Quote from: jj2007 on November 11, 2023, 03:51:56 AMWhen will you post the English version? :biggrin:

I don't know. In English could look to much easy  :biggrin:
Equations in Assembly: SmplMath

Biterider

Hi HSE
Interesting idea.  :thumbsup:
I'll look into the details at the weekend. 
What I've seen so far is that you call directly and avoid a virtual table completely.

Biterider

HSE

Quote from: Biterider on November 11, 2023, 05:41:19 AMWhat I've seen so far is that you call directly and avoid a virtual table completely.

 :thumbsup:
Equations in Assembly: SmplMath

Biterider

Hi HSE
I looked a little deeper into the code and found it really good.  :biggrin:
Your approach is to make all calls static eliminating all indirections. That's good and saves some execution speed.

What I'm not sure about is looking into inheritance, how an ancestor code is called. 
Another feature that will work is polymorphism, but atm I don't know how such a call will look like...

Good stuff!  :thumbsup:

Biterider


HSE

Hi Biterider!

Quote from: Biterider on November 12, 2023, 10:41:12 PMWhat I'm not sure about is looking into inheritance, how an ancestor code is called.
:biggrin: I forgot to discriminate that, because logical names ACall, ICall, etc are used in ObjAsm. Then now is Heritage call: HCall (updated in first post)

Quote from: Biterider on November 12, 2023, 10:41:12 PMAnother feature that will work is polymorphism, but atm I don't know how such a call will look like...

I thinking in conceptual levels for Objects Systems:

  • Level 0: structure in memory, with related procedures.
  • Level 1: inheritance of structure and procedures (extends in Java) without virtual table. 
  • Level 2: procedure polymorphism.
  • Level 3: structure and procedure additions, or multiple inheritance if you like (implements in Java)
  • level 4: complete virtual procedure table
  • level 5: templates
  • level 6: something else?

Note that ObjAsm is "level 5 or more" except "level 3"

Also you can see that I'm uploading Block_L1.inc  :biggrin:

I can't think how to make polymorphism without a partial virtual procedure table, then "Block_L2.inc" build a partial table. No escape because I need polymorphism in a couple of programs  :rolleyes: 

If there is a better idea...

I also think that multiple inheritance can easily be added to ObjAsm, but I have to play with that in this more simple system.

Thanks, HSE.
Equations in Assembly: SmplMath

Biterider

Hi HSE
Level 3 does indeed have good potential for discussion. 
I remember reading an article by a development team at Google where they wrote that they were moving away from inheritance because they wanted to flatten the inheritance path. The solution they came up with was "gluing" objects together in the form we know in ObjAsm as "Embed".
They claimed that their approach allows them to keep a better overview and avoid jumping around the inheritance ladder, making the code more efficient.

Biterider

HSE

Quote from: Biterider on November 13, 2023, 04:36:06 AMLevel 3 does indeed have good potential for discussion.

:thumbsup:

Quote from: Biterider on November 13, 2023, 04:36:06 AMThe solution they came up with was "gluing" objects together

Yes, for specific purposes have no sense inheritance at machine code level, preprocessor can deal with that :biggrin:

Equations in Assembly: SmplMath

HSE

Hi all!

This is Level 2, with polymorphism.

For example, 2 differents objects descendents of "prueba":
    BCall prueba, print2, item3
    BCall prueba, print2, item4

result in:
----- polymorphism test -----

20
This is otromas

Press any key to continue ...

If you remember that "print2" is polymorphic, requiere less preprocess to use Polymorphic call: PCall:
    PCall prueba, print2, item3
    PCall prueba, print2, item4

Regards, HSE.
Equations in Assembly: SmplMath

Rockphorr

Hi!

Any light OOP System will grow up to the monster-size OOP System.

I use a pointer to the structure in the register, so in the method all operations look like:

mov AX,(struc_name PTR [reg_name]).struc_member


How do you implement the heap of objects ?? Is it a list or a tree or a array or something else ?

When I using a register that points to structure I think that may be implement a handle for the object in the heap.

HSE

Hi,

Quote from: Rockphorr on December 26, 2023, 08:23:31 AMAny light OOP System will grow up to the monster-size OOP System.

The complete OOP System I use is ObjAsm, this must be more simple.


Quote from: Rockphorr on December 26, 2023, 08:23:31 AMI use a pointer to the structure in the register

Is just that  :thumbsup:


Quote from: Rockphorr on December 26, 2023, 08:23:31 AMHow do you implement the heap of objects ?? Is it a list or a tree or a array or something else ?

Can be implemented how you want.


Quote from: Rockphorr on December 26, 2023, 08:23:31 AMWhen I using a register that points to structure I think that may be implement a handle for the object in the heap.

Obviously.

Thanks.
Equations in Assembly: SmplMath

TimoVJL

Global OOP optimizer could remove useless code and zero unused methods.
May the source be with you