Hi,
Skip this msg unless theory about interpreters implementations matters to you.
Stack based... to what extend (speculations about RITE) ?
Two things:
1) I guess we are not talking of the micro-processor's stack (SP) here.
Stack "less" interpreters are considered easier/better approach.
See stackless Python. Anyway, Continuations make it tricky to use the
processor's stack. You need a SpaghettiStack.
2) Regarding the "expression evaluation stack". That is a different matter.
Probably the one involved when talking about "stack based vs register
based".
For this case, I may point out that sometimes the compiler can get some
knowledge about "how deep" that stack most probably needs to be (I
suppose it
can never actually know the max depth, due to
Continuation/Blocks/eval()).
However, for the cases where the compiler knows about the stack depth,
it is faster to perform absolute addressing instead of relative
addressing
with some SP (you avoid the ++SP/--SP house keeping, among others).
Example 1: Stack based imaginary VM. c = a + b
push b # Alloc stack slot, link to previous, put b's value in it
push a # Alloc stack slot, link to previous, put a's value in it
meth +, 2 # Invoke method, dealloc 1 stack slot
pop c # Mov top-of-stack to c, dealloc 1 stack slot.
Example 2: Precomputed stack accesses
stack 2 # Alloc stack slots, done once when
ActivationRecord is created.
mov b, 0 # put b's value in first slot
mov a, 1 # put a's value in second slot
meth +, 0, 2 # Invoke method, args in first & second slots
mov 0, c # Mov first slot's value to c
Benefit:
- Speed ! One allocation only
Drawback:
- Compiler must compute @stackDepth of each method definition.
- Efficient allocation of stacks requires some pool management for
most frequent stack sizes.
Considering that Rite's main purpose is speed, stack management probably
deserve to be as efficient as possible.
I don't know wether the result should be called stack based or register
based, because there still is a variable depth stack yet you most of the
time use it as an array of registers.
Yours,
Jean-Hugues Robert
See also:
http://www.c2.com/cgi/wiki?ActivationRecord
http://www.c2.com/cgi/wiki?StacklessPython
http://www.c2.com/cgi/wiki?ContinuationExplanation
http://www.c2.com/cgi/wiki?SpaghettiStack