OLD | NEW |
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 <stdlib.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
11 | 11 |
12 #include "platform/assert.h" | 12 #include "platform/assert.h" |
13 | 13 |
14 #include "bin/builtin.h" | 14 #include "bin/builtin.h" |
15 #include "bin/dartutils.h" | 15 #include "bin/dartutils.h" |
16 #include "bin/embedded_dart_io.h" | 16 #include "bin/embedded_dart_io.h" |
17 #include "bin/file.h" | 17 #include "bin/file.h" |
18 #include "bin/io_natives.h" | 18 #include "bin/io_natives.h" |
19 #include "bin/platform.h" | 19 #include "bin/platform.h" |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 namespace bin { | 22 namespace bin { |
23 | 23 |
24 // Lists the native functions implementing basic functionality in | 24 // Lists the native functions implementing basic functionality in |
25 // standalone dart, such as printing, file I/O, and platform information. | 25 // standalone dart, such as printing, file I/O, and platform information. |
26 // Advanced I/O classes like sockets and process management are implemented | 26 // Advanced I/O classes like sockets and process management are implemented |
27 // using functions listed in io_natives.cc. | 27 // using functions listed in io_natives.cc. |
28 #define BUILTIN_NATIVE_LIST(V) \ | 28 #define BUILTIN_NATIVE_LIST(V) \ |
29 V(Builtin_PrintString, 1) \ | 29 V(Builtin_PrintString, 1) \ |
30 V(Builtin_GetCurrentDirectory, 0) \ | 30 V(Builtin_GetCurrentDirectory, 0) |
31 | 31 |
32 | 32 |
33 BUILTIN_NATIVE_LIST(DECLARE_FUNCTION); | 33 BUILTIN_NATIVE_LIST(DECLARE_FUNCTION); |
34 | 34 |
35 static struct NativeEntries { | 35 static struct NativeEntries { |
36 const char* name_; | 36 const char* name_; |
37 Dart_NativeFunction function_; | 37 Dart_NativeFunction function_; |
38 int argument_count_; | 38 int argument_count_; |
39 } BuiltinEntries[] = { | 39 } BuiltinEntries[] = {BUILTIN_NATIVE_LIST(REGISTER_FUNCTION)}; |
40 BUILTIN_NATIVE_LIST(REGISTER_FUNCTION) | |
41 }; | |
42 | 40 |
43 | 41 |
44 void Builtin_DummyNative(Dart_NativeArguments args) { | 42 void Builtin_DummyNative(Dart_NativeArguments args) { |
45 UNREACHABLE(); | 43 UNREACHABLE(); |
46 } | 44 } |
47 | 45 |
48 | 46 |
49 | |
50 /** | 47 /** |
51 * Looks up native functions in both libdart_builtin and libdart_io. | 48 * Looks up native functions in both libdart_builtin and libdart_io. |
52 */ | 49 */ |
53 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name, | 50 Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name, |
54 int argument_count, | 51 int argument_count, |
55 bool* auto_setup_scope) { | 52 bool* auto_setup_scope) { |
56 const char* function_name = NULL; | 53 const char* function_name = NULL; |
57 Dart_Handle err = Dart_StringToCString(name, &function_name); | 54 Dart_Handle err = Dart_StringToCString(name, &function_name); |
58 DART_CHECK_VALID(err); | 55 DART_CHECK_VALID(err); |
59 ASSERT(function_name != NULL); | 56 ASSERT(function_name != NULL); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 Dart_PropagateError(result); | 96 Dart_PropagateError(result); |
100 } | 97 } |
101 | 98 |
102 // Uses fwrite to support printing NUL bytes. | 99 // Uses fwrite to support printing NUL bytes. |
103 intptr_t res = fwrite(chars, 1, length, stdout); | 100 intptr_t res = fwrite(chars, 1, length, stdout); |
104 ASSERT(res == length); | 101 ASSERT(res == length); |
105 fputs("\n", stdout); | 102 fputs("\n", stdout); |
106 fflush(stdout); | 103 fflush(stdout); |
107 if (ShouldCaptureStdout()) { | 104 if (ShouldCaptureStdout()) { |
108 // For now we report print output on the Stdout stream. | 105 // For now we report print output on the Stdout stream. |
109 uint8_t newline[] = { '\n' }; | 106 uint8_t newline[] = {'\n'}; |
110 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length); | 107 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length); |
111 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", | 108 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", newline, sizeof(newline)); |
112 newline, sizeof(newline)); | |
113 } | 109 } |
114 } | 110 } |
115 | 111 |
116 } // namespace bin | 112 } // namespace bin |
117 } // namespace dart | 113 } // namespace dart |
OLD | NEW |