Chromium Code Reviews| 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 #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 "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/stub_code.h" | 10 #include "vm/stub_code.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #else | 36 #else |
| 37 | 37 |
| 38 #define CHECK_STACK_ALIGNMENT { } | 38 #define CHECK_STACK_ALIGNMENT { } |
| 39 | 39 |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 void SetReturnValueHelper(Dart_NativeArguments, Dart_Handle); | 42 void SetReturnValueHelper(Dart_NativeArguments, Dart_Handle); |
| 43 | 43 |
| 44 | |
| 44 // Class NativeArguments is used to access arguments passed in from | 45 // Class NativeArguments is used to access arguments passed in from |
| 45 // generated dart code to a runtime function or a dart library native | 46 // generated dart code to a runtime function or a dart library native |
| 46 // function. It is also used to set the return value if any at the slot | 47 // function. It is also used to set the return value if any at the slot |
| 47 // reserved for return values. | 48 // reserved for return values. |
| 48 // All runtime function/dart library native functions have the | 49 // All runtime function/dart library native functions have the |
| 49 // following signature: | 50 // following signature: |
| 50 // void function_name(NativeArguments arguments); | 51 // void function_name(NativeArguments arguments); |
| 51 // Inside the function, arguments are accessed as follows: | 52 // Inside the function, arguments are accessed as follows: |
| 52 // const Type& arg1 = Type::CheckedHandle(arguments.GetArgument(0)); | 53 // const Instance& arg0 = Instance::CheckedHandle(arguments.At(0)); |
| 53 // const Type& arg2 = Type::CheckedHandle(arguments.GetArgument(1)); | 54 // const Smi& arg1 = Smi::CheckedHandle(arguments.At(1)); |
| 54 // The return value is set as follows: | 55 // The return value is set as follows: |
| 55 // arguments.SetReturn(result); | 56 // arguments.SetReturn(result); |
| 56 // NOTE: Since we pass this as a pass by value argument in the stubs we don't | 57 // NOTE: Since we pass 'this' as a pass-by-value argument in the stubs we don't |
| 57 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a | 58 // have DISALLOW_COPY_AND_ASSIGN in the class definition and do not make it a |
| 58 // subclass of ValueObject. | 59 // subclass of ValueObject. |
| 59 class NativeArguments { | 60 class NativeArguments { |
| 60 public: | 61 public: |
| 61 Isolate* isolate() const { return isolate_; } | 62 Isolate* isolate() const { return isolate_; } |
| 62 int Count() const { return argc_; } | 63 int Count() const { return ArgcBits::decode(argc_tag_); } |
| 64 | |
| 65 // Returns true if the arguments are those of an instance function call. | |
| 66 bool AreOfInstanceFunction() const { | |
|
siva
2012/11/07 18:56:32
I find the name AreOfInstanceFunction() a bit hard
regis
2012/11/08 18:08:30
Done.
| |
| 67 return InstanceFunctionBit::decode(argc_tag_); | |
| 68 } | |
| 69 | |
| 70 // Returns true if the arguments are those of a closure function call. | |
| 71 bool AreOfClosureFunction() const { | |
| 72 return ClosureFunctionBit::decode(argc_tag_); | |
| 73 } | |
| 63 | 74 |
| 64 RawObject* At(int index) const { | 75 RawObject* At(int index) const { |
| 65 ASSERT(index >=0 && index < argc_); | 76 ASSERT(index >=0 && index < Count()); |
| 66 return (*argv_)[-index]; | 77 return (*argv_)[-index]; |
| 67 } | 78 } |
| 68 | 79 |
| 69 void SetReturn(const Object& value) const; | 80 void SetReturn(const Object& value) const; |
| 70 | 81 |
| 71 static intptr_t isolate_offset() { | 82 static intptr_t isolate_offset() { |
| 72 return OFFSET_OF(NativeArguments, isolate_); | 83 return OFFSET_OF(NativeArguments, isolate_); |
| 73 } | 84 } |
| 74 static intptr_t argc_offset() { return OFFSET_OF(NativeArguments, argc_); } | 85 static intptr_t argc_tag_offset() { |
| 86 return OFFSET_OF(NativeArguments, argc_tag_); | |
| 87 } | |
| 75 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } | 88 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } |
| 76 static intptr_t retval_offset() { | 89 static intptr_t retval_offset() { |
| 77 return OFFSET_OF(NativeArguments, retval_); | 90 return OFFSET_OF(NativeArguments, retval_); |
| 78 } | 91 } |
| 79 | 92 |
| 93 static int ParameterCountForResolution(const Function& function) { | |
| 94 ASSERT(function.is_native()); | |
| 95 ASSERT(!function.IsConstructor()); // Not supported. | |
| 96 int count = function.NumParameters(); | |
| 97 if (!function.is_static() && function.IsClosureFunction()) { | |
| 98 // The closure object is hidden and not accessible from native code. | |
| 99 // However, if the function is an instance closure function, the captured | |
| 100 // receiver located in the context is made accessible in native code at | |
| 101 // index 0, thereby hidding the closure object at index 0. | |
| 102 count--; | |
|
siva
2012/11/07 18:56:32
I am a little confused by this.
If a function is s
regis
2012/11/08 18:08:30
Oops. I do not know where the ! is coming from. Go
| |
| 103 } | |
| 104 return count; | |
| 105 } | |
| 106 | |
| 107 static int ComputeArgcTag(const Function& function) { | |
| 108 ASSERT(function.is_native()); | |
| 109 ASSERT(!function.IsConstructor()); // Not supported. | |
| 110 int tag = ArgcBits::encode(function.NumParameters()); | |
| 111 tag = InstanceFunctionBit::update(!function.is_static(), tag); | |
| 112 tag = ClosureFunctionBit::update(function.IsClosureFunction(), tag); | |
| 113 return tag; | |
| 114 } | |
| 115 | |
| 80 private: | 116 private: |
| 117 enum ArgcTagBits { | |
| 118 kArgcBit = 0, | |
| 119 kArgcSize = 24, | |
| 120 kInstanceFunctionBit = 24, | |
| 121 kClosureFunctionBit = 25, | |
| 122 }; | |
| 123 class ArgcBits : public BitField<int, kArgcBit, kArgcSize> {}; | |
| 124 class InstanceFunctionBit : public BitField<bool, kInstanceFunctionBit, 1> {}; | |
| 125 class ClosureFunctionBit : public BitField<bool, kClosureFunctionBit, 1> {}; | |
| 81 friend class BootstrapNatives; | 126 friend class BootstrapNatives; |
| 82 friend void SetReturnValueHelper(Dart_NativeArguments, Dart_Handle); | 127 friend void SetReturnValueHelper(Dart_NativeArguments, Dart_Handle); |
| 83 | 128 |
| 84 // Since this function is passed a RawObject directly, we need to be | 129 // Since this function is passed a RawObject directly, we need to be |
| 85 // exceedingly careful when we use it. If there are any other side | 130 // exceedingly careful when we use it. If there are any other side |
| 86 // effects in the statement that may cause GC, it could lead to | 131 // effects in the statement that may cause GC, it could lead to |
| 87 // bugs. | 132 // bugs. |
| 88 void SetReturnUnsafe(RawObject* value) const; | 133 void SetReturnUnsafe(RawObject* value) const; |
| 89 | 134 |
| 90 Isolate* isolate_; // Current isolate pointer. | 135 Isolate* isolate_; // Current isolate pointer. |
| 91 int argc_; // Number of arguments passed to the runtime call. | 136 int argc_tag_; // Encodes argument count and argument location. |
|
siva
2012/11/07 18:56:32
// Encodes argument count and argument location.
regis
2012/11/08 18:08:30
Done.
| |
| 92 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. | 137 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. |
| 93 RawObject** retval_; // Pointer to the return value area. | 138 RawObject** retval_; // Pointer to the return value area. |
| 94 }; | 139 }; |
| 95 | 140 |
| 96 } // namespace dart | 141 } // namespace dart |
| 97 | 142 |
| 98 #endif // VM_NATIVE_ARGUMENTS_H_ | 143 #endif // VM_NATIVE_ARGUMENTS_H_ |
| OLD | NEW |