@@ -423,6 +423,10 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
423
423
ASR::symbol_t * import_from_module (Allocator &al, ASR::Module_t *m, SymbolTable *current_scope,
424
424
std::string mname, std::string cur_sym_name, std::string new_sym_name,
425
425
const Location &loc, bool skip_current_scope_check=false ) {
426
+ // std::cout<<"module_name: "<<m->m_name<<std::endl;
427
+ // for( auto& itr: m->m_symtab->get_scope() ) {
428
+ // std::cout<<"itr.first: "<<itr.first<<std::endl;
429
+ // }
426
430
ASR::symbol_t *t = m->m_symtab ->resolve_symbol (cur_sym_name);
427
431
if (!t) {
428
432
throw SemanticError (" The symbol '" + cur_sym_name + " ' not found in the module '" + mname + " '" ,
@@ -481,11 +485,20 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
481
485
} else if (ASR::is_a<ASR::ExternalSymbol_t>(*t)) {
482
486
ASR::ExternalSymbol_t *es = ASR::down_cast<ASR::ExternalSymbol_t>(t);
483
487
SymbolTable *symtab = current_scope;
484
- while (symtab->parent != nullptr ) symtab = symtab->parent ;
485
- ASR::symbol_t *sym = symtab->get_symbol (es->m_module_name );
488
+ // while (symtab->parent != nullptr) symtab = symtab->parent;
489
+ ASR::symbol_t *sym = symtab->resolve_symbol (es->m_module_name );
486
490
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(sym);
487
- return import_from_module (al, m, symtab, es->m_name ,
491
+ return import_from_module (al, m, symtab, es->m_module_name ,
488
492
cur_sym_name, new_sym_name, loc);
493
+ } else if (ASR::is_a<ASR::Module_t>(*t)) {
494
+ ASR::Module_t* mt = ASR::down_cast<ASR::Module_t>(t);
495
+ std::string mangled_cur_sym_name = ASRUtils::get_mangled_name (mt, new_sym_name);
496
+ // std::cout<<"names: "<<mt->m_name<<" "<<cur_sym_name<<" "<<mangled_cur_sym_name<<" "<<new_sym_name<<" "<<mname<<std::endl;
497
+ if ( cur_sym_name == mangled_cur_sym_name ) {
498
+ throw SemanticError (" Importing modules isn't supported yet." , loc);
499
+ }
500
+ return import_from_module (al, mt, current_scope, std::string (mt->m_name ),
501
+ cur_sym_name, new_sym_name, loc);
489
502
} else {
490
503
throw SemanticError (" Only Subroutines, Functions, Variables and "
491
504
" ExternalSymbol are currently supported in 'import'" , loc);
@@ -3566,10 +3579,19 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
3566
3579
for (auto &mod_sym : mods) {
3567
3580
bool ltypes, enum_py;
3568
3581
set_module_symbol (mod_sym, paths);
3582
+ // std::cout<<"msym: "<<mod_sym<<" ";
3583
+ // for( auto path: paths ) {
3584
+ // std::cout<<path<<", ";
3585
+ // }
3586
+ // std::cout<<std::endl;
3569
3587
t = (ASR::symbol_t *)(load_module (al, st,
3570
3588
mod_sym, x.base .base .loc , diag, lm, false , paths, ltypes, enum_py,
3571
3589
[&](const std::string &msg, const Location &loc) { throw SemanticError (msg, loc); },
3572
3590
allow_implicit_casting));
3591
+ // std::cout<<"module_name.imported: "<<ASRUtils::symbol_name(t)<<std::endl;
3592
+ // for( auto& itr: ASRUtils::symbol_symtab(t)->get_scope() ) {
3593
+ // std::cout<<"itr.first: "<<itr.first<<std::endl;
3594
+ // }
3573
3595
if (ltypes || enum_py) {
3574
3596
// TODO: For now we skip ltypes import completely. Later on we should note what symbols
3575
3597
// got imported from it, and give an error message if an annotation is used without
@@ -5898,7 +5920,13 @@ Result<ASR::TranslationUnit_t*> python_ast_to_asr(Allocator &al, LocationManager
5898
5920
} else {
5899
5921
return res2.error ;
5900
5922
}
5901
- LFORTRAN_ASSERT (asr_verify (*tu, true , diagnostics));
5923
+ #if defined(WITH_LFORTRAN_ASSERT)
5924
+ diag::Diagnostics diagnostics;
5925
+ if (!asr_verify (*tu, true , diagnostics)) {
5926
+ std::cerr << diagnostics.render2 ();
5927
+ throw LCompilersException (" Verify failed" );
5928
+ };
5929
+ #endif
5902
5930
}
5903
5931
5904
5932
if (main_module) {
0 commit comments