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

Unified Diff: dart/frog/leg/api.dart

Issue 9639012: Implement the compiler API and use it in frog_leg.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/frog/leg/compiler.dart » ('j') | dart/frog/leg/frog_leg.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/api.dart
diff --git a/dart/frog/leg/api.dart b/dart/frog/leg/api.dart
index 306093135c7bb2c1bb1c055558b5eeecca11e3a2..a03d51ed5b5cc6de9fd5e46446cc3967db8bb998 100644
--- a/dart/frog/leg/api.dart
+++ b/dart/frog/leg/api.dart
@@ -3,7 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
#library('leg_api');
-#import('dart:uri');
+#import('../../lib/uri/uri.dart');
+#import('leg.dart', prefix: 'leg');
+#import('ssa/tracer.dart');
kasperl 2012/03/08 15:13:02 Should we give this a prefix too?
ahe 2012/03/08 16:29:42 Done.
+#import('../lang.dart', prefix: 'frog');
// Unless explicitly allowed, passing null for any argument to the
// methods of library will result in a NullPointerException being
@@ -35,5 +38,59 @@ typedef void DiagnosticHandler(Uri uri, int begin, int end,
* with [:fatal == true:].
*/
Future<String> compile(Uri script, Uri libraryRoot,
- ReadUriFromString provider, DiagnosticHandler handler);
-// TODO(ahe): Document libraryRoot argument.
+ ReadUriFromString provider, DiagnosticHandler handler) {
kasperl 2012/03/08 15:13:02 In these cases I prefer one argument per line.
ahe 2012/03/08 16:29:42 I don't agree, but done.
+ Compiler compiler = new Compiler(provider, handler, libraryRoot);
+ compiler.run(script);
+ String code = compiler.assembledCode;
+ Completer<String> completer = new Completer<String>();
+ completer.complete(code);
+ return completer.future;
+}
+
+// Implementation:
+class Compiler extends leg.Compiler {
+ ReadUriFromString provider;
+ DiagnosticHandler handler;
+ Uri libraryRoot;
+
+ Compiler(this.provider, this.handler, this.libraryRoot)
+ : super.withCurrentDirectory(null, tracer: new HTracer());
+
+ LibraryElement scanBuiltinLibrary(String filename) {
+ Uri uri = libraryRoot.resolve(filename);
+ LibraryElement library = scanner.loadLibrary(uri, null);
+ return library;
+ }
+
+ void log(message) {
+ handler(null, null, null, message, false);
+ }
+
+ Script readScript(Uri uri, [ScriptTag node]) {
+ String uriName = uri.toString();
+ // TODO(ahe): Clean this up.
+ if (uriName == 'dart:dom') {
+ uri = libraryRoot.resolve('../../../client/dom/frog/dom_frog.dart');
+ } else if (uriName == 'dart:html') {
+ uri = libraryRoot.resolve('../../../client/html/frog/html_frog.dart');
+ } else if (uriName == 'dart:json') {
+ uri = libraryRoot.resolve('../../../lib/json/json.dart');
+ }
+ String text = "";
+ try {
+ text = provider(uri).value;
kasperl 2012/03/08 15:13:02 Maybe add a comment here that explain why this is
ahe 2012/03/08 16:29:42 Done.
+ } catch (var exception) {
+ cancel("${uri.path}: $exception", node: node);
+ }
+ frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text);
+ return new leg.Script(uri, sourceFile);
+ }
+
+ bool run(Uri uri) {
+ bool success = super.run(uri);
+ for (final task in tasks) {
+ log('${task.name} took ${task.timing}msec');
+ }
+ return success;
+ }
+}
« no previous file with comments | « no previous file | dart/frog/leg/compiler.dart » ('j') | dart/frog/leg/frog_leg.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698