Skip to content

Commit 20d9536

Browse files
authored
Merge pull request #1795 from Smit-create/i-1782
ASR: Fix module imports for subroutines
2 parents cf1160b + 8472ea4 commit 20d9536

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ RUN(NAME vec_01 LABELS cpython llvm c)
499499
RUN(NAME test_str_comparison LABELS cpython llvm c)
500500
RUN(NAME test_bit_length LABELS cpython llvm c)
501501
RUN(NAME str_to_list_cast LABELS cpython llvm c)
502+
RUN(NAME test_sys_01 LABELS cpython llvm c)
503+
502504

503505
RUN(NAME test_package_01 LABELS cpython llvm)
504506
RUN(NAME test_pkg_lpdraw LABELS cpython llvm wasm)

integration_tests/test_sys_01.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import sys
2+
sys.exit(0)

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5900,6 +5900,24 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
59005900
throw SemanticError("'" + value + "' is not defined in the scope",
59015901
x.base.base.loc);
59025902
}
5903+
if (ASR::is_a<ASR::Module_t>(*t)) {
5904+
std::string call_name = at->m_attr;
5905+
std::string call_name_store = "__" + value + "_" + call_name;
5906+
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t);
5907+
call_name_store = ASRUtils::get_mangled_name(m, call_name_store);
5908+
ASR::symbol_t *st = current_scope->resolve_symbol(call_name_store);
5909+
if (!st) {
5910+
st = import_from_module(al, m, current_scope, value,
5911+
call_name, call_name_store, x.base.base.loc);
5912+
current_scope->add_symbol(call_name_store, st);
5913+
}
5914+
Vec<ASR::call_arg_t> args;
5915+
args.reserve(al, c->n_args);
5916+
visit_expr_list(c->m_args, c->n_args, args);
5917+
tmp = make_call_helper(al, st, current_scope, args,
5918+
call_name, x.base.base.loc);
5919+
return;
5920+
}
59035921
Vec<ASR::expr_t*> elements;
59045922
elements.reserve(al, c->n_args);
59055923
for (size_t i = 0; i < c->n_args; ++i) {

0 commit comments

Comments
 (0)