mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
make Dict.keys and Dict.values use list helpers for returning
This commit is contained in:
parent
de77748dd5
commit
85bf881b3b
2 changed files with 37 additions and 41 deletions
|
@ -408,7 +408,19 @@ const Dec = fn (?[*]u8) callconv(.C) void;
|
||||||
const Caller3 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
const Caller3 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
||||||
|
|
||||||
// Dict.insert : Dict k v, k, v -> Dict k v
|
// Dict.insert : Dict k v, k, v -> Dict k v
|
||||||
pub fn dictInsert(input: RocDict, alignment: Alignment, key: Opaque, key_width: usize, value: Opaque, value_width: usize, hash_fn: HashFn, is_eq: EqFn, dec_key: Dec, dec_value: Dec, output: *RocDict) callconv(.C) void {
|
pub fn dictInsert(
|
||||||
|
input: RocDict,
|
||||||
|
alignment: Alignment,
|
||||||
|
key: Opaque,
|
||||||
|
key_width: usize,
|
||||||
|
value: Opaque,
|
||||||
|
value_width: usize,
|
||||||
|
hash_fn: HashFn,
|
||||||
|
is_eq: EqFn,
|
||||||
|
dec_key: Dec,
|
||||||
|
dec_value: Dec,
|
||||||
|
output: *RocDict,
|
||||||
|
) callconv(.C) void {
|
||||||
var seed: u64 = INITIAL_SEED;
|
var seed: u64 = INITIAL_SEED;
|
||||||
|
|
||||||
var result = input.makeUnique(alignment, key_width, value_width);
|
var result = input.makeUnique(alignment, key_width, value_width);
|
||||||
|
@ -543,7 +555,13 @@ pub fn elementsRc(dict: RocDict, alignment: Alignment, key_width: usize, value_w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dictKeys(dict: RocDict, alignment: Alignment, key_width: usize, value_width: usize, inc_key: Inc, output: *RocList) callconv(.C) void {
|
pub fn dictKeys(
|
||||||
|
dict: RocDict,
|
||||||
|
alignment: Alignment,
|
||||||
|
key_width: usize,
|
||||||
|
value_width: usize,
|
||||||
|
inc_key: Inc,
|
||||||
|
) callconv(.C) RocList {
|
||||||
const size = dict.capacity();
|
const size = dict.capacity();
|
||||||
|
|
||||||
var length: usize = 0;
|
var length: usize = 0;
|
||||||
|
@ -558,8 +576,7 @@ pub fn dictKeys(dict: RocDict, alignment: Alignment, key_width: usize, value_wid
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
output.* = RocList.empty();
|
return RocList.empty();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data_bytes = length * key_width;
|
const data_bytes = length * key_width;
|
||||||
|
@ -581,10 +598,16 @@ pub fn dictKeys(dict: RocDict, alignment: Alignment, key_width: usize, value_wid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output.* = RocList{ .bytes = ptr, .length = length };
|
return RocList{ .bytes = ptr, .length = length };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dictValues(dict: RocDict, alignment: Alignment, key_width: usize, value_width: usize, inc_value: Inc, output: *RocList) callconv(.C) void {
|
pub fn dictValues(
|
||||||
|
dict: RocDict,
|
||||||
|
alignment: Alignment,
|
||||||
|
key_width: usize,
|
||||||
|
value_width: usize,
|
||||||
|
inc_value: Inc,
|
||||||
|
) callconv(.C) RocList {
|
||||||
const size = dict.capacity();
|
const size = dict.capacity();
|
||||||
|
|
||||||
var length: usize = 0;
|
var length: usize = 0;
|
||||||
|
@ -599,8 +622,7 @@ pub fn dictValues(dict: RocDict, alignment: Alignment, key_width: usize, value_w
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
output.* = RocList.empty();
|
return RocList.empty();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data_bytes = length * value_width;
|
const data_bytes = length * value_width;
|
||||||
|
@ -622,7 +644,7 @@ pub fn dictValues(dict: RocDict, alignment: Alignment, key_width: usize, value_w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output.* = RocList{ .bytes = ptr, .length = length };
|
return RocList{ .bytes = ptr, .length = length };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doNothing(_: Opaque) callconv(.C) void {
|
fn doNothing(_: Opaque) callconv(.C) void {
|
||||||
|
|
|
@ -19,6 +19,8 @@ use roc_module::symbol::Symbol;
|
||||||
use roc_mono::layout::{Builtin, Layout, LayoutIds};
|
use roc_mono::layout::{Builtin, Layout, LayoutIds};
|
||||||
use roc_target::TargetInfo;
|
use roc_target::TargetInfo;
|
||||||
|
|
||||||
|
use super::bitcode::call_list_bitcode_fn;
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
struct Alignment(u8);
|
struct Alignment(u8);
|
||||||
|
|
||||||
|
@ -429,9 +431,7 @@ pub fn dict_keys<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
let inc_key_fn = build_inc_wrapper(env, layout_ids, key_layout);
|
let inc_key_fn = build_inc_wrapper(env, layout_ids, key_layout);
|
||||||
|
|
||||||
let list_ptr = builder.build_alloca(zig_list_type(env), "list_ptr");
|
call_list_bitcode_fn(
|
||||||
|
|
||||||
call_void_bitcode_fn(
|
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
pass_dict_c_abi(env, dict),
|
pass_dict_c_abi(env, dict),
|
||||||
|
@ -439,21 +439,9 @@ pub fn dict_keys<'a, 'ctx, 'env>(
|
||||||
key_width.into(),
|
key_width.into(),
|
||||||
value_width.into(),
|
value_width.into(),
|
||||||
inc_key_fn.as_global_value().as_pointer_value().into(),
|
inc_key_fn.as_global_value().as_pointer_value().into(),
|
||||||
list_ptr.into(),
|
|
||||||
],
|
],
|
||||||
bitcode::DICT_KEYS,
|
bitcode::DICT_KEYS,
|
||||||
);
|
)
|
||||||
|
|
||||||
let list_ptr = env
|
|
||||||
.builder
|
|
||||||
.build_bitcast(
|
|
||||||
list_ptr,
|
|
||||||
super::convert::zig_list_type(env).ptr_type(AddressSpace::Generic),
|
|
||||||
"to_roc_list",
|
|
||||||
)
|
|
||||||
.into_pointer_value();
|
|
||||||
|
|
||||||
env.builder.build_load(list_ptr, "load_keys_list")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pass_dict_c_abi<'a, 'ctx, 'env>(
|
fn pass_dict_c_abi<'a, 'ctx, 'env>(
|
||||||
|
@ -687,9 +675,7 @@ pub fn dict_values<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
let inc_value_fn = build_inc_wrapper(env, layout_ids, value_layout);
|
let inc_value_fn = build_inc_wrapper(env, layout_ids, value_layout);
|
||||||
|
|
||||||
let list_ptr = builder.build_alloca(zig_list_type, "list_ptr");
|
call_list_bitcode_fn(
|
||||||
|
|
||||||
call_void_bitcode_fn(
|
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
pass_dict_c_abi(env, dict),
|
pass_dict_c_abi(env, dict),
|
||||||
|
@ -697,21 +683,9 @@ pub fn dict_values<'a, 'ctx, 'env>(
|
||||||
key_width.into(),
|
key_width.into(),
|
||||||
value_width.into(),
|
value_width.into(),
|
||||||
inc_value_fn.as_global_value().as_pointer_value().into(),
|
inc_value_fn.as_global_value().as_pointer_value().into(),
|
||||||
list_ptr.into(),
|
|
||||||
],
|
],
|
||||||
bitcode::DICT_VALUES,
|
bitcode::DICT_VALUES,
|
||||||
);
|
)
|
||||||
|
|
||||||
let list_ptr = env
|
|
||||||
.builder
|
|
||||||
.build_bitcast(
|
|
||||||
list_ptr,
|
|
||||||
super::convert::zig_list_type(env).ptr_type(AddressSpace::Generic),
|
|
||||||
"to_roc_list",
|
|
||||||
)
|
|
||||||
.into_pointer_value();
|
|
||||||
|
|
||||||
env.builder.build_load(list_ptr, "load_keys_list")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue