Initial implementation of tuple demonstration

This allows allocating a buffer of double pointers pointing to
the memory location in a bunch of variables. It is not particularly
ergonomic as is, and it seems unlikely the real world performance
benefit will exist.
This commit is contained in:
2024-02-27 21:59:10 -06:00
parent ef29b8abcb
commit 08e9bf08e7
4 changed files with 67 additions and 2 deletions

View File

@@ -64,8 +64,16 @@ typedef struct KiwiErr {
bool must_free;
} KiwiErr;
typedef struct KiwiTuple {
int count;
const double* values[?];
} KiwiTuple;
struct KiwiSolver;
void kiwi_tuple_init(KiwiTuple* tuple, int count, ...);
void kiwi_tuple_destroy(KiwiTuple* tuple);
KiwiVar* kiwi_var_construct(const char* name);
void kiwi_var_release(KiwiVar* var);
void kiwi_var_retain(KiwiVar* var);
@@ -196,6 +204,21 @@ function kiwi.is_constraint(o)
return ffi_istype(Constraint, o)
end
local Tuple = ffi.typeof("struct KiwiTuple") --[[@as kiwi.Tuple]]
kiwi.Tuple = Tuple
---@class kiwi.Tuple: ffi.cdata*
---@field values ffi.cdata*
---@field count integer
---@overload fun(vars: kiwi.Var[]): kiwi.Tuple
ffi.metatype(Tuple, {
__new = function(self, vars)
local t = ffi_new(self, #vars)
ljkiwi.kiwi_tuple_init(t, #vars, unpack(vars))
return ffi_gc(t, ljkiwi.kiwi_tuple_destroy)
end,
})
---@param expr kiwi.Expression
---@param var kiwi.Var
---@param coeff number?