That is incredible Charles,
great Job!
So the recommended sequence is following?:
- assign code to string
- compile code and return its handle
- call compiled code by handle
- release compiled code by handle
Shocked Petr
An Oxygen program can now compile strings of source code and run them without stopping. This allows EVAL functions to be implemented.
This is also a feature of Functional languages - being able to pass a function as a parameter of another function.
In our case, the function or expression is simply passed inside a string.
The compile() function is essentially a recursive operation and supports the full O2H Basic.
http://community.thinbasic.com/index.php?topic=2517
Compilefun3.tbasic
[code=thinbasic]
'RUNTIME COMPILING FROM STRINGS
'
uses "oxygen"
dim src as string
src = "
'
global as double x,y,z
function evaluate (s as string, b as long, e as long) as string
dim a,p=1 as long
dim v,u,cr as string
cr=chr(13) chr(10)
v=nuls 4000
mid v,p,s+cr+cr
p+=4+len s
a=compile `o2h `+s
if len (error) then print `runtime error: ` error : frees a : exit function
for x=b to e
call a
u=str(x)+chr(9)+str(y)+chr(13)+chr(10)
mid v,p,u : p+=len u
next
function=left v,p-1
frees a
end function
print evaluate `y=x*x*x`,1,10
print evaluate `y=sqrt x`,1,9
"
o2_basic src
'msgbox 0, o2_prep "o2h "+src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
[/code]
That is incredible Charles,
great Job!
So the recommended sequence is following?:
- assign code to string
- compile code and return its handle
- call compiled code by handle
- release compiled code by handle
Shocked Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Yes Petr, Right on!
The handle is really a BSTR containing the compiled code. So it is explicitly freed afterwards in this case.
Charles you are amazing man
Yes, that's really amazing.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Ok we need to start calling Charles-- Merlin after the famous Wizard. And what is all the more amazing is that he mentioned doing this yesterday or the day before and in the meantime added so many other features, like line numbers. Eros and Charles must be related somehow in lineage being both so super fast in complex code and feature development!!
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Bookmarks