[z-machine] Multiple stacks?
Amir Karger
amirkargerweb@yahoo.com
Sat, 11 Sep 2004 18:52:18 -0700 (PDT)
Just to add a few words:
--- Martin Rampersad <rems_support@sympatico.ca> wrote:
> Hello beska,
>
> I believe section 6.1 of the Z-Machine Standards Document separates
> the
> stack from the "routine call state". The routine call state can be
> implemented as a different stack, but the remarks section states that
> it is
> possible to mix the stack and the routine call state into one entity,
> but
> does not explain how.
>
> ________________________________
>
> On
> Behalf Of Mose Wingert
>
>
> Hello all...
>
> Though I'm a long time IF-er, I'm very new to the Z-Machine world.
Welcome! It's a neat little world, isn't it. (I'm mostly a newbie, too.
This is my first answer after a bunch of questions.)
> For a
> learning project, I'm trying to implement a Z-Machine...but I'm
> running into
> some troubles. The Z-Machine spec seems a bit unclear in a couple of
> places, and I'm not sure how to try to figure out what is correct.
By the way, you should download Spec1.1, which has a few interesting
points (although they're less verbose in explaining indirect variables
than I would like).
> In some places, such as the overview, it's mentioned that "the stack"
> is
> used to keep track of the routines called, and their local variables.
> But
> then in section 6.1 it mentions both the "stack" and the "routine
> call
> state" as separate items.
Without reading carefully, I'm pretty sure that just about everywhere
that the doc talks about the stack EXCEPT for section 6, it means the
two-byte push/pop stack. The call stack is only needed for (a)
saving/restoring, (b) keeping track of where you used to be when you
return from a call, (c) maybe throw/catch. Whereas the local stack can
be (and is) used by a whole bunch of opcodes to store results you'll
use later. Any time you txd a file and get lots of things like
add i j -> sp
That's the local stack, not the call stack. aka variable $00.
> My current conception of things is that there are two "stacks"...one
> that is
> just a stack of two byte words, that is accessed via pop and push...
> And
> the other is the routine call state, a stack that keeps all of its
> addresses
> and variable values in a single item on the stack.
This is exactly right although, again, you're allowed to put them on
the same stack in your implementation if you want. I.e., after pushing
the two-byte words due to push and pop, you push a whole subroutine
frame, which includes - well, the other stuff, as described in the
Quetzal docs - and then start pushing push/pop two-byte values for the
next subroutine. It's more work, because you need to keep track of
whether you're accidentally popping a subroutine instead of a stack
value, but it's less work because there's only one stack.
Hope that's slightly more clear.
-Amir
_______________________________
Do you Yahoo!?
Shop for Back-to-School deals on Yahoo! Shopping.
http://shopping.yahoo.com/backtoschool