Skip to content

Commit

Permalink
Merge pull request #2007 from MarcusDenker/22689-support-reification-…
Browse files Browse the repository at this point in the history
…value-and-operation-on-LiteralArray

22689-support-reification-value-and-operation-on-LiteralArray
  • Loading branch information
MarcusDenker committed Nov 21, 2018
2 parents 5063419 + 7a6fcfb commit 56c2a76
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Reflectivity-Tests/ReflectivityControlTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,9 @@ ReflectivityControlTest >> testInsteadAssign [
arguments: #(#name #newValue).
assignmentNode link: link.
self assert: assignmentNode hasMetalink.
self assert: (ReflectivityExamples >> #exampleAssignment) class = ReflectiveMethod.
self assert: (ReflectivityExamples >> #exampleAssignment) class equals: ReflectiveMethod.
instance := ReflectivityExamples new.
self assert: instance exampleAssignment = 3.
self assert: instance exampleAssignment equals: 3.
]

{ #category : #'tests - instead' }
Expand Down
142 changes: 142 additions & 0 deletions src/Reflectivity-Tests/ReflectivityReificationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ ReflectivityReificationTest >> testAccessTemp [
self assert: tag equals: 3
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testLiteralOperationAfter [
| literalNode |
literalNode := (ReflectivityExamples >> #exampleLiteral) ast statements first value.
self assert: literalNode isLiteralNode.
link := MetaLink new
metaObject: [:value | self assert: value value equals: 2];
selector: #value:;
arguments: #(operation);
control: #after.
literalNode link: link.
self assert: literalNode hasMetalinkAfter.
self assert: ReflectivityExamples new exampleLiteral == 2.
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testLiteralValueAfter [
| literalNode |
Expand Down Expand Up @@ -92,6 +107,91 @@ ReflectivityReificationTest >> testReifyArguments2level [
self assert: tag = #(1 2)
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testReifyArrayOperationAfter [
| sendNode instance |
sendNode := (ReflectivityExamples >> #exampleArray) ast body
statements first value.
link := MetaLink new
metaObject: self;
selector: #tagExec:;
control: #after;
arguments: #(operation).
sendNode link: link.
self assert: sendNode hasMetalink.
self
assert: (ReflectivityExamples >> #exampleArray) class
equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleArray equals: #(3).
self assert: tag value equals: #(3)
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testReifyArrayOperationBefore [

"
sendNode := (ReflectivityExamples >> #exampleArray) ast body
statements first value.
link := MetaLink new
metaObject: self;
selector: #tagExec:;
control: #before;
arguments: #(operation).
sendNode link: link.
self assert: sendNode hasMetalink.
self
assert: (ReflectivityExamples >> #exampleArray) class
equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleArray equals: #(3).
self assert: tag value equals: #(3)"
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testReifyArrayOperationInstead [

"sendNode := (ReflectivityExamples >> #exampleArray) ast body
statements first value.
link := MetaLink new
metaObject: self;
selector: #tagExec:;
control: #instead;
arguments: #(operation).
sendNode link: link.
self assert: sendNode hasMetalink.
self
assert: (ReflectivityExamples >> #exampleArray) class
equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleArray equals: self.
self assert: tag value equals: #(3)"
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testReifyArrayValue [
| sendNode instance |
sendNode := (ReflectivityExamples >> #exampleArray) ast body
statements first value.
link := MetaLink new
metaObject: self;
selector: #tagExec:;
control: #after;
arguments: #(value).
sendNode link: link.
self assert: sendNode hasMetalink.
self
assert: (ReflectivityExamples >> #exampleArray) class
equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleArray equals: #(3).
self assert: tag equals: #(3)
]

{ #category : #'tests - operations' }
ReflectivityReificationTest >> testReifyAssignmentClassVarOperationAfter [
| varNode instance reachHere |
Expand Down Expand Up @@ -564,6 +664,48 @@ ReflectivityReificationTest >> testReifyIvarVariable [
self assert: (tag isKindOf: Slot)
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testReifyLiteralArrayOperation [
| sendNode instance |
sendNode := (ReflectivityExamples >> #exampleLiteralArray) ast body
statements first value.
link := MetaLink new
metaObject: self;
selector: #tagExec:;
control: #after;
arguments: #(operation).
sendNode link: link.
self assert: sendNode hasMetalink.
self
assert: (ReflectivityExamples >> #exampleLiteralArray) class
equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleLiteralArray equals: #(1).
self assert: tag value equals: #(1)
]

{ #category : #'tests - misc' }
ReflectivityReificationTest >> testReifyLiteralArrayValue [
| sendNode instance |
sendNode := (ReflectivityExamples >> #exampleLiteralArray) ast body
statements first value.
link := MetaLink new
metaObject: self;
selector: #tagExec:;
control: #after;
arguments: #(value).
sendNode link: link.
self assert: sendNode hasMetalink.
self
assert: (ReflectivityExamples >> #exampleLiteralArray) class
equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleLiteralArray equals: #(1).
self assert: tag equals: #(1)
]

{ #category : #'tests - allnodes' }
ReflectivityReificationTest >> testReifyMethod [
| varNode instance origMethod |
Expand Down
29 changes: 28 additions & 1 deletion src/Reflectivity/RFOperationReification.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ Class {

{ #category : #'plugin interface' }
RFOperationReification class >> entities [
^{RBVariableNode. RBMessageNode. RBMethodNode . RBReturnNode. RBAssignmentNode}
^{RBVariableNode. RBMessageNode. RBMethodNode . RBReturnNode. RBAssignmentNode. RBLiteralNode. RBLiteralArrayNode. RBArrayNode}
]

{ #category : #'plugin interface' }
RFOperationReification class >> key [
^#operation
]

{ #category : #generate }
RFOperationReification >> genForRBArrayNode [
^RBVariableNode named: #RFReifyValueVar
]

{ #category : #generate }
RFOperationReification >> genForRBAssignmentNode [
entity variable isTemp ifTrue: [
Expand All @@ -41,6 +46,18 @@ RFOperationReification >> genForRBAssignmentNode [
self error: 'not supported'
]

{ #category : #generate }
RFOperationReification >> genForRBLiteralArrayNode [
"same as #value, no need to wrap as the literal understands #value"
^RBLiteralArrayNode value: entity value
]

{ #category : #generate }
RFOperationReification >> genForRBLiteralValueNode [
"same as #value, no need to wrap as the literal understands #value"
^RBLiteralNode value: entity value
]

{ #category : #generate }
RFOperationReification >> genForRBMessageNode [
^RBParser parseExpression: ('RFMessageOperation
Expand Down Expand Up @@ -101,9 +118,19 @@ RFOperationReification >> preamble: aNode [
aNode isMethod ifTrue: [ ^self preambleForMethod: aNode ].
aNode isReturn ifTrue: [ ^self preambleForReturn: aNode ].
aNode isAssignment ifTrue: [ ^self preambleForAssignment: aNode ].
aNode isDynamicArray ifTrue: [ ^self preambleForArray: aNode ].
^super preamble: aNode.
]

{ #category : #generate }
RFOperationReification >> preambleForArray: aNode [
"balance stack for instead"
self flag: #TBD. "need to pop of the complete stack for instead, need to create the array for #before?"
link control= #instead
ifTrue: [ ^RFStorePopIntoTempNode named: #RFReifyValueVar ]
ifFalse: [^RFStoreIntoTempNode named: #RFReifyValueVar ]
]

{ #category : #generate }
RFOperationReification >> preambleForAssignment: aNode [
"balance stack for instead"
Expand Down
14 changes: 12 additions & 2 deletions src/Reflectivity/RFValueReification.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Class {

{ #category : #'plugin interface' }
RFValueReification class >> entities [
^{RBVariableNode. RBAssignmentNode. RBReturnNode. RBMessageNode . RBLiteralValueNode . LiteralVariable . Slot}
^{RBVariableNode. RBAssignmentNode. RBReturnNode. RBMessageNode . RBLiteralValueNode . RBLiteralArrayNode. RBArrayNode . LiteralVariable . Slot}
]

{ #category : #'plugin interface' }
Expand All @@ -43,12 +43,22 @@ RFValueReification >> genForLiteralVariable [
^RFLiteralVariableNode value: entity value
]

{ #category : #generate }
RFValueReification >> genForRBArrayNode [
^RBVariableNode named: #RFReifyValueVar
]

{ #category : #generate }
RFValueReification >> genForRBAssignmentNode [
"#value for Assignemnt is the old value, is that what we want?"
^RBVariableNode named: entity variable name
]

{ #category : #generate }
RFValueReification >> genForRBLiteralArrayNode [
^RBLiteralArrayNode value: entity value
]

{ #category : #generate }
RFValueReification >> genForRBLiteralValueNode [
^RBLiteralValueNode value: entity value
Expand All @@ -73,7 +83,7 @@ RFValueReification >> genForRBVariableNode [
{ #category : #generate }
RFValueReification >> preamble: aNode [
(aNode isKindOf: RBProgramNode) ifFalse: [ ^#() ].
^(aNode isReturn or: [ aNode isMessage])
^(aNode isReturn or: [ aNode isMessage or: [aNode isDynamicArray]])
ifTrue: [RFStoreIntoTempNode named: #RFReifyValueVar]
ifFalse: [ #() ].
]

0 comments on commit 56c2a76

Please sign in to comment.