move bitcode support functions around

This commit is contained in:
Folkert 2021-02-17 21:52:19 +01:00
parent 619749c954
commit a3d0dc2fc3
9 changed files with 341 additions and 322 deletions

View file

@ -4,6 +4,7 @@ const RocResult = utils.RocResult;
const mem = std.mem;
const Allocator = mem.Allocator;
const EqFn = fn (?[*]u8, ?[*]u8) callconv(.C) bool;
const Opaque = ?[*]u8;
pub const RocList = extern struct {
@ -242,3 +243,19 @@ pub fn listWalkBackwards(list: RocList, stepper: Opaque, stepper_caller: Caller2
utils.decref(std.heap.c_allocator, alignment, list.bytes, data_bytes);
}
}
// List.contains : List k, k -> Bool
pub fn listContains(list: RocList, key: Opaque, key_width: usize, is_eq: EqFn) callconv(.C) bool {
if (list.bytes) |source_ptr| {
const size = list.len();
var i: usize = 0;
while (i < size) : (i += 1) {
const element = source_ptr + i * key_width;
if (is_eq(element, key)) {
return true;
}
}
}
return false;
}

View file

@ -12,6 +12,7 @@ comptime {
exportListFn(list.listWalkBackwards, "walk_backwards");
exportListFn(list.listKeepOks, "keep_oks");
exportListFn(list.listKeepErrs, "keep_errs");
exportListFn(list.listContains, "contains");
}
// Dict Module