OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// This is an interface to the Dart Kernel parser and Kernel binary generator. | 5 /// This is an interface to the Dart Kernel parser and Kernel binary generator. |
6 /// | 6 /// |
7 /// It is used by the kernel-isolate to load Dart source code and generate | 7 /// It is used by the kernel-isolate to load Dart source code and generate |
8 /// Kernel binary format. | 8 /// Kernel binary format. |
9 /// | 9 /// |
10 /// This is either invoked as the root script of the Kernel isolate when used | 10 /// This is either invoked as the root script of the Kernel isolate when used |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 | 45 |
46 import 'package:kernel/analyzer/loader.dart'; | 46 import 'package:kernel/analyzer/loader.dart'; |
47 import 'package:kernel/binary/ast_to_binary.dart'; | 47 import 'package:kernel/binary/ast_to_binary.dart'; |
48 import 'package:kernel/kernel.dart'; | 48 import 'package:kernel/kernel.dart'; |
49 import 'package:kernel/target/targets.dart'; | 49 import 'package:kernel/target/targets.dart'; |
50 | 50 |
51 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 51 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
52 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | 52 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
53 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 53 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
54 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 54 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
55 show KernelSourceTarget; | 55 show KernelTarget; |
56 import 'package:front_end/src/fasta/ast_kind.dart' show AstKind; | 56 import 'package:front_end/src/fasta/ast_kind.dart' show AstKind; |
57 import 'package:front_end/src/fasta/errors.dart' show InputError; | 57 import 'package:front_end/src/fasta/errors.dart' show InputError; |
58 | 58 |
59 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); | 59 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); |
60 const int workerPort = const int.fromEnvironment('DFE_WORKER_PORT') ?? 0; | 60 const int workerPort = const int.fromEnvironment('DFE_WORKER_PORT') ?? 0; |
61 const bool useFasta = const bool.fromEnvironment('DFE_USE_FASTA'); | 61 const bool useFasta = const bool.fromEnvironment('DFE_USE_FASTA'); |
62 | 62 |
63 class DataSink implements Sink<List<int>> { | 63 class DataSink implements Sink<List<int>> { |
64 final BytesBuilder builder = new BytesBuilder(); | 64 final BytesBuilder builder = new BytesBuilder(); |
65 | 65 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 } | 155 } |
156 | 156 |
157 Target target = getTarget("vm", new TargetFlags(strongMode: false)); | 157 Target target = getTarget("vm", new TargetFlags(strongMode: false)); |
158 | 158 |
159 Program program; | 159 Program program; |
160 if (useFasta) { | 160 if (useFasta) { |
161 final uriTranslator = await TranslateUri.parse(new Uri.file(packageConfig)); | 161 final uriTranslator = await TranslateUri.parse(new Uri.file(packageConfig)); |
162 final Ticker ticker = new Ticker(isVerbose: verbose); | 162 final Ticker ticker = new Ticker(isVerbose: verbose); |
163 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator); | 163 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator); |
164 dillTarget.read(new Uri.directory(sdkPath).resolve('platform.dill')); | 164 dillTarget.read(new Uri.directory(sdkPath).resolve('platform.dill')); |
165 final KernelSourceTarget sourceTarget = | 165 final KernelTarget kernelTarget = |
166 new KernelSourceTarget(dillTarget, uriTranslator); | 166 new KernelTarget(dillTarget, uriTranslator); |
167 try { | 167 try { |
168 sourceTarget.read(fileName); | 168 kernelTarget.read(fileName); |
169 await dillTarget.writeOutline(null); | 169 await dillTarget.writeOutline(null); |
170 program = await sourceTarget.writeOutline(null); | 170 program = await kernelTarget.writeOutline(null); |
171 program = await sourceTarget.writeProgram(null, AstKind.Kernel); | 171 program = await kernelTarget.writeProgram(null, AstKind.Kernel); |
172 if (sourceTarget.errors.isNotEmpty) { | 172 if (kernelTarget.errors.isNotEmpty) { |
173 return new CompilationError(sourceTarget.errors | 173 return new CompilationError(kernelTarget.errors |
174 .map((err) => err.toString()) | 174 .map((err) => err.toString()) |
175 .toList(growable: false)); | 175 .toList(growable: false)); |
176 } | 176 } |
177 } on InputError catch (e) { | 177 } on InputError catch (e) { |
178 return new CompilationError(<String>[e.error]); | 178 return new CompilationError(<String>[e.error]); |
179 } | 179 } |
180 } else { | 180 } else { |
181 DartOptions dartOptions = new DartOptions( | 181 DartOptions dartOptions = new DartOptions( |
182 strongMode: false, | 182 strongMode: false, |
183 strongModeSdk: false, | 183 strongModeSdk: false, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 loader, scriptUri, packagesUri.path, patchedSdk.path); | 340 loader, scriptUri, packagesUri.path, patchedSdk.path); |
341 | 341 |
342 if (result is CompilationOk) { | 342 if (result is CompilationOk) { |
343 request.response.statusCode = HttpStatus.OK; | 343 request.response.statusCode = HttpStatus.OK; |
344 request.response.headers.contentType = ContentType.BINARY; | 344 request.response.headers.contentType = ContentType.BINARY; |
345 request.response.add(result.binary); | 345 request.response.add(result.binary); |
346 request.response.close(); | 346 request.response.close(); |
347 } else { | 347 } else { |
348 request.response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; | 348 request.response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; |
349 request.response.headers.contentType = ContentType.TEXT; | 349 request.response.headers.contentType = ContentType.TEXT; |
350 request.response.write(JSON.encode(result.toJson())); | 350 request.response.write(JSON.encode(result)); |
ahe
2017/02/08 16:55:29
JSON.encode calls toJson implicitly, and it isn't
Vyacheslav Egorov (Google)
2017/02/09 09:26:38
Sweet. I did not know that. Thanks for fixing.
| |
351 request.response.close(); | 351 request.response.close(); |
352 } | 352 } |
353 }); | 353 }); |
354 ProcessSignal.SIGTERM.watch().first.then((_) => server.close()); | 354 ProcessSignal.SIGTERM.watch().first.then((_) => server.close()); |
355 }); | 355 }); |
356 } | 356 } |
357 | 357 |
358 train(String scriptUri) { | 358 train(String scriptUri) { |
359 // TODO(28532): Enable on Windows. | 359 // TODO(28532): Enable on Windows. |
360 if (Platform.isWindows) return; | 360 if (Platform.isWindows) return; |
(...skipping 23 matching lines...) Expand all Loading... | |
384 // provides a script to compile to warm-up generated code. | 384 // provides a script to compile to warm-up generated code. |
385 train(args[1]); | 385 train(args[1]); |
386 } else { | 386 } else { |
387 // Entry point for the Kernel isolate. | 387 // Entry point for the Kernel isolate. |
388 return new RawReceivePort()..handler = _processLoadRequest; | 388 return new RawReceivePort()..handler = _processLoadRequest; |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 // This duplicates functionality from the Loader which we can't easily | 392 // This duplicates functionality from the Loader which we can't easily |
393 // access from here. | 393 // access from here. |
394 Uri _findPackagesFile(Uri base) async { | 394 Future<Uri> _findPackagesFile(Uri base) async { |
395 var dir = new File.fromUri(base).parent; | 395 var dir = new File.fromUri(base).parent; |
396 while (true) { | 396 while (true) { |
397 final packagesFile = dir.uri.resolve(".packages"); | 397 final packagesFile = dir.uri.resolve(".packages"); |
398 if (await new File.fromUri(packagesFile).exists()) { | 398 if (await new File.fromUri(packagesFile).exists()) { |
399 return packagesFile; | 399 return packagesFile; |
400 } | 400 } |
401 if (dir.parent.path == dir.path) { | 401 if (dir.parent.path == dir.path) { |
402 break; | 402 break; |
403 } | 403 } |
404 dir = dir.parent; | 404 dir = dir.parent; |
405 } | 405 } |
406 return null; | 406 return null; |
407 } | 407 } |
OLD | NEW |