Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: STATIC elements in UDT

  1. #11
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: STATIC elements in UDT

    I understand it will take time Eros, but the water under the bridge at least is flowing in the right direction
    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

  2. #12

    Re: STATIC elements in UDT

    Setting up OOP structures and function calls is very easy. Managing OOP syntax is the more complicated part. But with sophisticated support for UDTs in thinBasic, most of the work is already done!

    Bearing in mind that everything has to be woven into the interpreter, I would implement OOP (with minimal ASM) something like this:

    [code=thinbasic]

    type object_class
    pvft as long
    ' other elements
    a as long
    b as long
    end type

    'CREATE VIRTUAL FUNCTIONS

    function fun1(this as object_class, [other params]) as [return type]
    this.a=
    ...
    end function

    function fun2(this as object_class, [other params]) as [return type]
    ...
    end function


    'CREATE VIRTUAL FUNCTION TABLE

    dim virt_fun_table(n) as long

    virt_fun_table(0) =codeptr(fun1)
    virt_fun_table(1) =codeptr(fun2)

    'CREATE VIRTUAL TABLE POINTER

    dim pvft as long
    cpvft=vartptr(virt_fun_table(0))


    'CREATING OBJECTS

    dim ob as object_class

    ' each object initialised with its class vft pointer

    ob.pvft=cpvft

    CALLING THE CLASS FUNCTION GENERICALLY:

    '1: get the function pointer from the table

    dim absolute vft(n) as long at ob.pvft
    fun=vft(1)

    '2: push the params onto the stack in reverse order
    'if you are passing params BYREF then push the param address onto the stack instead.

    a=varptr(param2)
    ! push a
    a=varptr(param1)
    ! push a

    '3: then push self last of all

    a=varptr(ob)
    ! push a

    '4: then make the call

    ! call fun





    [/code]

Page 2 of 2 FirstFirst 12

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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