OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE.md file. | |
4 | |
5 library fletchc.bytecode_builder; | |
6 | |
7 import 'package:semantic_visitor/semantic_visitor.dart' show | |
8 SemanticVisitor; | |
9 | |
10 import 'package:compiler/src/elements/elements.dart'; | |
11 import 'package:compiler/src/resolution/resolution.dart'; | |
12 import 'package:compiler/src/tree/tree.dart'; | |
13 import 'package:compiler/src/universe/universe.dart'; | |
14 import 'package:compiler/src/util/util.dart' show Spannable; | |
15 import 'package:compiler/src/dart_types.dart'; | |
16 | |
17 import 'fletch_context.dart'; | |
18 | |
19 import '../bytecodes.dart'; | |
20 | |
21 class BytecodeBuilder extends SemanticVisitor { | |
kasperl
2015/02/11 13:50:29
I think it might make sense to have three differen
ahe
2015/02/11 14:35:25
That makes a lot of sense. I'll try to get started
| |
22 final FletchContext context; | |
23 | |
24 final List<Bytecode> bytecodes = <Bytecode>[]; | |
25 | |
26 final Map<dynamic, int> constants = <dynamic, int>{}; | |
27 | |
28 BytecodeBuilder(this.context, element) | |
29 : super(element.resolvedAst.elements); | |
30 | |
31 int allocateConstant(constant) { | |
32 return constants.putIfAbsent(constant, () => constants.length); | |
33 } | |
34 | |
35 void visitStaticMethodInvocation( | |
36 Send node, | |
37 /* MethodElement */ element, | |
38 NodeList arguments, | |
39 Selector selector) { | |
40 arguments.accept(this); | |
41 int id = allocateConstant(element); | |
42 bytecodes.add(new InvokeStaticUnfold(id)); | |
43 } | |
44 | |
45 void visitLiteralString(LiteralString node) { | |
46 int id = allocateConstant(node.dartString.slowToString()); | |
47 bytecodes.add(new LoadConstUnfold(id)); | |
48 } | |
49 | |
50 void visitLiteralInt(LiteralInt node) { | |
51 int id = allocateConstant(node.value); | |
52 bytecodes.add(new LoadConstUnfold(id)); | |
53 } | |
54 | |
55 void visitFunctionExpression(FunctionExpression node) { | |
56 node.body.accept(this); | |
57 } | |
58 | |
59 void visitBlock(Block node) { | |
60 node.visitChildren(this); | |
61 } | |
62 | |
63 void visitNodeList(NodeList node) { | |
64 node.visitChildren(this); | |
65 } | |
66 | |
67 void visitExpressionStatement(ExpressionStatement node) { | |
68 node.visitChildren(this); | |
69 bytecodes.add(const Pop()); | |
70 } | |
71 | |
72 void visitParameterAccess( | |
73 Send node, | |
74 ParameterElement element) { | |
75 internalError( | |
76 node, "[visitParameterAccess] isn't implemented."); | |
77 } | |
78 | |
79 void visitParameterAssignment( | |
80 SendSet node, | |
81 ParameterElement element, | |
82 Node rhs) { | |
83 internalError( | |
84 node, "[visitParameterAssignment] isn't implemented."); | |
85 } | |
86 | |
87 void visitParameterInvocation( | |
88 Send node, | |
89 ParameterElement element, | |
90 NodeList arguments, | |
91 Selector selector) { | |
92 internalError( | |
93 node, "[visitParameterInvocation] isn't implemented."); | |
94 } | |
95 | |
96 void visitLocalVariableAccess( | |
97 Send node, | |
98 LocalVariableElement element) { | |
99 internalError( | |
100 node, "[visitLocalVariableAccess] isn't implemented."); | |
101 } | |
102 | |
103 void visitLocalVariableAssignment( | |
104 SendSet node, | |
105 LocalVariableElement element, | |
106 Node rhs) { | |
107 internalError( | |
108 node, "[visitLocalVariableAssignment] isn't implemented."); | |
109 } | |
110 | |
111 void visitLocalVariableInvocation( | |
112 Send node, | |
113 LocalVariableElement element, | |
114 NodeList arguments, | |
115 Selector selector) { | |
116 internalError( | |
117 node, "[visitLocalVariableInvocation] isn't implemented."); | |
118 } | |
119 | |
120 void visitLocalFunctionAccess( | |
121 Send node, | |
122 LocalFunctionElement element) { | |
123 internalError( | |
124 node, "[visitLocalFunctionAccess] isn't implemented."); | |
125 } | |
126 | |
127 void visitLocalFunctionAssignment( | |
128 SendSet node, | |
129 LocalFunctionElement element, | |
130 Node rhs, | |
131 Selector selector) { | |
132 internalError( | |
133 node, "[visitLocalFunctionAssignment] isn't implemented."); | |
134 } | |
135 | |
136 void visitLocalFunctionInvocation( | |
137 Send node, | |
138 LocalFunctionElement element, | |
139 NodeList arguments, | |
140 Selector selector) { | |
141 internalError( | |
142 node, "[visitLocalFunctionInvocation] isn't implemented."); | |
143 } | |
144 | |
145 void visitDynamicAccess( | |
146 Send node, | |
147 Selector selector) { | |
148 internalError( | |
149 node, "[visitDynamicAccess] isn't implemented."); | |
150 } | |
151 | |
152 void visitDynamicAssignment( | |
153 SendSet node, | |
154 Selector selector, | |
155 Node rhs) { | |
156 internalError( | |
157 node, "[visitDynamicAssignment] isn't implemented."); | |
158 } | |
159 | |
160 void visitDynamicInvocation( | |
161 Send node, | |
162 NodeList arguments, | |
163 Selector selector) { | |
164 internalError( | |
165 node, "[visitDynamicInvocation] isn't implemented."); | |
166 } | |
167 | |
168 void visitStaticFieldAccess( | |
169 Send node, | |
170 FieldElement element) { | |
171 internalError( | |
172 node, "[visitStaticFieldAccess] isn't implemented."); | |
173 } | |
174 | |
175 void visitStaticFieldAssignment( | |
176 SendSet node, | |
177 FieldElement element, | |
178 Node rhs) { | |
179 internalError( | |
180 node, "[visitStaticFieldAssignment] isn't implemented."); | |
181 } | |
182 | |
183 void visitStaticFieldInvocation( | |
184 Send node, | |
185 FieldElement element, | |
186 NodeList arguments, | |
187 Selector selector) { | |
188 internalError( | |
189 node, "[visitStaticFieldInvocation] isn't implemented."); | |
190 } | |
191 | |
192 void visitStaticMethodAccess( | |
193 Send node, | |
194 MethodElement element) { | |
195 internalError( | |
196 node, "[visitStaticMethodAccess] isn't implemented."); | |
197 } | |
198 | |
199 void visitStaticPropertyAccess( | |
200 Send node, | |
201 FunctionElement element) { | |
202 internalError( | |
203 node, "[visitStaticPropertyAccess] isn't implemented."); | |
204 } | |
205 | |
206 void visitStaticPropertyAssignment( | |
207 SendSet node, | |
208 FunctionElement element, | |
209 Node rhs) { | |
210 internalError( | |
211 node, "[visitStaticPropertyAssignment] isn't implemented."); | |
212 } | |
213 | |
214 void visitStaticPropertyInvocation( | |
215 Send node, | |
216 FieldElement element, | |
217 NodeList arguments, | |
218 Selector selector) { | |
219 internalError( | |
220 node, "[visitStaticPropertyInvocation] isn't implemented."); | |
221 } | |
222 | |
223 void visitTopLevelFieldAccess( | |
224 Send node, | |
225 FieldElement element) { | |
226 internalError( | |
227 node, "[visitTopLevelFieldAccess] isn't implemented."); | |
228 } | |
229 | |
230 void visitTopLevelFieldAssignment( | |
231 SendSet node, | |
232 FieldElement element, | |
233 Node rhs) { | |
234 internalError( | |
235 node, "[visitTopLevelFieldAssignment] isn't implemented."); | |
236 } | |
237 | |
238 void visitTopLevelFieldInvocation( | |
239 Send node, | |
240 FieldElement element, | |
241 NodeList arguments, | |
242 Selector selector) { | |
243 internalError( | |
244 node, "[visitTopLevelFieldInvocation] isn't implemented."); | |
245 } | |
246 | |
247 void visitTopLevelMethodAccess( | |
248 Send node, | |
249 MethodElement element) { | |
250 internalError( | |
251 node, "[visitTopLevelMethodAccess] isn't implemented."); | |
252 } | |
253 | |
254 void visitTopLevelMethodInvocation( | |
255 Send node, | |
256 MethodElement element, | |
257 NodeList arguments, | |
258 Selector selector) { | |
259 internalError( | |
260 node, "[visitTopLevelMethodInvocation] isn't implemented."); | |
261 } | |
262 | |
263 void visitTopLevelPropertyAccess( | |
264 Send node, | |
265 FunctionElement element) { | |
266 internalError( | |
267 node, "[visitTopLevelPropertyAccess] isn't implemented."); | |
268 } | |
269 | |
270 void visitTopLevelPropertyAssignment( | |
271 SendSet node, | |
272 FunctionElement element, | |
273 Node rhs) { | |
274 internalError( | |
275 node, "[visitTopLevelPropertyAssignment] isn't implemented."); | |
276 } | |
277 | |
278 void visitTopLevelPropertyInvocation( | |
279 Send node, | |
280 FieldElement element, | |
281 NodeList arguments, | |
282 Selector selector) { | |
283 internalError( | |
284 node, "[visitTopLevelPropertyInvocation] isn't implemented."); | |
285 } | |
286 | |
287 void visitClassTypeLiteralAccess( | |
288 Send node, | |
289 ClassElement element) { | |
290 internalError( | |
291 node, "[visitClassTypeLiteralAccess] isn't implemented."); | |
292 } | |
293 | |
294 void visitClassTypeLiteralInvocation( | |
295 Send node, | |
296 ClassElement element, | |
297 NodeList arguments, | |
298 Selector selector) { | |
299 internalError( | |
300 node, "[visitClassTypeLiteralInvocation] isn't implemented."); | |
301 } | |
302 | |
303 void visitClassTypeLiteralAssignment( | |
304 SendSet node, | |
305 ClassElement element, | |
306 Node rhs) { | |
307 internalError( | |
308 node, "[visitClassTypeLiteralAssignment] isn't implemented."); | |
309 } | |
310 | |
311 void visitTypedefTypeLiteralAccess( | |
312 Send node, | |
313 TypedefElement element) { | |
314 internalError( | |
315 node, "[visitTypedefTypeLiteralAccess] isn't implemented."); | |
316 } | |
317 | |
318 void visitTypedefTypeLiteralInvocation( | |
319 Send node, | |
320 TypedefElement element, | |
321 NodeList arguments, | |
322 Selector selector) { | |
323 internalError( | |
324 node, "[visitTypedefTypeLiteralInvocation] isn't implemented."); | |
325 } | |
326 | |
327 void visitTypedefTypeLiteralAssignment( | |
328 SendSet node, | |
329 TypedefElement element, | |
330 Node rhs) { | |
331 internalError( | |
332 node, "[visitTypedefTypeLiteralAssignment] isn't implemented."); | |
333 } | |
334 | |
335 void visitTypeVariableTypeLiteralAccess( | |
336 Send node, | |
337 TypeVariableElement element) { | |
338 internalError( | |
339 node, "[visitTypeVariableTypeLiteralAccess] isn't implemented."); | |
340 } | |
341 | |
342 void visitTypeVariableTypeLiteralInvocation( | |
343 Send node, | |
344 TypeVariableElement element, | |
345 NodeList arguments, | |
346 Selector selector) { | |
347 internalError( | |
348 node, "[visitTypeVariableTypeLiteralInvocation] isn't implemented."); | |
349 } | |
350 | |
351 void visitTypeVariableTypeLiteralAssignment( | |
352 SendSet node, | |
353 TypeVariableElement element, | |
354 Node rhs) { | |
355 internalError( | |
356 node, "[visitTypeVariableTypeLiteralAssignment] isn't implemented."); | |
357 } | |
358 | |
359 void visitDynamicTypeLiteralAccess( | |
360 Send node) { | |
361 internalError( | |
362 node, "[visitDynamicTypeLiteralAccess] isn't implemented."); | |
363 } | |
364 | |
365 void visitAssert( | |
366 Send node, | |
367 Node expression) { | |
368 internalError( | |
369 node, "[visitAssert] isn't implemented."); | |
370 } | |
371 | |
372 void internalError(Spannable spannable, String reason) { | |
373 context.compiler.internalError(spannable, reason); | |
374 } | |
375 } | |
OLD | NEW |