MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
nom.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/def.h"
4
5namespace mim {
6
7/// Nominal newtype formation.
8/// Two Nom%s are only equal if their Nom::key%s are, so two Nom%s over the same Nom::op may still be distinct types.
9/// It is up to the frontend to hand out a fresh Nom::key per declaration; Def::sym is mere debug info.
10/// A recursive Nom refers to itself through a mutable Nom::op.
11class Nom : public Def, public Setters<Nom> {
12private:
13 Nom(const Def* type, const Def* op, flags_t key)
14 : Def(Node, type, {op}, key) {}
15
16public:
17 using Setters<Nom>::set;
18
19 /// @name ops
20 ///@{
21 const Def* op() const { return Def::op(0); } ///< The wrapped type.
22 ///@}
23
24 flags_t key() const { return flags(); } ///< What tells this Nom apart from one over the same Nom::op.
25
26 static constexpr auto Node = mim::Node::Nom;
27 static constexpr size_t Num_Ops = 1;
28
29private:
30 friend class World;
31};
32
33/// Nominal newtype term introduction.
34class Name : public Def, public Setters<Name> {
35private:
36 Name(const Def* type, const Def* value)
37 : Def(Node, type, {value}, 0) {}
38
39public:
40 using Setters<Name>::set;
41
42 /// @name ops
43 ///@{
44 const Def* op() const { return Def::op(0); }
45 const Nom* nom() const { return type()->as<Nom>(); }
46 ///@}
47
48 static constexpr auto Node = mim::Node::Name;
49 static constexpr size_t Num_Ops = 1;
50
51private:
52 friend class World;
53};
54
55/// Nominal newtype term elimination.
56class Struc : public Def, public Setters<Struc> {
57private:
58 Struc(const Def* type, const Def* value)
59 : Def(Node, type, {value}, 0) {}
60
61public:
62 using Setters<Struc>::set;
63
64 /// @name ops
65 ///@{
66 const Def* op() const { return Def::op(0); }
67 ///@}
68
69 static constexpr auto Node = mim::Node::Struc;
70 static constexpr size_t Num_Ops = 1;
71
72private:
73 friend class World;
74};
75
76} // namespace mim
Def * set(size_t i, const Def *)
Successively set from left to right.
Definition def.cpp:188
constexpr flags_t flags() const noexcept
Definition def.h:311
const Def * op(size_t i) const noexcept
Definition def.h:377
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.h:1119
const Nom * nom() const
Definition nom.h:45
friend class World
Definition nom.h:52
static constexpr size_t Num_Ops
Definition nom.h:49
const Def * op() const
Definition nom.h:44
static constexpr auto Node
Definition nom.h:48
Nominal newtype formation.
Definition nom.h:11
flags_t key() const
What tells this Nom apart from one over the same Nom::op.
Definition nom.h:24
static constexpr auto Node
Definition nom.h:26
friend class World
Definition nom.h:30
const Def * op() const
The wrapped type.
Definition nom.h:21
static constexpr size_t Num_Ops
Definition nom.h:27
CRTP-based mixin to declare setters for Def::loc & Def::name using a covariant return type.
Definition def.h:220
const Def * op() const
Definition nom.h:66
friend class World
Definition nom.h:73
static constexpr auto Node
Definition nom.h:69
static constexpr size_t Num_Ops
Definition nom.h:70
Definition ast.h:16
u64 flags_t
Definition types.h:39
@ Struc
Definition def.h:125
@ Name
Definition def.h:125
@ Nom
Definition def.h:125