mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 00:09:33 +03:00
LIST_REVERSE works, so long as the list is made up of ints equal to 1
This commit is contained in:
parent
d8a8741aed
commit
7bd7e697b0
@ -522,6 +522,15 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
),
|
||||
);
|
||||
|
||||
// reverse : List elem -> List elem
|
||||
add_type(
|
||||
Symbol::LIST_REVERSE,
|
||||
SolvedType::Func(
|
||||
vec![list_type(flex(TVAR1))],
|
||||
Box::new(list_type(flex(TVAR1))),
|
||||
),
|
||||
);
|
||||
|
||||
// len : List * -> Int
|
||||
add_type(
|
||||
Symbol::LIST_LEN,
|
||||
|
@ -630,6 +630,28 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
)
|
||||
});
|
||||
|
||||
// reverse : Attr * (List (Attr * a)) -> Attr * (List (Attr * a))
|
||||
add_type(Symbol::LIST_REVERSE, {
|
||||
let_tvars! { a, star1, star2 };
|
||||
|
||||
unique_function(
|
||||
vec![SolvedType::Apply(
|
||||
Symbol::ATTR_ATTR,
|
||||
vec![
|
||||
flex(star1),
|
||||
SolvedType::Apply(Symbol::LIST_LIST, vec![flex(a)]),
|
||||
],
|
||||
)],
|
||||
SolvedType::Apply(
|
||||
Symbol::ATTR_ATTR,
|
||||
vec![
|
||||
boolean(star2),
|
||||
SolvedType::Apply(Symbol::LIST_LIST, vec![flex(a)]),
|
||||
],
|
||||
),
|
||||
)
|
||||
});
|
||||
|
||||
// push : Attr * (List a)
|
||||
// , a
|
||||
// -> Attr * (List a)
|
||||
|
@ -1610,18 +1610,18 @@ fn call_with_args<'a, 'ctx, 'env>(
|
||||
// dont need to allocate memory for the index or the check
|
||||
// if list_len == 0
|
||||
let comparison = builder.build_int_compare(
|
||||
IntPredicate::EQ,
|
||||
IntPredicate::NE,
|
||||
list_len,
|
||||
ctx.i64_type().const_int(0, false),
|
||||
"atleastzero",
|
||||
);
|
||||
|
||||
let build_then = || {
|
||||
// Allocate space for the new array that we'll copy into.
|
||||
let elem_bytes = elem_layout.stack_size(env.ptr_bytes) as u64;
|
||||
|
||||
match list_layout {
|
||||
Layout::Builtin(Builtin::List(elem_layout)) => {
|
||||
// Allocate space for the new array that we'll copy into.
|
||||
let elem_bytes = elem_layout.stack_size(env.ptr_bytes) as u64;
|
||||
|
||||
let list_ptr = {
|
||||
let len_type = env.ptr_int();
|
||||
let len = len_type.const_int(elem_bytes, false);
|
||||
@ -1663,7 +1663,7 @@ fn call_with_args<'a, 'ctx, 'env>(
|
||||
|
||||
// Mutate the new array in-place to change the element.
|
||||
// builder.build_store(elem_ptr, builder.build_load(elem_ptr, "List.get"));
|
||||
builder.build_store(elem_ptr, curr_index);
|
||||
builder.build_store(elem_ptr, ctx.i64_type().const_int(1, false));
|
||||
|
||||
// #index != 0
|
||||
let end_cond = builder.build_int_compare(
|
||||
|
@ -512,10 +512,14 @@ mod gen_builtins {
|
||||
assert_evals_to!("List.repeat 5 1", &[1, 1, 1, 1, 1], &'static [i64]);
|
||||
assert_evals_to!("List.repeat 4 2", &[2, 2, 2, 2], &'static [i64]);
|
||||
|
||||
assert_evals_to!("List.repeat 0 []", &[], &'static [i64]);
|
||||
assert_evals_to!("List.repeat 2 []", &[&[], &[]], &'static [&'static [i64]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_reverse() {
|
||||
assert_evals_to!("List.reverse [1, 2, 3]", &[3, 2, 1], &'static [i64]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_list_len() {
|
||||
with_larger_debug_stack(|| {
|
||||
|
Loading…
Reference in New Issue
Block a user