Skip to content

expose _get_body #70

@thautwarm

Description

@thautwarm

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

 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.

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions