MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
axiom.cpp
Go to the documentation of this file.
1#include "mim/axiom.h"
2
3#include "mim/world.h"
4
5namespace mim {
6
7Axiom::Axiom(NormalizeFn normalizer, u8 curry, u8 trip, const Def* type, plugin_t plugin, tag_t tag, sub_t sub)
8 : Def(Node, type, Defs{}, plugin | (flags_t(tag) << 8_u64) | flags_t(sub)) {
9 normalizer_ = normalizer;
10 curry_ = curry;
11 trip_ = trip;
12}
13
14std::pair<u8, u8> Axiom::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
38std::tuple<const Axiom*, u8, u8> Axiom::get(const Def* def) {
39 if (auto axiom = def->isa<Axiom>()) return {axiom, axiom->curry(), axiom->trip()};
40 if (auto app = def->isa<App>()) return {app->axiom(), app->curry(), app->trip()};
41 return {nullptr, 0, 0};
42}
43
44} // namespace mim
Base class for all Defs.
Definition def.h:223
A dependent function type.
Definition lam.h:11
Definition cfg.h:11
View< const Def * > Defs
Definition def.h:61
u8 sub_t
Definition types.h:48
u64 flags_t
Definition types.h:45
GIDSet< Def * > MutSet
Definition def.h:69
u64 plugin_t
Definition types.h:46
u8 tag_t
Definition types.h:47
uint8_t u8
Definition types.h:34
Ref(*)(Ref, Ref, Ref) NormalizeFn
Definition def.h:102