This commit is contained in:
Folkert 2022-03-02 15:29:45 +01:00
parent ec099bbdec
commit b8fd6992a2
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 72 additions and 0 deletions

View file

@ -23,6 +23,7 @@ impl Constraints {
pub const CATEGORY_RECORD: Index<Category> = Index::new(0);
#[inline(always)]
pub fn push_type(&mut self, typ: Type) -> Index<Type> {
match typ {
Type::EmptyRec => Self::EMPTY_RECORD,
@ -31,6 +32,12 @@ impl Constraints {
}
}
#[inline(always)]
pub fn push_expected_type(&mut self, expected: Expected<Type>) -> Index<Expected<Type>> {
Index::push_new(&mut self.expectations, expected)
}
#[inline(always)]
pub fn push_category(&mut self, category: Category) -> Index<Category> {
match category {
Category::Record => Self::CATEGORY_RECORD,
@ -156,6 +163,21 @@ impl Constraints {
Constraint::Let(let_index)
}
pub fn and_contraint<I>(&mut self, constraints: I) -> Constraint
where
I: IntoIterator<Item = Constraint>,
{
let start = self.constraints.len() as u32;
self.constraints.extend(constraints);
let end = self.constraints.len() as u32;
let slice = Slice::new(start, (end - start) as u16);
Constraint::And(slice)
}
}
static_assertions::assert_eq_size!([u8; 4 * 8], Constraint);