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

Side by Side Diff: runtime/bin/builtin_natives.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_in.cc ('k') | runtime/bin/builtin_nolib.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 "bin/builtin.h"
6
7 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <stdio.h>
8 #include <string.h> 7 #include <string.h>
9 8
10 #include "bin/dartutils.h"
11 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10
12 #include "platform/assert.h" 11 #include "platform/assert.h"
13 12
13 #include "bin/builtin.h"
14 #include "bin/dartutils.h"
15 #include "bin/io_natives.h"
14 16
15 namespace dart { 17 namespace dart {
16 namespace bin { 18 namespace bin {
17 19
18 // Lists the native functions implementing basic functionality in 20 // Lists the native functions implementing basic functionality in
19 // standalone dart, such as printing, file I/O, and platform information. 21 // standalone dart, such as printing, file I/O, and platform information.
20 // Advanced I/O classes like sockets and process management are implemented 22 // Advanced I/O classes like sockets and process management are implemented
21 // using functions listed in io_natives.cc. 23 // using functions listed in io_natives.cc.
22 #define BUILTIN_NATIVE_LIST(V) \ 24 #define BUILTIN_NATIVE_LIST(V) \
23 V(Directory_Exists, 1) \ 25 V(Directory_Exists, 1) \
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 64
63 static struct NativeEntries { 65 static struct NativeEntries {
64 const char* name_; 66 const char* name_;
65 Dart_NativeFunction function_; 67 Dart_NativeFunction function_;
66 int argument_count_; 68 int argument_count_;
67 } BuiltinEntries[] = { 69 } BuiltinEntries[] = {
68 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION) 70 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION)
69 }; 71 };
70 72
71 73
72 Dart_NativeFunction Builtin::BuiltinNativeLookup(Dart_Handle name, 74 /**
73 int argument_count) { 75 * Looks up native functions in both libdart_builtin and libdart_io.
76 */
77 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name,
78 int argument_count) {
74 const char* function_name = NULL; 79 const char* function_name = NULL;
75 Dart_Handle result = Dart_StringToCString(name, &function_name); 80 Dart_Handle result = Dart_StringToCString(name, &function_name);
76 DART_CHECK_VALID(result); 81 DART_CHECK_VALID(result);
77 ASSERT(function_name != NULL); 82 ASSERT(function_name != NULL);
78 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); 83 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
79 for (int i = 0; i < num_entries; i++) { 84 for (int i = 0; i < num_entries; i++) {
80 struct NativeEntries* entry = &(BuiltinEntries[i]); 85 struct NativeEntries* entry = &(BuiltinEntries[i]);
81 if (!strcmp(function_name, entry->name_) && 86 if (!strcmp(function_name, entry->name_) &&
82 (entry->argument_count_ == argument_count)) { 87 (entry->argument_count_ == argument_count)) {
83 return reinterpret_cast<Dart_NativeFunction>(entry->function_); 88 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
84 } 89 }
85 } 90 }
86 return NULL; 91 return IONativeLookup(name, argument_count);
87 } 92 }
88 93
89 94
90 // Implementation of native functions which are used for some 95 // Implementation of native functions which are used for some
91 // test/debug functionality in standalone dart mode. 96 // test/debug functionality in standalone dart mode.
92 97 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
93 void Builtin::PrintString(FILE* out, Dart_Handle str) { 98 Dart_EnterScope();
94 intptr_t length = 0; 99 intptr_t length = 0;
95 uint8_t* chars = NULL; 100 uint8_t* chars = NULL;
101 Dart_Handle str = Dart_GetNativeArgument(args, 0);
96 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); 102 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length);
97 if (Dart_IsError(result)) { 103 if (Dart_IsError(result)) {
98 // TODO(turnidge): Consider propagating some errors here. What if 104 // TODO(turnidge): Consider propagating some errors here. What if
99 // an isolate gets interrupted by the embedder in the middle of 105 // an isolate gets interrupted by the embedder in the middle of
100 // Dart_StringToUTF8? We need to make sure not to swallow the 106 // Dart_StringToUTF8? We need to make sure not to swallow the
101 // interrupt. 107 // interrupt.
102 fputs(Dart_GetError(result), out); 108 fputs(Dart_GetError(result), stdout);
103 } else { 109 } else {
104 fwrite(chars, sizeof(*chars), length, out); 110 fwrite(chars, sizeof(*chars), length, stdout);
105 } 111 }
106 fputc('\n', out); 112 fputc('\n', stdout);
107 fflush(out); 113 fflush(stdout);
108 }
109
110
111 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
112 Dart_EnterScope();
113 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0));
114 Dart_ExitScope(); 114 Dart_ExitScope();
115 } 115 }
116 116
117 } // namespace bin 117 } // namespace bin
118 } // namespace dart 118 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/builtin_in.cc ('k') | runtime/bin/builtin_nolib.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698