Author Topic: What does o2_exec return exactly?  (Read 2166 times)

0 Members and 1 Guest are viewing this topic.

Mark0

  • Newbie
  • *
  • Posts: 3
    • Mark0.net
What does o2_exec return exactly?
« 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!

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4097
    • Oxygen Basic
Re: What does o2_exec return exactly?
« Reply #1 on: March 09, 2011, 09:07:22 AM »
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

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4097
    • Oxygen Basic
Re: What does o2_exec return exactly?
« Reply #2 on: March 10, 2011, 02:15:10 AM »

To illustrate how this might work:

Code: [Select]

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

Mark0

  • Newbie
  • *
  • Posts: 3
    • Mark0.net
Re: What does o2_exec return exactly?
« Reply #3 on: March 10, 2011, 05:15:03 AM »
That sounds nice!
Many thanks for the explanations!

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4097
    • Oxygen Basic
Re: What does o2_exec return exactly?
« Reply #4 on: March 10, 2011, 05:53:19 AM »
Thanks Marco,

I should mention that the '<=' notation is new to the Alpha 29 version I uploaded yesterday.

Code: [Select]
'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