diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 00:02:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 01:21:34 -0300 |
| commit | a6f294ef5b50aeb5b69e486838378654e318ed04 (patch) | |
| tree | 3a223f1027389dd30d8347462cee4f9b6eb7ecf6 /addons | |
| parent | e9b4f0e1c37c5c1f369d152d0a70b672433c94b5 (diff) | |
| download | pardes-a6f294ef5b50aeb5b69e486838378654e318ed04.tar.gz pardes-a6f294ef5b50aeb5b69e486838378654e318ed04.zip | |
kinds #4, the fake addon and the addon test: addons/fake/fake.c is the template, every function of src/kinds/pardes_addon.h in a few lines (a counter its keys, clicks, words, ticks and jobs move, a 2x2 picture, a body, an address, a ctl read, a dump and a load), built by the build with -Wall -Wextra -Werror four more ways for the loader to refuse (another ABI, no pardes_addon, a word that is the core's) or reload (no record of its own); `pardes --addon-test <lib> <script>` loads a library into a session of its own (80x24 unless `size`, `seed N` for the panes' seeds, jobs at once, a clock moved only by `tick` and `settle`, which ticks until the kind asks for no frame) and prints the pane's tag, cells and placements after each line of keys, clicks and words; the addon-test step (and behaviour-test) runs it over the fake against addons/fake/fake.out; T1 (test/behaviour/addons.zig): Addon load, /addons with its path, BLAKE3 and panes open, the words in /commands and Help, a word refused away from its kind, unload refused while a pane is open, a compiled-in kind not unloadable; a library of another ABI, one with no export, one whose word is the core's and a file that is no library each refused and listed with why; a pane of the kind taking keys, a click, a word, a job, its body and ctl read, Esc leaving it; a dump restored with the addon, without it (the placeholder, a word refused there), and the addon loaded again reopening it in place with its count; a reload refused for a half-built library with the old one running on, one taking the state across by dump and load, one with no record coming back from its words' last values; a Look by an addon's extension; a test session lets go of its addons at its end (the registry is the process's); gates on the head: core-test 961/961 and unit-test 1494/1495 tui, 1538/1539 gui, behaviour-test 250/250, pane-test 171/172, snap all 108 ok, process-test 0 of 37 failed on both, addon-test ok, hxdiff 19 and hxparity 6 mismatches (the base's), hxgolf 0, replicas, gui-golden, monkey-gui, daemon.py main and window-clients, soak local pass
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/fake/fake.c | 199 | ||||
| -rw-r--r-- | addons/fake/fake.out | 78 | ||||
| -rw-r--r-- | addons/fake/fake.script | 9 |
3 files changed, 286 insertions, 0 deletions
diff --git a/addons/fake/fake.c b/addons/fake/fake.c new file mode 100644 index 00000000..ad0f83ee --- /dev/null +++ b/addons/fake/fake.c @@ -0,0 +1,199 @@ +/* fake.c: the template addon, every function of pardes_addon.h in a few + * lines, and what the loader's tests drive (test/behaviour/addons.zig, + * `pardes --addon-test`). + * + * cc -shared -fPIC -I src/kinds -o fake.so addons/fake/fake.c + * + * A pane of it counts: keys and clicks and ticks and words each add to a + * count it paints, dumps and answers `where` with; `:N` sets it. */ +#include "pardes_addon.h" + +/* The loader's tests build it wrong on purpose: another ABI, no export, + * a word that is the core's; and once with no record of its own. */ +#ifndef FAKE_NAME +#define FAKE_NAME "fake" +#endif +#ifndef FAKE_WORD +#define FAKE_WORD "Fake" +#endif +#ifdef FAKE_NO_EXPORT +#define pardes_addon fake_not_exported +#endif + +static const pa_api *api; + +typedef struct { + unsigned count, ticks; + char last[16]; + uint8_t pixels[2 * 2 * 4]; +} fake; + +static int init(const pa_api *a) { + api = a; + return 0; +} + +static void *open(const char *path, const uint8_t *bytes, uint64_t len) { + fake *f = api->alloc(sizeof *f); + if (!f) return 0; + uint64_t seed = api->seed(); + for (int i = 0; i < 16; i++) f->pixels[i] = (uint8_t)(i * 16 + (seed >> (i % 8)) % 2); + f->count = bytes ? (unsigned)len : 0; + (void)path; + return f; +} + +static void close(void *st) { (void)st; } + +static uint64_t tick(void *st, uint64_t now) { + fake *f = st; + f->ticks++; + return f->ticks < 3 ? now + 100000000u : 0; /* ten a second, three times */ +} + +static void num(char *out, unsigned n) { + char t[12]; + int k = 0; + do t[k++] = (char)('0' + n % 10); while (n /= 10); + while (k) *out++ = t[--k]; + *out = 0; +} + +static void paint(void *st, const pa_window *w, pa_paint *out) { + fake *f = st; + char line[48] = "count "; + num(line + 6, f ? f->count : 0); + pa_put(w, 0, 0, line, PA_INDEX(2), PA_DEFAULT); + if (f && f->last[0]) pa_put(w, 1, 0, f->last, PA_DEFAULT, PA_DEFAULT); + const char *p = "fake"; + for (out->prefix_len = 0; p[out->prefix_len]; out->prefix_len++) out->prefix[out->prefix_len] = p[out->prefix_len]; + if (f && out->cap > 0 && w->rows > 2) { + pa_placement *pl = &out->placements[out->n++]; + *pl = (pa_placement){.rgba = f->pixels, .w = 2, .h = 2, .stride = 8, .src = {0, 0, 2, 2}, .dst = {0, 2, 2, 1}, .key = f->count}; + } +} + +static int key(void *st, const pa_key *k) { + fake *f = st; + if (k->cp == 'q') return 0; /* not taken: the core's */ + f->count++; + f->last[0] = 'k'; + f->last[1] = k->cp < 128 ? (char)k->cp : '?'; + f->last[2] = 0; + return 1; +} + +static int mouse(void *st, const pa_mouse *m) { + fake *f = st; + if (m->action != PA_PRESS) return 1; + f->count++; + f->last[0] = 'm'; + num(f->last + 1, m->col); + return 1; +} + +static uint64_t body_len(void *st) { (void)st; return 6; } + +static uint32_t body(void *st, uint64_t off, char *buf, uint32_t n) { + (void)st; + const char *text = "fake\n\n"; + uint32_t k = 0; + while (off + k < 6 && k < n) { buf[k] = text[off + k]; k++; } + return k; +} + +static int address(void *st, const char *text, uint32_t n) { + fake *f = st; + unsigned v = 0; + uint32_t i = text[0] == ':' ? 1 : 0; + if (i >= n) return 0; + for (; i < n; i++) { + if (text[i] < '0' || text[i] > '9') return 0; + v = v * 10 + (unsigned)(text[i] - '0'); + } + f->count = v; + return 1; +} + +static uint32_t where(void *st, char *buf, uint32_t n) { + fake *f = st; + char t[12]; + num(t, f->count); + uint32_t k = 0; + while (t[k] && k < n) { buf[k] = t[k]; k++; } + return k; +} + +static int ctl(void *st, const char *line, uint32_t n, char *reply, uint32_t cap) { + fake *f = st; + /* FakeBump [n]: adds n (1); FakeJob: counts the bytes a job answers. */ + if (n >= 8 && line[4] == 'B') { + unsigned by = 0; + for (uint32_t i = 9; i < n && line[i] >= '0' && line[i] <= '9'; i++) by = by * 10 + (unsigned)(line[i] - '0'); + f->count += by ? by : 1; + return 0; + } + if (n >= 7 && line[4] == 'J') return api->job("abc", 3) ? 0 : 1; + const char *no = "no such fake word"; + uint32_t k = 0; + while (no[k] && k + 1 < cap) { reply[k] = no[k]; k++; } + reply[k] = 0; + return 1; +} + +static uint32_t ctl_read(void *st, char *buf, uint32_t n) { + fake *f = st; + char t[24] = "count:"; + num(t + 6, f->count); + uint32_t k = 0; + while (t[k] && k < n) { buf[k] = t[k]; k++; } + return k; +} + +static uint32_t job_run(const uint8_t *in, uint32_t n, pa_out *out) { + uint8_t *o = out->alloc(out, n * 2); + if (!o) return 0; + for (uint32_t i = 0; i < n; i++) o[i] = o[n + i] = in[i]; + return n * 2; +} + +static void job_done(void *st, uint32_t token, const uint8_t *out, uint32_t n) { + fake *f = st; + (void)token; (void)out; + f->count += n; +} + +#ifndef FAKE_NO_DUMP +static uint32_t dump(void *st, uint8_t *buf, uint32_t n) { + fake *f = st; + if (n >= 4) for (int i = 0; i < 4; i++) buf[i] = (uint8_t)(f->count >> (8 * i)); + return 4; +} + +static int load(void *st, const uint8_t *buf, uint32_t n, uint32_t version) { + fake *f = st; + if (n != 4 || version > 1) return 1; + f->count = (unsigned)buf[0] | (unsigned)buf[1] << 8 | (unsigned)buf[2] << 16 | (unsigned)buf[3] << 24; + return 0; +} +#endif + +static const pa_word words[] = { + {.size = sizeof(pa_word), .name = FAKE_WORD, .leader = "zf", .opens = 1, .doc = "a fake pane, counting"}, + {.size = sizeof(pa_word), .name = "FakeBump", .arg = PA_ARG_OPTIONAL, .doc = "add to the count"}, + {.size = sizeof(pa_word), .name = "FakeJob", .doc = "count a job's answer"}, +}; + +const pa_ops pardes_addon = { + .head = PA_ADDON(FAKE_NAME, 1, ".fake", words, 3), +#ifdef FAKE_ABI + .head.abi = FAKE_ABI, +#endif + .init = init, .open = open, .close = close, .tick = tick, .paint = paint, + .key = key, .mouse = mouse, .body_len = body_len, .body = body, + .address = address, .where = where, .ctl = ctl, .ctl_read = ctl_read, + .job_run = job_run, .job_done = job_done, +#ifndef FAKE_NO_DUMP + .dump = dump, .load = load, +#endif +}; diff --git a/addons/fake/fake.out b/addons/fake/fake.out new file mode 100644 index 00000000..40b958f8 --- /dev/null +++ b/addons/fake/fake.out @@ -0,0 +1,78 @@ +> seed 7 +> size 60 20 +tag fake +|count 0 +| +| +| +| +| +| +| +placement 2x2 src 0,0 2x2 over 0,2 2x1 key 4b3cd99b86ea3486 +> key ab +tag fake +|count 2 +|kb +| +| +| +| +| +| +placement 2x2 src 0,0 2x2 over 0,2 2x1 key fdcaab9076ad067e +> click 3 1 +tag fake +|count 3 +|m3 +| +| +| +| +| +| +placement 2x2 src 0,0 2x2 over 0,2 2x1 key 71e39225f0cec2a5 +> FakeBump 10 +tag fake +|count 13 +|m3 +| +| +| +| +| +| +placement 2x2 src 0,0 2x2 over 0,2 2x1 key 54740e23065232cf +> FakeJob +tag fake +|count 13 +|m3 +| +| +| +| +| +| +placement 2x2 src 0,0 2x2 over 0,2 2x1 key 54740e23065232cf +> tick 100 +tag fake +|count 19 +|m3 +| +| +| +| +| +| +placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 +> settle +tag fake +|count 19 +|m3 +| +| +| +| +| +| +placement 2x2 src 0,0 2x2 over 0,2 2x1 key 540d6c1b4eee5716 diff --git a/addons/fake/fake.script b/addons/fake/fake.script new file mode 100644 index 00000000..35407cd7 --- /dev/null +++ b/addons/fake/fake.script @@ -0,0 +1,9 @@ +# pardes --addon-test fake.so addons/fake/fake.script | diff addons/fake/fake.out - +seed 7 +size 60 20 +key ab +click 3 1 +FakeBump 10 +FakeJob +tick 100 +settle |
