Results 1 to 6 of 6

Thread: Compiling in Runtime ---> EVAL+++

  1. #1

    Compiling in Runtime ---> EVAL+++

    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]

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: Compiling in Runtime ---> EVAL+++

    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

  3. #3

    Re: Compiling in Runtime ---> EVAL+++


    Yes Petr, Right on!

    The handle is really a BSTR containing the compiled code. So it is explicitly freed afterwards in this case.

  4. #4

    Re: Compiling in Runtime ---> EVAL+++

    Charles you are amazing man

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10

    Re: Compiling in Runtime ---> EVAL+++

    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

  6. #6
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Compiling in Runtime ---> EVAL+++

    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

Similar Threads

  1. what's compiling ???
    By Lionheart008 in forum Shout Box Area
    Replies: 11
    Last Post: 05-11-2009, 20:48

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •