| 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/globals.h" | 5 #include "platform/globals.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 const Type& variable_type = Type::ZoneHandle(Type::DynamicType()); | 51 const Type& variable_type = Type::ZoneHandle(Type::DynamicType()); |
| 52 return new LocalVariable(kPos, variable_name, variable_type); | 52 return new LocalVariable(kPos, variable_name, variable_type); |
| 53 } | 53 } |
| 54 | 54 |
| 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->InsertParameterAt(0, 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.HasOptionalParameters()); | 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, |
| 76 new StaticCallNode(kPos, function, arguments))); | 76 new StaticCallNode(kPos, function, arguments))); |
| 77 } | 77 } |
| 78 CODEGEN_TEST2_RUN(StaticCallReturnParameterCodegen, | 78 CODEGEN_TEST2_RUN(StaticCallReturnParameterCodegen, |
| 79 ReturnParameterCodegen, | 79 ReturnParameterCodegen, |
| 80 Smi::New(3)) | 80 Smi::New(3)) |
| 81 | 81 |
| 82 | 82 |
| 83 CODEGEN_TEST_GENERATE(SmiParamSumCodegen, test) { | 83 CODEGEN_TEST_GENERATE(SmiParamSumCodegen, test) { |
| 84 SequenceNode* node_seq = test->node_sequence(); | 84 SequenceNode* node_seq = test->node_sequence(); |
| 85 const int num_params = 2; | 85 const int num_params = 2; |
| 86 LocalVariable* param1 = NewTestLocalVariable("param1"); | 86 LocalVariable* param1 = NewTestLocalVariable("param1"); |
| 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->InsertParameterAt(0, param1); |
| 92 local_scope->AddVariable(param2); | 92 local_scope->InsertParameterAt(1, 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.HasOptionalParameters()); | 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)); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // A NativeBodyNode, preceded by an EnterNode and followed by a ReturnNode, | 199 // A NativeBodyNode, preceded by an EnterNode and followed by a ReturnNode, |
| 200 // implements the body of a native Dart function. Let's take this native | 200 // implements the body of a native Dart function. Let's take this native |
| 201 // function as an example: int dec(int a, int b = 1) native; | 201 // function as an example: int dec(int a, int b = 1) native; |
| 202 // Since this function has an optional parameter, its prologue will copy | 202 // Since this function has an optional parameter, its prologue will copy |
| 203 // incoming parameters to locals. | 203 // incoming parameters to locals. |
| 204 SequenceNode* node_seq = test->node_sequence(); | 204 SequenceNode* node_seq = test->node_sequence(); |
| 205 const int num_fixed_params = 1; | 205 const int num_fixed_params = 1; |
| 206 const int num_opt_params = 1; | 206 const int num_opt_params = 1; |
| 207 const int num_params = num_fixed_params + num_opt_params; | 207 const int num_params = num_fixed_params + num_opt_params; |
| 208 LocalScope* local_scope = node_seq->scope(); | 208 LocalScope* local_scope = node_seq->scope(); |
| 209 local_scope->AddVariable(NewTestLocalVariable("a")); | 209 local_scope->InsertParameterAt(0, NewTestLocalVariable("a")); |
| 210 local_scope->AddVariable(NewTestLocalVariable("b")); | 210 local_scope->InsertParameterAt(1, NewTestLocalVariable("b")); |
| 211 ASSERT(local_scope->num_variables() == num_params); | 211 ASSERT(local_scope->num_variables() == num_params); |
| 212 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); | 212 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); |
| 213 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. | 213 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. |
| 214 test->set_default_parameter_values(default_values); | 214 test->set_default_parameter_values(default_values); |
| 215 const Function& function = test->function(); | 215 const Function& function = test->function(); |
| 216 function.set_is_native(true); | 216 function.set_is_native(true); |
| 217 function.set_num_fixed_parameters(num_fixed_params); | 217 function.set_num_fixed_parameters(num_fixed_params); |
| 218 function.SetNumOptionalParameters(num_opt_params, true); | 218 function.SetNumOptionalParameters(num_opt_params, true); |
| 219 const String& native_name = | 219 const String& native_name = |
| 220 String::ZoneHandle(Symbols::New("TestSmiSub")); | 220 String::ZoneHandle(Symbols::New("TestSmiSub")); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Tested Dart code: | 370 // Tested Dart code: |
| 371 // int sum(int a, int b, | 371 // int sum(int a, int b, |
| 372 // [int c = 10, int d = 21, int e = -32]) native: "TestSmiSum"; | 372 // [int c = 10, int d = 21, int e = -32]) native: "TestSmiSum"; |
| 373 // The native entry TestSmiSum implements sum natively. | 373 // The native entry TestSmiSum implements sum natively. |
| 374 CODEGEN_TEST_GENERATE(NativeSumCodegen, test) { | 374 CODEGEN_TEST_GENERATE(NativeSumCodegen, test) { |
| 375 SequenceNode* node_seq = test->node_sequence(); | 375 SequenceNode* node_seq = test->node_sequence(); |
| 376 const int num_fixed_params = 2; | 376 const int num_fixed_params = 2; |
| 377 const int num_opt_params = 3; | 377 const int num_opt_params = 3; |
| 378 const int num_params = num_fixed_params + num_opt_params; | 378 const int num_params = num_fixed_params + num_opt_params; |
| 379 LocalScope* local_scope = node_seq->scope(); | 379 LocalScope* local_scope = node_seq->scope(); |
| 380 local_scope->AddVariable(NewTestLocalVariable("a")); | 380 local_scope->InsertParameterAt(0, NewTestLocalVariable("a")); |
| 381 local_scope->AddVariable(NewTestLocalVariable("b")); | 381 local_scope->InsertParameterAt(1, NewTestLocalVariable("b")); |
| 382 local_scope->AddVariable(NewTestLocalVariable("c")); | 382 local_scope->InsertParameterAt(2, NewTestLocalVariable("c")); |
| 383 local_scope->AddVariable(NewTestLocalVariable("d")); | 383 local_scope->InsertParameterAt(3, NewTestLocalVariable("d")); |
| 384 local_scope->AddVariable(NewTestLocalVariable("e")); | 384 local_scope->InsertParameterAt(4, NewTestLocalVariable("e")); |
| 385 ASSERT(local_scope->num_variables() == num_params); | 385 ASSERT(local_scope->num_variables() == num_params); |
| 386 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); | 386 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); |
| 387 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10))); | 387 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10))); |
| 388 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); | 388 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); |
| 389 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); | 389 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); |
| 390 test->set_default_parameter_values(default_values); | 390 test->set_default_parameter_values(default_values); |
| 391 const Function& function = test->function(); | 391 const Function& function = test->function(); |
| 392 function.set_is_native(true); | 392 function.set_is_native(true); |
| 393 function.set_num_fixed_parameters(num_fixed_params); | 393 function.set_num_fixed_parameters(num_fixed_params); |
| 394 function.SetNumOptionalParameters(num_opt_params, true); | 394 function.SetNumOptionalParameters(num_opt_params, true); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 Smi::New(0 + 1 + 1 + 2 + 3)) | 467 Smi::New(0 + 1 + 1 + 2 + 3)) |
| 468 | 468 |
| 469 | 469 |
| 470 // Tested Dart code: | 470 // Tested Dart code: |
| 471 // int sum(a, b, c) native: "TestNonNullSmiSum"; | 471 // int sum(a, b, c) native: "TestNonNullSmiSum"; |
| 472 // The native entry TestNonNullSmiSum implements sum natively. | 472 // The native entry TestNonNullSmiSum implements sum natively. |
| 473 CODEGEN_TEST_GENERATE(NativeNonNullSumCodegen, test) { | 473 CODEGEN_TEST_GENERATE(NativeNonNullSumCodegen, test) { |
| 474 SequenceNode* node_seq = test->node_sequence(); | 474 SequenceNode* node_seq = test->node_sequence(); |
| 475 const int num_params = 3; | 475 const int num_params = 3; |
| 476 LocalScope* local_scope = node_seq->scope(); | 476 LocalScope* local_scope = node_seq->scope(); |
| 477 local_scope->AddVariable(NewTestLocalVariable("a")); | 477 local_scope->InsertParameterAt(0, NewTestLocalVariable("a")); |
| 478 local_scope->AddVariable(NewTestLocalVariable("b")); | 478 local_scope->InsertParameterAt(1, NewTestLocalVariable("b")); |
| 479 local_scope->AddVariable(NewTestLocalVariable("c")); | 479 local_scope->InsertParameterAt(2, NewTestLocalVariable("c")); |
| 480 ASSERT(local_scope->num_variables() == num_params); | 480 ASSERT(local_scope->num_variables() == num_params); |
| 481 const Function& function = test->function(); | 481 const Function& function = test->function(); |
| 482 function.set_is_native(true); | 482 function.set_is_native(true); |
| 483 function.set_num_fixed_parameters(num_params); | 483 function.set_num_fixed_parameters(num_params); |
| 484 ASSERT(!function.HasOptionalParameters()); | 484 ASSERT(!function.HasOptionalParameters()); |
| 485 function.set_parameter_types(Array::Handle(Array::New(num_params))); | 485 function.set_parameter_types(Array::Handle(Array::New(num_params))); |
| 486 function.set_parameter_names(Array::Handle(Array::New(num_params))); | 486 function.set_parameter_names(Array::Handle(Array::New(num_params))); |
| 487 const Type& param_type = Type::Handle(Type::DynamicType()); | 487 const Type& param_type = Type::Handle(Type::DynamicType()); |
| 488 for (int i = 0; i < num_params; i++) { | 488 for (int i = 0; i < num_params; i++) { |
| 489 function.SetParameterTypeAt(i, param_type); | 489 function.SetParameterTypeAt(i, param_type); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 intptr_t num_libs = libs.Length(); | 561 intptr_t num_libs = libs.Length(); |
| 562 Library& app_lib = Library::Handle(); | 562 Library& app_lib = Library::Handle(); |
| 563 app_lib ^= libs.At(num_libs - 1); | 563 app_lib ^= libs.At(num_libs - 1); |
| 564 ASSERT(!app_lib.IsNull()); | 564 ASSERT(!app_lib.IsNull()); |
| 565 const Class& cls = Class::Handle( | 565 const Class& cls = Class::Handle( |
| 566 app_lib.LookupClass(String::Handle(Symbols::New("A")))); | 566 app_lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 567 EXPECT_EQ(cls.raw(), result.clazz()); | 567 EXPECT_EQ(cls.raw(), result.clazz()); |
| 568 } | 568 } |
| 569 | 569 |
| 570 } // namespace dart | 570 } // namespace dart |
| OLD | NEW |