[Vm-dev] Interpreter versus StackInterpreter hierarchy
Ben Coman
btc at openinworld.com
Thu May 19 13:42:27 UTC 2016
The hierarchy goes
VMClass
InterpreterPrimitives
StackIntepreter
StackIntepreterPrimitives
CoInterpreter
CoInterpreterPrimitives
from which a tick / tock (XXInterpreter / XXInterpreterPrimitives)
pattern is apparent,
and I wonder why Interpreter is missing above InterpreterPrimitives
sitting off to the side. I guess it is something to do with
InterpreterPrimitives composing objectMemory as an instance variable
rather than inheriting from ObjectMemory as Interpeter does?
The reason I ask is that I'm trying a new approach to the OwnedLock primitives
where if waitAcquire primitive sleeps, when the process wakes up it
retries the primitive.
So effectively the process sleeps at the top of the waitAquire rather
than the bottom,
and the process truly cannot proceed past that point until it gains
the lock. I have this working if StackInterpreterPrimitives holds the
primitive, but if I move the primitive to InterpreterPrimitives,
instructionPointer is unknown.
P.S. For the curious, here is the proof of concept I tried. A single
call to the primitive counts up to four by backing up the
instructionPointer such that the primitive is executed again, until
the exit condition of four is reached.
(Note the use of Semaphore and ExcessSignalsIndex is not significant,
just an expedient template I was familiar with.)
# VM SIDE...
StackInterpreterPrimitives >> primitiveRetryExperiment
| excessSignals stackTop |
stackTop := self stackTop.
excessSignals := objectMemory fetchInteger: ExcessSignalsIndex
ofObject: stackTop.
excessSignals := excessSignals + 1.
objectMemory storeInteger: ExcessSignalsIndex
ofObject: stackTop
withValue: excessSignals.
[ excessSignals > 3 ] ifFalse: [ instructionPointer :=
instructionPointer - 1 ].
StackInterpreter class >> initializePrimitiveTable
(234 primitiveRetryExperiment)
# IMAGE SIDE...
Semaphore subclass: #PrimExp
instanceVariableNames: ''
classVariableNames: ''
package: '0PrimitiveRetryExperiment'
PrimExp >> initialize
excessSignals := 1.
PrimExp >> primRetryExperiment
<primitive: 234>
PrimExp >> excessSignals
^ excessSignals
# TEST CASE...
PrimExp new primRetryExperiment excessSignals
--> 4
I've only done this with the Stack VM so far. I'll report further
when I try it with Cog.
cheers -ben
More information about the Vm-dev
mailing list