Old o2 example "Compile" ?

Started by Frank Brübach, March 25, 2024, 04:31:53 PM

Previous topic - Next topic

0 Members and 8 Guests are viewing this topic.

Frank Brübach

Hello all

Found this old oxygen example there is a Compiler / uncompile command how I can fix this example?


  ' what does it mean this command "compile" ? = o2_basic(s) ?

extern lib "oxygen.dll"
    declare function o2_basic(byref s as asciiz) as long
    declare function o2_exec (byval p as long) as long
    declare function o2_errno() as long
    declare function o2_error() as asciiz ptr
  end extern
  '
  dim qu as string
  dim cr as string
  dim src as string
  qu=chr(34)
  cr=chr(13)+chr(10)
  src="print " + qu+"Hello Oxygen"+qu+cr
  print src
  '
  o2_basic(src)
  '
  if o2_errno()<>0
    print o2_error()
  else
    o2_exec(0)
  end if
  end

  ' what is uncompile ?

  '--------------------------------------------------------------------------
  function evaluate (s as string, byval b as long, byval e as long) as string
  '==========================================================================
  '
  double x,y,z
  long a,i,p=1
  string v,u,tab,cr,er as string
  '
  cr=chr(13) chr(10) : tab=chr 9
  v=nuls 4000
  mid v,p,s+cr+cr
  p+=4+len s
  '
  a=compile s ' what is compile ?'
  'a=o2_basic s ' what is compile ?
  'o2_basic
  er=error
  if er then print `runtime error: `  er : uncompile a : exit function
  for i=b to e
    x=i
    call a
    u=str(x) tab str(y) cr
    mid v,p,u : p+=len u
  next
  '
  function=left v,p-1
  'uncompile a
  end function
 
  print evaluate `y=x*x*x`,1,10
  print evaluate `y=sqrt x`,1,9
 

Thanks, frank
  •  

Charles Pegge

#1
It must be very old code. It looks like secondary compiling which o2 no longer supports. You can see the source code of the current compiler in \tools\co2.o2bas