2011-10-05 05:20:07 +00:00
|
|
|
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "vm/dart_entry.h"
|
|
|
|
|
2013-07-26 18:18:56 +00:00
|
|
|
#include "vm/class_finalizer.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
#include "vm/code_generator.h"
|
|
|
|
#include "vm/compiler.h"
|
2013-07-01 17:29:18 +00:00
|
|
|
#include "vm/debugger.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
#include "vm/object_store.h"
|
|
|
|
#include "vm/resolver.h"
|
2013-02-25 19:30:29 +00:00
|
|
|
#include "vm/simulator.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
#include "vm/stub_code.h"
|
2012-07-24 00:01:50 +00:00
|
|
|
#include "vm/symbols.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2013-01-07 18:36:39 +00:00
|
|
|
// A cache of VM heap allocated arguments descriptors.
|
|
|
|
RawArray* ArgumentsDescriptor::cached_args_descriptors_[kCachedDescriptorCount];
|
|
|
|
|
|
|
|
|
2013-02-25 19:30:29 +00:00
|
|
|
RawObject* DartEntry::InvokeFunction(const Function& function,
|
|
|
|
const Array& arguments) {
|
|
|
|
const Array& arguments_descriptor =
|
2012-12-18 21:36:01 +00:00
|
|
|
Array::Handle(ArgumentsDescriptor::New(arguments.Length()));
|
2013-02-25 19:30:29 +00:00
|
|
|
return InvokeFunction(function, arguments, arguments_descriptor);
|
2012-12-18 21:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 19:30:29 +00:00
|
|
|
RawObject* DartEntry::InvokeFunction(const Function& function,
|
|
|
|
const Array& arguments,
|
|
|
|
const Array& arguments_descriptor) {
|
2011-10-05 05:20:07 +00:00
|
|
|
const Context& context =
|
2013-08-02 11:32:05 +00:00
|
|
|
Context::Handle(Isolate::Current()->object_store()->empty_context());
|
2011-10-05 05:20:07 +00:00
|
|
|
ASSERT(context.isolate() == Isolate::Current());
|
2013-02-25 19:30:29 +00:00
|
|
|
return InvokeFunction(function, arguments, arguments_descriptor, context);
|
2012-12-18 21:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 19:30:29 +00:00
|
|
|
RawObject* DartEntry::InvokeFunction(const Function& function,
|
|
|
|
const Array& arguments,
|
|
|
|
const Array& arguments_descriptor,
|
|
|
|
const Context& context) {
|
2011-10-05 05:20:07 +00:00
|
|
|
// Get the entrypoint corresponding to the function specified, this
|
|
|
|
// will result in a compilation of the function if it is not already
|
|
|
|
// compiled.
|
|
|
|
if (!function.HasCode()) {
|
2012-02-02 19:05:06 +00:00
|
|
|
const Error& error = Error::Handle(Compiler::CompileFunction(function));
|
|
|
|
if (!error.IsNull()) {
|
|
|
|
return error.raw();
|
|
|
|
}
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
|
|
|
// Now Call the invoke stub which will invoke the dart function.
|
|
|
|
invokestub entrypoint = reinterpret_cast<invokestub>(
|
|
|
|
StubCode::InvokeDartCodeEntryPoint());
|
2012-02-28 01:31:44 +00:00
|
|
|
const Code& code = Code::Handle(function.CurrentCode());
|
|
|
|
ASSERT(!code.IsNull());
|
2013-01-31 23:56:48 +00:00
|
|
|
ASSERT(Isolate::Current()->no_callback_scope_depth() == 0);
|
2013-03-05 00:04:32 +00:00
|
|
|
#if defined(USING_SIMULATOR)
|
2013-02-25 19:30:29 +00:00
|
|
|
return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call(
|
|
|
|
reinterpret_cast<int32_t>(entrypoint),
|
|
|
|
static_cast<int32_t>(code.EntryPoint()),
|
|
|
|
reinterpret_cast<int32_t>(&arguments_descriptor),
|
|
|
|
reinterpret_cast<int32_t>(&arguments),
|
2013-03-07 11:04:27 +00:00
|
|
|
reinterpret_cast<int32_t>(&context)));
|
2013-02-25 19:30:29 +00:00
|
|
|
#else
|
|
|
|
return entrypoint(code.EntryPoint(),
|
|
|
|
arguments_descriptor,
|
|
|
|
arguments,
|
|
|
|
context);
|
|
|
|
#endif
|
2012-12-18 21:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 19:30:29 +00:00
|
|
|
RawObject* DartEntry::InvokeClosure(const Array& arguments) {
|
2012-12-19 21:26:29 +00:00
|
|
|
const Array& arguments_descriptor =
|
2012-12-18 21:36:01 +00:00
|
|
|
Array::Handle(ArgumentsDescriptor::New(arguments.Length()));
|
2013-02-25 19:30:29 +00:00
|
|
|
return InvokeClosure(arguments, arguments_descriptor);
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 19:30:29 +00:00
|
|
|
RawObject* DartEntry::InvokeClosure(const Array& arguments,
|
2012-12-19 21:26:29 +00:00
|
|
|
const Array& arguments_descriptor) {
|
2013-02-25 19:30:29 +00:00
|
|
|
Instance& instance = Instance::Handle();
|
|
|
|
instance ^= arguments.At(0);
|
2012-12-14 19:04:01 +00:00
|
|
|
// Get the entrypoint corresponding to the closure function or to the call
|
|
|
|
// method of the instance. This will result in a compilation of the function
|
|
|
|
// if it is not already compiled.
|
|
|
|
Function& function = Function::Handle();
|
|
|
|
Context& context = Context::Handle();
|
2012-12-19 21:26:29 +00:00
|
|
|
if (instance.IsCallable(&function, &context)) {
|
|
|
|
// Only invoke the function if its arguments are compatible.
|
|
|
|
const ArgumentsDescriptor args_desc(arguments_descriptor);
|
|
|
|
if (function.AreValidArgumentCounts(args_desc.Count(),
|
|
|
|
args_desc.NamedCount(),
|
|
|
|
NULL)) {
|
|
|
|
// The closure or non-closure object (receiver) is passed as implicit
|
|
|
|
// first argument. It is already included in the arguments array.
|
2013-02-25 19:30:29 +00:00
|
|
|
return InvokeFunction(function, arguments, arguments_descriptor, context);
|
2012-02-02 19:05:06 +00:00
|
|
|
}
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
2012-12-19 21:26:29 +00:00
|
|
|
// There is no compatible 'call' method, so invoke noSuchMethod.
|
|
|
|
return InvokeNoSuchMethod(instance,
|
2013-01-02 19:31:59 +00:00
|
|
|
Symbols::Call(),
|
2012-12-19 21:26:29 +00:00
|
|
|
arguments,
|
|
|
|
arguments_descriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver,
|
|
|
|
const String& target_name,
|
|
|
|
const Array& arguments,
|
|
|
|
const Array& arguments_descriptor) {
|
|
|
|
ASSERT(receiver.raw() == arguments.At(0));
|
2013-04-15 15:42:44 +00:00
|
|
|
// Allocate an Invocation object.
|
2012-12-19 21:26:29 +00:00
|
|
|
const Library& core_lib = Library::Handle(Library::CoreLibrary());
|
2013-01-17 00:42:03 +00:00
|
|
|
|
2013-01-02 19:31:59 +00:00
|
|
|
Class& invocation_mirror_class = Class::Handle(
|
2013-01-17 00:42:03 +00:00
|
|
|
core_lib.LookupClass(
|
2013-09-09 21:52:40 +00:00
|
|
|
String::Handle(core_lib.PrivateName(Symbols::InvocationMirror()))));
|
2012-12-19 21:26:29 +00:00
|
|
|
ASSERT(!invocation_mirror_class.IsNull());
|
2013-01-17 00:42:03 +00:00
|
|
|
const String& function_name =
|
|
|
|
String::Handle(core_lib.PrivateName(Symbols::AllocateInvocationMirror()));
|
2012-12-19 21:26:29 +00:00
|
|
|
const Function& allocation_function = Function::Handle(
|
|
|
|
Resolver::ResolveStaticByName(invocation_mirror_class,
|
2013-01-17 00:42:03 +00:00
|
|
|
function_name,
|
2012-12-19 21:26:29 +00:00
|
|
|
Resolver::kIsQualified));
|
|
|
|
ASSERT(!allocation_function.IsNull());
|
2013-10-22 22:12:07 +00:00
|
|
|
const int kNumAllocationArgs = 4;
|
2012-12-19 21:26:29 +00:00
|
|
|
const Array& allocation_args = Array::Handle(Array::New(kNumAllocationArgs));
|
|
|
|
allocation_args.SetAt(0, target_name);
|
|
|
|
allocation_args.SetAt(1, arguments_descriptor);
|
|
|
|
allocation_args.SetAt(2, arguments);
|
2013-10-22 22:12:07 +00:00
|
|
|
allocation_args.SetAt(3, Bool::False()); // Not a super invocation.
|
2012-12-19 21:26:29 +00:00
|
|
|
const Object& invocation_mirror = Object::Handle(
|
2013-02-25 19:30:29 +00:00
|
|
|
InvokeFunction(allocation_function, allocation_args));
|
2012-12-19 21:26:29 +00:00
|
|
|
|
|
|
|
// Now use the invocation mirror object and invoke NoSuchMethod.
|
|
|
|
const int kNumArguments = 2;
|
2013-07-16 09:38:13 +00:00
|
|
|
ArgumentsDescriptor args_desc(
|
|
|
|
Array::Handle(ArgumentsDescriptor::New(kNumArguments)));
|
2012-12-19 21:26:29 +00:00
|
|
|
const Function& function = Function::Handle(
|
|
|
|
Resolver::ResolveDynamic(receiver,
|
2013-01-02 19:31:59 +00:00
|
|
|
Symbols::NoSuchMethod(),
|
2013-07-16 09:38:13 +00:00
|
|
|
args_desc));
|
2012-12-19 21:26:29 +00:00
|
|
|
ASSERT(!function.IsNull());
|
|
|
|
const Array& args = Array::Handle(Array::New(kNumArguments));
|
|
|
|
args.SetAt(0, receiver);
|
|
|
|
args.SetAt(1, invocation_mirror);
|
2013-02-25 19:30:29 +00:00
|
|
|
return InvokeFunction(function, args);
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-05 19:50:50 +00:00
|
|
|
ArgumentsDescriptor::ArgumentsDescriptor(const Array& array)
|
|
|
|
: array_(array) {
|
2012-12-05 12:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intptr_t ArgumentsDescriptor::Count() const {
|
|
|
|
return Smi::CheckedHandle(array_.At(kCountIndex)).Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intptr_t ArgumentsDescriptor::PositionalCount() const {
|
|
|
|
return Smi::CheckedHandle(array_.At(kPositionalCountIndex)).Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-11 10:01:50 +00:00
|
|
|
RawString* ArgumentsDescriptor::NameAt(intptr_t index) const {
|
2012-12-07 17:59:53 +00:00
|
|
|
const intptr_t offset = kFirstNamedEntryIndex +
|
|
|
|
(index * kNamedEntrySize) +
|
|
|
|
kNameOffset;
|
2013-07-11 10:01:50 +00:00
|
|
|
String& result = String::Handle();
|
|
|
|
result ^= array_.At(offset);
|
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ArgumentsDescriptor::MatchesNameAt(intptr_t index,
|
|
|
|
const String& other) const {
|
|
|
|
return NameAt(index) == other.raw();
|
2012-12-05 12:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intptr_t ArgumentsDescriptor::count_offset() {
|
2013-05-21 09:34:50 +00:00
|
|
|
return Array::element_offset(kCountIndex);
|
2012-12-05 12:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intptr_t ArgumentsDescriptor::positional_count_offset() {
|
2013-05-21 09:34:50 +00:00
|
|
|
return Array::element_offset(kPositionalCountIndex);
|
2012-12-05 12:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intptr_t ArgumentsDescriptor::first_named_entry_offset() {
|
2013-05-21 09:34:50 +00:00
|
|
|
return Array::element_offset(kFirstNamedEntryIndex);
|
2012-12-05 12:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RawArray* ArgumentsDescriptor::New(intptr_t num_arguments,
|
|
|
|
const Array& optional_arguments_names) {
|
2012-06-26 17:43:44 +00:00
|
|
|
const intptr_t num_named_args =
|
|
|
|
optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length();
|
2013-01-07 18:36:39 +00:00
|
|
|
if (num_named_args == 0) {
|
|
|
|
return ArgumentsDescriptor::New(num_arguments);
|
|
|
|
}
|
2012-06-26 17:43:44 +00:00
|
|
|
const intptr_t num_pos_args = num_arguments - num_named_args;
|
|
|
|
|
2012-12-05 12:05:57 +00:00
|
|
|
// Build the arguments descriptor array, which consists of the total
|
|
|
|
// argument count; the positional argument count; a sequence of (name,
|
|
|
|
// position) pairs, sorted by name, for each named optional argument; and
|
|
|
|
// a terminating null to simplify iterating in generated code.
|
|
|
|
const intptr_t descriptor_len = LengthFor(num_named_args);
|
|
|
|
Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld));
|
2012-06-26 17:43:44 +00:00
|
|
|
|
|
|
|
// Set total number of passed arguments.
|
2012-12-05 12:05:57 +00:00
|
|
|
descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments)));
|
2012-06-26 17:43:44 +00:00
|
|
|
// Set number of positional arguments.
|
2012-12-05 12:05:57 +00:00
|
|
|
descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args)));
|
|
|
|
// Set alphabetically sorted entries for named arguments.
|
2012-06-26 17:43:44 +00:00
|
|
|
String& name = String::Handle();
|
|
|
|
Smi& pos = Smi::Handle();
|
2012-12-05 12:05:57 +00:00
|
|
|
for (intptr_t i = 0; i < num_named_args; i++) {
|
2013-01-23 20:01:31 +00:00
|
|
|
name ^= optional_arguments_names.At(i);
|
2012-06-26 17:43:44 +00:00
|
|
|
pos = Smi::New(num_pos_args + i);
|
2012-12-05 12:05:57 +00:00
|
|
|
intptr_t insert_index = kFirstNamedEntryIndex + (kNamedEntrySize * i);
|
2012-06-26 17:43:44 +00:00
|
|
|
// Shift already inserted pairs with "larger" names.
|
2012-12-05 12:05:57 +00:00
|
|
|
String& previous_name = String::Handle();
|
|
|
|
Smi& previous_pos = Smi::Handle();
|
|
|
|
while (insert_index > kFirstNamedEntryIndex) {
|
|
|
|
intptr_t previous_index = insert_index - kNamedEntrySize;
|
2013-01-23 20:01:31 +00:00
|
|
|
previous_name ^= descriptor.At(previous_index + kNameOffset);
|
2012-12-05 12:05:57 +00:00
|
|
|
intptr_t result = name.CompareTo(previous_name);
|
2012-06-26 17:43:44 +00:00
|
|
|
ASSERT(result != 0); // Duplicate argument names checked in parser.
|
|
|
|
if (result > 0) break;
|
2013-01-23 20:01:31 +00:00
|
|
|
previous_pos ^= descriptor.At(previous_index + kPositionOffset);
|
2012-12-05 12:05:57 +00:00
|
|
|
descriptor.SetAt(insert_index + kNameOffset, previous_name);
|
|
|
|
descriptor.SetAt(insert_index + kPositionOffset, previous_pos);
|
|
|
|
insert_index = previous_index;
|
2012-06-26 17:43:44 +00:00
|
|
|
}
|
|
|
|
// Insert pair in descriptor array.
|
2012-12-05 12:05:57 +00:00
|
|
|
descriptor.SetAt(insert_index + kNameOffset, name);
|
|
|
|
descriptor.SetAt(insert_index + kPositionOffset, pos);
|
2012-06-26 17:43:44 +00:00
|
|
|
}
|
|
|
|
// Set terminating null.
|
2013-06-20 19:49:30 +00:00
|
|
|
descriptor.SetAt(descriptor_len - 1, Object::null_object());
|
2012-06-26 17:43:44 +00:00
|
|
|
|
|
|
|
// Share the immutable descriptor when possible by canonicalizing it.
|
|
|
|
descriptor.MakeImmutable();
|
2013-06-12 21:27:37 +00:00
|
|
|
descriptor ^= descriptor.CheckAndCanonicalize(NULL);
|
|
|
|
ASSERT(!descriptor.IsNull());
|
2012-12-05 12:05:57 +00:00
|
|
|
return descriptor.raw();
|
2012-06-26 17:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 21:36:01 +00:00
|
|
|
RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) {
|
2013-01-07 18:36:39 +00:00
|
|
|
ASSERT(num_arguments >= 0);
|
|
|
|
if (num_arguments < kCachedDescriptorCount) {
|
|
|
|
return cached_args_descriptors_[num_arguments];
|
|
|
|
}
|
|
|
|
return NewNonCached(num_arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments,
|
|
|
|
bool canonicalize) {
|
2012-12-18 21:36:01 +00:00
|
|
|
// Build the arguments descriptor array, which consists of the total
|
|
|
|
// argument count; the positional argument count; and
|
|
|
|
// a terminating null to simplify iterating in generated code.
|
|
|
|
const intptr_t descriptor_len = LengthFor(0);
|
|
|
|
Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld));
|
|
|
|
const Smi& arg_count = Smi::Handle(Smi::New(num_arguments));
|
|
|
|
|
|
|
|
// Set total number of passed arguments.
|
|
|
|
descriptor.SetAt(kCountIndex, arg_count);
|
|
|
|
|
|
|
|
// Set number of positional arguments.
|
|
|
|
descriptor.SetAt(kPositionalCountIndex, arg_count);
|
|
|
|
|
|
|
|
// Set terminating null.
|
2013-06-20 19:49:30 +00:00
|
|
|
descriptor.SetAt((descriptor_len - 1), Object::null_object());
|
2012-12-18 21:36:01 +00:00
|
|
|
|
|
|
|
// Share the immutable descriptor when possible by canonicalizing it.
|
|
|
|
descriptor.MakeImmutable();
|
2013-01-07 18:36:39 +00:00
|
|
|
if (canonicalize) {
|
2013-06-12 21:27:37 +00:00
|
|
|
descriptor ^= descriptor.CheckAndCanonicalize(NULL);
|
2013-01-07 18:36:39 +00:00
|
|
|
}
|
2013-06-12 21:27:37 +00:00
|
|
|
ASSERT(!descriptor.IsNull());
|
2012-12-18 21:36:01 +00:00
|
|
|
return descriptor.raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-07 18:36:39 +00:00
|
|
|
void ArgumentsDescriptor::InitOnce() {
|
|
|
|
for (int i = 0; i < kCachedDescriptorCount; i++) {
|
|
|
|
cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 21:49:45 +00:00
|
|
|
RawObject* DartLibraryCalls::InstanceCreate(const Library& lib,
|
|
|
|
const String& class_name,
|
|
|
|
const String& constructor_name,
|
|
|
|
const Array& arguments) {
|
2013-09-09 21:52:40 +00:00
|
|
|
const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name));
|
2011-10-05 05:20:07 +00:00
|
|
|
ASSERT(!cls.IsNull());
|
|
|
|
// For now, we only support a non-parameterized or raw type.
|
2012-12-18 21:36:01 +00:00
|
|
|
const int kNumExtraArgs = 2; // implicit rcvr and construction phase args.
|
2011-10-05 05:20:07 +00:00
|
|
|
const Instance& exception_object = Instance::Handle(Instance::New(cls));
|
2012-12-18 21:36:01 +00:00
|
|
|
const Array& constructor_arguments =
|
2012-12-18 23:47:35 +00:00
|
|
|
Array::Handle(Array::New(arguments.Length() + kNumExtraArgs));
|
2012-12-18 21:36:01 +00:00
|
|
|
constructor_arguments.SetAt(0, exception_object);
|
|
|
|
constructor_arguments.SetAt(
|
|
|
|
1, Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
|
2012-12-18 23:47:35 +00:00
|
|
|
Object& obj = Object::Handle();
|
|
|
|
for (intptr_t i = 0; i < arguments.Length(); i++) {
|
|
|
|
obj = arguments.At(i);
|
|
|
|
constructor_arguments.SetAt((i + kNumExtraArgs), obj);
|
2012-12-18 21:36:01 +00:00
|
|
|
}
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2013-02-21 18:53:27 +00:00
|
|
|
const String& function_name = String::Handle(
|
|
|
|
String::Concat(class_name, constructor_name));
|
|
|
|
const Function& constructor =
|
|
|
|
Function::Handle(cls.LookupConstructorAllowPrivate(function_name));
|
2011-10-05 05:20:07 +00:00
|
|
|
ASSERT(!constructor.IsNull());
|
2012-12-18 21:36:01 +00:00
|
|
|
const Object& retval =
|
2013-02-25 19:30:29 +00:00
|
|
|
Object::Handle(DartEntry::InvokeFunction(constructor,
|
|
|
|
constructor_arguments));
|
2012-02-02 19:05:06 +00:00
|
|
|
ASSERT(retval.IsNull() || retval.IsError());
|
|
|
|
if (retval.IsError()) {
|
|
|
|
return retval.raw();
|
|
|
|
}
|
2011-10-05 05:20:07 +00:00
|
|
|
return exception_object.raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-02 19:05:06 +00:00
|
|
|
RawObject* DartLibraryCalls::ToString(const Instance& receiver) {
|
2011-10-05 05:20:07 +00:00
|
|
|
const int kNumArguments = 1; // Receiver.
|
2013-07-16 09:38:13 +00:00
|
|
|
ArgumentsDescriptor args_desc(
|
|
|
|
Array::Handle(ArgumentsDescriptor::New(kNumArguments)));
|
2011-10-05 05:20:07 +00:00
|
|
|
const Function& function = Function::Handle(
|
|
|
|
Resolver::ResolveDynamic(receiver,
|
2013-01-02 19:31:59 +00:00
|
|
|
Symbols::toString(),
|
2013-07-16 09:38:13 +00:00
|
|
|
args_desc));
|
2011-10-05 05:20:07 +00:00
|
|
|
ASSERT(!function.IsNull());
|
2012-12-18 21:36:01 +00:00
|
|
|
const Array& args = Array::Handle(Array::New(kNumArguments));
|
|
|
|
args.SetAt(0, receiver);
|
2013-02-25 19:30:29 +00:00
|
|
|
const Object& result = Object::Handle(DartEntry::InvokeFunction(function,
|
|
|
|
args));
|
2012-02-02 19:05:06 +00:00
|
|
|
ASSERT(result.IsInstance() || result.IsError());
|
2011-10-05 05:20:07 +00:00
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-02 19:05:06 +00:00
|
|
|
RawObject* DartLibraryCalls::Equals(const Instance& left,
|
|
|
|
const Instance& right) {
|
2011-10-05 05:20:07 +00:00
|
|
|
const int kNumArguments = 2;
|
2013-07-16 09:38:13 +00:00
|
|
|
ArgumentsDescriptor args_desc(
|
|
|
|
Array::Handle(ArgumentsDescriptor::New(kNumArguments)));
|
2011-10-05 05:20:07 +00:00
|
|
|
const Function& function = Function::Handle(
|
|
|
|
Resolver::ResolveDynamic(left,
|
2013-01-02 19:31:59 +00:00
|
|
|
Symbols::EqualOperator(),
|
2013-07-16 09:38:13 +00:00
|
|
|
args_desc));
|
2011-10-05 05:20:07 +00:00
|
|
|
ASSERT(!function.IsNull());
|
2012-12-18 21:36:01 +00:00
|
|
|
|
|
|
|
const Array& args = Array::Handle(Array::New(kNumArguments));
|
|
|
|
args.SetAt(0, left);
|
|
|
|
args.SetAt(1, right);
|
2013-02-25 19:30:29 +00:00
|
|
|
const Object& result = Object::Handle(DartEntry::InvokeFunction(function,
|
|
|
|
args));
|
2012-02-02 19:05:06 +00:00
|
|
|
ASSERT(result.IsInstance() || result.IsError());
|
2011-10-05 05:20:07 +00:00
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
|
2011-12-14 18:27:58 +00:00
|
|
|
|
2012-12-20 20:03:07 +00:00
|
|
|
RawObject* DartLibraryCalls::LookupReceivePort(Dart_Port port_id) {
|
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
Function& function =
|
|
|
|
Function::Handle(isolate,
|
|
|
|
isolate->object_store()->lookup_receive_port_function());
|
|
|
|
const int kNumArguments = 1;
|
|
|
|
if (function.IsNull()) {
|
|
|
|
Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
|
|
|
|
ASSERT(!isolate_lib.IsNull());
|
|
|
|
const String& class_name =
|
2013-01-02 19:31:59 +00:00
|
|
|
String::Handle(isolate_lib.PrivateName(Symbols::_ReceivePortImpl()));
|
2013-01-17 00:42:03 +00:00
|
|
|
const String& function_name =
|
|
|
|
String::Handle(isolate_lib.PrivateName(Symbols::_lookupReceivePort()));
|
2012-12-20 20:03:07 +00:00
|
|
|
function = Resolver::ResolveStatic(isolate_lib,
|
|
|
|
class_name,
|
2013-01-17 00:42:03 +00:00
|
|
|
function_name,
|
2012-12-20 20:03:07 +00:00
|
|
|
kNumArguments,
|
2013-01-02 19:31:59 +00:00
|
|
|
Object::empty_array(),
|
2013-09-09 21:52:40 +00:00
|
|
|
Resolver::kIsQualified);
|
2013-07-23 00:19:39 +00:00
|
|
|
ASSERT(!function.IsNull());
|
2012-12-20 20:03:07 +00:00
|
|
|
isolate->object_store()->set_lookup_receive_port_function(function);
|
|
|
|
}
|
|
|
|
const Array& args = Array::Handle(Array::New(kNumArguments));
|
|
|
|
args.SetAt(0, Integer::Handle(Integer::New(port_id)));
|
|
|
|
const Object& result =
|
2013-02-25 19:30:29 +00:00
|
|
|
Object::Handle(DartEntry::InvokeFunction(function, args));
|
2012-12-20 20:03:07 +00:00
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RawObject* DartLibraryCalls::HandleMessage(const Object& receive_port,
|
2011-12-14 18:27:58 +00:00
|
|
|
Dart_Port reply_port_id,
|
|
|
|
const Instance& message) {
|
2012-12-20 12:42:11 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
Function& function =
|
|
|
|
Function::Handle(isolate,
|
|
|
|
isolate->object_store()->handle_message_function());
|
2011-12-14 18:27:58 +00:00
|
|
|
const int kNumArguments = 3;
|
2012-12-20 12:42:11 +00:00
|
|
|
if (function.IsNull()) {
|
|
|
|
Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
|
|
|
|
ASSERT(!isolate_lib.IsNull());
|
|
|
|
const String& class_name =
|
2013-01-02 19:31:59 +00:00
|
|
|
String::Handle(isolate_lib.PrivateName(Symbols::_ReceivePortImpl()));
|
2013-01-17 00:42:03 +00:00
|
|
|
const String& function_name =
|
|
|
|
String::Handle(isolate_lib.PrivateName(Symbols::_handleMessage()));
|
2012-12-20 12:42:11 +00:00
|
|
|
function = Resolver::ResolveStatic(isolate_lib,
|
|
|
|
class_name,
|
2013-01-17 00:42:03 +00:00
|
|
|
function_name,
|
2012-12-20 12:42:11 +00:00
|
|
|
kNumArguments,
|
2013-01-02 19:31:59 +00:00
|
|
|
Object::empty_array(),
|
2013-09-09 21:52:40 +00:00
|
|
|
Resolver::kIsQualified);
|
2013-07-23 00:19:39 +00:00
|
|
|
ASSERT(!function.IsNull());
|
2012-12-20 12:42:11 +00:00
|
|
|
isolate->object_store()->set_handle_message_function(function);
|
|
|
|
}
|
|
|
|
const Array& args = Array::Handle(isolate, Array::New(kNumArguments));
|
2012-12-20 20:03:07 +00:00
|
|
|
args.SetAt(0, receive_port);
|
2012-12-20 12:42:11 +00:00
|
|
|
args.SetAt(1, Integer::Handle(isolate, Integer::New(reply_port_id)));
|
2012-12-18 21:36:01 +00:00
|
|
|
args.SetAt(2, message);
|
2013-07-01 17:29:18 +00:00
|
|
|
if (isolate->debugger()->IsStepping()) {
|
|
|
|
// If the isolate is being debugged and the debugger was stepping
|
|
|
|
// through code, enable single stepping so debugger will stop
|
|
|
|
// at the first location the user is interested in.
|
|
|
|
isolate->debugger()->SetSingleStep();
|
|
|
|
}
|
2012-12-20 12:42:11 +00:00
|
|
|
const Object& result =
|
2013-02-25 19:30:29 +00:00
|
|
|
Object::Handle(isolate, DartEntry::InvokeFunction(function, args));
|
2012-02-02 19:05:06 +00:00
|
|
|
ASSERT(result.IsNull() || result.IsError());
|
2011-12-14 18:27:58 +00:00
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
|
2012-03-12 23:51:03 +00:00
|
|
|
|
|
|
|
RawObject* DartLibraryCalls::NewSendPort(intptr_t port_id) {
|
|
|
|
Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
|
|
|
|
ASSERT(!isolate_lib.IsNull());
|
|
|
|
const String& class_name =
|
2013-01-02 19:31:59 +00:00
|
|
|
String::Handle(isolate_lib.PrivateName(Symbols::_SendPortImpl()));
|
2012-03-12 23:51:03 +00:00
|
|
|
const int kNumArguments = 1;
|
2013-01-17 00:42:03 +00:00
|
|
|
const String& function_name =
|
|
|
|
String::Handle(isolate_lib.PrivateName(Symbols::_create()));
|
2012-03-12 23:51:03 +00:00
|
|
|
const Function& function = Function::Handle(
|
|
|
|
Resolver::ResolveStatic(isolate_lib,
|
|
|
|
class_name,
|
2013-01-17 00:42:03 +00:00
|
|
|
function_name,
|
2012-03-12 23:51:03 +00:00
|
|
|
kNumArguments,
|
2013-01-02 19:31:59 +00:00
|
|
|
Object::empty_array(),
|
2013-09-09 21:52:40 +00:00
|
|
|
Resolver::kIsQualified));
|
2013-07-23 00:19:39 +00:00
|
|
|
ASSERT(!function.IsNull());
|
2012-12-18 21:36:01 +00:00
|
|
|
const Array& args = Array::Handle(Array::New(kNumArguments));
|
|
|
|
args.SetAt(0, Integer::Handle(Integer::New(port_id)));
|
2013-02-25 19:30:29 +00:00
|
|
|
return DartEntry::InvokeFunction(function, args);
|
2012-03-12 23:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RawObject* DartLibraryCalls::MapSetAt(const Instance& map,
|
|
|
|
const Instance& key,
|
|
|
|
const Instance& value) {
|
2012-12-18 21:36:01 +00:00
|
|
|
const int kNumArguments = 3;
|
2013-07-16 09:38:13 +00:00
|
|
|
ArgumentsDescriptor args_desc(
|
|
|
|
Array::Handle(ArgumentsDescriptor::New(kNumArguments)));
|
2012-03-12 23:51:03 +00:00
|
|
|
const Function& function = Function::Handle(
|
2013-01-02 19:31:59 +00:00
|
|
|
Resolver::ResolveDynamic(map,
|
|
|
|
Symbols::AssignIndexToken(),
|
2013-07-16 09:38:13 +00:00
|
|
|
args_desc));
|
2012-03-12 23:51:03 +00:00
|
|
|
ASSERT(!function.IsNull());
|
2012-12-18 21:36:01 +00:00
|
|
|
const Array& args = Array::Handle(Array::New(kNumArguments));
|
|
|
|
args.SetAt(0, map);
|
|
|
|
args.SetAt(1, key);
|
|
|
|
args.SetAt(2, value);
|
2013-02-25 19:30:29 +00:00
|
|
|
const Object& result = Object::Handle(DartEntry::InvokeFunction(function,
|
|
|
|
args));
|
2012-03-12 23:51:03 +00:00
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RawObject* DartLibraryCalls::PortGetId(const Instance& port) {
|
|
|
|
const Class& cls = Class::Handle(port.clazz());
|
2013-01-17 00:42:03 +00:00
|
|
|
const Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
|
|
|
|
const String& func_name =
|
|
|
|
String::Handle(isolate_lib.PrivateName(
|
|
|
|
String::Handle(Field::GetterName(Symbols::_id()))));
|
2012-03-12 23:51:03 +00:00
|
|
|
const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name));
|
|
|
|
ASSERT(!func.IsNull());
|
2012-12-18 21:36:01 +00:00
|
|
|
const Array& args = Array::Handle(Array::New(1));
|
|
|
|
args.SetAt(0, port);
|
2013-02-25 19:30:29 +00:00
|
|
|
return DartEntry::InvokeFunction(func, args);
|
2012-03-12 23:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
} // namespace dart
|