2021-10-27 01:11:46 -07:00
|
|
|
use std::{fmt, rc::Rc};
|
|
|
|
|
|
|
|
//TODO need to hook this into the actual typechecking system somehow
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct TypeId {
|
|
|
|
local_name: Rc<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for TypeId {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "TypeId:{}", self.local_name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TypeId {
|
|
|
|
pub fn local_name(&self) -> &str {
|
|
|
|
self.local_name.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TypeContext;
|
|
|
|
|
|
|
|
impl TypeContext {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self
|
|
|
|
}
|
2021-10-27 15:39:09 -07:00
|
|
|
|
|
|
|
//TODO flesh this out...
|
|
|
|
pub fn id_from_name(&self, name: &str) -> TypeId {
|
|
|
|
TypeId { local_name: Rc::new(name.to_string()) }
|
|
|
|
}
|
2021-10-27 01:11:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct TypeError {
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub enum TypeConst {
|
|
|
|
Unit,
|
|
|
|
Nat,
|
|
|
|
Int,
|
|
|
|
Float,
|
|
|
|
StringT,
|
|
|
|
Bool,
|
|
|
|
Ordering,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub enum Type {
|
|
|
|
Const(TypeConst),
|
|
|
|
//Var(TypeVar),
|
|
|
|
Arrow { params: Vec<Type>, ret: Box<Type> },
|
|
|
|
Compound { ty_name: String, args: Vec<Type> },
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! ty {
|
|
|
|
($type_name:ident) => {
|
|
|
|
Type::Const(crate::type_inference::TypeConst::$type_name)
|
|
|
|
};
|
|
|
|
($t1:ident -> $t2:ident) => {
|
|
|
|
Type::Arrow { params: vec![ty!($t1)], ret: box ty!($t2) }
|
|
|
|
};
|
|
|
|
($t1:ident -> $t2:ident -> $t3:ident) => {
|
|
|
|
Type::Arrow { params: vec![ty!($t1), ty!($t2)], ret: box ty!($t3) }
|
|
|
|
};
|
|
|
|
($type_list:ident, $ret_type:ident) => {
|
|
|
|
Type::Arrow { params: $type_list, ret: box $ret_type }
|
|
|
|
};
|
|
|
|
}
|