From bfa54e02881f56b3a969220ecaac706542046149 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Wed, 30 Sep 2026 15:24:56 +0100 Subject: 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. --- serve/test-message-json.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'serve/test-message-json.c') diff --git a/serve/test-message-json.c b/serve/test-message-json.c index 618a363..b2bad37 100644 --- a/serve/test-message-json.c +++ b/serve/test-message-json.c @@ -1,7 +1,7 @@ /* JSON numbers are read as strtod reads them, bit for bit: in the forms a * client writes (a program's shortest digits, fixed decimals, exponents), at * the edges of the exact path (2^53, 10^22) and past them, and refused when - * not finite or not JSON. */ + * not finite or not JSON. A bool is true or false, nothing else. */ #include "message-json.h" #include #include @@ -43,6 +43,15 @@ int main(void) { double value; CHECK(!read_number(refused[i], &value)); } + static const PureField truth = {.type = PURE_FIELD_BOOL, .offset = 1}; + unsigned char prefix[2] = {7, 7}; + CHECK(pure_json_fixed(&truth, (const unsigned char *)"true", 4, prefix) && prefix[1] == 1 && prefix[0] == 7); + CHECK(pure_json_fixed(&truth, (const unsigned char *)"false", 5, prefix) && prefix[1] == 0); + static const char *const not_bools[] = {"", "1", "0", "True", "\"true\"", "tru", "truex", "false ", "null", "t"}; + for (size_t i = 0; i < sizeof(not_bools) / sizeof(*not_bools); ++i) + CHECK(!pure_json_fixed(&truth, (const unsigned char *)not_bools[i], strlen(not_bools[i]), prefix) && prefix[1] == 0); + double number; + CHECK(!read_number("true", &number) && !read_number("false", &number)); uint64_t seed = 0x6a736f6eu; size_t read = 0; for (unsigned i = 0; i < 400000; ++i) { -- cgit v1.2.3