aboutsummaryrefslogtreecommitdiffstats
path: root/core/module.h
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-10-04 13:30:31 +0100
committereunhhu <[email protected]>2026-10-04 13:30:31 +0100
commitd806c3197500565d20787161d1e1e94ce39df7a1 (patch)
tree26664778482aa7051d89d07c01f79e4527560a8d /core/module.h
parentf668d54e0c84bdb6240ba1133ee167385a7dc440 (diff)
downloadpure-d806c3197500565d20787161d1e1e94ce39df7a1.tar.gz
pure-d806c3197500565d20787161d1e1e94ce39df7a1.zip
Keep transient states the app's while it runs, never stored (018 stage 1)
Diffstat (limited to 'core/module.h')
-rw-r--r--core/module.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/module.h b/core/module.h
index 162a8b1..d0a82bc 100644
--- a/core/module.h
+++ b/core/module.h
@@ -144,6 +144,12 @@ typedef union { double num; int64_t i64; } PureValue;
* message's rows field fills it as the message arrives, it is emptied when
* every event ends, and it is never saved nor logged for undoing. */
enum { PURE_CURSOR_STAYS = 1, PURE_LIST_ROWS = 256 };
+/* A transient state (bit 8 of its type word in a module, a bit of
+ * PureModule.transient): the app holds it while it runs, and undoes it with
+ * a failed event, but never saves it: each start begins it at its initial
+ * value (docs/design/018). A stored cursor or index is of a stored text or
+ * list. */
+enum { PURE_STATE_TRANSIENT = 256 };
/* A table view has one row per item of a list, or per item its filter
* keeps; its columns are number, bool, i64 or text views evaluated for one
* row at a time. */
@@ -217,6 +223,7 @@ typedef struct {
uint8_t state_type[PURE_MODULE_STATES];
uint16_t state_ref[PURE_MODULE_STATES]; /* text: constant; cursor: text; list: record; index: list */
uint8_t state_flags[PURE_MODULE_STATES]; /* cursor: PURE_CURSOR_STAYS; list: PURE_LIST_ROWS >> 8 */
+ uint32_t transient; /* a bit per transient state */
/* A keyed list: its key field + 1 (0: none). Its items stay in key order
* (numbers by value, texts by bytes), each key once, and keys do not change. */
uint8_t state_key[PURE_MODULE_STATES];
@@ -248,6 +255,9 @@ typedef struct {
PureValue record_field_default[PURE_MODULE_RECORD_FIELDS]; /* a number (a bool's 0 or 1), an i64, or a text constant's index */
} PureModule;
+/* Whether a state of m is transient (PURE_STATE_TRANSIENT). */
+static inline bool pure_state_transient(const PureModule *m, uint32_t state) { return m->transient >> state & 1; }
+
/* Decode and verify into out, which must be zeroed (a static one is) or hold
* a loaded module: what it held is given back first. On failure out holds
* nothing and error names the rule. */