BContext.st
changeset 1 a27a279701f8
child 3 24d81bf47225
equal deleted inserted replaced
0:aa2498ef6470 1:a27a279701f8
       
     1 "
       
     2  COPYRIGHT (c) 1993 by Claus Gittinger
       
     3               All Rights Reserved
       
     4 
       
     5  This software is furnished under a license and may be used
       
     6  only in accordance with the terms of that license and with the
       
     7  inclusion of the above copyright notice.   This software may not
       
     8  be provided or otherwise made available to, or used by, any
       
     9  other person.  No title to or ownership of the software is
       
    10  hereby transferred.
       
    11 "
       
    12 
       
    13 Context subclass:#BlockContext
       
    14        instanceVariableNames:''  "do not add instvars here"
       
    15        classVariableNames:''
       
    16        poolDictionaries:''
       
    17        category:'Kernel-Methods'
       
    18 !
       
    19 
       
    20 BlockContext comment:'
       
    21 
       
    22 COPYRIGHT (c) 1993 by Claus Gittinger
       
    23               All Rights Reserved
       
    24 
       
    25 BlockContexts represent the stack context objects of blocks. The layout is the same
       
    26 as for other contexts - this class has been added to avoid a flag in an instance variable.
       
    27 (has become necessary with cheap blocks, which have no home).
       
    28 
       
    29 Warning: layout and size known by compiler and runtime system - do not change.
       
    30 
       
    31 %W% %E%
       
    32 '!
       
    33 
       
    34 !BlockContext methodsFor:'accessing'!
       
    35 
       
    36 isBlockContext
       
    37     "return true, iff the receiver is a BlockContext, false otherwise"
       
    38 
       
    39     ^ true
       
    40 !
       
    41 
       
    42 methodHome
       
    43     "return the method-home for block contexts"
       
    44 
       
    45     |con h|
       
    46 
       
    47     home isNil ifTrue:[^ nil]. "XXX will change soon"
       
    48     home isContext ifFalse:[^ nil]. "copying blocks have no method home"
       
    49 
       
    50     con := self.
       
    51     h := home.
       
    52     [h notNil] whileTrue:[
       
    53         con := h.
       
    54         h := con home
       
    55     ].
       
    56     ^ con
       
    57 !
       
    58 
       
    59 home
       
    60     "return the immediate home of the receiver.
       
    61      normally this is the methodcontext, where the block was created,
       
    62      for nested block contexts, this is the surrounding blocks context."
       
    63 
       
    64     home isContext ifFalse:[^ nil]. "copying blocks have no home"
       
    65     ^ home
       
    66 !
       
    67 
       
    68 selector
       
    69     "return the selector of the context - which is one of the value
       
    70      selectors"
       
    71 
       
    72     |nargs|
       
    73 
       
    74     nargs := self nargs.
       
    75     (nargs == 0) ifTrue:[^ #value].
       
    76     (nargs == 1) ifTrue:[^ #value:].
       
    77     (nargs == 2) ifTrue:[^ #value:value:].
       
    78     (nargs == 3) ifTrue:[^ #value:value:value:].
       
    79     (nargs == 4) ifTrue:[^ #value:value:value:value:].
       
    80     (nargs == 5) ifTrue:[^ #value:value:value:value:value:].
       
    81     ^ nil
       
    82 ! !
       
    83 
       
    84 !BlockContext methodsFor:'printing'!
       
    85 
       
    86 receiverPrintString
       
    87     home isNil ifTrue:[
       
    88 	^ '[] optimized'
       
    89     ].
       
    90     home isContext ifFalse:[
       
    91 	"a copying block"
       
    92 
       
    93 	"receiverClassName := home selfValue class name."
       
    94 	^ '[] optimized'
       
    95     ].
       
    96 
       
    97     ^ '[] in ' , receiver class name , '-' , self methodHome selector
       
    98 !
       
    99 
       
   100 printReceiver
       
   101     self receiverPrintString print
       
   102 !
       
   103     
       
   104 printString
       
   105     ^ self receiverPrintString , ' ' , self selector printString
       
   106 ! !