builtins: Move return pointer to first position for fromUtf8C

This commit is contained in:
Brian Carroll 2022-07-04 11:02:19 +01:00
parent a342f02824
commit 60d29c2e25
No known key found for this signature in database
GPG Key ID: 9CF4E3BF9C4722C7
3 changed files with 12 additions and 21 deletions

View File

@ -1552,7 +1552,7 @@ const CountAndStart = extern struct {
start: usize,
};
pub fn fromUtf8C(arg: RocList, update_mode: UpdateMode, output: *FromUtf8Result) callconv(.C) void {
pub fn fromUtf8C(output: *FromUtf8Result, arg: RocList, update_mode: UpdateMode) callconv(.C) void {
output.* = fromUtf8(arg, update_mode);
}

View File

@ -194,9 +194,9 @@ pub fn str_from_utf8<'a, 'ctx, 'env>(
call_void_bitcode_fn(
env,
&[
result_ptr.into(),
list_symbol_to_c_abi(env, scope, list).into(),
pass_update_mode(env, update_mode),
result_ptr.into(),
],
bitcode::STR_FROM_UTF8,
);

View File

@ -265,29 +265,20 @@ impl<'a> LowLevelCall<'a> {
Low-level op returns a struct with all the data for both Ok and Err.
Roc AST wrapper converts this to a tag union, with app-dependent tag IDs.
fromUtf8C(arg: RocList, update_mode: UpdateMode, output: *FromUtf8Result) callconv(.C) void
fromUtf8C(output: *FromUtf8Result, arg: RocList, update_mode: UpdateMode) callconv(.C) void
output: *FromUtf8Result i32
arg: RocList i64, i32
update_mode: UpdateMode i32
output: *FromUtf8Result i32
*/
let (ret_ptr, ret_offset) = match &self.ret_storage {
StoredValue::StackMemory { location, .. } => {
location.local_and_offset(backend.storage.stack_frame_pointer)
}
_ => internal_error!("Low-level op StrFromUtf8 should return a struct"),
};
// Return pointer is the last arg rather than the first, so we can't use the usual helper.
backend
.storage
.load_symbol_zig(&mut backend.code_builder, self.arguments[0]);
backend.storage.load_symbols_for_call(
backend.env.arena,
&mut backend.code_builder,
self.arguments,
self.ret_symbol,
&WasmLayout::new(&self.ret_layout),
CallConv::Zig,
);
backend.code_builder.i32_const(UPDATE_MODE_IMMUTABLE);
backend.code_builder.get_local(ret_ptr);
if ret_offset != 0 {
backend.code_builder.i32_const(ret_offset as i32);
backend.code_builder.i32_add();
}
backend.call_host_fn_after_loading_args(bitcode::STR_FROM_UTF8, 4, false);
}
StrTrimLeft => self.load_args_and_call_zig(backend, bitcode::STR_TRIM_LEFT),