[Vm-dev] HackerNews + vm-dev = a lightbulb saying "STACK!"
eliot.miranda at gmail.com
Tue Oct 9 22:35:36 UTC 2012
On Tue, Oct 9, 2012 at 11:24 AM, Bert Freudenberg <bert at freudenbergs.de>wrote:
> On 06.10.2012, at 16:13, Chris Cunnington <smalltalktelevision at gmail.com>
> > How are stack languages related to Smalltalk?
> The Squeak VM *is* a stack machine. For passing arguments to a method it
> uses a stack exclusively (in contrast to most microprocessors, which use
> registers, and only use the stack for larger function calls). E.g., you can
> switch a Squeak browser to show byte codes. That demonstrates how the stack
> is used:
> ^ 3 + 4
> switch to byte codes:
> 21 <20> pushConstant: 3
> 22 <21> pushConstant: 4
> 23 <B0> send: +
> 24 <7C> returnTop
> > And then I realized the StackVM is called a StackVM because it uses a
> ... STACK.
> No, every Squeak VM (interpreter, Cog, etc) with the current byte code set
> uses a stack. The Stack VM is so called because it maps the Smalltalk stack
> to the native C code stack for speed.
Not quite. The virtual Smalltalk-80 machine is a spaghetti stack, composed
of a chain of MethodContext objects, each contaning its own stack for
evaluation. The interpreter operates on these context objects directly,
maintaining an activeContext and using its stack for evaluation. The stack
VM maps contexts to a machine stack, so that arguments don't have to be
copied from sender context to new context, and so that context objects do
not have to be allocated on every send, both of which are crucial for
performance. But this machine stack is distinct from the C stack,
organized as a set of pages of fixed size, so as to make the stack
effectively infinite (overflowing onto the heap in the form of contexts).
The interpreter's implementation (the C functions making up the
interpreter), and in Cog, the JIT's compiler implementation, run on the C
stack, but Smalltalk is not executed on the C stack in any of the Squeak
> - Bert -
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Vm-dev