From 37d3a1e152707d2da587440c4cea8601b9ef0fd2 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sun, 27 Sep 2026 13:14:38 +0100 Subject: Lay Pure out as a core with the parts selected around it The app model, the tree store and the HTTP host lived in prototypes/connections among the earlier document runtime, the store was known only by its format's name, and Vega compiled six Pure sources by path. Now, as the README's principle has it: core/ runtime, flow and the app model (module*.c), with what the core asks of storage (state.h, store.h) store/ the tree store (PURETRE3, PUREREC1) serve/ pure-serve: HTTP host, outbound delivery, JSON in place cli/ pure-run, pure-edit-module A top-level make builds libpure.a (app model and store, for hosts to link) and the hosts; make check runs the store's and the app model's tests. The earlier runtime still builds from prototypes/connections against core/ and store/ (check, check-tree and check-core pass). Design 009 records the rule: parts by role behind libraries; git repositories split by coupling, so the store stays here while its contract moves with the core, and Vega stays apart. --- core/module-list.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 core/module-list.h (limited to 'core/module-list.h') diff --git a/core/module-list.h b/core/module-list.h new file mode 100644 index 0000000..a721ff0 --- /dev/null +++ b/core/module-list.h @@ -0,0 +1,74 @@ +#ifndef PURE_MODULE_LIST_H +#define PURE_MODULE_LIST_H +#include "result.h" +#include "state.h" +#include +#include +#include + +/* Executor paths that run once per module or app (loading, verifying, + * starting, replacing, reading stored states) are built for size; events + * stay built for speed. */ +#if defined(__GNUC__) || defined(__clang__) +#define PURE_COLD __attribute__((cold)) +#else +#define PURE_COLD +#endif + +/* Runtime-owned lists of records for the module executor. An item is one + * cell per field: a number, or text bytes the list owns. Every change made + * during an event is logged; a failed event undoes the log in reverse and a + * successful one frees what it replaced. */ +typedef struct { double num; unsigned char *text; size_t size; } PureCell; +typedef struct PureList PureList; +typedef struct { void *entries; size_t count, capacity; } PureUndo; +/* Items a list let go while a shared copy may still read them. */ +typedef struct { void *entries; size_t count, capacity; } PureRetired; + +enum { PURE_LIST_ITEMS = 65536 }; + +PureList *pure_list_new(unsigned fields, const uint8_t *text_fields); +void pure_list_free(PureList *); +size_t pure_list_count(const PureList *); +/* Share the items as they are with a read-only copy (for readers on other + * threads), without copying them: from then on the list copies an item it + * changes, and items it lets go go to retired instead of being freed, since + * the copy may still read them. The copy is freed with pure_list_free, on any + * thread, when its last reference goes (pure_list_hold takes one more). Only + * between events (no change waits to be committed or undone). */ +PureList *pure_list_share(PureList *, PureRetired *retired); +void pure_list_hold(PureList *copy); +/* Whether copy shares list's items as they are now. */ +bool pure_list_current(const PureList *copy, const PureList *list); +/* Free items retired while no copy that shared them remains. */ +void pure_retired_free(PureRetired *); +/* Insert a copy of cells (text bytes are copied) before position at. A NULL + * log means the change is not undone. */ +PureResult pure_list_insert(PureList *, size_t at, const PureCell *cells, PureUndo *); +PureResult pure_list_remove(PureList *, size_t at, PureUndo *); +PureResult pure_list_set(PureList *, size_t at, unsigned field, PureCell value, PureUndo *); +PureCell pure_list_get(const PureList *, size_t at, unsigned field); +/* In a list ordered by field (a keyed list): the first position whose item's + * field does not order below key (numbers by value, texts by bytes), and + * whether that item's field is key. */ +size_t pure_list_seek(const PureList *, unsigned field, PureCell key, bool *found); +/* The list's items ordered by field, as a keyed list keeps them: *out is NULL + * when they already are, or a new list in that order with moved[position + * before] = position after for every item. CONFLICT when two items have the + * same key (nothing is made). */ +PureResult pure_list_sorted(const PureList *, unsigned field, PureList **out, size_t *moved); +/* A list may keep a stored copy in a draft: header bytes, then each item's + * fields in order (a number as its binary64 bits, little-endian; a text as a + * u32le length and its bytes). Every change splices the draft as well, and a + * change the draft refuses (such as its size limit) does not happen. Undoing + * an event changes only the list: the caller restores the draft's version. */ +void pure_list_mirror(PureList *, PureDraft *, size_t header); +/* Store every item after the header (the draft holds just the header). */ +PureResult pure_list_write(PureList *); +/* Append the items stored in bytes; each field is checked. Before mirroring. */ +PureResult pure_list_read(PureList *, const unsigned char *bytes, size_t size); +/* Undo the changes logged after mark (a count taken earlier), newest first. */ +void pure_undo_rollback(PureUndo *, size_t mark); +void pure_undo_commit(PureUndo *); +void pure_undo_free(PureUndo *); +#endif -- cgit v1.2.3