mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
CHECK 2 done
Add support for handling generic types in LLVM backend - Updated `lb_type_internal` to return a pointer type for unspecialized generics. - Modified `write_type_to_canonical_string` to handle specialized generics without panicking. - Enhanced `default_type` to return the default type of specialized generics when applicable.
This commit is contained in:
@@ -2212,6 +2212,14 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
|||||||
|
|
||||||
case Type_BitField:
|
case Type_BitField:
|
||||||
return lb_type_internal(m, type->BitField.backing_type);
|
return lb_type_internal(m, type->BitField.backing_type);
|
||||||
|
|
||||||
|
case Type_Generic:
|
||||||
|
if (type->Generic.specialized) {
|
||||||
|
return lb_type_internal(m, type->Generic.specialized);
|
||||||
|
} else {
|
||||||
|
// For unspecialized generics, use a pointer type as a placeholder
|
||||||
|
return LLVMPointerType(LLVMInt8TypeInContext(m->ctx), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GB_PANIC("Invalid type %s", type_to_string(type));
|
GB_PANIC("Invalid type %s", type_to_string(type));
|
||||||
|
|||||||
@@ -756,8 +756,12 @@ gb_internal void write_type_to_canonical_string(TypeWriter *w, Type *type) {
|
|||||||
type_writer_appendc(w, "/");
|
type_writer_appendc(w, "/");
|
||||||
write_type_to_canonical_string(w, type->Generic.specialized);
|
write_type_to_canonical_string(w, type->Generic.specialized);
|
||||||
}
|
}
|
||||||
|
} else if (type->Generic.specialized) {
|
||||||
|
// If we have a specialized type, use that instead of panicking
|
||||||
|
write_type_to_canonical_string(w, type->Generic.specialized);
|
||||||
} else {
|
} else {
|
||||||
GB_PANIC("Type_Generic should never be hit");
|
// For unspecialized generics, use a generic placeholder string
|
||||||
|
type_writer_appendc(w, "rawptr");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -2932,6 +2932,10 @@ gb_internal Type *default_type(Type *type) {
|
|||||||
case Basic_UntypedString: return t_string;
|
case Basic_UntypedString: return t_string;
|
||||||
case Basic_UntypedRune: return t_rune;
|
case Basic_UntypedRune: return t_rune;
|
||||||
}
|
}
|
||||||
|
} else if (type->kind == Type_Generic) {
|
||||||
|
if (type->Generic.specialized) {
|
||||||
|
return default_type(type->Generic.specialized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user