-
-
Notifications
You must be signed in to change notification settings - Fork 346
/
RFASTTranslatorForEffect.class.st
143 lines (106 loc) · 4.21 KB
/
RFASTTranslatorForEffect.class.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"
WORKAROUND: copy of OCASTTranslatorForEffect
Will be removed when the new Translor design is in place
"
Class {
#name : #RFASTTranslatorForEffect,
#superclass : #RFASTTranslator,
#category : #'Reflectivity-Compiler'
}
{ #category : #'inline messages' }
RFASTTranslatorForEffect >> emitAnd: aMessageNode [
super emitAnd: aMessageNode.
methodBuilder popTop.
]
{ #category : #'inline messages' }
RFASTTranslatorForEffect >> emitIfFalse: aMessageNode [
valueTranslator visitNode: aMessageNode receiver.
methodBuilder jumpAheadTo: #else if: true.
self visitInlinedBlockNode: aMessageNode arguments first.
methodBuilder jumpAheadTarget: #else.
]
{ #category : #'inline messages' }
RFASTTranslatorForEffect >> emitIfNotNil: aMessageNode [
| args |
valueTranslator visitNode: aMessageNode receiver.
args := aMessageNode arguments.
args first arguments ifNotEmpty: [ args first arguments first binding emitStore: methodBuilder ].
methodBuilder pushLiteral: nil.
methodBuilder send: #==.
methodBuilder jumpAheadTo: #end if: true.
self visitInlinedBlockNode: args first.
methodBuilder jumpAheadTarget: #end.
]
{ #category : #'inline messages' }
RFASTTranslatorForEffect >> emitIfTrue: aMessageNode [
valueTranslator visitNode: aMessageNode receiver.
methodBuilder jumpAheadTo: #else if: false.
self visitInlinedBlockNode: aMessageNode arguments first.
methodBuilder jumpAheadTarget: #else.
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> emitMessageNode: aMessageNode [
super emitMessageNode: aMessageNode.
methodBuilder popTop.
]
{ #category : #'inline messages' }
RFASTTranslatorForEffect >> emitOr: aMessageNode [
super emitOr: aMessageNode.
methodBuilder popTop.
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitArrayNode: anArrayNode [
"An arrayNode may have side effect, for example: '{self foo}'. So we cannot just generate nothing for this node."
super visitArrayNode: anArrayNode.
methodBuilder popTop.
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitAssignmentNode: anAssignmentNode [
super visitAssignmentNode: anAssignmentNode .
methodBuilder popTop.
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitBlockNode: aBlockNode [
"A block has no side effect, so a block translated for effect just doesn't generate anything"
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitLiteralArrayNode: aLiteralNode [
"when visiting a literal array for effect, we could push it and then pop it, but we do nothing"
methodBuilder addLiteral: aLiteralNode value
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitLiteralNode: aLiteralNode [
"when visiting a literal for effect, we could push it and then pop it, but we do nothing"
methodBuilder addLiteral: aLiteralNode value
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitParseErrorNode: anErrorNode [
super visitParseErrorNode: anErrorNode.
methodBuilder popTop.
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitSequenceNode: aSequenceNode [
self emitPreamble: aSequenceNode.
self emitMetaLinkBefore: aSequenceNode.
self emitPrepareLinkAfter: aSequenceNode.
aSequenceNode hasMetalinkInstead
ifTrue: [ self emitMetaLinkInstead: aSequenceNode ]
ifFalse: [ aSequenceNode statements do: [:each | self visitNode: each]. ].
self emitMetaLinkAfter: aSequenceNode.
(aSequenceNode hasMetalinkAfter or: [ aSequenceNode hasMetalinkInstead ]) ifTrue: [aSequenceNode parent isMethod
ifTrue: [methodBuilder returnTop]
ifFalse: [methodBuilder popTop]]
]
{ #category : #'visitor-double dispatching' }
RFASTTranslatorForEffect >> visitVariableNode: aVariableNode [
| binding |
self emitPreamble: aVariableNode.
self emitMetaLinkBefore: aVariableNode.
aVariableNode hasMetalinkInstead
ifTrue: [ self emitMetaLinkInstead: aVariableNode ].
"when visiting a variable for effect, we could push it and then pop it, but we do nothing"
binding := aVariableNode binding.
(binding isLiteralVariable or: [ binding isUndeclared ])
ifTrue: [ methodBuilder addLiteral: binding assoc ].
self emitMetaLinkAfterNoEnsure: aVariableNode.
]