add adts to type system

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