diff --git a/src/libasr/pass/global_stmts.cpp b/src/libasr/pass/global_stmts.cpp index 8a9c35f89e..5a6f775571 100644 --- a/src/libasr/pass/global_stmts.cpp +++ b/src/libasr/pass/global_stmts.cpp @@ -91,6 +91,7 @@ void pass_wrap_global_stmts(Allocator &al, target = return_var_ref; idx++; } else { + // TODO: We will need to add support to return other ASR::ttypeType::* throw LCompilersException("Return type not supported in interactive mode"); } ASR::stmt_t* asr_stmt = ASRUtils::STMT(ASR::make_Assignment_t(al, loc, target, value, nullptr)); @@ -119,7 +120,7 @@ void pass_wrap_global_stmts(Allocator &al, /* a_body */ body.p, /* n_body */ body.size(), /* a_return_var */ (return_var ? return_var_ref : nullptr), - (return_var ? ASR::abiType::BindC : ASR::abiType::Source), + ASR::abiType::Source, ASR::Public, ASR::Implementation, nullptr, false, false, false, false, false, diff --git a/src/lpython/python_evaluator.cpp b/src/lpython/python_evaluator.cpp index f7314fcb32..daaa25f9a9 100644 --- a/src/lpython/python_evaluator.cpp +++ b/src/lpython/python_evaluator.cpp @@ -105,13 +105,48 @@ Result PythonCompiler::evaluate( } bool call_run_fn = false; + std::string return_type; if (m->get_return_type(run_fn) != "none") { call_run_fn = true; + return_type = m->get_return_type(run_fn); } e->add_module(std::move(m)); if (call_run_fn) { - e->voidfn(run_fn); + if (return_type == "integer4") { + int32_t r = e->int32fn(run_fn); + result.type = EvalResult::integer4; + result.i32 = r; + } else if (return_type == "integer8") { + int64_t r = e->int64fn(run_fn); + result.type = EvalResult::integer8; + result.i64 = r; + } else if (return_type == "real4") { + float r = e->floatfn(run_fn); + result.type = EvalResult::real4; + result.f32 = r; + } else if (return_type == "real8") { + double r = e->doublefn(run_fn); + result.type = EvalResult::real8; + result.f64 = r; + } else if (return_type == "complex4") { + std::complex r = e->complex4fn(run_fn); + result.type = EvalResult::complex4; + result.c32.re = r.real(); + result.c32.im = r.imag(); + } else if (return_type == "complex8") { + std::complex r = e->complex8fn(run_fn); + result.type = EvalResult::complex8; + result.c64.re = r.real(); + result.c64.im = r.imag(); + } else if (return_type == "void") { + e->voidfn(run_fn); + result.type = EvalResult::statement; + } else if (return_type == "none") { + result.type = EvalResult::none; + } else { + throw LCompilersException("FortranEvaluator::evaluate(): Return type not supported"); + } } if (call_run_fn) { diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 1538901fe0..4e8a8159a2 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4088,8 +4088,8 @@ class SymbolTableVisitor : public CommonVisitor { // Every module goes into a Module_t SymbolTable *parent_scope = current_scope; + ASR::Module_t* module_sym = nullptr; if (parent_scope->get_scope().find(module_name) == parent_scope->get_scope().end()) { - ASR::Module_t* module_sym = nullptr; current_scope = al.make_new(parent_scope); ASR::asr_t *tmp1 = ASR::make_Module_t(al, x.base.base.loc, /* a_symtab */ current_scope, @@ -4103,7 +4103,6 @@ class SymbolTableVisitor : public CommonVisitor { for (size_t i=0; im_dependencies = current_module_dependencies.p; module_sym->n_dependencies = current_module_dependencies.size(); @@ -4111,13 +4110,22 @@ class SymbolTableVisitor : public CommonVisitor { create_GenericProcedure(x.base.base.loc); } } else { - ASR::Module_t* module_sym = - ASR::down_cast(parent_scope->resolve_symbol(module_name)); + module_sym = ASR::down_cast(parent_scope->resolve_symbol(module_name)); LCOMPILERS_ASSERT(module_sym != nullptr); current_scope = module_sym->m_symtab; for (size_t i=0; in_dependencies; i++) { + if (module_sym->m_dependencies[i]) { + current_module_dependencies.push_back(al, module_sym->m_dependencies[i]); + } + } + module_sym->m_dependencies = current_module_dependencies.p; + module_sym->n_dependencies = current_module_dependencies.size(); + if (!overload_defs.empty()) { + create_GenericProcedure(x.base.base.loc); + } } global_scope = nullptr; @@ -6691,8 +6699,7 @@ class BodyVisitor : public CommonVisitor { // If tmp is a statement and not an expression // never cast into expression using ASRUtils::EXPR // Just ignore and exit the function naturally. - if( tmp && !ASR::is_a(*tmp) ) { - LCOMPILERS_ASSERT(ASR::is_a(*tmp)); + if( tmp && !ASR::is_a(*tmp) ) { tmp = nullptr; } }