Skip to content

Commit

Permalink
- rename lookUpVar:inContext: to #lookupAndReadVar:inContext
Browse files Browse the repository at this point in the history
- remove all the  lookUpVar:inContext methods that where not needed
- factor out caclulation of index into #indexFromIR (for temps)
  • Loading branch information
MarcusDenker committed Sep 19, 2019
1 parent 8435b02 commit 7e4f6b1
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 73 deletions.
28 changes: 14 additions & 14 deletions src/OpalCompiler-Core/OCAbstractMethodScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,22 @@ OCAbstractMethodScope >> localTemps [
^localVars asArray
]

{ #category : #lookup }
OCAbstractMethodScope >> lookupAndReadVar: name inContext: aContext [
"We lookup a variable in a context. If it not in this context, we look in the outer context using the corresponding outer scope. If found, we return the value"

| variable theValue |

variable := self
variableNamed: name
ifAbsent: [ ^self outerScopeLookupVar: name inContext: aContext].
theValue := variable readFromContext: aContext scope: self.
^ theValue
]

{ #category : #lookup }
OCAbstractMethodScope >> lookupTempVector: name inContext: aContext [
"Similar to lookupVariable:inContext: but looks for a temp vector. If we don't find the temp vector (because it was nilled or not created), we lookup in the outer context with the corresponding outer scope"
"Similar to lookupAndReadVar:inContext: but looks for a temp vector. If we don't find the temp vector (because it was nilled or not created), we lookup in the outer context with the corresponding outer scope"

| variable theVector |
variable := self
Expand All @@ -194,24 +207,11 @@ OCAbstractMethodScope >> lookupVar: name [

]

{ #category : #lookup }
OCAbstractMethodScope >> lookupVar: name inContext: aContext [
"We lookup a variable in a context. If it not in this context, we look in the outer context using the corresponding outer scope"

| variable theValue |
variable := self
variableNamed: name
ifAbsent: [ ^self outerScopeLookupVar: name inContext: aContext].
theValue := variable readFromContext: aContext scope: self.
^ theValue
]

{ #category : #lookup }
OCAbstractMethodScope >> lookupVarForDeclaration: name [
tempVars at: name ifPresent: [:v | ^ v].
name = 'thisContext' ifTrue: [^ thisContextVar].
^self outerScope lookupVarForDeclaration: name

]

{ #category : #debugging }
Expand Down
12 changes: 6 additions & 6 deletions src/OpalCompiler-Core/OCAbstractScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ OCAbstractScope >> isMethodScope [
^false
]

{ #category : #lookup }
OCAbstractScope >> lookupAndReadVar: name inContext: aContext [

^ self outerScope lookupAndReadVar: name inContext: aContext outerContext
]

{ #category : #lookup }
OCAbstractScope >> lookupSelector: name [

Expand All @@ -69,12 +75,6 @@ OCAbstractScope >> lookupVar: name [
^ self outerScope lookupVar: name
]

{ #category : #lookup }
OCAbstractScope >> lookupVar: name inContext: aContext [

^ self outerScope lookupVar: name inContext: aContext outerContext
]

{ #category : #lookup }
OCAbstractScope >> lookupVarForDeclaration: name [
"subclass responsibility"
Expand Down
2 changes: 1 addition & 1 deletion src/OpalCompiler-Core/OCBlockScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ OCBlockScope >> nextOuterScopeContextOf: aContext [
{ #category : #lookup }
OCBlockScope >> outerScopeLookupVar: name inContext: aContext [
^ self outerScope
lookupVar: name
lookupAndReadVar: name
inContext: (self nextOuterScopeContextOf: aContext)
]
7 changes: 0 additions & 7 deletions src/OpalCompiler-Core/OCClassScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ OCClassScope >> lookupVar: name [
ifNil: [ outerScope lookupVar: name]
]

{ #category : #lookup }
OCClassScope >> lookupVar: name inContext: aContext [
"I'll lookup a variable in a class. The context does not play any role in here because variables in classes are statically defined"

^ self lookupVar: name
]

{ #category : #lookup }
OCClassScope >> lookupVarForDeclaration: name [
^self lookupVar: name
Expand Down
7 changes: 0 additions & 7 deletions src/OpalCompiler-Core/OCEnvironmentScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ OCEnvironmentScope >> lookupVar: name [

]

{ #category : #lookup }
OCEnvironmentScope >> lookupVar: name inContext: aContext [
"I'll lookup a variable in the (global) environment. The context does not play any role in here because variables in classes are statically defined"

^ self lookupVar: name
]

{ #category : #creation }
OCEnvironmentScope >> newClassScope: aClass [

Expand Down
15 changes: 0 additions & 15 deletions src/OpalCompiler-Core/OCExtraBindingScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ OCExtraBindingScope >> lookupVar: name [
^ super lookupVar: name
]

{ #category : #lookup }
OCExtraBindingScope >> lookupVar: name inContext: context [

name = 'self' ifTrue: [ ^outerScope lookupVar: name inContext: context outerContext].
name = 'super' ifTrue: [ ^outerScope lookupVar: name inContext: context outerContext].
"Globals are not shadowed"
name first isUppercase ifTrue: [ | found |
found := outerScope outerScope lookupVar: name inContext: context outerContext.
found ifNotNil: [ ^found ]].

(bindings bindingOf: name asSymbol) ifNotNil: [:assoc |
^ OCLiteralVariable new assoc: assoc; scope: self; yourself].
^ super lookupVar: name inContext: context outerContext.
]

{ #category : #'instance creation' }
OCExtraBindingScope >> newMethodScope [

Expand Down
9 changes: 0 additions & 9 deletions src/OpalCompiler-Core/OCInstanceScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ OCInstanceScope >> lookupVar: name [
^ vars at: name ifAbsent: [self outerScope lookupVar: name]
]

{ #category : #lookup }
OCInstanceScope >> lookupVar: name inContext: aContext [
"Return a ScopeVar for my inst var with this name. Return nil if none found"

name = 'self' ifTrue: [^ selfVar].
name = 'super' ifTrue: [^ superVar].
^ vars at: name ifAbsent: [self outerScope lookupVar: name inContext: aContext ]
]

{ #category : #lookup }
OCInstanceScope >> lookupVarForDeclaration: name [
"Return a ScopeVar for my inst var with this name. Return nil if none found"
Expand Down
12 changes: 0 additions & 12 deletions src/OpalCompiler-Core/OCRequestorScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ OCRequestorScope >> lookupVar: name [
^ super lookupVar: name
]

{ #category : #lookup }
OCRequestorScope >> lookupVar: name inContext: context [

name = 'self' ifTrue: [ ^outerScope lookupVar: name inContext: context outerContext].
name = 'super' ifTrue: [ ^outerScope lookupVar: name inContext: context outerContext].
name first isUppercase ifTrue: [ ^outerScope lookupVar: name inContext: context outerContext].

(requestor bindingOf: name asSymbol) ifNotNil: [:assoc |
^ OCLiteralVariable new assoc: assoc; scope: self; yourself].
^ super lookupVar: name inContext: context outerContext.
]

{ #category : #lookup }
OCRequestorScope >> newMethodScope [

Expand Down
9 changes: 7 additions & 2 deletions src/OpalCompiler-Core/OCTempVariable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ OCTempVariable >> hash [
^ name hash bitXor: (usage hash bitXor: scope hash).
]

{ #category : #debugging }
OCTempVariable >> indexFromIR [
^scope outerNotOptimizedScope node irInstruction indexForVarNamed: name
]

{ #category : #initialization }
OCTempVariable >> initialize [
super initialize.
Expand Down Expand Up @@ -129,13 +134,13 @@ OCTempVariable >> markWrite [

{ #category : #debugging }
OCTempVariable >> readFromContext: aContext scope: contextScope [
^ aContext tempAt: (contextScope outerNotOptimizedScope node irInstruction indexForVarNamed: name)
^ aContext tempAt: self indexFromIR
]

{ #category : #debugging }
OCTempVariable >> searchFromContext: aContext scope: contextScope [

^ contextScope lookupVar: name inContext: aContext
^ contextScope lookupAndReadVar: name inContext: aContext
]

{ #category : #debugging }
Expand Down

0 comments on commit 7e4f6b1

Please sign in to comment.