Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: frog/leg/compiler.dart

Issue 9193016: Add the arity to calls, and support noSuchMethodException. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | frog/leg/emitter.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 Map<int, BailoutInfo> bailouts = null; 9 Map<int, BailoutInfo> bailouts = null;
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 TreeValidatorTask validator; 52 TreeValidatorTask validator;
53 ResolverTask resolver; 53 ResolverTask resolver;
54 TypeCheckerTask checker; 54 TypeCheckerTask checker;
55 SsaBuilderTask builder; 55 SsaBuilderTask builder;
56 SsaOptimizerTask optimizer; 56 SsaOptimizerTask optimizer;
57 SsaCodeGeneratorTask generator; 57 SsaCodeGeneratorTask generator;
58 CodeEmitterTask emitter; 58 CodeEmitterTask emitter;
59 CompileTimeConstantHandler compileTimeConstantHandler; 59 CompileTimeConstantHandler compileTimeConstantHandler;
60 60
61 static final SourceString MAIN = const SourceString('main'); 61 static final SourceString MAIN = const SourceString('main');
62 static final SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod');
62 63
63 Compiler() 64 Compiler()
64 : types = new Types(), 65 : types = new Types(),
65 universe = new Universe(), 66 universe = new Universe(),
66 worklist = new Queue<WorkItem>() { 67 worklist = new Queue<WorkItem>() {
67 namer = new Namer(this); 68 namer = new Namer(this);
68 compileTimeConstantHandler = new CompileTimeConstantHandler(this); 69 compileTimeConstantHandler = new CompileTimeConstantHandler(this);
69 scanner = new ScannerTask(this); 70 scanner = new ScannerTask(this);
70 parser = new ParserTask(this); 71 parser = new ParserTask(this);
71 validator = new TreeValidatorTask(this); 72 validator = new TreeValidatorTask(this);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 127 }
127 128
128 void scanCoreLibrary() { 129 void scanCoreLibrary() {
129 String fileName = io.join([legDirectory, 'lib', 'core.dart']); 130 String fileName = io.join([legDirectory, 'lib', 'core.dart']);
130 currentElement = new CompilationUnitElement( 131 currentElement = new CompilationUnitElement(
131 readScript(fileName), currentLibrary); 132 readScript(fileName), currentLibrary);
132 scanner.scan(currentElement); 133 scanner.scan(currentElement);
133 // Make our special function a foreign kind. 134 // Make our special function a foreign kind.
134 universe.define(new ForeignElement(const SourceString('JS'))); 135 universe.define(new ForeignElement(const SourceString('JS')));
135 universe.define(new ForeignElement(const SourceString('UNINTERCEPTED'))); 136 universe.define(new ForeignElement(const SourceString('UNINTERCEPTED')));
137 // TODO(ngeoffray): Lazily add this method.
138 universe.invokedNames[NO_SUCH_METHOD] = new Set<int>.from(<int>[2]);
136 } 139 }
137 140
138 void enqueueInvokedInstanceMethods() { 141 void enqueueInvokedInstanceMethods() {
139 // TODO(floitsch): find a more efficient way of doing this. 142 // TODO(floitsch): find a more efficient way of doing this.
140 // Run through the classes and see if we need to compile methods. 143 // Run through the classes and see if we need to compile methods.
141 for (ClassElement classElement in universe.instantiatedClasses) { 144 for (ClassElement classElement in universe.instantiatedClasses) {
142 for (ClassElement currentClass = classElement; 145 for (ClassElement currentClass = classElement;
143 currentClass !== null; 146 currentClass !== null;
144 currentClass = currentClass.superClass) { 147 currentClass = currentClass.superClass) {
145 // TODO(floitsch): we don't need to add members that have been 148 // TODO(floitsch): we don't need to add members that have been
146 // overwritten by subclasses. 149 // overwritten by subclasses.
147 for (Element member in currentClass.members) { 150 for (Element member in currentClass.members) {
148 SourceString name = member.name; 151 SourceString name = member.name;
149 if (Elements.isInstanceMethod(member) && 152 if (Elements.isInstanceMethod(member) &&
150 universe.generatedCode[member] === null && 153 universe.generatedCode[member] === null) {
151 universe.invokedNames.contains(name.stringValue)) { 154 FunctionElement element = member;
152 addToWorklist(member); 155 Set<int> invocations = universe.invokedNames[name];
156 if (invocations != null
157 && invocations.contains(element.parameterCount(this))) {
158 addToWorklist(member);
159 }
153 } 160 }
154 } 161 }
155 } 162 }
156 } 163 }
157 } 164 }
158 165
159 void runCompiler(Script script) { 166 void runCompiler(Script script) {
160 scanCoreLibrary(); 167 scanCoreLibrary();
161 currentElement = new CompilationUnitElement(script, currentLibrary); 168 currentElement = new CompilationUnitElement(script, currentLibrary);
162 scanner.scan(currentElement); 169 scanner.scan(currentElement);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { 219 if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
213 registerInstantiatedClass(element.enclosingElement); 220 registerInstantiatedClass(element.enclosingElement);
214 } 221 }
215 worklist.add(new WorkItem.toCompile(element)); 222 worklist.add(new WorkItem.toCompile(element));
216 } 223 }
217 224
218 void registerStaticUse(Element element) { 225 void registerStaticUse(Element element) {
219 addToWorklist(element); 226 addToWorklist(element);
220 } 227 }
221 228
222 void registerDynamicInvocation(SourceString methodName) { 229 void registerDynamicInvocation(SourceString methodName, int arity) {
223 universe.invokedNames.add(methodName.stringValue); 230 Set<int> existing = universe.invokedNames[methodName];
231 if (existing == null) {
232 universe.invokedNames[methodName] = new Set.from(<int>[arity]);
233 } else {
234 existing.add(arity);
235 }
224 } 236 }
225 237
226 void registerDynamicGetter(SourceString methodName) { 238 void registerDynamicGetter(SourceString methodName) {
227 universe.invokedGetters.add(methodName.stringValue); 239 universe.invokedGetters.add(methodName);
228 } 240 }
229 241
230 void registerDynamicSetter(SourceString methodName) { 242 void registerDynamicSetter(SourceString methodName) {
231 universe.invokedSetters.add(methodName.stringValue); 243 universe.invokedSetters.add(methodName);
232 } 244 }
233 245
234 void registerInstantiatedClass(ClassElement element) { 246 void registerInstantiatedClass(ClassElement element) {
235 universe.instantiatedClasses.add(element); 247 universe.instantiatedClasses.add(element);
236 } 248 }
237 249
238 Element resolveType(ClassElement element) { 250 Element resolveType(ClassElement element) {
239 parser.parse(element); 251 parser.parse(element);
240 resolver.resolveType(element); 252 resolver.resolveType(element);
241 return element; 253 return element;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 296
285 class CompilerCancelledException implements Exception { 297 class CompilerCancelledException implements Exception {
286 final String reason; 298 final String reason;
287 CompilerCancelledException(this.reason); 299 CompilerCancelledException(this.reason);
288 300
289 String toString() { 301 String toString() {
290 String banner = 'compiler cancelled'; 302 String banner = 'compiler cancelled';
291 return (reason !== null) ? '$banner: $reason' : '$banner'; 303 return (reason !== null) ? '$banner: $reason' : '$banner';
292 } 304 }
293 } 305 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | frog/leg/emitter.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698