mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
make things compile
This commit is contained in:
parent
2355bbf815
commit
a05d8b52c0
3 changed files with 42 additions and 34 deletions
|
@ -134,30 +134,18 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
|
|||
)
|
||||
.into_pointer_value();
|
||||
|
||||
let input = env.builder.build_load(argument_cast, "get_value");
|
||||
let tag_value = env.builder.build_load(argument_cast, "get_value");
|
||||
|
||||
let tag_value = crate::llvm::build::extract_tag_discriminant(
|
||||
env,
|
||||
function_value,
|
||||
union_layout,
|
||||
input,
|
||||
);
|
||||
let actual_tag_id = {
|
||||
let tag_id_i64 = crate::llvm::build::extract_tag_discriminant(
|
||||
env,
|
||||
function_value,
|
||||
union_layout,
|
||||
tag_value,
|
||||
);
|
||||
|
||||
let actual_tag_id =
|
||||
env.builder
|
||||
.build_int_cast(tag_value, env.context.i16_type(), "to_i16");
|
||||
|
||||
let data_ptr = {
|
||||
let index = env
|
||||
.context
|
||||
.i64_type()
|
||||
.const_int(TAG_DATA_INDEX as u64, false);
|
||||
let ptr = unsafe {
|
||||
env.builder
|
||||
.build_in_bounds_gep(argument_cast, &[index], "get_tag_id")
|
||||
};
|
||||
|
||||
env.builder.build_bitcast(ptr, i8_ptr_type, "to_opaque")
|
||||
.build_int_cast(tag_id_i64, env.context.i16_type(), "to_i16")
|
||||
};
|
||||
|
||||
let answer = env.builder.build_int_compare(
|
||||
|
@ -167,7 +155,7 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
|
|||
"compare",
|
||||
);
|
||||
|
||||
let field_vals = [(0, answer.into()), (1, data_ptr)];
|
||||
let field_vals = [(0, answer.into()), (1, *tag_value_ptr)];
|
||||
|
||||
let output = struct_from_fields(env, output_type, field_vals.iter().copied());
|
||||
|
||||
|
|
|
@ -996,19 +996,10 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
|
||||
// Create the struct_type
|
||||
let struct_type = ctx.struct_type(field_types.into_bump_slice(), false);
|
||||
let mut struct_val = struct_type.const_zero().into();
|
||||
|
||||
// Insert field exprs into struct_val
|
||||
for (index, field_val) in field_vals.into_iter().enumerate() {
|
||||
struct_val = builder
|
||||
.build_insert_value(
|
||||
struct_val,
|
||||
field_val,
|
||||
index as u32,
|
||||
"insert_multi_tag_field",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let struct_val =
|
||||
struct_from_fields(env, struct_type, field_vals.into_iter().enumerate());
|
||||
|
||||
// How we create tag values
|
||||
//
|
||||
|
@ -1036,7 +1027,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
|
||||
let internal_type = basic_type_from_layout(env, &tag_layout);
|
||||
|
||||
cast_tag_to_block_of_memory(builder, struct_val.into_struct_value(), internal_type)
|
||||
cast_tag_to_block_of_memory(builder, struct_val, internal_type)
|
||||
}
|
||||
Tag {
|
||||
arguments,
|
||||
|
@ -1575,6 +1566,29 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn struct_from_fields<'a, 'ctx, 'env, I>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
struct_type: StructType<'ctx>,
|
||||
values: I,
|
||||
) -> StructValue<'ctx>
|
||||
where
|
||||
I: Iterator<Item = (usize, BasicValueEnum<'ctx>)>,
|
||||
{
|
||||
let mut struct_value = struct_type.const_zero().into();
|
||||
|
||||
// Insert field exprs into struct_val
|
||||
for (index, field_val) in values {
|
||||
let index: u32 = index as u32;
|
||||
|
||||
struct_value = env
|
||||
.builder
|
||||
.build_insert_value(struct_value, field_val, index, "insert_record_field")
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
struct_value.into_struct_value()
|
||||
}
|
||||
|
||||
fn lookup_at_index_ptr<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
field_layouts: &[Layout<'_>],
|
||||
|
|
|
@ -180,3 +180,9 @@ pub fn zig_str_type<'a, 'ctx, 'env>(
|
|||
) -> StructType<'ctx> {
|
||||
env.module.get_struct_type("str.RocStr").unwrap()
|
||||
}
|
||||
|
||||
pub fn zig_has_tag_id_type<'a, 'ctx, 'env>(
|
||||
env: &crate::llvm::build::Env<'a, 'ctx, 'env>,
|
||||
) -> StructType<'ctx> {
|
||||
env.module.get_struct_type("list.HasTagId").unwrap()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue