1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
use crate::opcode;
use crate::{Var, Var_};
use core::ops::Range;
pub trait Sort {
fn is_pure(&self) -> bool;
fn is_strict(&self) -> bool;
fn is_provable(&self) -> bool;
fn is_free(&self) -> bool;
}
pub trait Term {
type Type: Var;
fn sort_idx(&self) -> u8;
fn is_definition(&self) -> bool;
fn binders(&self) -> Range<usize>;
fn return_type(&self) -> &Self::Type;
fn command_stream(&self) -> Range<usize>;
}
pub trait Theorem {
fn binders(&self) -> Range<usize>;
fn unify_commands(&self) -> Range<usize>;
}
pub trait Table {
type Sort: Sort;
type Term: Term<Type = Self::Var>;
type Theorem: Theorem;
type Var: Var;
fn sort(&self, idx: u8) -> Option<&Self::Sort>;
fn nr_sorts(&self) -> u8;
fn term(&self, idx: u32) -> Option<&Self::Term>;
fn nr_terms(&self) -> u32;
fn theorem(&self, idx: u32) -> Option<&Self::Theorem>;
fn nr_theorems(&self) -> u32;
fn unify_commands(&self, idx: Range<usize>) -> Option<&[opcode::Command<opcode::Unify>]>;
fn unify_command(&self, idx: usize) -> Option<&opcode::Command<opcode::Unify>>;
fn binders(&self, idx: Range<usize>) -> Option<&[Self::Var]>;
}
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Sort_(pub u8);
impl From<u8> for Sort_ {
fn from(value: u8) -> Sort_ {
Sort_(value)
}
}
impl Sort for Sort_ {
#[inline(always)]
fn is_pure(&self) -> bool {
(self.0 & 0x01) != 0
}
#[inline(always)]
fn is_strict(&self) -> bool {
(self.0 & 0x02) != 0
}
#[inline(always)]
fn is_provable(&self) -> bool {
(self.0 & 0x04) != 0
}
#[inline(always)]
fn is_free(&self) -> bool {
(self.0 & 0x08) != 0
}
}
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
pub struct Term_ {
pub sort: u8,
pub binders: Range<usize>,
pub ret_type: Var_,
pub unify_commands: Range<usize>,
}
impl Term for Term_ {
type Type = Var_;
fn sort_idx(&self) -> u8 {
self.sort & 0x7F
}
fn is_definition(&self) -> bool {
(self.sort & 0x80) != 0
}
fn binders(&self) -> Range<usize> {
self.binders.clone()
}
fn return_type(&self) -> &Self::Type {
&self.ret_type
}
fn command_stream(&self) -> Range<usize> {
self.unify_commands.clone()
}
}
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
pub struct Theorem_ {
pub binders: Range<usize>,
pub unify_commands: Range<usize>,
}
impl Theorem for Theorem_ {
fn binders(&self) -> Range<usize> {
self.binders.clone()
}
fn unify_commands(&self) -> Range<usize> {
self.unify_commands.clone()
}
}
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
pub struct Table_ {
pub sorts: Vec<Sort_>,
pub theorems: Vec<Theorem_>,
pub terms: Vec<Term_>,
pub unify: Vec<opcode::Command<opcode::Unify>>,
pub binders: Vec<Var_>,
}
impl Table for Table_ {
type Sort = Sort_;
type Term = Term_;
type Theorem = Theorem_;
type Var = Var_;
fn sort(&self, idx: u8) -> Option<&Self::Sort> {
self.sorts.get(idx as usize)
}
fn nr_sorts(&self) -> u8 {
self.sorts.len() as u8
}
fn term(&self, idx: u32) -> Option<&Self::Term> {
self.terms.get(idx as usize)
}
fn nr_terms(&self) -> u32 {
self.terms.len() as u32
}
fn theorem(&self, idx: u32) -> Option<&Self::Theorem> {
self.theorems.get(idx as usize)
}
fn nr_theorems(&self) -> u32 {
self.theorems.len() as u32
}
fn unify_commands(&self, idx: Range<usize>) -> Option<&[opcode::Command<opcode::Unify>]> {
self.unify.get(idx)
}
fn unify_command(&self, idx: usize) -> Option<&opcode::Command<opcode::Unify>> {
self.unify.get(idx as usize)
}
fn binders(&self, idx: Range<usize>) -> Option<&[Self::Var]> {
self.binders.get(idx)
}
}