Skip to content

Commit

Permalink
Fix ASR verify pass error while using Interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipul-Cariappa committed May 25, 2024
1 parent 0de9355 commit 842d96c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libasr/asr_scopes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <libasr/asr_scopes.h>
#include <libasr/asr_utils.h>
#include <libasr/pass/pass_utils.h>

std::string lcompilers_unique_ID;

Expand Down Expand Up @@ -39,14 +40,13 @@ void SymbolTable::mark_all_variables_external(Allocator &al) {
case (ASR::symbolType::Function) : {
ASR::Function_t *v = ASR::down_cast<ASR::Function_t>(a.second);
ASR::FunctionType_t* v_func_type = ASR::down_cast<ASR::FunctionType_t>(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) : {
Expand Down
5 changes: 5 additions & 0 deletions src/libasr/asr_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
}

void visit_Function(const Function_t &x) {
ASR::FunctionType_t* x_func_type = ASR::down_cast<ASR::FunctionType_t>(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<std::string> function_dependencies_copy = function_dependencies;
function_dependencies.clear();
function_dependencies.reserve(x.n_dependencies);
Expand Down
17 changes: 17 additions & 0 deletions src/lpython/tests/test_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,20 @@ TEST_CASE("PythonCompiler 1") {
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
}

TEST_CASE("PythonCompiler 2") {
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<PythonCompiler::EvalResult>
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
}

0 comments on commit 842d96c

Please sign in to comment.