Re: Suggested enhancement

new topic     » goto parent     » topic index » view thread      » older message » newer message

JEFF ZEITLIN suggested:

>   Allow a procedure/function call "execute" (or something along
>   those lines) which takes a sequence of characters forming
>   valid Euphoria statements, and returns whatever executing
>   those statements results in - or nothing at all, if there's no
>   return value in the statements.  This would allow:
>
>   1. A CHAIN facility - read a Euphoria program text into the
>            variable foo, then "execute(foo)".

  If the his would add powerful tools, especially for an array of
functions.
  ie.
        function calculate ( number1, number2, operator )
                VirtualMachine = { "add", "subtract", "multiply",
"divide" }
                foo = VirtualMachine[operator] & "(number1, number2)"
                return execute(foo)   --ie execute( "add(number1,
number2)" )
        end function


>
>   2. A macro facility for any Euphoria program - let the user
>            define macros using Euphoria, and any interface that
>            the program author feels is best for the purpose,
>            then "execute(macrovariable)".
>
>   3. A procedural parameter capability - you could write highly
>            generic routines without needing to redefine
>            procedures or functions for (for example)
>            comparisons. "function sort(fooseq, compareproc) ...
>            if execute(compareproc) = -1 then ..."

  I don't understand this one.

>
>   4. A dynamic code facility - since "includes" are idempotent,
>            and cannot be done except at the absolute top level
>            of the program, there's no simple way of defining
>            what gets done "on the fly" such that you can have
>            the Euphoria-knowledgeable user instruct you as to
>            how to handle unforseen situations, and be able to
>            implement those solutions immediately (i.e., without
>            shutting down and restarting the program).
>            "while 1 do ... userproc = ... execute(userproc) ..."

  This is exactly what i want.
  Especially if the imported procedures could be stored in a precompiled
  form, with necessary stubs to slot right in, fast...
    and of course could recieve paramters and return.

  And if they could call imported procedures, then you'd need some
method
  to avoid infinte regression and overflowing the stack, etc.
  I'd favour a system variable that let you set the size of the stack,
and
  whether the overflow would exit the program or be a 'soft error' that
ended
  the function, returning a NULL or somesuch.

  I'd like to know more how the interpreter works, does it create
  bytecode ??  Can that bytecode be loaded on the fly.

  If these are too much, then can i have this...
        The "switch to" statement (a specialized version of Case,
stripped for
speed)

   switch to variable {
        code for variable = 0;    -- seperated by semi-colons
        code for variable = 1;
          ...
        code for variable = n;
        }
        code for else  -- optional, handles variable <> 0 - n
   end switch

   multiple lines of code

  ie.
        function VirtualMachine ( OPCODE var1 )
                switch to OPCODE {
                        Stack = {} ;
                        Stack = Stack & Heap[ var1 ] ;
                        Heap[ var1 ] = Stack[ length(Stack) ] ;
                        Stack = Stack[ 1 ... length(Stack) - 1 ] ;
                          ... etc ..
                        }
                end switch
        end function


-banjo

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu