mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Fix plumbing
This commit is contained in:
parent
107822a5cc
commit
ade591dd10
6 changed files with 22 additions and 14 deletions
|
@ -722,6 +722,16 @@ pub fn listAppend(list: RocList, alignment: u32, element: Opaque, element_width:
|
|||
return output;
|
||||
}
|
||||
|
||||
pub fn listSwap(
|
||||
list: RocList,
|
||||
alignment: u32,
|
||||
element_width: usize,
|
||||
index_1: usize,
|
||||
index_2: usize,
|
||||
) callconv(.C) RocList {
|
||||
return RocList.empty();
|
||||
}
|
||||
|
||||
pub fn listDrop(
|
||||
list: RocList,
|
||||
alignment: u32,
|
||||
|
|
|
@ -1885,13 +1885,13 @@ fn list_set(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
}
|
||||
|
||||
/// List.swap : List elem, Nat, Nat -> List elem
|
||||
fn list_drop(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
fn list_swap(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let list_var = var_store.fresh();
|
||||
let index1_var = var_store.fresh();
|
||||
let index2_var = var_store.fresh();
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::ListDrop,
|
||||
op: LowLevel::ListSwap,
|
||||
args: vec![
|
||||
(list_var, Var(Symbol::ARG_1)),
|
||||
(index1_var, Var(Symbol::ARG_2)),
|
||||
|
|
|
@ -4171,15 +4171,16 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
let (list, list_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||
let original_wrapper = list.into_struct_value();
|
||||
|
||||
let count = load_symbol(scope, &args[1]);
|
||||
let index_1 = load_symbol(scope, &args[1]);
|
||||
let index_2 = load_symbol(scope, &args[2]);
|
||||
|
||||
match list_layout {
|
||||
Layout::Builtin(Builtin::EmptyList) => empty_list(env),
|
||||
Layout::Builtin(Builtin::List(element_layout)) => list_swap(
|
||||
env,
|
||||
layout_ids,
|
||||
original_wrapper,
|
||||
count.into_int_value(),
|
||||
index_1.into_int_value(),
|
||||
index_2.into_int_value(),
|
||||
element_layout,
|
||||
),
|
||||
_ => unreachable!("Invalid layout {:?} in List.swap", list_layout),
|
||||
|
|
|
@ -307,19 +307,19 @@ pub fn list_append<'a, 'ctx, 'env>(
|
|||
/// List.swap : List elem, Nat, Nat -> List elem
|
||||
pub fn list_swap<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
original_wrapper: StructValue<'ctx>,
|
||||
count: IntValue<'ctx>,
|
||||
index_1: IntValue<'ctx>,
|
||||
index_2: IntValue<'ctx>,
|
||||
element_layout: &Layout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let dec_element_fn = build_dec_wrapper(env, layout_ids, &element_layout);
|
||||
call_bitcode_fn_returns_list(
|
||||
env,
|
||||
&[
|
||||
pass_list_as_i128(env, original_wrapper.into()),
|
||||
env.alignment_intvalue(&element_layout),
|
||||
layout_width(env, &element_layout),
|
||||
count.into(),
|
||||
index_1.into(),
|
||||
index_2.into(),
|
||||
],
|
||||
&bitcode::LIST_SWAP,
|
||||
)
|
||||
|
|
|
@ -40,6 +40,7 @@ pub enum LowLevel {
|
|||
ListKeepErrs,
|
||||
ListSortWith,
|
||||
ListDrop,
|
||||
ListSwap,
|
||||
DictSize,
|
||||
DictEmpty,
|
||||
DictInsert,
|
||||
|
|
|
@ -181,11 +181,7 @@ fn list_drop() {
|
|||
|
||||
#[test]
|
||||
fn list_swap() {
|
||||
assert_evals_to!(
|
||||
"List.swap [] 0 1",
|
||||
RocList::from_slice(&[]),
|
||||
RocList<i64>
|
||||
);
|
||||
assert_evals_to!("List.swap [] 0 1", RocList::from_slice(&[]), RocList<i64>);
|
||||
assert_evals_to!(
|
||||
"List.swap [ 0 ] 1 2",
|
||||
RocList::from_slice(&[0]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue