aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/connections/serve.c
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-26 18:10:52 +0100
committereunhhu <[email protected]>2026-09-26 18:10:52 +0100
commit4874acb6b2c7bc4efa82aad0209f3022e1d3fa02 (patch)
treed8753980444c7c09445340e77fdb944042d93ee8 /prototypes/connections/serve.c
parent9a201c8229e4f45524b7bc9f2f1f127683091740 (diff)
downloadpure-4874acb6b2c7bc4efa82aad0209f3022e1d3fa02.tar.gz
pure-4874acb6b2c7bc4efa82aad0209f3022e1d3fa02.zip
Size a module's code and constants to the module; raise their limits
A real app (a board, a stopwatch) already used a quarter of the 512 instructions, since a fn is inlined where it is called, and every text it shows is one of 64 constants. The code and the constants now live in one block sized to the module, which load takes and pure_module_release gives back; the limits rise to 65,535 instructions and 4,096 constants of up to 1 MiB, while PureModule shrinks from 28,664 to 11,936 bytes. The verifier's branch marks are sized to the block instead of 64 KiB on the stack. pure_module_read reads a module file whole, and every host uses it instead of a 128 KiB buffer.
Diffstat (limited to 'prototypes/connections/serve.c')
-rw-r--r--prototypes/connections/serve.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/prototypes/connections/serve.c b/prototypes/connections/serve.c
index a60bf44..469c487 100644
--- a/prototypes/connections/serve.c
+++ b/prototypes/connections/serve.c
@@ -1268,14 +1268,9 @@ static bool replies_borrow(const PureModule *m, uint32_t input) {
/* ---- Main ------------------------------------------------------------- */
static bool load_module(PureModule *m, const char *path, bool *documents, uint32_t *show_out, uint32_t *edit_out) {
- static unsigned char bytes[1 << 17];
- char error[128];
- FILE *file = fopen(path, "rb");
- size_t size = file ? fread(bytes, 1, sizeof(bytes), file) : 0;
- bool read_ok = file && !ferror(file) && size < sizeof(bytes);
- if (file) fclose(file);
- if (!read_ok || pure_module_load(bytes, size, m, error, sizeof(error)) != PURE_OK) {
- fprintf(stderr, "Module: %s\n", read_ok ? error : "cannot read");
+ char error[160];
+ if (pure_module_read(path, m, error, sizeof(error)) != PURE_OK) {
+ fprintf(stderr, "Module: %s\n", error);
return false;
}
/* Documents are served when the module has show and edit, as keyed messages. */