Skip to content

Commit

Permalink
expose the closure conversion API (mk_expr) to address #69
Browse files Browse the repository at this point in the history
  • Loading branch information
thautwarm committed Feb 12, 2022
1 parent 6ebfe69 commit d882d12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/GeneralizedGenerated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down

0 comments on commit d882d12

Please sign in to comment.