diff options
| author | eunhhu <[email protected]> | 2026-09-25 11:05:51 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-25 11:05:51 +0100 |
| commit | 3e35975ee9120042baa0e8fe2bb2d52311204e84 (patch) | |
| tree | c56902403251c964f493e69df7e343167e981a81 /src/main.c | |
| parent | e058795152fdb678aa71b67acd7a0fb44dabe747 (diff) | |
| download | aup-3e35975ee9120042baa0e8fe2bb2d52311204e84.tar.gz aup-3e35975ee9120042baa0e8fe2bb2d52311204e84.zip | |
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.
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 38 |
1 files changed, 38 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +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; +} |
