Merge branch 'trunk' into deps

This commit is contained in:
Richard Feldman 2021-11-06 07:19:02 -04:00 committed by GitHub
commit 3df3e2f0d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 0 deletions

View file

@ -47,3 +47,4 @@ Joshua Warner <joshuawarner32@gmail.com>
Luiz Carlos L. G. de Oliveira <luizcarlos1405@gmail.com> Luiz Carlos L. G. de Oliveira <luizcarlos1405@gmail.com>
Oleksii Skidan <al.skidan@gmail.com> Oleksii Skidan <al.skidan@gmail.com>
Martin Janiczek <martin@janiczek.cz> Martin Janiczek <martin@janiczek.cz>
Eric Newbury <enewbury@users.noreply.github.com>

View file

@ -979,6 +979,13 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
Box::new(list_type(flex(TVAR1))), Box::new(list_type(flex(TVAR1))),
); );
// dropFirst : List elem -> List elem
add_top_level_function_type!(
Symbol::LIST_DROP_FIRST,
vec![list_type(flex(TVAR1))],
Box::new(list_type(flex(TVAR1))),
);
// swap : List elem, Nat, Nat -> List elem // swap : List elem, Nat, Nat -> List elem
add_top_level_function_type!( add_top_level_function_type!(
Symbol::LIST_SWAP, Symbol::LIST_SWAP,

View file

@ -92,6 +92,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
LIST_MAP4 => list_map4, LIST_MAP4 => list_map4,
LIST_DROP => list_drop, LIST_DROP => list_drop,
LIST_DROP_AT => list_drop_at, LIST_DROP_AT => list_drop_at,
LIST_DROP_FIRST => list_drop_first,
LIST_DROP_LAST => list_drop_last, LIST_DROP_LAST => list_drop_last,
LIST_SWAP => list_swap, LIST_SWAP => list_swap,
LIST_MAP_WITH_INDEX => list_map_with_index, LIST_MAP_WITH_INDEX => list_map_with_index,
@ -2049,6 +2050,30 @@ fn list_drop_at(symbol: Symbol, var_store: &mut VarStore) -> Def {
) )
} }
fn list_drop_first(symbol: Symbol, var_store: &mut VarStore) -> Def {
let list_var = var_store.fresh();
let index_var = var_store.fresh();
let num_var = Variable::NAT;
let num_precision_var = Variable::NATURAL;
let body = RunLowLevel {
op: LowLevel::ListDropAt,
args: vec![
(list_var, Var(Symbol::ARG_1)),
(index_var, int(num_var, num_precision_var, 0)),
],
ret_var: list_var,
};
defn(
symbol,
vec![(list_var, Symbol::ARG_1)],
var_store,
body,
list_var,
)
}
/// List.dropLast: List elem -> List elem /// List.dropLast: List elem -> List elem
fn list_drop_last(symbol: Symbol, var_store: &mut VarStore) -> Def { fn list_drop_last(symbol: Symbol, var_store: &mut VarStore) -> Def {
let list_var = var_store.fresh(); let list_var = var_store.fresh();

View file

@ -1061,6 +1061,7 @@ define_builtins! {
38 LIST_MAX: "max" 38 LIST_MAX: "max"
39 LIST_MAX_GT: "#maxGt" 39 LIST_MAX_GT: "#maxGt"
40 LIST_MAP4: "map4" 40 LIST_MAP4: "map4"
41 LIST_DROP_FIRST: "dropFirst"
} }
5 RESULT: "Result" => { 5 RESULT: "Result" => {
0 RESULT_RESULT: "Result" imported // the Result.Result type alias 0 RESULT_RESULT: "Result" imported // the Result.Result type alias

View file

@ -267,6 +267,17 @@ fn list_drop_last_mutable() {
); );
} }
#[test]
fn list_drop_first() {
assert_evals_to!(
"List.dropFirst [1, 2, 3]",
RocList::from_slice(&[2, 3]),
RocList<i64>
);
assert_evals_to!("List.dropFirst []", RocList::from_slice(&[]), RocList<i64>);
assert_evals_to!("List.dropFirst [0]", RocList::from_slice(&[]), RocList<i64>);
}
#[test] #[test]
fn list_swap() { 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>);