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

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

Issue 9373043: Move helpers and interceptors to own library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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 | dart/frog/leg/lib/core.dart » ('j') | no next file with comments »
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 bool allowSpeculativeOptimization = true; 10 bool allowSpeculativeOptimization = true;
(...skipping 29 matching lines...) Expand all
40 Queue<WorkItem> worklist; 40 Queue<WorkItem> worklist;
41 Universe universe; 41 Universe universe;
42 String assembledCode; 42 String assembledCode;
43 Namer namer; 43 Namer namer;
44 Types types; 44 Types types;
45 final String currentDirectory; 45 final String currentDirectory;
46 46
47 CompilerTask measuredTask; 47 CompilerTask measuredTask;
48 Element _currentElement; 48 Element _currentElement;
49 LibraryElement coreLibrary; 49 LibraryElement coreLibrary;
50 LibraryElement coreImplLibrary;
51 LibraryElement jsHelperLibrary;
50 LibraryElement mainApp; 52 LibraryElement mainApp;
51 53
52 Element get currentElement() => _currentElement; 54 Element get currentElement() => _currentElement;
53 withCurrentElement(Element element, f()) { 55 withCurrentElement(Element element, f()) {
54 Element old = currentElement; 56 Element old = currentElement;
55 _currentElement = element; 57 _currentElement = element;
56 try { 58 try {
57 return f(); 59 return f();
58 } finally { 60 } finally {
59 _currentElement = old; 61 _currentElement = old;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // writes directly into a file. 138 // writes directly into a file.
137 if (GENERATE_SSA_TRACE) { 139 if (GENERATE_SSA_TRACE) {
138 print("------------------"); 140 print("------------------");
139 print(new HTracer.singleton()); 141 print(new HTracer.singleton());
140 print("------------------"); 142 print("------------------");
141 } 143 }
142 log('compilation succeeded'); 144 log('compilation succeeded');
143 return true; 145 return true;
144 } 146 }
145 147
146 void scanCoreLibrary() { 148 LibraryElement scanBuiltinLibrary(String filename) {
147 String fileName = io.join([legDirectory, 'lib', 'core.dart']); 149 String fileName = io.join([legDirectory, 'lib', filename]);
148 Uri cwd = new Uri(scheme: 'file', path: currentDirectory); 150 Uri cwd = new Uri(scheme: 'file', path: currentDirectory);
149 Uri uri = cwd.resolve(fileName); 151 Uri uri = cwd.resolve(fileName);
150 Script script = readScript(uri); 152 LibraryElement library = scanner.loadLibrary(uri, null);
151 coreLibrary = new LibraryElement(script);
152 withCurrentElement(coreLibrary, () => scanner.scan(currentElement));
153 // Make our special function a foreign kind. 153 // Make our special function a foreign kind.
154 coreLibrary.define(new ForeignElement( 154 library.define(new ForeignElement(
155 const SourceString('JS'), coreLibrary), this); 155 const SourceString('JS'), library), this);
156 coreLibrary.define(new ForeignElement( 156 library.define(new ForeignElement(
157 const SourceString('UNINTERCEPTED'), coreLibrary), this); 157 const SourceString('UNINTERCEPTED'), library), this);
158 coreLibrary.define(new ForeignElement( 158 library.define(new ForeignElement(
159 const SourceString('JS_HAS_EQUALS'), coreLibrary), this); 159 const SourceString('JS_HAS_EQUALS'), library), this);
ngeoffray 2012/02/10 08:51:44 We're defining those guys in all (core, coreimpl,
ahe 2012/02/14 12:55:26 It's not immediately obvious how to do so. I'll tr
160 return library;
161 }
162
163 void scanBuiltinLibraries() {
164 coreLibrary = scanBuiltinLibrary('core.dart');
165 coreImplLibrary = scanBuiltinLibrary('coreimpl.dart');
166 jsHelperLibrary = scanBuiltinLibrary('js_helper.dart');
160 // TODO(ngeoffray): Lazily add this method. 167 // TODO(ngeoffray): Lazily add this method.
161 universe.invokedNames[NO_SUCH_METHOD] = 168 universe.invokedNames[NO_SUCH_METHOD] =
162 new Set<Invocation>.from(<Invocation>[new Invocation(2)]); 169 new Set<Invocation>.from(<Invocation>[new Invocation(2)]);
163 } 170 }
164 171
165 void enqueueInvokedInstanceMethods() { 172 void enqueueInvokedInstanceMethods() {
166 // TODO(floitsch): find a more efficient way of doing this. 173 // TODO(floitsch): find a more efficient way of doing this.
167 // Run through the classes and see if we need to compile methods. 174 // Run through the classes and see if we need to compile methods.
168 for (ClassElement classElement in universe.instantiatedClasses) { 175 for (ClassElement classElement in universe.instantiatedClasses) {
169 for (ClassElement currentClass = classElement; 176 for (ClassElement currentClass = classElement;
(...skipping 22 matching lines...) Expand all
192 if (universe.invokedSetters.contains(member.name)) { 199 if (universe.invokedSetters.contains(member.name)) {
193 addToWorklist(member); 200 addToWorklist(member);
194 } 201 }
195 } 202 }
196 } 203 }
197 } 204 }
198 } 205 }
199 } 206 }
200 207
201 void runCompiler(Script script) { 208 void runCompiler(Script script) {
202 scanCoreLibrary(); 209 scanBuiltinLibraries();
203 mainApp = new LibraryElement(script); 210 mainApp = new LibraryElement(script);
204 Element element; 211 Element element;
205 withCurrentElement(mainApp, () { 212 withCurrentElement(mainApp, () {
206 scanner.scan(currentElement); 213 scanner.scan(currentElement);
207 element = mainApp.find(MAIN); 214 element = mainApp.find(MAIN);
208 if (element === null) cancel('Could not find $MAIN'); 215 if (element === null) cancel('Could not find $MAIN');
209 }); 216 });
210 worklist.add(new WorkItem.toCompile(element)); 217 worklist.add(new WorkItem.toCompile(element));
211 do { 218 do {
212 while (!worklist.isEmpty()) { 219 while (!worklist.isEmpty()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 reportWarning(Node node, var message) {} 313 reportWarning(Node node, var message) {}
307 reportError(Node node, var message) {} 314 reportError(Node node, var message) {}
308 315
309 Script readScript(Uri uri) { 316 Script readScript(Uri uri) {
310 unimplemented('Compiler.readScript'); 317 unimplemented('Compiler.readScript');
311 } 318 }
312 319
313 String get legDirectory() { 320 String get legDirectory() {
314 unimplemented('Compiler.legDirectory'); 321 unimplemented('Compiler.legDirectory');
315 } 322 }
323
324 Element findHelper(SourceString name) => jsHelperLibrary.find(name);
316 } 325 }
317 326
318 class CompilerTask { 327 class CompilerTask {
319 final Compiler compiler; 328 final Compiler compiler;
320 final Stopwatch watch; 329 final Stopwatch watch;
321 330
322 CompilerTask(this.compiler) : watch = new Stopwatch(); 331 CompilerTask(this.compiler) : watch = new Stopwatch();
323 332
324 String get name() => 'Unknown task'; 333 String get name() => 'Unknown task';
325 int get timing() => watch.elapsedInMs(); 334 int get timing() => watch.elapsedInMs();
(...skipping 14 matching lines...) Expand all
340 349
341 class CompilerCancelledException implements Exception { 350 class CompilerCancelledException implements Exception {
342 final String reason; 351 final String reason;
343 CompilerCancelledException(this.reason); 352 CompilerCancelledException(this.reason);
344 353
345 String toString() { 354 String toString() {
346 String banner = 'compiler cancelled'; 355 String banner = 'compiler cancelled';
347 return (reason !== null) ? '$banner: $reason' : '$banner'; 356 return (reason !== null) ? '$banner: $reason' : '$banner';
348 } 357 }
349 } 358 }
OLDNEW
« no previous file with comments | « no previous file | dart/frog/leg/lib/core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698