From 3e35975ee9120042baa0e8fe2bb2d52311204e84 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Fri, 25 Sep 2026 11:05:51 +0100 Subject: Compile v0a programs to verified Pure modules aup check/build parse states, key inputs, views and handlers (with if/else and else-if), resolve names, generate forward-only stack code and encode a Pure module v1 deterministically. Diagnostics carry file:line:column. make check loads every module with Pure's verifier, checks determinism, 20 diagnostics and accepted forms, replacement by name, 600 generated programs and damaged sources (every emitted module verifies), and replays random event scripts against the workbench Zig engine: 16,667 snapshots across counter, toggle, charge, else-if and fault programs matched, including 921 failed events. The sanitizer-built compiler passes the same checks. --- src/main.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..3731eec --- /dev/null +++ b/src/main.c @@ -0,0 +1,38 @@ +#define _POSIX_C_SOURCE 200809L +#include "aup.h" +#include +#include +#include + +static int usage(void) { + fputs("aup check FILE\naup build FILE -o OUT.pmod\n", stderr); + return 2; +} + +int main(int argc, char **argv) { + bool build = argc == 5 && !strcmp(argv[1], "build") && !strcmp(argv[3], "-o"); + if (!build && !(argc == 3 && !strcmp(argv[1], "check"))) return usage(); + const char *path = argv[2]; + FILE *file = fopen(path, "rb"); + if (!file) { perror(path); return 2; } + static char source[AUP_SOURCE_LIMIT + 1]; + size_t length = fread(source, 1, sizeof(source), file); + bool unreadable = ferror(file); + fclose(file); + if (unreadable) { fprintf(stderr, "%s: cannot read\n", path); return 2; } + unsigned char *module; + size_t size; + AupDiagnostic error; + if (!aup_compile(source, length, &module, &size, &error)) { + fprintf(stderr, "%s:%d:%d: %s\n", path, error.line, error.column, error.message); + return 1; + } + int status = 0; + if (build) { + FILE *out = fopen(argv[4], "wb"); + if (!out || fwrite(module, 1, size, out) != size) { perror(argv[4]); status = 2; } + if (out && fclose(out)) { perror(argv[4]); status = 2; } + } + free(module); + return status; +} -- cgit v1.2.3