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

Side by Side Diff: src/full-codegen.cc

Issue 9722043: Refactor code generation for global declarations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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
« no previous file with comments | « src/full-codegen.h ('k') | src/hydrogen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 void FullCodeGenerator::DoTest(const TestContext* context) { 563 void FullCodeGenerator::DoTest(const TestContext* context) {
564 DoTest(context->condition(), 564 DoTest(context->condition(),
565 context->true_label(), 565 context->true_label(),
566 context->false_label(), 566 context->false_label(),
567 context->fall_through()); 567 context->fall_through());
568 } 568 }
569 569
570 570
571 void FullCodeGenerator::VisitDeclarations( 571 void FullCodeGenerator::VisitDeclarations(
572 ZoneList<Declaration*>* declarations) { 572 ZoneList<Declaration*>* declarations) {
573 int save_global_count = global_count_; 573 ASSERT(globals_.is_empty());
574 global_count_ = 0;
575
576 AstVisitor::VisitDeclarations(declarations); 574 AstVisitor::VisitDeclarations(declarations);
577 575 if (!globals_.is_empty()) {
578 // Batch declare global functions and variables.
579 if (global_count_ > 0) {
580 Handle<FixedArray> array =
581 isolate()->factory()->NewFixedArray(2 * global_count_, TENURED);
582 int length = declarations->length();
583 for (int j = 0, i = 0; i < length; i++) {
584 Declaration* decl = declarations->at(i);
585 Variable* var = decl->proxy()->var();
586
587 if (var->IsUnallocated()) {
588 array->set(j++, *(var->name()));
589 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration();
590 if (fun_decl == NULL) {
591 if (var->binding_needs_init()) {
592 // In case this binding needs initialization use the hole.
593 array->set_the_hole(j++);
594 } else {
595 array->set_undefined(j++);
596 }
597 } else {
598 Handle<SharedFunctionInfo> function =
599 Compiler::BuildFunctionInfo(fun_decl->fun(), script());
600 // Check for stack-overflow exception.
601 if (function.is_null()) {
602 SetStackOverflow();
603 return;
604 }
605 array->set(j++, *function);
606 }
607 }
608 }
609 // Invoke the platform-dependent code generator to do the actual 576 // Invoke the platform-dependent code generator to do the actual
610 // declaration the global functions and variables. 577 // declaration the global functions and variables.
578 Handle<FixedArray> array =
579 isolate()->factory()->NewFixedArray(globals_.length(), TENURED);
580 for (int i = 0; i < globals_.length(); ++i) array->set(i, *globals_.at(i));
611 DeclareGlobals(array); 581 DeclareGlobals(array);
582 globals_.Clear();
612 } 583 }
613
614 global_count_ = save_global_count;
615 } 584 }
616 585
617 586
618 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { 587 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) {
619 // TODO(rossberg) 588 // TODO(rossberg)
620 } 589 }
621 590
622 591
623 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) { 592 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) {
624 // TODO(rossberg) 593 // TODO(rossberg)
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 } 1365 }
1397 1366
1398 return false; 1367 return false;
1399 } 1368 }
1400 1369
1401 1370
1402 #undef __ 1371 #undef __
1403 1372
1404 1373
1405 } } // namespace v8::internal 1374 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/full-codegen.h ('k') | src/hydrogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698