mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
wasm: List.swap
This commit is contained in:
parent
29e9e5b88e
commit
bbefacb76d
2 changed files with 36 additions and 2 deletions
|
@ -591,7 +591,41 @@ impl<'a> LowLevelCall<'a> {
|
||||||
ListRange => todo!("{:?}", self.lowlevel),
|
ListRange => todo!("{:?}", self.lowlevel),
|
||||||
ListSublist => todo!("{:?}", self.lowlevel),
|
ListSublist => todo!("{:?}", self.lowlevel),
|
||||||
ListDropAt => todo!("{:?}", self.lowlevel),
|
ListDropAt => todo!("{:?}", self.lowlevel),
|
||||||
ListSwap => todo!("{:?}", self.lowlevel),
|
ListSwap => {
|
||||||
|
// List.swap : List elem, Nat, Nat -> List elem
|
||||||
|
let list: Symbol = self.arguments[0];
|
||||||
|
let index_1: Symbol = self.arguments[1];
|
||||||
|
let index_2: Symbol = self.arguments[2];
|
||||||
|
|
||||||
|
let elem_layout = unwrap_list_elem_layout(self.ret_layout);
|
||||||
|
let (elem_width, elem_align) = elem_layout.stack_size_and_alignment(TARGET_INFO);
|
||||||
|
|
||||||
|
// Zig arguments Wasm types
|
||||||
|
// (return pointer) i32
|
||||||
|
// list: RocList, i64, i32
|
||||||
|
// alignment: u32, i32
|
||||||
|
// element_width: usize, i32
|
||||||
|
// index_1: usize, i32
|
||||||
|
// index_2: usize, i32
|
||||||
|
// update_mode: UpdateMode, i32
|
||||||
|
|
||||||
|
// Load the return pointer and the list
|
||||||
|
backend.storage.load_symbols_for_call(
|
||||||
|
backend.env.arena,
|
||||||
|
&mut backend.code_builder,
|
||||||
|
&[list],
|
||||||
|
self.ret_symbol,
|
||||||
|
&WasmLayout::new(&self.ret_layout),
|
||||||
|
CallConv::Zig,
|
||||||
|
);
|
||||||
|
|
||||||
|
backend.code_builder.i32_const(elem_align as i32);
|
||||||
|
backend.code_builder.i32_const(elem_width as i32);
|
||||||
|
backend.storage.load_symbols(&mut backend.code_builder, &[index_1, index_2]);
|
||||||
|
backend.code_builder.i32_const(UPDATE_MODE_IMMUTABLE);
|
||||||
|
|
||||||
|
backend.call_host_fn_after_loading_args(bitcode::LIST_SWAP, 8, false);
|
||||||
|
}
|
||||||
|
|
||||||
DictSize | DictEmpty | DictInsert | DictRemove | DictContains | DictGetUnsafe
|
DictSize | DictEmpty | DictInsert | DictRemove | DictContains | DictGetUnsafe
|
||||||
| DictKeys | DictValues | DictUnion | DictIntersection | DictDifference
|
| DictKeys | DictValues | DictUnion | DictIntersection | DictDifference
|
||||||
|
|
|
@ -550,7 +550,7 @@ fn list_drop_first() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(feature = "gen-llvm"))]
|
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||||
fn list_swap() {
|
fn list_swap() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
"List.swap [] 0 1",
|
"List.swap [] 0 1",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue