From 4874acb6b2c7bc4efa82aad0209f3022e1d3fa02 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 18:10:52 +0100 Subject: 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. --- prototypes/connections/edit-module.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'prototypes/connections/edit-module.c') diff --git a/prototypes/connections/edit-module.c b/prototypes/connections/edit-module.c index 9305923..3ce272e 100644 --- a/prototypes/connections/edit-module.c +++ b/prototypes/connections/edit-module.c @@ -89,19 +89,11 @@ int main(int argc, char **argv) { if (!show && !number(argv[at + 2], INT64_MAX, &expected)) goto usage; if (edit && (!number(argv[at + 3], UINT32_MAX, &offset) || !number(argv[at + 4], UINT32_MAX, &remove))) goto usage; - static unsigned char image[1 << 17]; static PureModule module; char error[160]; - FILE *source = fopen(module_path, "rb"); - size_t image_size = source ? fread(image, 1, sizeof(image), source) : 0; - if (!source || ferror(source) || image_size == sizeof(image)) { - if (source) fclose(source); - fputs("Module: cannot read module\n", stderr); - return 2; - } - fclose(source); - if (pure_module_load(image, image_size, &module, error, sizeof(error)) != PURE_OK) { - fprintf(stderr, "Module: %s\n", error); + PureResult read = pure_module_read(module_path, &module, error, sizeof(error)); + if (read != PURE_OK) { + fprintf(stderr, "Module: %s\n", read == PURE_NOT_FOUND ? "cannot read module" : error); return 2; } int input = pure_module_input(&module, show ? "show" : "edit"); -- cgit v1.2.3