mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
feat(bitcode/list): implement listReverse
This commit is contained in:
parent
1459679faf
commit
17b39fa1ce
3 changed files with 27 additions and 0 deletions
|
@ -118,6 +118,31 @@ const Caller1 = fn (?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
|||
const Caller2 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
||||
const Caller3 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
||||
|
||||
pub fn listReverse(list: RocList, alignment: usize, element_width: usize) callconv(.C) RocList {
|
||||
if (list.bytes) |source_ptr| {
|
||||
const size = list.len();
|
||||
|
||||
var i: usize = 0;
|
||||
var end: usize = size - 1;
|
||||
|
||||
const output = RocList.allocate(std.heap.c_allocator, alignment, size, element_width);
|
||||
|
||||
const target_ptr = output.bytes orelse unreachable;
|
||||
|
||||
while (i < size) : (i += 1) {
|
||||
const source_position = end - i;
|
||||
|
||||
@memcpy(target_ptr + (i * element_width), source_ptr + (source_position * element_width), element_width);
|
||||
}
|
||||
|
||||
utils.decref(std.heap.c_allocator, alignment, list.bytes, size * element_width);
|
||||
|
||||
return output;
|
||||
} else {
|
||||
return RocList.empty();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listMap(list: RocList, transform: Opaque, caller: Caller1, alignment: usize, old_element_width: usize, new_element_width: usize) callconv(.C) RocList {
|
||||
if (list.bytes) |source_ptr| {
|
||||
const size = list.len();
|
||||
|
|
|
@ -20,6 +20,7 @@ comptime {
|
|||
exportListFn(list.listRepeat, "repeat");
|
||||
exportListFn(list.listAppend, "append");
|
||||
exportListFn(list.listRange, "range");
|
||||
exportListFn(list.listReverse, "reverse");
|
||||
}
|
||||
|
||||
// Dict Module
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue