Skip to content

Commit

Permalink
this change makes sure that the copied vars of the temp vector are s…
Browse files Browse the repository at this point in the history
…tandard copied vars. This allows us to easily find their definiton scope (this will be used in a second step) and in addition simplify the code a bit
  • Loading branch information
MarcusDenker committed Oct 11, 2019
1 parent 2268d33 commit 9046c45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/OpalCompiler-Core/OCASTClosureAnalyzer.class.st
Expand Up @@ -68,6 +68,8 @@ OCASTClosureAnalyzer >> visitVariableNode: aVariableNode [
aVariableNode adaptToSemanticNode.
aVariableNode isTemp ifFalse: [^self].
var := self lookupAndFixBinding: aVariableNode.
var isTempVectorTemp ifTrue: [scope addCopyingTempToAllScopesUpToDefVectorNamed: var vectorName].
var isTempVectorTemp ifTrue: [ | vectorVar |
vectorVar := scope lookupVar: var vectorName.
scope addCopyingTempToAllScopesUpToDefTemp: vectorVar].
var isCopying ifTrue: [scope addCopyingTempToAllScopesUpToDefTemp: var].
]
34 changes: 14 additions & 20 deletions src/OpalCompiler-Core/OCAbstractMethodScope.class.st
Expand Up @@ -9,7 +9,8 @@ Class {
'tempVars',
'copiedVars',
'tempVector',
'id'
'id',
'tempVectorVar'
],
#category : #'OpalCompiler-Core-Semantics'
}
Expand All @@ -26,32 +27,15 @@ OCAbstractMethodScope >> addCopyingTemp: aTempVar [
^copiedVars
]

{ #category : #'temp vars - copying' }
OCAbstractMethodScope >> addCopyingTempNamed: name [
copiedVars add: (OCCopyingTempVariable new
name: name;
scope: self;
yourself).
^copiedVars
]

{ #category : #'temp vars - copying' }
OCAbstractMethodScope >> addCopyingTempToAllScopesUpToDefTemp: aVar [

(self hasCopyingTempNamed: aVar name) ifFalse: [self addCopyingTemp: aVar].
tempVars at: aVar name ifPresent: [:v | ^ self].
self = aVar scope ifTrue: [^ self].
^ self outerScope addCopyingTempToAllScopesUpToDefTemp: aVar.

]

{ #category : #'temp vars - copying' }
OCAbstractMethodScope >> addCopyingTempToAllScopesUpToDefVectorNamed: aName [

(self hasCopyingTempNamed: aName) ifFalse: [self addCopyingTempNamed: aName].
self tempVectorName = aName ifTrue: [^ self].
^ self outerScope addCopyingTempToAllScopesUpToDefVectorNamed: aName.
]

{ #category : #'temp vars' }
OCAbstractMethodScope >> addTemp: name [
^self addTemp: OCTempVariable new withName: name
Expand Down Expand Up @@ -177,10 +161,12 @@ OCAbstractMethodScope >> lookupDefiningContextForVariable: var startingFrom: aCo

{ #category : #lookup }
OCAbstractMethodScope >> lookupVar: name [

copiedVars at: name ifPresent: [:v | ^ v].
tempVector at: name ifPresent: [:v | ^ v].
tempVector at: name ifPresent: [:v | ^ v].
tempVars at: name ifPresent: [:v | ^ v].
name = 'thisContext' ifTrue: [^ thisContextVar].
name = self tempVectorName ifTrue: [ ^ self tempVectorVar ].
^self outerScope lookupVar: name

]
Expand Down Expand Up @@ -286,3 +272,11 @@ OCAbstractMethodScope >> tempVectorName [
This way we avoid name clashes "
^'0vector', id asString
]

{ #category : #'temp vars - vector' }
OCAbstractMethodScope >> tempVectorVar [
^ tempVectorVar ifNil: [ tempVectorVar := OCTempVariable new
name: self tempVectorName;
scope: self;
yourself]
]

0 comments on commit 9046c45

Please sign in to comment.