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

Unified Diff: vm/object.cc

Issue 11087070: - Get rid of RawClosure class and use RawInstance for closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vm/object.h ('k') | vm/object_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/object.cc
===================================================================
--- vm/object.cc (revision 13564)
+++ vm/object.cc (working copy)
@@ -1345,8 +1345,7 @@
result.set_handle_vtable(fake.vtable());
result.set_instance_size(FakeObject::InstanceSize());
result.set_next_field_offset(FakeObject::InstanceSize());
- ASSERT((FakeObject::kClassId != kInstanceCid) &&
- (FakeObject::kClassId != kClosureCid));
+ ASSERT((FakeObject::kClassId != kInstanceCid));
result.set_id(FakeObject::kClassId);
result.raw_ptr()->state_bits_ = 0;
// VM backed classes are almost ready: run checks and resolve class
@@ -1778,10 +1777,6 @@
}
-// Force instantiation of template version to work around ld problems.
-template RawClass* Class::New<Closure>(intptr_t index);
-
-
template <class FakeInstance>
RawClass* Class::New(const String& name,
const Script& script,
@@ -1827,10 +1822,12 @@
type_parameters = owner_class.type_parameters();
}
const intptr_t token_pos = signature_function.token_pos();
- Class& result = Class::Handle(New<Closure>(name, script, token_pos));
+ Class& result = Class::Handle(New<Instance>(name, script, token_pos));
const Type& super_type = Type::Handle(Type::ObjectType());
const Array& empty_array = Array::Handle(Object::empty_array());
ASSERT(!super_type.IsNull());
+ result.set_instance_size(Closure::InstanceSize());
+ result.set_next_field_offset(Closure::InstanceSize());
result.set_super_type(super_type);
result.set_signature_function(signature_function);
result.set_type_parameters(type_parameters);
@@ -3142,7 +3139,7 @@
if (!IsFactory() || (raw_ptr()->data_ == Object::null())) {
return false;
}
- ASSERT(!IsClosure()); // A factory cannot also be a closure.
+ ASSERT(!IsClosureFunction()); // A factory cannot also be a closure.
return true;
}
@@ -8120,6 +8117,12 @@
}
+bool Instance::IsClosure() const {
+ const Class& cls = Class::Handle(clazz());
+ return cls.IsSignatureClass();
+}
+
+
RawInstance* Instance::New(const Class& cls, Heap::Space space) {
Instance& result = Instance::Handle();
{
@@ -8158,8 +8161,11 @@
// Can occur when running disassembler.
return "Instance";
} else {
+ if (IsClosure()) {
+ return Closure::ToCString(*this);
+ }
const char* kFormat = "Instance of '%s'";
- Class& cls = Class::Handle(clazz());
+ const Class& cls = Class::Handle(clazz());
AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
const intptr_t num_type_arguments = cls.NumTypeArguments();
if (num_type_arguments > 0) {
@@ -11894,55 +11900,45 @@
}
+const char* Closure::ToCString(const Instance& closure) {
+ const Function& fun = Function::Handle(Closure::function(closure));
+ const bool is_implicit_closure = fun.IsImplicitClosureFunction();
+ const char* fun_sig = String::Handle(fun.Signature()).ToCString();
+ const char* from = is_implicit_closure ? " from " : "";
+ const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
+ const char* format = "Closure: %s%s%s";
+ intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1;
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
+ OS::SNPrint(chars, len, format, fun_sig, from, fun_desc);
+ return chars;
+}
-RawClosure* Closure::New(const Function& function,
- const Context& context,
- Heap::Space space) {
+
+RawInstance* Closure::New(const Function& function,
+ const Context& context,
+ Heap::Space space) {
Isolate* isolate = Isolate::Current();
ASSERT(context.isolate() == isolate);
const Class& cls = Class::Handle(function.signature_class());
- Closure& result = Closure::Handle();
+ ASSERT(cls.instance_size() == Closure::InstanceSize());
+ Instance& result = Instance::Handle();
{
RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space);
NoGCScope no_gc;
result ^= raw;
}
- result.set_function(function);
- result.set_context(context);
+ Closure::set_function(result, function);
+ Closure::set_context(result, context);
return result.raw();
}
-void Closure::set_context(const Context& value) const {
- StorePointer(&raw_ptr()->context_, value.raw());
-}
-
-
-void Closure::set_function(const Function& value) const {
- StorePointer(&raw_ptr()->function_, value.raw());
-}
-
-
const char* DartFunction::ToCString() const {
return "Function type class";
}
-const char* Closure::ToCString() const {
- const Function& fun = Function::Handle(function());
- const bool is_implicit_closure = fun.IsImplicitClosureFunction();
- const char* fun_sig = String::Handle(fun.Signature()).ToCString();
- const char* from = is_implicit_closure ? " from " : "";
- const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
- const char* format = "Closure: %s%s%s";
- intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1;
- char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
- OS::SNPrint(chars, len, format, fun_sig, from, fun_desc);
- return chars;
-}
-
-
intptr_t Stacktrace::Length() const {
const Array& code_array = Array::Handle(raw_ptr()->code_array_);
return code_array.Length();
« no previous file with comments | « vm/object.h ('k') | vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698