+typesys crate

This commit is contained in:
Alain Zscheile 2023-05-25 09:14:02 +02:00
parent 5a3254004f
commit 5672942c6b
3 changed files with 45 additions and 0 deletions

4
Cargo.lock generated
View file

@ -161,6 +161,10 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "wafl-typesys"
version = "0.1.0"
[[package]]
name = "windows-sys"
version = "0.45.0"

View file

@ -0,0 +1,8 @@
[package]
name = "wafl-typesys"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1,33 @@
use core::fmt;
use std::collections::BTreeMap;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub enum Type {
Top,
Bot,
Primitive(PrimitiveType),
Union(Vec<Type>),
Inter(Vec<Type>),
Function(Box<(Type, Type)>),
Recursive(Arc<TypeVariable>, Box<Type>),
Variable(Arc<TypeVariable>),
Record(BTreeMap<String, Type>),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PrimitiveType {
Integer,
}
#[derive(Debug)]
pub struct TypeVariable {
pub name_hint: String,
pub hash_: u32,
}
impl fmt::Display for TypeVariable {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{:x}", self.name_hint, self.hash_)
}
}