diff --git a/src/lower/mod.rs b/src/lower/mod.rs index 889ce212..9b347fa6 100644 --- a/src/lower/mod.rs +++ b/src/lower/mod.rs @@ -56,7 +56,7 @@ fn lower_type( match &resolved_type.kind { resolved::TypeKind::Unresolved => panic!("got unresolved type during lower_type!"), - resolved::TypeKind::Polymorph(_) => todo!("lower polymorph"), + resolved::TypeKind::Polymorph(_, _) => todo!("cannot directly lower polymorpn"), resolved::TypeKind::Boolean => Ok(ir::Type::Boolean), resolved::TypeKind::Integer(bits, sign) => Ok(match (bits, sign) { (Bits::Bits8, Sign::Signed) => ir::Type::S8, diff --git a/src/resolve/function_head.rs b/src/resolve/function_head.rs index b5afe7cb..46b6313e 100644 --- a/src/resolve/function_head.rs +++ b/src/resolve/function_head.rs @@ -38,10 +38,6 @@ pub fn create_function_heads( .iter() .any(|param| param.ast_type.contains_polymorph().is_some()); - if is_generic { - todo!("resolving generic functions is not implemented yet"); - } - let parameters = resolve_parameters(&type_ctx, &function.parameters)?; let return_type = type_ctx.resolve(&function.return_type)?; diff --git a/src/resolve/type_ctx/resolve_type.rs b/src/resolve/type_ctx/resolve_type.rs index 2b7c368d..0b2cbb1e 100644 --- a/src/resolve/type_ctx/resolve_type.rs +++ b/src/resolve/type_ctx/resolve_type.rs @@ -3,7 +3,7 @@ use crate::{ ast::{self, IntegerBits}, ir::IntegerSign, resolve::error::{ResolveError, ResolveErrorKind}, - resolved, + resolved::{self, Constraint}, source_files::Source, }; use std::borrow::Borrow; @@ -93,12 +93,20 @@ impl<'a> ResolveTypeCtx<'a> { }, )) } - ast::TypeKind::Polymorph(polymorph, constaints) => { - if !constaints.is_empty() { - todo!("resolve polymorph constaints"); + ast::TypeKind::Polymorph(polymorph, constraints) => { + let mut resolved_constraints = vec![]; + + if !constraints.is_empty() { + eprintln!( + "warning: resolving polymorph constaints not completely implemented yet" + ); + resolved_constraints.push(Constraint::Add); } - Ok(resolved::TypeKind::Polymorph(polymorph.clone())) + Ok(resolved::TypeKind::Polymorph( + polymorph.clone(), + resolved_constraints, + )) } } .map(|kind| kind.at(ast_type.source)) diff --git a/src/resolved/datatype/kind/mod.rs b/src/resolved/datatype/kind/mod.rs index 36b626a4..58f7bd8e 100644 --- a/src/resolved/datatype/kind/mod.rs +++ b/src/resolved/datatype/kind/mod.rs @@ -1,4 +1,5 @@ mod anonymous_enum; +mod constraint; mod fixed_array; mod function_pointer; @@ -10,6 +11,7 @@ use crate::{ target::Target, }; pub use anonymous_enum::AnonymousEnum; +pub use constraint::Constraint; use derive_more::{IsVariant, Unwrap}; pub use fixed_array::FixedArray; pub use function_pointer::FunctionPointer; @@ -35,7 +37,7 @@ pub enum TypeKind { Enum(HumanName, EnumRef), Structure(HumanName, StructureRef), TypeAlias(HumanName, TypeAliasRef), - Polymorph(String), + Polymorph(String, Vec), } impl TypeKind { @@ -68,7 +70,7 @@ impl TypeKind { | TypeKind::FunctionPointer(..) | TypeKind::Enum(_, _) | TypeKind::AnonymousEnum(_) - | TypeKind::Polymorph(_) => None, + | TypeKind::Polymorph(_, _) => None, } } } @@ -115,7 +117,17 @@ impl Display for TypeKind { } TypeKind::FunctionPointer(..) => f.write_str("function-pointer-type")?, TypeKind::Enum(name, _) => write!(f, "{}", name)?, - TypeKind::Polymorph(name) => write!(f, "${}", name)?, + TypeKind::Polymorph(name, constaints) => { + write!(f, "${}", name)?; + + if !constaints.is_empty() { + write!(f, ": ")?; + } + + for constaint in constaints { + write!(f, "{:?}", constaint)?; + } + } } Ok(())