Blocks don't need to spawn new VM
The following functions use doBC
to execute blocks:
- Object.get -> Object.deleGet
- instructions/block_call
- instructions/bl_either
- instructions/bl_if
- instructions/bl_until
- instructions/bl_while
- instructions/bl_loop
- instructions/q_proq
Unfortunately, doBC
allocates a new VMstate
and does run_vm
. This seems like unnecessary overhead.
Blocks are homomorphic to anonymous functions, but we can treat them, for the purposes of the VM as injected procedures. If we intend to replay the bytecode stream this would create serious problems, and if we are inserting instructions into the stream there's a potential for very odd bugs.
It might be possible to pass control flow between unrelated streams. A possible solution is to use a Return Stack ala Forth, which is checked for a new stream/offset tuple at the completion of the current one.
There's certainly another solution here, but the goal is to make the overhead of running code blocks invisible.