[z-machine] Multiple stacks?

katre katre@henchmonkey.org
Sat, 11 Sep 2004 23:03:27 -0400


--7AUc2qLy4jB3hD7Z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Amir Karger wrote:
> 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.
>=20

The big benefit to the one-stack form is that you get stack cleaning for
free.  Ie, if I have a function, push a value (foo), call a function,
push another value (bar), return, and then, in the first function, pop,
I should get back foo, not bar.  The stack needs to be cleaned up after
each function return, which you get for free when you pop off the entire
function header.  The glulx spec, while obviosly not directly relevant
to the z-machine, does a good job of explaining one way to do this.

katre


--7AUc2qLy4jB3hD7Z
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBQ7x/QtubI9TdqzIRAhodAKC+DC7EEZGrEVb88Cm9RTj3Rr0W6QCfYCyP
El31RUTIo6vqJsrwPaZMXDE=
=SGOX
-----END PGP SIGNATURE-----

--7AUc2qLy4jB3hD7Z--