mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
change over nullable wrapped
This commit is contained in:
parent
71857e83d0
commit
8add147dcf
5 changed files with 230 additions and 152 deletions
|
@ -34,12 +34,15 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>(
|
|||
Union(variant) => {
|
||||
use UnionLayout::*;
|
||||
match variant {
|
||||
Recursive(tags)
|
||||
| NullableWrapped {
|
||||
NullableWrapped {
|
||||
other_tags: tags, ..
|
||||
} => {
|
||||
let block = block_of_memory_slices(env.context, tags, env.ptr_bytes);
|
||||
block.ptr_type(AddressSpace::Generic).into()
|
||||
let data = block_of_memory_slices(env.context, tags, env.ptr_bytes);
|
||||
|
||||
env.context
|
||||
.struct_type(&[data, env.context.i64_type().into()], false)
|
||||
.ptr_type(AddressSpace::Generic)
|
||||
.into()
|
||||
}
|
||||
NullableUnwrapped { other_fields, .. } => {
|
||||
let block =
|
||||
|
@ -50,8 +53,16 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>(
|
|||
let block = block_of_memory_slices(env.context, &[fields], env.ptr_bytes);
|
||||
block.ptr_type(AddressSpace::Generic).into()
|
||||
}
|
||||
NonRecursive(_) => {
|
||||
let data = block_of_memory(env.context, layout, env.ptr_bytes);
|
||||
Recursive(tags) => {
|
||||
let data = block_of_memory_slices(env.context, tags, env.ptr_bytes);
|
||||
|
||||
env.context
|
||||
.struct_type(&[data, env.context.i64_type().into()], false)
|
||||
.ptr_type(AddressSpace::Generic)
|
||||
.into()
|
||||
}
|
||||
NonRecursive(tags) => {
|
||||
let data = block_of_memory_slices(env.context, tags, env.ptr_bytes);
|
||||
|
||||
env.context
|
||||
.struct_type(&[data, env.context.i64_type().into()], false)
|
||||
|
@ -117,6 +128,32 @@ pub fn block_of_memory_slices<'ctx>(
|
|||
block_of_memory_help(context, union_size)
|
||||
}
|
||||
|
||||
pub fn union_data_is_struct<'a, 'ctx, 'env>(
|
||||
env: &crate::llvm::build::Env<'a, 'ctx, 'env>,
|
||||
layouts: &[Layout<'_>],
|
||||
) -> StructType<'ctx> {
|
||||
let data_type = basic_type_from_record(env, layouts);
|
||||
union_data_is_struct_type(env.context, data_type.into_struct_type())
|
||||
}
|
||||
|
||||
pub fn union_data_is_struct_type<'ctx>(
|
||||
context: &'ctx Context,
|
||||
struct_type: StructType<'ctx>,
|
||||
) -> StructType<'ctx> {
|
||||
let tag_id_type = context.i64_type();
|
||||
context.struct_type(&[struct_type.into(), tag_id_type.into()], false)
|
||||
}
|
||||
|
||||
pub fn union_data_block_of_memory<'ctx>(
|
||||
context: &'ctx Context,
|
||||
layouts: &[&[Layout<'_>]],
|
||||
ptr_bytes: u32,
|
||||
) -> StructType<'ctx> {
|
||||
let tag_id_type = context.i64_type();
|
||||
let data_type = block_of_memory_slices(context, layouts, ptr_bytes);
|
||||
context.struct_type(&[data_type, tag_id_type.into()], false)
|
||||
}
|
||||
|
||||
pub fn block_of_memory<'ctx>(
|
||||
context: &'ctx Context,
|
||||
layout: &Layout<'_>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue