Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
ret_wrap.cpp
Go to the documentation of this file.
2
3namespace thorin {
4
6 auto ret_var = curr_mut()->ret_var();
7 if (!ret_var) return;
8
9 // new wrapper that calls the return continuation
10 auto ret_cont = world().mut_lam(ret_var->type()->as<Pi>())->set(ret_var->dbg());
11 ret_cont->app(false, ret_var, ret_cont->var())->set(ret_var->dbg());
12
13 // rebuild a new "var" that substitutes the actual ret_var with ret_cont
14 auto new_vars = curr_mut()->vars();
15 assert(new_vars.back() == ret_var && "we assume that the last element is the ret_var");
16 new_vars.back() = ret_cont;
17 auto new_var = world().tuple(curr_mut()->dom(), new_vars);
18 curr_mut()->reset(curr_mut()->reduce(new_var));
19}
20
21} // namespace thorin
Def * reset(size_t i, const Def *def)
Successively reset from left to right.
Definition def.h:291
auto vars(F f)
Definition def.h:403
Ref ret_var()
Yields the Lam::var of the Lam::ret_pi.
Definition lam.h:147
Lam * app(Filter filter, const Def *callee, const Def *arg)
Set body to an App of callee and arg.
Definition lam.cpp:29
Lam * set(Filter filter, const Def *body)
Definition lam.h:159
World & world()
Definition pass.h:296
A dependent function type.
Definition lam.h:11
void enter() override
Invoked just before Pass::rewriteing PassMan::curr_mut's body.
Definition ret_wrap.cpp:5
Ref tuple(Defs ops)
Definition world.cpp:226
Lam * mut_lam(const Pi *pi)
Definition world.h:263
Definition cfg.h:11