Skip to content

ASR: Fix module imports for subroutines #1795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ RUN(NAME vec_01 LABELS cpython llvm c)
RUN(NAME test_str_comparison LABELS cpython llvm c)
RUN(NAME test_bit_length LABELS cpython llvm c)
RUN(NAME str_to_list_cast LABELS cpython llvm c)
RUN(NAME test_sys_01 LABELS cpython llvm c)


RUN(NAME test_package_01 LABELS cpython llvm)
RUN(NAME test_pkg_lpdraw LABELS cpython llvm wasm)
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/test_sys_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import sys
sys.exit(0)
18 changes: 18 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5900,6 +5900,24 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
throw SemanticError("'" + value + "' is not defined in the scope",
x.base.base.loc);
}
if (ASR::is_a<ASR::Module_t>(*t)) {
std::string call_name = at->m_attr;
std::string call_name_store = "__" + value + "_" + call_name;
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t);
call_name_store = ASRUtils::get_mangled_name(m, call_name_store);
ASR::symbol_t *st = current_scope->resolve_symbol(call_name_store);
if (!st) {
st = import_from_module(al, m, current_scope, value,
call_name, call_name_store, x.base.base.loc);
current_scope->add_symbol(call_name_store, st);
}
Vec<ASR::call_arg_t> args;
args.reserve(al, c->n_args);
visit_expr_list(c->m_args, c->n_args, args);
tmp = make_call_helper(al, st, current_scope, args,
call_name, x.base.base.loc);
return;
}
Vec<ASR::expr_t*> elements;
elements.reserve(al, c->n_args);
for (size_t i = 0; i < c->n_args; ++i) {
Expand Down