Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Further Developments in Asmosphere III

  1. #1

    Further Developments in Asmosphere III

    Built in Object Oriented Programming Model

    Unlike previous models this does not rely on user defined macros. It uses virtual tables and pointers in a similar manner to COM. OOP is built into the Asmosphere preprocessor, taking care of all the tricky bits.

    This model also supports multiple inheritance - ie a class can have several ancestors.

    The extra notation required is minimal. In fact the words class and object are not used at all. The system is an extension of type.

    To declare a class, the type statement is divided into 2 parts: The first part contains methods, inherited structures and class static members. The second part contains the set of properties assigned to each object, (inherited properties are automatically appended)

    This is a class defined in a single line: ! denotes a method. / divides the two parts of the class, and inherited types must be followed by a comma as usual.

    type classAB classA, classB, 4 methodA! 4 methodB! 4 MethodC! membA / 4 vft 4 va 4 vb 4 vc

    this is immediately followed by a scoped class builder and a set of methods

    (
    build classAB
    exit
    var ClassAB this

    methodA:
    ...
    ret 4

    methodB:
    ...
    ret 4

    ...

    )


    to create an object:

    var ClassAB myObject
    myObject.vft=&ClassAB_table


    which gives us an empty object except for its virtual table pointer, which allows the object to call any of its methods, (including inherited methods)


    edx=myObject.methodA ...

    Because all the methods are defined inside the brackets, they are not visible to the rest of the program.

    Below is a simple piece used to test the basic functionality of the model. To use it you will need the new Oxygen:

    http://community.thinbasic.com/index.php?topic=1845.0


    [code=thinbasic]
    ' OOP with virtual tables


    uses "OXYGEN"
    uses "FILE"

    dim vv as long
    dim src as string

    src="
    indexers `esi` offset 0 ascending
    esi=dataspace 0x100
    type ClassA 4 a1! 4 a2! 4 fstatic / 4 pvft 4 pep 4 pip
    (
    build ClassA
    exit
    var classA this
    a1:
    this=&ClassA_Table
    ret 4
    a2:
    this=&ClassA_Table
    inc this.pip
    ret 4
    )
    type ClassB 4 b1! 4 b2! / 4 pvft 4 pep 4 pip
    (
    build ClassB
    exit
    var classB this
    b1:
    this=&ClassB_Table
    mov eax,66
    ret 4
    b2:
    this=&ClassB_Table
    inc this.pip
    ret 4
    )
    type classAA classA, 4 fna! 4 fnb! 4 fnc! 4 fstatic classB, / 4 pvft 4 aa 4 bb
    (
    build classAA
    exit
    var ClassAA this
    o2 /+4
    fna:
    this=&ClassAA_Table
    inc this.aa
    [#vv]=sizeof ClassAA
    ret 4
    fnb:
    this=&ClassAA_Table
    ret 4
    fnc:
    this=&ClassAA_Table
    ret 4
    )
    var classAA myobject
    myobject=&ClassAA_table


    ecx=myobject.fna ; test method fna
    ecx=myobject.fnb ; test method fnb
    [#vv]=myobject.b1 ; test inherited method
    ret

    "
    'msgbox 0,o2_view (src)
    o2_asmo src
    if len(o2_error) then
    msgbox 0,"OOP1: "+o2_error()+o2_view (src)
    stop
    end if
    o2_exec
    msgbox 0,"0x"+hex$(vv)


    [/code]

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,086
    Blog Entries
    5
    Rep Power
    725

    Re: Further Developments in Asmosphere III

    I knew you are working on something.
    Looks cool, it will take me some time to understand it fully though


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    Re: Further Developments in Asmosphere III

    Well it certainly kept me very quiet for a few days and I can't say it was easy but I think its the only way to really understand this genre of programming. I have not looked at COM for some time now - but it should be possible to create COM objects cleanly as well as implementing more generalised OOP, since similar structures are used in C++.

    The invisible work done by the system takes care of constructing tables of function pointers (virtual functions) and organising the elements of inherited structures in general. This was really too complicated to handle in macros so it made sense to internalise it.

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    65
    Posts
    3,869
    Rep Power
    401

    Re: Further Developments in Asmosphere III

    Charles thanks you always seems to shock in a positive way!

    I don't understand how this works:

    type classAA classA, 4 fna! 4 fnb! 4 fnc! 4 fstatic classB, / 4 pvft 4 aa 4 bb

    In your first post, this I could sort of follow as to what is what:

    type classAB classA, classB, 4 methodA! 4 methodB! 4 MethodC! membA / 4 vft 4 va 4 vb 4 vc

    So could the code in the script be written as:
    type classAA classA, classB, 4 fna! 4 fnb! 4 fnc! 4 fstatic / 4 pvft 4 aa 4 bb



    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #5

    Re: Further Developments in Asmosphere III


    Yes Kent, I should clarify that following type the first name is the class you are creating and anything after that is an element or inherited type. It may help if i write it in block form:

    type ClassAA
    (
    classA, ; inherited class
    classB, ; inherited class

    4 methodA! ; method pointer added for this class (note the ! suffix)
    4 methodB! ; another

    4 fstatic ; a static class member ( no ! suffix)
    ; this becomes accessible as 'ClassAA_table.fstatic'

    / ; object members:

    4 pvft ; pointer to the virtual function table (always present)
    4 va ; a property
    4 vb ; another property
    4 vc ; ...

    )

  6. #6

    Re: Further Developments in Asmosphere III

    Unions:


    type tvec 4 x 4 y 4 z 4 w = 4 red 4 green 4 blue 4 alpha

    any number of unions are possible in a type statement. Here is another in block form

    type tvec4
    (
    4 x 4 y 4 z 4 w
    =
    4 red 4 green 4 blue 4 alpha
    =
    4 cyan 4 magenta 4 yellow 4 alpha
    =
    16 v
    )




    Assignments

    Most programming involves moving values from one variable to another - so building the assignment operator in the Assembler can greatly decrease the line count. Though the '=' sign still has a restricted meaning, its functionality has been extended to include most 32 bit assignments via the eax register.

    a=b

    is translated as:

    mov eax,b
    mov a,eax


    String literals are represented by their starting address, so it is possible to say

    var 4 a
    a=`hello world`


    a can then be used directly many sdk calls which take a string pointer.)
    (string literals are always terminated with 2 nulls.

    Addresses


    c=&d

    this is the equivalent of c=varptr(d)


    Indirection

    **a=*b

    the PB equivalent of this is @@a=@b





    Once again a new version:
    _________________________________________________
    http://community.thinbasic.com/index.php?topic=1845.0







  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,086
    Blog Entries
    5
    Rep Power
    725

    Re: Further Developments in Asmosphere III

    Thanks a lot Charles,

    this kind of simplifications make asm much more attractive.
    Freedom of choice whether to stay cool and write raw assembly or just make life less complicated and use simplified syntax is why I like Oxygen module a lot


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8

    Re: Further Developments in Asmosphere III

    Charles,
    Sorry if this is out of place but can Asmosphere be used by other systems other than ThinBasic?
    I've been toying around with tcc and the classes would be fun to use(actually play with).

    James

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    54
    Posts
    8,636
    Blog Entries
    2
    Rep Power
    10

    Re: Further Developments in Asmosphere III

    James,

    inside Oxygen there are FreeBasic sources of thinBasic module. It should not be complex to compile as generic DLL.

    In any case have a look at: http://www.jose.it-berater.org/smffo...hp?board=154.0

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  10. #10

    Re: Further Developments in Asmosphere III

    Hi James,

    I am running behind on the standalone version of Oxygen. thinBasic has the leading edge and is actually a very good environment for developing and testing modular software.

    Oxygen.bas (included in the version on the JRS forum) replaces the thinBasic.bas top end for use as a conventional DLL. I compile this in sync with the thinBasic version but my packaging and testing scheme for this needs a little more work.

Page 1 of 4 123 ... LastLast

Similar Threads

  1. Further Developments in Asmosphere I.
    By Charles Pegge in forum Legacy
    Replies: 78
    Last Post: 21-06-2008, 00:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •