use morphic update mode

This commit is contained in:
Folkert 2021-06-22 20:53:55 +02:00
parent 059cac3b98
commit 27308e98b7
5 changed files with 73 additions and 20 deletions

View file

@ -13,6 +13,7 @@ use inkwell::context::Context;
use inkwell::types::{BasicType, BasicTypeEnum, PointerType};
use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, StructValue};
use inkwell::{AddressSpace, IntPredicate};
use morphic_lib::UpdateMode;
use roc_builtins::bitcode;
use roc_mono::layout::{Builtin, Layout, LayoutIds};
@ -350,6 +351,7 @@ pub fn list_set<'a, 'ctx, 'env>(
index: IntValue<'ctx>,
element: BasicValueEnum<'ctx>,
element_layout: &'a Layout<'a>,
update_mode: UpdateMode,
) -> BasicValueEnum<'ctx> {
let dec_element_fn = build_dec_wrapper(env, layout_ids, element_layout);
@ -359,6 +361,11 @@ pub fn list_set<'a, 'ctx, 'env>(
env.context.i8_type().ptr_type(AddressSpace::Generic),
);
let symbol = match update_mode {
UpdateMode::InPlace => bitcode::LIST_SET_IN_PLACE,
UpdateMode::Immutable => bitcode::LIST_SET,
};
let new_bytes = call_bitcode_fn(
env,
&[
@ -370,7 +377,7 @@ pub fn list_set<'a, 'ctx, 'env>(
layout_width(env, element_layout),
dec_element_fn.as_global_value().as_pointer_value().into(),
],
&bitcode::LIST_SET,
&symbol,
);
store_list(env, new_bytes.into_pointer_value(), length)