# HG changeset patch # User David Anderson # Date 1358037326 28800 # Node ID 05de34f712fe4e281521d3801d19e9ef6fc66966 # Parent 99ab8b19f0b9a0399ec2d35fc85c218ad12535c6 Add support for mutually recursive imports. diff -r 99ab8b19f0b9 -r 05de34f712fe src/compiler/CompileContext.cpp --- a/src/compiler/CompileContext.cpp Sat Jan 12 16:26:09 2013 -0800 +++ b/src/compiler/CompileContext.cpp Sat Jan 12 16:35:26 2013 -0800 @@ -231,7 +231,7 @@ bool CompileContext::add(Handle module) { - if (module->compiled()) + if (module->compiled() || module->translationUnit()) return true; TranslationUnit *tu = new (zone_->pool()) TranslationUnit(module); @@ -239,6 +239,8 @@ if (!unparsed_.append(tu) || !units_.append(tu)) return false; + module->setTranslationUnit(tu); + return true; } @@ -289,9 +291,6 @@ if (unit->failed()) continue; - // Mark the module as currently in translation. - unit->module()->setTranslationUnit(unit); - PopulateNamesAndTypes(zone_, *this, unit); } @@ -309,11 +308,6 @@ BindNamesAndTypes(zone_, *this, unit); } - // Intermediate phase. Decide which modules we should not perform - // semantic analysis on. - if (!propagateFailure()) - return false; - // Phase 4. Now we can finally perform SemA+bytecode compilation. for (size_t i = 0; i < units_.length(); i++) { TranslationUnit *unit = units_[i]; diff -r 99ab8b19f0b9 -r 05de34f712fe src/compiler/NameBinding.cpp --- a/src/compiler/NameBinding.cpp Sat Jan 12 16:26:09 2013 -0800 +++ b/src/compiler/NameBinding.cpp Sat Jan 12 16:35:26 2013 -0800 @@ -897,7 +897,9 @@ assert(false); } else { Local module(zone_, Module::cast(importable)); - if (!module->globals()) + + // Always grab from the translation unit if we can, for now. + if (module->translationUnit()) importFromTranslationUnit(node, module->translationUnit()); else assert(false); diff -r 99ab8b19f0b9 -r 05de34f712fe tests/basic/recursive_import_1_a.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/recursive_import_1_a.out Sat Jan 12 16:35:26 2013 -0800 @@ -0,0 +1,1 @@ +10 diff -r 99ab8b19f0b9 -r 05de34f712fe tests/basic/recursive_import_1_a.sp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/recursive_import_1_a.sp Sat Jan 12 16:35:26 2013 -0800 @@ -0,0 +1,9 @@ +from recursive_import_1_b import f; + +native PrintNum(num); + +public main() +{ + f(); +} + diff -r 99ab8b19f0b9 -r 05de34f712fe tests/basic/recursive_import_1_b.sp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/basic/recursive_import_1_b.sp Sat Jan 12 16:35:26 2013 -0800 @@ -0,0 +1,6 @@ +from recursive_import_1_a import PrintNum; + +public f() +{ + PrintNum(10); +}