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

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

Issue 11360121: When building standalone Dart executable, put implementation of dart:io natives in a separate libra… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix grammar. Created 8 years, 1 month 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
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" 5 #include "bin/builtin.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
11 #include "include/dart_api.h" 11 #include "include/dart_api.h"
12 #include "platform/assert.h" 12 #include "platform/assert.h"
13 13
14 14
15 // List all native functions implemented in standalone dart that is used 15 // Lists the native functions implementing basic functionality in
16 // to inject additional functionality e.g: Logger, file I/O, socket I/O etc. 16 // standalone dart, such as printing, file I/O, and platform information.
17 // Advanced I/O classes like sockets and process management are implemented
18 // using functions listed in io_natives.cc.
17 #define BUILTIN_NATIVE_LIST(V) \ 19 #define BUILTIN_NATIVE_LIST(V) \
18 V(Common_IsBuiltinList, 1) \ 20 V(Common_IsBuiltinList, 1) \
19 V(Crypto_GetRandomBytes, 1) \ 21 V(Crypto_GetRandomBytes, 1) \
Mads Ager (google) 2012/11/08 09:32:26 I think these first two can be moved too?
20 V(Directory_Exists, 1) \ 22 V(Directory_Exists, 1) \
21 V(Directory_Create, 1) \ 23 V(Directory_Create, 1) \
22 V(Directory_Current, 0) \ 24 V(Directory_Current, 0) \
23 V(Directory_CreateTemp, 1) \ 25 V(Directory_CreateTemp, 1) \
24 V(Directory_Delete, 2) \ 26 V(Directory_Delete, 2) \
25 V(Directory_Rename, 2) \ 27 V(Directory_Rename, 2) \
26 V(Directory_NewServicePort, 0) \ 28 V(Directory_NewServicePort, 0) \
27 V(EventHandler_Start, 1) \
28 V(EventHandler_SendData, 4) \
29 V(Exit, 1) \ 29 V(Exit, 1) \
30 V(File_Open, 2) \ 30 V(File_Open, 2) \
31 V(File_Exists, 1) \ 31 V(File_Exists, 1) \
32 V(File_Close, 1) \ 32 V(File_Close, 1) \
33 V(File_ReadByte, 1) \ 33 V(File_ReadByte, 1) \
34 V(File_WriteByte, 2) \ 34 V(File_WriteByte, 2) \
35 V(File_ReadList, 4) \ 35 V(File_ReadList, 4) \
36 V(File_WriteList, 4) \ 36 V(File_WriteList, 4) \
37 V(File_Position, 1) \ 37 V(File_Position, 1) \
38 V(File_SetPosition, 2) \ 38 V(File_SetPosition, 2) \
39 V(File_Truncate, 2) \ 39 V(File_Truncate, 2) \
40 V(File_Length, 1) \ 40 V(File_Length, 1) \
41 V(File_LengthFromName, 1) \ 41 V(File_LengthFromName, 1) \
42 V(File_LastModified, 1) \ 42 V(File_LastModified, 1) \
43 V(File_Flush, 1) \ 43 V(File_Flush, 1) \
44 V(File_Create, 1) \ 44 V(File_Create, 1) \
45 V(File_Delete, 1) \ 45 V(File_Delete, 1) \
46 V(File_Directory, 1) \ 46 V(File_Directory, 1) \
47 V(File_FullPath, 1) \ 47 V(File_FullPath, 1) \
48 V(File_OpenStdio, 1) \ 48 V(File_OpenStdio, 1) \
49 V(File_GetStdioHandleType, 1) \ 49 V(File_GetStdioHandleType, 1) \
50 V(File_NewServicePort, 0) \ 50 V(File_NewServicePort, 0) \
51 V(Logger_PrintString, 1) \ 51 V(Logger_PrintString, 1) \
52 V(Platform_NumberOfProcessors, 0) \ 52 V(Platform_NumberOfProcessors, 0) \
53 V(Platform_OperatingSystem, 0) \ 53 V(Platform_OperatingSystem, 0) \
54 V(Platform_PathSeparator, 0) \ 54 V(Platform_PathSeparator, 0) \
55 V(Platform_LocalHostname, 0) \ 55 V(Platform_LocalHostname, 0) \
56 V(Platform_Environment, 0) \ 56 V(Platform_Environment, 0)
57 V(Process_Start, 10) \
58 V(Process_Kill, 3) \
59 V(ServerSocket_CreateBindListen, 4) \
60 V(ServerSocket_Accept, 2) \
61 V(Socket_CreateConnect, 3) \
62 V(Socket_Available, 1) \
63 V(Socket_Read, 2) \
64 V(Socket_ReadList, 4) \
65 V(Socket_WriteList, 4) \
66 V(Socket_GetPort, 1) \
67 V(Socket_GetRemotePeer, 1) \
68 V(Socket_GetError, 1) \
69 V(Socket_GetStdioHandle, 2) \
70 V(Socket_NewServicePort, 0)
71 57
72 58
73 BUILTIN_NATIVE_LIST(DECLARE_FUNCTION); 59 BUILTIN_NATIVE_LIST(DECLARE_FUNCTION);
74 60
75 static struct NativeEntries { 61 static struct NativeEntries {
76 const char* name_; 62 const char* name_;
77 Dart_NativeFunction function_; 63 Dart_NativeFunction function_;
78 int argument_count_; 64 int argument_count_;
79 } BuiltinEntries[] = { 65 } BuiltinEntries[] = {
80 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION) 66 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION)
81 }; 67 };
82 68
83 69
84 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name, 70 Dart_NativeFunction Builtin::BuiltinNativeLookup(Dart_Handle name,
85 int argument_count) { 71 int argument_count) {
86 const char* function_name = NULL; 72 const char* function_name = NULL;
87 Dart_Handle result = Dart_StringToCString(name, &function_name); 73 Dart_Handle result = Dart_StringToCString(name, &function_name);
88 DART_CHECK_VALID(result); 74 DART_CHECK_VALID(result);
89 ASSERT(function_name != NULL); 75 ASSERT(function_name != NULL);
90 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); 76 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
91 for (int i = 0; i < num_entries; i++) { 77 for (int i = 0; i < num_entries; i++) {
92 struct NativeEntries* entry = &(BuiltinEntries[i]); 78 struct NativeEntries* entry = &(BuiltinEntries[i]);
93 if (!strcmp(function_name, entry->name_) && 79 if (!strcmp(function_name, entry->name_) &&
94 (entry->argument_count_ == argument_count)) { 80 (entry->argument_count_ == argument_count)) {
95 return reinterpret_cast<Dart_NativeFunction>(entry->function_); 81 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 114
129 115
130 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { 116 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) {
131 Dart_EnterScope(); 117 Dart_EnterScope();
132 int64_t status = 0; 118 int64_t status = 0;
133 // Ignore result if passing invalid argument and just exit 0. 119 // Ignore result if passing invalid argument and just exit 0.
134 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 120 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
135 Dart_ExitScope(); 121 Dart_ExitScope();
136 exit(status); 122 exit(status);
137 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698