aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/connections/pure-run.c
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-25 15:00:27 +0100
committereunhhu <[email protected]>2026-09-25 15:00:27 +0100
commit82f685e5583d3edc4e5d9d327e9925705ce51b1d (patch)
tree85b0889aa1152bb79b3e16c2711da83bb42d8402 /prototypes/connections/pure-run.c
parent50a271cc241fb9fcdb196d45ba113f74cb318b47 (diff)
downloadpure-82f685e5583d3edc4e5d9d327e9925705ce51b1d.tar.gz
pure-82f685e5583d3edc4e5d9d327e9925705ce51b1d.zip
Add conditional joins and table views to Pure modules
Module format v5 lets a value cross a join: the verifier records the stack each branch brings to its target and requires every path to agree on height, types and owners, with at most 8 such joins ahead. Branches are now allowed in views, so a view can be a conditional expression. A table view has one row per item of a list. Its columns are number or text views evaluated for one row at a time and may read that row (ROW). Hosts compute only the cells they show through pure_app_rows, pure_app_cell and pure_app_cell_text. Column names are scoped to their table. The view limit rises to 64, columns included. pure-run prints a table view as an array of row objects.
Diffstat (limited to 'prototypes/connections/pure-run.c')
-rw-r--r--prototypes/connections/pure-run.c52
1 files changed, 38 insertions, 14 deletions
diff --git a/prototypes/connections/pure-run.c b/prototypes/connections/pure-run.c
index 7f9f316..8a9788f 100644
--- a/prototypes/connections/pure-run.c
+++ b/prototypes/connections/pure-run.c
@@ -8,7 +8,8 @@
* JSON snapshot per command. Not a product interface.
* down NAME | up NAME | frame [N] | type NAME HEX|- | replace PATH | show
* Text states and text views print as JSON strings; cursors as byte positions;
- * lists as arrays of objects; indices as positions. A failed view is null. */
+ * 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"};
static bool load(const char *path, PureModule *module) {
@@ -67,6 +68,27 @@ static void show_list(const PureModule *m, const PureList *list, const PureRecor
putchar(']');
}
+/* A number 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;
+ bool column = m->view_table[view];
+ 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");
+ else {
+ putchar('"');
+ json_span(NULL, (PureSpan){text.bytes, text.used});
+ putchar('"');
+ }
+ } else if (column ? pure_app_cell(app, view, row, &value) : pure_app_view(app, view, &value)) printf("%.17g", value);
+ else printf("null");
+}
+
static void show(PureApp *app, const char *failure) {
const PureModule *m = app->module;
printf("{\"states\":{");
@@ -80,21 +102,23 @@ static void show(PureApp *app, const char *failure) {
else printf("%.17g", app->values[i]);
}
printf("},\"views\":{");
+ bool first = true;
for (uint32_t i = 0; i < m->views; ++i) {
- printf("%s\"%s\":", i ? "," : "", m->view_names[i]);
- double value;
- static Collected text;
- text.used = 0;
- text.fits = true;
- if (m->view_type[i] == PURE_VIEW_TEXT) {
- if (pure_app_view_text(app, i, collect, &text) != PURE_OK || !text.fits) printf("null");
- else {
- putchar('"');
- json_span(NULL, (PureSpan){text.bytes, text.used});
- putchar('"');
+ if (m->view_table[i]) continue;
+ printf("%s\"%s\":", first ? "" : ",", m->view_names[i]);
+ first = false;
+ if (m->view_type[i] != PURE_VIEW_TABLE) { show_value(app, i, 0); continue; }
+ putchar('[');
+ for (size_t row = 0; row < pure_app_rows(app, i); ++row) {
+ printf("%s{", row ? "," : "");
+ for (uint32_t c = 0, shown = 0; c < m->views; ++c) {
+ if (m->view_table[c] != i + 1) continue;
+ printf("%s\"%s\":", shown++ ? "," : "", m->view_names[c]);
+ show_value(app, c, row);
}
- } else if (pure_app_view(app, i, &value)) printf("%.17g", value);
- else printf("null");
+ putchar('}');
+ }
+ 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],