diff --git a/README.md b/README.md index 92f4f86..de0eaf7 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,11 @@ julia> g(1) 2 ``` +julia> @generated function g() + Module = Main + mk_expr(Module, :( (x -> x)(1))) +end + ## No `eval`/`invokelatest`! ```julia diff --git a/src/GeneralizedGenerated.jl b/src/GeneralizedGenerated.jl index 484e5b6..b638d53 100644 --- a/src/GeneralizedGenerated.jl +++ b/src/GeneralizedGenerated.jl @@ -6,7 +6,7 @@ List = LinkedList export NGG export gg, @gg, UnderGlobal, @under_global -export RuntimeFn, closure_conv, mk_function, mkngg +export RuntimeFn, closure_conv, mk_function, mkngg, mk_expr export to_type, from_type, runtime_eval include("closure_conv.jl") @@ -26,6 +26,17 @@ function mk_function(mod::Module, ex) fn end +""" +process an expression and perform closure conversions for all nested expressions. +""" +function mk_expr(mod::Module, ex) + ex = macroexpand(mod, ex) + ex = simplify_ex(ex) + ex = solve!(ex) + closure_conv(mod, ex) +end + + function mk_function(mod::Module, args, kwargs, body) mk_function(mod, Expr(:function, :($(args...), ; $(kwargs...)), body)) end