MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
nom.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mim/def.h
"
4
5
namespace
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.
11
class
Nom :
public
Def,
public
Setters
<Nom> {
12
private
:
13
Nom(
const
Def*
type
,
const
Def*
op
,
flags_t
key
)
14
: Def(
Node
,
type
, {
op
},
key
) {}
15
16
public
:
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
29
private
:
30
friend
class
World
;
31
};
32
33
/// Nominal newtype term introduction.
34
class
Name :
public
Def,
public
Setters
<Name> {
35
private
:
36
Name(
const
Def*
type
,
const
Def* value)
37
: Def(
Node
,
type
, {value}, 0) {}
38
39
public
:
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
51
private
:
52
friend
class
World
;
53
};
54
55
/// Nominal newtype term elimination.
56
class
Struc :
public
Def,
public
Setters
<Struc> {
57
private
:
58
Struc(
const
Def*
type
,
const
Def* value)
59
: Def(
Node
,
type
, {value}, 0) {}
60
61
public
:
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
72
private
:
73
friend
class
World
;
74
};
75
76
}
// namespace mim
mim::Def::set
Def * set(size_t i, const Def *)
Successively set from left to right.
Definition
def.cpp:188
mim::Def::flags
constexpr flags_t flags() const noexcept
Definition
def.h:311
mim::Def::op
const Def * op(size_t i) const noexcept
Definition
def.h:377
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1119
mim::Name::nom
const Nom * nom() const
Definition
nom.h:45
mim::Name::World
friend class World
Definition
nom.h:52
mim::Name::Num_Ops
static constexpr size_t Num_Ops
Definition
nom.h:49
mim::Name::op
const Def * op() const
Definition
nom.h:44
mim::Name::Node
static constexpr auto Node
Definition
nom.h:48
mim::Nom
Nominal newtype formation.
Definition
nom.h:11
mim::Nom::key
flags_t key() const
What tells this Nom apart from one over the same Nom::op.
Definition
nom.h:24
mim::Nom::Node
static constexpr auto Node
Definition
nom.h:26
mim::Nom::World
friend class World
Definition
nom.h:30
mim::Nom::op
const Def * op() const
The wrapped type.
Definition
nom.h:21
mim::Nom::Num_Ops
static constexpr size_t Num_Ops
Definition
nom.h:27
mim::Setters
CRTP-based mixin to declare setters for Def::loc & Def::name using a covariant return type.
Definition
def.h:220
mim::Struc::op
const Def * op() const
Definition
nom.h:66
mim::Struc::World
friend class World
Definition
nom.h:73
mim::Struc::Node
static constexpr auto Node
Definition
nom.h:69
mim::Struc::Num_Ops
static constexpr size_t Num_Ops
Definition
nom.h:70
def.h
mim
Definition
ast.h:16
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::Node::Struc
@ Struc
Definition
def.h:125
mim::Node::Name
@ Name
Definition
def.h:125
mim::Node::Nom
@ Nom
Definition
def.h:125
include
mim
nom.h
Generated by
1.18.0