JuliaStaging / JuliaStaging/GeneralizedGenerated.jl

expose `_get_body`

Open
#70 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
89
Forks
12
PR merge metrics
No merged PRs in 30d

Description

`_get_body` extracts the type encoding of the body of GG functions.

```julia
julia> fun = mk_function(Main, :(function (x) x + 1 end))
function = (x;) -> begin
begin
(Main).:+(x, 1)
end
end

julia> from_type(GeneralizedGenerated._get_body(fun))

quote
begin
#= REPL[27]:1 =#
#= REPL[27]:1 =#
(Main).:+(x, 1)
end
end
```

This is very useful to control scopes.

For instance, if we want to specify bind values to local variables in the generated body, we can firstly create a dummy function and specify arguments which will be bound to our values.

```julia
@gg function f(M::Module, a, b)

c = 1
fun = mk_function(M, :(function (a, b, c)
...
end))

body = from_type(_get_body(fun))

quote
let c = $c
$body
end
end
end
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.