MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
cps.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/rewrite.h>
4#include <mim/world.h>
5
7
8namespace mim::plug::cps {
9
10/// @name cps.cps2ds_dep
11/// ```
12/// let k: Cn [t: T, Cn U t] = ...;
13/// let f: [t: T] → U = cps.cps2ds_dep (lm (t': T): * = [t → t']U) k;
14/// ```
15///@{
16inline const Def* op_cps2ds_dep(const Def* k) {
17 auto& w = k->world();
18 auto K = Pi::isa_cn(k->type());
19 auto [T, R] = K->doms<2>();
20 auto U = Pi::isa_cn(R)->dom();
21 auto l = w.mut_lam(T, w.type())->set("Uf");
22 auto body = U;
23
24 // U only refers to `var#0`; the second component is a placeholder that is never projected.
25 if (auto [dom, var] = K->dom()->isa_binder<Sigma>(); dom)
26 body = VarRewriter(var, w.tuple({l->var(), w.tuple()})).rewrite(U);
27 l->set(true, body);
28
29 return w.app(w.app(w.app(w.annex<cps::cps2ds_dep>(), T), l), k);
30}
31///@}
32
33} // namespace mim::plug::cps
Base class for all Defs.
Definition def.h:289
World & world() const noexcept
Definition def.h:1105
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.h:1119
static const Pi * isa_cn(const Def *d)
Definition lam.h:50
const Def * dom() const
Definition lam.h:38
A dependent tuple type.
Definition tuple.h:39
VarRewriter(World &world)
Definition rewrite.h:146
The CPS Plugin
Definition cps.h:8
const Def * op_cps2ds_dep(const Def *k)
Definition cps.h:16