| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 CODEGEN_TEST_GENERATE(ReturnParameterCodegen, test) { | 56 CODEGEN_TEST_GENERATE(ReturnParameterCodegen, test) { |
| 57 SequenceNode* node_seq = test->node_sequence(); | 57 SequenceNode* node_seq = test->node_sequence(); |
| 58 const int num_params = 1; | 58 const int num_params = 1; |
| 59 LocalVariable* parameter = NewTestLocalVariable("parameter"); | 59 LocalVariable* parameter = NewTestLocalVariable("parameter"); |
| 60 LocalScope* local_scope = node_seq->scope(); | 60 LocalScope* local_scope = node_seq->scope(); |
| 61 local_scope->AddVariable(parameter); | 61 local_scope->AddVariable(parameter); |
| 62 ASSERT(local_scope->num_variables() == num_params); | 62 ASSERT(local_scope->num_variables() == num_params); |
| 63 const Function& function = test->function(); | 63 const Function& function = test->function(); |
| 64 function.set_num_fixed_parameters(num_params); | 64 function.set_num_fixed_parameters(num_params); |
| 65 ASSERT(function.num_optional_parameters() == 0); | 65 ASSERT(!function.HasOptionalParameters()); |
| 66 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, parameter))); | 66 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, parameter))); |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 CODEGEN_TEST2_GENERATE(StaticCallReturnParameterCodegen, function, test) { | 70 CODEGEN_TEST2_GENERATE(StaticCallReturnParameterCodegen, function, test) { |
| 71 // Wrap and call the ReturnParameterCodegen test above as a static function. | 71 // Wrap and call the ReturnParameterCodegen test above as a static function. |
| 72 SequenceNode* node_seq = test->node_sequence(); | 72 SequenceNode* node_seq = test->node_sequence(); |
| 73 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 73 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 74 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3)))); | 74 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3)))); |
| 75 node_seq->Add(new ReturnNode(kPos, | 75 node_seq->Add(new ReturnNode(kPos, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 LocalVariable* param2 = NewTestLocalVariable("param2"); | 87 LocalVariable* param2 = NewTestLocalVariable("param2"); |
| 88 const int num_locals = 1; | 88 const int num_locals = 1; |
| 89 LocalVariable* sum = NewTestLocalVariable("sum"); | 89 LocalVariable* sum = NewTestLocalVariable("sum"); |
| 90 LocalScope* local_scope = node_seq->scope(); | 90 LocalScope* local_scope = node_seq->scope(); |
| 91 local_scope->AddVariable(param1); | 91 local_scope->AddVariable(param1); |
| 92 local_scope->AddVariable(param2); | 92 local_scope->AddVariable(param2); |
| 93 local_scope->AddVariable(sum); | 93 local_scope->AddVariable(sum); |
| 94 ASSERT(local_scope->num_variables() == num_params + num_locals); | 94 ASSERT(local_scope->num_variables() == num_params + num_locals); |
| 95 const Function& function = test->function(); | 95 const Function& function = test->function(); |
| 96 function.set_num_fixed_parameters(num_params); | 96 function.set_num_fixed_parameters(num_params); |
| 97 ASSERT(function.num_optional_parameters() == 0); | 97 ASSERT(!function.HasOptionalParameters()); |
| 98 BinaryOpNode* add = new BinaryOpNode(kPos, | 98 BinaryOpNode* add = new BinaryOpNode(kPos, |
| 99 Token::kADD, | 99 Token::kADD, |
| 100 new LoadLocalNode(kPos, param1), | 100 new LoadLocalNode(kPos, param1), |
| 101 new LoadLocalNode(kPos, param2)); | 101 new LoadLocalNode(kPos, param2)); |
| 102 node_seq->Add(new StoreLocalNode(kPos, sum, add)); | 102 node_seq->Add(new StoreLocalNode(kPos, sum, add)); |
| 103 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, sum))); | 103 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, sum))); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 CODEGEN_TEST2_GENERATE(StaticCallSmiParamSumCodegen, function, test) { | 107 CODEGEN_TEST2_GENERATE(StaticCallSmiParamSumCodegen, function, test) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 new LiteralNode(kPos, Double::ZoneHandle(Double::New(0.5, Heap::kOld))); | 189 new LiteralNode(kPos, Double::ZoneHandle(Double::New(0.5, Heap::kOld))); |
| 190 BinaryOpNode* sub_node = new BinaryOpNode(kPos, Token::kSUB, a, b); | 190 BinaryOpNode* sub_node = new BinaryOpNode(kPos, Token::kSUB, a, b); |
| 191 BinaryOpNode* mul_node = new BinaryOpNode(kPos, Token::kMUL, sub_node, c); | 191 BinaryOpNode* mul_node = new BinaryOpNode(kPos, Token::kMUL, sub_node, c); |
| 192 BinaryOpNode* div_node = new BinaryOpNode(kPos, Token::kDIV, mul_node, b); | 192 BinaryOpNode* div_node = new BinaryOpNode(kPos, Token::kDIV, mul_node, b); |
| 193 node_seq->Add(new ReturnNode(kPos, div_node)); | 193 node_seq->Add(new ReturnNode(kPos, div_node)); |
| 194 } | 194 } |
| 195 CODEGEN_TEST_RUN(BinaryOpCodegen, Double::New(2.5)); | 195 CODEGEN_TEST_RUN(BinaryOpCodegen, Double::New(2.5)); |
| 196 | 196 |
| 197 | 197 |
| 198 // Tested Dart code: | 198 // Tested Dart code: |
| 199 // int dec(int a, int b = 1) native: "TestSmiSub"; | 199 // int dec(int a, [int b = 1]) native: "TestSmiSub"; |
| 200 // The native entry TestSmiSub implements dec natively. | 200 // The native entry TestSmiSub implements dec natively. |
| 201 CODEGEN_TEST_GENERATE(NativeDecCodegen, test) { | 201 CODEGEN_TEST_GENERATE(NativeDecCodegen, test) { |
| 202 // A NativeBodyNode, preceded by an EnterNode and followed by a ReturnNode, | 202 // A NativeBodyNode, preceded by an EnterNode and followed by a ReturnNode, |
| 203 // implements the body of a native Dart function. Let's take this native | 203 // implements the body of a native Dart function. Let's take this native |
| 204 // function as an example: int dec(int a, int b = 1) native; | 204 // function as an example: int dec(int a, int b = 1) native; |
| 205 // Since this function has an optional parameter, its prologue will copy | 205 // Since this function has an optional parameter, its prologue will copy |
| 206 // incoming parameters to locals. | 206 // incoming parameters to locals. |
| 207 SequenceNode* node_seq = test->node_sequence(); | 207 SequenceNode* node_seq = test->node_sequence(); |
| 208 const int num_fixed_params = 1; | 208 const int num_fixed_params = 1; |
| 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_num_fixed_parameters(num_fixed_params); | 219 function.SetNumberOfParameters(num_fixed_params, num_opt_params, true); |
| 220 function.set_num_optional_parameters(num_opt_params); | |
| 221 const bool has_opt_params = true; | 220 const bool has_opt_params = true; |
| 222 const String& native_name = | 221 const String& native_name = |
| 223 String::ZoneHandle(Symbols::New("TestSmiSub")); | 222 String::ZoneHandle(Symbols::New("TestSmiSub")); |
| 224 NativeFunction native_function = | 223 NativeFunction native_function = |
| 225 reinterpret_cast<NativeFunction>(TestSmiSub); | 224 reinterpret_cast<NativeFunction>(TestSmiSub); |
| 226 node_seq->Add(new ReturnNode(kPos, | 225 node_seq->Add(new ReturnNode(kPos, |
| 227 new NativeBodyNode(kPos, | 226 new NativeBodyNode(kPos, |
| 228 native_name, | 227 native_name, |
| 229 native_function, | 228 native_function, |
| 230 num_params, | 229 num_params, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 local_scope->AddVariable(NewTestLocalVariable("c")); | 379 local_scope->AddVariable(NewTestLocalVariable("c")); |
| 381 local_scope->AddVariable(NewTestLocalVariable("d")); | 380 local_scope->AddVariable(NewTestLocalVariable("d")); |
| 382 local_scope->AddVariable(NewTestLocalVariable("e")); | 381 local_scope->AddVariable(NewTestLocalVariable("e")); |
| 383 ASSERT(local_scope->num_variables() == num_params); | 382 ASSERT(local_scope->num_variables() == num_params); |
| 384 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); | 383 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); |
| 385 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10))); | 384 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10))); |
| 386 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); | 385 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); |
| 387 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); | 386 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); |
| 388 test->set_default_parameter_values(default_values); | 387 test->set_default_parameter_values(default_values); |
| 389 const Function& function = test->function(); | 388 const Function& function = test->function(); |
| 390 function.set_num_fixed_parameters(num_fixed_params); | 389 function.SetNumberOfParameters(num_fixed_params, num_opt_params, true); |
| 391 function.set_num_optional_parameters(num_opt_params); | |
| 392 function.set_parameter_types(Array::Handle(Array::New(num_params))); | 390 function.set_parameter_types(Array::Handle(Array::New(num_params))); |
| 393 function.set_parameter_names(Array::Handle(Array::New(num_params))); | 391 function.set_parameter_names(Array::Handle(Array::New(num_params))); |
| 394 const Type& param_type = Type::Handle(Type::DynamicType()); | 392 const Type& param_type = Type::Handle(Type::DynamicType()); |
| 395 for (int i = 0; i < num_params - 1; i++) { | 393 for (int i = 0; i < num_params - 1; i++) { |
| 396 function.SetParameterTypeAt(i, param_type); | 394 function.SetParameterTypeAt(i, param_type); |
| 397 } | 395 } |
| 398 const bool has_opt_params = true; | 396 const bool has_opt_params = true; |
| 399 const String& native_name = | 397 const String& native_name = |
| 400 String::ZoneHandle(Symbols::New("TestSmiSum")); | 398 String::ZoneHandle(Symbols::New("TestSmiSum")); |
| 401 NativeFunction native_function = | 399 NativeFunction native_function = |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 app_lib ^= libs.At(num_libs - 1); | 509 app_lib ^= libs.At(num_libs - 1); |
| 512 ASSERT(!app_lib.IsNull()); | 510 ASSERT(!app_lib.IsNull()); |
| 513 const Class& cls = Class::Handle( | 511 const Class& cls = Class::Handle( |
| 514 app_lib.LookupClass(String::Handle(Symbols::New("A")))); | 512 app_lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 515 EXPECT_EQ(cls.raw(), result.clazz()); | 513 EXPECT_EQ(cls.raw(), result.clazz()); |
| 516 } | 514 } |
| 517 | 515 |
| 518 } // namespace dart | 516 } // namespace dart |
| 519 | 517 |
| 520 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) | 518 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) |
| OLD | NEW |