Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: runtime/bin/builtin_gen_snapshot.cc

Issue 14752008: Final step towards loading core library scripts directly from the sources (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/builtin.cc ('k') | runtime/bin/builtin_in.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 <stdlib.h>
5 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h>
6 8
7 #include "include/dart_api.h" 9 #include "include/dart_api.h"
8 10
9 #include "bin/builtin.h" 11 #include "bin/builtin.h"
10 #include "bin/dartutils.h"
11
12 12
13 namespace dart { 13 namespace dart {
14 namespace bin { 14 namespace bin {
15 15
16 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = { 16 // Lists the native function implementing basic logging facility.
17 /* { url_, source_, patch_url_, patch_source_, has_natives_ } */ 17 #define BUILTIN_NATIVE_LIST(V) \
18 { DartUtils::kBuiltinLibURL, builtin_source_, NULL, NULL, true }, 18 V(Logger_PrintString, 1)
19 { DartUtils::kIOLibURL, io_source_, 19
20 DartUtils::kIOLibPatchURL, io_patch_, true }, 20 BUILTIN_NATIVE_LIST(DECLARE_FUNCTION);
21
22 static struct NativeEntries {
23 const char* name_;
24 Dart_NativeFunction function_;
25 int argument_count_;
26 } BuiltinEntries[] = {
27 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION)
21 }; 28 };
22 29
23 30
24 Dart_Handle Builtin::Source(BuiltinLibraryId id) {
25 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) ==
26 kInvalidLibrary);
27 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary);
28 return DartUtils::NewString(builtin_libraries_[id].source_);
29 }
30
31
32 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name, 31 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name,
33 int argument_count) { 32 int argument_count) {
34 UNREACHABLE(); 33 const char* function_name = NULL;
34 Dart_Handle result = Dart_StringToCString(name, &function_name);
35 DART_CHECK_VALID(result);
36 ASSERT(function_name != NULL);
37 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
38 for (int i = 0; i < num_entries; i++) {
39 struct NativeEntries* entry = &(BuiltinEntries[i]);
40 if (!strcmp(function_name, entry->name_) &&
41 (entry->argument_count_ == argument_count)) {
42 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
43 }
44 }
35 return NULL; 45 return NULL;
36 } 46 }
37 47
38 48
39 void Builtin::SetNativeResolver(BuiltinLibraryId id) { 49 // Implementation of native functions which are used for some
40 UNREACHABLE(); 50 // test/debug functionality in standalone dart mode.
41 } 51 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
42 52 Dart_EnterScope();
43 53 intptr_t length = 0;
44 Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) { 54 uint8_t* chars = NULL;
45 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == 55 Dart_Handle str = Dart_GetNativeArgument(args, 0);
46 kInvalidLibrary); 56 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length);
47 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); 57 if (Dart_IsError(result)) {
48 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); 58 // TODO(turnidge): Consider propagating some errors here. What if
49 Dart_Handle library = Dart_LookupLibrary(url); 59 // an isolate gets interrupted by the embedder in the middle of
50 if (Dart_IsError(library)) { 60 // Dart_StringToUTF8? We need to make sure not to swallow the
51 library = Dart_LoadLibrary(url, Source(id)); 61 // interrupt.
52 if (!Dart_IsError(library) && (builtin_libraries_[id].has_natives_)) { 62 fputs(Dart_GetError(result), stdout);
53 // Setup the native resolver for built in library functions. 63 } else {
54 // Looks up native functions only in libdart_builtin, not libdart_io. 64 fwrite(chars, sizeof(*chars), length, stdout);
55 // This is for use in the snapshot generator, which should be
56 // independent of most of the dart:io C++ code.
57 DART_CHECK_VALID(Dart_SetNativeResolver(library, BuiltinNativeLookup));
58 }
59 if (builtin_libraries_[id].patch_url_ != NULL) {
60 ASSERT(builtin_libraries_[id].patch_source_ != NULL);
61 Dart_Handle patch_url =
62 DartUtils::NewString(builtin_libraries_[id].patch_url_);
63 Dart_Handle patch_source =
64 DartUtils::NewString(builtin_libraries_[id].patch_source_);
65 DART_CHECK_VALID(Dart_LoadPatch(library, patch_url, patch_source));
66 }
67 } 65 }
68 DART_CHECK_VALID(library); 66 fputc('\n', stdout);
69 return library; 67 fflush(stdout);
68 Dart_ExitScope();
70 } 69 }
71 70
72 } // namespace bin 71 } // namespace bin
73 } // namespace dart 72 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/builtin.cc ('k') | runtime/bin/builtin_in.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698