Add builder methods to create custom types

This commit is contained in:
Sofia 2025-07-16 16:16:18 +03:00
parent 31185d921e
commit 29996c4a30
2 changed files with 19 additions and 0 deletions

View File

@ -80,6 +80,16 @@ impl Builder {
value
}
pub(crate) unsafe fn add_type(&self, mod_val: &ModuleValue, data: TypeData) -> TypeValue {
unsafe {
let mut modules = self.modules.borrow_mut();
let module = modules.get_unchecked_mut(mod_val.0);
let value = TypeValue(module.value, module.types.len());
module.types.push(TypeHolder { value, data });
value
}
}
pub(crate) unsafe fn add_function(
&self,
mod_val: &ModuleValue,

View File

@ -76,6 +76,15 @@ impl<'ctx> Module<'ctx> {
}
}
pub fn custom_type(&mut self, ty: CustomTypeKind) -> TypeValue {
unsafe {
let (name, kind) = match &ty {
CustomTypeKind::NamedStruct(NamedStruct(name, _)) => (name.clone(), ty),
};
self.builder.add_type(&self.value, TypeData { name, kind })
}
}
pub fn value(&self) -> ModuleValue {
self.value
}