3.6 The context unwinding system
When the C code files in something, the doits in the file-in are
evaluated in a different execution environment so that the file-in
is protected from errors signalled in the doit; the same also
happens, for example, when you do a C callin to Smalltalk.
Now, suppose that you want to evaluate something using Behavior's
evaluate: method. Instead of using complex exception handling
code, the unwinding system can be used to obtain that behavior with code
as simple as this:
| [ lastResult := evalFor perform: selector ] valueWithUnwind.
|
In fact, using valueWithUnwind arranges things so that an exception
will resume execution after the block, instead of stopping it.
This system is quite low-level, so it should not be used in most cases:
as a rule of thumb, use it only when the corresponding C code uses the
prepareExecutionEnvironment , stopExecuting and
finishExecutionEnvironment functions. The places where I'm using
it obey this rule. They include the exception handling system, the ST parser,
Behavior>>#evalString:to: and Behavior>>#evalString:to:ifError: .
The valueWithUnwind method is defined in `BlkClosure.st', but it
mostly relies on code in the `ContextPart.st' file. Here are the
methods involved in the unwinding mechanism: you can find descriptions in
the Smalltalk source code. Note that all these methods are internal, this
reference is provided just for sake of completeness.
-
ContextPart class>>#unwind
-
ContextPart class>>#unwind:
-
ContextPart>>#mark
-
ContextPart>>#returnTo:
-
Process>>#unwindPoints
|