BlockNode.st
changeset 19 84a1ddf215a5
parent 15 992c3d87edbf
child 20 f8dd8ba75205
equal deleted inserted replaced
18:343ca93df0e0 19:84a1ddf215a5
    24 COPYRIGHT (c) 1989 by Claus Gittinger
    24 COPYRIGHT (c) 1989 by Claus Gittinger
    25               All Rights Reserved
    25               All Rights Reserved
    26 
    26 
    27 implement interpreted blocks
    27 implement interpreted blocks
    28 
    28 
    29 $Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.5 1994-02-25 12:51:06 claus Exp $
    29 $Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.6 1994-03-30 10:09:44 claus Exp $
    30 '!
    30 '!
    31 
    31 
    32 !BlockNode class methodsFor:'instance creation'!
    32 !BlockNode class methodsFor:'instance creation'!
    33 
    33 
    34 arguments:argList home:h variables:vars
    34 arguments:argList home:h variables:vars
    36 ! !
    36 ! !
    37 
    37 
    38 !BlockNode methodsFor:'private accessing'!
    38 !BlockNode methodsFor:'private accessing'!
    39 
    39 
    40 setArguments:argList home:h variables:vars
    40 setArguments:argList home:h variables:vars
       
    41     inlineBlock := false.
    41     needsHome := false.
    42     needsHome := false.
    42     blockArgs := argList.
    43     blockArgs := argList.
    43     home := h.
    44     home := h.
    44     blockVars := vars
    45     blockVars := vars
    45 ! !
    46 ! !
   385     ].
   386     ].
   386 
   387 
   387     (aStream contents) at:pos+1 put:(aStream position)
   388     (aStream contents) at:pos+1 put:(aStream position)
   388 !
   389 !
   389 
   390 
       
   391 codeForSideEffectOn:aStream inBlock:b
       
   392     "generate code for this statement - value not needed.
       
   393      For blocks, no code is generated at all."
       
   394 
       
   395     ^ self
       
   396 !
       
   397 
   390 codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded
   398 codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded
   391     |thisStatement nextStatement|
   399     |thisStatement nextStatement|
   392 
   400 
   393     blockVars notNil ifTrue:[
   401     blockVars notNil ifTrue:[
   394         "cannot currently compile this block inline (have to move blockvars into
   402         "cannot currently compile this block inline (have to move blockvars into
   437     statements isNil ifTrue:[
   445     statements isNil ifTrue:[
   438         "a []-block"
   446         "a []-block"
   439 
   447 
   440         cheapy := Block code:nil
   448         cheapy := Block code:nil
   441                         byteCode:(ByteArray with:(ByteCodeCompiler byteCodeFor:#pushNil)
   449                         byteCode:(ByteArray with:(ByteCodeCompiler byteCodeFor:#pushNil)
   442 					    with:(ByteCodeCompiler byteCodeFor:#blockRetTop))
   450                                             with:(ByteCodeCompiler byteCodeFor:#blockRetTop))
   443                         nargs:(blockArgs size)
   451                         nargs:(blockArgs size)
   444                         sourcePosition:nil 
   452                         sourcePosition:nil 
   445                         initialPC:nil 
   453                         initialPC:nil 
   446                         literals:nil
   454                         literals:nil
   447 			dynamic:false.
   455                         dynamic:false.
   448 
   456 
   449         ^ ConstantNode type:#Block value:cheapy
   457         ^ ConstantNode type:#Block value:cheapy
   450     ].
   458     ].
   451     statements nextStatement notNil ifTrue:[^ nil].
   459     statements nextStatement notNil ifTrue:[^ nil].
   452     (statements isMemberOf:StatementNode) ifFalse:[^ nil].
   460     (statements isMemberOf:StatementNode) ifFalse:[^ nil].
   456 
   464 
   457     val := e value.
   465     val := e value.
   458     val == 0 ifTrue:[
   466     val == 0 ifTrue:[
   459         "a [0]-block"
   467         "a [0]-block"
   460 
   468 
   461 	code := ByteArray with:(ByteCodeCompiler byteCodeFor:#push0)
   469         code := ByteArray with:(ByteCodeCompiler byteCodeFor:#push0)
   462 			  with:(ByteCodeCompiler byteCodeFor:#blockRetTop).
   470                           with:(ByteCodeCompiler byteCodeFor:#blockRetTop).
   463     ].
   471     ].
   464     val == 1 ifTrue:[
   472     val == 1 ifTrue:[
   465         "a [1]-block"
   473         "a [1]-block"
   466 
   474 
   467 	code := ByteArray with:(ByteCodeCompiler byteCodeFor:#push1)
   475         code := ByteArray with:(ByteCodeCompiler byteCodeFor:#push1)
   468 			  with:(ByteCodeCompiler byteCodeFor:#blockRetTop).
   476                           with:(ByteCodeCompiler byteCodeFor:#blockRetTop).
   469     ].
   477     ].
   470 
   478 
   471     val == true ifTrue:[
   479     val == true ifTrue:[
   472         "a [true]-block"
   480         "a [true]-block"
   473 
   481 
   494                     byteCode:code
   502                     byteCode:code
   495                     nargs:(blockArgs size)
   503                     nargs:(blockArgs size)
   496                     sourcePosition:nil 
   504                     sourcePosition:nil 
   497                     initialPC:nil 
   505                     initialPC:nil 
   498                     literals:nil
   506                     literals:nil
   499 		    dynamic:false.
   507                     dynamic:false.
   500         ^ ConstantNode type:#Block value:cheapy
   508         ^ ConstantNode type:#Block value:cheapy
   501     ].
   509     ].
   502 
   510 
   503     ^ nil
   511     ^ nil
   504 ! !
   512 ! !