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

Side by Side Diff: runtime/vm/object.cc

Issue 8429027: Add an external array type to support typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: wrap another native, tweak whitespace Created 9 years, 1 month 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/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
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
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
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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 return object_store->four_byte_string_class(); 1114 return object_store->four_byte_string_class();
1103 case kBool: 1115 case kBool:
1104 ASSERT(object_store->bool_class() != Class::null()); 1116 ASSERT(object_store->bool_class() != Class::null());
1105 return object_store->bool_class(); 1117 return object_store->bool_class();
1106 case kArray: 1118 case kArray:
1107 ASSERT(object_store->array_class() != Class::null()); 1119 ASSERT(object_store->array_class() != Class::null());
1108 return object_store->array_class(); 1120 return object_store->array_class();
1109 case kImmutableArray: 1121 case kImmutableArray:
1110 ASSERT(object_store->immutable_array_class() != Class::null()); 1122 ASSERT(object_store->immutable_array_class() != Class::null());
1111 return object_store->immutable_array_class(); 1123 return object_store->immutable_array_class();
1124 case kByteBuffer:
1125 ASSERT(object_store->byte_buffer_class() != Class::null());
1126 return object_store->byte_buffer_class();
1112 case kStacktrace: 1127 case kStacktrace:
1113 ASSERT(object_store->stacktrace_class() != Class::null()); 1128 ASSERT(object_store->stacktrace_class() != Class::null());
1114 return object_store->stacktrace_class(); 1129 return object_store->stacktrace_class();
1115 case kJSRegExp: 1130 case kJSRegExp:
1116 ASSERT(object_store->jsregexp_class() != Class::null()); 1131 ASSERT(object_store->jsregexp_class() != Class::null());
1117 return object_store->jsregexp_class(); 1132 return object_store->jsregexp_class();
1118 case kClosure: 1133 case kClosure:
1119 return Class::New<Closure>(); 1134 return Class::New<Closure>();
1120 case kInstance: 1135 case kInstance:
1121 return Class::New<Instance>(); 1136 return Class::New<Instance>();
(...skipping 5533 matching lines...) Expand 10 before | Expand all | Expand 10 after
6655 RawArray* Array::Empty() { 6670 RawArray* Array::Empty() {
6656 return Isolate::Current()->object_store()->empty_array(); 6671 return Isolate::Current()->object_store()->empty_array();
6657 } 6672 }
6658 6673
6659 6674
6660 const char* ImmutableArray::ToCString() const { 6675 const char* ImmutableArray::ToCString() const {
6661 return "ImmutableArray"; 6676 return "ImmutableArray";
6662 } 6677 }
6663 6678
6664 6679
6680 RawByteBuffer* ByteBuffer::New(uint8_t* data,
6681 intptr_t len,
6682 Heap::Space space) {
6683 Isolate* isolate = Isolate::Current();
6684 const Class& byte_buffer_class =
6685 Class::Handle(isolate->object_store()->byte_buffer_class());
6686 ByteBuffer& result = ByteBuffer::Handle();
6687 {
6688 RawObject* raw = Object::Allocate(byte_buffer_class,
6689 ByteBuffer::InstanceSize(),
6690 space);
6691 NoGCScope no_gc;
6692 result ^= raw;
6693 result.SetLength(len);
6694 result.SetData(data);
6695 }
6696 return result.raw();
6697 }
6698
6699
6700 bool ByteBuffer::Equals(const Instance& other) const {
6701 if (this->raw() == other.raw()) {
6702 // Both handles point to the same raw instance.
6703 return true;
6704 }
6705
6706 if (!other.IsByteBuffer() || other.IsNull()) {
6707 return false;
6708 }
6709
6710 ByteBuffer& other_array = ByteBuffer::Handle();
6711 other_array ^= other.raw();
6712
6713 intptr_t len = this->Length();
6714 if (len != other_array.Length()) {
6715 return false;
6716 }
6717
6718 return !memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len);
Ivan Posva 2011/11/16 22:50:01 Please do not use ints as boolean: return memcmp(.
cshapiro 2011/11/17 03:17:02 Certainly. Done.
6719 }
6720
6721
6722 const char* ByteBuffer::ToCString() const {
6723 return "ByteBuffer";
6724 }
6725
6726
6665 RawClosure* Closure::New(const Function& function, 6727 RawClosure* Closure::New(const Function& function,
6666 const Context& context, 6728 const Context& context,
6667 Heap::Space space) { 6729 Heap::Space space) {
6668 Isolate* isolate = Isolate::Current(); 6730 Isolate* isolate = Isolate::Current();
6669 ASSERT(context.isolate() == isolate); 6731 ASSERT(context.isolate() == isolate);
6670 6732
6671 const Class& cls = Class::Handle(function.signature_class()); 6733 const Class& cls = Class::Handle(function.signature_class());
6672 Closure& result = Closure::Handle(); 6734 Closure& result = Closure::Handle();
6673 { 6735 {
6674 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space); 6736 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
6964 const String& str = String::Handle(pattern()); 7026 const String& str = String::Handle(pattern());
6965 const char* format = "JSRegExp: pattern=%s flags=%s"; 7027 const char* format = "JSRegExp: pattern=%s flags=%s";
6966 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7028 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6967 char* chars = reinterpret_cast<char*>( 7029 char* chars = reinterpret_cast<char*>(
6968 Isolate::Current()->current_zone()->Allocate(len + 1)); 7030 Isolate::Current()->current_zone()->Allocate(len + 1));
6969 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7031 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6970 return chars; 7032 return chars;
6971 } 7033 }
6972 7034
6973 } // namespace dart 7035 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698