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 #include "vm/native_entry.h" | 5 #include "vm/native_entry.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 state->set_reusable_scope(scope); | 122 state->set_reusable_scope(scope); |
123 } else { | 123 } else { |
124 ASSERT(state->reusable_scope() != scope); | 124 ASSERT(state->reusable_scope() != scope); |
125 delete scope; | 125 delete scope; |
126 } | 126 } |
127 DEOPTIMIZE_ALOT; | 127 DEOPTIMIZE_ALOT; |
128 VERIFY_ON_TRANSITION; | 128 VERIFY_ON_TRANSITION; |
129 } | 129 } |
130 | 130 |
131 | 131 |
132 static bool IsNativeKeyword(const TokenStream::Iterator& it) { | |
133 return Token::IsIdentifier(it.CurrentTokenKind()) && | |
134 (it.CurrentLiteral() == Symbols::Native().raw()); | |
135 } | |
136 | |
137 | |
138 static NativeFunction ResolveNativeFunction(Zone* zone, | 132 static NativeFunction ResolveNativeFunction(Zone* zone, |
139 const Function& func, | 133 const Function& func, |
140 bool* is_bootstrap_native) { | 134 bool* is_bootstrap_native) { |
141 const Script& script = Script::Handle(zone, func.script()); | |
142 const Class& cls = Class::Handle(zone, func.Owner()); | 135 const Class& cls = Class::Handle(zone, func.Owner()); |
143 const Library& library = Library::Handle(zone, cls.library()); | 136 const Library& library = Library::Handle(zone, cls.library()); |
144 | 137 |
145 *is_bootstrap_native = | 138 *is_bootstrap_native = |
146 Bootstrap::IsBootstapResolver(library.native_entry_resolver()); | 139 Bootstrap::IsBootstapResolver(library.native_entry_resolver()); |
147 | 140 |
148 TokenStream::Iterator it(TokenStream::Handle(zone, script.tokens()), | 141 const String& native_name = String::Handle(zone, func.native_name()); |
149 func.token_pos()); | 142 ASSERT(!native_name.IsNull()); |
150 | |
151 const intptr_t end_pos = func.end_token_pos(); | |
152 while (!IsNativeKeyword(it) && it.CurrentPosition() <= end_pos) { | |
153 it.Advance(); | |
154 } | |
155 ASSERT(IsNativeKeyword(it)); | |
156 it.Advance(); | |
157 ASSERT(it.CurrentTokenKind() == Token::kSTRING); | |
158 const String& native_name = String::Handle(it.CurrentLiteral()); | |
159 | 143 |
160 const int num_params = NativeArguments::ParameterCountForResolution(func); | 144 const int num_params = NativeArguments::ParameterCountForResolution(func); |
161 bool auto_setup_scope = true; | 145 bool auto_setup_scope = true; |
162 return NativeEntry::ResolveNative( | 146 return NativeEntry::ResolveNative( |
163 library, native_name, num_params, &auto_setup_scope); | 147 library, native_name, num_params, &auto_setup_scope); |
164 } | 148 } |
165 | 149 |
166 | 150 |
167 uword NativeEntry::LinkNativeCallEntry() { | 151 uword NativeEntry::LinkNativeCallEntry() { |
168 uword entry = reinterpret_cast<uword>(NativeEntry::LinkNativeCall); | 152 uword entry = reinterpret_cast<uword>(NativeEntry::LinkNativeCall); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (call_through_wrapper) { | 252 if (call_through_wrapper) { |
269 NativeEntry::NativeCallWrapper( | 253 NativeEntry::NativeCallWrapper( |
270 args, reinterpret_cast<Dart_NativeFunction>(target_function)); | 254 args, reinterpret_cast<Dart_NativeFunction>(target_function)); |
271 } else { | 255 } else { |
272 target_function(arguments); | 256 target_function(arguments); |
273 } | 257 } |
274 } | 258 } |
275 | 259 |
276 | 260 |
277 } // namespace dart | 261 } // namespace dart |
OLD | NEW |