Skip to content

Commit

Permalink
Merge pull request #2012 from MarcusDenker/22695-Make-value-for-work-…
Browse files Browse the repository at this point in the history
…method-after

22695-Make-value-for-work-method-after
  • Loading branch information
MarcusDenker committed Nov 27, 2018
2 parents aab4604 + c8d5b50 commit 9a2bec8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
18 changes: 18 additions & 0 deletions src/Reflectivity-Tests/ReflectivityControlTest.class.st
Expand Up @@ -196,6 +196,24 @@ ReflectivityControlTest >> testAfterMethod [
self assert: (ReflectivityExamples >> #exampleMethod) class equals: CompiledMethod
]

{ #category : #'tests - after' }
ReflectivityControlTest >> testAfterMethod2 [
| methodNode instance |
methodNode := (ReflectivityExamples >> #exampleMethod2) ast.
link := MetaLink new
metaObject: self;
selector: #tagExec;
control: #after.
methodNode link: link.
self assert: methodNode hasMetalink.
self assert: (ReflectivityExamples >> #exampleMethod2) class equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleMethod2 equals: instance.
self assert: tag equals: #yes.
self assert: (ReflectivityExamples >> #exampleMethod2) class equals: CompiledMethod
]

{ #category : #'tests - level' }
ReflectivityControlTest >> testAfterMethodLevel [
| methodNode |
Expand Down
6 changes: 6 additions & 0 deletions src/Reflectivity-Tests/ReflectivityExamples.class.st
Expand Up @@ -107,6 +107,12 @@ ReflectivityExamples >> exampleMethod [
^ 2 + 3
]

{ #category : #examples }
ReflectivityExamples >> exampleMethod2 [

2 + 3
]

{ #category : #examples }
ReflectivityExamples >> exampleMethodMultipleSites [
Transcript show: Object new.
Expand Down
12 changes: 5 additions & 7 deletions src/Reflectivity-Tests/ReflectivityReificationTest.class.st
Expand Up @@ -872,24 +872,22 @@ ReflectivityReificationTest >> testReifyMethodThisContextAfter [

{ #category : #'tests - method' }
ReflectivityReificationTest >> testReifyMethodValue [
| sendNode instance |
"not working yet. Need to somehow access return value of whole method"
self skip.
sendNode := (ReflectivityExamples >> #exampleMethod) ast.
| methodNode instance |
methodNode := (ReflectivityExamples >> #exampleMethod) ast.
link := MetaLink new
metaObject: self;
selector: #tagExec:;
control: #after;
arguments: #(value).
sendNode link: link.
self assert: sendNode hasMetalink.
methodNode link: link.
self assert: methodNode hasMetalink.
self
assert: (ReflectivityExamples >> #exampleMethod) class
equals: ReflectiveMethod.
self assert: tag isNil.
instance := ReflectivityExamples new.
self assert: instance exampleMethod equals: 5.
self assert: tag equals: #exampleMethod
self assert: tag equals: 5
]

{ #category : #'tests - assignment' }
Expand Down
9 changes: 3 additions & 6 deletions src/Reflectivity/RFASTTranslator.class.st
Expand Up @@ -24,15 +24,14 @@ RFASTTranslator >> emitMessageNode: aMessageNode [
ifFalse: [ valueTranslator visitNode: aMessageNode receiver ].
aMessageNode arguments do: [ :each | valueTranslator visitNode: each ].
self emitPreamble: aMessageNode.
self emitPrepareLinkAfter: aMessageNode.
self emitMetaLinkBefore: aMessageNode.
aMessageNode hasMetalinkInstead
ifTrue: [ self emitMetaLinkInstead: aMessageNode ]
ifFalse: [
aMessageNode isSuperSend
ifTrue: [ methodBuilder send: aMessageNode selector toSuperOf: self compilationContext getClass ]
ifFalse: [ methodBuilder send: aMessageNode selector ] ].
self emitMetaLinkAfter: aMessageNode.
self emitMetaLinkAfterNoEnsure: aMessageNode.
]

{ #category : #reflectivity }
Expand Down Expand Up @@ -239,8 +238,6 @@ RFASTTranslator >> visitMethodNode: aMethodNode [
aMethodNode pragmas do: [:each | self visitPragmaNode: each].
methodBuilder numArgs: aMethodNode arguments size.

self emitPrepareLinkAfter: aMethodNode.

(aMethodNode hasMetalinkInstead and: [ aMethodNode isPrimitive not ])
ifTrue: [ self emitMetaLinkInstead: aMethodNode. methodBuilder returnTop.
^self. ].
Expand All @@ -251,9 +248,9 @@ RFASTTranslator >> visitMethodNode: aMethodNode [
withVars: (aMethodNode scope tempVector collect: [:each| each name]) asArray.
].
effectTranslator visitNode: aMethodNode body.
aMethodNode isPrimitive ifFalse: [self emitMetaLinkAfterNoEnsure: aMethodNode].
(aMethodNode hasProperty: #wrappedPrimitive) ifTrue: [methodBuilder pushTemp: #RFValueReificationVar; returnTop].
aMethodNode body lastIsReturn ifFalse: [methodBuilder pushReceiver; returnTop].
self emitMetaLinkAfter: aMethodNode.
aMethodNode hasMetalinkAfter ifTrue: [methodBuilder returnTop].

]

Expand Down
3 changes: 1 addition & 2 deletions src/Reflectivity/RFASTTranslatorForEffect.class.st
Expand Up @@ -129,7 +129,6 @@ RFASTTranslatorForEffect >> visitVariableNode: aVariableNode [

self emitPreamble: aVariableNode.
self emitMetaLinkBefore: aVariableNode.
self emitPrepareLinkAfter: aVariableNode.

aVariableNode hasMetalinkInstead
ifTrue: [ self emitMetaLinkInstead: aVariableNode ].
Expand All @@ -139,6 +138,6 @@ RFASTTranslatorForEffect >> visitVariableNode: aVariableNode [
(binding isLiteralVariable or: [ binding isUndeclared ])
ifTrue: [ methodBuilder addLiteral: binding assoc ].

self emitMetaLinkAfter: aVariableNode.
self emitMetaLinkAfterNoEnsure: aVariableNode.

]
1 change: 1 addition & 0 deletions src/Reflectivity/RFSemanticAnalyzer.class.st
Expand Up @@ -72,6 +72,7 @@ RFSemanticAnalyzer >> visitMethodNode: aMethodNode [
aMethodNode scope: scope. scope node: aMethodNode.
aMethodNode arguments do: [:node | self declareArgumentNode: node ].
aMethodNode pragmas do: [:each | self visitNode: each].
self declareVariableNode: (RBVariableNode named: #RFValueReificationVar).
self analyseForLinksForNodes: aMethodNode.
self visitNode: aMethodNode body.

Expand Down
3 changes: 1 addition & 2 deletions src/Reflectivity/RFValueReification.class.st
Expand Up @@ -71,7 +71,7 @@ RFValueReification >> genForRBMessageNode [

{ #category : #generate }
RFValueReification >> genForRBMethodNode [
^RBVariableNode named: #RFReifyValueVar
^RBTemporaryNode named: #RFValueReificationVar
]

{ #category : #generate }
Expand All @@ -88,7 +88,6 @@ RFValueReification >> genForRBVariableNode [
{ #category : #generate }
RFValueReification >> postamble: aNode [
(aNode isKindOf: RBProgramNode) ifFalse: [ ^#() ].
aNode isMethod ifTrue: [^RFStoreIntoTempNode named: 'RFReifyValueVar'. ].
aNode isMessage ifTrue: [^RFStoreIntoTempNode named: 'RFReifyValueVar'. ].
^super postamble: aNode.

Expand Down
20 changes: 16 additions & 4 deletions src/Reflectivity/ReflectiveMethod.class.st
Expand Up @@ -34,9 +34,9 @@ ReflectiveMethod >> ast [

{ #category : #evaluation }
ReflectiveMethod >> compileAndInstallCompiledMethod [
(compiledMethod isRealPrimitive and: [ast hasMetalink]) ifTrue: [ self generatePrimitiveWrapper ].
self wrapperNeeded ifTrue: [ self generatePrimitiveWrapper ].
self recompileAST.
self installCompiledMethod.
self installCompiledMethod.
]

{ #category : #accessing }
Expand Down Expand Up @@ -90,7 +90,7 @@ ReflectiveMethod >> flushCache [

{ #category : #evaluation }
ReflectiveMethod >> generatePrimitiveWrapper [
| wrappedMethod send wrapperMethod |
| wrappedMethod send wrapperMethod assignmentNode |
OCASTSemanticCleaner clean: ast.
ast compilationContext
semanticAnalyzerClass: RFSemanticAnalyzer;
Expand All @@ -103,10 +103,14 @@ ReflectiveMethod >> generatePrimitiveWrapper [
selector: #rFwithArgs:executeMethod:
arguments: {RBArrayNode statements: ast arguments . (RFLiteralVariableNode value: wrappedMethod)}.

assignmentNode := RBAssignmentNode
variable: (RBVariableNode named: #RFValueReificationVar)
value: send.

wrapperMethod := RBMethodNode
selector: ast selector
arguments: ast arguments
body: (RBReturnNode value: send) asSequenceNode.
body: assignmentNode asSequenceNode.

wrapperMethod methodClass: ast methodClass.
wrapperMethod propertyAt: #wrappedPrimitive put: true.
Expand Down Expand Up @@ -330,3 +334,11 @@ ReflectiveMethod >> spotterPreviewCodeIn: aComposite [
ReflectiveMethod >> spotterSelectFor: aStep [
self compiledMethod spotterSelectFor: aStep
]

{ #category : #evaluation }
ReflectiveMethod >> wrapperNeeded [
ast hasMetalink ifFalse: [ ^false ].
compiledMethod isRealPrimitive ifTrue: [ ^true ].
ast hasMetalinkAfter ifTrue: [ ^true ].
^false.
]

0 comments on commit 9a2bec8

Please sign in to comment.