-
Notifications
You must be signed in to change notification settings - Fork 67
/
RBMethodNode.extension.st
112 lines (102 loc) · 3.97 KB
/
RBMethodNode.extension.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Extension { #name : #RBMethodNode }
{ #category : #'*VMMakerCompatibilityForPharo6-C translation' }
RBMethodNode >> asTranslationMethodOfClass: aTMethodClass [
"Answer a TMethod (or subclass) derived from the receiver."
| additionalMethodState comment |
additionalMethodState := AdditionalMethodState forMethod: nil selector: selector.
pragmas ifNotNil:
[pragmas do:
[:pragmaNode|
additionalMethodState := additionalMethodState copyWith: pragmaNode asPragma]].
comment := self commentOrNil.
self body commentOrNil ifNotNil: [ :bodyComment |
comment := comment
ifNil: [ bodyComment ]
ifNotNil: [ comment, self body commentOrNil ].
].
^aTMethodClass new
setSelector: selector
definingClass: compilationContext getClass
args: arguments
locals: ((self allDefinedVariables copyWithoutAll: (arguments collect: #name)) collect: [:string| string -> string])
block: (body lastIsReturn
ifTrue: [body]
ifFalse: [body shallowCopy
addSelfReturn;
yourself])
primitive: ((pragmas ifNotNil:
[pragmas detect: [:pragmaNode| pragmaNode selector beginsWith: #primitve:] ifNone: []])
ifNil: [0]
ifNotNil: [:pragmaNode| pragmaNode arguments first value])
properties: additionalMethodState
comment: comment
]
{ #category : #'*VMMakerCompatibilityForPharo6-C translation' }
RBMethodNode >> asTranslationMethodOfClass: aTMethodClass forCodeGenerator: aCodeGenerator [
"Answer a TMethod (or subclass) derived from the receiver."
| additionalMethodState comment renamedSelector |
additionalMethodState := AdditionalMethodState forMethod: nil selector: selector.
pragmas ifNotNil:
[pragmas do:
[:pragmaNode|
additionalMethodState := additionalMethodState copyWith: pragmaNode asPragma]].
additionalMethodState := additionalMethodState copyWith: #codeGenerator -> aCodeGenerator.
comment := self commentOrNil.
self body commentOrNil ifNotNil: [ :bodyComment |
comment := comment
ifNil: [ bodyComment ]
ifNotNil: [ comment, self body commentOrNil ].
].
renamedSelector := self methodClass renameSelectorIfStaticallyResolved: selector.
^aTMethodClass new
setSelector: renamedSelector
definingClass: compilationContext getClass
args: arguments
locals: ((self allDefinedVariables copyWithoutAll: (arguments collect: #name)) collect: [:string| string -> string])
block: (body lastIsReturn
ifTrue: [body]
ifFalse: [body shallowCopy
addSelfReturn;
yourself])
primitive: ((pragmas ifNotNil:
[pragmas detect: [:pragmaNode| pragmaNode selector beginsWith: #primitve:] ifNone: []])
ifNil: [0]
ifNotNil: [:pragmaNode| pragmaNode arguments first value])
properties: additionalMethodState
comment: comment
]
{ #category : #'*VMMakerCompatibilityForPharo6-results' }
RBMethodNode >> printSchematicTempsFor: blockNode in: blockScope on: stream [
| startPos vectorStartPos |
startPos := stream position.
blockNode arguments do:
[:n|
stream position > startPos ifTrue: [stream space].
stream nextPutAll: n name].
blockScope isBlockScope ifTrue:
[(blockScope copiedVars "filter out remotes, e.g. 0vector0"
reject: [:var| var name first isDigit]) do:
[:var|
stream position > startPos ifTrue: [stream space].
stream nextPutAll: var name]].
(blockNode temporaries reject: [:var| (blockScope lookupVar: var name) isRemote]) do:
[:var|
stream position > startPos ifTrue: [stream space].
stream nextPutAll: var name].
vectorStartPos := stream position.
(blockNode temporaries select: [:var| (blockScope lookupVar: var name) isRemote]) do:
[:var|
stream position = vectorStartPos ifTrue:
[vectorStartPos > startPos ifTrue: [stream space].
stream nextPut: $(].
stream nextPutAll: var name].
stream position > vectorStartPos ifTrue: [stream nextPut: $)]
]
{ #category : #'*VMMakerCompatibilityForPharo6-C translation' }
RBMethodNode >> quickMethodReturnLiteral [
| node |
node := body statements last value.
^node isVariable
ifTrue: [node name]
ifFalse: [node value]
]