Merge remote-tracking branch 'origin/trunk' into update_zig_09

This commit is contained in:
Folkert 2022-02-18 22:39:44 +01:00
commit 6631845a3c
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
60 changed files with 1597 additions and 1032 deletions

View file

@ -5014,7 +5014,7 @@ fn run_higher_order_low_level<'a, 'ctx, 'env>(
}
}
ListMapWithIndex { xs } => {
// List.mapWithIndex : List before, (Nat, before -> after) -> List after
// List.mapWithIndex : List before, (before, Nat -> after) -> List after
let (list, list_layout) = load_symbol_and_layout(scope, xs);
let (function, closure, closure_layout) = function_details!();
@ -5024,7 +5024,7 @@ fn run_higher_order_low_level<'a, 'ctx, 'env>(
Layout::Builtin(Builtin::List(element_layout)),
Layout::Builtin(Builtin::List(result_layout)),
) => {
let argument_layouts = &[Layout::usize(env.target_info), **element_layout];
let argument_layouts = &[**element_layout, Layout::usize(env.target_info)];
let roc_function_call = roc_function_call(
env,
@ -5484,13 +5484,13 @@ fn run_low_level<'a, 'ctx, 'env>(
list_single(env, arg, arg_layout)
}
ListRepeat => {
// List.repeat : Int, elem -> List elem
// List.repeat : elem, Nat -> List elem
debug_assert_eq!(args.len(), 2);
let list_len = load_symbol(scope, &args[0]).into_int_value();
let (elem, elem_layout) = load_symbol_and_layout(scope, &args[1]);
let (elem, elem_layout) = load_symbol_and_layout(scope, &args[0]);
let list_len = load_symbol(scope, &args[1]).into_int_value();
list_repeat(env, layout_ids, list_len, elem, elem_layout)
list_repeat(env, layout_ids, elem, elem_layout, list_len)
}
ListReverse => {
// List.reverse : List elem -> List elem
@ -5692,7 +5692,7 @@ fn run_low_level<'a, 'ctx, 'env>(
match arg_builtin {
Int(int_width) => {
let int_type = convert::int_type_from_int_width(env, *int_width);
build_int_unary_op(env, arg.into_int_value(), int_type, op)
build_int_unary_op(env, arg.into_int_value(), int_type, op, layout)
}
Float(float_width) => build_float_unary_op(
env,
@ -6924,6 +6924,7 @@ fn build_int_unary_op<'a, 'ctx, 'env>(
arg: IntValue<'ctx>,
int_type: IntType<'ctx>,
op: LowLevel,
return_layout: &Layout<'a>,
) -> BasicValueEnum<'ctx> {
use roc_module::low_level::LowLevel::*;
@ -6939,12 +6940,19 @@ fn build_int_unary_op<'a, 'ctx, 'env>(
int_abs_raise_on_overflow(env, arg, int_type)
}
NumToFloat => {
// TODO: Handle different sized numbers
// This is an Int, so we need to convert it.
let target_float_type = match return_layout {
Layout::Builtin(Builtin::Float(float_width)) => {
convert::float_type_from_float_width(env, *float_width)
}
_ => internal_error!("There can only be floats here!"),
};
bd.build_cast(
InstructionOpcode::SIToFP,
arg,
env.context.f64_type(),
target_float_type,
"i64_to_f64",
)
}

View file

@ -119,13 +119,13 @@ pub fn list_single<'a, 'ctx, 'env>(
)
}
/// List.repeat : Int, elem -> List elem
/// List.repeat : elem, Nat -> List elem
pub fn list_repeat<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
list_len: IntValue<'ctx>,
element: BasicValueEnum<'ctx>,
element_layout: &Layout<'a>,
list_len: IntValue<'ctx>,
) -> BasicValueEnum<'ctx> {
let inc_element_fn = build_inc_n_wrapper(env, layout_ids, element_layout);
@ -687,7 +687,7 @@ pub fn list_sort_with<'a, 'ctx, 'env>(
)
}
/// List.mapWithIndex : List before, (Nat, before -> after) -> List after
/// List.mapWithIndex : List before, (before, Nat -> after) -> List after
pub fn list_map_with_index<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
roc_function_call: RocFunctionCall<'ctx>,