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,9 +5820,42 @@ fn run_low_level<'a, 'ctx, 'env>(
// Str.getScalarUnsafe : Str, Nat -> { bytesParsed : Nat, scalar : U32 }
debug_assert_eq!(args.len(), 2);
use roc_target::OperatingSystem::*;
let string = load_symbol(scope, &args[0]);
let index = load_symbol(scope, &args[1]);
match env.target_info.operating_system {
Windows => {
// we have to go digging to find the return type
let function = env
.module
.get_function(bitcode::STR_GET_SCALAR_UNSAFE)
.unwrap();
let return_type = function.get_type().get_param_types()[0]
.into_pointer_type()
.get_element_type()
.into_struct_type();
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],
@ -5840,6 +5873,9 @@ fn run_low_level<'a, 'ctx, 'env>(
}
}
}
Wasi => unimplemented!(),
}
}
StrCountUtf8Bytes => {
// Str.countUtf8Bytes : Str -> Nat
debug_assert_eq!(args.len(), 1);