Add some comments and TODOs

This commit is contained in:
Brendan Hansknecht 2022-02-24 20:40:45 -08:00
parent ba2e8cd32b
commit 27b47713aa
2 changed files with 12 additions and 1 deletions

View file

@ -1301,6 +1301,10 @@ inline fn listReplaceInPlaceHelp(
element: Opaque, element: Opaque,
element_width: usize, element_width: usize,
) ?[*]u8 { ) ?[*]u8 {
// TODO: figure out how to return an element and a List.
// We only know the elment size at runtime.
// This code is currently the same as listSet.
// the element we will replace // the element we will replace
var element_at_index = (bytes orelse undefined) + (index * element_width); var element_at_index = (bytes orelse undefined) + (index * element_width);
@ -1321,6 +1325,10 @@ inline fn listReplaceImmutable(
element: Opaque, element: Opaque,
element_width: usize, element_width: usize,
) ?[*]u8 { ) ?[*]u8 {
// TODO: figure out how to return an element and a List.
// We only know the elment size at runtime.
// This code is currently the same as listSet.
const data_bytes = length * element_width; const data_bytes = length * element_width;
var new_bytes = utils.allocateWithRefcount(data_bytes, alignment); var new_bytes = utils.allocateWithRefcount(data_bytes, alignment);

View file

@ -294,19 +294,22 @@ pub fn list_drop_at<'a, 'ctx, 'env>(
/// List.replace : List elem, Nat, elem -> List elem /// List.replace : List elem, Nat, elem -> List elem
pub fn list_replace<'a, 'ctx, 'env>( pub fn list_replace<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>, _layout_ids: &mut LayoutIds<'a>,
list: BasicValueEnum<'ctx>, list: BasicValueEnum<'ctx>,
index: IntValue<'ctx>, index: IntValue<'ctx>,
element: BasicValueEnum<'ctx>, element: BasicValueEnum<'ctx>,
element_layout: &Layout<'a>, element_layout: &Layout<'a>,
update_mode: UpdateMode, update_mode: UpdateMode,
) -> BasicValueEnum<'ctx> { ) -> BasicValueEnum<'ctx> {
// TODO: This or elsewhere needs to deal with building the record that gets returned.
let (length, bytes) = load_list( let (length, bytes) = load_list(
env.builder, env.builder,
list.into_struct_value(), list.into_struct_value(),
env.context.i8_type().ptr_type(AddressSpace::Generic), env.context.i8_type().ptr_type(AddressSpace::Generic),
); );
// Assume the bounds have already been checked earlier
// (e.g. by List.replace or List.set, which wrap List.#replaceUnsafe)
let new_bytes = match update_mode { let new_bytes = match update_mode {
UpdateMode::InPlace => call_bitcode_fn( UpdateMode::InPlace => call_bitcode_fn(
env, env,