cl-typeck: Turn ref into a linked list.

This should be fine, since the only thing you can do with a ref is dereference it.
This commit is contained in:
John 2024-07-26 02:14:41 -05:00
parent 03a4e76292
commit 4096442f75
4 changed files with 10 additions and 13 deletions

View File

@ -21,10 +21,8 @@ impl fmt::Display for Entry<'_, '_> {
TypeKind::Instance(id) => write!(f, "{}", self.with_id(*id)), TypeKind::Instance(id) => write!(f, "{}", self.with_id(*id)),
TypeKind::Intrinsic(kind) => write!(f, "{kind}"), TypeKind::Intrinsic(kind) => write!(f, "{kind}"),
TypeKind::Adt(adt) => write_adt(adt, self, f), TypeKind::Adt(adt) => write_adt(adt, self, f),
&TypeKind::Ref(cnt, id) => { &TypeKind::Ref(id) => {
for _ in 0..cnt {
f.write_str("&")?; f.write_str("&")?;
}
let h_id = self.with_id(id); let h_id = self.with_id(id);
write_name_or(h_id, f) write_name_or(h_id, f)
} }

View File

@ -97,8 +97,12 @@ impl TypeExpression for TyTuple {
impl TypeExpression for TyRef { impl TypeExpression for TyRef {
fn evaluate(&self, table: &mut Table, node: Handle) -> Result<Handle, Error> { fn evaluate(&self, table: &mut Table, node: Handle) -> Result<Handle, Error> {
let Self { mutable: _, count, to } = self; let Self { mutable: _, count, to } = self;
let kind = TypeKind::Ref(*count, to.evaluate(table, node)?); let mut t = to.evaluate(table, node)?;
Ok(table.anon_type(kind)) for _ in 0..*count {
let kind = TypeKind::Ref(t);
t = table.anon_type(kind)
}
Ok(t)
} }
} }

View File

@ -17,7 +17,7 @@ pub enum TypeKind {
/// A user-defined aromatic data type /// A user-defined aromatic data type
Adt(Adt), Adt(Adt),
/// A reference to an already-defined type: &T /// A reference to an already-defined type: &T
Ref(u16, Handle), Ref(Handle),
/// A contiguous view of dynamically sized memory /// A contiguous view of dynamically sized memory
Slice(Handle), Slice(Handle),
/// A contiguous view of statically sized memory /// A contiguous view of statically sized memory

View File

@ -11,12 +11,7 @@ impl Display for TypeKind {
TypeKind::Instance(def) => write!(f, "alias to #{def}"), TypeKind::Instance(def) => write!(f, "alias to #{def}"),
TypeKind::Intrinsic(i) => i.fmt(f), TypeKind::Intrinsic(i) => i.fmt(f),
TypeKind::Adt(a) => a.fmt(f), TypeKind::Adt(a) => a.fmt(f),
TypeKind::Ref(cnt, def) => { TypeKind::Ref(def) => write!(f, "&{def}"),
for _ in 0..*cnt {
f.write_str("&")?;
}
def.fmt(f)
}
TypeKind::Slice(def) => write!(f, "slice [#{def}]"), TypeKind::Slice(def) => write!(f, "slice [#{def}]"),
TypeKind::Array(def, size) => write!(f, "array [#{def}; {size}]"), TypeKind::Array(def, size) => write!(f, "array [#{def}; {size}]"),
TypeKind::Tuple(defs) => { TypeKind::Tuple(defs) => {