[squeak-dev] Implementing control operators

Frank Shearar frank.shearar at angband.za.org
Wed Apr 13 22:07:43 UTC 2011


I'm playing around with Danvy and Filinski's shift/reset operators, 
which allow a nice (lexically scoped) syntax for capturing partial 
continuations.

In particular, reset marks the stack in some way, and a later shift 
reifies the call stack between itself and reset as a function.

To that end, I'm delving into the guts of how exceptions work. I've a 
few questions:

First, I know that VMMaker (especially Interpreter 
class>>initializeBytecodeTable) lists all the known numbered primitives. 
In particular, BlockClosure>>on:do: uses <primitive: 199>.

on: exception do: handlerAction
	"Evaluate the receiver in the scope of an exception handler."

	| handlerActive |
	<primitive: 199>  "just a marker, fail and execute the following"
	handlerActive := true.
	^ self value

and

bytecodePrimClass
	| rcvr |
	rcvr := self internalStackTop.
	self internalPop: 1 thenPush: (self fetchClassOf: rcvr).
	self fetchNextBytecode.

is the implementation of that bytecode.

But what's this really doing? Or, rather, how is what it's doing 
connected with marking a context so as to find an exception handler?

If it's purely a marker, could one use another primitive? (Other than 
"that's how we do it, and Things Will Break if something changes the 
primitive number". I can only find MethodContext>>isHandlerContext 
caring about the particular primitive number)

Could one, in principle at least, lose the primitive invocation and have 
an instvar isHandlerContext on ContextPart (MethodContext, more likely), 
and just repeatedly walk down the stack to find the handler rather than 
using another primitive to find the handler?

Secondly, what's handlerActive for in #on:do:? It's a local variable set 
and then never referenced. (No other method has 'handlerActive' in its 
source, in the base image.)

Thanks!

frank



More information about the Squeak-dev mailing list