All right, with a HUGE stress on “preudo”. Thinking in Scheme and currently programming in Lua probably makes for a weird parody of JS, and not knowing the Z-machine VM may make the whole proposal unapplicable.
I assume, possibly wrongly, that the VM code looks somewhat like:
Label1: (* Probably line numbers are used, but put an L before them and they become legal JS function names *)
Do a
Do b
...
Do c
Goto Label2
Label3:
Do d
Do e
if F goto Label3 end
Do g
Do h
Goto Label4 (* Or at some point there is an end instruction, or we simply run off the end of the code *)
The level 1 translation of this is a switch; the level 2 translation - I understand - a set of mutually recursive functions:
function Label1() {
<Do a>
<Do b>
...
<Do c>
Label2()
}
function Label3() {
<Do e>
<Do f>
if (F) Label3()
else {
<Do g>
<Do h>
Label4()
}
}
If the ZVM has subroutine calls, they will translate in non-tail calls, and use the JS call stack. Also, it may be useful to pass a standard set of arguments around (which doesn’t affect my point). There may be elected jump targets (goto targets[j]), but this assumes there are no freely computed ones. Am I correct so far?
Now this approach with functions is a show stopper on both sides. For you, because you cannot create one huge function, because that would mean once-for-all compilation instead of JIT, and for SJ, because it cannot get rid of those function calls. JS being an imperative language, the function definitions might change at ny time, so it must go through the environment lookup process for each call.
With once-for-all compilation, one might wrap the whole collection of functions up, thus:
function play() {
var Label1 = function() {
...
}
var Label3 = function() {
...
}
...
Label1()
}
Now JS ought to be able to deduce that there is no assignment to any LabelN variable, nor a general eval or other spoilgame, so the values of the function variables will never change, and therefore function calls can be translated into direct jumps to the code.
Does that make things clearer, or only more muddled? Or am y clearly muddled?