| OLD | NEW |
| 1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 #ifdef FLETCH_ENABLE_LIVE_CODING | 5 #ifdef DARTINO_ENABLE_LIVE_CODING |
| 6 | 6 |
| 7 #include <stddef.h> // for size_t | 7 #include <stddef.h> // for size_t |
| 8 | 8 |
| 9 #include "include/fletch_api.h" | 9 #include "include/dartino_api.h" |
| 10 | 10 |
| 11 #include "src/shared/connection.h" | 11 #include "src/shared/connection.h" |
| 12 #include "src/shared/flags.h" | 12 #include "src/shared/flags.h" |
| 13 #include "src/shared/utils.h" | 13 #include "src/shared/utils.h" |
| 14 #include "src/shared/version.h" | 14 #include "src/shared/version.h" |
| 15 #include "src/shared/platform.h" | 15 #include "src/shared/platform.h" |
| 16 #include "src/shared/globals.h" | 16 #include "src/shared/globals.h" |
| 17 | 17 |
| 18 #include "src/vm/session.h" | 18 #include "src/vm/session.h" |
| 19 #include "src/vm/log_print_interceptor.h" | 19 #include "src/vm/log_print_interceptor.h" |
| 20 | 20 |
| 21 namespace fletch { | 21 namespace dartino { |
| 22 | 22 |
| 23 static int RunSession(Connection* connection) { | 23 static int RunSession(Connection* connection) { |
| 24 Session session(connection); | 24 Session session(connection); |
| 25 session.Initialize(); | 25 session.Initialize(); |
| 26 session.StartMessageProcessingThread(); | 26 session.StartMessageProcessingThread(); |
| 27 int result = session.ProcessRun(); | 27 int result = session.ProcessRun(); |
| 28 session.JoinMessageProcessingThread(); | 28 session.JoinMessageProcessingThread(); |
| 29 return result; | 29 return result; |
| 30 } | 30 } |
| 31 | 31 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 static bool EndsWith(const char* s, const char* suffix) { | 54 static bool EndsWith(const char* s, const char* suffix) { |
| 55 int s_length = strlen(s); | 55 int s_length = strlen(s); |
| 56 int suffix_length = strlen(suffix); | 56 int suffix_length = strlen(suffix); |
| 57 return (suffix_length <= s_length) | 57 return (suffix_length <= s_length) |
| 58 ? strncmp(s + s_length - suffix_length, suffix, suffix_length) == 0 | 58 ? strncmp(s + s_length - suffix_length, suffix, suffix_length) == 0 |
| 59 : false; | 59 : false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 static void PrintUsage() { | 62 static void PrintUsage() { |
| 63 Print::Out("fletch-vm - The embedded Dart virtual machine.\n\n"); | 63 Print::Out("dartino-vm - The embedded Dart virtual machine.\n\n"); |
| 64 Print::Out( | 64 Print::Out( |
| 65 " fletch-vm [--port=<port>] [--host=<address>] " | 65 " dartino-vm [--port=<port>] [--host=<address>] " |
| 66 "[snapshot file]\n\n"); | 66 "[snapshot file]\n\n"); |
| 67 Print::Out("When specifying a snapshot other options are ignored.\n\n"); | 67 Print::Out("When specifying a snapshot other options are ignored.\n\n"); |
| 68 Print::Out("Options:\n"); | 68 Print::Out("Options:\n"); |
| 69 Print::Out( | 69 Print::Out( |
| 70 " --port: specifies which port to listen on. Defaults " | 70 " --port: specifies which port to listen on. Defaults " |
| 71 "to random port.\n"); | 71 "to random port.\n"); |
| 72 Print::Out( | 72 Print::Out( |
| 73 " --host: specifies which host address to listen on. " | 73 " --host: specifies which host address to listen on. " |
| 74 "Defaults to 127.0.0.1.\n"); | 74 "Defaults to 127.0.0.1.\n"); |
| 75 Print::Out(" --help: print out 'fletch-vm' usage.\n"); | 75 Print::Out(" --help: print out 'dartino-vm' usage.\n"); |
| 76 Print::Out(" --version: print the version.\n"); | 76 Print::Out(" --version: print the version.\n"); |
| 77 Print::Out("\n"); | 77 Print::Out("\n"); |
| 78 } | 78 } |
| 79 | 79 |
| 80 static void PrintVersion() { Print::Out("%s\n", GetVersion()); } | 80 static void PrintVersion() { Print::Out("%s\n", GetVersion()); } |
| 81 | 81 |
| 82 static int Main(int argc, char** argv) { | 82 static int Main(int argc, char** argv) { |
| 83 #ifdef DEBUG | 83 #ifdef DEBUG |
| 84 if (Platform::GetEnv("FLETCH_VM_WAIT") != NULL) { | 84 if (Platform::GetEnv("DARTINO_VM_WAIT") != NULL) { |
| 85 Platform::WaitForDebugger(argv[0]); | 85 Platform::WaitForDebugger(argv[0]); |
| 86 } | 86 } |
| 87 #endif | 87 #endif |
| 88 Flags::ExtractFromCommandLine(&argc, argv); | 88 Flags::ExtractFromCommandLine(&argc, argv); |
| 89 FletchSetup(); | 89 DartinoSetup(); |
| 90 | 90 |
| 91 if (argc > 5) { | 91 if (argc > 5) { |
| 92 Print::Out("Too many arguments.\n\n"); | 92 Print::Out("Too many arguments.\n\n"); |
| 93 PrintUsage(); | 93 PrintUsage(); |
| 94 exit(1); | 94 exit(1); |
| 95 } else if (argc < 1) { | 95 } else if (argc < 1) { |
| 96 Print::Out("Not enough arguments.\n\n"); | 96 Print::Out("Not enough arguments.\n\n"); |
| 97 PrintUsage(); | 97 PrintUsage(); |
| 98 exit(1); | 98 exit(1); |
| 99 } | 99 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 // Check if we're passed an snapshot file directly. | 157 // Check if we're passed an snapshot file directly. |
| 158 if (run_snapshot) { | 158 if (run_snapshot) { |
| 159 List<uint8> bytes = Platform::LoadFile(input); | 159 List<uint8> bytes = Platform::LoadFile(input); |
| 160 if (bytes.is_empty()) { | 160 if (bytes.is_empty()) { |
| 161 Print::Out("\n"); // Separate error from Platform::LoadFile from usage. | 161 Print::Out("\n"); // Separate error from Platform::LoadFile from usage. |
| 162 PrintUsage(); | 162 PrintUsage(); |
| 163 exit(1); | 163 exit(1); |
| 164 } | 164 } |
| 165 if (IsSnapshot(bytes)) { | 165 if (IsSnapshot(bytes)) { |
| 166 FletchProgram program = FletchLoadSnapshot(bytes.data(), bytes.length()); | 166 DartinoProgram program = |
| 167 result = FletchRunMain(program); | 167 DartinoLoadSnapshot(bytes.data(), bytes.length()); |
| 168 FletchDeleteProgram(program); | 168 result = DartinoRunMain(program); |
| 169 DartinoDeleteProgram(program); |
| 169 interactive = false; | 170 interactive = false; |
| 170 } else { | 171 } else { |
| 171 Print::Out("The file '%s' is not a snapshot.\n\n"); | 172 Print::Out("The file '%s' is not a snapshot.\n\n"); |
| 172 if (EndsWith(input, ".dart")) { | 173 if (EndsWith(input, ".dart")) { |
| 173 Print::Out("Try: 'fletch run %s'\n\n", input); | 174 Print::Out("Try: 'dartino run %s'\n\n", input); |
| 174 } else { | 175 } else { |
| 175 PrintUsage(); | 176 PrintUsage(); |
| 176 } | 177 } |
| 177 exit(1); | 178 exit(1); |
| 178 } | 179 } |
| 179 bytes.Delete(); | 180 bytes.Delete(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 // If we haven't already run from a snapshot, we start an | 183 // If we haven't already run from a snapshot, we start an |
| 183 // interactive programming session that talks to a separate | 184 // interactive programming session that talks to a separate |
| 184 // compiler process. | 185 // compiler process. |
| 185 if (interactive) { | 186 if (interactive) { |
| 186 Connection* connection = WaitForCompilerConnection(host, port, port_file); | 187 Connection* connection = WaitForCompilerConnection(host, port, port_file); |
| 187 result = RunSession(connection); | 188 result = RunSession(connection); |
| 188 } | 189 } |
| 189 | 190 |
| 190 FletchTearDown(); | 191 DartinoTearDown(); |
| 191 return result; | 192 return result; |
| 192 } | 193 } |
| 193 | 194 |
| 194 } // namespace fletch | 195 } // namespace dartino |
| 195 | 196 |
| 196 // Forward main calls to fletch::Main. | 197 // Forward main calls to dartino::Main. |
| 197 int main(int argc, char** argv) { return fletch::Main(argc, argv); } | 198 int main(int argc, char** argv) { return dartino::Main(argc, argv); } |
| 198 | 199 |
| 199 #endif // FLETCH_ENABLE_LIVE_CODING | 200 #endif // DARTINO_ENABLE_LIVE_CODING |
| OLD | NEW |