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/handles_impl.h" | 10 #include "vm/handles_impl.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 static intptr_t isolate_offset() { | 124 static intptr_t isolate_offset() { |
125 return OFFSET_OF(NativeArguments, isolate_); | 125 return OFFSET_OF(NativeArguments, isolate_); |
126 } | 126 } |
127 static intptr_t argc_tag_offset() { | 127 static intptr_t argc_tag_offset() { |
128 return OFFSET_OF(NativeArguments, argc_tag_); | 128 return OFFSET_OF(NativeArguments, argc_tag_); |
129 } | 129 } |
130 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } | 130 static intptr_t argv_offset() { return OFFSET_OF(NativeArguments, argv_); } |
131 static intptr_t retval_offset() { | 131 static intptr_t retval_offset() { |
132 return OFFSET_OF(NativeArguments, retval_); | 132 return OFFSET_OF(NativeArguments, retval_); |
133 } | 133 } |
| 134 static intptr_t AutoSetupScopeMask() { |
| 135 return AutoSetupScopeBits::mask_in_place(); |
| 136 } |
134 | 137 |
135 static int ParameterCountForResolution(const Function& function) { | 138 static int ParameterCountForResolution(const Function& function) { |
136 ASSERT(function.is_native()); | 139 ASSERT(function.is_native()); |
137 ASSERT(!function.IsConstructor()); // Not supported. | 140 ASSERT(!function.IsConstructor()); // Not supported. |
138 int count = function.NumParameters(); | 141 int count = function.NumParameters(); |
139 if (function.is_static() && function.IsClosureFunction()) { | 142 if (function.is_static() && function.IsClosureFunction()) { |
140 // The closure object is hidden and not accessible from native code. | 143 // The closure object is hidden and not accessible from native code. |
141 // However, if the function is an instance closure function, the captured | 144 // However, if the function is an instance closure function, the captured |
142 // receiver located in the context is made accessible in native code at | 145 // receiver located in the context is made accessible in native code at |
143 // index 0, thereby hidding the closure object at index 0. | 146 // index 0, thereby hidding the closure object at index 0. |
144 count--; | 147 count--; |
145 } | 148 } |
146 return count; | 149 return count; |
147 } | 150 } |
148 | 151 |
149 static int ComputeArgcTag(const Function& function) { | 152 static int ComputeArgcTag(const Function& function) { |
150 ASSERT(function.is_native()); | 153 ASSERT(function.is_native()); |
151 ASSERT(!function.IsConstructor()); // Not supported. | 154 ASSERT(!function.IsConstructor()); // Not supported. |
152 int tag = ArgcBits::encode(function.NumParameters()); | 155 int tag = ArgcBits::encode(function.NumParameters()); |
153 int function_bits = 0; | 156 int function_bits = 0; |
154 if (!function.is_static()) { | 157 if (!function.is_static()) { |
155 function_bits |= kInstanceFunctionBit; | 158 function_bits |= kInstanceFunctionBit; |
156 } | 159 } |
157 if (function.IsClosureFunction()) { | 160 if (function.IsClosureFunction()) { |
158 function_bits |= kClosureFunctionBit; | 161 function_bits |= kClosureFunctionBit; |
159 } | 162 } |
160 return FunctionBits::update(function_bits, tag); | 163 tag = FunctionBits::update(function_bits, tag); |
| 164 if (function.IsNativeAutoSetupScope()) { |
| 165 tag = AutoSetupScopeBits::update(1, tag); |
| 166 } |
| 167 return tag; |
161 } | 168 } |
162 | 169 |
163 private: | 170 private: |
164 enum { | 171 enum { |
165 kInstanceFunctionBit = 1, | 172 kInstanceFunctionBit = 1, |
166 kClosureFunctionBit = 2, | 173 kClosureFunctionBit = 2, |
167 }; | 174 }; |
168 enum ArgcTagBits { | 175 enum ArgcTagBits { |
169 kArgcBit = 0, | 176 kArgcBit = 0, |
170 kArgcSize = 24, | 177 kArgcSize = 24, |
171 kFunctionBit = 24, | 178 kFunctionBit = 24, |
172 kFunctionSize = 2, | 179 kFunctionSize = 2, |
| 180 kAutoSetupScopeBit = 26, |
173 }; | 181 }; |
174 class ArgcBits : public BitField<int, kArgcBit, kArgcSize> {}; | 182 class ArgcBits : public BitField<int, kArgcBit, kArgcSize> {}; |
175 class FunctionBits : public BitField<int, kFunctionBit, kFunctionSize> {}; | 183 class FunctionBits : public BitField<int, kFunctionBit, kFunctionSize> {}; |
| 184 class AutoSetupScopeBits : public BitField<int, kAutoSetupScopeBit, 1> {}; |
176 friend class Api; | 185 friend class Api; |
177 friend class BootstrapNatives; | 186 friend class BootstrapNatives; |
178 friend class Simulator; | 187 friend class Simulator; |
179 | 188 |
180 // Since this function is passed a RawObject directly, we need to be | 189 // Since this function is passed a RawObject directly, we need to be |
181 // exceedingly careful when we use it. If there are any other side | 190 // exceedingly careful when we use it. If there are any other side |
182 // effects in the statement that may cause GC, it could lead to | 191 // effects in the statement that may cause GC, it could lead to |
183 // bugs. | 192 // bugs. |
184 void SetReturnUnsafe(RawObject* value) const { | 193 void SetReturnUnsafe(RawObject* value) const { |
185 *retval_ = value; | 194 *retval_ = value; |
(...skipping 22 matching lines...) Expand all Loading... |
208 | 217 |
209 Isolate* isolate_; // Current isolate pointer. | 218 Isolate* isolate_; // Current isolate pointer. |
210 int argc_tag_; // Encodes argument count and invoked native call type. | 219 int argc_tag_; // Encodes argument count and invoked native call type. |
211 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. | 220 RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. |
212 RawObject** retval_; // Pointer to the return value area. | 221 RawObject** retval_; // Pointer to the return value area. |
213 }; | 222 }; |
214 | 223 |
215 } // namespace dart | 224 } // namespace dart |
216 | 225 |
217 #endif // VM_NATIVE_ARGUMENTS_H_ | 226 #endif // VM_NATIVE_ARGUMENTS_H_ |
OLD | NEW |