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

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: Make loads and stores byte relative 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 5513 matching lines...) Expand 10 before | Expand all | Expand 10 after
6635 RawArray* Array::Empty() { 6650 RawArray* Array::Empty() {
6636 return Isolate::Current()->object_store()->empty_array(); 6651 return Isolate::Current()->object_store()->empty_array();
6637 } 6652 }
6638 6653
6639 6654
6640 const char* ImmutableArray::ToCString() const { 6655 const char* ImmutableArray::ToCString() const {
6641 return "ImmutableArray"; 6656 return "ImmutableArray";
6642 } 6657 }
6643 6658
6644 6659
6660 RawByteBuffer* ByteBuffer::New(uint8_t* data,
6661 intptr_t len,
6662 Heap::Space space) {
6663 Isolate* isolate = Isolate::Current();
6664 const Class& byte_buffer_class =
6665 Class::Handle(isolate->object_store()->byte_buffer_class());
6666 ByteBuffer& result = ByteBuffer::Handle();
6667 {
6668 RawObject* raw = Object::Allocate(byte_buffer_class,
6669 ByteBuffer::InstanceSize(),
6670 space);
6671 NoGCScope no_gc;
6672 result ^= raw;
6673 result.SetLength(len);
6674 result.SetData(data);
6675 }
6676 return result.raw();
6677 }
6678
6679
6680 bool ByteBuffer::Equals(const Instance& other) const {
6681 if (this->raw() == other.raw()) {
6682 // Both handles point to the same raw instance.
6683 return true;
6684 }
6685
6686 if (!other.IsByteBuffer() || other.IsNull()) {
6687 return false;
6688 }
6689
6690 ByteBuffer& other_array = ByteBuffer::Handle();
6691 other_array ^= other.raw();
6692
6693 intptr_t len = this->Length();
6694 if (len != other_array.Length()) {
6695 return false;
6696 }
6697
6698 return !memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len);
6699 }
6700
6701
6702 const char* ByteBuffer::ToCString() const {
6703 return "ByteBuffer";
6704 }
6705
6706
6645 RawClosure* Closure::New(const Function& function, 6707 RawClosure* Closure::New(const Function& function,
6646 const Context& context, 6708 const Context& context,
6647 Heap::Space space) { 6709 Heap::Space space) {
6648 Isolate* isolate = Isolate::Current(); 6710 Isolate* isolate = Isolate::Current();
6649 ASSERT(context.isolate() == isolate); 6711 ASSERT(context.isolate() == isolate);
6650 6712
6651 const Class& cls = Class::Handle(function.signature_class()); 6713 const Class& cls = Class::Handle(function.signature_class());
6652 Closure& result = Closure::Handle(); 6714 Closure& result = Closure::Handle();
6653 { 6715 {
6654 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space); 6716 RawObject* raw = Object::Allocate(cls, Closure::InstanceSize(), space);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
6944 const String& str = String::Handle(pattern()); 7006 const String& str = String::Handle(pattern());
6945 const char* format = "JSRegExp: pattern=%s flags=%s"; 7007 const char* format = "JSRegExp: pattern=%s flags=%s";
6946 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7008 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6947 char* chars = reinterpret_cast<char*>( 7009 char* chars = reinterpret_cast<char*>(
6948 Isolate::Current()->current_zone()->Allocate(len + 1)); 7010 Isolate::Current()->current_zone()->Allocate(len + 1));
6949 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7011 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6950 return chars; 7012 return chars;
6951 } 7013 }
6952 7014
6953 } // namespace dart 7015 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698