mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-18 17:49:47 +00:00
fix get scalar unsafe for windows
This commit is contained in:
parent
a52a148424
commit
828ded8ebc
1 changed files with 49 additions and 13 deletions
|
@ -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 => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue