OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
11 | 11 |
12 // Implementation of native functions which are used for some | 12 static void SetupCorelibImports(Dart_Handle builtin_lib) { |
13 // test/debug functionality in standalone dart mode. | 13 // Lookup the core libraries and import the builtin library into them. |
| 14 Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL); |
| 15 Dart_Handle core_lib = Dart_LookupLibrary(url); |
| 16 DART_CHECK_VALID(core_lib); |
| 17 DART_CHECK_VALID(Dart_LibraryImportLibrary(core_lib, builtin_lib)); |
14 | 18 |
15 void PrintString(FILE* out, Dart_Handle str) { | 19 url = Dart_NewString(DartUtils::kCoreImplLibURL); |
16 const char* cstring = NULL; | 20 Dart_Handle coreimpl_lib = Dart_LookupLibrary(url); |
17 Dart_Handle result = Dart_StringToCString(str, &cstring); | 21 DART_CHECK_VALID(coreimpl_lib); |
18 if (Dart_IsError(result)) { | 22 DART_CHECK_VALID(Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib)); |
19 cstring = Dart_GetError(result); | |
20 } | |
21 fprintf(out, "%s\n", cstring); | |
22 fflush(out); | |
23 } | 23 } |
24 | 24 |
25 | 25 |
26 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { | 26 Dart_Handle Builtin::Source() { |
27 Dart_EnterScope(); | 27 Dart_Handle source = Dart_NewString(Builtin::Builtin_source_); |
28 PrintString(stdout, Dart_GetNativeArgument(args, 0)); | 28 return source; |
29 Dart_ExitScope(); | |
30 } | 29 } |
31 | 30 |
32 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { | 31 |
33 Dart_EnterScope(); | 32 void Builtin::SetupLibrary(Dart_Handle builtin_lib) { |
34 int64_t status = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 33 // Setup core lib, builtin import structure. |
35 Dart_ExitScope(); | 34 SetupCorelibImports(builtin_lib); |
36 exit(status); | 35 // Setup the native resolver for built in library functions. |
| 36 DART_CHECK_VALID(Dart_SetNativeResolver(builtin_lib, NativeLookup)); |
37 } | 37 } |
| 38 |
| 39 |
| 40 void Builtin::ImportLibrary(Dart_Handle library) { |
| 41 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| 42 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
| 43 if (Dart_IsError(builtin_lib)) { |
| 44 builtin_lib = Dart_LoadLibrary(url, Source()); |
| 45 if (!Dart_IsError(builtin_lib)) { |
| 46 SetupLibrary(builtin_lib); |
| 47 } |
| 48 } |
| 49 // Import the builtin library into current library. |
| 50 DART_CHECK_VALID(builtin_lib); |
| 51 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, builtin_lib)); |
| 52 } |
OLD | NEW |