12 auto new_lam = rewrite_lam(lam);
14 DLOG(
"new lam: {} : {}", new_lam, new_lam->type());
17 DLOG(
"new app: {} : {}", new_app, new_app->type());
22 return Rewriter::rewrite_imm_App(app);
27const Def* DS2CPS::rewrite_lam(
Lam* lam) {
28 if (
auto i = rewritten_.find(lam); i != rewritten_.end())
return i->second;
30 auto pi = lam->
type();
32 auto codom = pi->codom();
36 if (codom->isa<
Pi>())
return rewrite(lam);
38 DLOG(
"rewrite DS function {} : {}", lam, lam->
type());
41 auto rw_codom = codom;
44 if (
auto var = pi->has_var()) {
46 map(var, sigma->var(2, 0));
54 DLOG(
"original codom: {}", codom);
55 DLOG(
"rewritten codom: {}", rw_codom);
59 auto [filter, cps_body] = lam->
reduce<2>(cps_lam->var(2, 0));
64 DLOG(
"cps body: {} : {}", cps_body, cps_body->type());
66 cps_lam->app(filter, cps_lam->vars().back(), cps_body);
69 DLOG(
"replace {} : {}", lam, lam->
type());
70 DLOG(
"with {} : {}", rewritten_[lam], rewritten_[lam]->type());
72 return rewritten_[lam];
const Def * callee() const
T * isa_mut() const
If this is mutable, it will cast constness away and perform a dynamic_cast to T.
const Def * debug_suffix(std::string) const
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
static const Lam * isa_cn(const Def *d)
Lam * set(Filter filter, const Def *body)
A dependent function type.
World & new_world()
Create new Defs into this.
virtual const Def * map(const Def *old_def, const Def *new_def)
virtual const Def * rewrite(const Def *)
Sigma * set(size_t i, const Def *def)
const Def * app(const Def *callee, const Def *arg)
Lam * mut_con(const Def *dom)
Sigma * mut_sigma(const Def *type, size_t size)
const Def * rewrite_imm_App(const App *) override
#define DLOG(...)
Vaporizes to nothingness in Debug build.
const Def * op_cps2ds_dep(const Def *k)