Back: Behavior-testing the method dictionary
Up: Class reference
Forward: BlockClosure class-instance creation
 
Top: GNU Smalltalk User's Guide
Contents: Table of Contents
Index: Class index
About: About this document

6.9 BlockClosure

Defined in namespace Smalltalk
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.

6.9.1 BlockClosure class: instance creation  (class)
6.9.2 BlockClosure class: testing  (class)
6.9.3 BlockClosure: accessing  (instance)
6.9.4 BlockClosure: built ins  (instance)
6.9.5 BlockClosure: control structures  (instance)
6.9.6 BlockClosure: exception handling  (instance)
6.9.7 BlockClosure: multiple process  (instance)
6.9.8 BlockClosure: overriding  (instance)
6.9.9 BlockClosure: testing  (instance)


6.9.1 BlockClosure class: instance creation

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

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.


6.9.2 BlockClosure class: testing

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


6.9.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


6.9.4 BlockClosure: built ins

blockCopy: outerContext
Generate a BlockClosure identical to the receiver, with the given context as its outer context.

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


6.9.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 re- start

whileTrue
Evaluate the receiver until it returns false

whileTrue: aBlock
Evaluate the receiver. If it returns true, evaluate aBlock and re- start


6.9.6 BlockClosure: exception handling

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; when any exception is signaled exit returning the result of evaluating aBlock; if no exception is raised, return the result of evaluating the receiver

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:

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. You should usually rely on #ensure: and #on:do:


6.9.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 (can be useful for queuing interrupts from within the uninterruptible 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

valueWithoutPreemption
Evaluate the receiver without ever having it pre-empted by another process. This selector name is deprecated; use #forkWithoutPreemption instead.


6.9.8 BlockClosure: overriding

deepCopy
Answer the receiver.

shallowCopy
Answer the receiver.


6.9.9 BlockClosure: testing

hasMethodReturn
Answer whether the block contains a method return




This document was generated on May, 12 2002 using texi2html