From 86e3bf4d3222f92b0745262e3f1a7c1700885d82 Mon Sep 17 00:00:00 2001 From: NotAFile Date: Tue, 5 Apr 2022 15:11:26 +0200 Subject: [PATCH] add adts to type system --- src/frontend/types.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/frontend/types.rs b/src/frontend/types.rs index c22edd5..a42be05 100644 --- a/src/frontend/types.rs +++ b/src/frontend/types.rs @@ -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, - ret: Type, +pub enum Adt { + Struct(Struct), +} + +#[derive(Debug, Clone)] +pub struct Struct { + members: Vec, } #[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), } }