Author Topic: O2 JIT function calls  (Read 6731 times)

0 Members and 2 Guests are viewing this topic.

JRS

  • Guest
O2 JIT function calls
« on: May 26, 2013, 04:40:46 PM »
Charles,

Do you see anyway I can use DLLC to compile an O2 function (as a SB string) and call it from SB at runtime?

The old sbo2.dll looks like it is close. The only down side (maybe) is that SB & O2 talk via a buffer string. I'm not sure if that O2 code will even compile with the current version of OxygenBasic. (I'll give it a try.)

An example would be making the mandel() function in the JAPI Mandelbrot Set SB script an O2 compiled function generated at runtime from a SB string.

John
« Last Edit: May 26, 2013, 08:08:32 PM by JRS »

Charles Pegge

  • Guest
Re: O2 JIT function calls
« Reply #1 on: May 26, 2013, 08:58:34 PM »
Hi John,

It should be possible to use oxygen like any other DLL. o2_mode 0..1 are used to specify that the source strings are char*, rather than bstrings. I will make an example.
« Last Edit: May 29, 2013, 01:15:36 AM by Charles Pegge »

JRS

  • Guest
Re: O2 JIT function calls
« Reply #2 on: May 26, 2013, 09:36:35 PM »
Thank You!

This was the final installment to the DLLC masterpiece. This solves the last issue of using an interpreter. Being able to selectively compile CPU intensive tasks with O2 makes SB the dream scripting engine. IMHO.

« Last Edit: May 26, 2013, 10:55:12 PM by JRS »

Charles Pegge

  • Guest
Re: O2 JIT function calls
« Reply #3 on: May 28, 2013, 05:18:13 AM »

Hi John,

Could you pls send a recent libscriba.dll (32 bit)

JRS

  • Guest
Re: O2 JIT function calls
« Reply #4 on: May 28, 2013, 07:17:46 AM »
Just sent by e-mail.

John

Charles Pegge

  • Guest
Re: O2 JIT function calls
« Reply #5 on: May 28, 2013, 10:11:45 AM »
Thanks John. I needed it for the sbembed tests.
« Last Edit: May 28, 2013, 01:54:02 PM by Charles Pegge »

JRS

  • Guest
Re: O2 JIT function calls
« Reply #6 on: May 28, 2013, 10:18:00 AM »
Sitting on the edge of my seat!   :o

I also sent you (by e-mail) a link to the current SB 2.2 VC10 beta source.


Charles Pegge

  • Guest
Re: O2 JIT function calls
« Reply #7 on: May 28, 2013, 02:42:00 PM »
Yes got it thanks.

Here is the simplest SB deployment of Oxygen:

direct execution.

 include "dllcinc.sb"

  oxy=dllfile("/scriptbasic/modules/oxygen.dll")

  o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  o2_error = dllproc( oxy, "o2_error c*=()         " )
  o2_errno = dllproc( oxy, "o2_errno i =()         " )
  o2_len   = dllproc( oxy, "o2_len   i =()         " )
  o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )

  dllcall o2_mode,1
  src="""

  print "Hello World!"

  """

  function oxygen(src)
  dllcall o2_basic,src
  if (dllcall(o2_errno)<>0) then
    dllprnt dllcall(o2_error)
    a=0
  else
    a=dllcall(o2_exec,0)
  end if
  oxygen=a
  end function

  a=oxygen(src)
  dllprnt "Return code: " & a & "\n"
  dllfile
  line input q

JRS

  • Guest
Re: O2 JIT function calls
« Reply #8 on: May 28, 2013, 02:57:50 PM »
That looks simple enough.

Is there any changes to DLLC or Oxygen DLLs to try this?

Thanks for this great effort and contribution to the ScriptBasic project.


JRS

  • Guest
Re: O2 JIT function calls
« Reply #9 on: May 28, 2013, 03:19:28 PM »
I tried your example with the current code base and it worked.

This is very cool!



Code: [Select]
include "dllcinc.sb"

oxy=dllfile("/sb22/bin/oxygen.dll")

o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
o2_error = dllproc( oxy, "o2_error c*=()         " )
o2_errno = dllproc( oxy, "o2_errno i =()         " )
o2_len   = dllproc( oxy, "o2_len   i =()         " )
o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )

dllcall o2_mode,1
src="""

print "Hello World!"

"""

function oxygen(src)
dllcall o2_basic,src
if (dllcall(o2_errno)<>0) then
  dllprnt dllcall(o2_error)
  a=0
else
  a=dllcall(o2_exec,0)
end if
oxygen=a
end function

a=oxygen(src)
dllprnt "Return code: " & a & "\n"
dllfile
line input q

C:\SB22\o2call>scriba o2c_1.sb
Return code: 0

C:\SB22\o2call>

JRS

  • Guest
Re: O2 JIT function calls
« Reply #10 on: May 28, 2013, 07:29:29 PM »
Charles,

It looks like Hello World! is as far as I can go. the following (or anything else I try) produces an error.

Code: [Select]
src="""

sys x

for x = 1 to 10
next x

"""


C:\SB22\o2call>scriba o2c_1.sb
ERROR:
Unidentified operand
WORD:   n
LINE:   3
Return code: 0

C:\SB22\o2call>

Charles Pegge

  • Guest
Re: O2 JIT function calls
« Reply #11 on: May 28, 2013, 08:17:53 PM »
Hi John,

If you do a full download of Oxygen, there are 4 examples dllco2_A .. dllco2_D, the last being a dll emulation. DLLC has been tweaked so that oxygen-compiled functions can be declared with dllproc(..).

All the sb examples require DLLC.dll, a copy of the new Oxygen.dll and IUP.dll to go into /scriptbasic/modules/.

I will be adding error reporting to DLLC shortly.

Charles


X

JRS

  • Guest
Re: O2 JIT function calls
« Reply #12 on: May 28, 2013, 08:21:06 PM »
I always tend to show up at the party early.

I will download and start testing now.

Thank You!

JRS

  • Guest
Re: O2 JIT function calls
« Reply #13 on: May 28, 2013, 08:49:26 PM »
Charles,

When I try to return a result from a O2 generated function it goes into an endless loop in the function. (Hello World! message box repeats)

John

Code: [Select]

  include "dllcinc.sb"

  oxy=dllfile("/sb22/modules/oxygen.dll")

  o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  o2_error = dllproc( oxy, "o2_error c*=()         " )
  o2_errno = dllproc( oxy, "o2_errno i =()         " )
  o2_len   = dllproc( oxy, "o2_len   i =()         " )
  o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )

  dllcall o2_mode,1

' ==============================
  src="""
  extern

  function funA(sys v) as sys
  print "Hello World!"
  funA = v
  end function

  function funB(sys v) as sys
  print "Goodbye World! "
  funB = v
  end function

  sub finish()
  terminate
  end sub

  function link(sys n) as sys
  select n
  case 0 : return @finish
  case 1 : return @funA
  case 2 : return @funB
  end select
  end function

  end extern
 

  addr link
  """
' ==============================

  function oxygen(src)
  dllcall o2_basic,src
  if (dllcall(o2_errno)<>0) then
    dllprnt dllcall(o2_error)
    a=0
  else
    a=dllcall(o2_exec,0)
  end if
  oxygen=a
  end function
  '
  a=oxygen(src)
  '
  if (a<>0) then
  '
' ==============================
  '
  Hello   = dllproc(a,"Hello   i=(i value) ", dllcald(a,1) )
  Goodbye = dllproc(a,"Goodbye i=(i value) ", dllcald(a,2) )
  Finish  = dllproc(a,"Finish    ()        ", dllcald(a,0) )
  '
' ==============================
  '
  h = dllcall(hello,123)
  g = dllcall(Goodbye,321)
  dllcall(Finish)
  print "hello return: ",h,"\n"
  print "goodbye return: ",g,"\n"
  dllprnt "Return code: " & a & "\n"
  '
  end if
  dllfile
  line input q

JRS

  • Guest
Re: O2 JIT function calls
« Reply #14 on: May 28, 2013, 08:59:29 PM »
Too funny!!!

I need to remember what BASIC I'm coding in.

Code: [Select]
 function funA(sys v) as sys
  print "Hello World!"
  return v
  end function

  function funB(sys v) as sys
  print "Goodbye World! "
  return v
  end function

C:\SB22\o2call>scriba dllco2_D.sb
hello return: 123
goodbye return: 321
Return code: 17864768

C:\SB22\o2call>

I hope I can find a way someday to compensate you for this incredible work of coding art. Just saying thank you doesn't seem quite enough.
« Last Edit: May 28, 2013, 09:07:40 PM by JRS »