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

Side by Side Diff: vm/dart_entry.cc

Issue 11613009: Changed the API in DartEntry for invoking dart code from C++ to make it more compatible with the re… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years 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 #include "vm/dart_entry.h" 5 #include "vm/dart_entry.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/resolver.h" 10 #include "vm/resolver.h"
11 #include "vm/stub_code.h" 11 #include "vm/stub_code.h"
12 #include "vm/symbols.h" 12 #include "vm/symbols.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 RawObject* DartEntry::InvokeDynamic( 16 RawObject* DartEntry::InvokeDynamic(const Function& function,
17 const Instance& receiver, 17 const Array& arguments) {
18 const Function& function, 18 const Array& arg_desc =
19 const GrowableArray<const Object*>& arguments, 19 Array::Handle(ArgumentsDescriptor::New(arguments.Length()));
20 const Array& optional_arguments_names) { 20 return InvokeDynamic(function, arguments, arg_desc);
21 }
22
23
24 RawObject* DartEntry::InvokeDynamic(const Function& function,
25 const Array& arguments,
26 const Array& arg_descriptor) {
21 // Get the entrypoint corresponding to the function specified, this 27 // Get the entrypoint corresponding to the function specified, this
22 // will result in a compilation of the function if it is not already 28 // will result in a compilation of the function if it is not already
23 // compiled. 29 // compiled.
24 if (!function.HasCode()) { 30 if (!function.HasCode()) {
25 const Error& error = Error::Handle(Compiler::CompileFunction(function)); 31 const Error& error = Error::Handle(Compiler::CompileFunction(function));
26 if (!error.IsNull()) { 32 if (!error.IsNull()) {
27 return error.raw(); 33 return error.raw();
28 } 34 }
29 } 35 }
30 36
31 // Set up arguments to include the receiver as the first argument.
32 const int num_arguments = arguments.length() + 1;
33 GrowableArray<const Object*> args(num_arguments);
34 const Object& arg0 = Object::ZoneHandle(receiver.raw());
35 args.Add(&arg0);
36 for (int i = 1; i < num_arguments; i++) {
37 args.Add(arguments[i - 1]);
38 }
39 // Now Call the invoke stub which will invoke the dart function. 37 // Now Call the invoke stub which will invoke the dart function.
40 invokestub entrypoint = reinterpret_cast<invokestub>( 38 invokestub entrypoint = reinterpret_cast<invokestub>(
41 StubCode::InvokeDartCodeEntryPoint()); 39 StubCode::InvokeDartCodeEntryPoint());
42 const Context& context = 40 const Context& context =
43 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); 41 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context());
44 ASSERT(context.isolate() == Isolate::Current()); 42 ASSERT(context.isolate() == Isolate::Current());
45 const Code& code = Code::Handle(function.CurrentCode()); 43 const Code& code = Code::Handle(function.CurrentCode());
46 ASSERT(!code.IsNull()); 44 ASSERT(!code.IsNull());
47 const Array& arg_descriptor = 45 return entrypoint(code.EntryPoint(), arg_descriptor, arguments, context);
48 Array::Handle(ArgumentsDescriptor::New(num_arguments,
49 optional_arguments_names));
50 return entrypoint(code.EntryPoint(), arg_descriptor, args.data(), context);
51 } 46 }
52 47
53 48
54 RawObject* DartEntry::InvokeStatic( 49 RawObject* DartEntry::InvokeStatic(const Function& function,
55 const Function& function, 50 const Array& arguments) {
56 const GrowableArray<const Object*>& arguments, 51 const Array& arg_desc =
57 const Array& optional_arguments_names) { 52 Array::Handle(ArgumentsDescriptor::New(arguments.Length()));
53 return InvokeStatic(function, arguments, arg_desc);
54 }
55
56
57 RawObject* DartEntry::InvokeStatic(const Function& function,
58 const Array& arguments,
59 const Array& arg_descriptor) {
58 // Get the entrypoint corresponding to the function specified, this 60 // Get the entrypoint corresponding to the function specified, this
59 // will result in a compilation of the function if it is not already 61 // will result in a compilation of the function if it is not already
60 // compiled. 62 // compiled.
61 ASSERT(!function.IsNull()); 63 ASSERT(!function.IsNull());
62 if (!function.HasCode()) { 64 if (!function.HasCode()) {
63 const Error& error = Error::Handle(Compiler::CompileFunction(function)); 65 const Error& error = Error::Handle(Compiler::CompileFunction(function));
64 if (!error.IsNull()) { 66 if (!error.IsNull()) {
65 return error.raw(); 67 return error.raw();
66 } 68 }
67 } 69 }
68 // Now Call the invoke stub which will invoke the dart function. 70 // Now Call the invoke stub which will invoke the dart function.
69 invokestub entrypoint = reinterpret_cast<invokestub>( 71 invokestub entrypoint = reinterpret_cast<invokestub>(
70 StubCode::InvokeDartCodeEntryPoint()); 72 StubCode::InvokeDartCodeEntryPoint());
71 const Context& context = 73 const Context& context =
72 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context()); 74 Context::ZoneHandle(Isolate::Current()->object_store()->empty_context());
73 ASSERT(context.isolate() == Isolate::Current()); 75 ASSERT(context.isolate() == Isolate::Current());
74 const Code& code = Code::Handle(function.CurrentCode()); 76 const Code& code = Code::Handle(function.CurrentCode());
75 ASSERT(!code.IsNull()); 77 ASSERT(!code.IsNull());
76 const Array& arg_descriptor = 78 return entrypoint(code.EntryPoint(), arg_descriptor, arguments, context);
77 Array::Handle(ArgumentsDescriptor::New(arguments.length(),
78 optional_arguments_names));
79 return entrypoint(code.EntryPoint(), arg_descriptor, arguments.data(),
80 context);
81 } 79 }
82 80
83 81
84 // TODO(regis): Pass arguments as an Array including the receiver. 82 RawObject* DartEntry::InvokeClosure(const Instance& closure,
85 RawObject* DartEntry::InvokeClosure( 83 const Array& arguments) {
86 const Instance& instance, 84 const Array& arg_desc =
87 const GrowableArray<const Object*>& arguments, 85 Array::Handle(ArgumentsDescriptor::New(arguments.Length()));
88 const Array& optional_arguments_names) { 86 return InvokeClosure(closure, arguments, arg_desc);
87 }
88
89
90 RawObject* DartEntry::InvokeClosure(const Instance& instance,
91 const Array& arguments,
92 const Array& arg_descriptor) {
93 ASSERT(instance.raw() == arguments.At(0));
89 // Get the entrypoint corresponding to the closure function or to the call 94 // Get the entrypoint corresponding to the closure function or to the call
90 // method of the instance. This will result in a compilation of the function 95 // method of the instance. This will result in a compilation of the function
91 // if it is not already compiled. 96 // if it is not already compiled.
92 Function& function = Function::Handle(); 97 Function& function = Function::Handle();
93 Context& context = Context::Handle(); 98 Context& context = Context::Handle();
94 if (!instance.IsCallable(&function, &context)) { 99 if (!instance.IsCallable(&function, &context)) {
95 // Set up arguments to include the receiver as the first argument. 100 // Set up arguments to include the receiver as the first argument.
96 const int num_arguments = arguments.length() + 1;
97 const Array& args = Array::Handle(Array::New(num_arguments));
98 args.SetAt(0, instance);
99 for (int i = 1; i < num_arguments; i++) {
100 args.SetAt(i, *arguments[i - 1]);
101 }
102 const String& call_symbol = String::Handle(Symbols::Call()); 101 const String& call_symbol = String::Handle(Symbols::Call());
103 const Object& null_object = Object::Handle(); 102 const Object& null_object = Object::Handle();
104 GrowableArray<const Object*> dart_arguments(5); 103 GrowableArray<const Object*> dart_arguments(5);
105 dart_arguments.Add(&instance); 104 dart_arguments.Add(&instance);
106 dart_arguments.Add(&call_symbol); 105 dart_arguments.Add(&call_symbol);
107 dart_arguments.Add(&args); // Including instance. 106 dart_arguments.Add(&arguments); // Includes instance.
108 dart_arguments.Add(&null_object); // TODO(regis): Provide names. 107 dart_arguments.Add(&null_object); // TODO(regis): Provide names.
109 // If a function "call" with different arguments exists, it will have been 108 // If a function "call" with different arguments exists, it will have been
110 // invoked above, so no need to handle this case here. 109 // invoked above, so no need to handle this case here.
111 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); 110 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments);
112 UNREACHABLE(); 111 UNREACHABLE();
113 return Object::null(); 112 return Object::null();
114 } 113 }
115 ASSERT(!function.IsNull()); 114 ASSERT(!function.IsNull());
116 if (!function.HasCode()) { 115 if (!function.HasCode()) {
117 const Error& error = Error::Handle(Compiler::CompileFunction(function)); 116 const Error& error = Error::Handle(Compiler::CompileFunction(function));
118 if (!error.IsNull()) { 117 if (!error.IsNull()) {
119 return error.raw(); 118 return error.raw();
120 } 119 }
121 } 120 }
122 // Set up arguments to include the receiver as the first argument.
123 const int num_arguments = arguments.length() + 1;
124 GrowableArray<const Object*> args(num_arguments);
125 const Object& arg0 = Object::ZoneHandle(instance.raw());
126 args.Add(&arg0);
127 for (int i = 1; i < num_arguments; i++) {
128 args.Add(arguments[i - 1]);
129 }
130 // Now call the invoke stub which will invoke the closure. 121 // Now call the invoke stub which will invoke the closure.
131 invokestub entrypoint = reinterpret_cast<invokestub>( 122 invokestub entrypoint = reinterpret_cast<invokestub>(
132 StubCode::InvokeDartCodeEntryPoint()); 123 StubCode::InvokeDartCodeEntryPoint());
133 ASSERT(context.isolate() == Isolate::Current()); 124 ASSERT(context.isolate() == Isolate::Current());
134 const Code& code = Code::Handle(function.CurrentCode()); 125 const Code& code = Code::Handle(function.CurrentCode());
135 ASSERT(!code.IsNull()); 126 ASSERT(!code.IsNull());
136 const Array& arg_descriptor = 127 return entrypoint(code.EntryPoint(), arg_descriptor, arguments, context);
137 Array::Handle(ArgumentsDescriptor::New(num_arguments,
138 optional_arguments_names));
139 return entrypoint(code.EntryPoint(), arg_descriptor, args.data(), context);
140 } 128 }
141 129
142 130
143 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) 131 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array)
144 : array_(array) { 132 : array_(array) {
145 } 133 }
146 134
147 135
148 intptr_t ArgumentsDescriptor::Count() const { 136 intptr_t ArgumentsDescriptor::Count() const {
149 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); 137 return Smi::CheckedHandle(array_.At(kCountIndex)).Value();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // Set terminating null. 212 // Set terminating null.
225 descriptor.SetAt(descriptor_len - 1, Object::Handle()); 213 descriptor.SetAt(descriptor_len - 1, Object::Handle());
226 214
227 // Share the immutable descriptor when possible by canonicalizing it. 215 // Share the immutable descriptor when possible by canonicalizing it.
228 descriptor.MakeImmutable(); 216 descriptor.MakeImmutable();
229 descriptor ^= descriptor.Canonicalize(); 217 descriptor ^= descriptor.Canonicalize();
230 return descriptor.raw(); 218 return descriptor.raw();
231 } 219 }
232 220
233 221
222 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) {
223 // Build the arguments descriptor array, which consists of the total
224 // argument count; the positional argument count; and
225 // a terminating null to simplify iterating in generated code.
226 const intptr_t descriptor_len = LengthFor(0);
227 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld));
228 const Smi& arg_count = Smi::Handle(Smi::New(num_arguments));
229
230 // Set total number of passed arguments.
231 descriptor.SetAt(kCountIndex, arg_count);
232
233 // Set number of positional arguments.
234 descriptor.SetAt(kPositionalCountIndex, arg_count);
235
236 // Set terminating null.
237 descriptor.SetAt((descriptor_len - 1), Object::Handle());
238
239 // Share the immutable descriptor when possible by canonicalizing it.
240 descriptor.MakeImmutable();
241 descriptor ^= descriptor.Canonicalize();
242 return descriptor.raw();
243 }
244
245
234 RawObject* DartLibraryCalls::ExceptionCreate( 246 RawObject* DartLibraryCalls::ExceptionCreate(
235 const Library& lib, 247 const Library& lib,
236 const String& class_name, 248 const String& class_name,
237 const GrowableArray<const Object*>& arguments) { 249 const GrowableArray<const Object*>& arguments) {
238 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name)); 250 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name));
239 ASSERT(!cls.IsNull()); 251 ASSERT(!cls.IsNull());
240 // For now, we only support a non-parameterized or raw type. 252 // For now, we only support a non-parameterized or raw type.
253 const int kNumExtraArgs = 2; // implicit rcvr and construction phase args.
241 const Instance& exception_object = Instance::Handle(Instance::New(cls)); 254 const Instance& exception_object = Instance::Handle(Instance::New(cls));
242 GrowableArray<const Object*> constructor_arguments(arguments.length() + 2); 255 const Array& constructor_arguments =
243 constructor_arguments.Add(&exception_object); 256 Array::Handle(Array::New(arguments.length() + kNumExtraArgs));
244 constructor_arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll))); 257 constructor_arguments.SetAt(0, exception_object);
245 constructor_arguments.AddArray(arguments); 258 constructor_arguments.SetAt(
259 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
260 for (intptr_t i = 0; i < arguments.length(); i++) {
261 constructor_arguments.SetAt((i + kNumExtraArgs), *(arguments[i]));
262 }
246 263
247 String& constructor_name = String::Handle( 264 String& constructor_name = String::Handle(
248 String::Concat(class_name, Symbols::DotHandle())); 265 String::Concat(class_name, Symbols::DotHandle()));
249 Function& constructor = 266 Function& constructor =
250 Function::Handle(cls.LookupConstructor(constructor_name)); 267 Function::Handle(cls.LookupConstructor(constructor_name));
251 ASSERT(!constructor.IsNull()); 268 ASSERT(!constructor.IsNull());
252 const Array& kNoArgumentNames = Array::Handle(); 269 const Object& retval =
253 const Object& retval = Object::Handle( 270 Object::Handle(DartEntry::InvokeStatic(constructor, constructor_arguments));
254 DartEntry::InvokeStatic(constructor, constructor_arguments,
255 kNoArgumentNames));
256 ASSERT(retval.IsNull() || retval.IsError()); 271 ASSERT(retval.IsNull() || retval.IsError());
257 if (retval.IsError()) { 272 if (retval.IsError()) {
258 return retval.raw(); 273 return retval.raw();
259 } 274 }
260 return exception_object.raw(); 275 return exception_object.raw();
261 } 276 }
262 277
263 278
264 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { 279 RawObject* DartLibraryCalls::ToString(const Instance& receiver) {
265 const String& function_name = 280 const String& function_name =
266 String::Handle(Symbols::New("toString")); 281 String::Handle(Symbols::New("toString"));
267 GrowableArray<const Object*> arguments;
268 const int kNumArguments = 1; // Receiver. 282 const int kNumArguments = 1; // Receiver.
269 const int kNumNamedArguments = 0; // None. 283 const int kNumNamedArguments = 0; // None.
270 const Array& kNoArgumentNames = Array::Handle();
271 const Function& function = Function::Handle( 284 const Function& function = Function::Handle(
272 Resolver::ResolveDynamic(receiver, 285 Resolver::ResolveDynamic(receiver,
273 function_name, 286 function_name,
274 kNumArguments, 287 kNumArguments,
275 kNumNamedArguments)); 288 kNumNamedArguments));
276 ASSERT(!function.IsNull()); 289 ASSERT(!function.IsNull());
277 const Object& result = Object::Handle( 290 const Array& args = Array::Handle(Array::New(kNumArguments));
278 DartEntry::InvokeDynamic(receiver, 291 args.SetAt(0, receiver);
279 function, 292 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function,
280 arguments, 293 args));
281 kNoArgumentNames));
282 ASSERT(result.IsInstance() || result.IsError()); 294 ASSERT(result.IsInstance() || result.IsError());
283 return result.raw(); 295 return result.raw();
284 } 296 }
285 297
286 298
287 RawObject* DartLibraryCalls::Equals(const Instance& left, 299 RawObject* DartLibraryCalls::Equals(const Instance& left,
288 const Instance& right) { 300 const Instance& right) {
289 GrowableArray<const Object*> arguments;
290 arguments.Add(&right);
291 const int kNumArguments = 2; 301 const int kNumArguments = 2;
292 const int kNumNamedArguments = 0; 302 const int kNumNamedArguments = 0;
293 const Array& kNoArgumentNames = Array::Handle();
294 const Function& function = Function::Handle( 303 const Function& function = Function::Handle(
295 Resolver::ResolveDynamic(left, 304 Resolver::ResolveDynamic(left,
296 Symbols::EqualOperatorHandle(), 305 Symbols::EqualOperatorHandle(),
297 kNumArguments, 306 kNumArguments,
298 kNumNamedArguments)); 307 kNumNamedArguments));
299 ASSERT(!function.IsNull()); 308 ASSERT(!function.IsNull());
300 const Object& result = Object::Handle( 309
301 DartEntry::InvokeDynamic(left, function, arguments, kNoArgumentNames)); 310 const Array& args = Array::Handle(Array::New(kNumArguments));
311 args.SetAt(0, left);
312 args.SetAt(1, right);
313 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function,
314 args));
302 ASSERT(result.IsInstance() || result.IsError()); 315 ASSERT(result.IsInstance() || result.IsError());
303 return result.raw(); 316 return result.raw();
304 } 317 }
305 318
306 319
307 RawObject* DartLibraryCalls::HandleMessage(Dart_Port dest_port_id, 320 RawObject* DartLibraryCalls::HandleMessage(Dart_Port dest_port_id,
308 Dart_Port reply_port_id, 321 Dart_Port reply_port_id,
309 const Instance& message) { 322 const Instance& message) {
310 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); 323 Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
311 ASSERT(!isolate_lib.IsNull()); 324 ASSERT(!isolate_lib.IsNull());
312 const String& public_class_name = 325 const String& public_class_name =
313 String::Handle(Symbols::New("_ReceivePortImpl")); 326 String::Handle(Symbols::New("_ReceivePortImpl"));
314 const String& class_name = 327 const String& class_name =
315 String::Handle(isolate_lib.PrivateName(public_class_name)); 328 String::Handle(isolate_lib.PrivateName(public_class_name));
316 const String& function_name = 329 const String& function_name =
317 String::Handle(Symbols::New("_handleMessage")); 330 String::Handle(Symbols::New("_handleMessage"));
318 const int kNumArguments = 3; 331 const int kNumArguments = 3;
319 const Array& kNoArgumentNames = Array::Handle(); 332 const Array& kNoArgumentNames = Array::Handle();
320 const Function& function = Function::Handle( 333 const Function& function = Function::Handle(
321 Resolver::ResolveStatic(isolate_lib, 334 Resolver::ResolveStatic(isolate_lib,
322 class_name, 335 class_name,
323 function_name, 336 function_name,
324 kNumArguments, 337 kNumArguments,
325 kNoArgumentNames, 338 kNoArgumentNames,
326 Resolver::kIsQualified)); 339 Resolver::kIsQualified));
327 GrowableArray<const Object*> arguments(kNumArguments); 340 const Array& args = Array::Handle(Array::New(kNumArguments));
328 arguments.Add(&Integer::Handle(Integer::New(dest_port_id))); 341 args.SetAt(0, Integer::Handle(Integer::New(dest_port_id)));
329 arguments.Add(&Integer::Handle(Integer::New(reply_port_id))); 342 args.SetAt(1, Integer::Handle(Integer::New(reply_port_id)));
330 arguments.Add(&message); 343 args.SetAt(2, message);
331 const Object& result = Object::Handle( 344 const Object& result = Object::Handle(DartEntry::InvokeStatic(function,
332 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); 345 args));
333 ASSERT(result.IsNull() || result.IsError()); 346 ASSERT(result.IsNull() || result.IsError());
334 return result.raw(); 347 return result.raw();
335 } 348 }
336 349
337 350
338 RawObject* DartLibraryCalls::NewSendPort(intptr_t port_id) { 351 RawObject* DartLibraryCalls::NewSendPort(intptr_t port_id) {
339 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); 352 Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
340 ASSERT(!isolate_lib.IsNull()); 353 ASSERT(!isolate_lib.IsNull());
341 const String& public_class_name = 354 const String& public_class_name =
342 String::Handle(String::New("_SendPortImpl")); 355 String::Handle(String::New("_SendPortImpl"));
343 const String& class_name = 356 const String& class_name =
344 String::Handle(isolate_lib.PrivateName(public_class_name)); 357 String::Handle(isolate_lib.PrivateName(public_class_name));
345 const String& function_name = String::Handle(Symbols::New("_create")); 358 const String& function_name = String::Handle(Symbols::New("_create"));
346 const int kNumArguments = 1; 359 const int kNumArguments = 1;
347 const Array& kNoArgumentNames = Array::Handle(); 360 const Array& kNoArgumentNames = Array::Handle();
348 const Function& function = Function::Handle( 361 const Function& function = Function::Handle(
349 Resolver::ResolveStatic(isolate_lib, 362 Resolver::ResolveStatic(isolate_lib,
350 class_name, 363 class_name,
351 function_name, 364 function_name,
352 kNumArguments, 365 kNumArguments,
353 kNoArgumentNames, 366 kNoArgumentNames,
354 Resolver::kIsQualified)); 367 Resolver::kIsQualified));
355 GrowableArray<const Object*> arguments(kNumArguments); 368 const Array& args = Array::Handle(Array::New(kNumArguments));
356 arguments.Add(&Integer::Handle(Integer::New(port_id))); 369 args.SetAt(0, Integer::Handle(Integer::New(port_id)));
357 return DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); 370 return DartEntry::InvokeStatic(function, args);
358 } 371 }
359 372
360 373
361 RawObject* DartLibraryCalls::MapSetAt(const Instance& map, 374 RawObject* DartLibraryCalls::MapSetAt(const Instance& map,
362 const Instance& key, 375 const Instance& key,
363 const Instance& value) { 376 const Instance& value) {
364 String& name = String::Handle(Symbols::AssignIndexToken()); 377 String& name = String::Handle(Symbols::AssignIndexToken());
378 const int kNumArguments = 3;
365 const Function& function = Function::Handle( 379 const Function& function = Function::Handle(
366 Resolver::ResolveDynamic(map, name, 3, 0)); 380 Resolver::ResolveDynamic(map, name, kNumArguments, 0));
367 ASSERT(!function.IsNull()); 381 ASSERT(!function.IsNull());
368 GrowableArray<const Object*> args(2); 382 const Array& args = Array::Handle(Array::New(kNumArguments));
369 args.Add(&key); 383 args.SetAt(0, map);
370 args.Add(&value); 384 args.SetAt(1, key);
371 const Array& kNoArgumentNames = Array::Handle(); 385 args.SetAt(2, value);
372 const Object& result = Object::Handle( 386 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function,
373 DartEntry::InvokeDynamic(map, function, args, kNoArgumentNames)); 387 args));
374 return result.raw(); 388 return result.raw();
375 } 389 }
376 390
377 391
378 RawObject* DartLibraryCalls::PortGetId(const Instance& port) { 392 RawObject* DartLibraryCalls::PortGetId(const Instance& port) {
379 const String& field_name = String::Handle(Symbols::New("_id")); 393 const String& field_name = String::Handle(Symbols::New("_id"));
380 const Class& cls = Class::Handle(port.clazz()); 394 const Class& cls = Class::Handle(port.clazz());
381 const String& func_name = String::Handle(Field::GetterName(field_name)); 395 const String& func_name = String::Handle(Field::GetterName(field_name));
382 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); 396 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name));
383 ASSERT(!func.IsNull()); 397 ASSERT(!func.IsNull());
384 GrowableArray<const Object*> arguments; 398 const Array& args = Array::Handle(Array::New(1));
385 const Array& kNoArgumentNames = Array::Handle(); 399 args.SetAt(0, port);
386 return DartEntry::InvokeDynamic(port, func, arguments, kNoArgumentNames); 400 return DartEntry::InvokeDynamic(func, args);
387 } 401 }
388 402
389 403
390 } // namespace dart 404 } // namespace dart
OLDNEW
« vm/dart_entry.h ('K') | « vm/dart_entry.h ('k') | vm/dart_entry_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698