make conversion a cast again

This commit is contained in:
Folkert 2021-09-12 14:28:44 +02:00
parent 0b893eb972
commit c0cfd6ac16
2 changed files with 13 additions and 22 deletions

View file

@ -1150,8 +1150,8 @@ fn strToBytes(arg: RocStr) RocList {
} }
const FromUtf8Result = extern struct { const FromUtf8Result = extern struct {
string: RocStr,
byte_index: usize, byte_index: usize,
string: RocStr,
is_ok: bool, is_ok: bool,
problem_code: Utf8ByteProblem, problem_code: Utf8ByteProblem,
}; };

View file

@ -1,5 +1,5 @@
use crate::llvm::bitcode::{call_bitcode_fn, call_void_bitcode_fn}; use crate::llvm::bitcode::{call_bitcode_fn, call_void_bitcode_fn};
use crate::llvm::build::{complex_bitcast, struct_from_fields, Env, Scope}; use crate::llvm::build::{complex_bitcast, Env, Scope};
use crate::llvm::build_list::{allocate_list, call_bitcode_fn_returns_list, store_list}; use crate::llvm::build_list::{allocate_list, call_bitcode_fn_returns_list, store_list};
use inkwell::builder::Builder; use inkwell::builder::Builder;
use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, StructValue}; use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, StructValue};
@ -281,27 +281,18 @@ fn decode_from_utf8_result<'a, 'ctx, 'env>(
match env.ptr_bytes { match env.ptr_bytes {
8 | 4 => { 8 | 4 => {
let zig_struct = builder let result_ptr_cast = env
.build_load(pointer, "load_utf8_validate_bytes_result") .builder
.into_struct_value(); .build_bitcast(
pointer,
record_type.ptr_type(AddressSpace::Generic),
"to_unnamed",
)
.into_pointer_value();
let string = builder builder
.build_extract_value(zig_struct, 0, "string") .build_load(result_ptr_cast, "load_utf8_validate_bytes_result")
.unwrap(); .into_struct_value()
let byte_index = builder
.build_extract_value(zig_struct, 1, "byte_index")
.unwrap();
let is_ok = builder.build_extract_value(zig_struct, 2, "is_ok").unwrap();
let problem_code = builder
.build_extract_value(zig_struct, 3, "problem_code")
.unwrap();
let values = [byte_index, string, is_ok, problem_code];
struct_from_fields(env, record_type, values.iter().copied().enumerate())
} }
_ => unreachable!(), _ => unreachable!(),
} }