Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: runtime/vm/code_generator_test.cc

Issue 11468016: Rename GET_NATIVE_ARGUMENT macro to GET_NON_NULL_NATIVE_ARGUMENT. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); 389 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21)));
390 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); 390 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32)));
391 test->set_default_parameter_values(default_values); 391 test->set_default_parameter_values(default_values);
392 const Function& function = test->function(); 392 const Function& function = test->function();
393 function.set_is_native(true); 393 function.set_is_native(true);
394 function.set_num_fixed_parameters(num_fixed_params); 394 function.set_num_fixed_parameters(num_fixed_params);
395 function.SetNumOptionalParameters(num_opt_params, true); 395 function.SetNumOptionalParameters(num_opt_params, true);
396 function.set_parameter_types(Array::Handle(Array::New(num_params))); 396 function.set_parameter_types(Array::Handle(Array::New(num_params)));
397 function.set_parameter_names(Array::Handle(Array::New(num_params))); 397 function.set_parameter_names(Array::Handle(Array::New(num_params)));
398 const Type& param_type = Type::Handle(Type::DynamicType()); 398 const Type& param_type = Type::Handle(Type::DynamicType());
399 for (int i = 0; i < num_params - 1; i++) { 399 for (int i = 0; i < num_params; i++) {
400 function.SetParameterTypeAt(i, param_type); 400 function.SetParameterTypeAt(i, param_type);
401 } 401 }
402 const String& native_name = 402 const String& native_name =
403 String::ZoneHandle(Symbols::New("TestSmiSum")); 403 String::ZoneHandle(Symbols::New("TestSmiSum"));
404 NativeFunction native_function = 404 NativeFunction native_function =
405 reinterpret_cast<NativeFunction>(TestSmiSum); 405 reinterpret_cast<NativeFunction>(TestSmiSum);
406 node_seq->Add(new ReturnNode(kPos, 406 node_seq->Add(new ReturnNode(kPos,
407 new NativeBodyNode(kPos, 407 new NativeBodyNode(kPos,
408 function, 408 function,
409 native_name, 409 native_name,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3)))); 458 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))));
459 node_seq->Add(new ReturnNode(kPos, 459 node_seq->Add(new ReturnNode(kPos,
460 new StaticCallNode(kPos, function, arguments))); 460 new StaticCallNode(kPos, function, arguments)));
461 } 461 }
462 CODEGEN_TEST2_RUN( 462 CODEGEN_TEST2_RUN(
463 StaticSumCallTenFiboCodegen, 463 StaticSumCallTenFiboCodegen,
464 NativeSumCodegen, 464 NativeSumCodegen,
465 Smi::New(0 + 1 + 1 + 2 + 3)) 465 Smi::New(0 + 1 + 1 + 2 + 3))
466 466
467 467
468 // Tested Dart code:
469 // int sum(a, b, c) native: "TestNonNullSmiSum";
470 // The native entry TestNonNullSmiSum implements sum natively.
471 CODEGEN_TEST_GENERATE(NativeNonNullSumCodegen, test) {
472 SequenceNode* node_seq = test->node_sequence();
473 const int num_params = 3;
474 LocalScope* local_scope = node_seq->scope();
475 local_scope->AddVariable(NewTestLocalVariable("a"));
476 local_scope->AddVariable(NewTestLocalVariable("b"));
477 local_scope->AddVariable(NewTestLocalVariable("c"));
478 ASSERT(local_scope->num_variables() == num_params);
479 const Function& function = test->function();
480 function.set_is_native(true);
481 function.set_num_fixed_parameters(num_params);
482 ASSERT(!function.HasOptionalParameters());
483 function.set_parameter_types(Array::Handle(Array::New(num_params)));
484 function.set_parameter_names(Array::Handle(Array::New(num_params)));
485 const Type& param_type = Type::Handle(Type::DynamicType());
486 for (int i = 0; i < num_params; i++) {
487 function.SetParameterTypeAt(i, param_type);
488 }
489 const String& native_name =
490 String::ZoneHandle(Symbols::New("TestNonNullSmiSum"));
491 NativeFunction native_function =
492 reinterpret_cast<NativeFunction>(TestNonNullSmiSum);
493 node_seq->Add(new ReturnNode(kPos,
494 new NativeBodyNode(kPos,
495 function,
496 native_name,
497 native_function)));
498 }
499
500
501 // Tested Dart code, calling function sum declared above:
502 // return sum(1, null, 3);
503 CODEGEN_TEST2_GENERATE(StaticNonNullSumCallCodegen, function, test) {
504 SequenceNode* node_seq = test->node_sequence();
505 ArgumentListNode* arguments = new ArgumentListNode(kPos);
506 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1))));
507 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle()));
508 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))));
509 node_seq->Add(new ReturnNode(kPos,
510 new StaticCallNode(kPos, function, arguments)));
511 }
512 CODEGEN_TEST2_RUN(StaticNonNullSumCallCodegen,
513 NativeNonNullSumCodegen,
514 Smi::New(1 + 3))
515
516
468 // Test allocation of dart objects. 517 // Test allocation of dart objects.
469 CODEGEN_TEST_GENERATE(AllocateNewObjectCodegen, test) { 518 CODEGEN_TEST_GENERATE(AllocateNewObjectCodegen, test) {
470 const char* kScriptChars = 519 const char* kScriptChars =
471 "class A {\n" 520 "class A {\n"
472 " A() {}\n" 521 " A() {}\n"
473 " static bar() { return 42; }\n" 522 " static bar() { return 42; }\n"
474 "}\n"; 523 "}\n";
475 524
476 String& url = String::Handle(String::New("dart-test:CompileScript")); 525 String& url = String::Handle(String::New("dart-test:CompileScript"));
477 String& source = String::Handle(String::New(kScriptChars)); 526 String& source = String::Handle(String::New(kScriptChars));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 app_lib ^= libs.At(num_libs - 1); 561 app_lib ^= libs.At(num_libs - 1);
513 ASSERT(!app_lib.IsNull()); 562 ASSERT(!app_lib.IsNull());
514 const Class& cls = Class::Handle( 563 const Class& cls = Class::Handle(
515 app_lib.LookupClass(String::Handle(Symbols::New("A")))); 564 app_lib.LookupClass(String::Handle(Symbols::New("A"))));
516 EXPECT_EQ(cls.raw(), result.clazz()); 565 EXPECT_EQ(cls.raw(), result.clazz());
517 } 566 }
518 567
519 } // namespace dart 568 } // namespace dart
520 569
521 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) 570 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698