| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library fletchc_blaze; | 5 library dartino_compiler_blaze; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'dart:convert' show | 9 import 'dart:convert' show |
| 10 LineSplitter, | 10 LineSplitter, |
| 11 UTF8; | 11 UTF8; |
| 12 | 12 |
| 13 import 'dart:io'; | 13 import 'dart:io'; |
| 14 | 14 |
| 15 import 'package:fletchc/session.dart' show | 15 import 'package:dartino_compiler/session.dart' show |
| 16 Session; | 16 Session; |
| 17 | 17 |
| 18 import 'package:fletchc/src/hub/session_manager.dart'; | 18 import 'package:dartino_compiler/src/hub/session_manager.dart'; |
| 19 | 19 |
| 20 import 'package:fletchc/src/worker/developer.dart' show | 20 import 'package:dartino_compiler/src/worker/developer.dart' show |
| 21 Address, | 21 Address, |
| 22 Settings, | 22 Settings, |
| 23 SessionState; | 23 SessionState; |
| 24 | 24 |
| 25 import 'package:fletchc/src/worker/developer.dart' as developer; | 25 import 'package:dartino_compiler/src/worker/developer.dart' as developer; |
| 26 | 26 |
| 27 import 'package:fletchc/src/verbs/infrastructure.dart' show | 27 import 'package:dartino_compiler/src/verbs/infrastructure.dart' show |
| 28 fileUri; | 28 fileUri; |
| 29 | 29 |
| 30 import 'package:compiler/src/filenames.dart' show | 30 import 'package:compiler/src/filenames.dart' show |
| 31 appendSlash; | 31 appendSlash; |
| 32 | 32 |
| 33 class FletchRunner { | 33 class DartinoRunner { |
| 34 | 34 |
| 35 Future<int> run(List<String> arguments) async { | 35 Future<int> run(List<String> arguments) async { |
| 36 int debugPort; | 36 int debugPort; |
| 37 String packages; | 37 String packages; |
| 38 String snapshot; | 38 String snapshot; |
| 39 String script; | 39 String script; |
| 40 Uri libraryRoot; | 40 Uri libraryRoot; |
| 41 Uri fletchVm; | 41 Uri dartinoVm; |
| 42 Uri nativesJson; | 42 Uri nativesJson; |
| 43 | 43 |
| 44 for (int i = 0; i < arguments.length; ++i) { | 44 for (int i = 0; i < arguments.length; ++i) { |
| 45 String arg = arguments[i]; | 45 String arg = arguments[i]; |
| 46 if (arg == "--debug") { | 46 if (arg == "--debug") { |
| 47 if (debugPort != null) throw "Cannot supply multiple debug ports"; | 47 if (debugPort != null) throw "Cannot supply multiple debug ports"; |
| 48 debugPort = int.parse(arguments[++i]); | 48 debugPort = int.parse(arguments[++i]); |
| 49 } else if (arg == "--packages") { | 49 } else if (arg == "--packages") { |
| 50 if (packages != null) throw "Cannot supply multiple package files"; | 50 if (packages != null) throw "Cannot supply multiple package files"; |
| 51 packages = arguments[++i]; | 51 packages = arguments[++i]; |
| 52 } else if (arg == "--snapshot") { | 52 } else if (arg == "--snapshot") { |
| 53 if (snapshot != null) throw "Cannot export to multiple snapshot files"; | 53 if (snapshot != null) throw "Cannot export to multiple snapshot files"; |
| 54 snapshot = arguments[++i]; | 54 snapshot = arguments[++i]; |
| 55 } else if (arg == "--library-root") { | 55 } else if (arg == "--library-root") { |
| 56 if (libraryRoot != null) throw "Cannot use multiple library roots"; | 56 if (libraryRoot != null) throw "Cannot use multiple library roots"; |
| 57 libraryRoot = Uri.base.resolve(appendSlash(arguments[++i])); | 57 libraryRoot = Uri.base.resolve(appendSlash(arguments[++i])); |
| 58 } else if (arg == "--patch-root") { | 58 } else if (arg == "--patch-root") { |
| 59 throw "--patch-root not supported anymore"; | 59 throw "--patch-root not supported anymore"; |
| 60 } else if (arg == "--fletch-vm") { | 60 } else if (arg == "--dartino-vm") { |
| 61 if (fletchVm != null) throw "Cannot use multiple Fletch VMs"; | 61 if (dartinoVm != null) throw "Cannot use multiple Dartino VMs"; |
| 62 fletchVm = Uri.base.resolve(arguments[++i]); | 62 dartinoVm = Uri.base.resolve(arguments[++i]); |
| 63 } else if (arg == "--natives-json") { | 63 } else if (arg == "--natives-json") { |
| 64 if (nativesJson != null) throw "Cannot use multiple natives json files"; | 64 if (nativesJson != null) throw "Cannot use multiple natives json files"; |
| 65 nativesJson = Uri.base.resolve(arguments[++i]); | 65 nativesJson = Uri.base.resolve(arguments[++i]); |
| 66 } else if (arg.startsWith("-")) { | 66 } else if (arg.startsWith("-")) { |
| 67 throw "Unknown option $arg"; | 67 throw "Unknown option $arg"; |
| 68 } else { | 68 } else { |
| 69 if (script != null) throw "Cannot run multiple scripts"; | 69 if (script != null) throw "Cannot run multiple scripts"; |
| 70 script = arg; | 70 script = arg; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 if (script == null) { | 74 if (script == null) { |
| 75 throw "Supply a script to run"; | 75 throw "Supply a script to run"; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (packages == null) { | 78 if (packages == null) { |
| 79 packages = ".packages"; | 79 packages = ".packages"; |
| 80 } | 80 } |
| 81 | 81 |
| 82 Address device = | 82 Address device = |
| 83 (debugPort != null) ? new Address("localhost", debugPort) : null; | 83 (debugPort != null) ? new Address("localhost", debugPort) : null; |
| 84 | 84 |
| 85 Settings settings = new Settings( | 85 Settings settings = new Settings( |
| 86 fileUri(packages, Uri.base), <String>["--verbose"], null, device, null); | 86 fileUri(packages, Uri.base), <String>["--verbose"], null, device, null); |
| 87 | 87 |
| 88 SessionState state = developer.createSessionState( | 88 SessionState state = developer.createSessionState( |
| 89 "fletchc-blaze", | 89 "dartino_compiler-blaze", |
| 90 settings, | 90 settings, |
| 91 libraryRoot: libraryRoot, | 91 libraryRoot: libraryRoot, |
| 92 fletchVm: fletchVm, | 92 dartinoVm: dartinoVm, |
| 93 nativesJson: nativesJson); | 93 nativesJson: nativesJson); |
| 94 | 94 |
| 95 int result = await developer.compile(fileUri(script, Uri.base), state); | 95 int result = await developer.compile(fileUri(script, Uri.base), state); |
| 96 | 96 |
| 97 if (result != 0) { | 97 if (result != 0) { |
| 98 print(state.getLog()); | 98 print(state.getLog()); |
| 99 return result; | 99 return result; |
| 100 } | 100 } |
| 101 | 101 |
| 102 if (device != null) { | 102 if (device != null) { |
| 103 await developer.attachToVm(device.host, device.port, state); | 103 await developer.attachToVm(device.host, device.port, state); |
| 104 state.stdoutSink.attachCommandSender(stdout.add); | 104 state.stdoutSink.attachCommandSender(stdout.add); |
| 105 state.stderrSink.attachCommandSender(stderr.add); | 105 state.stderrSink.attachCommandSender(stderr.add); |
| 106 | 106 |
| 107 Session session = state.session; | 107 Session session = state.session; |
| 108 for (FletchDelta delta in state.compilationResults) { | 108 for (DartinoDelta delta in state.compilationResults) { |
| 109 await session.applyDelta(delta); | 109 await session.applyDelta(delta); |
| 110 } | 110 } |
| 111 | 111 |
| 112 var input = stdin.transform(UTF8.decoder).transform(new LineSplitter()); | 112 var input = stdin.transform(UTF8.decoder).transform(new LineSplitter()); |
| 113 await session.debug(input); | 113 await session.debug(input); |
| 114 } else { | 114 } else { |
| 115 await developer.startAndAttachDirectly(state); | 115 await developer.startAndAttachDirectly(state); |
| 116 state.stdoutSink.attachCommandSender(stdout.add); | 116 state.stdoutSink.attachCommandSender(stdout.add); |
| 117 state.stderrSink.attachCommandSender(stderr.add); | 117 state.stderrSink.attachCommandSender(stderr.add); |
| 118 | 118 |
| 119 if (snapshot != null) { | 119 if (snapshot != null) { |
| 120 await developer.export(state, fileUri(snapshot, Uri.base)); | 120 await developer.export(state, fileUri(snapshot, Uri.base)); |
| 121 } else { | 121 } else { |
| 122 await developer.run(state); | 122 await developer.run(state); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 return result; | 126 return result; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 main(List<String> arguments) async { | 130 main(List<String> arguments) async { |
| 131 return await new FletchRunner().run(arguments); | 131 return await new DartinoRunner().run(arguments); |
| 132 } | 132 } |
| OLD | NEW |