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

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

Issue 10928160: Limit the maximum number of formal parameters (32K fixed and 32K optional) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_pos_params = 1;
210 const int num_params = num_fixed_params + num_opt_params; 210 const int num_opt_named_params = 0;
211 const int num_params =
212 num_fixed_params + num_opt_pos_params + num_opt_named_params;
211 LocalScope* local_scope = node_seq->scope(); 213 LocalScope* local_scope = node_seq->scope();
212 local_scope->AddVariable(NewTestLocalVariable("a")); 214 local_scope->AddVariable(NewTestLocalVariable("a"));
213 local_scope->AddVariable(NewTestLocalVariable("b")); 215 local_scope->AddVariable(NewTestLocalVariable("b"));
214 ASSERT(local_scope->num_variables() == num_params); 216 ASSERT(local_scope->num_variables() == num_params);
215 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); 217 const Array& default_values =
218 Array::ZoneHandle(Array::New(num_opt_pos_params));
216 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. 219 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1.
217 test->set_default_parameter_values(default_values); 220 test->set_default_parameter_values(default_values);
218 const Function& function = test->function(); 221 const Function& function = test->function();
219 function.SetNumberOfParameters(num_fixed_params, num_opt_params, true); 222 function.set_num_fixed_parameters(num_fixed_params);
223 function.SetNumOptionalParameters(num_opt_pos_params, num_opt_named_params);
220 const bool has_opt_params = true; 224 const bool has_opt_params = true;
221 const String& native_name = 225 const String& native_name =
222 String::ZoneHandle(Symbols::New("TestSmiSub")); 226 String::ZoneHandle(Symbols::New("TestSmiSub"));
223 NativeFunction native_function = 227 NativeFunction native_function =
224 reinterpret_cast<NativeFunction>(TestSmiSub); 228 reinterpret_cast<NativeFunction>(TestSmiSub);
225 node_seq->Add(new ReturnNode(kPos, 229 node_seq->Add(new ReturnNode(kPos,
226 new NativeBodyNode(kPos, 230 new NativeBodyNode(kPos,
227 native_name, 231 native_name,
228 native_function, 232 native_function,
229 num_params, 233 num_params,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 CODEGEN_TEST_RUN(InstanceCallCodegen, Smi::New(42)) 368 CODEGEN_TEST_RUN(InstanceCallCodegen, Smi::New(42))
365 369
366 370
367 // Tested Dart code: 371 // Tested Dart code:
368 // int sum(int a, int b, 372 // int sum(int a, int b,
369 // [int c = 10, int d = 21, int e = -32]) native: "TestSmiSum"; 373 // [int c = 10, int d = 21, int e = -32]) native: "TestSmiSum";
370 // The native entry TestSmiSum implements sum natively. 374 // The native entry TestSmiSum implements sum natively.
371 CODEGEN_TEST_GENERATE(NativeSumCodegen, test) { 375 CODEGEN_TEST_GENERATE(NativeSumCodegen, test) {
372 SequenceNode* node_seq = test->node_sequence(); 376 SequenceNode* node_seq = test->node_sequence();
373 const int num_fixed_params = 2; 377 const int num_fixed_params = 2;
374 const int num_opt_params = 3; 378 const int num_opt_pos_params = 3;
375 const int num_params = num_fixed_params + num_opt_params; 379 const int num_opt_named_params = 0;
380 const int num_params =
381 num_fixed_params + num_opt_pos_params + num_opt_named_params;
376 LocalScope* local_scope = node_seq->scope(); 382 LocalScope* local_scope = node_seq->scope();
377 local_scope->AddVariable(NewTestLocalVariable("a")); 383 local_scope->AddVariable(NewTestLocalVariable("a"));
378 local_scope->AddVariable(NewTestLocalVariable("b")); 384 local_scope->AddVariable(NewTestLocalVariable("b"));
379 local_scope->AddVariable(NewTestLocalVariable("c")); 385 local_scope->AddVariable(NewTestLocalVariable("c"));
380 local_scope->AddVariable(NewTestLocalVariable("d")); 386 local_scope->AddVariable(NewTestLocalVariable("d"));
381 local_scope->AddVariable(NewTestLocalVariable("e")); 387 local_scope->AddVariable(NewTestLocalVariable("e"));
382 ASSERT(local_scope->num_variables() == num_params); 388 ASSERT(local_scope->num_variables() == num_params);
383 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); 389 const Array& default_values =
390 Array::ZoneHandle(Array::New(num_opt_pos_params));
384 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10))); 391 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(10)));
385 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21))); 392 default_values.SetAt(1, Smi::ZoneHandle(Smi::New(21)));
386 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32))); 393 default_values.SetAt(2, Smi::ZoneHandle(Smi::New(-32)));
387 test->set_default_parameter_values(default_values); 394 test->set_default_parameter_values(default_values);
388 const Function& function = test->function(); 395 const Function& function = test->function();
389 function.SetNumberOfParameters(num_fixed_params, num_opt_params, true); 396 function.set_num_fixed_parameters(num_fixed_params);
397 function.SetNumOptionalParameters(num_opt_pos_params, num_opt_named_params);
390 function.set_parameter_types(Array::Handle(Array::New(num_params))); 398 function.set_parameter_types(Array::Handle(Array::New(num_params)));
391 function.set_parameter_names(Array::Handle(Array::New(num_params))); 399 function.set_parameter_names(Array::Handle(Array::New(num_params)));
392 const Type& param_type = Type::Handle(Type::DynamicType()); 400 const Type& param_type = Type::Handle(Type::DynamicType());
393 for (int i = 0; i < num_params - 1; i++) { 401 for (int i = 0; i < num_params - 1; i++) {
394 function.SetParameterTypeAt(i, param_type); 402 function.SetParameterTypeAt(i, param_type);
395 } 403 }
396 const bool has_opt_params = true; 404 const bool has_opt_params = true;
397 const String& native_name = 405 const String& native_name =
398 String::ZoneHandle(Symbols::New("TestSmiSum")); 406 String::ZoneHandle(Symbols::New("TestSmiSum"));
399 NativeFunction native_function = 407 NativeFunction native_function =
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 app_lib ^= libs.At(num_libs - 1); 517 app_lib ^= libs.At(num_libs - 1);
510 ASSERT(!app_lib.IsNull()); 518 ASSERT(!app_lib.IsNull());
511 const Class& cls = Class::Handle( 519 const Class& cls = Class::Handle(
512 app_lib.LookupClass(String::Handle(Symbols::New("A")))); 520 app_lib.LookupClass(String::Handle(Symbols::New("A"))));
513 EXPECT_EQ(cls.raw(), result.clazz()); 521 EXPECT_EQ(cls.raw(), result.clazz());
514 } 522 }
515 523
516 } // namespace dart 524 } // namespace dart
517 525
518 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) 526 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64)
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/compiler.cc » ('j') | runtime/vm/object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698