OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/code_generator.h" | 5 #include "vm/code_generator.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const Array& args = Array::Handle(Array::New(4)); | 141 const Array& args = Array::Handle(Array::New(4)); |
142 args.SetAt(0, length); | 142 args.SetAt(0, length); |
143 args.SetAt(1, Integer::Handle(Integer::New(0))); | 143 args.SetAt(1, Integer::Handle(Integer::New(0))); |
144 args.SetAt(2, Integer::Handle(Integer::New(Array::kMaxElements))); | 144 args.SetAt(2, Integer::Handle(Integer::New(Array::kMaxElements))); |
145 args.SetAt(3, Symbols::Length()); | 145 args.SetAt(3, Symbols::Length()); |
146 Exceptions::ThrowByType(Exceptions::kRange, args); | 146 Exceptions::ThrowByType(Exceptions::kRange, args); |
147 } | 147 } |
148 | 148 |
149 | 149 |
150 // Helper returning the token position of the Dart caller. | 150 // Helper returning the token position of the Dart caller. |
151 static intptr_t GetCallerLocation() { | 151 static TokenPosition GetCallerLocation() { |
152 DartFrameIterator iterator; | 152 DartFrameIterator iterator; |
153 StackFrame* caller_frame = iterator.NextFrame(); | 153 StackFrame* caller_frame = iterator.NextFrame(); |
154 ASSERT(caller_frame != NULL); | 154 ASSERT(caller_frame != NULL); |
155 return caller_frame->GetTokenPos(); | 155 return caller_frame->GetTokenPos(); |
156 } | 156 } |
157 | 157 |
158 | 158 |
159 // Allocate a new object. | 159 // Allocate a new object. |
160 // Arg0: class of the object that needs to be allocated. | 160 // Arg0: class of the object that needs to be allocated. |
161 // Arg1: type arguments of the object that needs to be allocated. | 161 // Arg1: type arguments of the object that needs to be allocated. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 DEFINE_RUNTIME_ENTRY(InstantiateType, 2) { | 201 DEFINE_RUNTIME_ENTRY(InstantiateType, 2) { |
202 AbstractType& type = AbstractType::CheckedHandle(arguments.ArgAt(0)); | 202 AbstractType& type = AbstractType::CheckedHandle(arguments.ArgAt(0)); |
203 const TypeArguments& instantiator = | 203 const TypeArguments& instantiator = |
204 TypeArguments::CheckedHandle(arguments.ArgAt(1)); | 204 TypeArguments::CheckedHandle(arguments.ArgAt(1)); |
205 ASSERT(!type.IsNull() && !type.IsInstantiated()); | 205 ASSERT(!type.IsNull() && !type.IsInstantiated()); |
206 ASSERT(instantiator.IsNull() || instantiator.IsInstantiated()); | 206 ASSERT(instantiator.IsNull() || instantiator.IsInstantiated()); |
207 Error& bound_error = Error::Handle(); | 207 Error& bound_error = Error::Handle(); |
208 type = type.InstantiateFrom(instantiator, &bound_error, NULL, Heap::kOld); | 208 type = type.InstantiateFrom(instantiator, &bound_error, NULL, Heap::kOld); |
209 if (!bound_error.IsNull()) { | 209 if (!bound_error.IsNull()) { |
210 // Throw a dynamic type error. | 210 // Throw a dynamic type error. |
211 const intptr_t location = GetCallerLocation(); | 211 const TokenPosition location = GetCallerLocation(); |
212 String& bound_error_message = String::Handle( | 212 String& bound_error_message = String::Handle( |
213 String::New(bound_error.ToErrorCString())); | 213 String::New(bound_error.ToErrorCString())); |
214 Exceptions::CreateAndThrowTypeError( | 214 Exceptions::CreateAndThrowTypeError( |
215 location, Symbols::Empty(), Symbols::Empty(), | 215 location, Symbols::Empty(), Symbols::Empty(), |
216 Symbols::Empty(), bound_error_message); | 216 Symbols::Empty(), bound_error_message); |
217 UNREACHABLE(); | 217 UNREACHABLE(); |
218 } | 218 } |
219 if (type.IsTypeRef()) { | 219 if (type.IsTypeRef()) { |
220 type = TypeRef::Cast(type).type(); | 220 type = TypeRef::Cast(type).type(); |
221 ASSERT(!type.IsTypeRef()); | 221 ASSERT(!type.IsTypeRef()); |
(...skipping 18 matching lines...) Expand all Loading... |
240 // Code inlined in the caller should have optimized the case where the | 240 // Code inlined in the caller should have optimized the case where the |
241 // instantiator can be reused as type argument vector. | 241 // instantiator can be reused as type argument vector. |
242 ASSERT(instantiator.IsNull() || !type_arguments.IsUninstantiatedIdentity()); | 242 ASSERT(instantiator.IsNull() || !type_arguments.IsUninstantiatedIdentity()); |
243 if (isolate->flags().type_checks()) { | 243 if (isolate->flags().type_checks()) { |
244 Error& bound_error = Error::Handle(); | 244 Error& bound_error = Error::Handle(); |
245 type_arguments = | 245 type_arguments = |
246 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, | 246 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, |
247 &bound_error); | 247 &bound_error); |
248 if (!bound_error.IsNull()) { | 248 if (!bound_error.IsNull()) { |
249 // Throw a dynamic type error. | 249 // Throw a dynamic type error. |
250 const intptr_t location = GetCallerLocation(); | 250 const TokenPosition location = GetCallerLocation(); |
251 String& bound_error_message = String::Handle( | 251 String& bound_error_message = String::Handle( |
252 String::New(bound_error.ToErrorCString())); | 252 String::New(bound_error.ToErrorCString())); |
253 Exceptions::CreateAndThrowTypeError( | 253 Exceptions::CreateAndThrowTypeError( |
254 location, Symbols::Empty(), Symbols::Empty(), | 254 location, Symbols::Empty(), Symbols::Empty(), |
255 Symbols::Empty(), bound_error_message); | 255 Symbols::Empty(), bound_error_message); |
256 UNREACHABLE(); | 256 UNREACHABLE(); |
257 } | 257 } |
258 } else { | 258 } else { |
259 type_arguments = | 259 type_arguments = |
260 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL); | 260 type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 const Bool& result = | 469 const Bool& result = |
470 Bool::Get(instance.IsInstanceOf(type, | 470 Bool::Get(instance.IsInstanceOf(type, |
471 instantiator_type_arguments, | 471 instantiator_type_arguments, |
472 &bound_error)); | 472 &bound_error)); |
473 if (FLAG_trace_type_checks) { | 473 if (FLAG_trace_type_checks) { |
474 PrintTypeCheck("InstanceOf", | 474 PrintTypeCheck("InstanceOf", |
475 instance, type, instantiator_type_arguments, result); | 475 instance, type, instantiator_type_arguments, result); |
476 } | 476 } |
477 if (!result.value() && !bound_error.IsNull()) { | 477 if (!result.value() && !bound_error.IsNull()) { |
478 // Throw a dynamic type error only if the instanceof test fails. | 478 // Throw a dynamic type error only if the instanceof test fails. |
479 const intptr_t location = GetCallerLocation(); | 479 const TokenPosition location = GetCallerLocation(); |
480 String& bound_error_message = String::Handle( | 480 String& bound_error_message = String::Handle( |
481 String::New(bound_error.ToErrorCString())); | 481 String::New(bound_error.ToErrorCString())); |
482 Exceptions::CreateAndThrowTypeError( | 482 Exceptions::CreateAndThrowTypeError( |
483 location, Symbols::Empty(), Symbols::Empty(), | 483 location, Symbols::Empty(), Symbols::Empty(), |
484 Symbols::Empty(), bound_error_message); | 484 Symbols::Empty(), bound_error_message); |
485 UNREACHABLE(); | 485 UNREACHABLE(); |
486 } | 486 } |
487 UpdateTypeTestCache( | 487 UpdateTypeTestCache( |
488 instance, type, instantiator_type_arguments, result, cache); | 488 instance, type, instantiator_type_arguments, result, cache); |
489 arguments.SetReturn(result); | 489 arguments.SetReturn(result); |
(...skipping 26 matching lines...) Expand all Loading... |
516 const bool is_instance_of = src_instance.IsInstanceOf( | 516 const bool is_instance_of = src_instance.IsInstanceOf( |
517 dst_type, instantiator_type_arguments, &bound_error); | 517 dst_type, instantiator_type_arguments, &bound_error); |
518 | 518 |
519 if (FLAG_trace_type_checks) { | 519 if (FLAG_trace_type_checks) { |
520 PrintTypeCheck("TypeCheck", | 520 PrintTypeCheck("TypeCheck", |
521 src_instance, dst_type, instantiator_type_arguments, | 521 src_instance, dst_type, instantiator_type_arguments, |
522 Bool::Get(is_instance_of)); | 522 Bool::Get(is_instance_of)); |
523 } | 523 } |
524 if (!is_instance_of) { | 524 if (!is_instance_of) { |
525 // Throw a dynamic type error. | 525 // Throw a dynamic type error. |
526 const intptr_t location = GetCallerLocation(); | 526 const TokenPosition location = GetCallerLocation(); |
527 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType()); | 527 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType()); |
528 String& src_type_name = String::Handle(src_type.UserVisibleName()); | 528 String& src_type_name = String::Handle(src_type.UserVisibleName()); |
529 String& dst_type_name = String::Handle(); | 529 String& dst_type_name = String::Handle(); |
530 Library& dst_type_lib = Library::Handle(); | 530 Library& dst_type_lib = Library::Handle(); |
531 if (!dst_type.IsInstantiated()) { | 531 if (!dst_type.IsInstantiated()) { |
532 // Instantiate dst_type before reporting the error. | 532 // Instantiate dst_type before reporting the error. |
533 const AbstractType& instantiated_dst_type = AbstractType::Handle( | 533 const AbstractType& instantiated_dst_type = AbstractType::Handle( |
534 dst_type.InstantiateFrom(instantiator_type_arguments, NULL)); | 534 dst_type.InstantiateFrom(instantiator_type_arguments, NULL)); |
535 // Note that instantiated_dst_type may be malbounded. | 535 // Note that instantiated_dst_type may be malbounded. |
536 dst_type_name = instantiated_dst_type.UserVisibleName(); | 536 dst_type_name = instantiated_dst_type.UserVisibleName(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 arguments.SetReturn(src_instance); | 569 arguments.SetReturn(src_instance); |
570 } | 570 } |
571 | 571 |
572 | 572 |
573 // Report that the type of the given object is not bool in conditional context. | 573 // Report that the type of the given object is not bool in conditional context. |
574 // Throw assertion error if the object is null. (cf. Boolean Conversion | 574 // Throw assertion error if the object is null. (cf. Boolean Conversion |
575 // in language Spec.) | 575 // in language Spec.) |
576 // Arg0: bad object. | 576 // Arg0: bad object. |
577 // Return value: none, throws TypeError or AssertionError. | 577 // Return value: none, throws TypeError or AssertionError. |
578 DEFINE_RUNTIME_ENTRY(NonBoolTypeError, 1) { | 578 DEFINE_RUNTIME_ENTRY(NonBoolTypeError, 1) { |
579 const intptr_t location = GetCallerLocation(); | 579 const TokenPosition location = GetCallerLocation(); |
580 const Instance& src_instance = Instance::CheckedHandle(arguments.ArgAt(0)); | 580 const Instance& src_instance = Instance::CheckedHandle(arguments.ArgAt(0)); |
581 | 581 |
582 if (src_instance.IsNull()) { | 582 if (src_instance.IsNull()) { |
583 const Array& args = Array::Handle(Array::New(4)); | 583 const Array& args = Array::Handle(Array::New(4)); |
584 args.SetAt(0, String::Handle( | 584 args.SetAt(0, String::Handle( |
585 String::New("Failed assertion: boolean expression must not be null"))); | 585 String::New("Failed assertion: boolean expression must not be null"))); |
586 | 586 |
587 // No source code for this assertion, set url to null. | 587 // No source code for this assertion, set url to null. |
588 args.SetAt(1, String::Handle(String::null())); | 588 args.SetAt(1, String::Handle(String::null())); |
589 args.SetAt(2, Smi::Handle(Smi::New(0))); | 589 args.SetAt(2, Smi::Handle(Smi::New(0))); |
(...skipping 16 matching lines...) Expand all Loading... |
606 UNREACHABLE(); | 606 UNREACHABLE(); |
607 } | 607 } |
608 | 608 |
609 | 609 |
610 // Report that the type of the type check is malformed or malbounded. | 610 // Report that the type of the type check is malformed or malbounded. |
611 // Arg0: src value. | 611 // Arg0: src value. |
612 // Arg1: name of destination being assigned to. | 612 // Arg1: name of destination being assigned to. |
613 // Arg2: type of destination being assigned to. | 613 // Arg2: type of destination being assigned to. |
614 // Return value: none, throws an exception. | 614 // Return value: none, throws an exception. |
615 DEFINE_RUNTIME_ENTRY(BadTypeError, 3) { | 615 DEFINE_RUNTIME_ENTRY(BadTypeError, 3) { |
616 const intptr_t location = GetCallerLocation(); | 616 const TokenPosition location = GetCallerLocation(); |
617 const Instance& src_value = Instance::CheckedHandle(arguments.ArgAt(0)); | 617 const Instance& src_value = Instance::CheckedHandle(arguments.ArgAt(0)); |
618 const String& dst_name = String::CheckedHandle(arguments.ArgAt(1)); | 618 const String& dst_name = String::CheckedHandle(arguments.ArgAt(1)); |
619 const AbstractType& dst_type = | 619 const AbstractType& dst_type = |
620 AbstractType::CheckedHandle(arguments.ArgAt(2)); | 620 AbstractType::CheckedHandle(arguments.ArgAt(2)); |
621 const AbstractType& src_type = AbstractType::Handle(src_value.GetType()); | 621 const AbstractType& src_type = AbstractType::Handle(src_value.GetType()); |
622 const String& src_type_name = String::Handle(src_type.UserVisibleName()); | 622 const String& src_type_name = String::Handle(src_type.UserVisibleName()); |
623 | 623 |
624 String& dst_type_name = String::Handle(); | 624 String& dst_type_name = String::Handle(); |
625 LanguageError& error = LanguageError::Handle(dst_type.error()); | 625 LanguageError& error = LanguageError::Handle(dst_type.error()); |
626 ASSERT(!error.IsNull()); | 626 ASSERT(!error.IsNull()); |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 if (do_stacktrace) { | 1374 if (do_stacktrace) { |
1375 String& var_name = String::Handle(); | 1375 String& var_name = String::Handle(); |
1376 Instance& var_value = Instance::Handle(); | 1376 Instance& var_value = Instance::Handle(); |
1377 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); | 1377 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); |
1378 intptr_t num_frames = stack->Length(); | 1378 intptr_t num_frames = stack->Length(); |
1379 for (intptr_t i = 0; i < num_frames; i++) { | 1379 for (intptr_t i = 0; i < num_frames; i++) { |
1380 ActivationFrame* frame = stack->FrameAt(i); | 1380 ActivationFrame* frame = stack->FrameAt(i); |
1381 // Variable locations and number are unknown when precompiling. | 1381 // Variable locations and number are unknown when precompiling. |
1382 const int num_vars = | 1382 const int num_vars = |
1383 FLAG_precompilation ? 0 : frame->NumLocalVariables(); | 1383 FLAG_precompilation ? 0 : frame->NumLocalVariables(); |
1384 intptr_t unused; | 1384 TokenPosition unused = TokenPosition::kNoSource; |
1385 for (intptr_t v = 0; v < num_vars; v++) { | 1385 for (intptr_t v = 0; v < num_vars; v++) { |
1386 frame->VariableAt(v, &var_name, &unused, &unused, &var_value); | 1386 frame->VariableAt(v, &var_name, &unused, &unused, &var_value); |
1387 } | 1387 } |
1388 } | 1388 } |
1389 } | 1389 } |
1390 | 1390 |
1391 const Error& error = Error::Handle(isolate->HandleInterrupts()); | 1391 const Error& error = Error::Handle(isolate->HandleInterrupts()); |
1392 if (!error.IsNull()) { | 1392 if (!error.IsNull()) { |
1393 Exceptions::PropagateError(error); | 1393 Exceptions::PropagateError(error); |
1394 UNREACHABLE(); | 1394 UNREACHABLE(); |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1888 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
1889 const TypedData& new_data = | 1889 const TypedData& new_data = |
1890 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1890 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
1891 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1891 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
1892 typed_data_cell.SetAt(0, new_data); | 1892 typed_data_cell.SetAt(0, new_data); |
1893 arguments.SetReturn(new_data); | 1893 arguments.SetReturn(new_data); |
1894 } | 1894 } |
1895 | 1895 |
1896 | 1896 |
1897 } // namespace dart | 1897 } // namespace dart |
OLD | NEW |