--- a/BlockNode.st Mon Oct 21 15:03:05 1996 +0200
+++ b/BlockNode.st Mon Oct 21 15:59:35 1996 +0200
@@ -12,7 +12,7 @@
ParseNode subclass:#BlockNode
instanceVariableNames:'blockArgs statements home inlineBlock exitBlock blockVars
- needsHome lineNr'
+ needsHome lineNr endLineNr'
classVariableNames:''
poolDictionaries:''
category:'System-Compiler-Support'
@@ -60,6 +60,12 @@
blockArgs := argList
!
+endLineNumber:aNumber
+ endLineNr := aNumber
+
+ "Created: 21.10.1996 / 14:17:57 / cg"
+!
+
home
^ home
!
@@ -194,7 +200,7 @@
].
code notNil ifTrue:[
- cheapy := Block
+ cheapy := CheapBlock
byteCode:code
numArgs:(blockArgs size)
sourcePosition:nil
@@ -205,7 +211,7 @@
^ nil
- "Modified: 17.10.1996 / 14:04:34 / cg"
+ "Modified: 21.10.1996 / 13:55:52 / cg"
!
codeForSideEffectOn:aStream inBlock:b for:aCompiler
@@ -223,41 +229,47 @@
|thisStatement nextStatement|
blockVars notNil ifTrue:[
- "cannot currently compile this block inline (have to move blockvars into
- surrounding method. generate a make-block and send it value"
+ "cannot currently compile this block inline (have to move blockvars into
+ surrounding method. generate a make-block and send it value"
"/ Transcript showCR:'cannot (yet) compile block with blockvars inline'.
- self codeOn:aStream inBlock:b for:aCompiler.
- aStream nextPut:#value.
- (aCompiler hasLineNumber:#value) ifTrue:[
- aStream nextPut:lineNr.
- ].
- valueNeeded ifFalse:[
- aStream nextPut:#drop
- ].
- ^ self
+ self codeOn:aStream inBlock:b for:aCompiler.
+ aStream nextPut:#value.
+ (aCompiler hasLineNumber:#value) ifTrue:[
+ aStream nextPut:lineNr.
+ ].
+ valueNeeded ifFalse:[
+ aStream nextPut:#drop
+ ].
+ ^ self
].
+
inlineBlock := true.
statements isNil ifTrue:[
- valueNeeded ifTrue:[
- aStream nextPut:#pushNil
- ]
+ valueNeeded ifTrue:[
+ aStream nextPut:#pushNil
+ ]
] ifFalse:[
- thisStatement := statements.
- [thisStatement notNil] whileTrue:[
- nextStatement := thisStatement nextStatement.
- (nextStatement notNil or:[valueNeeded not]) ifTrue:[
- thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler
- ] ifFalse:[
- thisStatement codeOn:aStream inBlock:b for:aCompiler
- ].
- thisStatement := nextStatement
- ]
- ]
+ thisStatement := statements.
+ [thisStatement notNil] whileTrue:[
+ nextStatement := thisStatement nextStatement.
+ (nextStatement notNil or:[valueNeeded not]) ifTrue:[
+ thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler
+ ] ifFalse:[
+ thisStatement codeOn:aStream inBlock:b for:aCompiler
+ ].
+ thisStatement := nextStatement
+ ]
+ ].
+ endLineNr notNil ifTrue:[
+ ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler
+ ].
+
+ "Modified: 21.10.1996 / 14:43:20 / cg"
!
codeOn:aStream inBlock:b for:aCompiler
- |thisStatement nextStatement pos code cheapy|
+ |thisStatement nextStatement lastStatement pos code cheapy p0|
cheapy := self checkForSimpleBlock.
cheapy notNil ifTrue:[
@@ -271,8 +283,13 @@
aStream nextPut:0. "+1"
aStream nextPut:(blockVars size). "+2"
aStream nextPut:(blockArgs size). "+3"
+ "+4"
statements isNil ifTrue:[
- aStream nextPut:#pushNil "+4"
+ endLineNr notNil ifTrue:[
+ ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler
+ ].
+ aStream nextPut:#pushNil.
+ aStream nextPut:#retTop.
] ifFalse:[
thisStatement := statements.
[thisStatement notNil] whileTrue:[
@@ -280,26 +297,40 @@
nextStatement notNil ifTrue:[
thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler
] ifFalse:[
- thisStatement codeOn:aStream inBlock:self for:aCompiler
+ lastStatement := thisStatement
].
thisStatement := nextStatement
- ]
+ ].
+
+ lastStatement isPrimary ifTrue:[
+ ReturnNode
+ codeSimpleReturnFor:lastStatement expression
+ inBlock:nil
+ on:aStream
+ inLine:endLineNr
+ for:aCompiler
+ ].
+ lastStatement codeOn:aStream inBlock:self for:aCompiler.
+ endLineNr notNil ifTrue:[
+ ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler
+ ].
+ aStream nextPut:#retTop.
].
- aStream nextPut:#retTop.
"check for [0]-block;
these are sometimes used as in ... ifAbsent:[0]
"
code := (aStream contents).
- (code at:pos+4) == #push0 ifTrue:[
- (code at:pos+5) == #retTop ifTrue:[
- aStream position:pos.
- code grow:pos.
- aStream nextPut:#mk0Block.
- ^ self
+ p0 := pos+4.
+ (code at:p0) == #lineno ifTrue:[
+ p0 := p0 + 2
+ ] ifFalse:[
+ (code at:p0) == #lineno16 ifTrue:[
+ p0 := p0 + 3
]
].
- (code at:pos+4) == #ret0 ifTrue:[
+
+ (code at:p0) == #ret0 ifTrue:[
aStream position:pos.
code grow:pos.
aStream nextPut:#mk0Block.
@@ -310,25 +341,16 @@
these come to play when code in blocks is commented
out, or as dummy exception blocks
"
- code := (aStream contents).
- (code at:pos+4) == #pushNil ifTrue:[
- (code at:pos+5) == #retTop ifTrue:[
- aStream position:pos.
- code grow:pos.
- aStream nextPut:#mkNilBlock.
- ^ self
- ]
- ].
- (code at:pos+4) == #retNil ifTrue:[
+ (code at:p0) == #retNil ifTrue:[
aStream position:pos.
code grow:pos.
aStream nextPut:#mkNilBlock.
^ self
].
- (aStream contents) at:pos+1 put:(aStream position)
+ code at:pos+1 put:(aStream position)
- "Modified: 19.8.1996 / 14:29:06 / cg"
+ "Modified: 21.10.1996 / 14:53:41 / cg"
! !
!BlockNode methodsFor:'evaluating'!
@@ -588,5 +610,5 @@
!BlockNode class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.30 1996-10-17 13:08:38 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.31 1996-10-21 13:59:35 cg Exp $'
! !