BASIC Developer & Support Resources > Compilers

Calling the Oxygen DLL

(1/10) > >>

JRS:
Charles,

I want to try using the DYC (generic DLL interface extension module) in SB to call the Oxygen JIT compiler with a program string. Can you show us an example of this?

John

cevpegge:
Here is the Hello program John

I tested this with Oxygen.dll is the same folder as the script


--- Code: ---'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic

module dyc

'FUNCTION DECLARATIONS
 
declare sub     ::dyc alias "dyc" lib "dyc"

end module


'OXYGEN SOURCE CODE
'------------------

src="""
  print "Greetings from OxygenBasic!"

""" & chr$(0)

dyc::dyc("ms,i,OXYGEN.DLL,o2_mode,L",0)
dyc::dyc("ms,i,OXYGEN.DLL,o2_basic,Z",src)


'how do we make dll calls that have no arguments?
'e=dyc::dyc("ms,i,OXYGEN.DLL,o2_error,")
e=0
if e=0 then
  dyc::dyc("ms,i,OXYGEN.DLL,o2_exec,L",0)
endif


--- End code ---

Some obstacles:

I would like to return error numbers and messages but DYC does not seem to support DLL calls without arguments

DYC does not seem to support returned zStrings

How do you Switch off the console?

Anyway, it's a start :)

Charles

JRS:
Thanks Charles, that is a great start and allows me to try to figure out the issues you ran into are.

I'll let you know what I come up with.

JRS:
Charles,

I gave your test program a try and all I get is a beep and back to the prompt. Were you able to get it to print from O2?


--- Code: ---'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic


'FUNCTION DECLARATIONS
 
declare sub dyc alias "dyc" lib "dyc"


'OXYGEN SOURCE CODE
'------------------

src="""
  print "Greetings from OxygenBasic!"

""" & CHR(0)

dyc("ms,i,OXYGEN.DLL,o2_mode,L",0)
dyc("ms,i,OXYGEN.DLL,o2_basic,Z",src)


' how do we make dll calls that have no arguments?
' e=dyc::dyc("ms,i,OXYGEN.DLL,o2_error,")
e=0
IF e=0 THEN
  dyc("ms,i,OXYGEN.DLL,o2_exec,L",0)
END IF

--- End code ---

P.S.

I placed the OXYGEN.DLL in the same directory as this program. The strange thing is the scriba -d option isn't returning any extension module (DYC) load messages.  ???

Update

I included DYC (see below) and was able to get the -d load verification. Sooo, it looks like the only response from O2 in this demo is a beep. Correct?

C:\scriptbasic\test>scriba -d o2test2.sb
Searching installed module header file 'dyc.bas' ...
Checking installed module header file location 'c:\scriptbasic\include\dyc.bas' Result=OK
Including file 'c:\scriptbasic\include\dyc.bas'

C:\scriptbasic\test>


--- Code: ---'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic

INCLUDE dyc.bas

'OXYGEN SOURCE CODE
'------------------

src="""
  print "Greetings from OxygenBasic!"

""" & chr$(0)

dyc::dyc("ms,i,OXYGEN.DLL,o2_mode,L",0)
dyc::dyc("ms,i,OXYGEN.DLL,o2_basic,Z",src)


'how do we make dll calls that have no arguments?
'e=dyc::dyc("ms,i,OXYGEN.DLL,o2_error,")
e=0
if e=0 then
  dyc::dyc("ms,i,OXYGEN.DLL,o2_exec,L",0)
endif

--- End code ---

Update

This is where I am with this. I think I figured out the no argument issue.


--- Code: ---'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic

INCLUDE dyc.bas

'OXYGEN SOURCE CODE
'------------------

src="""
  print "Greetings from OxygenBasic!"

""" & chr$(0)

ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_mode,L",0)
PRINT "Debug 1: ",ok,"\n"
ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_basic,Z",src)
PRINT "Debug 2: ",ok,"\n"

'how do we make dll calls that have no arguments?
e=dyc::dyc("ms,i,OXYGEN.DLL,o2_error,L",undef)
PRINT "Debug 3: ",e,"\n"

if e=0 then
  ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_exec,L",0)
  PRINT "Debug 4: ",ok,"\n"
endif

--- End code ---

C:\scriptbasic\test>o2test2.sb
Debug 1: 0
Debug 2: 4181568
Debug 3: 0
Debug 4: 2440708

C:\scriptbasic\test>

Update

I wanted to see if the o2_error() function was really working with my no argument guess.


--- Code: ---'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic

INCLUDE dyc.bas

'OXYGEN SOURCE CODE
'------------------

src="""
  print "Greetings from OxygenBasic!"

""" & chr$(0)

ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_mode,L",0)
PRINT "Debug 1: ",ok,"\n"
ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_basic,Z","printt" & chr(0))
PRINT "Debug 2: ",ok,"\n"

'how do we make dll calls that have no arguments?
e=dyc::dyc("ms,i,OXYGEN.DLL,o2_error,L",undef)
PRINT "Debug 3: ",e,"\n"

if e=0 then
  ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_exec,L",0)
  PRINT "Debug 4: ",ok,"\n"
endif

--- End code ---

C:\scriptbasic\test>o2test.sb
Debug 1: 0
Debug 2: 4160992
Debug 3: 4161176

C:\scriptbasic\test>

Update

You asked "How do you Switch off the console?" so here is my attempt. The console title changes to the name of the program running but nothing prints. (O2 or my debug PRINTs)


--- Code: ---'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic

INCLUDE dyc.bas
INCLUDE cio.bas

cio::Detach()

'OXYGEN SOURCE CODE
'------------------

src="""
  print "Greetings from OxygenBasic!"

""" & chr$(0)

ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_mode,L",0)
PRINT "Debug 1: ",ok,"\n"
ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_basic,Z","print \"JRS\"" & chr(0))
PRINT "Debug 2: ",ok,"\n"

'how do we make dll calls that have no arguments?
e=dyc::dyc("ms,i,OXYGEN.DLL,o2_error,L",undef)
PRINT "Debug 3: ",e,"\n"

if e=0 then
  ok = dyc::dyc("ms,i,OXYGEN.DLL,o2_exec,L",0)
  PRINT "Debug 4: ",ok,"\n"
endif

SLEEP 5

--- End code ---

cevpegge:

Hi John,

Thanks for investigating.

Detaching the console is a fair compromise. It flashes briefly on the screen at the start of the program.

I think we have differing file mappings. I am running the script from the OxygenBasic folder alongside Oxygen.dll. SB knows where the extension modules are located but not the .bas declaration files, so I put the module declarations directly into the demo script.

(I'm using Notepad++)

When the SB script is run, you may see the console flash on and off the screen then A message box should appear with the greeting.

Still no luck with o2_error. The expression you tried still pushes a Long integer onto the CPU stack causing a GPF.
I think that DYC has no provision for handling an empty argument list.


Charles

This includes Console detach:

--- Code: ---'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic


'INCLUDE cio.bas
'INCLUDE dyc.bas

module cio
  declare sub ::detach        alias "sbdetach"   lib "cio"
end module

cio::Detach()

module dyc
  declare sub     ::dyc alias "dyc" lib "dyc"
end module



'OXYGEN SOURCE CODE
'------------------

src="""
  print "Greetings from OxygenBasic!"

""" & chr$(0)

dyc::dyc("ms,i,OXYGEN.DLL,o2_mode,L",0)
dyc::dyc("ms,i,OXYGEN.DLL,o2_basic,Z",src)


'how do we make dll calls that have no arguments?
'e=dyc::dyc("ms,i,OXYGEN.DLL,o2_errno,L",undef)
e=0
if e=0 then
  dyc::dyc("ms,i,OXYGEN.DLL,o2_exec,L",0)
endif

--- End code ---


Navigation

[0] Message Index

[#] Next page

Go to full version