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

Side by Side Diff: vm/native_entry.h

Issue 10874072: Use the return value of vm native methods to set the return value, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 3 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
OLDNEW
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 #ifndef VM_NATIVE_ENTRY_H_ 5 #ifndef VM_NATIVE_ENTRY_H_
6 #define VM_NATIVE_ENTRY_H_ 6 #define VM_NATIVE_ENTRY_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
11 #include "vm/native_arguments.h" 11 #include "vm/native_arguments.h"
12 #include "vm/verifier.h" 12 #include "vm/verifier.h"
13 13
14 #include "include/dart_api.h" 14 #include "include/dart_api.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 DECLARE_FLAG(bool, trace_natives); 18 DECLARE_FLAG(bool, trace_natives);
19 19
20 // Forward declarations. 20 // Forward declarations.
21 class Class; 21 class Class;
22 class String; 22 class String;
23 23
24 typedef void (*NativeFunction)(NativeArguments* arguments); 24 typedef void (*NativeFunction)(NativeArguments* arguments);
25 25
26 26
27 #define NATIVE_ENTRY_FUNCTION(name) DN_##name 27 #define NATIVE_ENTRY_FUNCTION(name) BootstrapNatives::DN_##name
28
29
30 // Helper macros for declaring and defining native entries.
31 #define REGISTER_NATIVE_ENTRY(name, count) \
32 { ""#name, NATIVE_ENTRY_FUNCTION(name), count },
33 28
34 29
35 #define DEFINE_NATIVE_ENTRY(name, argument_count) \ 30 #define DEFINE_NATIVE_ENTRY(name, argument_count) \
36 static void DN_Helper##name(Isolate* isolate, NativeArguments* arguments); \ 31 static RawObject* DN_Helper##name(Isolate* isolate, \
37 void NATIVE_ENTRY_FUNCTION(name)(Dart_NativeArguments args) { \ 32 NativeArguments* arguments); \
33 void NATIVE_ENTRY_FUNCTION(name)(Dart_NativeArguments args) { \
38 CHECK_STACK_ALIGNMENT; \ 34 CHECK_STACK_ALIGNMENT; \
39 VERIFY_ON_TRANSITION; \ 35 VERIFY_ON_TRANSITION; \
40 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); \ 36 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); \
41 ASSERT(arguments->Count() == argument_count); \ 37 ASSERT(arguments->Count() == argument_count); \
42 if (FLAG_trace_natives) OS::Print("Calling native: %s\n", ""#name); \ 38 if (FLAG_trace_natives) OS::Print("Calling native: %s\n", ""#name); \
43 { \ 39 { \
44 Zone zone(arguments->isolate()); \ 40 Zone zone(arguments->isolate()); \
45 HANDLESCOPE(arguments->isolate()); \ 41 HANDLESCOPE(arguments->isolate()); \
46 DN_Helper##name(arguments->isolate(), arguments); \ 42 arguments->SetReturnUnsafe( \
43 DN_Helper##name(arguments->isolate(), arguments)); \
47 } \ 44 } \
48 VERIFY_ON_TRANSITION; \ 45 VERIFY_ON_TRANSITION; \
49 } \ 46 } \
50 static void DN_Helper##name(Isolate* isolate, NativeArguments* arguments) 47 static RawObject* DN_Helper##name(Isolate* isolate, \
48 NativeArguments* arguments)
51 49
52 50
53 #define DECLARE_NATIVE_ENTRY(name, argument_count) \
54 extern void NATIVE_ENTRY_FUNCTION(name)(Dart_NativeArguments arguments);
55
56 // Natives should throw an exception if an illegal argument is passed. 51 // Natives should throw an exception if an illegal argument is passed.
57 // type name = value. 52 // type name = value.
58 #define GET_NATIVE_ARGUMENT(type, name, value) \ 53 #define GET_NATIVE_ARGUMENT(type, name, value) \
59 const Instance& __##name##_instance__ = \ 54 const Instance& __##name##_instance__ = \
60 Instance::CheckedHandle(isolate, value); \ 55 Instance::CheckedHandle(isolate, value); \
61 if (!__##name##_instance__.Is##type()) { \ 56 if (!__##name##_instance__.Is##type()) { \
62 GrowableArray<const Object*> __args__; \ 57 GrowableArray<const Object*> __args__; \
63 __args__.Add(&__##name##_instance__); \ 58 __args__.Add(&__##name##_instance__); \
64 Exceptions::ThrowByType(Exceptions::kIllegalArgument, __args__); \ 59 Exceptions::ThrowByType(Exceptions::kIllegalArgument, __args__); \
65 } \ 60 } \
66 const type& name = type::Cast(__##name##_instance__); 61 const type& name = type::Cast(__##name##_instance__);
67 62
68 63
69 64
70 // Helper class for resolving and handling native functions. 65 // Helper class for resolving and handling native functions.
71 class NativeEntry : public AllStatic { 66 class NativeEntry : public AllStatic {
72 public: 67 public:
73 // Resolve specified dart native function to the actual native entrypoint. 68 // Resolve specified dart native function to the actual native entrypoint.
74 static NativeFunction ResolveNative(const Class& cls, 69 static NativeFunction ResolveNative(const Class& cls,
75 const String& function_name, 70 const String& function_name,
76 int number_of_arguments); 71 int number_of_arguments);
77 }; 72 };
78 73
79 } // namespace dart 74 } // namespace dart
80 75
81 #endif // VM_NATIVE_ENTRY_H_ 76 #endif // VM_NATIVE_ENTRY_H_
OLDNEW
« vm/bootstrap_natives.h ('K') | « vm/native_arguments.cc ('k') | vm/native_entry_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698