| 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 /** The one true [World]. */ | 5 /** The one true [World]. */ |
| 6 World world; | 6 World world; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Experimental phase to enable await, only set when using the | 9 * Experimental phase to enable await, only set when using the |
| 10 * await/awaitc.dart entrypoint. | 10 * await/awaitc.dart entrypoint. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 return 'CompilerException: $_message'; | 55 return 'CompilerException: $_message'; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** Counters that track statistics about the generated code. */ | 60 /** Counters that track statistics about the generated code. */ |
| 61 class CounterLog { | 61 class CounterLog { |
| 62 int dynamicMethodCalls = 0; | 62 int dynamicMethodCalls = 0; |
| 63 int typeAsserts = 0; | 63 int typeAsserts = 0; |
| 64 int objectProtoMembers = 0; | 64 int objectProtoMembers = 0; |
| 65 int invokeCalls = 0; | |
| 66 int msetN = 0; | |
| 67 | 65 |
| 68 info() { | 66 info() { |
| 69 world.info('Dynamically typed method calls: $dynamicMethodCalls'); | 67 world.info('Dynamically typed method calls: $dynamicMethodCalls'); |
| 70 world.info('Generated type assertions: $typeAsserts'); | 68 world.info('Generated type assertions: $typeAsserts'); |
| 71 world.info('Members on Object.prototype: $objectProtoMembers'); | 69 world.info('Members on Object.prototype: $objectProtoMembers'); |
| 72 world.info('Invoke calls: $invokeCalls'); | |
| 73 world.info('msetN calls: $msetN'); | |
| 74 } | 70 } |
| 75 | 71 |
| 76 // We need to push a new counter when we are abstract interpreting, so we | 72 // We need to push a new counter when we are abstract interpreting, so we |
| 77 // can discard it if we discard the code. | 73 // can discard it if we discard the code. |
| 78 // TODO(jmesserly): this is ugly but I'm not sure how to make it cleaner, | 74 // TODO(jmesserly): this is ugly but I'm not sure how to make it cleaner, |
| 79 // other than splitting abstract interpretation and code generation (which | 75 // other than splitting abstract interpretation and code generation (which |
| 80 // has its own problems). | 76 // has its own problems). |
| 81 add(CounterLog other) { | 77 add(CounterLog other) { |
| 82 dynamicMethodCalls += other.dynamicMethodCalls; | 78 dynamicMethodCalls += other.dynamicMethodCalls; |
| 83 typeAsserts += other.typeAsserts; | 79 typeAsserts += other.typeAsserts; |
| 84 objectProtoMembers += other.objectProtoMembers; | 80 objectProtoMembers += other.objectProtoMembers; |
| 85 invokeCalls += other.invokeCalls; | |
| 86 msetN += other.msetN; | |
| 87 } | 81 } |
| 88 } | 82 } |
| 89 | 83 |
| 90 | |
| 91 /** Represents a Dart "world" of code. */ | 84 /** Represents a Dart "world" of code. */ |
| 92 class World { | 85 class World { |
| 93 WorldGenerator gen; | 86 WorldGenerator gen; |
| 94 String legCode; // TODO(kasperl): Remove this temporary kludge. | 87 String legCode; // TODO(kasperl): Remove this temporary kludge. |
| 95 String frogCode; | 88 String frogCode; |
| 96 | 89 |
| 97 FileSystem files; | 90 FileSystem files; |
| 98 final LibraryReader reader; | 91 final LibraryReader reader; |
| 99 | 92 |
| 100 Map<String, Library> libraries; | 93 Map<String, Library> libraries; |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 resolveAll() { | 457 resolveAll() { |
| 465 for (var lib in libraries.getValues()) { | 458 for (var lib in libraries.getValues()) { |
| 466 lib.resolve(); | 459 lib.resolve(); |
| 467 } | 460 } |
| 468 for (var lib in libraries.getValues()) { | 461 for (var lib in libraries.getValues()) { |
| 469 lib.postResolveChecks(); | 462 lib.postResolveChecks(); |
| 470 } | 463 } |
| 471 } | 464 } |
| 472 | 465 |
| 473 findMainMethod(Library lib) { | 466 findMainMethod(Library lib) { |
| 474 var main = lib.lookup('main', lib.span); | 467 var mainMembers = lib.topType.resolveMember('main'); |
| 475 if (main == null) { | 468 var main = null; |
| 469 if (mainMembers == null || mainMembers.members.length == 0) { |
| 476 fatal('no main method specified'); | 470 fatal('no main method specified'); |
| 471 } else if (mainMembers.members.length > 1) { |
| 472 for (var m in mainMembers.members) { |
| 473 main = m; |
| 474 error('more than one main member (using last?)', main.span); |
| 475 } |
| 476 } else { |
| 477 main = mainMembers.members[0]; |
| 477 } | 478 } |
| 478 return main; | 479 return main; |
| 479 } | 480 } |
| 480 | 481 |
| 481 generateCode(Library lib) { | 482 generateCode(Library lib) { |
| 482 gen = new WorldGenerator(findMainMethod(lib), new CodeWriter()); | 483 gen = new WorldGenerator(findMainMethod(lib), new CodeWriter()); |
| 483 gen.run(); | 484 gen.run(); |
| 484 frogCode = gen.writer.text; | 485 frogCode = gen.writer.text; |
| 485 jsBytesWritten = frogCode.length; | 486 jsBytesWritten = frogCode.length; |
| 486 gen = null; | 487 gen = null; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 601 |
| 601 withTiming(String name, f()) { | 602 withTiming(String name, f()) { |
| 602 final sw = new Stopwatch(); | 603 final sw = new Stopwatch(); |
| 603 sw.start(); | 604 sw.start(); |
| 604 var result = f(); | 605 var result = f(); |
| 605 sw.stop(); | 606 sw.stop(); |
| 606 info('$name in ${sw.elapsedInMs()}msec'); | 607 info('$name in ${sw.elapsedInMs()}msec'); |
| 607 return result; | 608 return result; |
| 608 } | 609 } |
| 609 } | 610 } |
| OLD | NEW |