aboutsummaryrefslogtreecommitdiffstats
path: root/core/module-list.h
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-30 16:16:08 +0100
committereunhhu <[email protected]>2026-09-30 16:16:08 +0100
commit46c303a41e9dd9cd0e6bd50511e8d7253a0ef438 (patch)
tree7564bf80ac43ff0964c64acd6a15f7299fa48997 /core/module-list.h
parente02bfc916743a0327d76144b32b6ec6381e5907f (diff)
downloadpure-46c303a41e9dd9cd0e6bd50511e8d7253a0ef438.tar.gz
pure-46c303a41e9dd9cd0e6bd50511e8d7253a0ef438.zip
Give i64 its own type in modules, lists, stores and the host (016 stage 2)
An i64 is an int64_t in a value's 8 bytes, its own stack type: CONST and NUM_TEXT take argument 2 for one, eleven opcodes are appended (ADD, SUB and MUL fail as overflow past its range, DIV and MOD floor and fail as divide by zero, NEG, COMPARE with a relation, MIN, MAX, and I64_FROM and NUM_FROM, which convert only where the value fits and else fail as limit), and moves (LOAD, STORE, locals, items, FIELD, SEND) copy it as they copy a number. Type codes: state 6, record field 3, message field 7 (8 bytes), view 4, local 3. v6 stays: all of it is added. - Folds with PURE_FOLD_INTEGER sum (overflow fails), keep the most or least of, or count the different i64s; distinct's set keeps an i64's -1 apart from its free mark. Blocks with an i64 run item by item. - A list's kinds are its stored header's (number, text, bytes, bool, integer): integer columns are int64_t, ordered as integers as keys (found without guide keys for now), stored in 8 bytes and logged as zigzag varints of any size. Records name their fields' type in one array (record_field_type) in place of text and bool flags. - A number, a bool and an i64 carry over each other by one rule, pure_cell_as, wherever one becomes another: a module replaced, a stored value or item read by another module, a waiting send recast. A u32 field delivers to an i64 one. - The host reads i64 fields from JSON, rows and queries as integer digits in range and nothing else, and shows every digit in views, tables, deliveries and pure-run. Faults are named by one function, pure_fault_name, in place of three tables; overflow is new. test-module: 28 arithmetic cases at the range's ends, relations, conversions both ways, 14 refusals, a keyed i64 list app (order, a sum that overflows, a failed add undone, messages and sends of 8 bytes, every digit as text), recasts, replacement between numbers, bools and i64s, and three stored runs against memory with restarts (46 images written).
Diffstat (limited to 'core/module-list.h')
-rw-r--r--core/module-list.h34
1 files changed, 24 insertions, 10 deletions
diff --git a/core/module-list.h b/core/module-list.h
index 603134a..75a871f 100644
--- a/core/module-list.h
+++ b/core/module-list.h
@@ -16,9 +16,9 @@
#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. */
+ * cell per field: a number, an integer, 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 { union { double num; int64_t i64; }; unsigned char *text; size_t size; } PureCell;
typedef struct PureList PureList;
/* An event's list changes; a removed item's cells wait in cells. */
@@ -36,7 +36,7 @@ typedef struct { void *entries; size_t count, capacity; } PureRetired;
typedef struct {
size_t start;
unsigned count;
- union { const double *numbers; const PureSpan *texts; } column[16];
+ union { const double *numbers; const int64_t *integers; const PureSpan *texts; } column[16];
/* Where the run is in the list's tree, for the next one. */
const void *path[16];
uint8_t taken[16];
@@ -46,9 +46,22 @@ typedef struct {
/* A list holds up to PURE_LIST_ITEMS items, a run up to PURE_LIST_RUN. */
enum { PURE_LIST_ITEMS = 1 << 24, PURE_LIST_RUN = 32 };
-/* text_fields: a field's kind, 0 a number, 1 a text (UTF-8, checked when
- * read), 2 bytes (any: a runtime list's). */
-PureList *pure_list_new(unsigned fields, const uint8_t *text_fields);
+/* A field's kind: a number, a text (UTF-8, checked when read), bytes (any: a
+ * runtime list's), a bool (a number 0 or 1, kept as a number is) or an
+ * integer (an int64_t, ordered as one). A stored list's header names its
+ * fields by these kinds. */
+enum { PURE_CELL_NUMBER = 0, PURE_CELL_TEXT = 1, PURE_CELL_BYTES = 2, PURE_CELL_BOOL = 3, PURE_CELL_INTEGER = 4 };
+static inline bool pure_cell_text(uint8_t kind) { return kind == PURE_CELL_TEXT || kind == PURE_CELL_BYTES; }
+/* Whether a number, bool or integer cell holds what its kind may: a finite
+ * number, a bool 0 or 1 (either zero), any integer. */
+bool pure_cell_fits(uint8_t kind, PureCell cell);
+/* A number, a bool or an integer as another of them holds it (a module
+ * replaced, a stored value read by another module, a waiting send recast):
+ * true with *cell made the other when it fits (a bool from 0 or 1, either
+ * zero false; a number from an integer within 2^53; an integer from a
+ * whole number in its range), else false. Texts only as themselves. */
+bool pure_cell_as(uint8_t from, uint8_t to, PureCell *cell);
+PureList *pure_list_new(unsigned fields, const uint8_t *kinds);
void pure_list_free(PureList *);
/* Let every item go (retired where a shared copy may read it). */
void pure_list_clear(PureList *);
@@ -97,8 +110,8 @@ PureCell pure_list_get(const PureList *, size_t at, unsigned field);
bool pure_list_run(const PureList *, size_t at, PureRun *);
bool pure_list_next(const PureList *, PureRun *);
/* 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. */
+ * field does not order below key (numbers and integers 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 field a keyed list keeps its items in order of: when it is a number
* field, seek by it reads each level's keys from one node (field -1, or a
@@ -110,7 +123,8 @@ PureResult pure_list_keyed(PureList *, int field);
* same key (nothing is made). */
PureResult pure_list_sorted(const PureList *, unsigned field, PureList **out, size_t *moved);
/* The stored form of items: each item's fields in order, a number as its
- * binary64 bits (little-endian), a text as a u32le length and its bytes.
+ * binary64 bits and an integer as its two's complement (8 bytes,
+ * little-endian), a text as a u32le length and its bytes.
* pure_list_size is the bytes of all the items so stored, and
* pure_list_encode writes them to out. */
size_t pure_list_size(const PureList *);