OLD | NEW |
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_ARGUMENTS_H_ | 5 #ifndef VM_NATIVE_ARGUMENTS_H_ |
6 #define VM_NATIVE_ARGUMENTS_H_ | 6 #define VM_NATIVE_ARGUMENTS_H_ |
7 | 7 |
8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 // Forward declarations. | 12 // Forward declarations. |
| 13 class Isolate; |
13 class Object; | 14 class Object; |
14 class RawObject; | 15 class RawObject; |
15 | 16 |
16 | 17 |
17 // Class NativeArguments is used to access arguments passed in from | 18 // Class NativeArguments is used to access arguments passed in from |
18 // generated dart code to a runtime function or a dart library native | 19 // generated dart code to a runtime function or a dart library native |
19 // function. It is also used to set the return value if any at the slot | 20 // function. It is also used to set the return value if any at the slot |
20 // reserved for return values. | 21 // reserved for return values. |
21 // All runtime function/dart library native functions have the | 22 // All runtime function/dart library native functions have the |
22 // following signature: | 23 // following signature: |
23 // void function_name(NativeArguments arguments); | 24 // void function_name(NativeArguments arguments); |
24 // Inside the function, arguments are accessed as follows: | 25 // Inside the function, arguments are accessed as follows: |
25 // const Type& arg1 = Type::CheckedHandle(arguments.GetArgument(0)); | 26 // const Type& arg1 = Type::CheckedHandle(arguments.GetArgument(0)); |
26 // const Type& arg2 = Type::CheckedHandle(arguments.GetArgument(1)); | 27 // const Type& arg2 = Type::CheckedHandle(arguments.GetArgument(1)); |
27 // The return value is set as follows: | 28 // The return value is set as follows: |
28 // arguments.SetReturnValue(result); | 29 // arguments.SetReturnValue(result); |
29 // NOTE: Since we pass this as a pass by value argument in the stubs we don't | 30 // NOTE: Since we pass this as a pass by value argument in the stubs we don't |
30 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a | 31 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a |
31 // subclass of ValueObject. | 32 // subclass of ValueObject. |
32 class NativeArguments { | 33 class NativeArguments { |
33 public: | 34 public: |
| 35 Isolate* isolate() const { return isolate_; } |
34 int Count() const { return argc_; } | 36 int Count() const { return argc_; } |
35 | 37 |
36 RawObject* At(int index) const { | 38 RawObject* At(int index) const { |
37 ASSERT(index >=0 && index < argc_); | 39 ASSERT(index >=0 && index < argc_); |
38 return (*argv_)[-index]; | 40 return (*argv_)[-index]; |
39 } | 41 } |
40 | 42 |
41 void SetReturn(const Object& value) const; | 43 void SetReturn(const Object& value) const; |
42 | 44 |
| 45 static intptr_t isolate_offset() { |
| 46 return OFFSET_OF(NativeArguments, isolate_); |
| 47 } |
43 static intptr_t argc_offset() { return OFFSET_OF(NativeArguments, argc_); } | 48 static intptr_t argc_offset() { return OFFSET_OF(NativeArguments, argc_); } |
44 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } | 49 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } |
45 static intptr_t retval_offset() { | 50 static intptr_t retval_offset() { |
46 return OFFSET_OF(NativeArguments, retval_); | 51 return OFFSET_OF(NativeArguments, retval_); |
47 } | 52 } |
48 | 53 |
49 private: | 54 private: |
| 55 Isolate* isolate_; // Current isolate pointer. |
50 int argc_; // Number of arguments passed to the runtime call. | 56 int argc_; // Number of arguments passed to the runtime call. |
51 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. | 57 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. |
52 RawObject** retval_; // Pointer to the return value area. | 58 RawObject** retval_; // Pointer to the return value area. |
53 }; | 59 }; |
54 | 60 |
55 } // namespace dart | 61 } // namespace dart |
56 | 62 |
57 #endif // VM_NATIVE_ARGUMENTS_H_ | 63 #endif // VM_NATIVE_ARGUMENTS_H_ |
OLD | NEW |