From 93d95fbf3b611d40145439a7f08b01e852806134 Mon Sep 17 00:00:00 2001 From: Denis Kudriashov Date: Sun, 21 Jun 2020 23:58:19 +0100 Subject: [PATCH 1/5] Renames: ReservedVariable with SelfVariable, SuperVariable and ThisContextVariable subclasses. ReservedVariable is direct subclass of Variable. Its protocol is cleaned from old LocalVariable superclass. Old classes names are deprecated and moved to Deprecated90 --- .../OCSelfVariable.class.st | 2 +- .../OCSpecialVariable.class.st | 2 +- .../OCSuperVariable.class.st | 2 +- .../OCThisContextVariable.class.st | 2 +- src/Kernel/Variable.class.st | 2 +- src/OpalCompiler-Core/LocalVariable.class.st | 116 ++++++++++++++++++ .../OCAbstractMethodScope.class.st | 4 +- .../OCInstanceScope.class.st | 8 +- .../ReservedVariable.class.st | 47 +++++++ src/OpalCompiler-Core/SelfVariable.class.st | 37 ++++++ src/OpalCompiler-Core/SuperVariable.class.st | 37 ++++++ .../ThisContextVariable.class.st | 37 ++++++ 12 files changed, 282 insertions(+), 14 deletions(-) rename src/{OpalCompiler-Core => Deprecated90}/OCSelfVariable.class.st (92%) rename src/{OpalCompiler-Core => Deprecated90}/OCSpecialVariable.class.st (92%) rename src/{OpalCompiler-Core => Deprecated90}/OCSuperVariable.class.st (94%) rename src/{OpalCompiler-Core => Deprecated90}/OCThisContextVariable.class.st (92%) create mode 100644 src/OpalCompiler-Core/LocalVariable.class.st create mode 100644 src/OpalCompiler-Core/ReservedVariable.class.st create mode 100644 src/OpalCompiler-Core/SelfVariable.class.st create mode 100644 src/OpalCompiler-Core/SuperVariable.class.st create mode 100644 src/OpalCompiler-Core/ThisContextVariable.class.st diff --git a/src/OpalCompiler-Core/OCSelfVariable.class.st b/src/Deprecated90/OCSelfVariable.class.st similarity index 92% rename from src/OpalCompiler-Core/OCSelfVariable.class.st rename to src/Deprecated90/OCSelfVariable.class.st index 9a35bbbaf4a..26f2dbed2a8 100644 --- a/src/OpalCompiler-Core/OCSelfVariable.class.st +++ b/src/Deprecated90/OCSelfVariable.class.st @@ -4,7 +4,7 @@ I model self variables Class { #name : #OCSelfVariable, #superclass : #OCSpecialVariable, - #category : #'OpalCompiler-Core-Semantics' + #category : #'Deprecated90-OpalCompiler-Core' } { #category : #accessing } diff --git a/src/OpalCompiler-Core/OCSpecialVariable.class.st b/src/Deprecated90/OCSpecialVariable.class.st similarity index 92% rename from src/OpalCompiler-Core/OCSpecialVariable.class.st rename to src/Deprecated90/OCSpecialVariable.class.st index df03cbed710..cc4a7fb6c00 100644 --- a/src/OpalCompiler-Core/OCSpecialVariable.class.st +++ b/src/Deprecated90/OCSpecialVariable.class.st @@ -4,7 +4,7 @@ I model self, thisContext and super Class { #name : #OCSpecialVariable, #superclass : #OCAbstractLocalVariable, - #category : #'OpalCompiler-Core-Semantics' + #category : #'Deprecated90-OpalCompiler-Core' } { #category : #emitting } diff --git a/src/OpalCompiler-Core/OCSuperVariable.class.st b/src/Deprecated90/OCSuperVariable.class.st similarity index 94% rename from src/OpalCompiler-Core/OCSuperVariable.class.st rename to src/Deprecated90/OCSuperVariable.class.st index 613e54de08a..9dd85fd3714 100644 --- a/src/OpalCompiler-Core/OCSuperVariable.class.st +++ b/src/Deprecated90/OCSuperVariable.class.st @@ -4,7 +4,7 @@ I model super variables Class { #name : #OCSuperVariable, #superclass : #OCSpecialVariable, - #category : #'OpalCompiler-Core-Semantics' + #category : #'Deprecated90-OpalCompiler-Core' } { #category : #accessing } diff --git a/src/OpalCompiler-Core/OCThisContextVariable.class.st b/src/Deprecated90/OCThisContextVariable.class.st similarity index 92% rename from src/OpalCompiler-Core/OCThisContextVariable.class.st rename to src/Deprecated90/OCThisContextVariable.class.st index 6a03e58a04d..4215cc2c91b 100644 --- a/src/OpalCompiler-Core/OCThisContextVariable.class.st +++ b/src/Deprecated90/OCThisContextVariable.class.st @@ -4,7 +4,7 @@ I model thisContext variables Class { #name : #OCThisContextVariable, #superclass : #OCSpecialVariable, - #category : #'OpalCompiler-Core-Semantics' + #category : #'Deprecated90-OpalCompiler-Core' } { #category : #accessing } diff --git a/src/Kernel/Variable.class.st b/src/Kernel/Variable.class.st index ad69de0ea97..51244829594 100644 --- a/src/Kernel/Variable.class.st +++ b/src/Kernel/Variable.class.st @@ -137,7 +137,7 @@ Variable >> isSelf [ { #category : #testing } Variable >> isSelfOrSuper [ - ^ false + ^ self isSelf or: [ self isSuper ] ] { #category : #testing } diff --git a/src/OpalCompiler-Core/LocalVariable.class.st b/src/OpalCompiler-Core/LocalVariable.class.st new file mode 100644 index 00000000000..8701951fdac --- /dev/null +++ b/src/OpalCompiler-Core/LocalVariable.class.st @@ -0,0 +1,116 @@ +" +I am an argument or temporary variable of a method or block. + +index is not the index in the bytecode but just used for sorting +(see tempVars). to be fixed... +" +Class { + #name : #LocalVariable, + #superclass : #Variable, + #instVars : [ + 'scope', + 'usage' + ], + #category : #'OpalCompiler-Core-Semantics' +} + +{ #category : #converting } +LocalVariable >> asString [ + + ^ self name +] + +{ #category : #accessing } +LocalVariable >> definingScope [ + ^ scope +] + +{ #category : #testing } +LocalVariable >> isLocal [ + + ^true +] + +{ #category : #'read/write usage' } +LocalVariable >> isRead [ + ^usage = #read + +] + +{ #category : #testing } +LocalVariable >> isRemote [ + ^false +] + +{ #category : #'read/write usage' } +LocalVariable >> isRepeatedWrite [ + ^usage = #repeatedWrite + +] + +{ #category : #'read/write usage' } +LocalVariable >> isUninitialized [ + + ^ self isWrite not +] + +{ #category : #'read/write usage' } +LocalVariable >> isUnused [ + "when the var is never read or written, it is not used. + Note: we have a special #arg use which means arguments are never unused" + ^ usage isNil +] + +{ #category : #'read/write usage' } +LocalVariable >> isWrite [ + ^ usage = #write or: [ self isRepeatedWrite ] +] + +{ #category : #'read/write usage' } +LocalVariable >> markRead [ + "reading does not change a #write, nor an #arg" + usage ifNil: [usage := #read] +] + +{ #category : #'read/write usage' } +LocalVariable >> markRepeatedWrite [ + "blocks in a loop have to know if write usage happens outside (just #write) or + in the loop -> #repeatedWrite" + usage := #repeatedWrite. +] + +{ #category : #'read/write usage' } +LocalVariable >> markWrite [ + "write is the strongest use: a read is turned into a write" + usage := #write. +] + +{ #category : #printing } +LocalVariable >> printOn: stream [ + + stream nextPutAll: self name +] + +{ #category : #accessing } +LocalVariable >> scope [ + + ^ scope +] + +{ #category : #initializing } +LocalVariable >> scope: aLexicalScope [ + + scope := aLexicalScope +] + +{ #category : #accessing } +LocalVariable >> usage [ + + ^ usage +] + +{ #category : #accessing } +LocalVariable >> usage: anObject [ + + usage := anObject +] diff --git a/src/OpalCompiler-Core/OCAbstractMethodScope.class.st b/src/OpalCompiler-Core/OCAbstractMethodScope.class.st index afe41d88179..32a1a58a9f3 100644 --- a/src/OpalCompiler-Core/OCAbstractMethodScope.class.st +++ b/src/OpalCompiler-Core/OCAbstractMethodScope.class.st @@ -120,9 +120,7 @@ OCAbstractMethodScope >> initialize [ copiedVars := Dictionary new. id := 0. - thisContextVar := OCThisContextVariable new - scope: self; yourself. - + thisContextVar := ThisContextVariable new ] { #category : #'temp vars' } diff --git a/src/OpalCompiler-Core/OCInstanceScope.class.st b/src/OpalCompiler-Core/OCInstanceScope.class.st index 36417298fcc..a9f4e2da15e 100644 --- a/src/OpalCompiler-Core/OCInstanceScope.class.st +++ b/src/OpalCompiler-Core/OCInstanceScope.class.st @@ -32,12 +32,8 @@ OCInstanceScope >> hasBindingThatBeginsWith: aString [ OCInstanceScope >> initialize [ vars := Dictionary new. - selfVar := OCSelfVariable new - scope: self; - yourself. - superVar := OCSuperVariable new - scope: self; - yourself. + selfVar := SelfVariable new. + superVar := SuperVariable new ] { #category : #acessing } diff --git a/src/OpalCompiler-Core/ReservedVariable.class.st b/src/OpalCompiler-Core/ReservedVariable.class.st new file mode 100644 index 00000000000..509beba44a5 --- /dev/null +++ b/src/OpalCompiler-Core/ReservedVariable.class.st @@ -0,0 +1,47 @@ +" +I model self, thisContext and super +" +Class { + #name : #ReservedVariable, + #superclass : #Variable, + #category : #'OpalCompiler-Core-Semantics' +} + +{ #category : #testing } +ReservedVariable class >> isAbstract [ + ^self = ReservedVariable +] + +{ #category : #converting } +ReservedVariable >> asString [ + + ^ self name +] + +{ #category : #'code generation' } +ReservedVariable >> emitStore: methodBuilder [ + + self shouldNotImplement +] + +{ #category : #testing } +ReservedVariable >> isSpecialVariable [ + ^true +] + +{ #category : #testing } +ReservedVariable >> isWritable [ + ^ false +] + +{ #category : #printing } +ReservedVariable >> printOn: stream [ + + stream nextPutAll: self name +] + +{ #category : #debugging } +ReservedVariable >> write: aValue inContext: aContext [ + + self error: name, ' is reserved word and cant be modified' +] diff --git a/src/OpalCompiler-Core/SelfVariable.class.st b/src/OpalCompiler-Core/SelfVariable.class.st new file mode 100644 index 00000000000..bc3333dee34 --- /dev/null +++ b/src/OpalCompiler-Core/SelfVariable.class.st @@ -0,0 +1,37 @@ +" +I model ""self"" keyword +" +Class { + #name : #SelfVariable, + #superclass : #ReservedVariable, + #category : #'OpalCompiler-Core-Semantics' +} + +{ #category : #accessing } +SelfVariable class >> semanticNodeClass [ + + ^RBSelfNode +] + +{ #category : #emitting } +SelfVariable >> emitValue: methodBuilder [ + + methodBuilder pushReceiver +] + +{ #category : #initialization } +SelfVariable >> initialize [ + super initialize. + + name := 'self' +] + +{ #category : #testing } +SelfVariable >> isSelf [ + ^true +] + +{ #category : #debugging } +SelfVariable >> readInContext: aContext [ + ^aContext receiver +] diff --git a/src/OpalCompiler-Core/SuperVariable.class.st b/src/OpalCompiler-Core/SuperVariable.class.st new file mode 100644 index 00000000000..36896de7252 --- /dev/null +++ b/src/OpalCompiler-Core/SuperVariable.class.st @@ -0,0 +1,37 @@ +" +I model ""super"" keyword +" +Class { + #name : #SuperVariable, + #superclass : #ReservedVariable, + #category : #'OpalCompiler-Core-Semantics' +} + +{ #category : #accessing } +SuperVariable class >> semanticNodeClass [ + + ^RBSuperNode +] + +{ #category : #emitting } +SuperVariable >> emitValue: methodBuilder [ + "super references the receiver, send that follows is a super send (the message lookup starts in the superclass)" + methodBuilder pushReceiver +] + +{ #category : #initialization } +SuperVariable >> initialize [ + super initialize. + + name := 'super' +] + +{ #category : #testing } +SuperVariable >> isSuper [ + ^true +] + +{ #category : #debugging } +SuperVariable >> readInContext: aContext [ + ^aContext receiver +] diff --git a/src/OpalCompiler-Core/ThisContextVariable.class.st b/src/OpalCompiler-Core/ThisContextVariable.class.st new file mode 100644 index 00000000000..f4de607fe78 --- /dev/null +++ b/src/OpalCompiler-Core/ThisContextVariable.class.st @@ -0,0 +1,37 @@ +" +I model thisContext keyword +" +Class { + #name : #ThisContextVariable, + #superclass : #ReservedVariable, + #category : #'OpalCompiler-Core-Semantics' +} + +{ #category : #accessing } +ThisContextVariable class >> semanticNodeClass [ + + ^RBThisContextNode +] + +{ #category : #emitting } +ThisContextVariable >> emitValue: methodBuilder [ + + methodBuilder pushThisContext +] + +{ #category : #initialization } +ThisContextVariable >> initialize [ + super initialize. + + name := 'thisContext' +] + +{ #category : #testing } +ThisContextVariable >> isThisContext [ + ^true +] + +{ #category : #debugging } +ThisContextVariable >> readInContext: aContext [ + ^aContext +] From 723b45f8cbfd0ceb778c92392f37798c9070fea1 Mon Sep 17 00:00:00 2001 From: Denis Kudriashov Date: Mon, 22 Jun 2020 00:03:34 +0100 Subject: [PATCH 2/5] Optimization: all reserved (special) variables are singletons with #instance class side variable. It should optimize memory required for AST structures. --- src/OpalCompiler-Core/OCAbstractMethodScope.class.st | 2 +- src/OpalCompiler-Core/OCInstanceScope.class.st | 4 ++-- src/OpalCompiler-Core/ReservedVariable.class.st | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/OpalCompiler-Core/OCAbstractMethodScope.class.st b/src/OpalCompiler-Core/OCAbstractMethodScope.class.st index 32a1a58a9f3..d517e22e4ea 100644 --- a/src/OpalCompiler-Core/OCAbstractMethodScope.class.st +++ b/src/OpalCompiler-Core/OCAbstractMethodScope.class.st @@ -120,7 +120,7 @@ OCAbstractMethodScope >> initialize [ copiedVars := Dictionary new. id := 0. - thisContextVar := ThisContextVariable new + thisContextVar := ThisContextVariable instance ] { #category : #'temp vars' } diff --git a/src/OpalCompiler-Core/OCInstanceScope.class.st b/src/OpalCompiler-Core/OCInstanceScope.class.st index a9f4e2da15e..159aa52d0bf 100644 --- a/src/OpalCompiler-Core/OCInstanceScope.class.st +++ b/src/OpalCompiler-Core/OCInstanceScope.class.st @@ -32,8 +32,8 @@ OCInstanceScope >> hasBindingThatBeginsWith: aString [ OCInstanceScope >> initialize [ vars := Dictionary new. - selfVar := SelfVariable new. - superVar := SuperVariable new + selfVar := SelfVariable instance. + superVar := SuperVariable instance ] { #category : #acessing } diff --git a/src/OpalCompiler-Core/ReservedVariable.class.st b/src/OpalCompiler-Core/ReservedVariable.class.st index 509beba44a5..39a8c44d218 100644 --- a/src/OpalCompiler-Core/ReservedVariable.class.st +++ b/src/OpalCompiler-Core/ReservedVariable.class.st @@ -4,9 +4,17 @@ I model self, thisContext and super Class { #name : #ReservedVariable, #superclass : #Variable, + #classInstVars : [ + 'instance' + ], #category : #'OpalCompiler-Core-Semantics' } +{ #category : #accessing } +ReservedVariable class >> instance [ + ^instance ifNil: [ instance := self new ] +] + { #category : #testing } ReservedVariable class >> isAbstract [ ^self = ReservedVariable From b9907f711d9a7539b138c1d102252de104a1725d Mon Sep 17 00:00:00 2001 From: Denis Kudriashov Date: Mon, 22 Jun 2020 00:12:24 +0100 Subject: [PATCH 3/5] Rename special variable into reserved variable in all class names and API --- .../OCStoreIntoSpecialVariableError.class.st | 2 +- src/Deprecated90/RBVariableNode.extension.st | 10 ++++++++++ src/Deprecated90/Variable.extension.st | 9 +++++++++ src/Kernel/Variable.class.st | 10 +++++----- src/OpalCompiler-Core/OCASTSemanticAnalyzer.class.st | 6 +++--- .../OCStoreIntoReservedVariableError.class.st | 5 +++++ src/OpalCompiler-Core/RBVariableNode.extension.st | 6 +++--- src/OpalCompiler-Core/ReservedVariable.class.st | 2 +- 8 files changed, 37 insertions(+), 13 deletions(-) rename src/{OpalCompiler-Core => Deprecated90}/OCStoreIntoSpecialVariableError.class.st (76%) create mode 100644 src/Deprecated90/RBVariableNode.extension.st create mode 100644 src/OpalCompiler-Core/OCStoreIntoReservedVariableError.class.st diff --git a/src/OpalCompiler-Core/OCStoreIntoSpecialVariableError.class.st b/src/Deprecated90/OCStoreIntoSpecialVariableError.class.st similarity index 76% rename from src/OpalCompiler-Core/OCStoreIntoSpecialVariableError.class.st rename to src/Deprecated90/OCStoreIntoSpecialVariableError.class.st index 7e01e0f718e..da3bf753f5f 100644 --- a/src/OpalCompiler-Core/OCStoreIntoSpecialVariableError.class.st +++ b/src/Deprecated90/OCStoreIntoSpecialVariableError.class.st @@ -5,5 +5,5 @@ Error when trying to assign to a special Variable. Class { #name : #OCStoreIntoSpecialVariableError, #superclass : #OCSemanticError, - #category : #'OpalCompiler-Core-Exception' + #category : #'Deprecated90-OpalCompiler-Core' } diff --git a/src/Deprecated90/RBVariableNode.extension.st b/src/Deprecated90/RBVariableNode.extension.st new file mode 100644 index 00000000000..bb30eaee03d --- /dev/null +++ b/src/Deprecated90/RBVariableNode.extension.st @@ -0,0 +1,10 @@ +Extension { #name : #RBVariableNode } + +{ #category : #'*Deprecated90' } +RBVariableNode >> isSpecialVariable [ + self + deprecated: 'Use #isReservedVariable instead.' + transformWith: '`@receiver isSpecialVariable' -> '`@receiver isReservedVariable'. + + ^ self isReservedVariable +] diff --git a/src/Deprecated90/Variable.extension.st b/src/Deprecated90/Variable.extension.st index 07b6498eab4..8ff7f4d75ce 100644 --- a/src/Deprecated90/Variable.extension.st +++ b/src/Deprecated90/Variable.extension.st @@ -1,5 +1,14 @@ Extension { #name : #Variable } +{ #category : #'*Deprecated90' } +Variable >> isSpecialVariable [ + self + deprecated: 'Use #isReservedVariable instead.' + transformWith: '`@receiver isSpecialVariable' -> '`@receiver isReservedVariable'. + + ^ self isReservedVariable +] + { #category : #'*Deprecated90' } Variable >> variable [ diff --git a/src/Kernel/Variable.class.st b/src/Kernel/Variable.class.st index 51244829594..ef6a3d6530b 100644 --- a/src/Kernel/Variable.class.st +++ b/src/Kernel/Variable.class.st @@ -129,6 +129,11 @@ Variable >> isReferenced [ ^ self subclassResponsibility ] +{ #category : #testing } +Variable >> isReservedVariable [ + ^false +] + { #category : #testing } Variable >> isSelf [ ^false @@ -140,11 +145,6 @@ Variable >> isSelfOrSuper [ ^ self isSelf or: [ self isSuper ] ] -{ #category : #testing } -Variable >> isSpecialVariable [ - ^false -] - { #category : #testing } Variable >> isSuper [ ^false diff --git a/src/OpalCompiler-Core/OCASTSemanticAnalyzer.class.st b/src/OpalCompiler-Core/OCASTSemanticAnalyzer.class.st index b90ca7bc05a..2c066aea134 100644 --- a/src/OpalCompiler-Core/OCASTSemanticAnalyzer.class.st +++ b/src/OpalCompiler-Core/OCASTSemanticAnalyzer.class.st @@ -99,7 +99,7 @@ OCASTSemanticAnalyzer >> lookupVariableForWrite: aVariableNode [ var := scope lookupVar: aVariableNode name. var ifNil: [^var]. - var isSpecialVariable ifTrue: [ self storeIntoSpecialVariable: aVariableNode ]. + var isReservedVariable ifTrue: [ self storeIntoReservedVariable: aVariableNode ]. var isWritable ifFalse: [ self storeIntoReadOnlyVariable: aVariableNode ]. var isTemp ifTrue: [ self analyseEscapingWrite: var ]. ^var @@ -122,9 +122,9 @@ OCASTSemanticAnalyzer >> storeIntoReadOnlyVariable: variableNode [ ] { #category : #'error handling' } -OCASTSemanticAnalyzer >> storeIntoSpecialVariable: variableNode [ +OCASTSemanticAnalyzer >> storeIntoReservedVariable: variableNode [ compilationContext optionSkipSemanticWarnings ifTrue: [ ^ self ]. - ^ OCStoreIntoSpecialVariableError new + ^ OCStoreIntoReservedVariableError new node: variableNode; compilationContext: compilationContext; messageText: 'Cannot store into'; diff --git a/src/OpalCompiler-Core/OCStoreIntoReservedVariableError.class.st b/src/OpalCompiler-Core/OCStoreIntoReservedVariableError.class.st new file mode 100644 index 00000000000..ef5187fc78e --- /dev/null +++ b/src/OpalCompiler-Core/OCStoreIntoReservedVariableError.class.st @@ -0,0 +1,5 @@ +Class { + #name : #OCStoreIntoReservedVariableError, + #superclass : #OCSemanticError, + #category : #'OpalCompiler-Core-Exception' +} diff --git a/src/OpalCompiler-Core/RBVariableNode.extension.st b/src/OpalCompiler-Core/RBVariableNode.extension.st index 3cc12f2b9d8..fc66f5b5a58 100644 --- a/src/OpalCompiler-Core/RBVariableNode.extension.st +++ b/src/OpalCompiler-Core/RBVariableNode.extension.st @@ -24,7 +24,7 @@ RBVariableNode >> isArgOrTemp [ { #category : #'*opalcompiler-core' } RBVariableNode >> isClean [ - ^ (self isInstance | self isSpecialVariable) not + ^ (self isInstance | self isReservedVariable) not ] { #category : #'*opalcompiler-core' } @@ -38,8 +38,8 @@ RBVariableNode >> isInstance [ ] { #category : #'*opalcompiler-core' } -RBVariableNode >> isSpecialVariable [ - ^ self binding isSpecialVariable +RBVariableNode >> isReservedVariable [ + ^ self binding isReservedVariable ] { #category : #'*opalcompiler-core' } diff --git a/src/OpalCompiler-Core/ReservedVariable.class.st b/src/OpalCompiler-Core/ReservedVariable.class.st index 39a8c44d218..f60fbe5c18f 100644 --- a/src/OpalCompiler-Core/ReservedVariable.class.st +++ b/src/OpalCompiler-Core/ReservedVariable.class.st @@ -33,7 +33,7 @@ ReservedVariable >> emitStore: methodBuilder [ ] { #category : #testing } -ReservedVariable >> isSpecialVariable [ +ReservedVariable >> isReservedVariable [ ^true ] From 71197b5026da380a673b8dd370b826fb8b4cdb09 Mon Sep 17 00:00:00 2001 From: Denis Kudriashov Date: Mon, 22 Jun 2020 00:14:59 +0100 Subject: [PATCH 4/5] remove new class recently added by mistake --- src/OpalCompiler-Core/LocalVariable.class.st | 116 ------------------- 1 file changed, 116 deletions(-) delete mode 100644 src/OpalCompiler-Core/LocalVariable.class.st diff --git a/src/OpalCompiler-Core/LocalVariable.class.st b/src/OpalCompiler-Core/LocalVariable.class.st deleted file mode 100644 index 8701951fdac..00000000000 --- a/src/OpalCompiler-Core/LocalVariable.class.st +++ /dev/null @@ -1,116 +0,0 @@ -" -I am an argument or temporary variable of a method or block. - -index is not the index in the bytecode but just used for sorting -(see tempVars). to be fixed... -" -Class { - #name : #LocalVariable, - #superclass : #Variable, - #instVars : [ - 'scope', - 'usage' - ], - #category : #'OpalCompiler-Core-Semantics' -} - -{ #category : #converting } -LocalVariable >> asString [ - - ^ self name -] - -{ #category : #accessing } -LocalVariable >> definingScope [ - ^ scope -] - -{ #category : #testing } -LocalVariable >> isLocal [ - - ^true -] - -{ #category : #'read/write usage' } -LocalVariable >> isRead [ - ^usage = #read - -] - -{ #category : #testing } -LocalVariable >> isRemote [ - ^false -] - -{ #category : #'read/write usage' } -LocalVariable >> isRepeatedWrite [ - ^usage = #repeatedWrite - -] - -{ #category : #'read/write usage' } -LocalVariable >> isUninitialized [ - - ^ self isWrite not -] - -{ #category : #'read/write usage' } -LocalVariable >> isUnused [ - "when the var is never read or written, it is not used. - Note: we have a special #arg use which means arguments are never unused" - ^ usage isNil -] - -{ #category : #'read/write usage' } -LocalVariable >> isWrite [ - ^ usage = #write or: [ self isRepeatedWrite ] -] - -{ #category : #'read/write usage' } -LocalVariable >> markRead [ - "reading does not change a #write, nor an #arg" - usage ifNil: [usage := #read] -] - -{ #category : #'read/write usage' } -LocalVariable >> markRepeatedWrite [ - "blocks in a loop have to know if write usage happens outside (just #write) or - in the loop -> #repeatedWrite" - usage := #repeatedWrite. -] - -{ #category : #'read/write usage' } -LocalVariable >> markWrite [ - "write is the strongest use: a read is turned into a write" - usage := #write. -] - -{ #category : #printing } -LocalVariable >> printOn: stream [ - - stream nextPutAll: self name -] - -{ #category : #accessing } -LocalVariable >> scope [ - - ^ scope -] - -{ #category : #initializing } -LocalVariable >> scope: aLexicalScope [ - - scope := aLexicalScope -] - -{ #category : #accessing } -LocalVariable >> usage [ - - ^ usage -] - -{ #category : #accessing } -LocalVariable >> usage: anObject [ - - usage := anObject -] From 8c7eaa3460c386bfe4d481eef8742c9026702026 Mon Sep 17 00:00:00 2001 From: Denis Kudriashov Date: Mon, 22 Jun 2020 20:44:15 +0100 Subject: [PATCH 5/5] fix test for forbidden reserved variable assignements --- src/OpalCompiler-Tests/OCASTVariableTranslatorTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpalCompiler-Tests/OCASTVariableTranslatorTest.class.st b/src/OpalCompiler-Tests/OCASTVariableTranslatorTest.class.st index 84a2bdf0058..3dd3c4eb71c 100644 --- a/src/OpalCompiler-Tests/OCASTVariableTranslatorTest.class.st +++ b/src/OpalCompiler-Tests/OCASTVariableTranslatorTest.class.st @@ -38,14 +38,14 @@ OCASTVariableTranslatorTest >> testAssignInstanceVariable [ OCASTVariableTranslatorTest >> testAssignSelfVariable [ self should: [self compileSource: 'foo - self := 17'] raise: OCStoreIntoSpecialVariableError + self := 17'] raise: OCStoreIntoReservedVariableError ] { #category : #'testing - variables' } OCASTVariableTranslatorTest >> testAssignSuperVariable [ self should: [self compileSource: 'foo - super := 17'] raise: OCStoreIntoSpecialVariableError + super := 17'] raise: OCStoreIntoReservedVariableError ] { #category : #'testing - variables' } @@ -59,7 +59,7 @@ OCASTVariableTranslatorTest >> testAssignTemporaryVariable [ OCASTVariableTranslatorTest >> testAssignThisContextVariable [ self should: [self compileSource: 'foo - thisContext := 17'] raise: OCStoreIntoSpecialVariableError + thisContext := 17'] raise: OCStoreIntoReservedVariableError ] { #category : #'testing - variables' }