diff --git a/src/libasr/asr_scopes.cpp b/src/libasr/asr_scopes.cpp index a50e471c60..c999eaec69 100644 --- a/src/libasr/asr_scopes.cpp +++ b/src/libasr/asr_scopes.cpp @@ -3,6 +3,7 @@ #include #include +#include std::string lcompilers_unique_ID; @@ -39,14 +40,13 @@ void SymbolTable::mark_all_variables_external(Allocator &al) { case (ASR::symbolType::Function) : { ASR::Function_t *v = ASR::down_cast(a.second); ASR::FunctionType_t* v_func_type = ASR::down_cast(v->m_function_signature); - if ((v_func_type->m_abi != ASR::abiType::Intrinsic) && - (v_func_type->m_abi != ASR::abiType::Interactive)) { - v->m_dependencies = nullptr; - v->n_dependencies = 0; + if (v_func_type->m_abi != ASR::abiType::Interactive) { + v_func_type->m_abi = ASR::abiType::Interactive; v->m_body = nullptr; v->n_body = 0; + PassUtils::UpdateDependenciesVisitor ud(al); + ud.visit_Function(*v); } - v_func_type->m_abi = ASR::abiType::Interactive; break; } case (ASR::symbolType::Module) : { diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 16b255f8cc..19adc83ae8 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -420,6 +420,11 @@ class VerifyVisitor : public BaseWalkVisitor } void visit_Function(const Function_t &x) { + ASR::FunctionType_t* x_func_type = ASR::down_cast(x.m_function_signature); + if (x_func_type->m_abi == abiType::Interactive) { + require(x.n_body == 0, + "The Function::n_body should be 0 if abi set to Interactive"); + } std::vector function_dependencies_copy = function_dependencies; function_dependencies.clear(); function_dependencies.reserve(x.n_dependencies); diff --git a/src/lpython/python_evaluator.cpp b/src/lpython/python_evaluator.cpp index 67f2b4df69..9db6d0ec7b 100644 --- a/src/lpython/python_evaluator.cpp +++ b/src/lpython/python_evaluator.cpp @@ -41,6 +41,22 @@ PythonCompiler::PythonCompiler(CompilerOptions compiler_options) PythonCompiler::~PythonCompiler() = default; +Result PythonCompiler::evaluate2(const std::string &code) { + LocationManager lm; + LCompilers::PassManager lpm; + lpm.use_default_passes(); + { + LCompilers::LocationManager::FileLocations fl; + fl.in_filename = "input"; + std::ofstream out("input"); + out << code; + lm.files.push_back(fl); + lm.init_simple(code); + lm.file_ends.push_back(code.size()); + } + diag::Diagnostics diagnostics; + return evaluate(code, false, lm, lpm, diagnostics); +} Result PythonCompiler::evaluate( #ifdef HAVE_LFORTRAN_LLVM diff --git a/src/lpython/python_evaluator.h b/src/lpython/python_evaluator.h index 9cba5267ed..fe4ce5b4ac 100644 --- a/src/lpython/python_evaluator.h +++ b/src/lpython/python_evaluator.h @@ -56,6 +56,8 @@ class PythonCompiler const std::string &code_orig, bool verbose, LocationManager &lm, LCompilers::PassManager& pass_manager, diag::Diagnostics &diagnostics); + Result evaluate2(const std::string &code); + Result get_ast2( const std::string &code_orig, diag::Diagnostics &diagnostics); diff --git a/src/lpython/tests/test_llvm.cpp b/src/lpython/tests/test_llvm.cpp index a660dd7509..5a07bc6ce9 100644 --- a/src/lpython/tests/test_llvm.cpp +++ b/src/lpython/tests/test_llvm.cpp @@ -607,3 +607,20 @@ define float @f() float r = e.floatfn("f"); CHECK(std::abs(r - 8) < 1e-6); } + +TEST_CASE("FortranEvaluator 1") { + CompilerOptions cu; + cu.po.disable_main = true; + cu.emit_debug_line_column = false; + cu.generate_object_code = false; + cu.interactive = true; + cu.po.runtime_library_dir = LCompilers::LPython::get_runtime_library_dir(); + PythonCompiler e(cu); + LCompilers::Result + r = e.evaluate2("i: i32 = 3 % 1"); + CHECK(r.ok); + CHECK(r.result.type == PythonCompiler::EvalResult::none); + r = e.evaluate2("i"); + CHECK(r.ok); + CHECK(r.result.type == PythonCompiler::EvalResult::none); // TODO: change to integer4 and check the value once printing top level expressions is implemented +}