| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // be true before calling Class::New<Class>(), or it will fail. | 232 // be true before calling Class::New<Class>(), or it will fail. |
| 233 class_class_ = Class::Handle().raw(); // Set 'class_class_' to 'null_'. | 233 class_class_ = Class::Handle().raw(); // Set 'class_class_' to 'null_'. |
| 234 cls = Class::New<Class>(); | 234 cls = Class::New<Class>(); |
| 235 cls.set_is_finalized(); | 235 cls.set_is_finalized(); |
| 236 class_class_ = cls.raw(); | 236 class_class_ = cls.raw(); |
| 237 // Make the class_ field point to itself. | 237 // Make the class_ field point to itself. |
| 238 class_class_->ptr()->class_ = class_class_; | 238 class_class_->ptr()->class_ = class_class_; |
| 239 | 239 |
| 240 // Allocate and initialize the null class. | 240 // Allocate and initialize the null class. |
| 241 cls = Class::New<Instance>(); | 241 cls = Class::New<Instance>(); |
| 242 cls.set_is_finalized(); | |
| 243 null_class_ = cls.raw(); | 242 null_class_ = cls.raw(); |
| 244 | 243 |
| 245 // Complete initialization of null_ instance, i.e. initialize its class_ | 244 // Complete initialization of null_ instance, i.e. initialize its class_ |
| 246 // field. | 245 // field. |
| 247 null_->ptr()->class_ = null_class_; | 246 null_->ptr()->class_ = null_class_; |
| 248 | 247 |
| 249 // Allocate and initialize the sentinel values of an instance class. | 248 // Allocate and initialize the sentinel values of an instance class. |
| 250 { | 249 { |
| 251 cls = Class::New<Instance>(); | 250 cls = Class::New<Instance>(); |
| 252 Instance& sentinel = Instance::Handle(); | 251 Instance& sentinel = Instance::Handle(); |
| 253 sentinel ^= Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); | 252 sentinel ^= Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); |
| 254 sentinel_ = sentinel.raw(); | 253 sentinel_ = sentinel.raw(); |
| 255 | 254 |
| 256 Instance& transition_sentinel = Instance::Handle(); | 255 Instance& transition_sentinel = Instance::Handle(); |
| 257 transition_sentinel ^= | 256 transition_sentinel ^= |
| 258 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); | 257 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); |
| 259 transition_sentinel_ = transition_sentinel.raw(); | 258 transition_sentinel_ = transition_sentinel.raw(); |
| 260 } | 259 } |
| 261 | 260 |
| 262 // The interface "Dynamic" is not a VM internal class. It is the type class of | 261 // The interface "Dynamic" is not a VM internal class. It is the type class of |
| 263 // the "unknown type". For efficiency, we allocate it in the VM isolate. | 262 // the "unknown type". For efficiency, we allocate it in the VM isolate. |
| 264 // Therefore, it cannot have a heap allocated name (the name is hard coded, | 263 // Therefore, it cannot have a heap allocated name (the name is hard coded, |
| 265 // see GetSingletonClassIndex) and its array fields cannot be set to the empty | 264 // see GetSingletonClassIndex) and its array fields cannot be set to the empty |
| 266 // array, but remain null. | 265 // array, but remain null. |
| 267 cls = Class::New<Instance>(); | 266 cls = Class::New<Instance>(); |
| 268 cls.set_is_finalized(); | |
| 269 cls.set_is_interface(); | 267 cls.set_is_interface(); |
| 270 dynamic_class_ = cls.raw(); | 268 dynamic_class_ = cls.raw(); |
| 271 | 269 |
| 272 // Allocate the remaining VM internal classes. | 270 // Allocate the remaining VM internal classes. |
| 273 cls = Class::New<UnresolvedClass>(); | 271 cls = Class::New<UnresolvedClass>(); |
| 274 unresolved_class_class_ = cls.raw(); | 272 unresolved_class_class_ = cls.raw(); |
| 275 | 273 |
| 276 cls = Class::New<Instance>(); | 274 cls = Class::New<Instance>(); |
| 277 cls.set_is_finalized(); | |
| 278 void_class_ = cls.raw(); | 275 void_class_ = cls.raw(); |
| 279 | 276 |
| 280 cls = Class::New<ParameterizedType>(); | 277 cls = Class::New<ParameterizedType>(); |
| 281 parameterized_type_class_ = cls.raw(); | 278 parameterized_type_class_ = cls.raw(); |
| 282 | 279 |
| 283 cls = Class::New<TypeParameter>(); | 280 cls = Class::New<TypeParameter>(); |
| 284 type_parameter_class_ = cls.raw(); | 281 type_parameter_class_ = cls.raw(); |
| 285 | 282 |
| 286 cls = Class::New<InstantiatedType>(); | 283 cls = Class::New<InstantiatedType>(); |
| 287 instantiated_type_class_ = cls.raw(); | 284 instantiated_type_class_ = cls.raw(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 cls = Class::New<ContextScope>(); | 328 cls = Class::New<ContextScope>(); |
| 332 context_scope_class_ = cls.raw(); | 329 context_scope_class_ = cls.raw(); |
| 333 | 330 |
| 334 cls = Class::New<ApiFailure>(); | 331 cls = Class::New<ApiFailure>(); |
| 335 api_failure_class_ = cls.raw(); | 332 api_failure_class_ = cls.raw(); |
| 336 | 333 |
| 337 ASSERT(class_class() != null_); | 334 ASSERT(class_class() != null_); |
| 338 } | 335 } |
| 339 | 336 |
| 340 | 337 |
| 341 RawClass* Object::CreateAndRegisterCoreInterface(const char* cname, | |
| 342 const Script& script, | |
| 343 const Library& core_lib) { | |
| 344 const String& name = String::Handle(String::NewSymbol(cname)); | |
| 345 const Class& cls = Class::Handle(Class::NewInterface(name, script)); | |
| 346 core_lib.AddClass(cls); | |
| 347 return cls.raw(); | |
| 348 } | |
| 349 | |
| 350 | |
| 351 void Object::RegisterCoreImplClass(const Class& cls, | |
| 352 const char* cname, | |
| 353 const Script& impl_script, | |
| 354 const Library& core_impl_lib) { | |
| 355 const String& name = String::Handle(String::NewSymbol(cname)); | |
| 356 cls.set_name(name); | |
| 357 cls.set_script(impl_script); | |
| 358 core_impl_lib.AddClass(cls); | |
| 359 } | |
| 360 | |
| 361 | |
| 362 void Object::Init(Isolate* isolate) { | 338 void Object::Init(Isolate* isolate) { |
| 363 TIMERSCOPE(time_bootstrap); | 339 TIMERSCOPE(time_bootstrap); |
| 364 ObjectStore* object_store = isolate->object_store(); | 340 ObjectStore* object_store = isolate->object_store(); |
| 365 | 341 |
| 366 Class& cls = Class::Handle(); | 342 Class& cls = Class::Handle(); |
| 367 Type& type = Type::Handle(); | 343 Type& type = Type::Handle(); |
| 344 String& name = String::Handle(); |
| 368 Array& array = Array::Handle(); | 345 Array& array = Array::Handle(); |
| 369 | 346 |
| 370 // All RawArray fields will be initialized to an empty array, therefore | 347 // All RawArray fields will be initialized to an empty array, therefore |
| 371 // initialize array class first. | 348 // initialize array class first. |
| 372 cls = Class::New<Array>(); | 349 cls = Class::New<Array>(); |
| 373 object_store->set_array_class(cls); | 350 object_store->set_array_class(cls); |
| 374 | 351 |
| 375 // Array and ImmutableArray are the only VM classes that are parameterized. | 352 // Array and ImmutableArray are the only VM classes that are parameterized. |
| 376 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 353 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we |
| 377 // need to set the offset of their type_arguments_ field, which is explicitly | 354 // need to set the offset of their type_arguments_ field, which is explicitly |
| 378 // declared in RawArray. | 355 // declared in RawArray. |
| 379 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); | 356 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); |
| 380 | 357 |
| 381 Array& empty_array = Array::Handle(); | 358 Array& empty_array = Array::Handle(); |
| 382 empty_array = Array::New(0, Heap::kOld); | 359 empty_array = Array::New(0, Heap::kOld); |
| 383 object_store->set_empty_array(empty_array); | 360 object_store->set_empty_array(empty_array); |
| 384 | 361 |
| 385 // Re-initialize fields of the array class now that the empty array | 362 // Re-initialize fields of the array class now that the empty array |
| 386 // has been created. | 363 // has been created. |
| 387 cls.InitEmptyFields(); | 364 cls.InitEmptyFields(); |
| 388 | 365 |
| 366 cls = Class::New<ImmutableArray>(); |
| 367 object_store->set_immutable_array_class(cls); |
| 368 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); |
| 369 |
| 370 // Allocate and initialize the object class and type. |
| 371 cls = Class::New<Instance>(); |
| 372 object_store->set_object_class(cls); |
| 373 type = Type::NewNonParameterizedType(cls); |
| 374 object_store->set_object_type(type); |
| 375 |
| 376 cls = Class::New<Smi>(); |
| 377 object_store->set_smi_class(cls); |
| 378 |
| 379 cls = Class::New<Mint>(); |
| 380 object_store->set_mint_class(cls); |
| 381 |
| 382 cls = Class::New<Bigint>(); |
| 383 object_store->set_bigint_class(cls); |
| 384 |
| 385 cls = Class::New<Double>(); |
| 386 object_store->set_double_class(cls); |
| 387 |
| 388 cls = Class::New<OneByteString>(); |
| 389 object_store->set_one_byte_string_class(cls); |
| 390 |
| 391 cls = Class::New<TwoByteString>(); |
| 392 object_store->set_two_byte_string_class(cls); |
| 393 |
| 394 cls = Class::New<FourByteString>(); |
| 395 object_store->set_four_byte_string_class(cls); |
| 396 |
| 397 cls = Class::New<Bool>(); |
| 398 object_store->set_bool_class(cls); |
| 399 |
| 400 cls = Class::New<UnhandledException>(); |
| 401 object_store->set_unhandled_exception_class(cls); |
| 402 |
| 403 cls = Class::New<Stacktrace>(); |
| 404 object_store->set_stacktrace_class(cls); |
| 405 // Set the super type so that the 'toString' method is implemented. |
| 406 type = object_store->object_type(); |
| 407 cls.set_super_type(type); |
| 408 |
| 409 cls = Class::New<JSRegExp>(); |
| 410 object_store->set_jsregexp_class(cls); |
| 411 |
| 389 // Setup the symbol table used within the String class. | 412 // Setup the symbol table used within the String class. |
| 390 const int kInitialSymbolTableSize = 16; | 413 const int kInitialSymbolTableSize = 16; |
| 391 array = Array::New(kInitialSymbolTableSize + 1); | 414 array = Array::New(kInitialSymbolTableSize + 1); |
| 392 // Last element contains the count of used slots. | 415 // Last element contains the count of used slots. |
| 393 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); | 416 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); |
| 394 object_store->set_symbol_table(array); | 417 object_store->set_symbol_table(array); |
| 395 | 418 |
| 396 // Pre-allocate the OneByteString class needed by the symbol table. | |
| 397 cls = Class::New<OneByteString>(); | |
| 398 object_store->set_one_byte_string_class(cls); | |
| 399 | |
| 400 // Basic infrastructure has been setup, initialize the class dictionary. | 419 // Basic infrastructure has been setup, initialize the class dictionary. |
| 401 Library::InitCoreLibrary(isolate); | 420 Library::InitCoreLibrary(isolate); |
| 402 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 421 Library& core_lib = Library::Handle(isolate->object_store()->core_library()); |
| 403 ASSERT(!core_lib.IsNull()); | 422 ASSERT(!core_lib.IsNull()); |
| 404 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | 423 Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| 405 ASSERT(!core_impl_lib.IsNull()); | 424 ASSERT(!core_impl_lib.IsNull()); |
| 406 | 425 |
| 407 object_store->set_pending_classes(Array::Handle()); | 426 // Allocate pre-initialized values. |
| 427 Bool& bool_value = Bool::Handle(); |
| 428 bool_value = Bool::New(true); |
| 429 object_store->set_true_value(bool_value); |
| 430 bool_value = Bool::New(false); |
| 431 object_store->set_false_value(bool_value); |
| 432 |
| 433 object_store->set_pending_classes(Array::Handle(Array::Empty())); |
| 408 | 434 |
| 409 Context& context = Context::Handle(Context::New(0)); | 435 Context& context = Context::Handle(Context::New(0)); |
| 410 object_store->set_empty_context(context); | 436 object_store->set_empty_context(context); |
| 411 | 437 |
| 412 // Now that the symbol table is initialized and that the core dictionary as | 438 // Now that the String class is initialized and the dictionary has been setup, |
| 413 // well as the core implementation dictionary have been setup, preallocate | 439 // add the names to preallocated classes and register them in the dictionary. |
| 414 // remaining classes and register them by name in the dictionaries. | |
| 415 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript()); | 440 const Script& impl_script = Script::Handle(Bootstrap::LoadImplScript()); |
| 416 GrowableArray<const Class*> pending_classes; | |
| 417 | 441 |
| 418 cls = Class::New<Smi>(); | 442 name = String::NewSymbol("Smi"); |
| 419 object_store->set_smi_class(cls); | 443 cls = object_store->smi_class(); |
| 420 RegisterCoreImplClass(cls, "Smi", impl_script, core_impl_lib); | 444 cls.set_name(name); |
| 421 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 445 cls.set_script(impl_script); |
| 446 core_impl_lib.AddClass(cls); |
| 422 | 447 |
| 423 cls = Class::New<Mint>(); | 448 name = String::NewSymbol("OneByteString"); |
| 424 object_store->set_mint_class(cls); | 449 cls = object_store->one_byte_string_class(); |
| 425 RegisterCoreImplClass(cls, "Mint", impl_script, core_impl_lib); | 450 cls.set_name(name); |
| 426 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 451 cls.set_script(impl_script); |
| 452 core_impl_lib.AddClass(cls); |
| 427 | 453 |
| 428 cls = Class::New<Bigint>(); | 454 name = String::NewSymbol("TwoByteString"); |
| 429 object_store->set_bigint_class(cls); | 455 cls = object_store->two_byte_string_class(); |
| 430 RegisterCoreImplClass(cls, "Bigint", impl_script, core_impl_lib); | 456 cls.set_name(name); |
| 431 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 457 cls.set_script(impl_script); |
| 458 core_impl_lib.AddClass(cls); |
| 432 | 459 |
| 433 cls = Class::New<Double>(); | 460 name = String::NewSymbol("FourByteString"); |
| 434 object_store->set_double_class(cls); | 461 cls = object_store->four_byte_string_class(); |
| 435 RegisterCoreImplClass(cls, "Double", impl_script, core_impl_lib); | 462 cls.set_name(name); |
| 436 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 463 cls.set_script(impl_script); |
| 464 core_impl_lib.AddClass(cls); |
| 437 | 465 |
| 438 cls = Class::New<Bool>(); | 466 name = String::NewSymbol("Mint"); |
| 439 object_store->set_bool_class(cls); | 467 cls = object_store->mint_class(); |
| 440 RegisterCoreImplClass(cls, "Bool", impl_script, core_impl_lib); | 468 cls.set_name(name); |
| 441 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 469 cls.set_script(impl_script); |
| 470 core_impl_lib.AddClass(cls); |
| 442 | 471 |
| 443 cls = object_store->array_class(); // Was allocated above. | 472 name = String::NewSymbol("Bigint"); |
| 444 RegisterCoreImplClass(cls, "ObjectArray", impl_script, core_impl_lib); | 473 cls = object_store->bigint_class(); |
| 445 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 474 cls.set_name(name); |
| 475 cls.set_script(impl_script); |
| 476 core_impl_lib.AddClass(cls); |
| 446 | 477 |
| 447 cls = Class::New<ImmutableArray>(); | 478 name = String::NewSymbol("Double"); |
| 448 object_store->set_immutable_array_class(cls); | 479 cls = object_store->double_class(); |
| 449 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); | 480 cls.set_name(name); |
| 481 cls.set_script(impl_script); |
| 482 core_impl_lib.AddClass(cls); |
| 483 |
| 484 name = String::NewSymbol("Bool"); |
| 485 cls = object_store->bool_class(); |
| 486 cls.set_name(name); |
| 487 cls.set_script(impl_script); |
| 488 core_impl_lib.AddClass(cls); |
| 489 |
| 490 name = String::NewSymbol("ObjectArray"); |
| 491 cls = object_store->array_class(); |
| 492 cls.set_name(name); |
| 493 cls.set_script(impl_script); |
| 494 core_impl_lib.AddClass(cls); |
| 495 |
| 496 name = String::NewSymbol("ImmutableArray"); |
| 497 cls = object_store->immutable_array_class(); |
| 450 ASSERT(object_store->immutable_array_class() != object_store->array_class()); | 498 ASSERT(object_store->immutable_array_class() != object_store->array_class()); |
| 451 RegisterCoreImplClass(cls, "ImmutableArray", impl_script, core_impl_lib); | 499 cls.set_name(name); |
| 452 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 500 cls.set_script(impl_script); |
| 501 core_impl_lib.AddClass(cls); |
| 453 | 502 |
| 454 cls = object_store->one_byte_string_class(); // Was allocated above. | 503 name = String::NewSymbol("UnhandledException"); |
| 455 RegisterCoreImplClass(cls, "OneByteString", impl_script, core_impl_lib); | 504 cls = object_store->unhandled_exception_class(); |
| 456 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 505 cls.set_name(name); |
| 506 cls.set_script(impl_script); |
| 507 core_impl_lib.AddClass(cls); |
| 457 | 508 |
| 458 cls = Class::New<TwoByteString>(); | 509 name = String::NewSymbol("Stacktrace"); |
| 459 object_store->set_two_byte_string_class(cls); | 510 cls = object_store->stacktrace_class(); |
| 460 RegisterCoreImplClass(cls, "TwoByteString", impl_script, core_impl_lib); | 511 cls.set_name(name); |
| 461 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 512 cls.set_script(impl_script); |
| 513 core_impl_lib.AddClass(cls); |
| 462 | 514 |
| 463 cls = Class::New<FourByteString>(); | 515 name = String::NewSymbol("JSSyntaxRegExp"); |
| 464 object_store->set_four_byte_string_class(cls); | 516 cls = object_store->jsregexp_class(); |
| 465 RegisterCoreImplClass(cls, "FourByteString", impl_script, core_impl_lib); | 517 cls.set_name(name); |
| 466 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 518 cls.set_script(impl_script); |
| 467 | 519 core_impl_lib.AddClass(cls); |
| 468 cls = Class::New<UnhandledException>(); | |
| 469 object_store->set_unhandled_exception_class(cls); | |
| 470 RegisterCoreImplClass(cls, "UnhandledException", impl_script, core_impl_lib); | |
| 471 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | |
| 472 | |
| 473 cls = Class::New<Stacktrace>(); | |
| 474 object_store->set_stacktrace_class(cls); | |
| 475 RegisterCoreImplClass(cls, "Stacktrace", impl_script, core_impl_lib); | |
| 476 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | |
| 477 // Super type set below, after Object is allocated. | |
| 478 | |
| 479 cls = Class::New<JSRegExp>(); | |
| 480 object_store->set_jsregexp_class(cls); | |
| 481 RegisterCoreImplClass(cls, "JSSyntaxRegExp", impl_script, core_impl_lib); | |
| 482 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | |
| 483 | 520 |
| 484 // Initialize the base interfaces used by the core VM classes. | 521 // Initialize the base interfaces used by the core VM classes. |
| 485 const Script& script = Script::Handle(Bootstrap::LoadScript()); | 522 const Script& script = Script::Handle(Bootstrap::LoadScript()); |
| 486 | 523 |
| 487 // Allocate and initialize the Object class and type. | 524 name = String::NewSymbol("Object"); |
| 488 // Object class is the only pre-allocated non-interface in the core library. | 525 cls = object_store->object_class(); |
| 489 cls = Class::New<Instance>(); | 526 cls.set_name(name); |
| 490 object_store->set_object_class(cls); | |
| 491 cls.set_name(String::Handle(String::NewSymbol("Object"))); | |
| 492 cls.set_script(script); | 527 cls.set_script(script); |
| 493 core_lib.AddClass(cls); | 528 core_lib.AddClass(cls); |
| 494 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | |
| 495 type = Type::NewNonParameterizedType(cls); | |
| 496 object_store->set_object_type(type); | |
| 497 | 529 |
| 498 // Set the super type of class Stacktrace to Object type so that the | 530 name = String::NewSymbol("Function"); |
| 499 // 'toString' method is implemented. | 531 cls = Class::NewInterface(name, script); |
| 500 cls = object_store->stacktrace_class(); | 532 core_lib.AddClass(cls); |
| 501 cls.set_super_type(type); | |
| 502 | |
| 503 cls = CreateAndRegisterCoreInterface("Function", script, core_lib); | |
| 504 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | |
| 505 type = Type::NewNonParameterizedType(cls); | 533 type = Type::NewNonParameterizedType(cls); |
| 506 object_store->set_function_interface(type); | 534 object_store->set_function_interface(type); |
| 507 | 535 |
| 508 cls = CreateAndRegisterCoreInterface("num", script, core_lib); | 536 name = String::NewSymbol("num"); |
| 509 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 537 cls = Class::NewInterface(name, script); |
| 538 core_lib.AddClass(cls); |
| 510 type = Type::NewNonParameterizedType(cls); | 539 type = Type::NewNonParameterizedType(cls); |
| 511 object_store->set_number_interface(type); | 540 object_store->set_number_interface(type); |
| 512 | 541 |
| 513 cls = CreateAndRegisterCoreInterface("int", script, core_lib); | 542 name = String::NewSymbol("int"); |
| 514 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 543 cls = Class::NewInterface(name, script); |
| 544 core_lib.AddClass(cls); |
| 515 type = Type::NewNonParameterizedType(cls); | 545 type = Type::NewNonParameterizedType(cls); |
| 516 object_store->set_int_interface(type); | 546 object_store->set_int_interface(type); |
| 517 | 547 |
| 518 cls = CreateAndRegisterCoreInterface("double", script, core_lib); | 548 name = String::NewSymbol("double"); |
| 519 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 549 cls = Class::NewInterface(name, script); |
| 550 core_lib.AddClass(cls); |
| 520 type = Type::NewNonParameterizedType(cls); | 551 type = Type::NewNonParameterizedType(cls); |
| 521 object_store->set_double_interface(type); | 552 object_store->set_double_interface(type); |
| 522 | 553 |
| 523 cls = CreateAndRegisterCoreInterface("String", script, core_lib); | 554 name = String::NewSymbol("String"); |
| 524 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 555 cls = Class::NewInterface(name, script); |
| 556 core_lib.AddClass(cls); |
| 525 type = Type::NewNonParameterizedType(cls); | 557 type = Type::NewNonParameterizedType(cls); |
| 526 object_store->set_string_interface(type); | 558 object_store->set_string_interface(type); |
| 527 | 559 |
| 528 cls = CreateAndRegisterCoreInterface("bool", script, core_lib); | 560 name = String::NewSymbol("bool"); |
| 529 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 561 cls = Class::NewInterface(name, script); |
| 562 core_lib.AddClass(cls); |
| 530 type = Type::NewNonParameterizedType(cls); | 563 type = Type::NewNonParameterizedType(cls); |
| 531 object_store->set_bool_interface(type); | 564 object_store->set_bool_interface(type); |
| 532 | 565 |
| 533 cls = CreateAndRegisterCoreInterface("List", script, core_lib); | 566 name = String::NewSymbol("List"); |
| 534 pending_classes.Add(&Class::ZoneHandle(cls.raw())); | 567 cls = Class::NewInterface(name, script); |
| 568 core_lib.AddClass(cls); |
| 535 type = Type::NewNonParameterizedType(cls); | 569 type = Type::NewNonParameterizedType(cls); |
| 536 object_store->set_list_interface(type); | 570 object_store->set_list_interface(type); |
| 537 | 571 |
| 538 // The classes 'Null' and 'void' are not registered in the class dictionary, | 572 // The classes 'Null' and 'void' are not registered in the class dictionary, |
| 539 // because their names are reserved keywords. Their names are not heap | 573 // because their names are reserved keywords. Their names are not heap |
| 540 // allocated, because the classes reside in the VM isolate. | 574 // allocated, because the classes reside in the VM isolate. |
| 541 // The corresponding types are stored in the object store. | 575 // The corresponding types are stored in the object store. |
| 542 cls = null_class_; | 576 cls = null_class_; |
| 543 type = Type::NewNonParameterizedType(cls); | 577 type = Type::NewNonParameterizedType(cls); |
| 544 object_store->set_null_type(type); | 578 object_store->set_null_type(type); |
| 545 | 579 |
| 546 cls = void_class_; | 580 cls = void_class_; |
| 547 type = Type::NewNonParameterizedType(cls); | 581 type = Type::NewNonParameterizedType(cls); |
| 548 object_store->set_void_type(type); | 582 object_store->set_void_type(type); |
| 549 | 583 |
| 550 // The class 'Dynamic' is registered in the class dictionary because its name | 584 // The class 'Dynamic' is registered in the class dictionary because its name |
| 551 // is a built-in identifier, rather than a reserved keyword. Its name is not | 585 // is a built-in identifier, rather than a reserved keyword. Its name is not |
| 552 // heap allocated, because the class resides in the VM isolate. | 586 // heap allocated, because the class resides in the VM isolate. |
| 553 // The corresponding type, the "unknown type", is stored in the object store. | 587 // The corresponding type, the "unknown type", is stored in the object store. |
| 554 cls = dynamic_class_; | 588 cls = dynamic_class_; |
| 555 type = Type::NewNonParameterizedType(cls); | 589 type = Type::NewNonParameterizedType(cls); |
| 556 object_store->set_dynamic_type(type); | 590 object_store->set_dynamic_type(type); |
| 557 core_lib.AddClass(cls); | 591 core_lib.AddClass(cls); |
| 558 | 592 |
| 559 // Add the preallocated classes to the list of classes to be finalized. | 593 // Finish the initialization by compiling the bootstrap script containing the |
| 560 ClassFinalizer::ExpectClassesToFinalize(); | 594 // implementation of the internal classes. |
| 561 ClassFinalizer::AddClassesToFinalize(pending_classes); | 595 Bootstrap::Compile(Library::Handle(Library::CoreLibrary()), script); |
| 562 | 596 Bootstrap::Compile(Library::Handle(Library::CoreImplLibrary()), impl_script); |
| 563 // Allocate pre-initialized values. | |
| 564 Bool& bool_value = Bool::Handle(); | |
| 565 bool_value = Bool::New(true); | |
| 566 object_store->set_true_value(bool_value); | |
| 567 bool_value = Bool::New(false); | |
| 568 object_store->set_false_value(bool_value); | |
| 569 | |
| 570 // Finish the initialization by compiling the bootstrap scripts containing the | |
| 571 // base interfaces and the implementation of the internal classes. | |
| 572 Bootstrap::Compile(core_lib, script); | |
| 573 Bootstrap::Compile(core_impl_lib, impl_script); | |
| 574 | 597 |
| 575 Bootstrap::SetupNativeResolver(); | 598 Bootstrap::SetupNativeResolver(); |
| 576 | 599 |
| 577 // Remove the Object superclass cycle by setting the super type to null (not | 600 // Remove the Object superclass cycle by setting the super type to null (not |
| 578 // to the type of null). | 601 // to the type of null). |
| 579 cls = object_store->object_class(); | 602 cls = object_store->object_class(); |
| 580 cls.set_super_type(Type::Handle()); | 603 cls.set_super_type(Type::Handle()); |
| 581 | 604 |
| 582 ClassFinalizer::VerifyBootstrapClasses(); | 605 ClassFinalizer::VerifyBootstrapClasses(); |
| 583 } | 606 } |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 } | 1051 } |
| 1029 } | 1052 } |
| 1030 } | 1053 } |
| 1031 Class& result = Class::Handle(New<Closure>(name, script)); | 1054 Class& result = Class::Handle(New<Closure>(name, script)); |
| 1032 result.set_super_type(super_type); | 1055 result.set_super_type(super_type); |
| 1033 result.set_signature_function(signature_function); | 1056 result.set_signature_function(signature_function); |
| 1034 result.set_type_parameters(type_parameters); | 1057 result.set_type_parameters(type_parameters); |
| 1035 result.set_type_parameter_extends(type_parameter_extends); | 1058 result.set_type_parameter_extends(type_parameter_extends); |
| 1036 result.SetFields(Array::Handle(Array::Empty())); | 1059 result.SetFields(Array::Handle(Array::Empty())); |
| 1037 result.SetFunctions(Array::Handle(Array::Empty())); | 1060 result.SetFunctions(Array::Handle(Array::Empty())); |
| 1038 // Implements interface "Function". | 1061 // Implements interface Function. |
| 1039 const Type& function_interface = Type::Handle(Type::FunctionInterface()); | 1062 const Type& function_interface = Type::Handle(Type::FunctionInterface()); |
| 1040 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); | 1063 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); |
| 1041 interfaces.SetAt(0, function_interface); | 1064 interfaces.SetAt(0, function_interface); |
| 1042 result.set_interfaces(interfaces); | 1065 result.set_interfaces(interfaces); |
| 1043 // Unless the signature function already has a signature class, create a | 1066 // Unless the signature function already has a signature class, create a |
| 1044 // canonical signature class by having the signature function point back to | 1067 // canonical signature class by having the signature function pointing back to |
| 1045 // the signature class. | 1068 // the signature class. |
| 1046 if (signature_function.signature_class() == Object::null()) { | 1069 if (signature_function.signature_class() == Object::null()) { |
| 1047 signature_function.set_signature_class(result); | 1070 signature_function.set_signature_class(result); |
| 1048 } | 1071 } |
| 1049 // If the class finalizer is expecting more pending classes to finalize, it | |
| 1050 // will add the signature class to the pending list in order to postpone | |
| 1051 // finalization of the signature type. | |
| 1052 const Type& signature_type = Type::Handle(result.SignatureType()); | |
| 1053 ASSERT(!signature_type.IsFinalized()); | |
| 1054 String& errmsg = String::Handle(); | |
| 1055 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); | |
| 1056 ASSERT(errmsg.IsNull()); | |
| 1057 return result.raw(); | 1072 return result.raw(); |
| 1058 } | 1073 } |
| 1059 | 1074 |
| 1060 | 1075 |
| 1061 RawClass* Class::GetClass(ObjectKind kind) { | 1076 RawClass* Class::GetClass(ObjectKind kind) { |
| 1062 ObjectStore* object_store = Isolate::Current()->object_store(); | 1077 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 1063 switch (kind) { | 1078 switch (kind) { |
| 1064 case kUnhandledException: | 1079 case kUnhandledException: |
| 1065 ASSERT(object_store->unhandled_exception_class() != Class::null()); | 1080 ASSERT(object_store->unhandled_exception_class() != Class::null()); |
| 1066 return object_store->unhandled_exception_class(); | 1081 return object_store->unhandled_exception_class(); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 | 1329 |
| 1315 bool Class::IsTopLevel() const { | 1330 bool Class::IsTopLevel() const { |
| 1316 return String::Handle(Name()).Length() == 0; | 1331 return String::Handle(Name()).Length() == 0; |
| 1317 } | 1332 } |
| 1318 | 1333 |
| 1319 | 1334 |
| 1320 bool Class::TestType(TypeTestKind test, | 1335 bool Class::TestType(TypeTestKind test, |
| 1321 const TypeArguments& type_arguments, | 1336 const TypeArguments& type_arguments, |
| 1322 const Class& other, | 1337 const Class& other, |
| 1323 const TypeArguments& other_type_arguments) const { | 1338 const TypeArguments& other_type_arguments) const { |
| 1324 ASSERT(is_finalized()); | |
| 1325 ASSERT(other.is_finalized()); | |
| 1326 if (test == kIsAssignableTo) { | 1339 if (test == kIsAssignableTo) { |
| 1327 // The spec states that "a type T is assignable to a type S if T is a | 1340 // The spec states that "a type T is assignable to a type S if T is a |
| 1328 // subtype of S or S is a subtype of T". This is from the perspective of a | 1341 // subtype of S or S is a subtype of T". This is from the perspective of a |
| 1329 // static checker, which does not know the actual type of the assigned | 1342 // static checker, which does not know the actual type of the assigned |
| 1330 // value. However, this type information is available at run time in checked | 1343 // value. However, this type information is available at run time in checked |
| 1331 // mode. We therefore apply a more restrictive subtype check, which prevents | 1344 // mode. We therefore apply a more restrictive subtype check, which prevents |
| 1332 // heap pollution. We only keep the assignability check when assigning | 1345 // heap pollution. We only keep the assignability check when assigning |
| 1333 // values of a function type. | 1346 // values of a function type. |
| 1334 if (IsSignatureClass() && other.IsSignatureClass()) { | 1347 if (IsSignatureClass() && other.IsSignatureClass()) { |
| 1335 const Function& src_fun = Function::Handle(signature_function()); | 1348 const Function& src_fun = Function::Handle(signature_function()); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); | 1803 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); |
| 1791 } | 1804 } |
| 1792 | 1805 |
| 1793 | 1806 |
| 1794 bool Type::IsListInterface() const { | 1807 bool Type::IsListInterface() const { |
| 1795 return HasResolvedTypeClass() && | 1808 return HasResolvedTypeClass() && |
| 1796 (type_class() == Type::Handle(Type::ListInterface()).type_class()); | 1809 (type_class() == Type::Handle(Type::ListInterface()).type_class()); |
| 1797 } | 1810 } |
| 1798 | 1811 |
| 1799 | 1812 |
| 1800 bool Type::IsSignatureType() const { | |
| 1801 return HasResolvedTypeClass() && | |
| 1802 Class::Handle(type_class()).IsSignatureClass(); | |
| 1803 } | |
| 1804 | |
| 1805 | |
| 1806 bool Type::IsMoreSpecificThan(const Type& other) const { | 1813 bool Type::IsMoreSpecificThan(const Type& other) const { |
| 1807 ASSERT(IsFinalized()); | 1814 ASSERT(IsFinalized()); |
| 1808 ASSERT(other.IsFinalized()); | 1815 ASSERT(other.IsFinalized()); |
| 1809 // Type parameters cannot be handled by Class::IsMoreSpecificThan(). | 1816 // Type parameters cannot be handled by Class::IsMoreSpecificThan(). |
| 1810 if (IsTypeParameter() || other.IsTypeParameter()) { | 1817 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 1811 return IsTypeParameter() && other.IsTypeParameter() && | 1818 return IsTypeParameter() && other.IsTypeParameter() && |
| 1812 (Index() == other.Index()); | 1819 (Index() == other.Index()); |
| 1813 } | 1820 } |
| 1814 const Class& cls = Class::Handle(type_class()); | 1821 const Class& cls = Class::Handle(type_class()); |
| 1815 return cls.IsMoreSpecificThan(TypeArguments::Handle(arguments()), | 1822 return cls.IsMoreSpecificThan(TypeArguments::Handle(arguments()), |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2000 intptr_t offset) const { | 2007 intptr_t offset) const { |
| 2001 ASSERT(IsFinalized()); | 2008 ASSERT(IsFinalized()); |
| 2002 ASSERT(!IsInstantiated()); | 2009 ASSERT(!IsInstantiated()); |
| 2003 TypeArguments& type_arguments = TypeArguments::Handle(); | 2010 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 2004 if (!instantiator_type_arguments.IsNull()) { | 2011 if (!instantiator_type_arguments.IsNull()) { |
| 2005 type_arguments = arguments(); | 2012 type_arguments = arguments(); |
| 2006 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 2013 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, |
| 2007 offset); | 2014 offset); |
| 2008 } | 2015 } |
| 2009 const Class& cls = Class::Handle(type_class()); | 2016 const Class& cls = Class::Handle(type_class()); |
| 2010 ASSERT(cls.is_finalized()); | |
| 2011 ParameterizedType& instantiated_type = ParameterizedType::Handle( | 2017 ParameterizedType& instantiated_type = ParameterizedType::Handle( |
| 2012 ParameterizedType::New(cls, type_arguments)); | 2018 ParameterizedType::New(cls, type_arguments)); |
| 2013 ASSERT(type_arguments.IsNull() || | 2019 ASSERT(type_arguments.IsNull() || |
| 2014 (type_arguments.Length() == cls.NumTypeArguments())); | 2020 (type_arguments.Length() == cls.NumTypeArguments())); |
| 2015 instantiated_type.set_is_finalized(); | 2021 instantiated_type.set_is_finalized(); |
| 2016 return instantiated_type.raw(); | 2022 return instantiated_type.raw(); |
| 2017 } | 2023 } |
| 2018 | 2024 |
| 2019 | 2025 |
| 2020 bool ParameterizedType::Equals(const Type& other) const { | 2026 bool ParameterizedType::Equals(const Type& other) const { |
| (...skipping 4937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6958 const String& str = String::Handle(pattern()); | 6964 const String& str = String::Handle(pattern()); |
| 6959 const char* format = "JSRegExp: pattern=%s flags=%s"; | 6965 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 6960 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 6966 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 6961 char* chars = reinterpret_cast<char*>( | 6967 char* chars = reinterpret_cast<char*>( |
| 6962 Isolate::Current()->current_zone()->Allocate(len + 1)); | 6968 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 6963 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 6969 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 6964 return chars; | 6970 return chars; |
| 6965 } | 6971 } |
| 6966 | 6972 |
| 6967 } // namespace dart | 6973 } // namespace dart |
| OLD | NEW |