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

Side by Side Diff: frog/frog_leg.dart

Issue 10081004: Remove frog dependencies from lib/compiler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add TODO. Created 8 years, 8 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 | « frog/frog.dart ('k') | frog/frogc.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 #library('frog_leg'); 5 #library('frog_leg');
6 6
7 #import('dart:io'); 7 #import('dart:io');
8 #import('dart:uri');
8 9
9 #import('../../uri/uri.dart'); 10 #import('lang.dart', prefix: 'frog');
10 #import('source_file.dart'); 11 #import('../lib/compiler/compiler.dart', prefix: 'compiler');
11 #import('../../../frog/lang.dart', prefix: 'frog');
12 #import('../compiler.dart', prefix: 'compiler');
13 12
14 String relativize(Uri base, Uri uri) { 13 String relativize(Uri base, Uri uri) {
15 if (base.scheme == 'file' && 14 if (base.scheme == 'file' &&
16 base.scheme == uri.scheme && 15 base.scheme == uri.scheme &&
17 base.userInfo == uri.userInfo && 16 base.userInfo == uri.userInfo &&
18 base.domain == uri.domain && 17 base.domain == uri.domain &&
19 base.port == uri.port && 18 base.port == uri.port &&
20 uri.query == "" && uri.fragment == "") { 19 uri.query == "" && uri.fragment == "") {
21 if (uri.path.startsWith(base.path)) { 20 if (uri.path.startsWith(base.path)) {
22 return uri.path.substring(base.path.length); 21 return uri.path.substring(base.path.length);
(...skipping 21 matching lines...) Expand all
44 bool compile(frog.World world) { 43 bool compile(frog.World world) {
45 final throwOnError = frog.options.throwOnErrors; 44 final throwOnError = frog.options.throwOnErrors;
46 final showWarnings = frog.options.showWarnings; 45 final showWarnings = frog.options.showWarnings;
47 final allowMockCompilation = frog.options.allowMockCompilation; 46 final allowMockCompilation = frog.options.allowMockCompilation;
48 Uri cwd = new Uri(scheme: 'file', path: getCurrentDirectory()); 47 Uri cwd = new Uri(scheme: 'file', path: getCurrentDirectory());
49 Uri uri = cwd.resolve(frog.options.dartScript); 48 Uri uri = cwd.resolve(frog.options.dartScript);
50 String frogLibDir = frog.options.libDir; 49 String frogLibDir = frog.options.libDir;
51 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/"; 50 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/";
52 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir); 51 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir);
53 Uri libraryRoot = frogLib.resolve('../../'); 52 Uri libraryRoot = frogLib.resolve('../../');
54 Map<String, SourceFile> sourceFiles = <SourceFile>{}; 53 Map<String, frog.SourceFile> sourceFiles = <frog.SourceFile>{};
55 54
56 Future<String> provider(Uri uri) { 55 Future<String> provider(Uri uri) {
57 if (uri.scheme != 'file') { 56 if (uri.scheme != 'file') {
58 throw new IllegalArgumentException(uri); 57 throw new IllegalArgumentException(uri);
59 } 58 }
60 String source = world.files.readAll(uri.path); 59 String source = world.files.readAll(uri.path);
61 world.dartBytesRead += source.length; 60 world.dartBytesRead += source.length;
62 sourceFiles[uri.toString()] = 61 sourceFiles[uri.toString()] =
63 new SourceFile(relativize(cwd, uri), source); 62 new frog.SourceFile(relativize(cwd, uri), source);
64 Completer<String> completer = new Completer<String>(); 63 Completer<String> completer = new Completer<String>();
65 completer.complete(source); 64 completer.complete(source);
66 return completer.future; 65 return completer.future;
67 } 66 }
68 67
69 void handler(Uri uri, int begin, int end, String message, bool fatal) { 68 void handler(Uri uri, int begin, int end, String message, bool fatal) {
70 if (uri === null && !fatal) { 69 if (uri === null && !fatal) {
71 world.info('[leg] $message'); 70 world.info('[leg] $message');
72 return; 71 return;
73 } 72 }
74 if (uri === null) { 73 if (uri === null) {
75 assert(fatal); 74 assert(fatal);
76 print(message); 75 print(message);
77 } else if (fatal || showWarnings) { 76 } else if (fatal || showWarnings) {
78 SourceFile file = sourceFiles[uri.toString()]; 77 frog.SourceFile file = sourceFiles[uri.toString()];
79 print(file.getLocationMessage(message, begin, end, true)); 78 print(file.getLocationMessage(message, begin, end, true));
80 } 79 }
81 if (fatal && throwOnError) throw new AbortLeg(message); 80 if (fatal && throwOnError) throw new AbortLeg(message);
82 } 81 }
83 82
84 List<String> options = new List<String>(); 83 List<String> options = new List<String>();
85 if (allowMockCompilation) options.add('--allow-mock-compilation'); 84 if (allowMockCompilation) options.add('--allow-mock-compilation');
86 85
87 // TODO(ahe): We expect the future to be complete and call value 86 // TODO(ahe): We expect the future to be complete and call value
88 // directly. In effect, we don't support truly asynchronous API. 87 // directly. In effect, we don't support truly asynchronous API.
89 String code = 88 String code =
90 compiler.compile(uri, libraryRoot, provider, handler, options).value; 89 compiler.compile(uri, libraryRoot, provider, handler, options).value;
91 if (code === null) return false; 90 if (code === null) return false;
92 world.legCode = code; 91 world.legCode = code;
93 world.jsBytesWritten = code.length; 92 world.jsBytesWritten = code.length;
94 return true; 93 return true;
95 } 94 }
96 95
97 class AbortLeg { 96 class AbortLeg {
98 final message; 97 final message;
99 AbortLeg(this.message); 98 AbortLeg(this.message);
100 toString() => 'Aborted due to --throw-on-error: $message'; 99 toString() => 'Aborted due to --throw-on-error: $message';
101 } 100 }
102 101
103 String getCurrentDirectory() { 102 String getCurrentDirectory() {
104 String dir = new File(".").fullPathSync(); 103 String dir = new File(".").fullPathSync();
105 if (dir.endsWith("/")) return dir; 104 if (dir.endsWith("/")) return dir;
106 return "$dir/"; 105 return "$dir/";
107 } 106 }
OLDNEW
« no previous file with comments | « frog/frog.dart ('k') | frog/frogc.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698