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:
@@ -3,6 +3,7 @@
|
||||
#include <kiwi/kiwi.h>
|
||||
|
||||
#include <climits>
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
@@ -373,4 +374,31 @@ char* kiwi_solver_dumps(const KiwiSolver* s) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
void kiwi_tuple_init(KiwiTuple* tuple, int count, ...) {
|
||||
if (lk_unlikely(!tuple))
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
auto* var = va_arg(args, KiwiVar*);
|
||||
retain_unmanaged(var);
|
||||
tuple->values[i] = &var->m_value;
|
||||
}
|
||||
tuple->count = count;
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void kiwi_tuple_destroy(KiwiTuple* tuple) {
|
||||
if (lk_unlikely(!tuple))
|
||||
return;
|
||||
|
||||
for (int i = 0; i < tuple->count; ++i) {
|
||||
auto* value = const_cast<double*>(tuple->values[i]);
|
||||
release_unmanaged(
|
||||
reinterpret_cast<KiwiVar*>(reinterpret_cast<char*>(value) - offsetof(KiwiVar, m_value))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -61,7 +61,7 @@ typedef struct KiwiExpression {
|
||||
#if defined(LJKIWI_LUAJIT_DEF)
|
||||
KiwiTerm terms_[?];
|
||||
#elif defined(LJKIWI_USE_FAM_1)
|
||||
KiwiTerm terms_[1]; // LuaJIT: struct KiwiTerm terms_[?];
|
||||
KiwiTerm terms_[1];
|
||||
#else
|
||||
KiwiTerm terms_[];
|
||||
#endif
|
||||
@@ -74,8 +74,22 @@ typedef struct KiwiErr {
|
||||
bool must_free;
|
||||
} KiwiErr;
|
||||
|
||||
typedef struct KiwiTuple {
|
||||
int count;
|
||||
#if defined(LJKIWI_LUAJIT_DEF)
|
||||
const double* values[?];
|
||||
#elif defined(LJKIWI_USE_FAM_1)
|
||||
const double* values[1];
|
||||
#else
|
||||
const double* values[];
|
||||
#endif
|
||||
} KiwiTuple;
|
||||
|
||||
struct KiwiSolver;
|
||||
|
||||
LJKIWI_EXP void kiwi_tuple_init(KiwiTuple* tuple, int count, ...);
|
||||
LJKIWI_EXP void kiwi_tuple_destroy(KiwiTuple* tuple);
|
||||
|
||||
LJKIWI_EXP KiwiVar* kiwi_var_construct(const char* name);
|
||||
LJKIWI_EXP void kiwi_var_release(KiwiVar* var);
|
||||
LJKIWI_EXP void kiwi_var_retain(KiwiVar* var);
|
||||
|
||||
Reference in New Issue
Block a user