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 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 cls = Class::New<SendPort>(); | 1264 cls = Class::New<SendPort>(); |
1265 RegisterPrivateClass(cls, Symbols::_SendPortImpl(), isolate_lib); | 1265 RegisterPrivateClass(cls, Symbols::_SendPortImpl(), isolate_lib); |
1266 pending_classes.Add(cls); | 1266 pending_classes.Add(cls); |
1267 | 1267 |
1268 const Class& stacktrace_cls = Class::Handle(zone, | 1268 const Class& stacktrace_cls = Class::Handle(zone, |
1269 Class::New<Stacktrace>()); | 1269 Class::New<Stacktrace>()); |
1270 RegisterPrivateClass(stacktrace_cls, Symbols::_StackTrace(), core_lib); | 1270 RegisterPrivateClass(stacktrace_cls, Symbols::_StackTrace(), core_lib); |
1271 pending_classes.Add(stacktrace_cls); | 1271 pending_classes.Add(stacktrace_cls); |
1272 // Super type set below, after Object is allocated. | 1272 // Super type set below, after Object is allocated. |
1273 | 1273 |
1274 cls = Class::New<JSRegExp>(); | 1274 cls = Class::New<RegExp>(); |
1275 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); | 1275 RegisterPrivateClass(cls, Symbols::_RegExp(), core_lib); |
1276 pending_classes.Add(cls); | 1276 pending_classes.Add(cls); |
1277 | 1277 |
1278 // Initialize the base interfaces used by the core VM classes. | 1278 // Initialize the base interfaces used by the core VM classes. |
1279 | 1279 |
1280 // Allocate and initialize the pre-allocated classes in the core library. | 1280 // Allocate and initialize the pre-allocated classes in the core library. |
1281 // The script and token index of these pre-allocated classes is set up in | 1281 // The script and token index of these pre-allocated classes is set up in |
1282 // the parser when the corelib script is compiled (see | 1282 // the parser when the corelib script is compiled (see |
1283 // Parser::ParseClassDefinition). | 1283 // Parser::ParseClassDefinition). |
1284 cls = Class::New<Instance>(kInstanceCid); | 1284 cls = Class::New<Instance>(kInstanceCid); |
1285 object_store->set_object_class(cls); | 1285 object_store->set_object_class(cls); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 cls = Class::New<Bool>(); | 1703 cls = Class::New<Bool>(); |
1704 object_store->set_bool_class(cls); | 1704 object_store->set_bool_class(cls); |
1705 | 1705 |
1706 cls = Class::New<Instance>(kNullCid); | 1706 cls = Class::New<Instance>(kNullCid); |
1707 object_store->set_null_class(cls); | 1707 object_store->set_null_class(cls); |
1708 | 1708 |
1709 cls = Class::New<Capability>(); | 1709 cls = Class::New<Capability>(); |
1710 cls = Class::New<ReceivePort>(); | 1710 cls = Class::New<ReceivePort>(); |
1711 cls = Class::New<SendPort>(); | 1711 cls = Class::New<SendPort>(); |
1712 cls = Class::New<Stacktrace>(); | 1712 cls = Class::New<Stacktrace>(); |
1713 cls = Class::New<JSRegExp>(); | 1713 cls = Class::New<RegExp>(); |
1714 cls = Class::New<Number>(); | 1714 cls = Class::New<Number>(); |
1715 | 1715 |
1716 cls = Class::New<WeakProperty>(); | 1716 cls = Class::New<WeakProperty>(); |
1717 object_store->set_weak_property_class(cls); | 1717 object_store->set_weak_property_class(cls); |
1718 | 1718 |
1719 cls = Class::New<MirrorReference>(); | 1719 cls = Class::New<MirrorReference>(); |
1720 cls = Class::New<UserTag>(); | 1720 cls = Class::New<UserTag>(); |
1721 | 1721 |
1722 const Context& context = Context::Handle(zone, | 1722 const Context& context = Context::Handle(zone, |
1723 Context::New(0, Heap::kOld)); | 1723 Context::New(0, Heap::kOld)); |
(...skipping 3879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5603 | 5603 |
5604 | 5604 |
5605 // This field is heavily overloaded: | 5605 // This field is heavily overloaded: |
5606 // eval function: Script expression source | 5606 // eval function: Script expression source |
5607 // signature function: Function type | 5607 // signature function: Function type |
5608 // method extractor: Function extracted closure function | 5608 // method extractor: Function extracted closure function |
5609 // noSuchMethod dispatcher: Array arguments descriptor | 5609 // noSuchMethod dispatcher: Array arguments descriptor |
5610 // invoke-field dispatcher: Array arguments descriptor | 5610 // invoke-field dispatcher: Array arguments descriptor |
5611 // redirecting constructor: RedirectionData | 5611 // redirecting constructor: RedirectionData |
5612 // closure function: ClosureData | 5612 // closure function: ClosureData |
5613 // irregexp function: Array[0] = JSRegExp | 5613 // irregexp function: Array[0] = RegExp |
5614 // Array[1] = Smi string specialization cid | 5614 // Array[1] = Smi string specialization cid |
5615 // native function: Array[0] = String native name | 5615 // native function: Array[0] = String native name |
5616 // Array[1] = Function implicit closure function | 5616 // Array[1] = Function implicit closure function |
5617 // regular function: Function for implicit closure function | 5617 // regular function: Function for implicit closure function |
5618 void Function::set_data(const Object& value) const { | 5618 void Function::set_data(const Object& value) const { |
5619 StorePointer(&raw_ptr()->data_, value.raw()); | 5619 StorePointer(&raw_ptr()->data_, value.raw()); |
5620 } | 5620 } |
5621 | 5621 |
5622 | 5622 |
5623 bool Function::IsInFactoryScope() const { | 5623 bool Function::IsInFactoryScope() const { |
(...skipping 13 matching lines...) Expand all Loading... |
5637 StorePointer(&raw_ptr()->name_, value.raw()); | 5637 StorePointer(&raw_ptr()->name_, value.raw()); |
5638 } | 5638 } |
5639 | 5639 |
5640 | 5640 |
5641 void Function::set_owner(const Object& value) const { | 5641 void Function::set_owner(const Object& value) const { |
5642 ASSERT(!value.IsNull()); | 5642 ASSERT(!value.IsNull()); |
5643 StorePointer(&raw_ptr()->owner_, value.raw()); | 5643 StorePointer(&raw_ptr()->owner_, value.raw()); |
5644 } | 5644 } |
5645 | 5645 |
5646 | 5646 |
5647 RawJSRegExp* Function::regexp() const { | 5647 RawRegExp* Function::regexp() const { |
5648 ASSERT(kind() == RawFunction::kIrregexpFunction); | 5648 ASSERT(kind() == RawFunction::kIrregexpFunction); |
5649 const Array& pair = Array::Cast(Object::Handle(raw_ptr()->data_)); | 5649 const Array& pair = Array::Cast(Object::Handle(raw_ptr()->data_)); |
5650 return JSRegExp::RawCast(pair.At(0)); | 5650 return RegExp::RawCast(pair.At(0)); |
5651 } | 5651 } |
5652 | 5652 |
5653 | 5653 |
5654 intptr_t Function::string_specialization_cid() const { | 5654 intptr_t Function::string_specialization_cid() const { |
5655 ASSERT(kind() == RawFunction::kIrregexpFunction); | 5655 ASSERT(kind() == RawFunction::kIrregexpFunction); |
5656 const Array& pair = Array::Cast(Object::Handle(raw_ptr()->data_)); | 5656 const Array& pair = Array::Cast(Object::Handle(raw_ptr()->data_)); |
5657 return Smi::Value(Smi::RawCast(pair.At(1))); | 5657 return Smi::Value(Smi::RawCast(pair.At(1))); |
5658 } | 5658 } |
5659 | 5659 |
5660 | 5660 |
5661 void Function::SetRegExpData(const JSRegExp& regexp, | 5661 void Function::SetRegExpData(const RegExp& regexp, |
5662 intptr_t string_specialization_cid) const { | 5662 intptr_t string_specialization_cid) const { |
5663 ASSERT(kind() == RawFunction::kIrregexpFunction); | 5663 ASSERT(kind() == RawFunction::kIrregexpFunction); |
5664 ASSERT(RawObject::IsStringClassId(string_specialization_cid)); | 5664 ASSERT(RawObject::IsStringClassId(string_specialization_cid)); |
5665 ASSERT(raw_ptr()->data_ == Object::null()); | 5665 ASSERT(raw_ptr()->data_ == Object::null()); |
5666 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); | 5666 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); |
5667 pair.SetAt(0, regexp); | 5667 pair.SetAt(0, regexp); |
5668 pair.SetAt(1, Smi::Handle(Smi::New(string_specialization_cid))); | 5668 pair.SetAt(1, Smi::Handle(Smi::New(string_specialization_cid))); |
5669 set_data(pair); | 5669 set_data(pair); |
5670 } | 5670 } |
5671 | 5671 |
(...skipping 15739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21411 index += OS::SNPrint((chars + index), | 21411 index += OS::SNPrint((chars + index), |
21412 (total_len + 1 - index), | 21412 (total_len + 1 - index), |
21413 "%s", | 21413 "%s", |
21414 frame_strings[i]); | 21414 frame_strings[i]); |
21415 } | 21415 } |
21416 chars[total_len] = '\0'; | 21416 chars[total_len] = '\0'; |
21417 return chars; | 21417 return chars; |
21418 } | 21418 } |
21419 | 21419 |
21420 | 21420 |
21421 void JSRegExp::set_pattern(const String& pattern) const { | 21421 void RegExp::set_pattern(const String& pattern) const { |
21422 StorePointer(&raw_ptr()->pattern_, pattern.raw()); | 21422 StorePointer(&raw_ptr()->pattern_, pattern.raw()); |
21423 } | 21423 } |
21424 | 21424 |
21425 | 21425 |
21426 void JSRegExp::set_function(intptr_t cid, const Function& value) const { | 21426 void RegExp::set_function(intptr_t cid, const Function& value) const { |
21427 StorePointer(FunctionAddr(cid), value.raw()); | 21427 StorePointer(FunctionAddr(cid), value.raw()); |
21428 } | 21428 } |
21429 | 21429 |
21430 | 21430 |
21431 void JSRegExp::set_bytecode(bool is_one_byte, const TypedData& bytecode) const { | 21431 void RegExp::set_bytecode(bool is_one_byte, const TypedData& bytecode) const { |
21432 if (is_one_byte) { | 21432 if (is_one_byte) { |
21433 StorePointer(&raw_ptr()->one_byte_bytecode_, bytecode.raw()); | 21433 StorePointer(&raw_ptr()->one_byte_bytecode_, bytecode.raw()); |
21434 } else { | 21434 } else { |
21435 StorePointer(&raw_ptr()->two_byte_bytecode_, bytecode.raw()); | 21435 StorePointer(&raw_ptr()->two_byte_bytecode_, bytecode.raw()); |
21436 } | 21436 } |
21437 } | 21437 } |
21438 | 21438 |
21439 | 21439 |
21440 void JSRegExp::set_num_bracket_expressions(intptr_t value) const { | 21440 void RegExp::set_num_bracket_expressions(intptr_t value) const { |
21441 StoreSmi(&raw_ptr()->num_bracket_expressions_, Smi::New(value)); | 21441 StoreSmi(&raw_ptr()->num_bracket_expressions_, Smi::New(value)); |
21442 } | 21442 } |
21443 | 21443 |
21444 | 21444 |
21445 RawJSRegExp* JSRegExp::New(Heap::Space space) { | 21445 RawRegExp* RegExp::New(Heap::Space space) { |
21446 JSRegExp& result = JSRegExp::Handle(); | 21446 RegExp& result = RegExp::Handle(); |
21447 { | 21447 { |
21448 RawObject* raw = Object::Allocate(JSRegExp::kClassId, | 21448 RawObject* raw = Object::Allocate(RegExp::kClassId, |
21449 JSRegExp::InstanceSize(), | 21449 RegExp::InstanceSize(), |
21450 space); | 21450 space); |
21451 NoSafepointScope no_safepoint; | 21451 NoSafepointScope no_safepoint; |
21452 result ^= raw; | 21452 result ^= raw; |
21453 result.set_type(kUnitialized); | 21453 result.set_type(kUnitialized); |
21454 result.set_flags(0); | 21454 result.set_flags(0); |
21455 result.set_num_registers(-1); | 21455 result.set_num_registers(-1); |
21456 } | 21456 } |
21457 return result.raw(); | 21457 return result.raw(); |
21458 } | 21458 } |
21459 | 21459 |
21460 | 21460 |
21461 void* JSRegExp::GetDataStartAddress() const { | 21461 void* RegExp::GetDataStartAddress() const { |
21462 intptr_t addr = reinterpret_cast<intptr_t>(raw_ptr()); | 21462 intptr_t addr = reinterpret_cast<intptr_t>(raw_ptr()); |
21463 return reinterpret_cast<void*>(addr + sizeof(RawJSRegExp)); | 21463 return reinterpret_cast<void*>(addr + sizeof(RawRegExp)); |
21464 } | 21464 } |
21465 | 21465 |
21466 | 21466 |
21467 RawJSRegExp* JSRegExp::FromDataStartAddress(void* data) { | 21467 RawRegExp* RegExp::FromDataStartAddress(void* data) { |
21468 JSRegExp& regexp = JSRegExp::Handle(); | 21468 RegExp& regexp = RegExp::Handle(); |
21469 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawJSRegExp); | 21469 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawRegExp); |
21470 regexp ^= RawObject::FromAddr(addr); | 21470 regexp ^= RawObject::FromAddr(addr); |
21471 return regexp.raw(); | 21471 return regexp.raw(); |
21472 } | 21472 } |
21473 | 21473 |
21474 | 21474 |
21475 const char* JSRegExp::Flags() const { | 21475 const char* RegExp::Flags() const { |
21476 switch (flags()) { | 21476 switch (flags()) { |
21477 case kGlobal | kIgnoreCase | kMultiLine : | 21477 case kGlobal | kIgnoreCase | kMultiLine : |
21478 case kIgnoreCase | kMultiLine : | 21478 case kIgnoreCase | kMultiLine : |
21479 return "im"; | 21479 return "im"; |
21480 case kGlobal | kIgnoreCase : | 21480 case kGlobal | kIgnoreCase : |
21481 case kIgnoreCase: | 21481 case kIgnoreCase: |
21482 return "i"; | 21482 return "i"; |
21483 case kGlobal | kMultiLine : | 21483 case kGlobal | kMultiLine : |
21484 case kMultiLine: | 21484 case kMultiLine: |
21485 return "m"; | 21485 return "m"; |
21486 default: | 21486 default: |
21487 break; | 21487 break; |
21488 } | 21488 } |
21489 return ""; | 21489 return ""; |
21490 } | 21490 } |
21491 | 21491 |
21492 | 21492 |
21493 bool JSRegExp::CanonicalizeEquals(const Instance& other) const { | 21493 bool RegExp::CanonicalizeEquals(const Instance& other) const { |
21494 if (this->raw() == other.raw()) { | 21494 if (this->raw() == other.raw()) { |
21495 return true; // "===". | 21495 return true; // "===". |
21496 } | 21496 } |
21497 if (other.IsNull() || !other.IsJSRegExp()) { | 21497 if (other.IsNull() || !other.IsRegExp()) { |
21498 return false; | 21498 return false; |
21499 } | 21499 } |
21500 const JSRegExp& other_js = JSRegExp::Cast(other); | 21500 const RegExp& other_js = RegExp::Cast(other); |
21501 // Match the pattern. | 21501 // Match the pattern. |
21502 const String& str1 = String::Handle(pattern()); | 21502 const String& str1 = String::Handle(pattern()); |
21503 const String& str2 = String::Handle(other_js.pattern()); | 21503 const String& str2 = String::Handle(other_js.pattern()); |
21504 if (!str1.Equals(str2)) { | 21504 if (!str1.Equals(str2)) { |
21505 return false; | 21505 return false; |
21506 } | 21506 } |
21507 // Match the flags. | 21507 // Match the flags. |
21508 if ((is_global() != other_js.is_global()) || | 21508 if ((is_global() != other_js.is_global()) || |
21509 (is_ignore_case() != other_js.is_ignore_case()) || | 21509 (is_ignore_case() != other_js.is_ignore_case()) || |
21510 (is_multi_line() != other_js.is_multi_line())) { | 21510 (is_multi_line() != other_js.is_multi_line())) { |
21511 return false; | 21511 return false; |
21512 } | 21512 } |
21513 return true; | 21513 return true; |
21514 } | 21514 } |
21515 | 21515 |
21516 | 21516 |
21517 const char* JSRegExp::ToCString() const { | 21517 const char* RegExp::ToCString() const { |
21518 const String& str = String::Handle(pattern()); | 21518 const String& str = String::Handle(pattern()); |
21519 return OS::SCreate(Thread::Current()->zone(), | 21519 return OS::SCreate(Thread::Current()->zone(), |
21520 "JSRegExp: pattern=%s flags=%s", str.ToCString(), Flags()); | 21520 "RegExp: pattern=%s flags=%s", str.ToCString(), Flags()); |
21521 } | 21521 } |
21522 | 21522 |
21523 | 21523 |
21524 RawWeakProperty* WeakProperty::New(Heap::Space space) { | 21524 RawWeakProperty* WeakProperty::New(Heap::Space space) { |
21525 ASSERT(Isolate::Current()->object_store()->weak_property_class() | 21525 ASSERT(Isolate::Current()->object_store()->weak_property_class() |
21526 != Class::null()); | 21526 != Class::null()); |
21527 RawObject* raw = Object::Allocate(WeakProperty::kClassId, | 21527 RawObject* raw = Object::Allocate(WeakProperty::kClassId, |
21528 WeakProperty::InstanceSize(), | 21528 WeakProperty::InstanceSize(), |
21529 space); | 21529 space); |
21530 return reinterpret_cast<RawWeakProperty*>(raw); | 21530 return reinterpret_cast<RawWeakProperty*>(raw); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21723 return UserTag::null(); | 21723 return UserTag::null(); |
21724 } | 21724 } |
21725 | 21725 |
21726 | 21726 |
21727 const char* UserTag::ToCString() const { | 21727 const char* UserTag::ToCString() const { |
21728 const String& tag_label = String::Handle(label()); | 21728 const String& tag_label = String::Handle(label()); |
21729 return tag_label.ToCString(); | 21729 return tag_label.ToCString(); |
21730 } | 21730 } |
21731 | 21731 |
21732 } // namespace dart | 21732 } // namespace dart |
OLD | NEW |