diff options
| author | eunhhu <[email protected]> | 2026-09-30 15:24:56 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-30 15:24:56 +0100 |
| commit | bfa54e02881f56b3a969220ecaac706542046149 (patch) | |
| tree | 8c1e1b6d5a4b8a222cc56a6dc8e6a08a52a7a508 /core/module-save.h | |
| parent | 16fab9f3d71fa1fdb4cd38f7e9ae1e1eb4e75340 (diff) | |
| download | pure-bfa54e02881f56b3a969220ecaac706542046149.tar.gz pure-bfa54e02881f56b3a969220ecaac706542046149.zip | |
Give bools their own type in the module format (v6, 016 stage 1)
A condition was a number, non-zero being true: a flag was a number field,
a view showed 1 for true, and nothing kept a number from standing for a
bool or a bool from being added to. Now the verifier has a bool among its
stack types, and a verified module never mixes the two. No opcode is new:
- CONST with argument 1 is a bool (+0 or 1), NUM_TEXT with argument 1
writes one as true or false; LOAD and STORE take a number or a bool
state, locals may hold a bool (2).
- Comparisons (LT to NE, TEXT_COMPARE) and LIST_HAS give a bool; AND, OR
and NOT take and give them; JZ, REQUIRE, filters and folds' tests take
one (count and first leave a bool, sum, max, min and distinct a number
and a bool); EQ and NE compare two bools too.
- Type codes: state 5, record field 2, message field 6 (one byte in the
prefix, 0 or 1, or the message fails as limit), view 3. A bool's
constant, initial value and default are +0 or 1; a list is not keyed by
one. PUREMOD6: v5 modules are built again.
At run time a bool is a number's 0 or 1, so leaf-at-a-time folds run as
before. A number that becomes a bool (a module replaced, a stored state
or item read again, a waiting send recast) keeps 0 (either sign) and 1
and takes the default otherwise; a bool that becomes a number is 0 or 1.
The host carries bools on every boundary: JSON true and false only (a
row's field too), a query's true and false, true and false in views,
table JSON and HTTP deliveries; a link takes a bool only into a bool.
A stored outbox's field types were read back with a check that refused
bool (at or past rows): a node whose output had a bool field and a send
waiting could not start again. test-module now stores such a send and
opens it (it fails on the old check), beside 28 bool refusals of the
verifier and bool states, fields, views, sends, links and migration.
The lane generator makes numbers and bools apart.
Diffstat (limited to 'core/module-save.h')
| -rw-r--r-- | core/module-save.h | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/core/module-save.h b/core/module-save.h index d17cace..9c0f74e 100644 --- a/core/module-save.h +++ b/core/module-save.h @@ -65,15 +65,23 @@ PureResult pure_save_commit(PureApp *, const double *values, void *const *docume uint32_t pure_fields_lay_out(PureField *fields, uint32_t count); /* A send's payload, laid out for from's fields, made anew for to's (both * laid out): each field takes the value of from's of the same name when - * its type can hold it (u32 and number are numbers, bytes and text are - * bytes; a number that is not a u32, or bytes that are not UTF-8 for a - * text, cannot), else it is 0 or empty. The same rule moves a list's items - * (pure_list_migrate). STORE_ERROR when payload is not laid out by from. */ + * its type can hold it (u32, number and bool are numbers, bytes and text + * are bytes; a number that is not a u32, one that is not 0 or 1 for a bool, + * or bytes that are not UTF-8 for a text, cannot), else it is 0, false or + * empty. The same rule moves a list's items (pure_list_migrate). A link + * delivers only to a field of the same kind or a wider one + * (pure_module_takes). STORE_ERROR when payload is not laid out by from. */ PureResult pure_send_recast(const PureField *from, uint32_t from_count, const PureField *to, uint32_t to_count, PureSpan payload, unsigned char **out, size_t *size); -/* A list with record's fields, taking from `from` each field of the same name - * and kind and giving the others their defaults (module.c). */ +/* A record field's kind as a stored list names it: 0 a number, 1 a text, 3 + * a bool (2 is a runtime list's bytes); a list holds a bool as a number. */ +enum { PURE_RECORD_BOOL = 3 }; +uint8_t pure_record_kind(const PureModule *, uint32_t field); +/* A list with record's fields, taking from `from` (its fields' names and + * kinds) each field of the same name and kind, or a number and a bool from + * each other (0 and 1 are false and true; a bool's other numbers take the + * default), and giving the others their defaults (module.c). */ PureResult pure_list_migrate(PureList **out, const PureList *from, const char *const *names, - const uint8_t *text, unsigned count, const PureModule *m, uint32_t record); + const uint8_t *kinds, unsigned count, const PureModule *m, uint32_t record); #endif |
