At 04:53 PM 9/22/2001 -0400, Ken Fox wrote:
>I've been thinking about the possibility of building a higher-level
>VM. The current VM is very close to a traditional CPU.

It's not, we just haven't gotten to the interesting bits yet. :)

>What if we
>did something non-traditional that made implementing higher-level
>lexically scoped languages easier?
>
>What if the VM (and assembler) had lexical scoping built-in at
>the instruction level? Each instruction could be tagged with a
>scope and if the scope changes, the VM could automatically fixup
>the environment.

Can't do that easily. What about:

   sub foo {
     foo() if rand > .5;
   }

No scope changes there.

>The current dispatch loop is something like:
>
>   while (code)
>      code = dispatch(code)
>
>I'm proposing:
>
>   while (code)
>      if (code.scope != current.scope)
>         fixup_environment(code)
>      code = dispatch(code)

That also has the issue of putting scoping information in the instruction 
stream. That's a lot of rarely used data.

>If we include event checking in the dispatch loop, the scope change
>check is free because we can combine the two into a single test --
>scope 0 would be reserved for "event pending".

We're not adding event checking in the main dispatch loop, at least not at 
the moment.

>Lexically scoped instructions would also permit another possibility:
>a stack-less *and* register-less architecture. The VM could use
>frame offsets for everything -- the only operands needed in the
>assembler are local and global variables.

Registers get you what's essentially a set of handy temp spots. Not much 
reason to toss 'em. Your proposed solution, while reasonable, is also 
likely to be awfully slow.


                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to