MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
family.h
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// Families of Tok::Tag as reusable `case` labels; include this in `*.cpp` files only.
5/// A family expands to `first: case Tag::second: ...` and hence must be used as `case Tag::C_FAMILY:`.
6/// Families compose: a family may name another one.
7/// The including file must provide `using Tag = Tok::Tag;`.
8
9// clang-format off
10#define C_PRIMARY \
11 K_Level: \
12 case Tag::K_Nat: \
13 case Tag::K_Idx: \
14 case Tag::K_Bool: \
15 case Tag::K_ff: \
16 case Tag::K_tt: \
17 case Tag::K_i1: \
18 case Tag::K_i8: \
19 case Tag::K_i16: \
20 case Tag::K_i32: \
21 case Tag::K_i64: \
22 case Tag::K_I1: \
23 case Tag::K_I8: \
24 case Tag::K_I16: \
25 case Tag::K_I32: \
26 case Tag::K_I64: \
27 case Tag::T_star: \
28 case Tag::T_box
29
30#define C_ID M_id
31
32#define C_LIT \
33 T_bot: \
34 case Tag::T_top: \
35 case Tag::L_str: \
36 case Tag::L_c: \
37 case Tag::L_s: \
38 case Tag::L_u: \
39 case Tag::L_f: \
40 case Tag::L_i
41
42/// Numeric literals that a leading sign may be applied to.
43#define C_LIT_NUM \
44 L_s: \
45 case Tag::L_u: \
46 case Tag::L_f: \
47 case Tag::L_i
48
49/// Leading sign of a numeric literal.
50#define C_SIGN \
51 T_add: \
52 case Tag::T_sub
53
54/// Literals that already determine their type and hence must not be ascribed one.
55#define C_LIT_TYPED \
56 L_str: \
57 case Tag::L_c: \
58 case Tag::L_i
59
60#define C_LAM \
61 K_lam: \
62 case Tag::K_con: \
63 case Tag::K_fun
64
65#define C_RULE \
66 K_norm: \
67 case Tag::K_rule
68
69#define C_IMPORT \
70 K_import: \
71 case Tag::K_plugin
72
73#define C_DECL \
74 K_axm: \
75 case Tag::K_let: \
76 case Tag::K_mod: \
77 case Tag::K_mutual: \
78 case Tag::K_nom: \
79 case Tag::K_rec: \
80 case Tag::K_use: \
81 case Tag::C_IMPORT: \
82 case Tag::C_RULE: \
83 case Tag::C_LAM
84
85/// Direct-style binders; all other binders are CPS.
86#define C_DS \
87 T_lm: \
88 case Tag::K_lam
89
90/// Binders whose domain binds as tight as a `Cn`, i.e. no codomain follows.
91#define C_CN \
92 K_Cn: \
93 case Tag::K_cn: \
94 case Tag::K_con
95
96/// Binders that receive an implicit `ret` continuation.
97#define C_FN \
98 K_Fn: \
99 case Tag::K_fn: \
100 case Tag::K_fun
101
102#define C_SEQ \
103 D_angle_l: \
104 case Tag::D_quote_l
105
106#define C_PI \
107 D_brace_l: \
108 case Tag::K_Cn: \
109 case Tag::K_Fn
110
111#define C_LM \
112 T_lm: \
113 case Tag::K_cn: \
114 case Tag::K_fn
115
116#define C_EXPR \
117 C_PRIMARY: \
118 case Tag::C_ID: \
119 case Tag::C_LIT: \
120 case Tag::C_DECL: \
121 case Tag::C_PI: \
122 case Tag::C_LM: \
123 case Tag::K_Type: /*TypeExpr*/ \
124 case Tag::K_Rule: /*RuleExpr*/ \
125 case Tag::K_match: /*MatchExpr*/ \
126 case Tag::K_ret: /*RetExpr*/ \
127 case Tag::C_SEQ: /*SeqExpr, SingleExpr*/ \
128 case Tag::D_brckt_l: /*SigmaExpr*/ \
129 case Tag::D_paren_l /*TupleExpr*/
130
131#define C_CURRIED_P \
132 D_brace_l: \
133 case Tag::D_brckt_l: \
134 case Tag::D_paren_l
135// clang-format on
136
137/// Turns such a family into a predicate - a `case` label is of no use outside of a `switch`.
138#define ISA(tag, family) \
139 ([&] { \
140 switch (tag) { \
141 case Tok::Tag::family: return true; \
142 default: return false; \
143 } \
144 }())