From b494953fc2e25d8e293523fede0221fe2c9d0fab Mon Sep 17 00:00:00 2001 From: songjhaha Date: Fri, 20 Oct 2023 10:51:21 +0800 Subject: [PATCH] use Meta.parseall in JLEval --- src/core.jl | 2 +- src/run.jl | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core.jl b/src/core.jl index 5b81d15..d7deab7 100644 --- a/src/core.jl +++ b/src/core.jl @@ -71,7 +71,7 @@ end function JLEval(out::Ptr{JV}, module′::JV, code::TyList{UInt8})::ErrorCode try M = module′.ID == 0 ? Main : JV_LOAD(module′)::Module - v = Base.eval(M, Meta.parse(unsafe_string(code))) + v = Base.eval(M, Meta.parseall(unsafe_string(code))) unsafe_store!(out, JV_ALLOC(v)) return OK catch e diff --git a/src/run.jl b/src/run.jl index 50fbb52..7309732 100644 --- a/src/run.jl +++ b/src/run.jl @@ -46,6 +46,22 @@ @test JSym_LOAD(refSym[1]) == :ErrorException @test String(errMsgVec) == "syntax: incomplete: premature end of input" end + + s = """ + if true + 123 + else + 234 + end + 345 + """ + x = TyList(s) + out = [JV()] + GC.@preserve s begin + @test JLEval(pointer(out), JV(), x) == OK + @test JV_LOAD(out[1]) == 345 + JV_DEALLOC(out[1]) + end end @testset "JLCall" begin