Implement List.takeFirst

This commit is contained in:
satotake 2021-11-08 14:10:53 +00:00 committed by GitHub
parent 978f9e0bc6
commit 878400f95f
13 changed files with 145 additions and 1 deletions

View file

@ -297,6 +297,28 @@ pub fn list_swap<'a, 'ctx, 'env>(
)
}
/// List.takeFirst : List elem, Nat -> List elem
pub fn list_take_first<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
original_wrapper: StructValue<'ctx>,
count: 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_cc(env, original_wrapper.into()),
env.alignment_intvalue(element_layout),
layout_width(env, element_layout),
count.into(),
dec_element_fn.as_global_value().as_pointer_value().into(),
],
bitcode::LIST_TAKE_FIRST,
)
}
/// List.drop : List elem, Nat -> List elem
pub fn list_drop<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,