| 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 #include <dart_api.h> | 5 #include <dart_api.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "bin/log.h" | 10 #include "bin/log.h" |
| 11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
| 12 | 12 |
| 13 const char* kBuiltinScript = | 13 const char* kBuiltinScript = |
| 14 "_printString(String line) native \"Builtin_PrintString\";\n" | 14 "_printString(String line) native \"Builtin_PrintString\";\n" |
| 15 "_getPrintClosure() => _printString;\n"; | 15 "_getPrintClosure() => _printString;\n"; |
| 16 | 16 |
| 17 const char* kHelloWorldScript = "main() { print(\"Hello, Fuchsia!\"); }"; | 17 const char* kHelloWorldScript = "main() { print(\"Hello, Fuchsia!\"); }"; |
| 18 | 18 |
| 19 namespace dart { | 19 namespace dart { |
| 20 namespace bin { | 20 namespace bin { |
| 21 | 21 |
| 22 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we |
| 23 // link in a snapshot otherwise it is initialized to NULL. |
| 24 extern const uint8_t* vm_isolate_snapshot_buffer; |
| 25 |
| 26 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a |
| 27 // snapshot otherwise it is initialized to NULL. |
| 28 extern const uint8_t* isolate_snapshot_buffer; |
| 29 |
| 22 static void Builtin_PrintString(Dart_NativeArguments args) { | 30 static void Builtin_PrintString(Dart_NativeArguments args) { |
| 23 intptr_t length = 0; | 31 intptr_t length = 0; |
| 24 uint8_t* chars = NULL; | 32 uint8_t* chars = NULL; |
| 25 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 33 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
| 26 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); | 34 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); |
| 27 if (Dart_IsError(result)) { | 35 if (Dart_IsError(result)) { |
| 28 Dart_PropagateError(result); | 36 Dart_PropagateError(result); |
| 29 } | 37 } |
| 30 // Uses fwrite to support printing NUL bytes. | 38 // Uses fwrite to support printing NUL bytes. |
| 31 intptr_t res = fwrite(chars, 1, length, stdout); | 39 intptr_t res = fwrite(chars, 1, length, stdout); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 DART_CHECK_VALID(status); | 140 DART_CHECK_VALID(status); |
| 133 } | 141 } |
| 134 | 142 |
| 135 int Main() { | 143 int Main() { |
| 136 Log::Print("Calling Dart_SetVMFlags\n"); | 144 Log::Print("Calling Dart_SetVMFlags\n"); |
| 137 if (!Dart_SetVMFlags(0, NULL)) { | 145 if (!Dart_SetVMFlags(0, NULL)) { |
| 138 FATAL("Failed to set flags\n"); | 146 FATAL("Failed to set flags\n"); |
| 139 } | 147 } |
| 140 Log::Print("Calling Dart_Initialize\n"); | 148 Log::Print("Calling Dart_Initialize\n"); |
| 141 char* error = Dart_Initialize( | 149 char* error = Dart_Initialize( |
| 142 NULL, NULL, NULL, | 150 vm_isolate_snapshot_buffer, NULL, NULL, |
| 143 NULL, NULL, NULL, NULL, | 151 NULL, NULL, NULL, NULL, |
| 144 NULL, | 152 NULL, |
| 145 NULL, | 153 NULL, |
| 146 NULL, | 154 NULL, |
| 147 NULL, | 155 NULL, |
| 148 NULL, | 156 NULL, |
| 149 NULL, | 157 NULL, |
| 150 NULL); | 158 NULL); |
| 151 if (error != NULL) { | 159 if (error != NULL) { |
| 152 FATAL1("VM initialization failed: %s\n", error); | 160 FATAL1("VM initialization failed: %s\n", error); |
| 153 } | 161 } |
| 154 | 162 |
| 155 Log::Print("Creating Isolate\n"); | 163 Log::Print("Creating Isolate\n"); |
| 156 Dart_Isolate isolate = Dart_CreateIsolate( | 164 Dart_Isolate isolate = Dart_CreateIsolate( |
| 157 "script_uri", | 165 "script_uri", |
| 158 "main", | 166 "main", |
| 159 NULL, | 167 isolate_snapshot_buffer, |
| 160 NULL, | 168 NULL, |
| 161 NULL, | 169 NULL, |
| 162 &error); | 170 &error); |
| 163 if (isolate == NULL) { | 171 if (isolate == NULL) { |
| 164 FATAL1("Dart_CreateIsolate failed: %s\n", error); | 172 FATAL1("Dart_CreateIsolate failed: %s\n", error); |
| 165 } | 173 } |
| 166 | 174 |
| 167 Log::Print("Entering Scope\n"); | 175 Log::Print("Entering Scope\n"); |
| 168 Dart_EnterScope(); | 176 Dart_EnterScope(); |
| 169 | 177 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 Log::Print("Success!\n"); | 210 Log::Print("Success!\n"); |
| 203 return 0; | 211 return 0; |
| 204 } | 212 } |
| 205 | 213 |
| 206 } // namespace bin | 214 } // namespace bin |
| 207 } // namespace dart | 215 } // namespace dart |
| 208 | 216 |
| 209 int main(void) { | 217 int main(void) { |
| 210 return dart::bin::Main(); | 218 return dart::bin::Main(); |
| 211 } | 219 } |
| OLD | NEW |