| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/globals.h" | 6 #include "vm/globals.h" |
| 7 #include "vm/ast.h" | 7 #include "vm/ast.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/code_generator.h" | 10 #include "vm/code_generator.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. | 211 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. |
| 212 test->set_default_parameter_values(default_values); | 212 test->set_default_parameter_values(default_values); |
| 213 const Function& function = test->function(); | 213 const Function& function = test->function(); |
| 214 function.set_is_native(true); | 214 function.set_is_native(true); |
| 215 function.set_num_fixed_parameters(num_fixed_params); | 215 function.set_num_fixed_parameters(num_fixed_params); |
| 216 function.SetNumOptionalParameters(num_opt_params, true); | 216 function.SetNumOptionalParameters(num_opt_params, true); |
| 217 const String& native_name = | 217 const String& native_name = |
| 218 String::ZoneHandle(Symbols::New("TestSmiSub")); | 218 String::ZoneHandle(Symbols::New("TestSmiSub")); |
| 219 NativeFunction native_function = | 219 NativeFunction native_function = |
| 220 reinterpret_cast<NativeFunction>(TestSmiSub); | 220 reinterpret_cast<NativeFunction>(TestSmiSub); |
| 221 node_seq->Add(new ReturnNode(kPos, | 221 node_seq->Add( |
| 222 new NativeBodyNode(kPos, | 222 new ReturnNode(kPos, |
| 223 function, | 223 new NativeBodyNode(kPos, |
| 224 native_name, | 224 function, |
| 225 native_function))); | 225 native_name, |
| 226 native_function, |
| 227 false /* not bootstrap native */))); |
| 226 } | 228 } |
| 227 | 229 |
| 228 | 230 |
| 229 // Tested Dart code: | 231 // Tested Dart code: |
| 230 // return dec(5); | 232 // return dec(5); |
| 231 CODEGEN_TEST2_GENERATE(StaticDecCallCodegen, function, test) { | 233 CODEGEN_TEST2_GENERATE(StaticDecCallCodegen, function, test) { |
| 232 SequenceNode* node_seq = test->node_sequence(); | 234 SequenceNode* node_seq = test->node_sequence(); |
| 233 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 235 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 234 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(5)))); | 236 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(5)))); |
| 235 node_seq->Add(new ReturnNode(kPos, | 237 node_seq->Add(new ReturnNode(kPos, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 function.set_parameter_types(Array::Handle(Array::New(num_params))); | 393 function.set_parameter_types(Array::Handle(Array::New(num_params))); |
| 392 function.set_parameter_names(Array::Handle(Array::New(num_params))); | 394 function.set_parameter_names(Array::Handle(Array::New(num_params))); |
| 393 const Type& param_type = Type::Handle(Type::DynamicType()); | 395 const Type& param_type = Type::Handle(Type::DynamicType()); |
| 394 for (int i = 0; i < num_params; i++) { | 396 for (int i = 0; i < num_params; i++) { |
| 395 function.SetParameterTypeAt(i, param_type); | 397 function.SetParameterTypeAt(i, param_type); |
| 396 } | 398 } |
| 397 const String& native_name = | 399 const String& native_name = |
| 398 String::ZoneHandle(Symbols::New("TestSmiSum")); | 400 String::ZoneHandle(Symbols::New("TestSmiSum")); |
| 399 NativeFunction native_function = | 401 NativeFunction native_function = |
| 400 reinterpret_cast<NativeFunction>(TestSmiSum); | 402 reinterpret_cast<NativeFunction>(TestSmiSum); |
| 401 node_seq->Add(new ReturnNode(kPos, | 403 node_seq->Add( |
| 402 new NativeBodyNode(kPos, | 404 new ReturnNode(kPos, |
| 403 function, | 405 new NativeBodyNode(kPos, |
| 404 native_name, | 406 function, |
| 405 native_function))); | 407 native_name, |
| 408 native_function, |
| 409 false /* Not bootstrap native */))); |
| 406 } | 410 } |
| 407 | 411 |
| 408 | 412 |
| 409 // Tested Dart code, calling function sum declared above: | 413 // Tested Dart code, calling function sum declared above: |
| 410 // return sum(1, 3); | 414 // return sum(1, 3); |
| 411 // Optional arguments are not passed and hence are set to their default values. | 415 // Optional arguments are not passed and hence are set to their default values. |
| 412 CODEGEN_TEST2_GENERATE(StaticSumCallNoOptCodegen, function, test) { | 416 CODEGEN_TEST2_GENERATE(StaticSumCallNoOptCodegen, function, test) { |
| 413 SequenceNode* node_seq = test->node_sequence(); | 417 SequenceNode* node_seq = test->node_sequence(); |
| 414 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 418 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 415 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1)))); | 419 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1)))); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 function.set_parameter_types(Array::Handle(Array::New(num_params))); | 482 function.set_parameter_types(Array::Handle(Array::New(num_params))); |
| 479 function.set_parameter_names(Array::Handle(Array::New(num_params))); | 483 function.set_parameter_names(Array::Handle(Array::New(num_params))); |
| 480 const Type& param_type = Type::Handle(Type::DynamicType()); | 484 const Type& param_type = Type::Handle(Type::DynamicType()); |
| 481 for (int i = 0; i < num_params; i++) { | 485 for (int i = 0; i < num_params; i++) { |
| 482 function.SetParameterTypeAt(i, param_type); | 486 function.SetParameterTypeAt(i, param_type); |
| 483 } | 487 } |
| 484 const String& native_name = | 488 const String& native_name = |
| 485 String::ZoneHandle(Symbols::New("TestNonNullSmiSum")); | 489 String::ZoneHandle(Symbols::New("TestNonNullSmiSum")); |
| 486 NativeFunction native_function = | 490 NativeFunction native_function = |
| 487 reinterpret_cast<NativeFunction>(TestNonNullSmiSum); | 491 reinterpret_cast<NativeFunction>(TestNonNullSmiSum); |
| 488 node_seq->Add(new ReturnNode(kPos, | 492 node_seq->Add( |
| 489 new NativeBodyNode(kPos, | 493 new ReturnNode(kPos, |
| 490 function, | 494 new NativeBodyNode(kPos, |
| 491 native_name, | 495 function, |
| 492 native_function))); | 496 native_name, |
| 497 native_function, |
| 498 false /* Not bootstrap native */))); |
| 493 } | 499 } |
| 494 | 500 |
| 495 | 501 |
| 496 // Tested Dart code, calling function sum declared above: | 502 // Tested Dart code, calling function sum declared above: |
| 497 // return sum(1, null, 3); | 503 // return sum(1, null, 3); |
| 498 CODEGEN_TEST2_GENERATE(StaticNonNullSumCallCodegen, function, test) { | 504 CODEGEN_TEST2_GENERATE(StaticNonNullSumCallCodegen, function, test) { |
| 499 SequenceNode* node_seq = test->node_sequence(); | 505 SequenceNode* node_seq = test->node_sequence(); |
| 500 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 506 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 501 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1)))); | 507 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1)))); |
| 502 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle())); | 508 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle())); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 app_lib ^= libs.At(num_libs - 1); | 559 app_lib ^= libs.At(num_libs - 1); |
| 554 ASSERT(!app_lib.IsNull()); | 560 ASSERT(!app_lib.IsNull()); |
| 555 String& ambiguity_error_msg = String::Handle(); | 561 String& ambiguity_error_msg = String::Handle(); |
| 556 const Class& cls = Class::Handle( | 562 const Class& cls = Class::Handle( |
| 557 app_lib.LookupClass(String::Handle(Symbols::New("A")), | 563 app_lib.LookupClass(String::Handle(Symbols::New("A")), |
| 558 &ambiguity_error_msg)); | 564 &ambiguity_error_msg)); |
| 559 EXPECT_EQ(cls.raw(), result.clazz()); // No ambiguity error expected. | 565 EXPECT_EQ(cls.raw(), result.clazz()); // No ambiguity error expected. |
| 560 } | 566 } |
| 561 | 567 |
| 562 } // namespace dart | 568 } // namespace dart |
| OLD | NEW |