From 448252a297bdbeddad41013e09082edc686b201f 2022-02-15 10:30:25 From: mh Date: 2022-02-15 10:30:25 Subject: [PATCH] Add initial procedure for builtin types in type table --- diff --git a/src/protocol/parser/type_table.rs b/src/protocol/parser/type_table.rs index db185dcb1b7bd322239cbdde25ffb4c83505bfa8..d44a4f7b45d41f6ec57a0570073bc28c40a86d28 100644 --- a/src/protocol/parser/type_table.rs +++ b/src/protocol/parser/type_table.rs @@ -233,6 +233,7 @@ pub struct MonomorphExpression { //------------------------------------------------------------------------------ pub(crate) enum MonoTypeVariant { + Builtin, // no extra data, added manually in compiler initialization code Enum, // no extra data Struct(StructMonomorph), Union(UnionMonomorph), @@ -774,6 +775,25 @@ impl TypeTable { return type_id; } + /// Adds a builtin type to the type table. As this is only called by the + /// compiler during setup we assume it cannot fail. + // TODO: Finish this train of thought, requires a little bit of design work + pub(crate) fn add_builtin_type(&mut self, concrete_type: ConcreteType, poly_vars: &[PolymorphicVariable], size: usize, alignment: usize) -> TypeId { + self.mono_search_key.set(&concrete_type.parts, poly_vars); + debug_assert!(!self.mono_type_lookup.contains_key(&self.mono_search_key)); + let type_id = TypeId(self.mono_types.len() as i64); + self.mono_type_lookup.insert(self.mono_search_key.clone(), type_id); + self.mono_types.push(MonoType{ + type_id, + concrete_type, + size, + alignment, + variant: MonoTypeVariant::Builtin, + }); + + return type_id; + } + /// Adds a monomorphed type to the type table. If it already exists then the /// previous entry will be used. pub(crate) fn add_monomorphed_type( @@ -1245,6 +1265,9 @@ impl TypeTable { let mono_type = &self.mono_types[breadcrumb.type_id.0 as usize]; let resolve_result = match &mono_type.variant { + MonoTypeVariant::Builtin => { + TypeLoopResult::TypeExists + } MonoTypeVariant::Enum => { TypeLoopResult::TypeExists }, @@ -1786,7 +1809,7 @@ impl TypeTable { let mono_type = &self.mono_types[breadcrumb.type_id.0 as usize]; match &mono_type.variant { - MonoTypeVariant::Enum => { + MonoTypeVariant::Builtin | MonoTypeVariant::Enum => { // Size should already be computed dbg_code!({ let mono_type = &self.mono_types[breadcrumb.type_id.0 as usize];