This commit is contained in:
Folkert 2021-05-16 21:32:45 +02:00
parent 353e161f77
commit 4afd3cfce6
4 changed files with 22 additions and 17 deletions

View File

@ -11,6 +11,7 @@ const CompareFn = fn (?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) u8;
const Opaque = ?[*]u8;
const Inc = fn (?[*]u8) callconv(.C) void;
const IncN = fn (?[*]u8, usize) callconv(.C) void;
const Dec = fn (?[*]u8) callconv(.C) void;
pub const RocList = extern struct {
@ -615,7 +616,7 @@ pub fn listContains(list: RocList, key: Opaque, key_width: usize, is_eq: EqFn) c
return false;
}
pub fn listRepeat(count: usize, alignment: usize, element: Opaque, element_width: usize, inc_n_element: Inc) callconv(.C) RocList {
pub fn listRepeat(count: usize, alignment: usize, element: Opaque, element_width: usize, inc_n_element: IncN) callconv(.C) RocList {
if (count == 0) {
return RocList.empty();
}
@ -624,18 +625,15 @@ pub fn listRepeat(count: usize, alignment: usize, element: Opaque, element_width
var output = RocList.allocate(allocator, alignment, count, element_width);
if (output.bytes) |target_ptr| {
// increment the element's RC N times
inc_n_element(element, count);
var i: usize = 0;
const source = element orelse unreachable;
while (i < count) : (i += 1) {
@memcpy(target_ptr + i * element_width, source, element_width);
}
// TODO do all increments at once!
i = 0;
while (i < count) : (i += 1) {
inc_n_element(element);
}
return output;
} else {
unreachable;

View File

@ -218,7 +218,7 @@ pub fn build_inc_n_wrapper<'a, 'ctx, 'env>(
layout_ids: &mut LayoutIds<'a>,
layout: &Layout<'a>,
) -> FunctionValue<'ctx> {
build_rc_wrapper(env, layout_ids, layout, Mode::Inc)
build_rc_wrapper(env, layout_ids, layout, Mode::IncN)
}
/// a functin that accepts two arguments: the value to increment; increments by 1
@ -238,7 +238,7 @@ pub fn build_dec_wrapper<'a, 'ctx, 'env>(
build_rc_wrapper(env, layout_ids, layout, Mode::Dec)
}
pub fn build_rc_wrapper<'a, 'ctx, 'env>(
fn build_rc_wrapper<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
layout: &Layout<'a>,

View File

@ -397,9 +397,16 @@ pub fn dict_elements_rc<'a, 'ctx, 'env>(
let alignment = Alignment::from_key_value_layout(key_layout, value_layout, env.ptr_bytes);
let alignment_iv = env.context.i8_type().const_int(alignment as u64, false);
use crate::llvm::bitcode::build_rc_wrapper;
let inc_key_fn = build_rc_wrapper(env, layout_ids, key_layout, rc_operation);
let inc_value_fn = build_rc_wrapper(env, layout_ids, value_layout, rc_operation);
let (key_fn, value_fn) = match rc_operation {
Mode::Inc => (
build_inc_wrapper(env, layout_ids, key_layout),
build_inc_wrapper(env, layout_ids, value_layout),
),
Mode::Dec => (
build_dec_wrapper(env, layout_ids, key_layout),
build_dec_wrapper(env, layout_ids, value_layout),
),
};
call_void_bitcode_fn(
env,
@ -408,8 +415,8 @@ pub fn dict_elements_rc<'a, 'ctx, 'env>(
alignment_iv.into(),
key_width.into(),
value_width.into(),
inc_key_fn.as_global_value().as_pointer_value().into(),
inc_value_fn.as_global_value().as_pointer_value().into(),
key_fn.as_global_value().as_pointer_value().into(),
value_fn.as_global_value().as_pointer_value().into(),
],
&bitcode::DICT_ELEMENTS_RC,
);

View File

@ -1,7 +1,7 @@
#![allow(clippy::too_many_arguments)]
use crate::llvm::bitcode::{
build_compare_wrapper, build_dec_wrapper, build_eq_wrapper, build_inc_wrapper,
build_transform_caller, call_bitcode_fn, call_void_bitcode_fn,
build_compare_wrapper, build_dec_wrapper, build_eq_wrapper, build_inc_n_wrapper,
build_inc_wrapper, build_transform_caller, call_bitcode_fn, call_void_bitcode_fn,
};
use crate::llvm::build::{
allocate_with_refcount_help, cast_basic_basic, complex_bitcast, Env, InPlace,
@ -118,7 +118,7 @@ pub fn list_repeat<'a, 'ctx, 'env>(
element: BasicValueEnum<'ctx>,
element_layout: &Layout<'a>,
) -> BasicValueEnum<'ctx> {
let inc_element_fn = build_inc_wrapper(env, layout_ids, element_layout);
let inc_element_fn = build_inc_n_wrapper(env, layout_ids, element_layout);
call_bitcode_fn_returns_list(
env,