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
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]
Bookmarks