From a77b3377b8254f5feb03c4586ad96af9509afb34 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Fri, 12 May 2023 12:02:44 +0530 Subject: [PATCH 1/3] Fix module imports for subroutines --- src/lpython/semantics/python_ast_to_asr.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 1d491286e9..0eccbe5be3 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -5900,6 +5900,21 @@ class BodyVisitor : public CommonVisitor { throw SemanticError("'" + value + "' is not defined in the scope", x.base.base.loc); } + if (ASR::is_a(*t)) { + std::string call_name = at->m_attr; + std::string call_name_store = "__" + value + "_" + call_name; + ASR::Module_t *m = ASR::down_cast(t); + call_name_store = ASRUtils::get_mangled_name(m, call_name_store); + ASR::symbol_t *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 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 elements; elements.reserve(al, c->n_args); for (size_t i = 0; i < c->n_args; ++i) { From 6d08cff01341560d912ff22fcc1f3426b8b4bd35 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Fri, 12 May 2023 12:02:51 +0530 Subject: [PATCH 2/3] Add tests --- integration_tests/CMakeLists.txt | 2 ++ integration_tests/test_sys_01.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 integration_tests/test_sys_01.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index e4b0321dc6..5801f37afa 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -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) diff --git a/integration_tests/test_sys_01.py b/integration_tests/test_sys_01.py new file mode 100644 index 0000000000..e15e0b4503 --- /dev/null +++ b/integration_tests/test_sys_01.py @@ -0,0 +1,2 @@ +import sys +sys.exit(0) From 8472ea42e0038d85705ff60fffd2b9cacb7af4e3 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Fri, 12 May 2023 12:38:09 +0530 Subject: [PATCH 3/3] Import only once --- src/lpython/semantics/python_ast_to_asr.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 0eccbe5be3..58c33df44f 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -5905,9 +5905,12 @@ class BodyVisitor : public CommonVisitor { std::string call_name_store = "__" + value + "_" + call_name; ASR::Module_t *m = ASR::down_cast(t); call_name_store = ASRUtils::get_mangled_name(m, call_name_store); - ASR::symbol_t *st = import_from_module(al, m, current_scope, value, + 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); + current_scope->add_symbol(call_name_store, st); + } Vec args; args.reserve(al, c->n_args); visit_expr_list(c->m_args, c->n_args, args);