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

Unified Diff: dart/frog/leg/frog_leg.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: Addressed review comments and created separate implementation library 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 | « dart/frog/leg/compiler.dart ('k') | dart/tests/language/language-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/frog_leg.dart
diff --git a/dart/frog/leg/frog_leg.dart b/dart/frog/leg/frog_leg.dart
index c07aed4f5c625f569e7093ce1247f42db5b42173..b5a91274436d22ca63d6b403017e85270132783e 100644
--- a/dart/frog/leg/frog_leg.dart
+++ b/dart/frog/leg/frog_leg.dart
@@ -6,158 +6,46 @@
#import('../../lib/uri/uri.dart');
#import('../lang.dart', prefix: 'frog');
-#import('elements/elements.dart');
+#import('api.dart', prefix: 'api');
#import('io/io.dart', prefix: 'io');
-#import('leg.dart');
-#import('tree/tree.dart');
-#import('ssa/tracer.dart');
bool compile(frog.World world) {
final throwOnError = frog.options.throwOnErrors;
- final compiler = new WorldCompiler(world, throwOnError);
- Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory);
+ // final compiler = new WorldCompiler(world, throwOnError);
+ Uri cwd = new Uri(scheme: 'file', path: io.getCurrentDirectory());
Uri uri = cwd.resolve(frog.options.dartScript);
- return compiler.run(uri);
-}
-
-class WorldCompiler extends Compiler {
- final frog.World world;
- final bool throwOnError;
-
- WorldCompiler(this.world, this.throwOnError)
- : super.withCurrentDirectory(io.getCurrentDirectory(),
- tracer: new HTracer());
-
- void log(message) {
- if (frog.options.showInfo) {
- // Avoid calling message.toString() unless showInfo is on. It
- // could be slow.
- world.info('[leg] $message');
- }
- }
+ String frogLibDir = frog.options.libDir;
+ if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/";
+ Uri frogLib = new Uri(scheme: 'file', path: frogLibDir);
+ Uri libraryRoot = frogLib.resolve('../leg/lib/');
- bool run(Uri uri) {
- bool success = super.run(uri);
- if (success) {
- var code = assembledCode;
- world.legCode = code;
- world.jsBytesWritten = code.length;
- for (final task in tasks) {
- log('${task.name} took ${task.timing}msec');
- }
+ Future<String> provider(Uri uri) {
+ if (uri.scheme != 'file') {
+ throw new IllegalArgumentException(uri);
}
- return success;
+ String source = world.files.readAll(uri.path);
+ world.dartBytesRead += source.length;
+ Completer<String> completer = new Completer<String>();
+ completer.complete(source);
+ return completer.future;
}
- spanFromNode(Node node, Script current) {
- final begin = node.getBeginToken();
- final end = node.getEndToken();
- if (begin === null || end === null) {
- cancel('cannot find tokens to produce error message for $node.');
- }
- final startOffset = begin.charOffset;
- // TODO(ahe): Compute proper end offset.
- final endOffset = end.charOffset + 1;
- return new frog.SourceSpan(current.file, startOffset, endOffset);
- }
-
- currentScript() {
- if (currentElement === null) return null;
- CompilationUnitElement compilationUnit =
- currentElement.getCompilationUnit();
- if (compilationUnit === null) return null;
- return compilationUnit.script;
- }
-
- reportWarning(Node node, var message) {
- frog.SourceSpan span;
- Script current = currentScript();
- if (current === null) {
- world.fatal('No current script');
- } else if (node === null) {
- span = new frog.SourceSpan(current.file, 0, 0);
- } else {
- span = spanFromNode(node, current);
- }
- world.warning('$message.', span);
- }
-
- reportError(Node node, var message) {
- cancel(message.toString(), node);
- }
-
- Uri getUriFor(String fileName) {
- Uri cwd = new Uri(scheme: 'file', path: currentDirectory);
- return cwd.resolve(fileName);
- }
-
- Script readScript(Uri uri, [ScriptTag node]) {
- String uriName = uri.toString();
- // TODO(ahe): Clean this up.
- if (uriName == 'dart:dom') {
- uri = getUriFor(io.join([legDirectory, '..', '..',
- 'client', 'dom', 'frog', 'dom_frog.dart']));
- } else if (uriName == 'dart:html') {
- uri = getUriFor(io.join([legDirectory, '..', '..',
- 'client', 'html', 'frog', 'html_frog.dart']));
- } else if (uriName == 'dart:json') {
- uri = getUriFor(io.join([legDirectory, '..', '..',
- 'lib', 'json', 'json.dart']));
- }
- if (uri.scheme != 'file') cancel('cannot read $uri', node: node);
- String text = "";
- try {
- text = frog.world.files.readAll(uri.path);
- } catch (var exception) {
- cancel("${uri.path}: $exception", node: node);
- }
- world.dartBytesRead += text.length;
- frog.SourceFile sourceFile = new frog.SourceFile(uri.toString(), text);
- return new Script(uri, sourceFile);
- }
-
- String get legDirectory() => io.join([frog.options.libDir, '..', 'leg']);
-
- void cancel([String reason, Node node, token, instruction, element]) {
- Script script = currentScript();
- if (node !== null) {
- print(spanFromNode(node, script).toMessageString("cancel leg: $reason"));
- } else if (token !== null) {
- int begin = token.charOffset;
- int end = begin + 1; // TODO(ahe): Compute proper length.
- print(script.file.getLocationMessage("cancel leg: $reason",
- begin, end, true));
- } else if (element !== null) {
- if (element.position() === null) {
- // Sometimes, the backend fakes up elements that have no
- // position. So we use the enclosing element instead. It is
- // not a good error location, but cancel really is "internal
- // error" or "not implemented yet", so the vicinity is good
- // enough for now.
- element = element.enclosingElement;
- // TODO(ahe): I plan to overhaul this infrastructure anyways.
- }
- if (element !== null) {
- withCurrentElement(element,
- () => cancel(reason: reason, token: element.position()));
- }
- } else if (currentElement !== null) {
- cancel(reason, element: currentElement);
+ void handler(Uri uri, int begin, int end, String message, bool fatal) {
+ if (uri === null && !fatal) {
+ world.info('[leg] $message');
return;
}
- if (throwOnError) {
- throw new AbortLeg(reason);
- }
- super.cancel(reason, node, token, instruction);
+ print(message);
+ if (fatal && throwOnError) new AbortLeg(message);
}
- LibraryElement scanBuiltinLibrary(String filename) {
- String fileName = io.join([legDirectory, 'lib', filename]);
- Uri cwd = new Uri(scheme: 'file', path: currentDirectory);
- Uri uri = cwd.resolve(fileName);
- LibraryElement library = scanner.loadLibrary(uri, null);
- return library;
- }
+ // TODO(ahe): We expect the future to be complete and call value
+ // directly. In effect, we don't support truly asynchronous API.
+ String code = api.compile(uri, libraryRoot, provider, handler).value;
+ if (code === null) return false;
+ world.legCode = code;
+ world.jsBytesWritten = code.length;
+ return true;
}
class AbortLeg {
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698