MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
ret_wrap.cpp
Go to the documentation of this file.
1#include "mim/pass/ret_wrap.h"
2
3namespace mim {
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 mim
auto vars(F f)
Definition def.h:398
Def * reset(size_t i, const Def *def)
Successively reset from left to right.
Definition def.h:288
Lam * set(Filter filter, const Def *body)
Definition lam.h:158
Lam * app(Filter filter, const Def *callee, const Def *arg)
Set body to an App of callee and arg.
Definition lam.cpp:29
Ref ret_var()
Yields the Lam::var of the Lam::ret_pi.
Definition lam.h:146
World & world()
Definition pass.h:296
A dependent function type.
Definition lam.h:11
Lam * curr_mut() const
Definition pass.h:232
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:239
Lam * mut_lam(const Pi *pi)
Definition world.h:284
Definition cfg.h:11