Block activation

  • When literal block is compiled, a block object b1 is created with value method slot and parent* slot, set to traits block.

  • When expression containing the reference to the block is evaluated, the block is cloned to give an object b2, with an extra hidden slot containing a reference to the current activation, m .

  • When b2 is activated (using value ), its method is cloned, and a hidden parent installed by copying the reference to m .
    Example of block activation
    Source (in traits number):
    	signChar = 
    	(| s <- ©+© | < 0 ifTrue: [s: ©-©].··s)
    

    After compilation:
    In -42 signChar, about to send ifTrue:
    In the block:


Block activation

Block activation is similar to method activation, except that there is an extra stage. First, a block object is created at compile time. This has a parent* slot that refers to traits block, and a value method (appropriate to the number of arguments), with the block's code as the method body.

When the expression containing a reference to this block is evaluated, the block is cloned, and the clone is given a hidden slot that refer's to the current activation object.

When the block's method is activated (via a value message), the method is cloned and a hidden parent slot is added, containing a reference to the activation object saved in the previous step (not a self slot, as per methods). This allows the block to access the slots of enclosing block's and the outermost method (lexical scoping).

[ Previous ] [ Index ] [ Next ]