Oxygen Basic
Programming => Problems & Solutions => Topic started by: Mark0 on March 09, 2011, 07:50:14 AM
-
Maybe it's a bit of a stupid question but...
If the oxygen code contain something like "print mystring", o2_exec return a pointer to that string.
It's intentional or a collateral effect?
Thanks,
Bye!
-
Hi Marco,
When Oxygen executes as an embedded system it returns the value last assigned to the eax register. (When terminating Basic, this register is stacked while Oxygen releases all its libraries and memory allocations. then it is popped just before returning.)
Thinking of bindings to the host - this is am effective way of returning a pointer to any static workspace. A table of function pointers could be placed in a static array, then the base address is returned to the host.
Would this be useful for Python ?
Charles
-
To illustrate how this might work:
dim as sys table[10] 'an array for the function addresses
function foo() export
print "foo!"
end function
function bar() export
print "bar!"
end function
'
'this procedure explicitly releases Oxygen resources
'and is invoked when the host has finished with this program.
'
sub finish() export
terminate
end sub
'fill the table with function addresses
table<=& finish, & foo, & bar
'test foo and bar
'
'f=table[2] : call f
'f=table[3] : call f
'effectively leave the base address of table in the eax register
'a=& table
'or you can use assembler directly
lea eax,table
/*
PSEUDOCODE:
host side
o2_asmo source
base address of table=o2_exec
address of finish=table[1]
address of foo=table[2]
address of bar=table[3]
foo()
bar()
finish()
*/
Charles
-
That sounds nice!
Many thanks for the explanations!
-
Thanks Marco,
I should mention that the '<=' notation is new to the Alpha 29 version I uploaded yesterday.
'fill the table with function addresses
table<=& finish, & foo, & bar
prior versions use '=>' which of course points in the wrong direction! FreeBasic does it this way and Oxygen will still accept it.
Charles