MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
axm.cpp
Go to the documentation of this file.
1
#include "
mim/axm.h
"
2
3
#include "
mim/world.h
"
4
5
namespace
mim
{
6
7
Axm::Axm(
NormalizeFn
normalizer,
u8
curry,
u8
trip,
const
Def
* type,
plugin_t
plugin,
tag_t
tag,
sub_t
sub)
8
:
Def
(
Node
,
type
,
Defs
{},
Annex
::flags(plugin, tag,
sub
)) {
9
normalizer_ = normalizer;
10
curry_ = curry;
11
trip_ = trip;
12
}
13
14
std::pair<u8, u8>
Axm::infer_curry_and_trip
(
const
Def*
type
) {
15
u8
curry
= 0;
16
u8
trip
= 0;
17
MutSet
done;
18
while
(
auto
pi =
type
->isa<
Pi
>()) {
19
if
(
auto
mut = pi->isa_mut()) {
20
if
(
auto
[_, ins] = done.emplace(mut); !ins) {
21
// infer trip
22
auto
curr = pi;
23
do
{
24
++
trip
;
25
curr = curr->codom()->as<
Pi
>();
26
}
while
(curr != mut);
27
break
;
28
}
29
}
30
31
++
curry
;
32
type
= pi->codom();
33
}
34
35
return
{
curry
,
trip
};
36
}
37
38
std::tuple<const Axm*, u8, u8>
Axm::get
(
const
Def* def) {
39
if
(
auto
axm = def->isa<Axm>())
return
{axm, axm->curry(), axm->trip()};
40
if
(
auto
app = def->isa<
App
>())
return
{app->axm(), app->curry(), app->trip()};
41
return
{
nullptr
, 0, 0};
42
}
43
44
std::tuple<const Axm*, u8, u8>
Axm::next
(
const
Def* callee) {
45
auto
[axm,
curry
,
trip
] =
get
(callee);
46
if
(axm) {
47
curry
=
curry
== 0 ?
trip
:
curry
;
// counter exhausted - start the next trip
48
curry
=
curry
==
Trip_End
?
curry
:
curry
- 1;
// Trip_End sticks
49
}
50
return
{axm,
curry
,
trip
};
51
}
52
53
}
// namespace mim
axm.h
mim::App
Definition
lam.h:224
mim::Axm::trip
u8 trip() const
Definition
axm.h:38
mim::Axm::next
static std::tuple< const Axm *, u8, u8 > next(const Def *callee)
Like Axm::get, but advances the counter as one more App is about to be built on top of callee.
Definition
axm.cpp:44
mim::Axm::infer_curry_and_trip
static std::pair< u8, u8 > infer_curry_and_trip(const Def *type)
Definition
axm.cpp:14
mim::Axm::Trip_End
static constexpr u8 Trip_End
Definition
axm.h:148
mim::Axm::curry
u8 curry() const
Definition
axm.h:37
mim::Axm::get
static std::tuple< const Axm *, u8, u8 > get(const Def *def)
Yields currying counter of def.
Definition
axm.cpp:38
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1111
mim::Pi
A dependent function type.
Definition
lam.h:14
mim::plug::affine::op::sub
@ sub
Definition
autogen.h:48
mim::plug::refly::type
type
Definition
autogen.h:37
mim
Definition
ast.h:16
mim::sub_t
u8 sub_t
Definition
types.h:42
mim::Defs
fe::View< const Def * > Defs
Definition
def.h:91
mim::MutSet
GIDSet< Def * > MutSet
Definition
def.h:101
mim::NormalizeFn
const Def *(*)(const Def *, const Def *, const Def *) NormalizeFn
Definition
def.h:115
mim::plugin_t
u64 plugin_t
Definition
types.h:40
mim::tag_t
u8 tag_t
Definition
types.h:41
mim::u8
uint8_t u8
Definition
types.h:27
mim::Node
Node
Definition
def.h:120
mim::Annex
Holds info about an entity defined within a Plugin (called Annex).
Definition
plugin.h:182
world.h
src
mim
axm.cpp
Generated by
1.18.0