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 = K->dom(2, 0);
20 auto U = Pi::isa_cn(K->dom(2, 1))->dom();
21 auto l = w.mut_lam(T, w.type())->set("Uf");
22 auto body = U;
23
24 if (auto [dom, var] = K->dom()->isa_binder<Sigma>(); dom)
25 body = VarRewriter(var, l->var()).rewrite(U); // TODO typeof(dom->var()) != typeof(l->var())
26 l->set(true, body);
27
28 return w.app(w.app(w.app(w.annex<cps::cps2ds_dep>(), T), l), k);
29}
30///@}
31
32} // namespace mim::plug::cps
Base class for all Defs.
Definition def.h:273
World & world() const noexcept
Definition def.h:1097
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.h:1111
static const Pi * isa_cn(const Def *d)
Definition lam.h:46
const Def * dom() const
Definition lam.h:35
A dependent tuple type.
Definition tuple.h:23
VarRewriter(World &world)
Definition rewrite.h:118
The CPS Plugin
Definition cps.h:8
const Def * op_cps2ds_dep(const Def *k)
Definition cps.h:16