fix get scalar unsafe for windows

This commit is contained in:
Folkert 2022-09-04 18:57:56 +02:00
parent a52a148424
commit 828ded8ebc
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -5820,24 +5820,60 @@ fn run_low_level<'a, 'ctx, 'env>(
// Str.getScalarUnsafe : Str, Nat -> { bytesParsed : Nat, scalar : U32 } // Str.getScalarUnsafe : Str, Nat -> { bytesParsed : Nat, scalar : U32 }
debug_assert_eq!(args.len(), 2); debug_assert_eq!(args.len(), 2);
use roc_target::OperatingSystem::*;
let string = load_symbol(scope, &args[0]); let string = load_symbol(scope, &args[0]);
let index = load_symbol(scope, &args[1]); let index = load_symbol(scope, &args[1]);
let result = call_str_bitcode_fn( match env.target_info.operating_system {
env, Windows => {
&[string], // we have to go digging to find the return type
&[index], let function = env
BitcodeReturns::Basic, .module
bitcode::STR_GET_SCALAR_UNSAFE, .get_function(bitcode::STR_GET_SCALAR_UNSAFE)
); .unwrap();
// on 32-bit platforms, zig bitpacks the struct let return_type = function.get_type().get_param_types()[0]
match env.target_info.ptr_width() { .into_pointer_type()
PtrWidth::Bytes8 => result, .get_element_type()
PtrWidth::Bytes4 => { .into_struct_type();
let to = basic_type_from_layout(env, layout);
complex_bitcast_check_size(env, result, to, "to_roc_record") let result = env.builder.build_alloca(return_type, "result");
call_void_bitcode_fn(
env,
&[result.into(), string, index],
bitcode::STR_GET_SCALAR_UNSAFE,
);
let return_type = basic_type_from_layout(env, layout);
let cast_result = env.builder.build_pointer_cast(
result,
return_type.ptr_type(AddressSpace::Generic),
"cast",
);
env.builder.build_load(cast_result, "load_result")
} }
Unix => {
let result = call_str_bitcode_fn(
env,
&[string],
&[index],
BitcodeReturns::Basic,
bitcode::STR_GET_SCALAR_UNSAFE,
);
// on 32-bit platforms, zig bitpacks the struct
match env.target_info.ptr_width() {
PtrWidth::Bytes8 => result,
PtrWidth::Bytes4 => {
let to = basic_type_from_layout(env, layout);
complex_bitcast_check_size(env, result, to, "to_roc_record")
}
}
}
Wasi => unimplemented!(),
} }
} }
StrCountUtf8Bytes => { StrCountUtf8Bytes => {