Skip to content

Commit e55da7f

Browse files
committed
eval() without jl_begin_new_module for julia 1.11
It turns out it's possible to implement eval against an iterative lowering API even without the ability to begin and end a module - we just need to generate the right call expression within the module to recursively call the eval implementation.
1 parent 3b73976 commit e55da7f

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/eval.jl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,14 @@ end
439439
@fzone "JL: eval" function eval(mod::Module, ex::SyntaxTree;
440440
macro_world::UInt=Base.get_world_counter(),
441441
opts...)
442-
modules = Module[]
443442
iter = lower_init(ex, mod, macro_world; opts...)
443+
_eval(mod, iter)
444+
end
445+
446+
if VERSION >= v"1.13.0-DEV.1199" # https://github.com/JuliaLang/julia/pull/59604
447+
448+
function _eval(mod, iter)
449+
modules = Module[]
444450
new_mod = nothing
445451
result = nothing
446452
while true
@@ -467,6 +473,37 @@ end
467473
return result
468474
end
469475

476+
else
477+
478+
function _eval(mod, iter, new_mod=nothing)
479+
in_new_mod = !isnothing(new_mod)
480+
result = nothing
481+
while true
482+
thunk = lower_step(iter, new_mod)::Core.SimpleVector
483+
new_mod = nothing
484+
type = thunk[1]::Symbol
485+
if type == :done
486+
@assert !in_new_mod
487+
break
488+
elseif type == :begin_module
489+
name = thunk[2]::Symbol
490+
std_defs = thunk[3]
491+
result = Core.eval(mod,
492+
Expr(:module, std_defs, name,
493+
Expr(:block, thunk[4], Expr(:call, m->_eval(m, iter, m), name)))
494+
)
495+
elseif type == :end_module
496+
@assert in_new_mod
497+
return mod
498+
else
499+
@assert type == :thunk
500+
result = Core.eval(mod, thunk[2])
501+
end
502+
end
503+
return result
504+
end
505+
506+
end
470507

471508
"""
472509
include(mod::Module, path::AbstractString)

0 commit comments

Comments
 (0)