| OLD | NEW |
| 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('../../lib/uri/uri.dart'); | 7 #import('../../lib/uri/uri.dart'); |
| 8 #import('../../utils/compiler/source_file.dart'); |
| 8 #import('../lang.dart', prefix: 'frog'); | 9 #import('../lang.dart', prefix: 'frog'); |
| 9 #import('api.dart', prefix: 'api'); | 10 #import('api.dart', prefix: 'api'); |
| 10 #import('io/io.dart', prefix: 'io'); | 11 #import('io/io.dart', prefix: 'io'); |
| 11 | 12 |
| 12 String relativize(Uri base, Uri uri) { | 13 String relativize(Uri base, Uri uri) { |
| 13 if (base.scheme == 'file' && | 14 if (base.scheme == 'file' && |
| 14 base.scheme == uri.scheme && | 15 base.scheme == uri.scheme && |
| 15 base.userInfo == uri.userInfo && | 16 base.userInfo == uri.userInfo && |
| 16 base.domain == uri.domain && | 17 base.domain == uri.domain && |
| 17 base.port == uri.port && | 18 base.port == uri.port && |
| (...skipping 25 matching lines...) Expand all Loading... |
| 43 final throwOnError = frog.options.throwOnErrors; | 44 final throwOnError = frog.options.throwOnErrors; |
| 44 final showWarnings = frog.options.showWarnings; | 45 final showWarnings = frog.options.showWarnings; |
| 45 final allowMockCompilation = frog.options.allowMockCompilation; | 46 final allowMockCompilation = frog.options.allowMockCompilation; |
| 46 // final compiler = new WorldCompiler(world, throwOnError); | 47 // final compiler = new WorldCompiler(world, throwOnError); |
| 47 Uri cwd = new Uri(scheme: 'file', path: io.getCurrentDirectory()); | 48 Uri cwd = new Uri(scheme: 'file', path: io.getCurrentDirectory()); |
| 48 Uri uri = cwd.resolve(frog.options.dartScript); | 49 Uri uri = cwd.resolve(frog.options.dartScript); |
| 49 String frogLibDir = frog.options.libDir; | 50 String frogLibDir = frog.options.libDir; |
| 50 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/"; | 51 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/"; |
| 51 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir); | 52 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir); |
| 52 Uri libraryRoot = frogLib.resolve('../leg/lib/'); | 53 Uri libraryRoot = frogLib.resolve('../leg/lib/'); |
| 53 Map<String, frog.SourceFile> sourceFiles = <frog.SourceFile>{}; | 54 Map<String, SourceFile> sourceFiles = <SourceFile>{}; |
| 54 | 55 |
| 55 Future<String> provider(Uri uri) { | 56 Future<String> provider(Uri uri) { |
| 56 if (uri.scheme != 'file') { | 57 if (uri.scheme != 'file') { |
| 57 throw new IllegalArgumentException(uri); | 58 throw new IllegalArgumentException(uri); |
| 58 } | 59 } |
| 59 String source = world.files.readAll(uri.path); | 60 String source = world.files.readAll(uri.path); |
| 60 world.dartBytesRead += source.length; | 61 world.dartBytesRead += source.length; |
| 61 sourceFiles[uri.toString()] = | 62 sourceFiles[uri.toString()] = |
| 62 new frog.SourceFile(relativize(cwd, uri), source); | 63 new SourceFile(relativize(cwd, uri), source); |
| 63 Completer<String> completer = new Completer<String>(); | 64 Completer<String> completer = new Completer<String>(); |
| 64 completer.complete(source); | 65 completer.complete(source); |
| 65 return completer.future; | 66 return completer.future; |
| 66 } | 67 } |
| 67 | 68 |
| 68 void handler(Uri uri, int begin, int end, String message, bool fatal) { | 69 void handler(Uri uri, int begin, int end, String message, bool fatal) { |
| 69 if (uri === null && !fatal) { | 70 if (uri === null && !fatal) { |
| 70 world.info('[leg] $message'); | 71 world.info('[leg] $message'); |
| 71 return; | 72 return; |
| 72 } | 73 } |
| 73 if (uri === null) { | 74 if (uri === null) { |
| 74 assert(fatal); | 75 assert(fatal); |
| 75 print(message); | 76 print(message); |
| 76 } else if (fatal || showWarnings) { | 77 } else if (fatal || showWarnings) { |
| 77 frog.SourceFile file = sourceFiles[uri.toString()]; | 78 SourceFile file = sourceFiles[uri.toString()]; |
| 78 print(file.getLocationMessage(message, begin, end, true)); | 79 print(file.getLocationMessage(message, begin, end, true)); |
| 79 } | 80 } |
| 80 if (fatal && throwOnError) throw new AbortLeg(message); | 81 if (fatal && throwOnError) throw new AbortLeg(message); |
| 81 } | 82 } |
| 82 | 83 |
| 83 List<String> options = new List<String>(); | 84 List<String> options = new List<String>(); |
| 84 if (allowMockCompilation) options.add('--allow-mock-compilation'); | 85 if (allowMockCompilation) options.add('--allow-mock-compilation'); |
| 85 | 86 |
| 86 // TODO(ahe): We expect the future to be complete and call value | 87 // TODO(ahe): We expect the future to be complete and call value |
| 87 // directly. In effect, we don't support truly asynchronous API. | 88 // directly. In effect, we don't support truly asynchronous API. |
| 88 String code = api.compile(uri, libraryRoot, provider, handler, options).value; | 89 String code = api.compile(uri, libraryRoot, provider, handler, options).value; |
| 89 if (code === null) return false; | 90 if (code === null) return false; |
| 90 world.legCode = code; | 91 world.legCode = code; |
| 91 world.jsBytesWritten = code.length; | 92 world.jsBytesWritten = code.length; |
| 92 return true; | 93 return true; |
| 93 } | 94 } |
| 94 | 95 |
| 95 class AbortLeg { | 96 class AbortLeg { |
| 96 final message; | 97 final message; |
| 97 AbortLeg(this.message); | 98 AbortLeg(this.message); |
| 98 toString() => 'Aborted due to --throw-on-error: $message'; | 99 toString() => 'Aborted due to --throw-on-error: $message'; |
| 99 } | 100 } |
| OLD | NEW |