[virtmach] bytecodes and stacks

Reuben Thomas rrt1001@cl.cam.ac.uk
Sun, 28 Nov 1999 21:36:23 +0000 (GMT)


> Is it possible to just push/pop things off one stack, allowing for things 
> like global-variables and locally bound ones (eg. let in scheme)? or would 
> several be needed, leading to a towers of hanoi like situation, when you 
> needed  to reference a variable form an earlier "stack frame", not a fun 
> soulution.

There are many solutions. Native calling conventions demonstrate that
everything can be done with one stack. Many stack-based VMs use two, one
for computation ("data stack") and one for control flow ("return stack").
The return stack is often the same as the single native stack, holding
local variables &c.; the data stack is used in lieu of registers, but of
course with a data stack there is no need to spill to the return stack.

You can in any case think of two stacks as the same as one stack, given
certain usage restrictions. In ANSI Forth, several conceptual stacks, such
as the control-flow compilation stack and the floating-point stack, need
not be concrete, and can be the same as the data stack (which is
mandatory). This means that control flow compilation and floating-point
arithmetic have usage restrictions if you want to write code that works
on all systems. In general, most compilation-related code works on any
system (because few systems have a separate control-flow compilation
stack), but people who do lots of FP work tend to assume a separate FP
stack.

-- 
http://sc3d.org/rrt/ | certain, a.  insufficiently analysed