OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 class WorkItem { | 5 class WorkItem { |
6 final Element element; | 6 final Element element; |
7 TreeElements resolutionTree; | 7 TreeElements resolutionTree; |
8 Function run; | 8 Function run; |
9 bool allowSpeculativeOptimization = true; | 9 bool allowSpeculativeOptimization = true; |
10 List<HTypeGuard> guards = const <HTypeGuard>[]; | 10 List<HTypeGuard> guards = const <HTypeGuard>[]; |
(...skipping 17 matching lines...) Expand all Loading... | |
28 String codegen(Compiler compiler) { | 28 String codegen(Compiler compiler) { |
29 return compiler.codegen(this); | 29 return compiler.codegen(this); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 class Compiler implements DiagnosticListener { | 33 class Compiler implements DiagnosticListener { |
34 Queue<WorkItem> worklist; | 34 Queue<WorkItem> worklist; |
35 Universe universe; | 35 Universe universe; |
36 String assembledCode; | 36 String assembledCode; |
37 Namer namer; | 37 Namer namer; |
38 Types types; | 38 final Types types; |
39 | 39 |
40 final Tracer tracer; | 40 final Tracer tracer; |
41 | 41 |
42 CompilerTask measuredTask; | 42 CompilerTask measuredTask; |
43 Element _currentElement; | 43 Element _currentElement; |
44 LibraryElement coreLibrary; | 44 LibraryElement coreLibrary; |
45 LibraryElement coreImplLibrary; | 45 LibraryElement coreImplLibrary; |
46 LibraryElement isolateLibrary; | 46 LibraryElement isolateLibrary; |
47 LibraryElement jsHelperLibrary; | 47 LibraryElement jsHelperLibrary; |
48 LibraryElement mainApp; | 48 LibraryElement mainApp; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 void initializeSpecialClasses() { | 215 void initializeSpecialClasses() { |
216 objectClass = coreLibrary.find(const SourceString('Object')); | 216 objectClass = coreLibrary.find(const SourceString('Object')); |
217 boolClass = coreLibrary.find(const SourceString('bool')); | 217 boolClass = coreLibrary.find(const SourceString('bool')); |
218 numClass = coreLibrary.find(const SourceString('num')); | 218 numClass = coreLibrary.find(const SourceString('num')); |
219 intClass = coreLibrary.find(const SourceString('int')); | 219 intClass = coreLibrary.find(const SourceString('int')); |
220 doubleClass = coreLibrary.find(const SourceString('double')); | 220 doubleClass = coreLibrary.find(const SourceString('double')); |
221 stringClass = coreLibrary.find(const SourceString('String')); | 221 stringClass = coreLibrary.find(const SourceString('String')); |
222 functionClass = coreLibrary.find(const SourceString('Function')); | 222 functionClass = coreLibrary.find(const SourceString('Function')); |
223 listClass = coreLibrary.find(const SourceString('List')); | 223 listClass = coreLibrary.find(const SourceString('List')); |
224 closureClass = jsHelperLibrary.find(const SourceString('Closure')); | 224 closureClass = jsHelperLibrary.find(const SourceString('Closure')); |
225 dynamicClass = jsHelperLibrary.find(const SourceString('Dynamic')); | 225 dynamicClass = types.dynamicType.element; |
ahe
2012/04/12 15:05:23
I'd prefer getting the original to work.
| |
226 nullClass = jsHelperLibrary.find(const SourceString('Null')); | 226 nullClass = jsHelperLibrary.find(const SourceString('Null')); |
227 } | 227 } |
228 | 228 |
229 void scanBuiltinLibraries() { | 229 void scanBuiltinLibraries() { |
230 coreImplLibrary = scanBuiltinLibrary('coreimpl'); | 230 coreImplLibrary = scanBuiltinLibrary('coreimpl'); |
231 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 231 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); |
232 coreLibrary = scanBuiltinLibrary('core'); | 232 coreLibrary = scanBuiltinLibrary('core'); |
233 | 233 |
234 // Since coreLibrary import the libraries "coreimpl", and | 234 // Since coreLibrary import the libraries "coreimpl", and |
235 // "js_helper", coreLibrary is null when they are being built. So | 235 // "js_helper", coreLibrary is null when they are being built. So |
(...skipping 23 matching lines...) Expand all Loading... | |
259 const SourceString('JS_CURRENT_ISOLATE'), library), this); | 259 const SourceString('JS_CURRENT_ISOLATE'), library), this); |
260 library.define(new ForeignElement( | 260 library.define(new ForeignElement( |
261 const SourceString('JS_CALL_IN_ISOLATE'), library), this); | 261 const SourceString('JS_CALL_IN_ISOLATE'), library), this); |
262 library.define(new ForeignElement( | 262 library.define(new ForeignElement( |
263 const SourceString('DART_CLOSURE_TO_JS'), library), this); | 263 const SourceString('DART_CLOSURE_TO_JS'), library), this); |
264 } | 264 } |
265 | 265 |
266 void runCompiler(Uri uri) { | 266 void runCompiler(Uri uri) { |
267 scanBuiltinLibraries(); | 267 scanBuiltinLibraries(); |
268 mainApp = scanner.loadLibrary(uri, null); | 268 mainApp = scanner.loadLibrary(uri, null); |
269 final Element mainMethod = mainApp.find(MAIN); | 269 final Element mainElement = mainApp.find(MAIN); |
270 if (mainMethod === null) { | 270 if (mainElement === null) { |
271 withCurrentElement(mainApp, () => cancel('Could not find $MAIN')); | 271 withCurrentElement(mainApp, () => cancel('Could not find $MAIN')); |
272 } else { | 272 } else { |
273 withCurrentElement(mainMethod, () { | 273 withCurrentElement(mainElement, () { |
274 if (!mainMethod.isFunction()) { | 274 if (!mainElement.isFunction()) { |
275 cancel('main is not a function', element: mainMethod); | 275 cancel('main is not a function', element: mainElement); |
276 } | 276 } |
277 FunctionElement mainMethod = mainElement; | |
277 FunctionParameters parameters = mainMethod.computeParameters(this); | 278 FunctionParameters parameters = mainMethod.computeParameters(this); |
278 if (parameters.parameterCount > 0) { | 279 if (parameters.parameterCount > 0) { |
279 cancel('main cannot have parameters', element: mainMethod); | 280 cancel('main cannot have parameters', element: mainMethod); |
280 } | 281 } |
281 }); | 282 }); |
282 } | 283 } |
283 native.processNativeClasses(this, universe.libraries.getValues()); | 284 native.processNativeClasses(this, universe.libraries.getValues()); |
284 enqueue(new WorkItem.toCompile(mainMethod)); | 285 enqueue(new WorkItem.toCompile(mainElement)); |
285 codegenProgress.reset(); | 286 codegenProgress.reset(); |
286 while (!worklist.isEmpty()) { | 287 while (!worklist.isEmpty()) { |
287 WorkItem work = worklist.removeLast(); | 288 WorkItem work = worklist.removeLast(); |
288 withCurrentElement(work.element, () => (work.run)(this)); | 289 withCurrentElement(work.element, () => (work.run)(this)); |
289 } | 290 } |
290 workListIsClosed = true; | 291 workListIsClosed = true; |
291 assert(enqueuer.checkNoEnqueuedInvokedInstanceMethods()); | 292 assert(enqueuer.checkNoEnqueuedInvokedInstanceMethods()); |
292 enqueuer.registerFieldClosureInvocations(); | 293 enqueuer.registerFieldClosureInvocations(); |
293 emitter.assembleProgram(); | 294 emitter.assembleProgram(); |
294 if (!worklist.isEmpty()) { | 295 if (!worklist.isEmpty()) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 () => resolver.resolveSignature(element)); | 400 () => resolver.resolveSignature(element)); |
400 } | 401 } |
401 | 402 |
402 Constant compileVariable(VariableElement element) { | 403 Constant compileVariable(VariableElement element) { |
403 return withCurrentElement(element, () { | 404 return withCurrentElement(element, () { |
404 return constantHandler.compileVariable(element); | 405 return constantHandler.compileVariable(element); |
405 }); | 406 }); |
406 } | 407 } |
407 | 408 |
408 reportWarning(Node node, var message) { | 409 reportWarning(Node node, var message) { |
409 if (message is ResolutionWarning) { | 410 if (message is TypeWarning) { |
410 // TODO(ahe): Don't supress this warning when we support type variables. | |
411 if (message.message.kind === MessageKind.CANNOT_RESOLVE_TYPE) return; | |
412 } else if (message is TypeWarning) { | |
413 // TODO(ahe): Don't supress these warning when the type checker | 411 // TODO(ahe): Don't supress these warning when the type checker |
414 // is more complete. | 412 // is more complete. |
415 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return; | 413 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return; |
416 if (message.message.kind === MessageKind.MISSING_RETURN) return; | 414 if (message.message.kind === MessageKind.MISSING_RETURN) return; |
417 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return; | 415 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return; |
418 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return; | 416 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return; |
419 } | 417 } |
420 SourceSpan span = spanFromNode(node); | 418 SourceSpan span = spanFromNode(node); |
421 reportDiagnostic(span, "${magenta('warning:')} $message", false); | 419 reportDiagnostic(span, "${magenta('warning:')} $message", false); |
422 } | 420 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 } | 539 } |
542 } | 540 } |
543 | 541 |
544 class SourceSpan { | 542 class SourceSpan { |
545 final Uri uri; | 543 final Uri uri; |
546 final int begin; | 544 final int begin; |
547 final int end; | 545 final int end; |
548 | 546 |
549 const SourceSpan(this.uri, this.begin, this.end); | 547 const SourceSpan(this.uri, this.begin, this.end); |
550 } | 548 } |
OLD | NEW |