diff options
| author | eunhhu <[email protected]> | 2026-09-30 16:16:08 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-30 16:16:08 +0100 |
| commit | 46c303a41e9dd9cd0e6bd50511e8d7253a0ef438 (patch) | |
| tree | 7564bf80ac43ff0964c64acd6a15f7299fa48997 /cli | |
| parent | e02bfc916743a0327d76144b32b6ec6381e5907f (diff) | |
| download | pure-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 'cli')
| -rw-r--r-- | cli/pure-run.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/cli/pure-run.c b/cli/pure-run.c index b9eb222..64eb6ee 100644 --- a/cli/pure-run.c +++ b/cli/pure-run.c @@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 200809L #include "module-store.h" #include "store.h" +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -14,7 +15,6 @@ * Text states and text views print as JSON strings; cursors as byte positions; * lists as arrays of objects; indices as positions; a table view as an array * with an object of its columns per row. A failed view or cell is null. */ -static const char *const fault_names[] = {"none", "divide", "non_finite", "clamp", "limit", "not_found", "encoding", "exists"}; /* time MS sets the time events see (milliseconds since 1970); tick NAME is a timer's tick. */ static bool load(const char *path, PureModule *module) { @@ -53,8 +53,10 @@ static void show_list(const PureModule *m, const PureList *list, const PureRecor for (unsigned f = 0; f < record->count; ++f) { PureCell cell = pure_list_get(list, at, f); printf("%s\"%s\":", f ? "," : "", m->record_field_names[record->first + f]); - if (m->record_field_bool[record->first + f]) printf("%s", cell.num ? "true" : "false"); - else if (!m->record_field_text[record->first + f]) printf("%.17g", cell.num); + uint8_t type = m->record_field_type[record->first + f]; + if (type == PURE_RECORD_BOOL) printf("%s", cell.num ? "true" : "false"); + else if (type == PURE_RECORD_I64) printf("%" PRId64, cell.i64); + else if (type == PURE_RECORD_NUMBER) printf("%.17g", cell.num); else { putchar('"'); json_span(NULL, (PureSpan){cell.text, cell.size}); @@ -66,15 +68,19 @@ static void show_list(const PureModule *m, const PureList *list, const PureRecor putchar(']'); } -/* A number, bool or text view, or a column at a row. */ +/* A number, bool, i64 or text view, or a column at a row. */ static void show_value(PureApp *app, uint32_t view, size_t row) { const PureModule *m = app->module; static Collected text; text.used = 0; text.fits = true; double value; + int64_t integer; bool column = m->view_table[view]; - if (m->view_type[view] == PURE_VIEW_TEXT) { + if (m->view_type[view] == PURE_VIEW_I64) { + if (!(column ? pure_app_cell_i64(app, view, row, &integer) : pure_app_view_i64(app, view, &integer))) printf("null"); + else printf("%" PRId64, integer); + } else if (m->view_type[view] == PURE_VIEW_TEXT) { PureResult result = column ? pure_app_cell_text(app, view, row, collect, &text) : pure_app_view_text(app, view, collect, &text); if (result != PURE_OK || !text.fits) printf("null"); @@ -99,6 +105,7 @@ static void show(PureApp *app, const char *failure) { putchar('"'); } else if (m->state_type[i] == PURE_STATE_LIST) show_list(m, app->lists[i], &m->record[m->state_ref[i]]); else if (m->state_type[i] == PURE_STATE_BOOL) printf("%s", app->values[i].num ? "true" : "false"); + else if (m->state_type[i] == PURE_STATE_I64) printf("%" PRId64, app->values[i].i64); else printf("%.17g", app->values[i].num); } printf("},\"views\":{"); @@ -121,7 +128,7 @@ static void show(PureApp *app, const char *failure) { putchar(']'); } printf("},\"tick\":%llu,\"successfulEvents\":%llu,\"fault\":\"%s\",\"error\":%s%s%s}\n", - (unsigned long long)app->ticks, (unsigned long long)app->events, fault_names[app->fault], + (unsigned long long)app->ticks, (unsigned long long)app->events, pure_fault_name(app->fault), failure ? "\"" : "", failure ? failure : "null", failure ? "\"" : ""); } |
