On 11 Nov, 11:17, Klaim <
mjkl...@gmail.com> wrote:
> Nice ;D
>
> I looked at the code at that time I was saying it wasn't a really good
> solution, but couldn't found a "better" (read "clean and elegant") solution
> so I couldn't help on this (did try some fixes but they were too naive).
> So, how did you replace the exceptions? Some kind of return value system?
>
> Klaim
>
In the beginning, I wanted do adapt the throws to the early "VM event"
mechanism; that is, there was a various set of events that a script
may have sent to a VM for remote evasion. For example, the "suspend"
event required all the frames to exit to give the control back to the
topmost caller, possibly an embedding application, to allow it push
new data in the script. "Single step" was another event, and errors
was all VM events.
Then it came the need to raise errors even when a VM was not around,
and try/catch is a quite handy way to do that. Even LUA now manages
errors in the same way, (well, a bit more low level as they are C and
so need to manually use setjmp/longjmp, but the inner CPU mechanism
used is the same).
The model is now superseeded by more specific plugs (i.e. the async
message system, direct error throwing, VM inheritance and virtual step-
by-step method plugs), so the only event still in place was the
"return from current frame" event and the "quit the VM now". The
latter one is practically generated only by the exit() function, which
is hardly if ever called, and is still a throw.
For the frame return, as it is an internal VM-to-VM notify (the VM
finds that a frame terminates a local set of sub-frames, and need to
exit the main loop), setting a global variable in the VM is ok. The
only problem is that it adds an extra check in the while() loop, that
is not anymore a while(true), but it weights something around 1/100th
and 1/1000th of every VM loop, and VM loops weight about 1/20th to
1/500th of a real-world application.
... we can afford the extra check.