Skip to content

Commit

Permalink
Started creating limited trait system for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Nov 5, 2024
1 parent d533402 commit 506c1bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions src/resolve/function_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
18 changes: 13 additions & 5 deletions src/resolve/type_ctx/resolve_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
18 changes: 15 additions & 3 deletions src/resolved/datatype/kind/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod anonymous_enum;
mod constraint;
mod fixed_array;
mod function_pointer;

Expand All @@ -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;
Expand All @@ -35,7 +37,7 @@ pub enum TypeKind {
Enum(HumanName, EnumRef),
Structure(HumanName, StructureRef),
TypeAlias(HumanName, TypeAliasRef),
Polymorph(String),
Polymorph(String, Vec<Constraint>),
}

impl TypeKind {
Expand Down Expand Up @@ -68,7 +70,7 @@ impl TypeKind {
| TypeKind::FunctionPointer(..)
| TypeKind::Enum(_, _)
| TypeKind::AnonymousEnum(_)
| TypeKind::Polymorph(_) => None,
| TypeKind::Polymorph(_, _) => None,
}
}
}
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 506c1bd

Please sign in to comment.