| 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 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 7 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 8 | 8 |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 const int num_opt_params = 1; | 209 const int num_opt_params = 1; |
| 210 const int num_params = num_fixed_params + num_opt_params; | 210 const int num_params = num_fixed_params + num_opt_params; |
| 211 LocalScope* local_scope = node_seq->scope(); | 211 LocalScope* local_scope = node_seq->scope(); |
| 212 local_scope->AddVariable(NewTestLocalVariable("a")); | 212 local_scope->AddVariable(NewTestLocalVariable("a")); |
| 213 local_scope->AddVariable(NewTestLocalVariable("b")); | 213 local_scope->AddVariable(NewTestLocalVariable("b")); |
| 214 ASSERT(local_scope->num_variables() == num_params); | 214 ASSERT(local_scope->num_variables() == num_params); |
| 215 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); | 215 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); |
| 216 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. | 216 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. |
| 217 test->set_default_parameter_values(default_values); | 217 test->set_default_parameter_values(default_values); |
| 218 const Function& function = test->function(); | 218 const Function& function = test->function(); |
| 219 function.set_is_native(true); |
| 219 function.set_num_fixed_parameters(num_fixed_params); | 220 function.set_num_fixed_parameters(num_fixed_params); |
| 220 function.SetNumOptionalParameters(num_opt_params, true); | 221 function.SetNumOptionalParameters(num_opt_params, true); |
| 221 const bool has_opt_params = true; | |
| 222 const String& native_name = | 222 const String& native_name = |
| 223 String::ZoneHandle(Symbols::New("TestSmiSub")); | 223 String::ZoneHandle(Symbols::New("TestSmiSub")); |
| 224 NativeFunction native_function = | 224 NativeFunction native_function = |
| 225 reinterpret_cast<NativeFunction>(TestSmiSub); | 225 reinterpret_cast<NativeFunction>(TestSmiSub); |
| 226 node_seq->Add(new ReturnNode(kPos, | 226 node_seq->Add(new ReturnNode(kPos, |
| 227 new NativeBodyNode(kPos, | 227 new NativeBodyNode(kPos, |
| 228 function, |
| 228 native_name, | 229 native_name, |
| 229 native_function, | 230 native_function))); |
| 230 num_params, | |
| 231 has_opt_params, | |
| 232 false))); | |
| 233 } | 231 } |
| 234 | 232 |
| 235 | 233 |
| 236 // Tested Dart code: | 234 // Tested Dart code: |
| 237 // return dec(5); | 235 // return dec(5); |
| 238 CODEGEN_TEST2_GENERATE(StaticDecCallCodegen, function, test) { | 236 CODEGEN_TEST2_GENERATE(StaticDecCallCodegen, function, test) { |
| 239 SequenceNode* node_seq = test->node_sequence(); | 237 SequenceNode* node_seq = test->node_sequence(); |
| 240 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 238 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 241 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(5)))); | 239 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(5)))); |
| 242 node_seq->Add(new ReturnNode(kPos, | 240 node_seq->Add(new ReturnNode(kPos, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 local_scope->AddVariable(NewTestLocalVariable("c")); | 383 local_scope->AddVariable(NewTestLocalVariable("c")); |
| 386 local_scope->AddVariable(NewTestLocalVariable("d")); | 384 local_scope->AddVariable(NewTestLocalVariable("d")); |
| 387 local_scope->AddVariable(NewTestLocalVariable("e")); | 385 local_scope->AddVariable(NewTestLocalVariable("e")); |
| 388 ASSERT(local_scope->num_variables() == num_params); | 386 ASSERT(local_scope->num_variables() == num_params); |
| 389 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); | 387 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); |
| 390 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10))); | 388 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10))); |
| 391 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); | 389 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); |
| 392 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); | 390 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); |
| 393 test->set_default_parameter_values(default_values); | 391 test->set_default_parameter_values(default_values); |
| 394 const Function& function = test->function(); | 392 const Function& function = test->function(); |
| 393 function.set_is_native(true); |
| 395 function.set_num_fixed_parameters(num_fixed_params); | 394 function.set_num_fixed_parameters(num_fixed_params); |
| 396 function.SetNumOptionalParameters(num_opt_params, true); | 395 function.SetNumOptionalParameters(num_opt_params, true); |
| 397 function.set_parameter_types(Array::Handle(Array::New(num_params))); | 396 function.set_parameter_types(Array::Handle(Array::New(num_params))); |
| 398 function.set_parameter_names(Array::Handle(Array::New(num_params))); | 397 function.set_parameter_names(Array::Handle(Array::New(num_params))); |
| 399 const Type& param_type = Type::Handle(Type::DynamicType()); | 398 const Type& param_type = Type::Handle(Type::DynamicType()); |
| 400 for (int i = 0; i < num_params - 1; i++) { | 399 for (int i = 0; i < num_params - 1; i++) { |
| 401 function.SetParameterTypeAt(i, param_type); | 400 function.SetParameterTypeAt(i, param_type); |
| 402 } | 401 } |
| 403 const bool has_opt_params = true; | |
| 404 const String& native_name = | 402 const String& native_name = |
| 405 String::ZoneHandle(Symbols::New("TestSmiSum")); | 403 String::ZoneHandle(Symbols::New("TestSmiSum")); |
| 406 NativeFunction native_function = | 404 NativeFunction native_function = |
| 407 reinterpret_cast<NativeFunction>(TestSmiSum); | 405 reinterpret_cast<NativeFunction>(TestSmiSum); |
| 408 node_seq->Add(new ReturnNode(kPos, | 406 node_seq->Add(new ReturnNode(kPos, |
| 409 new NativeBodyNode(kPos, | 407 new NativeBodyNode(kPos, |
| 408 function, |
| 410 native_name, | 409 native_name, |
| 411 native_function, | 410 native_function))); |
| 412 num_params, | |
| 413 has_opt_params, | |
| 414 false))); | |
| 415 } | 411 } |
| 416 | 412 |
| 417 | 413 |
| 418 // Tested Dart code, calling function sum declared above: | 414 // Tested Dart code, calling function sum declared above: |
| 419 // return sum(1, 3); | 415 // return sum(1, 3); |
| 420 // Optional arguments are not passed and hence are set to their default values. | 416 // Optional arguments are not passed and hence are set to their default values. |
| 421 CODEGEN_TEST2_GENERATE(StaticSumCallNoOptCodegen, function, test) { | 417 CODEGEN_TEST2_GENERATE(StaticSumCallNoOptCodegen, function, test) { |
| 422 SequenceNode* node_seq = test->node_sequence(); | 418 SequenceNode* node_seq = test->node_sequence(); |
| 423 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 419 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 424 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1)))); | 420 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1)))); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 app_lib ^= libs.At(num_libs - 1); | 512 app_lib ^= libs.At(num_libs - 1); |
| 517 ASSERT(!app_lib.IsNull()); | 513 ASSERT(!app_lib.IsNull()); |
| 518 const Class& cls = Class::Handle( | 514 const Class& cls = Class::Handle( |
| 519 app_lib.LookupClass(String::Handle(Symbols::New("A")))); | 515 app_lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 520 EXPECT_EQ(cls.raw(), result.clazz()); | 516 EXPECT_EQ(cls.raw(), result.clazz()); |
| 521 } | 517 } |
| 522 | 518 |
| 523 } // namespace dart | 519 } // namespace dart |
| 524 | 520 |
| 525 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) | 521 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) |
| OLD | NEW |