add adts to type system

This commit is contained in:
NotAFile 2022-04-05 15:11:26 +02:00
parent c0be718bbc
commit 86e3bf4d32
1 changed files with 13 additions and 15 deletions

View File

@ -25,10 +25,8 @@ enum TypeKind {
ElabType(ElabKind), ElabType(ElabKind),
/// Signal/Wire of generic width /// Signal/Wire of generic width
Logic(ElabData), Logic(ElabData),
/// UInt of generic width /// User-defined ADT
UInt(ElabData), Adt(Adt),
/// Callable
Callable(FnSig),
/// A type that was not given and needs to be inferred /// A type that was not given and needs to be inferred
Infer, Infer,
/// A reference to a type variable as DeBruijn index /// A reference to a type variable as DeBruijn index
@ -37,9 +35,13 @@ enum TypeKind {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct FnSig { pub enum Adt {
params: Vec<Type>, Struct(Struct),
ret: Type, }
#[derive(Debug, Clone)]
pub struct Struct {
members: Vec<Type>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -182,8 +184,7 @@ impl TypingContext {
ElabValueData::Bytes(_) => None, ElabValueData::Bytes(_) => None,
}, },
}, },
TypeKind::UInt(_) => todo!(), TypeKind::Adt(_) => todo!("calculate struct width"),
TypeKind::Callable(_) => None,
TypeKind::Infer => None, TypeKind::Infer => None,
TypeKind::TypeVar(_, _) => None, TypeKind::TypeVar(_, _) => None,
} }
@ -214,8 +215,7 @@ impl TypingContext {
None None
} }
} }
TypeKind::UInt(_) => todo!(), TypeKind::Adt(_) => todo!("can not parameterize struct"),
TypeKind::Callable(_sig) => todo!("callable generic params"),
// need to know what the type is to parameterize it // need to know what the type is to parameterize it
TypeKind::Infer | &TypeKind::TypeVar(_, _) => None, TypeKind::Infer | &TypeKind::TypeVar(_, _) => None,
} }
@ -248,8 +248,7 @@ impl TypingContext {
TypeKind::Logic(data) => { TypeKind::Logic(data) => {
matches!(data.value, ElabValue::Concrete(_)) matches!(data.value, ElabValue::Concrete(_))
} }
TypeKind::UInt(_) => todo!(), TypeKind::Adt(_) => todo!("adt fully typed"),
TypeKind::Callable(_) => todo!(),
TypeKind::Infer => false, TypeKind::Infer => false,
TypeKind::TypeVar(dbi, _tvar) => { TypeKind::TypeVar(dbi, _tvar) => {
// if the DeBruijn index is 0, there is no further information to gain // if the DeBruijn index is 0, there is no further information to gain
@ -283,9 +282,8 @@ impl TypingContext {
self.pretty_value(&mut width, val)?; self.pretty_value(&mut width, val)?;
write!(w, "Logic<{}>", width) write!(w, "Logic<{}>", width)
} }
TypeKind::Adt(_) => write!(w, "Struct{{...}}"),
TypeKind::Infer => write!(w, "?"), TypeKind::Infer => write!(w, "?"),
TypeKind::UInt(_) => todo!("print uint"),
TypeKind::Callable(_sig) => todo!("print callable"),
TypeKind::TypeVar(_, tvar) => write!(w, "T{}", tvar), TypeKind::TypeVar(_, tvar) => write!(w, "T{}", tvar),
} }
} }