mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Merge branch 'trunk' into unique-builtins-implementations
This commit is contained in:
commit
cec3725941
@ -370,7 +370,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
),
|
||||
);
|
||||
|
||||
// get : List a, Int -> Result a [ IndexOutOfBounds ]*
|
||||
// get : List elem, Int -> Result elem [ IndexOutOfBounds ]*
|
||||
let index_out_of_bounds = SolvedType::TagUnion(
|
||||
vec![(TagName::Global("IndexOutOfBounds".into()), vec![])],
|
||||
Box::new(SolvedType::Wildcard),
|
||||
@ -392,7 +392,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
),
|
||||
);
|
||||
|
||||
// set : List a, Int, a -> List a
|
||||
// set : List elem, Int, elem -> List elem
|
||||
add_type(
|
||||
Symbol::LIST_SET,
|
||||
SolvedType::Func(
|
||||
@ -401,7 +401,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
),
|
||||
);
|
||||
|
||||
// map : List a, (a -> b) -> List b
|
||||
// map : List before, (before -> after) -> List after
|
||||
add_type(
|
||||
Symbol::LIST_MAP,
|
||||
SolvedType::Func(
|
||||
|
@ -604,6 +604,29 @@ fn call_with_args<'a, B: Backend>(
|
||||
Offset32::new(0),
|
||||
)
|
||||
}
|
||||
Symbol::LIST_SET => {
|
||||
// set : List elem, Int, elem -> List elem
|
||||
debug_assert!(args.len() == 3);
|
||||
|
||||
let list_ptr = args[0];
|
||||
let elem_index = args[1];
|
||||
let elem = args[2];
|
||||
|
||||
let elem_bytes = 8; // TODO Look this up instead of hardcoding it!
|
||||
let elem_size = builder.ins().iconst(types::I64, elem_bytes);
|
||||
|
||||
// Multiply the requested index by the size of each element.
|
||||
let offset = builder.ins().imul(elem_index, elem_size);
|
||||
|
||||
builder.ins().store_complex(
|
||||
MemFlags::new(),
|
||||
elem,
|
||||
&[list_ptr, offset],
|
||||
Offset32::new(0),
|
||||
);
|
||||
|
||||
list_ptr
|
||||
}
|
||||
_ => {
|
||||
let fn_id = match scope.get(&symbol) {
|
||||
Some(ScopeEntry::Func{ func_id, .. }) => *func_id,
|
||||
|
@ -604,6 +604,24 @@ fn call_with_args<'a, 'ctx, 'env>(
|
||||
|
||||
builder.build_load(elem_ptr, "List.get")
|
||||
}
|
||||
Symbol::LIST_SET => {
|
||||
debug_assert!(args.len() == 3);
|
||||
|
||||
let list_ptr = args[0].into_pointer_value();
|
||||
let elem_index = args[1].into_int_value();
|
||||
let elem = args[2];
|
||||
|
||||
let builder = env.builder;
|
||||
let elem_bytes = 8; // TODO Look this up instead of hardcoding it!
|
||||
let elem_size = env.context.i64_type().const_int(elem_bytes, false);
|
||||
let offset = builder.build_int_mul(elem_index, elem_size, "MUL_OFFSET");
|
||||
|
||||
let elem_ptr = unsafe { builder.build_gep(list_ptr, &[offset], "elem") };
|
||||
|
||||
builder.build_store(elem_ptr, elem);
|
||||
|
||||
list_ptr.into()
|
||||
}
|
||||
_ => {
|
||||
let fn_val = env
|
||||
.module
|
||||
|
@ -351,6 +351,11 @@ mod test_gen {
|
||||
assert_evals_to!("List.getUnsafe [ 12, 9, 6, 3 ] 1", 9, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_int_list() {
|
||||
assert_evals_to!("List.getUnsafe (List.set [ 12, 9, 7, 3 ] 1 42) 1", 42, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn branch_first_float() {
|
||||
assert_evals_to!(
|
||||
|
Loading…
Reference in New Issue
Block a user