resin 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/amber/css/amber-normalize.css +73 -73
- data/amber/css/amber-normalize.less +1 -1
- data/amber/css/amber.css +106 -106
- data/amber/css/helios.css +242 -0
- data/amber/images/hsplitter.png +0 -0
- data/amber/images/vsplitter.png +0 -0
- data/amber/js/Benchfib.deploy.js +116 -38
- data/amber/js/Benchfib.js +120 -42
- data/amber/js/Canvas.deploy.js +674 -403
- data/amber/js/Canvas.js +682 -411
- data/amber/js/Compiler-AST.deploy.js +1150 -0
- data/amber/js/Compiler-AST.js +1591 -0
- data/amber/js/Compiler-Core.deploy.js +1562 -0
- data/amber/js/Compiler-Core.js +1972 -0
- data/amber/js/Compiler-Exceptions.deploy.js +114 -0
- data/amber/js/Compiler-Exceptions.js +161 -0
- data/amber/js/Compiler-IR.deploy.js +2326 -0
- data/amber/js/Compiler-IR.js +3146 -0
- data/amber/js/Compiler-Inlining.deploy.js +1147 -0
- data/amber/js/Compiler-Inlining.js +1514 -0
- data/amber/js/Compiler-Semantic.deploy.js +1207 -0
- data/amber/js/Compiler-Semantic.js +1628 -0
- data/amber/js/Compiler-Tests.deploy.js +646 -60
- data/amber/js/Compiler-Tests.js +843 -82
- data/amber/js/Compiler.deploy.js +1097 -159
- data/amber/js/Compiler.js +1414 -161
- data/amber/js/Examples.deploy.js +31 -15
- data/amber/js/Examples.js +33 -17
- data/amber/js/Helios-Announcements.deploy.js +127 -0
- data/amber/js/Helios-Announcements.js +157 -0
- data/amber/js/Helios-Browser.deploy.js +1473 -0
- data/amber/js/Helios-Browser.js +1953 -0
- data/amber/js/Helios-Commands.deploy.js +403 -0
- data/amber/js/Helios-Commands.js +563 -0
- data/amber/js/Helios-Core.deploy.js +1070 -0
- data/amber/js/Helios-Core.js +1445 -0
- data/amber/js/Helios-Environments.deploy.js +132 -0
- data/amber/js/Helios-Environments.js +179 -0
- data/amber/js/Helios-Inspector.deploy.js +855 -0
- data/amber/js/Helios-Inspector.js +1155 -0
- data/amber/js/Helios-KeyBindings.deploy.js +753 -0
- data/amber/js/Helios-KeyBindings.js +1023 -0
- data/amber/js/Helios-Layout.deploy.js +383 -0
- data/amber/js/Helios-Layout.js +523 -0
- data/amber/js/Helios-Workspace.deploy.js +799 -0
- data/amber/js/Helios-Workspace.js +1074 -0
- data/amber/js/IDE.deploy.js +2541 -1490
- data/amber/js/IDE.js +2721 -1660
- data/amber/js/Importer-Exporter.deploy.js +671 -0
- data/amber/js/Importer-Exporter.js +816 -0
- data/amber/js/Kernel-Announcements.deploy.js +137 -20
- data/amber/js/Kernel-Announcements.js +176 -22
- data/amber/js/Kernel-Classes.deploy.js +555 -168
- data/amber/js/Kernel-Classes.js +662 -205
- data/amber/js/Kernel-Collections.deploy.js +1403 -618
- data/amber/js/Kernel-Collections.js +1545 -690
- data/amber/js/Kernel-Exceptions.deploy.js +109 -45
- data/amber/js/Kernel-Exceptions.js +123 -49
- data/amber/js/Kernel-Methods.deploy.js +196 -81
- data/amber/js/Kernel-Methods.js +214 -89
- data/amber/js/Kernel-Objects.deploy.js +1542 -1117
- data/amber/js/Kernel-Objects.js +1593 -1148
- data/amber/js/Kernel-Tests.deploy.js +1725 -772
- data/amber/js/Kernel-Tests.js +2301 -1123
- data/amber/js/Kernel-Transcript.deploy.js +23 -25
- data/amber/js/Kernel-Transcript.js +24 -26
- data/amber/js/SUnit.deploy.js +204 -131
- data/amber/js/SUnit.js +222 -139
- data/amber/js/Spaces.deploy.js +240 -0
- data/amber/js/Spaces.js +326 -0
- data/amber/js/amber.js +26 -7
- data/amber/js/boot.js +65 -47
- data/amber/js/init.js +1 -1
- data/amber/js/lib/CodeMirror/amber.css +21 -21
- data/amber/js/lib/CodeMirror/codemirror.css +119 -13
- data/amber/js/lib/CodeMirror/codemirror.js +2219 -1220
- data/amber/js/lib/CodeMirror/smalltalk.js +134 -129
- data/amber/js/lib/bootstrap/css/bootstrap.css +5837 -0
- data/amber/js/lib/bootstrap/css/bootstrap.min.css +841 -0
- data/amber/js/lib/bootstrap/img/glyphicons-halflings-white.png +0 -0
- data/amber/js/lib/bootstrap/img/glyphicons-halflings.png +0 -0
- data/amber/js/lib/bootstrap/js/bootstrap.js +2038 -0
- data/amber/js/lib/bootstrap/js/bootstrap.min.js +7 -0
- data/amber/js/lib/jQuery/jquery-1.8.2.min.js +2 -0
- data/amber/js/lib/jQuery/jquery-ui-1.8.24.custom.min.js +125 -0
- data/amber/st/Compiler-AST.st +505 -0
- data/amber/st/Compiler-Core.st +835 -0
- data/amber/st/Compiler-Exceptions.st +87 -0
- data/amber/st/Compiler-IR.st +1097 -0
- data/amber/st/Compiler-Inlining.st +650 -0
- data/amber/st/Compiler-Semantic.st +558 -0
- data/amber/st/Compiler-Tests.st +285 -381
- data/amber/st/Compiler.st +725 -2
- data/amber/st/Helios-Announcements.st +104 -0
- data/amber/st/Helios-Browser.st +708 -0
- data/amber/st/Helios-Commands.st +223 -0
- data/amber/st/Helios-Core.st +532 -0
- data/amber/st/Helios-Environments.st +98 -0
- data/amber/st/Helios-Inspector.st +367 -0
- data/amber/st/Helios-KeyBindings.st +337 -0
- data/amber/st/Helios-Layout.st +199 -0
- data/amber/st/Helios-Workspace.st +367 -0
- data/amber/st/IDE.st +75 -53
- data/amber/st/Importer-Exporter.st +386 -0
- data/amber/st/Kernel-Announcements.st +92 -0
- data/amber/st/Kernel-Classes.st +137 -15
- data/amber/st/Kernel-Collections.st +137 -47
- data/amber/st/Kernel-Exceptions.st +14 -0
- data/amber/st/Kernel-Methods.st +9 -1
- data/amber/st/Kernel-Objects.st +29 -5
- data/amber/st/Kernel-Tests.st +545 -199
- data/amber/st/SUnit.st +10 -0
- data/amber/st/Spaces.st +142 -0
- data/lib/resin/app.rb +1 -1
- metadata +86 -31
- data/amber/js/lib/jQuery/jquery-1.4.4.min.js +0 -167
- data/amber/js/lib/jQuery/jquery-1.6.4.min.js +0 -4
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Smalltalk current createPackage: 'Compiler-Exceptions' properties: #{}!
|
|
2
|
+
Error subclass: #CompilerError
|
|
3
|
+
instanceVariableNames: ''
|
|
4
|
+
package: 'Compiler-Exceptions'!
|
|
5
|
+
!CompilerError commentStamp!
|
|
6
|
+
I am the common superclass of all compiling errors.!
|
|
7
|
+
|
|
8
|
+
CompilerError subclass: #ParseError
|
|
9
|
+
instanceVariableNames: ''
|
|
10
|
+
package: 'Compiler-Exceptions'!
|
|
11
|
+
!ParseError commentStamp!
|
|
12
|
+
Instance of ParseError are signaled on any parsing error.
|
|
13
|
+
See `Smalltalk >> #parse:`!
|
|
14
|
+
|
|
15
|
+
CompilerError subclass: #SemanticError
|
|
16
|
+
instanceVariableNames: ''
|
|
17
|
+
package: 'Compiler-Exceptions'!
|
|
18
|
+
!SemanticError commentStamp!
|
|
19
|
+
I represent an abstract semantic error thrown by the SemanticAnalyzer.
|
|
20
|
+
Semantic errors can be unknown variable errors, etc.
|
|
21
|
+
See my subclasses for concrete errors.
|
|
22
|
+
|
|
23
|
+
The IDE should catch instances of Semantic error to deal with them when compiling!
|
|
24
|
+
|
|
25
|
+
SemanticError subclass: #InliningError
|
|
26
|
+
instanceVariableNames: ''
|
|
27
|
+
package: 'Compiler-Exceptions'!
|
|
28
|
+
!InliningError commentStamp!
|
|
29
|
+
Instances of InliningError are signaled when using an `InliningCodeGenerator`in a `Compiler`.!
|
|
30
|
+
|
|
31
|
+
SemanticError subclass: #InvalidAssignmentError
|
|
32
|
+
instanceVariableNames: 'variableName'
|
|
33
|
+
package: 'Compiler-Exceptions'!
|
|
34
|
+
!InvalidAssignmentError commentStamp!
|
|
35
|
+
I get signaled when a pseudo variable gets assigned.!
|
|
36
|
+
|
|
37
|
+
!InvalidAssignmentError methodsFor: 'accessing'!
|
|
38
|
+
|
|
39
|
+
messageText
|
|
40
|
+
^ ' Invalid assignment to variable: ', self variableName
|
|
41
|
+
!
|
|
42
|
+
|
|
43
|
+
variableName
|
|
44
|
+
^ variableName
|
|
45
|
+
!
|
|
46
|
+
|
|
47
|
+
variableName: aString
|
|
48
|
+
variableName := aString
|
|
49
|
+
! !
|
|
50
|
+
|
|
51
|
+
SemanticError subclass: #ShadowingVariableError
|
|
52
|
+
instanceVariableNames: 'variableName'
|
|
53
|
+
package: 'Compiler-Exceptions'!
|
|
54
|
+
!ShadowingVariableError commentStamp!
|
|
55
|
+
I get signaled when a variable in a block or method scope shadows a variable of the same name in an outer scope.!
|
|
56
|
+
|
|
57
|
+
!ShadowingVariableError methodsFor: 'accessing'!
|
|
58
|
+
|
|
59
|
+
messageText
|
|
60
|
+
^ 'Variable shadowing error: ', self variableName, ' is already defined'
|
|
61
|
+
!
|
|
62
|
+
|
|
63
|
+
variableName
|
|
64
|
+
^ variableName
|
|
65
|
+
!
|
|
66
|
+
|
|
67
|
+
variableName: aString
|
|
68
|
+
variableName := aString
|
|
69
|
+
! !
|
|
70
|
+
|
|
71
|
+
SemanticError subclass: #UnknownVariableError
|
|
72
|
+
instanceVariableNames: 'variableName'
|
|
73
|
+
package: 'Compiler-Exceptions'!
|
|
74
|
+
!UnknownVariableError commentStamp!
|
|
75
|
+
I get signaled when a variable is not defined.
|
|
76
|
+
The default behavior is to allow it, as this is how Amber currently is able to seamlessly send messages to JavaScript objects.!
|
|
77
|
+
|
|
78
|
+
!UnknownVariableError methodsFor: 'accessing'!
|
|
79
|
+
|
|
80
|
+
variableName
|
|
81
|
+
^ variableName
|
|
82
|
+
!
|
|
83
|
+
|
|
84
|
+
variableName: aString
|
|
85
|
+
variableName := aString
|
|
86
|
+
! !
|
|
87
|
+
|
|
@@ -0,0 +1,1097 @@
|
|
|
1
|
+
Smalltalk current createPackage: 'Compiler-IR' properties: #{}!
|
|
2
|
+
NodeVisitor subclass: #IRASTTranslator
|
|
3
|
+
instanceVariableNames: 'source theClass method sequence nextAlias'
|
|
4
|
+
package: 'Compiler-IR'!
|
|
5
|
+
!IRASTTranslator commentStamp!
|
|
6
|
+
I am the AST (abstract syntax tree) visitor responsible for building the intermediate representation graph.
|
|
7
|
+
I rely on a builder object, instance of IRBuilder.!
|
|
8
|
+
|
|
9
|
+
!IRASTTranslator methodsFor: 'accessing'!
|
|
10
|
+
|
|
11
|
+
method
|
|
12
|
+
^ method
|
|
13
|
+
!
|
|
14
|
+
|
|
15
|
+
method: anIRMethod
|
|
16
|
+
method := anIRMethod
|
|
17
|
+
!
|
|
18
|
+
|
|
19
|
+
nextAlias
|
|
20
|
+
nextAlias ifNil: [ nextAlias := 0 ].
|
|
21
|
+
nextAlias := nextAlias + 1.
|
|
22
|
+
^ nextAlias asString
|
|
23
|
+
!
|
|
24
|
+
|
|
25
|
+
sequence
|
|
26
|
+
^ sequence
|
|
27
|
+
!
|
|
28
|
+
|
|
29
|
+
sequence: anIRSequence
|
|
30
|
+
sequence := anIRSequence
|
|
31
|
+
!
|
|
32
|
+
|
|
33
|
+
source
|
|
34
|
+
^ source
|
|
35
|
+
!
|
|
36
|
+
|
|
37
|
+
source: aString
|
|
38
|
+
source := aString
|
|
39
|
+
!
|
|
40
|
+
|
|
41
|
+
theClass
|
|
42
|
+
^ theClass
|
|
43
|
+
!
|
|
44
|
+
|
|
45
|
+
theClass: aClass
|
|
46
|
+
theClass := aClass
|
|
47
|
+
!
|
|
48
|
+
|
|
49
|
+
withSequence: aSequence do: aBlock
|
|
50
|
+
| outerSequence |
|
|
51
|
+
outerSequence := self sequence.
|
|
52
|
+
self sequence: aSequence.
|
|
53
|
+
aBlock value.
|
|
54
|
+
self sequence: outerSequence.
|
|
55
|
+
^ aSequence
|
|
56
|
+
! !
|
|
57
|
+
|
|
58
|
+
!IRASTTranslator methodsFor: 'visiting'!
|
|
59
|
+
|
|
60
|
+
alias: aNode
|
|
61
|
+
| variable |
|
|
62
|
+
|
|
63
|
+
aNode isValueNode ifTrue: [ ^ self visit: aNode ].
|
|
64
|
+
|
|
65
|
+
variable := IRVariable new
|
|
66
|
+
variable: (AliasVar new name: '$', self nextAlias);
|
|
67
|
+
yourself.
|
|
68
|
+
|
|
69
|
+
self sequence add: (IRAssignment new
|
|
70
|
+
add: variable;
|
|
71
|
+
add: (self visit: aNode);
|
|
72
|
+
yourself).
|
|
73
|
+
|
|
74
|
+
self method internalVariables add: variable.
|
|
75
|
+
|
|
76
|
+
^ variable
|
|
77
|
+
!
|
|
78
|
+
|
|
79
|
+
visitAssignmentNode: aNode
|
|
80
|
+
| left right assignment |
|
|
81
|
+
right := self visit: aNode right.
|
|
82
|
+
left := self visit: aNode left.
|
|
83
|
+
self sequence add: (IRAssignment new
|
|
84
|
+
add: left;
|
|
85
|
+
add: right;
|
|
86
|
+
yourself).
|
|
87
|
+
^ left
|
|
88
|
+
!
|
|
89
|
+
|
|
90
|
+
visitBlockNode: aNode
|
|
91
|
+
| closure |
|
|
92
|
+
closure := IRClosure new
|
|
93
|
+
arguments: aNode parameters;
|
|
94
|
+
scope: aNode scope;
|
|
95
|
+
yourself.
|
|
96
|
+
aNode scope temps do: [ :each |
|
|
97
|
+
closure add: (IRTempDeclaration new
|
|
98
|
+
name: each name;
|
|
99
|
+
yourself) ].
|
|
100
|
+
aNode nodes do: [ :each | closure add: (self visit: each) ].
|
|
101
|
+
^ closure
|
|
102
|
+
!
|
|
103
|
+
|
|
104
|
+
visitBlockSequenceNode: aNode
|
|
105
|
+
^ self
|
|
106
|
+
withSequence: IRBlockSequence new
|
|
107
|
+
do: [
|
|
108
|
+
aNode nodes ifNotEmpty: [
|
|
109
|
+
aNode nodes allButLast do: [ :each |
|
|
110
|
+
self sequence add: (self visit: each) ].
|
|
111
|
+
aNode nodes last isReturnNode
|
|
112
|
+
ifFalse: [ self sequence add: (IRBlockReturn new add: (self visit: aNode nodes last); yourself) ]
|
|
113
|
+
ifTrue: [ self sequence add: (self visit: aNode nodes last) ]]]
|
|
114
|
+
!
|
|
115
|
+
|
|
116
|
+
visitCascadeNode: aNode
|
|
117
|
+
| alias |
|
|
118
|
+
|
|
119
|
+
aNode receiver isValueNode ifFalse: [
|
|
120
|
+
alias := self alias: aNode receiver.
|
|
121
|
+
aNode nodes do: [ :each |
|
|
122
|
+
each receiver: (VariableNode new binding: alias variable) ]].
|
|
123
|
+
|
|
124
|
+
aNode nodes allButLast do: [ :each |
|
|
125
|
+
self sequence add: (self visit: each) ].
|
|
126
|
+
|
|
127
|
+
^ self alias: aNode nodes last
|
|
128
|
+
!
|
|
129
|
+
|
|
130
|
+
visitDynamicArrayNode: aNode
|
|
131
|
+
| array |
|
|
132
|
+
array := IRDynamicArray new.
|
|
133
|
+
aNode nodes do: [ :each | array add: (self visit: each) ].
|
|
134
|
+
^ array
|
|
135
|
+
!
|
|
136
|
+
|
|
137
|
+
visitDynamicDictionaryNode: aNode
|
|
138
|
+
| dictionary |
|
|
139
|
+
dictionary := IRDynamicDictionary new.
|
|
140
|
+
aNode nodes do: [ :each | dictionary add: (self visit: each) ].
|
|
141
|
+
^ dictionary
|
|
142
|
+
!
|
|
143
|
+
|
|
144
|
+
visitJSStatementNode: aNode
|
|
145
|
+
^ IRVerbatim new
|
|
146
|
+
source: aNode source;
|
|
147
|
+
yourself
|
|
148
|
+
!
|
|
149
|
+
|
|
150
|
+
visitMethodNode: aNode
|
|
151
|
+
|
|
152
|
+
self method: (IRMethod new
|
|
153
|
+
source: self source;
|
|
154
|
+
arguments: aNode arguments;
|
|
155
|
+
selector: aNode selector;
|
|
156
|
+
messageSends: aNode messageSends;
|
|
157
|
+
classReferences: aNode classReferences;
|
|
158
|
+
scope: aNode scope;
|
|
159
|
+
yourself).
|
|
160
|
+
|
|
161
|
+
aNode scope temps do: [ :each |
|
|
162
|
+
self method add: (IRTempDeclaration new
|
|
163
|
+
name: each name;
|
|
164
|
+
yourself) ].
|
|
165
|
+
|
|
166
|
+
aNode nodes do: [ :each | self method add: (self visit: each) ].
|
|
167
|
+
|
|
168
|
+
aNode scope hasLocalReturn ifFalse: [
|
|
169
|
+
(self method add: IRReturn new) add: (IRVariable new
|
|
170
|
+
variable: (aNode scope pseudoVars at: 'self');
|
|
171
|
+
yourself) ].
|
|
172
|
+
|
|
173
|
+
^ self method
|
|
174
|
+
!
|
|
175
|
+
|
|
176
|
+
visitReturnNode: aNode
|
|
177
|
+
| return |
|
|
178
|
+
return := aNode nonLocalReturn
|
|
179
|
+
ifTrue: [ IRNonLocalReturn new ]
|
|
180
|
+
ifFalse: [ IRReturn new ].
|
|
181
|
+
return scope: aNode scope.
|
|
182
|
+
aNode nodes do: [ :each |
|
|
183
|
+
return add: (self alias: each) ].
|
|
184
|
+
^ return
|
|
185
|
+
!
|
|
186
|
+
|
|
187
|
+
visitSendNode: aNode
|
|
188
|
+
| send receiver arguments |
|
|
189
|
+
send := IRSend new.
|
|
190
|
+
send
|
|
191
|
+
selector: aNode selector;
|
|
192
|
+
index: aNode index.
|
|
193
|
+
aNode superSend ifTrue: [ send classSend: self theClass superclass ].
|
|
194
|
+
|
|
195
|
+
receiver := (aNode receiver shouldBeInlined or: [ aNode receiver shouldBeAliased ])
|
|
196
|
+
ifTrue: [ self alias: aNode receiver ]
|
|
197
|
+
ifFalse: [ self visit: aNode receiver ].
|
|
198
|
+
|
|
199
|
+
arguments := aNode arguments collect: [ :each |
|
|
200
|
+
each shouldBeInlined
|
|
201
|
+
ifTrue: [ self alias: each ]
|
|
202
|
+
ifFalse: [ self visit: each ]].
|
|
203
|
+
|
|
204
|
+
send add: receiver.
|
|
205
|
+
arguments do: [ :each | send add: each ].
|
|
206
|
+
|
|
207
|
+
^ send
|
|
208
|
+
!
|
|
209
|
+
|
|
210
|
+
visitSequenceNode: aNode
|
|
211
|
+
^ self
|
|
212
|
+
withSequence: IRSequence new
|
|
213
|
+
do: [
|
|
214
|
+
aNode nodes do: [ :each | | instruction |
|
|
215
|
+
instruction := self visit: each.
|
|
216
|
+
instruction isVariable ifFalse: [
|
|
217
|
+
self sequence add: instruction ]]]
|
|
218
|
+
!
|
|
219
|
+
|
|
220
|
+
visitValueNode: aNode
|
|
221
|
+
^ IRValue new
|
|
222
|
+
value: aNode value;
|
|
223
|
+
yourself
|
|
224
|
+
!
|
|
225
|
+
|
|
226
|
+
visitVariableNode: aNode
|
|
227
|
+
^ IRVariable new
|
|
228
|
+
variable: aNode binding;
|
|
229
|
+
yourself
|
|
230
|
+
! !
|
|
231
|
+
|
|
232
|
+
Object subclass: #IRInstruction
|
|
233
|
+
instanceVariableNames: 'parent instructions'
|
|
234
|
+
package: 'Compiler-IR'!
|
|
235
|
+
!IRInstruction commentStamp!
|
|
236
|
+
I am the abstract root class of the IR (intermediate representation) instructions class hierarchy.
|
|
237
|
+
The IR graph is used to emit JavaScript code using a JSStream.!
|
|
238
|
+
|
|
239
|
+
!IRInstruction methodsFor: 'accessing'!
|
|
240
|
+
|
|
241
|
+
instructions
|
|
242
|
+
^ instructions ifNil: [ instructions := OrderedCollection new ]
|
|
243
|
+
!
|
|
244
|
+
|
|
245
|
+
parent
|
|
246
|
+
^ parent
|
|
247
|
+
!
|
|
248
|
+
|
|
249
|
+
parent: anIRInstruction
|
|
250
|
+
parent := anIRInstruction
|
|
251
|
+
! !
|
|
252
|
+
|
|
253
|
+
!IRInstruction methodsFor: 'building'!
|
|
254
|
+
|
|
255
|
+
add: anObject
|
|
256
|
+
anObject parent: self.
|
|
257
|
+
^ self instructions add: anObject
|
|
258
|
+
!
|
|
259
|
+
|
|
260
|
+
remove
|
|
261
|
+
self parent remove: self
|
|
262
|
+
!
|
|
263
|
+
|
|
264
|
+
remove: anIRInstruction
|
|
265
|
+
self instructions remove: anIRInstruction
|
|
266
|
+
!
|
|
267
|
+
|
|
268
|
+
replace: anIRInstruction with: anotherIRInstruction
|
|
269
|
+
anotherIRInstruction parent: self.
|
|
270
|
+
self instructions
|
|
271
|
+
at: (self instructions indexOf: anIRInstruction)
|
|
272
|
+
put: anotherIRInstruction
|
|
273
|
+
!
|
|
274
|
+
|
|
275
|
+
replaceWith: anIRInstruction
|
|
276
|
+
self parent replace: self with: anIRInstruction
|
|
277
|
+
! !
|
|
278
|
+
|
|
279
|
+
!IRInstruction methodsFor: 'testing'!
|
|
280
|
+
|
|
281
|
+
canBeAssigned
|
|
282
|
+
^ true
|
|
283
|
+
!
|
|
284
|
+
|
|
285
|
+
isClosure
|
|
286
|
+
^ false
|
|
287
|
+
!
|
|
288
|
+
|
|
289
|
+
isInlined
|
|
290
|
+
^ false
|
|
291
|
+
!
|
|
292
|
+
|
|
293
|
+
isLocalReturn
|
|
294
|
+
^ false
|
|
295
|
+
!
|
|
296
|
+
|
|
297
|
+
isReturn
|
|
298
|
+
^ false
|
|
299
|
+
!
|
|
300
|
+
|
|
301
|
+
isSend
|
|
302
|
+
^ false
|
|
303
|
+
!
|
|
304
|
+
|
|
305
|
+
isSequence
|
|
306
|
+
^ false
|
|
307
|
+
!
|
|
308
|
+
|
|
309
|
+
isTempDeclaration
|
|
310
|
+
^ false
|
|
311
|
+
!
|
|
312
|
+
|
|
313
|
+
isVariable
|
|
314
|
+
^ false
|
|
315
|
+
! !
|
|
316
|
+
|
|
317
|
+
!IRInstruction methodsFor: 'visiting'!
|
|
318
|
+
|
|
319
|
+
accept: aVisitor
|
|
320
|
+
^ aVisitor visitIRInstruction: self
|
|
321
|
+
! !
|
|
322
|
+
|
|
323
|
+
!IRInstruction class methodsFor: 'instance creation'!
|
|
324
|
+
|
|
325
|
+
on: aBuilder
|
|
326
|
+
^ self new
|
|
327
|
+
builder: aBuilder;
|
|
328
|
+
yourself
|
|
329
|
+
! !
|
|
330
|
+
|
|
331
|
+
IRInstruction subclass: #IRAssignment
|
|
332
|
+
instanceVariableNames: ''
|
|
333
|
+
package: 'Compiler-IR'!
|
|
334
|
+
|
|
335
|
+
!IRAssignment methodsFor: 'visiting'!
|
|
336
|
+
|
|
337
|
+
accept: aVisitor
|
|
338
|
+
^ aVisitor visitIRAssignment: self
|
|
339
|
+
! !
|
|
340
|
+
|
|
341
|
+
IRInstruction subclass: #IRDynamicArray
|
|
342
|
+
instanceVariableNames: ''
|
|
343
|
+
package: 'Compiler-IR'!
|
|
344
|
+
|
|
345
|
+
!IRDynamicArray methodsFor: 'visiting'!
|
|
346
|
+
|
|
347
|
+
accept: aVisitor
|
|
348
|
+
^ aVisitor visitIRDynamicArray: self
|
|
349
|
+
! !
|
|
350
|
+
|
|
351
|
+
IRInstruction subclass: #IRDynamicDictionary
|
|
352
|
+
instanceVariableNames: ''
|
|
353
|
+
package: 'Compiler-IR'!
|
|
354
|
+
|
|
355
|
+
!IRDynamicDictionary methodsFor: 'visiting'!
|
|
356
|
+
|
|
357
|
+
accept: aVisitor
|
|
358
|
+
^ aVisitor visitIRDynamicDictionary: self
|
|
359
|
+
! !
|
|
360
|
+
|
|
361
|
+
IRInstruction subclass: #IRScopedInstruction
|
|
362
|
+
instanceVariableNames: 'scope'
|
|
363
|
+
package: 'Compiler-IR'!
|
|
364
|
+
|
|
365
|
+
!IRScopedInstruction methodsFor: 'accessing'!
|
|
366
|
+
|
|
367
|
+
scope
|
|
368
|
+
^ scope
|
|
369
|
+
!
|
|
370
|
+
|
|
371
|
+
scope: aScope
|
|
372
|
+
scope := aScope
|
|
373
|
+
! !
|
|
374
|
+
|
|
375
|
+
IRScopedInstruction subclass: #IRClosure
|
|
376
|
+
instanceVariableNames: 'arguments'
|
|
377
|
+
package: 'Compiler-IR'!
|
|
378
|
+
|
|
379
|
+
!IRClosure methodsFor: 'accessing'!
|
|
380
|
+
|
|
381
|
+
arguments
|
|
382
|
+
^ arguments ifNil: [ #() ]
|
|
383
|
+
!
|
|
384
|
+
|
|
385
|
+
arguments: aCollection
|
|
386
|
+
arguments := aCollection
|
|
387
|
+
!
|
|
388
|
+
|
|
389
|
+
scope: aScope
|
|
390
|
+
super scope: aScope.
|
|
391
|
+
aScope instruction: self
|
|
392
|
+
!
|
|
393
|
+
|
|
394
|
+
sequence
|
|
395
|
+
^ self instructions last
|
|
396
|
+
! !
|
|
397
|
+
|
|
398
|
+
!IRClosure methodsFor: 'testing'!
|
|
399
|
+
|
|
400
|
+
isClosure
|
|
401
|
+
^ true
|
|
402
|
+
! !
|
|
403
|
+
|
|
404
|
+
!IRClosure methodsFor: 'visiting'!
|
|
405
|
+
|
|
406
|
+
accept: aVisitor
|
|
407
|
+
^ aVisitor visitIRClosure: self
|
|
408
|
+
! !
|
|
409
|
+
|
|
410
|
+
IRScopedInstruction subclass: #IRMethod
|
|
411
|
+
instanceVariableNames: 'source selector classReferences messageSends arguments internalVariables'
|
|
412
|
+
package: 'Compiler-IR'!
|
|
413
|
+
!IRMethod commentStamp!
|
|
414
|
+
I am a method instruction!
|
|
415
|
+
|
|
416
|
+
!IRMethod methodsFor: 'accessing'!
|
|
417
|
+
|
|
418
|
+
arguments
|
|
419
|
+
^ arguments
|
|
420
|
+
!
|
|
421
|
+
|
|
422
|
+
arguments: aCollection
|
|
423
|
+
arguments := aCollection
|
|
424
|
+
!
|
|
425
|
+
|
|
426
|
+
classReferences
|
|
427
|
+
^ classReferences
|
|
428
|
+
!
|
|
429
|
+
|
|
430
|
+
classReferences: aCollection
|
|
431
|
+
classReferences := aCollection
|
|
432
|
+
!
|
|
433
|
+
|
|
434
|
+
internalVariables
|
|
435
|
+
^ internalVariables ifNil: [ internalVariables := Set new ]
|
|
436
|
+
!
|
|
437
|
+
|
|
438
|
+
messageSends
|
|
439
|
+
^ messageSends
|
|
440
|
+
!
|
|
441
|
+
|
|
442
|
+
messageSends: aCollection
|
|
443
|
+
messageSends := aCollection
|
|
444
|
+
!
|
|
445
|
+
|
|
446
|
+
scope: aScope
|
|
447
|
+
super scope: aScope.
|
|
448
|
+
aScope instruction: self
|
|
449
|
+
!
|
|
450
|
+
|
|
451
|
+
selector
|
|
452
|
+
^ selector
|
|
453
|
+
!
|
|
454
|
+
|
|
455
|
+
selector: aString
|
|
456
|
+
selector := aString
|
|
457
|
+
!
|
|
458
|
+
|
|
459
|
+
source
|
|
460
|
+
^ source
|
|
461
|
+
!
|
|
462
|
+
|
|
463
|
+
source: aString
|
|
464
|
+
source := aString
|
|
465
|
+
! !
|
|
466
|
+
|
|
467
|
+
!IRMethod methodsFor: 'visiting'!
|
|
468
|
+
|
|
469
|
+
accept: aVisitor
|
|
470
|
+
^ aVisitor visitIRMethod: self
|
|
471
|
+
! !
|
|
472
|
+
|
|
473
|
+
IRScopedInstruction subclass: #IRReturn
|
|
474
|
+
instanceVariableNames: ''
|
|
475
|
+
package: 'Compiler-IR'!
|
|
476
|
+
!IRReturn commentStamp!
|
|
477
|
+
I am a local return instruction.!
|
|
478
|
+
|
|
479
|
+
!IRReturn methodsFor: 'testing'!
|
|
480
|
+
|
|
481
|
+
canBeAssigned
|
|
482
|
+
^ false
|
|
483
|
+
!
|
|
484
|
+
|
|
485
|
+
isBlockReturn
|
|
486
|
+
^ false
|
|
487
|
+
!
|
|
488
|
+
|
|
489
|
+
isLocalReturn
|
|
490
|
+
^ true
|
|
491
|
+
!
|
|
492
|
+
|
|
493
|
+
isNonLocalReturn
|
|
494
|
+
^ self isLocalReturn not
|
|
495
|
+
!
|
|
496
|
+
|
|
497
|
+
isReturn
|
|
498
|
+
^ true
|
|
499
|
+
! !
|
|
500
|
+
|
|
501
|
+
!IRReturn methodsFor: 'visiting'!
|
|
502
|
+
|
|
503
|
+
accept: aVisitor
|
|
504
|
+
^ aVisitor visitIRReturn: self
|
|
505
|
+
! !
|
|
506
|
+
|
|
507
|
+
IRReturn subclass: #IRBlockReturn
|
|
508
|
+
instanceVariableNames: ''
|
|
509
|
+
package: 'Compiler-IR'!
|
|
510
|
+
!IRBlockReturn commentStamp!
|
|
511
|
+
Smalltalk blocks return their last statement. I am a implicit block return instruction.!
|
|
512
|
+
|
|
513
|
+
!IRBlockReturn methodsFor: 'testing'!
|
|
514
|
+
|
|
515
|
+
isBlockReturn
|
|
516
|
+
^ true
|
|
517
|
+
! !
|
|
518
|
+
|
|
519
|
+
!IRBlockReturn methodsFor: 'visiting'!
|
|
520
|
+
|
|
521
|
+
accept: aVisitor
|
|
522
|
+
^ aVisitor visitIRBlockReturn: self
|
|
523
|
+
! !
|
|
524
|
+
|
|
525
|
+
IRReturn subclass: #IRNonLocalReturn
|
|
526
|
+
instanceVariableNames: ''
|
|
527
|
+
package: 'Compiler-IR'!
|
|
528
|
+
!IRNonLocalReturn commentStamp!
|
|
529
|
+
I am a non local return instruction.
|
|
530
|
+
Non local returns are handled using a try/catch JS statement.
|
|
531
|
+
|
|
532
|
+
See IRNonLocalReturnHandling class!
|
|
533
|
+
|
|
534
|
+
!IRNonLocalReturn methodsFor: 'testing'!
|
|
535
|
+
|
|
536
|
+
isLocalReturn
|
|
537
|
+
^ false
|
|
538
|
+
! !
|
|
539
|
+
|
|
540
|
+
!IRNonLocalReturn methodsFor: 'visiting'!
|
|
541
|
+
|
|
542
|
+
accept: aVisitor
|
|
543
|
+
^ aVisitor visitIRNonLocalReturn: self
|
|
544
|
+
! !
|
|
545
|
+
|
|
546
|
+
IRInstruction subclass: #IRSend
|
|
547
|
+
instanceVariableNames: 'selector classSend index'
|
|
548
|
+
package: 'Compiler-IR'!
|
|
549
|
+
!IRSend commentStamp!
|
|
550
|
+
I am a message send instruction.!
|
|
551
|
+
|
|
552
|
+
!IRSend methodsFor: 'accessing'!
|
|
553
|
+
|
|
554
|
+
classSend
|
|
555
|
+
^ classSend
|
|
556
|
+
!
|
|
557
|
+
|
|
558
|
+
classSend: aClass
|
|
559
|
+
classSend := aClass
|
|
560
|
+
!
|
|
561
|
+
|
|
562
|
+
index
|
|
563
|
+
^ index
|
|
564
|
+
!
|
|
565
|
+
|
|
566
|
+
index: anInteger
|
|
567
|
+
index := anInteger
|
|
568
|
+
!
|
|
569
|
+
|
|
570
|
+
selector
|
|
571
|
+
^ selector
|
|
572
|
+
!
|
|
573
|
+
|
|
574
|
+
selector: aString
|
|
575
|
+
selector := aString
|
|
576
|
+
! !
|
|
577
|
+
|
|
578
|
+
!IRSend methodsFor: 'testing'!
|
|
579
|
+
|
|
580
|
+
isSend
|
|
581
|
+
^ true
|
|
582
|
+
! !
|
|
583
|
+
|
|
584
|
+
!IRSend methodsFor: 'visiting'!
|
|
585
|
+
|
|
586
|
+
accept: aVisitor
|
|
587
|
+
^ aVisitor visitIRSend: self
|
|
588
|
+
! !
|
|
589
|
+
|
|
590
|
+
IRInstruction subclass: #IRSequence
|
|
591
|
+
instanceVariableNames: ''
|
|
592
|
+
package: 'Compiler-IR'!
|
|
593
|
+
|
|
594
|
+
!IRSequence methodsFor: 'testing'!
|
|
595
|
+
|
|
596
|
+
isSequence
|
|
597
|
+
^ true
|
|
598
|
+
! !
|
|
599
|
+
|
|
600
|
+
!IRSequence methodsFor: 'visiting'!
|
|
601
|
+
|
|
602
|
+
accept: aVisitor
|
|
603
|
+
^ aVisitor visitIRSequence: self
|
|
604
|
+
! !
|
|
605
|
+
|
|
606
|
+
IRSequence subclass: #IRBlockSequence
|
|
607
|
+
instanceVariableNames: ''
|
|
608
|
+
package: 'Compiler-IR'!
|
|
609
|
+
|
|
610
|
+
!IRBlockSequence methodsFor: 'visiting'!
|
|
611
|
+
|
|
612
|
+
accept: aVisitor
|
|
613
|
+
^ aVisitor visitIRBlockSequence: self
|
|
614
|
+
! !
|
|
615
|
+
|
|
616
|
+
IRInstruction subclass: #IRTempDeclaration
|
|
617
|
+
instanceVariableNames: 'name'
|
|
618
|
+
package: 'Compiler-IR'!
|
|
619
|
+
!IRTempDeclaration commentStamp!
|
|
620
|
+
I am a temporary variable declaration instruction!
|
|
621
|
+
|
|
622
|
+
!IRTempDeclaration methodsFor: 'accessing'!
|
|
623
|
+
|
|
624
|
+
name
|
|
625
|
+
^ name
|
|
626
|
+
!
|
|
627
|
+
|
|
628
|
+
name: aString
|
|
629
|
+
name := aString
|
|
630
|
+
! !
|
|
631
|
+
|
|
632
|
+
!IRTempDeclaration methodsFor: 'visiting'!
|
|
633
|
+
|
|
634
|
+
accept: aVisitor
|
|
635
|
+
^ aVisitor visitIRTempDeclaration: self
|
|
636
|
+
!
|
|
637
|
+
|
|
638
|
+
isTempDeclaration
|
|
639
|
+
^ true
|
|
640
|
+
! !
|
|
641
|
+
|
|
642
|
+
IRInstruction subclass: #IRValue
|
|
643
|
+
instanceVariableNames: 'value'
|
|
644
|
+
package: 'Compiler-IR'!
|
|
645
|
+
!IRValue commentStamp!
|
|
646
|
+
I am the simplest possible instruction. I represent a value.!
|
|
647
|
+
|
|
648
|
+
!IRValue methodsFor: 'accessing'!
|
|
649
|
+
|
|
650
|
+
value
|
|
651
|
+
^value
|
|
652
|
+
!
|
|
653
|
+
|
|
654
|
+
value: aString
|
|
655
|
+
value := aString
|
|
656
|
+
! !
|
|
657
|
+
|
|
658
|
+
!IRValue methodsFor: 'visiting'!
|
|
659
|
+
|
|
660
|
+
accept: aVisitor
|
|
661
|
+
^ aVisitor visitIRValue: self
|
|
662
|
+
! !
|
|
663
|
+
|
|
664
|
+
IRInstruction subclass: #IRVariable
|
|
665
|
+
instanceVariableNames: 'variable'
|
|
666
|
+
package: 'Compiler-IR'!
|
|
667
|
+
!IRVariable commentStamp!
|
|
668
|
+
I am a variable instruction.!
|
|
669
|
+
|
|
670
|
+
!IRVariable methodsFor: 'accessing'!
|
|
671
|
+
|
|
672
|
+
variable
|
|
673
|
+
^ variable
|
|
674
|
+
!
|
|
675
|
+
|
|
676
|
+
variable: aScopeVariable
|
|
677
|
+
variable := aScopeVariable
|
|
678
|
+
! !
|
|
679
|
+
|
|
680
|
+
!IRVariable methodsFor: 'testing'!
|
|
681
|
+
|
|
682
|
+
isVariable
|
|
683
|
+
^ true
|
|
684
|
+
! !
|
|
685
|
+
|
|
686
|
+
!IRVariable methodsFor: 'visiting'!
|
|
687
|
+
|
|
688
|
+
accept: aVisitor
|
|
689
|
+
^ aVisitor visitIRVariable: self
|
|
690
|
+
! !
|
|
691
|
+
|
|
692
|
+
IRInstruction subclass: #IRVerbatim
|
|
693
|
+
instanceVariableNames: 'source'
|
|
694
|
+
package: 'Compiler-IR'!
|
|
695
|
+
|
|
696
|
+
!IRVerbatim methodsFor: 'accessing'!
|
|
697
|
+
|
|
698
|
+
source
|
|
699
|
+
^ source
|
|
700
|
+
!
|
|
701
|
+
|
|
702
|
+
source: aString
|
|
703
|
+
source := aString
|
|
704
|
+
! !
|
|
705
|
+
|
|
706
|
+
!IRVerbatim methodsFor: 'visiting'!
|
|
707
|
+
|
|
708
|
+
accept: aVisitor
|
|
709
|
+
^ aVisitor visitIRVerbatim: self
|
|
710
|
+
! !
|
|
711
|
+
|
|
712
|
+
Object subclass: #IRVisitor
|
|
713
|
+
instanceVariableNames: ''
|
|
714
|
+
package: 'Compiler-IR'!
|
|
715
|
+
|
|
716
|
+
!IRVisitor methodsFor: 'visiting'!
|
|
717
|
+
|
|
718
|
+
visit: anIRInstruction
|
|
719
|
+
^ anIRInstruction accept: self
|
|
720
|
+
!
|
|
721
|
+
|
|
722
|
+
visitIRAssignment: anIRAssignment
|
|
723
|
+
^ self visitIRInstruction: anIRAssignment
|
|
724
|
+
!
|
|
725
|
+
|
|
726
|
+
visitIRBlockReturn: anIRBlockReturn
|
|
727
|
+
^ self visitIRReturn: anIRBlockReturn
|
|
728
|
+
!
|
|
729
|
+
|
|
730
|
+
visitIRBlockSequence: anIRBlockSequence
|
|
731
|
+
^ self visitIRSequence: anIRBlockSequence
|
|
732
|
+
!
|
|
733
|
+
|
|
734
|
+
visitIRClosure: anIRClosure
|
|
735
|
+
^ self visitIRInstruction: anIRClosure
|
|
736
|
+
!
|
|
737
|
+
|
|
738
|
+
visitIRDynamicArray: anIRDynamicArray
|
|
739
|
+
^ self visitIRInstruction: anIRDynamicArray
|
|
740
|
+
!
|
|
741
|
+
|
|
742
|
+
visitIRDynamicDictionary: anIRDynamicDictionary
|
|
743
|
+
^ self visitIRInstruction: anIRDynamicDictionary
|
|
744
|
+
!
|
|
745
|
+
|
|
746
|
+
visitIRInlinedClosure: anIRInlinedClosure
|
|
747
|
+
^ self visitIRClosure: anIRInlinedClosure
|
|
748
|
+
!
|
|
749
|
+
|
|
750
|
+
visitIRInlinedSequence: anIRInlinedSequence
|
|
751
|
+
^ self visitIRSequence: anIRInlinedSequence
|
|
752
|
+
!
|
|
753
|
+
|
|
754
|
+
visitIRInstruction: anIRInstruction
|
|
755
|
+
anIRInstruction instructions do: [ :each | self visit: each ].
|
|
756
|
+
^ anIRInstruction
|
|
757
|
+
!
|
|
758
|
+
|
|
759
|
+
visitIRMethod: anIRMethod
|
|
760
|
+
^ self visitIRInstruction: anIRMethod
|
|
761
|
+
!
|
|
762
|
+
|
|
763
|
+
visitIRNonLocalReturn: anIRNonLocalReturn
|
|
764
|
+
^ self visitIRInstruction: anIRNonLocalReturn
|
|
765
|
+
!
|
|
766
|
+
|
|
767
|
+
visitIRNonLocalReturnHandling: anIRNonLocalReturnHandling
|
|
768
|
+
^ self visitIRInstruction: anIRNonLocalReturnHandling
|
|
769
|
+
!
|
|
770
|
+
|
|
771
|
+
visitIRReturn: anIRReturn
|
|
772
|
+
^ self visitIRInstruction: anIRReturn
|
|
773
|
+
!
|
|
774
|
+
|
|
775
|
+
visitIRSend: anIRSend
|
|
776
|
+
^ self visitIRInstruction: anIRSend
|
|
777
|
+
!
|
|
778
|
+
|
|
779
|
+
visitIRSequence: anIRSequence
|
|
780
|
+
^ self visitIRInstruction: anIRSequence
|
|
781
|
+
!
|
|
782
|
+
|
|
783
|
+
visitIRTempDeclaration: anIRTempDeclaration
|
|
784
|
+
^ self visitIRInstruction: anIRTempDeclaration
|
|
785
|
+
!
|
|
786
|
+
|
|
787
|
+
visitIRValue: anIRValue
|
|
788
|
+
^ self visitIRInstruction: anIRValue
|
|
789
|
+
!
|
|
790
|
+
|
|
791
|
+
visitIRVariable: anIRVariable
|
|
792
|
+
^ self visitIRInstruction: anIRVariable
|
|
793
|
+
!
|
|
794
|
+
|
|
795
|
+
visitIRVerbatim: anIRVerbatim
|
|
796
|
+
^ self visitIRInstruction: anIRVerbatim
|
|
797
|
+
! !
|
|
798
|
+
|
|
799
|
+
IRVisitor subclass: #IRJSTranslator
|
|
800
|
+
instanceVariableNames: 'stream'
|
|
801
|
+
package: 'Compiler-IR'!
|
|
802
|
+
|
|
803
|
+
!IRJSTranslator methodsFor: 'accessing'!
|
|
804
|
+
|
|
805
|
+
contents
|
|
806
|
+
^ self stream contents
|
|
807
|
+
!
|
|
808
|
+
|
|
809
|
+
stream
|
|
810
|
+
^ stream
|
|
811
|
+
!
|
|
812
|
+
|
|
813
|
+
stream: aStream
|
|
814
|
+
stream := aStream
|
|
815
|
+
! !
|
|
816
|
+
|
|
817
|
+
!IRJSTranslator methodsFor: 'initialization'!
|
|
818
|
+
|
|
819
|
+
initialize
|
|
820
|
+
super initialize.
|
|
821
|
+
stream := JSStream new.
|
|
822
|
+
! !
|
|
823
|
+
|
|
824
|
+
!IRJSTranslator methodsFor: 'visiting'!
|
|
825
|
+
|
|
826
|
+
visitIRAssignment: anIRAssignment
|
|
827
|
+
self visit: anIRAssignment instructions first.
|
|
828
|
+
self stream nextPutAssignment.
|
|
829
|
+
self visit: anIRAssignment instructions last.
|
|
830
|
+
!
|
|
831
|
+
|
|
832
|
+
visitIRClosure: anIRClosure
|
|
833
|
+
self stream
|
|
834
|
+
nextPutClosureWith: [ super visitIRClosure: anIRClosure ]
|
|
835
|
+
arguments: anIRClosure arguments
|
|
836
|
+
!
|
|
837
|
+
|
|
838
|
+
visitIRDynamicArray: anIRDynamicArray
|
|
839
|
+
self stream nextPutAll: '['.
|
|
840
|
+
anIRDynamicArray instructions
|
|
841
|
+
do: [ :each | self visit: each ]
|
|
842
|
+
separatedBy: [ self stream nextPutAll: ',' ].
|
|
843
|
+
stream nextPutAll: ']'
|
|
844
|
+
!
|
|
845
|
+
|
|
846
|
+
visitIRDynamicDictionary: anIRDynamicDictionary
|
|
847
|
+
self stream nextPutAll: 'smalltalk.HashedCollection._fromPairs_(['.
|
|
848
|
+
anIRDynamicDictionary instructions
|
|
849
|
+
do: [ :each | self visit: each ]
|
|
850
|
+
separatedBy: [self stream nextPutAll: ',' ].
|
|
851
|
+
self stream nextPutAll: '])'
|
|
852
|
+
!
|
|
853
|
+
|
|
854
|
+
visitIRMethod: anIRMethod
|
|
855
|
+
self stream
|
|
856
|
+
nextPutMethodDeclaration: anIRMethod
|
|
857
|
+
with: [ self stream
|
|
858
|
+
nextPutFunctionWith: [
|
|
859
|
+
anIRMethod internalVariables notEmpty ifTrue: [
|
|
860
|
+
self stream nextPutVars: (anIRMethod internalVariables asArray collect: [ :each |
|
|
861
|
+
each variable alias ]) ].
|
|
862
|
+
anIRMethod scope hasNonLocalReturn
|
|
863
|
+
ifTrue: [
|
|
864
|
+
self stream nextPutNonLocalReturnHandlingWith: [
|
|
865
|
+
super visitIRMethod: anIRMethod ]]
|
|
866
|
+
ifFalse: [ super visitIRMethod: anIRMethod ]]
|
|
867
|
+
arguments: anIRMethod arguments ]
|
|
868
|
+
!
|
|
869
|
+
|
|
870
|
+
visitIRNonLocalReturn: anIRNonLocalReturn
|
|
871
|
+
self stream nextPutNonLocalReturnWith: [
|
|
872
|
+
super visitIRNonLocalReturn: anIRNonLocalReturn ]
|
|
873
|
+
!
|
|
874
|
+
|
|
875
|
+
visitIRReturn: anIRReturn
|
|
876
|
+
self stream nextPutReturnWith: [
|
|
877
|
+
super visitIRReturn: anIRReturn ]
|
|
878
|
+
!
|
|
879
|
+
|
|
880
|
+
visitIRSend: anIRSend
|
|
881
|
+
self stream nextPutAll: 'smalltalk.send('.
|
|
882
|
+
self visit: anIRSend instructions first.
|
|
883
|
+
self stream nextPutAll: ',"', anIRSend selector asSelector, '",['.
|
|
884
|
+
anIRSend instructions allButFirst
|
|
885
|
+
do: [ :each | self visit: each ]
|
|
886
|
+
separatedBy: [ self stream nextPutAll: ',' ].
|
|
887
|
+
self stream nextPutAll: ']'.
|
|
888
|
+
"anIRSend index > 1
|
|
889
|
+
ifTrue: [
|
|
890
|
+
anIRSend classSend
|
|
891
|
+
ifNil: [ self stream nextPutAll: ',undefined' ]
|
|
892
|
+
ifNotNil: [ self stream nextPutAll: ',', anIRSend classSend asJavascript ].
|
|
893
|
+
self stream nextPutAll: ',', anIRSend index asString ]
|
|
894
|
+
ifFalse: ["
|
|
895
|
+
anIRSend classSend ifNotNil: [
|
|
896
|
+
self stream nextPutAll: ',', anIRSend classSend asJavascript ]"]".
|
|
897
|
+
self stream nextPutAll: ')'
|
|
898
|
+
!
|
|
899
|
+
|
|
900
|
+
visitIRSequence: anIRSequence
|
|
901
|
+
self stream nextPutSequenceWith: [
|
|
902
|
+
anIRSequence instructions do: [ :each |
|
|
903
|
+
self stream nextPutStatementWith: (self visit: each) ]]
|
|
904
|
+
!
|
|
905
|
+
|
|
906
|
+
visitIRTempDeclaration: anIRTempDeclaration
|
|
907
|
+
self stream nextPutVar: anIRTempDeclaration name asVariableName
|
|
908
|
+
!
|
|
909
|
+
|
|
910
|
+
visitIRValue: anIRValue
|
|
911
|
+
self stream nextPutAll: anIRValue value asJavascript
|
|
912
|
+
!
|
|
913
|
+
|
|
914
|
+
visitIRVariable: anIRVariable
|
|
915
|
+
anIRVariable variable name = 'thisContext'
|
|
916
|
+
ifTrue: [ self stream nextPutAll: 'smalltalk.getThisContext()' ]
|
|
917
|
+
ifFalse: [ self stream nextPutAll: anIRVariable variable alias ]
|
|
918
|
+
!
|
|
919
|
+
|
|
920
|
+
visitIRVerbatim: anIRVerbatim
|
|
921
|
+
self stream nextPutStatementWith: [
|
|
922
|
+
self stream nextPutAll: anIRVerbatim source ]
|
|
923
|
+
! !
|
|
924
|
+
|
|
925
|
+
Object subclass: #JSStream
|
|
926
|
+
instanceVariableNames: 'stream'
|
|
927
|
+
package: 'Compiler-IR'!
|
|
928
|
+
|
|
929
|
+
!JSStream methodsFor: 'accessing'!
|
|
930
|
+
|
|
931
|
+
contents
|
|
932
|
+
^ stream contents
|
|
933
|
+
! !
|
|
934
|
+
|
|
935
|
+
!JSStream methodsFor: 'initialization'!
|
|
936
|
+
|
|
937
|
+
initialize
|
|
938
|
+
super initialize.
|
|
939
|
+
stream := '' writeStream.
|
|
940
|
+
! !
|
|
941
|
+
|
|
942
|
+
!JSStream methodsFor: 'streaming'!
|
|
943
|
+
|
|
944
|
+
lf
|
|
945
|
+
stream lf
|
|
946
|
+
!
|
|
947
|
+
|
|
948
|
+
nextPut: aString
|
|
949
|
+
stream nextPut: aString
|
|
950
|
+
!
|
|
951
|
+
|
|
952
|
+
nextPutAll: aString
|
|
953
|
+
stream nextPutAll: aString
|
|
954
|
+
!
|
|
955
|
+
|
|
956
|
+
nextPutAssignment
|
|
957
|
+
stream nextPutAll: '='
|
|
958
|
+
!
|
|
959
|
+
|
|
960
|
+
nextPutClosureWith: aBlock arguments: anArray
|
|
961
|
+
stream nextPutAll: '(function('.
|
|
962
|
+
anArray
|
|
963
|
+
do: [ :each | stream nextPutAll: each asVariableName ]
|
|
964
|
+
separatedBy: [ stream nextPut: ',' ].
|
|
965
|
+
stream nextPutAll: '){'; lf.
|
|
966
|
+
aBlock value.
|
|
967
|
+
stream nextPutAll: '})'
|
|
968
|
+
!
|
|
969
|
+
|
|
970
|
+
nextPutFunctionWith: aBlock arguments: anArray
|
|
971
|
+
stream nextPutAll: 'fn: function('.
|
|
972
|
+
anArray
|
|
973
|
+
do: [ :each | stream nextPutAll: each asVariableName ]
|
|
974
|
+
separatedBy: [ stream nextPut: ',' ].
|
|
975
|
+
stream nextPutAll: '){'; lf.
|
|
976
|
+
stream nextPutAll: 'var self=this;'; lf.
|
|
977
|
+
aBlock value.
|
|
978
|
+
stream nextPutAll: '}'
|
|
979
|
+
!
|
|
980
|
+
|
|
981
|
+
nextPutIf: aBlock with: anotherBlock
|
|
982
|
+
stream nextPutAll: 'if('.
|
|
983
|
+
aBlock value.
|
|
984
|
+
stream nextPutAll: '){'; lf.
|
|
985
|
+
anotherBlock value.
|
|
986
|
+
stream nextPutAll: '}'
|
|
987
|
+
!
|
|
988
|
+
|
|
989
|
+
nextPutIfElse: aBlock with: ifBlock with: elseBlock
|
|
990
|
+
stream nextPutAll: 'if('.
|
|
991
|
+
aBlock value.
|
|
992
|
+
stream nextPutAll: '){'; lf.
|
|
993
|
+
ifBlock value.
|
|
994
|
+
stream nextPutAll: '} else {'; lf.
|
|
995
|
+
elseBlock value.
|
|
996
|
+
stream nextPutAll: '}'
|
|
997
|
+
!
|
|
998
|
+
|
|
999
|
+
nextPutMethodDeclaration: aMethod with: aBlock
|
|
1000
|
+
stream
|
|
1001
|
+
nextPutAll: 'smalltalk.method({'; lf;
|
|
1002
|
+
nextPutAll: 'selector: "', aMethod selector, '",'; lf;
|
|
1003
|
+
nextPutAll: 'source: ', aMethod source asJavascript, ',';lf.
|
|
1004
|
+
aBlock value.
|
|
1005
|
+
stream
|
|
1006
|
+
nextPutAll: ',', String lf, 'messageSends: ';
|
|
1007
|
+
nextPutAll: aMethod messageSends asArray asJavascript, ','; lf;
|
|
1008
|
+
nextPutAll: 'args: ', (aMethod arguments collect: [ :each | each value ]) asArray asJavascript, ','; lf;
|
|
1009
|
+
nextPutAll: 'referencedClasses: ['.
|
|
1010
|
+
aMethod classReferences
|
|
1011
|
+
do: [:each | stream nextPutAll: each asJavascript]
|
|
1012
|
+
separatedBy: [stream nextPutAll: ','].
|
|
1013
|
+
stream
|
|
1014
|
+
nextPutAll: ']';
|
|
1015
|
+
nextPutAll: '})'
|
|
1016
|
+
!
|
|
1017
|
+
|
|
1018
|
+
nextPutNonLocalReturnHandlingWith: aBlock
|
|
1019
|
+
stream
|
|
1020
|
+
nextPutAll: 'var $early={};'; lf;
|
|
1021
|
+
nextPutAll: 'try {'; lf.
|
|
1022
|
+
aBlock value.
|
|
1023
|
+
stream
|
|
1024
|
+
nextPutAll: '}'; lf;
|
|
1025
|
+
nextPutAll: 'catch(e) {if(e===$early)return e[0]; throw e}'; lf
|
|
1026
|
+
!
|
|
1027
|
+
|
|
1028
|
+
nextPutNonLocalReturnWith: aBlock
|
|
1029
|
+
stream nextPutAll: 'throw $early=['.
|
|
1030
|
+
aBlock value.
|
|
1031
|
+
stream nextPutAll: ']'
|
|
1032
|
+
!
|
|
1033
|
+
|
|
1034
|
+
nextPutReturn
|
|
1035
|
+
stream nextPutAll: 'return '
|
|
1036
|
+
!
|
|
1037
|
+
|
|
1038
|
+
nextPutReturnWith: aBlock
|
|
1039
|
+
self nextPutReturn.
|
|
1040
|
+
aBlock value
|
|
1041
|
+
!
|
|
1042
|
+
|
|
1043
|
+
nextPutSendTo: receiver selector: selector arguments: arguments
|
|
1044
|
+
stream nextPutAll: 'smalltalk.send('.
|
|
1045
|
+
receiver emitOn: self.
|
|
1046
|
+
stream nextPutAll: ',"', selector asSelector, '",['.
|
|
1047
|
+
arguments
|
|
1048
|
+
do: [ :each | each emitOn: self ]
|
|
1049
|
+
separatedBy: [ stream nextPutAll: ',' ].
|
|
1050
|
+
stream nextPutAll: '])'
|
|
1051
|
+
!
|
|
1052
|
+
|
|
1053
|
+
nextPutSequenceWith: aBlock
|
|
1054
|
+
"stream
|
|
1055
|
+
nextPutAll: 'switch(smalltalk.thisContext.pc){'; lf."
|
|
1056
|
+
aBlock value.
|
|
1057
|
+
"stream
|
|
1058
|
+
nextPutAll: '};'; lf"
|
|
1059
|
+
!
|
|
1060
|
+
|
|
1061
|
+
nextPutStatement: anInteger with: aBlock
|
|
1062
|
+
stream nextPutAll: 'case ', anInteger asString, ':'; lf.
|
|
1063
|
+
self nextPutStatementWith: aBlock.
|
|
1064
|
+
stream nextPutAll: 'smalltalk.thisContext.pc=', (anInteger + 1) asString, ';'; lf
|
|
1065
|
+
!
|
|
1066
|
+
|
|
1067
|
+
nextPutStatementWith: aBlock
|
|
1068
|
+
aBlock value.
|
|
1069
|
+
stream nextPutAll: ';'; lf
|
|
1070
|
+
!
|
|
1071
|
+
|
|
1072
|
+
nextPutVar: aString
|
|
1073
|
+
stream nextPutAll: 'var ', aString, ';'; lf
|
|
1074
|
+
!
|
|
1075
|
+
|
|
1076
|
+
nextPutVars: aCollection
|
|
1077
|
+
stream nextPutAll: 'var '.
|
|
1078
|
+
aCollection
|
|
1079
|
+
do: [ :each | stream nextPutAll: each ]
|
|
1080
|
+
separatedBy: [ stream nextPutAll: ',' ].
|
|
1081
|
+
stream nextPutAll: ';'; lf
|
|
1082
|
+
! !
|
|
1083
|
+
|
|
1084
|
+
!BlockClosure methodsFor: '*Compiler-IR'!
|
|
1085
|
+
|
|
1086
|
+
appendToInstruction: anIRInstruction
|
|
1087
|
+
anIRInstruction appendBlock: self
|
|
1088
|
+
! !
|
|
1089
|
+
|
|
1090
|
+
!String methodsFor: '*Compiler-IR'!
|
|
1091
|
+
|
|
1092
|
+
asVariableName
|
|
1093
|
+
^ (Smalltalk current reservedWords includes: self)
|
|
1094
|
+
ifTrue: [ self, '_' ]
|
|
1095
|
+
ifFalse: [ self ]
|
|
1096
|
+
! !
|
|
1097
|
+
|