Back: BindingDictionary-testing Up: Base classes Forward: BlockClosure class-instance creation   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.11 BlockClosure

Defined in namespace Smalltalk
Superclass: Object
Category: Language-Implementation
I am a factotum class. My instances represent Smalltalk blocks, portions of executeable code that have access to the environment that they were declared in, take parameters, and can be passed around as objects to be executed by methods outside the current class. Block closures are sent a message to compute their value and create a new execution context; this property can be used in the construction of control flow methods. They also provide some methods that are used in the creation of Processes from blocks.

1.11.1 BlockClosure class: instance creation  (class)
1.11.2 BlockClosure class: testing  (class)
1.11.3 BlockClosure: accessing  (instance)
1.11.4 BlockClosure: built ins  (instance)
1.11.5 BlockClosure: control structures  (instance)
1.11.6 BlockClosure: exception handling  (instance)
1.11.7 BlockClosure: multiple process  (instance)
1.11.8 BlockClosure: overriding  (instance)
1.11.9 BlockClosure: testing  (instance)
1.11.10 BlockClosure: unwind protection  (instance)


1.11.1 BlockClosure class: instance creation

block: aCompiledBlock
Answer a BlockClosure that activates the passed CompiledBlock.

block: aCompiledBlock receiver: anObject
Answer a BlockClosure that activates the passed CompiledBlock with the given receiver.

block: aCompiledBlock receiver: anObject outerContext: aContext
Answer a BlockClosure that activates the passed CompiledBlock with the given receiver.

numArgs: args numTemps: temps bytecodes: bytecodes depth: depth literals: literalArray
Answer a BlockClosure for a new CompiledBlock that is created using the passed parameters. To make it work, you must put the BlockClosure into a CompiledMethod's literals.


1.11.2 BlockClosure class: testing

isImmediate
Answer whether, if x is an instance of the receiver, x copy == x


1.11.3 BlockClosure: accessing

argumentCount
Answer the number of arguments passed to the receiver

block
Answer the CompiledBlock which contains the receiver's bytecodes

block: aCompiledBlock
Set the CompiledBlock which contains the receiver's bytecodes

finalIP
Answer the last instruction that can be executed by the receiver

fixTemps
This should fix the values of the temporary variables used in the block that are ordinarily shared with the method in which the block is defined. Not defined yet, but it is not harmful that it isn't. Answer the receiver.

initialIP
Answer the initial instruction pointer into the receiver.

method
Answer the CompiledMethod in which the receiver lies

numArgs
Answer the number of arguments passed to the receiver

numTemps
Answer the number of temporary variables used by the receiver

outerContext
Answer the method/block context which is the immediate outer of the receiver

outerContext: containingContext
Set the method/block context which is the immediate outer of the receiver

receiver
Answer the object that is used as `self' when executing the receiver (if nil, it might mean that the receiver is not valid though...)

receiver: anObject
Set the object that is used as `self' when executing the receiver

stackDepth
Answer the number of stack slots needed for the receiver


1.11.4 BlockClosure: built ins

cull: arg1
Evaluate the receiver, passing arg1 as the only parameter if the receiver has parameters.

cull: arg1 cull: arg2
Evaluate the receiver, passing arg1 and arg2 as parameters if the receiver accepts them.

cull: arg1 cull: arg2 cull: arg3
Evaluate the receiver, passing arg1, arg2 and arg3 as parameters if the receiver accepts them.

value
Evaluate the receiver passing no parameters

value: arg1
Evaluate the receiver passing arg1 as the only parameter

value: arg1 value: arg2
Evaluate the receiver passing arg1 and arg2 as the parameters

value: arg1 value: arg2 value: arg3
Evaluate the receiver passing arg1, arg2 and arg3 as the parameters

valueWithArguments: argumentsArray
Evaluate the receiver passing argArray's elements as the parameters


1.11.5 BlockClosure: control structures

repeat
Evaluate the receiver 'forever' (actually until a return is executed or the process is terminated).

whileFalse
Evaluate the receiver until it returns true

whileFalse: aBlock
Evaluate the receiver. If it returns false, evaluate aBlock and restart

whileTrue
Evaluate the receiver until it returns false

whileTrue: aBlock
Evaluate the receiver. If it returns true, evaluate aBlock and restart


1.11.6 BlockClosure: exception handling

ifError: aBlock
Evaluate the receiver; when #error: is called, pass to aBlock the receiver and the parameter, and answer the result of evaluating aBlock. If another exception is raised, it is passed to an outer handler; if no exception is raised, the result of evaluating the receiver is returned.

on: anException do: aBlock
Evaluate the receiver; when anException is signaled, evaluate aBlock passing a Signal describing the exception. Answer either the result of evaluating the receiver or the parameter of a Signal>>#return:

on: e1 do: b1 on: e2 do: b2
Evaluate the receiver; when e1 or e2 are signaled, evaluate respectively b1 or b2, passing a Signal describing the exception. Answer either the result of evaluating the receiver or the argument of a Signal>>#return:

on: e1 do: b1 on: e2 do: b2 on: e3 do: b3
Evaluate the receiver; when e1, e2 or e3 are signaled, evaluate respectively b1, b2 or b3, passing a Signal describing the exception. Answer either the result of evaluating the receiver or the parameter of a Signal>>#return:

on: e1 do: b1 on: e2 do: b2 on: e3 do: b3 on: e4 do: b4
Evaluate the receiver; when e1, e2, e3 or e4 are signaled, evaluate respectively b1, b2, b3 or b4, passing a Signal describing the exception. Answer either the result of evaluating the receiver or the parameter of a Signal>>#return:

on: e1 do: b1 on: e2 do: b2 on: e3 do: b3 on: e4 do: b4 on: e5 do: b5
Evaluate the receiver; when e1, e2, e3, e4 or e5 are signaled, evaluate respectively b1, b2, b3, b4 or b5, passing a Signal describing the exception. Answer either the result of evaluating the receiver or the parameter of a Signal>>#return:


1.11.7 BlockClosure: multiple process

fork
Create a new process executing the receiver and start it

forkAt: priority
Create a new process executing the receiver with given priority and start it

forkWithoutPreemption
Evaluate the receiver in a process that cannot be preempted. If the receiver expect a parameter, pass the current process.

newProcess
Create a new process executing the receiver in suspended state. The priority is the same as for the calling process. The receiver must not contain returns

newProcessWith: anArray
Create a new process executing the receiver with the passed arguments, and leave it in suspended state. The priority is the same as for the calling process. The receiver must not contain returns

valueWithoutInterrupts
Evaluate aBlock and delay all interrupts that are requested to the active process during its execution to after aBlock returns.

valueWithoutPreemption
Evaluate the receiver with external interrupts disabled. This effectively disables preemption as long as the block does not explicitly yield control, wait on semaphores, and the like.


1.11.8 BlockClosure: overriding

copy
Answer the receiver.

deepCopy
Answer a shallow copy.


1.11.9 BlockClosure: testing

hasMethodReturn
Answer whether the block contains a method return


1.11.10 BlockClosure: unwind protection

ensure: aBlock
Evaluate the receiver; when any exception is signaled exit returning the result of evaluating aBlock; if no exception is raised, return the result of evaluating aBlock when the receiver has ended

ifCurtailed: aBlock
Evaluate the receiver; if its execution triggers an unwind which truncates the execution of the block (`curtails' the block), evaluate aBlock. The three cases which can curtail the execution of the receiver are: a non-local return in the receiver, a non-local return in a block evaluated by the receiver which returns past the receiver itself, and an exception raised and not resumed during the execution of the receiver.

valueWithUnwind
Evaluate the receiver. Any errors caused by the block will cause a backtrace, but execution will continue in the method that sent #valueWithUnwind, after that call. Example: [ 1 / 0 ] valueWithUnwind. 'unwind works!' printNl.

Important: this method is public, but it is intended to be used in very special cases (as a rule of thumb, use it only when the corresponding C code uses the _gst_prepare_execution_environment and _gst_finish_execution_environment functions). You should usually rely on #ensure: and #on:do:.



Back: BlockClosure-testing Up: BlockClosure Forward: BlockContext   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on August, 19 2010 using texi2html