Skip to content

Commit 13bb54e

Browse files
authored
Merge pull request #2713 from Vipul-Cariappa/test
Initial test for Interactive
2 parents a7121a4 + d4e7def commit 13bb54e

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,4 @@ integration_tests/expr_12
236236
integration_tests/expr_12.c
237237

238238
# Interactive Shell
239-
/input
239+
input

src/lpython/python_evaluator.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ PythonCompiler::PythonCompiler(CompilerOptions compiler_options)
4141

4242
PythonCompiler::~PythonCompiler() = default;
4343

44+
Result<PythonCompiler::EvalResult> PythonCompiler::evaluate2(const std::string &code) {
45+
LocationManager lm;
46+
LCompilers::PassManager lpm;
47+
lpm.use_default_passes();
48+
{
49+
LCompilers::LocationManager::FileLocations fl;
50+
fl.in_filename = "input";
51+
std::ofstream out("input");
52+
out << code;
53+
lm.files.push_back(fl);
54+
lm.init_simple(code);
55+
lm.file_ends.push_back(code.size());
56+
}
57+
diag::Diagnostics diagnostics;
58+
return evaluate(code, false, lm, lpm, diagnostics);
59+
}
4460

4561
Result<PythonCompiler::EvalResult> PythonCompiler::evaluate(
4662
#ifdef HAVE_LFORTRAN_LLVM

src/lpython/python_evaluator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class PythonCompiler
5555
Result<PythonCompiler::EvalResult> evaluate(
5656
const std::string &code_orig, bool verbose, LocationManager &lm,
5757
LCompilers::PassManager& pass_manager, diag::Diagnostics &diagnostics);
58-
58+
59+
Result<PythonCompiler::EvalResult> evaluate2(const std::string &code);
60+
5961
Result<LCompilers::LPython::AST::ast_t*> get_ast2(
6062
const std::string &code_orig, diag::Diagnostics &diagnostics);
6163

src/lpython/tests/test_llvm.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,17 @@ define float @f()
607607
float r = e.floatfn("f");
608608
CHECK(std::abs(r - 8) < 1e-6);
609609
}
610+
611+
TEST_CASE("PythonCompiler 1") {
612+
CompilerOptions cu;
613+
cu.po.disable_main = true;
614+
cu.emit_debug_line_column = false;
615+
cu.generate_object_code = false;
616+
cu.interactive = true;
617+
cu.po.runtime_library_dir = LCompilers::LPython::get_runtime_library_dir();
618+
PythonCompiler e(cu);
619+
LCompilers::Result<PythonCompiler::EvalResult>
620+
r = e.evaluate2("1");
621+
CHECK(r.ok);
622+
CHECK(r.result.type == PythonCompiler::EvalResult::none); // TODO: change to integer4 and check the value once printing top level expressions is implemented
623+
}

0 commit comments

Comments
 (0)