| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 390 |
| 391 cls = Class::New<TwoByteString>(); | 391 cls = Class::New<TwoByteString>(); |
| 392 object_store->set_two_byte_string_class(cls); | 392 object_store->set_two_byte_string_class(cls); |
| 393 | 393 |
| 394 cls = Class::New<FourByteString>(); | 394 cls = Class::New<FourByteString>(); |
| 395 object_store->set_four_byte_string_class(cls); | 395 object_store->set_four_byte_string_class(cls); |
| 396 | 396 |
| 397 cls = Class::New<Bool>(); | 397 cls = Class::New<Bool>(); |
| 398 object_store->set_bool_class(cls); | 398 object_store->set_bool_class(cls); |
| 399 | 399 |
| 400 cls = Class::New<ByteBuffer>(); |
| 401 object_store->set_byte_buffer_class(cls); |
| 402 |
| 400 cls = Class::New<UnhandledException>(); | 403 cls = Class::New<UnhandledException>(); |
| 401 object_store->set_unhandled_exception_class(cls); | 404 object_store->set_unhandled_exception_class(cls); |
| 402 | 405 |
| 403 cls = Class::New<Stacktrace>(); | 406 cls = Class::New<Stacktrace>(); |
| 404 object_store->set_stacktrace_class(cls); | 407 object_store->set_stacktrace_class(cls); |
| 405 // Set the super type so that the 'toString' method is implemented. | 408 // Set the super type so that the 'toString' method is implemented. |
| 406 type = object_store->object_type(); | 409 type = object_store->object_type(); |
| 407 cls.set_super_type(type); | 410 cls.set_super_type(type); |
| 408 | 411 |
| 409 cls = Class::New<JSRegExp>(); | 412 cls = Class::New<JSRegExp>(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 523 |
| 521 // Initialize the base interfaces used by the core VM classes. | 524 // Initialize the base interfaces used by the core VM classes. |
| 522 const Script& script = Script::Handle(Bootstrap::LoadScript()); | 525 const Script& script = Script::Handle(Bootstrap::LoadScript()); |
| 523 | 526 |
| 524 name = String::NewSymbol("Object"); | 527 name = String::NewSymbol("Object"); |
| 525 cls = object_store->object_class(); | 528 cls = object_store->object_class(); |
| 526 cls.set_name(name); | 529 cls.set_name(name); |
| 527 cls.set_script(script); | 530 cls.set_script(script); |
| 528 core_lib.AddClass(cls); | 531 core_lib.AddClass(cls); |
| 529 | 532 |
| 533 name = String::NewSymbol("ByteBuffer"); |
| 534 cls = object_store->byte_buffer_class(); |
| 535 cls.set_name(name); |
| 536 cls.set_script(script); |
| 537 core_lib.AddClass(cls); |
| 538 |
| 530 name = String::NewSymbol("Function"); | 539 name = String::NewSymbol("Function"); |
| 531 cls = Class::NewInterface(name, script); | 540 cls = Class::NewInterface(name, script); |
| 532 core_lib.AddClass(cls); | 541 core_lib.AddClass(cls); |
| 533 type = Type::NewNonParameterizedType(cls); | 542 type = Type::NewNonParameterizedType(cls); |
| 534 object_store->set_function_interface(type); | 543 object_store->set_function_interface(type); |
| 535 | 544 |
| 536 name = String::NewSymbol("num"); | 545 name = String::NewSymbol("num"); |
| 537 cls = Class::NewInterface(name, script); | 546 cls = Class::NewInterface(name, script); |
| 538 core_lib.AddClass(cls); | 547 core_lib.AddClass(cls); |
| 539 type = Type::NewNonParameterizedType(cls); | 548 type = Type::NewNonParameterizedType(cls); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 cls = Class::New<Array>(); | 627 cls = Class::New<Array>(); |
| 619 object_store->set_array_class(cls); | 628 object_store->set_array_class(cls); |
| 620 | 629 |
| 621 Array& empty_array = Array::Handle(); | 630 Array& empty_array = Array::Handle(); |
| 622 empty_array = Array::New(0); | 631 empty_array = Array::New(0); |
| 623 object_store->set_empty_array(empty_array); | 632 object_store->set_empty_array(empty_array); |
| 624 | 633 |
| 625 cls = Class::New<ImmutableArray>(); | 634 cls = Class::New<ImmutableArray>(); |
| 626 object_store->set_immutable_array_class(cls); | 635 object_store->set_immutable_array_class(cls); |
| 627 | 636 |
| 637 cls = Class::New<ByteBuffer>(); |
| 638 object_store->set_byte_buffer_class(cls); |
| 639 |
| 628 cls = Class::New<Instance>(); | 640 cls = Class::New<Instance>(); |
| 629 object_store->set_object_class(cls); | 641 object_store->set_object_class(cls); |
| 630 | 642 |
| 631 cls = Class::New<Smi>(); | 643 cls = Class::New<Smi>(); |
| 632 object_store->set_smi_class(cls); | 644 object_store->set_smi_class(cls); |
| 633 | 645 |
| 634 cls = Class::New<Mint>(); | 646 cls = Class::New<Mint>(); |
| 635 object_store->set_mint_class(cls); | 647 object_store->set_mint_class(cls); |
| 636 | 648 |
| 637 cls = Class::New<Double>(); | 649 cls = Class::New<Double>(); |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 return object_store->four_byte_string_class(); | 1112 return object_store->four_byte_string_class(); |
| 1101 case kBool: | 1113 case kBool: |
| 1102 ASSERT(object_store->bool_class() != Class::null()); | 1114 ASSERT(object_store->bool_class() != Class::null()); |
| 1103 return object_store->bool_class(); | 1115 return object_store->bool_class(); |
| 1104 case kArray: | 1116 case kArray: |
| 1105 ASSERT(object_store->array_class() != Class::null()); | 1117 ASSERT(object_store->array_class() != Class::null()); |
| 1106 return object_store->array_class(); | 1118 return object_store->array_class(); |
| 1107 case kImmutableArray: | 1119 case kImmutableArray: |
| 1108 ASSERT(object_store->immutable_array_class() != Class::null()); | 1120 ASSERT(object_store->immutable_array_class() != Class::null()); |
| 1109 return object_store->immutable_array_class(); | 1121 return object_store->immutable_array_class(); |
| 1122 case kByteBuffer: |
| 1123 ASSERT(object_store->byte_buffer_class() != Class::null()); |
| 1124 return object_store->byte_buffer_class(); |
| 1110 case kStacktrace: | 1125 case kStacktrace: |
| 1111 ASSERT(object_store->stacktrace_class() != Class::null()); | 1126 ASSERT(object_store->stacktrace_class() != Class::null()); |
| 1112 return object_store->stacktrace_class(); | 1127 return object_store->stacktrace_class(); |
| 1113 case kJSRegExp: | 1128 case kJSRegExp: |
| 1114 ASSERT(object_store->jsregexp_class() != Class::null()); | 1129 ASSERT(object_store->jsregexp_class() != Class::null()); |
| 1115 return object_store->jsregexp_class(); | 1130 return object_store->jsregexp_class(); |
| 1116 case kClosure: | 1131 case kClosure: |
| 1117 return Class::New<Closure>(); | 1132 return Class::New<Closure>(); |
| 1118 case kInstance: | 1133 case kInstance: |
| 1119 return Class::New<Instance>(); | 1134 return Class::New<Instance>(); |
| (...skipping 5510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6630 RawArray* Array::Empty() { | 6645 RawArray* Array::Empty() { |
| 6631 return Isolate::Current()->object_store()->empty_array(); | 6646 return Isolate::Current()->object_store()->empty_array(); |
| 6632 } | 6647 } |
| 6633 | 6648 |
| 6634 | 6649 |
| 6635 const char* ImmutableArray::ToCString() const { | 6650 const char* ImmutableArray::ToCString() const { |
| 6636 return "ImmutableArray"; | 6651 return "ImmutableArray"; |
| 6637 } | 6652 } |
| 6638 | 6653 |
| 6639 | 6654 |
| 6655 RawByteBuffer* ByteBuffer::New(uint8_t* data, |
| 6656 intptr_t len, |
| 6657 Heap::Space space) { |
| 6658 Isolate* isolate = Isolate::Current(); |
| 6659 const Class& byte_buffer_class = |
| 6660 Class::Handle(isolate->object_store()->byte_buffer_class()); |
| 6661 ByteBuffer& result = ByteBuffer::Handle(); |
| 6662 { |
| 6663 RawObject* raw = Object::Allocate(byte_buffer_class, |
| 6664 ByteBuffer::InstanceSize(), |
| 6665 space); |
| 6666 NoGCScope no_gc; |
| 6667 result ^= raw; |
| 6668 result.SetLength(len); |
| 6669 result.SetData(data); |
| 6670 } |
| 6671 return result.raw(); |
| 6672 } |
| 6673 |
| 6674 |
| 6675 bool ByteBuffer::Equals(const Instance& other) const { |
| 6676 if (this->raw() == other.raw()) { |
| 6677 // Both handles point to the same raw instance. |
| 6678 return true; |
| 6679 } |
| 6680 |
| 6681 if (!other.IsByteBuffer() || other.IsNull()) { |
| 6682 return false; |
| 6683 } |
| 6684 |
| 6685 ByteBuffer& other_array = ByteBuffer::Handle(); |
| 6686 other_array ^= other.raw(); |
| 6687 |
| 6688 intptr_t len = this->Length(); |
| 6689 if (len != other_array.Length()) { |
| 6690 return false; |
| 6691 } |
| 6692 |
| 6693 return !memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len); |
| 6694 } |
| 6695 |
| 6696 |
| 6697 const char* ByteBuffer::ToCString() const { |
| 6698 return "ByteBuffer"; |
| 6699 } |
| 6700 |
| 6701 |
| 6640 RawClosure* Closure::New(const Function& function, | 6702 RawClosure* Closure::New(const Function& function, |
| 6641 const Context& context, | 6703 const Context& context, |
| 6642 Heap::Space space) { | 6704 Heap::Space space) { |
| 6643 Isolate* isolate = Isolate::Current(); | 6705 Isolate* isolate = Isolate::Current(); |
| 6644 ASSERT(context.isolate() == isolate); | 6706 ASSERT(context.isolate() == isolate); |
| 6645 | 6707 |
| 6646 const Class& cls = Class::Handle(function.signature_class()); | 6708 const Class& cls = Class::Handle(function.signature_class()); |
| 6647 Closure& result = Closure::Handle(); | 6709 Closure& result = Closure::Handle(); |
| 6648 { | 6710 { |
| 6649 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space); | 6711 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6939 const String& str = String::Handle(pattern()); | 7001 const String& str = String::Handle(pattern()); |
| 6940 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7002 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 6941 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7003 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 6942 char* chars = reinterpret_cast<char*>( | 7004 char* chars = reinterpret_cast<char*>( |
| 6943 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7005 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 6944 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7006 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 6945 return chars; | 7007 return chars; |
| 6946 } | 7008 } |
| 6947 | 7009 |
| 6948 } // namespace dart | 7010 } // namespace dart |
| OLD | NEW |