✓
Passing This code compiles and runs correctly.
Code
// Pins: a collected `*T` tor mints an opaque resource token — the wire
// never sees a pointer, only "h:Res:xxxxxx". The suffix is seeded hex,
// not a sequence (Lars ruling 2026-09-07/08, carried to the pool
// 2026-10-20): `h:Res:1` used to resolve because a counter was
// predictable — under the ruling it is a fabrication like any other.
// Binding is the only legal access: the `rN` name the report bound
// resolves across turns, literal token spellings refuse, and a
// discharged token refuses as spent.
//
// Output is kept deterministic: minted hex is never printed — only
// handle counts, the proc's own `used v=42`, and refusal text that
// quotes tokens spelled literally in this file.
import std/io
import std/bridge
import std/runtime
import reslib/res
std/runtime:register(scope: "res") {
reslib.res:mint -> mint(1)
reslib.res:grab -> grab(1)
reslib.res:release -> release(1)
}
tor step { br: *std/bridge:Bridge<session>, source: string<*>, tag: string }
step = std/bridge:run(br, source)
| result r |> std/io:print.ln("{{ tag:s }}: ok (holds {{ r.handles:d }})")
| unhandled-branch ub |> std/io:print.ln("{{ tag:s }} FAIL unhandled {{ ub.branch:s }}")
| defined d |> std/io:print.ln("{{ tag:s }} FAIL defined {{ d:s }}")
| dispatch-error e |> std/io:print.ln("{{ tag:s }} refused: {{ e.message:s }}")
| event-denied ev |> std/io:print.ln("{{ tag:s }} FAIL denied {{ ev:s }}")
| residue _ |> std/io:print.ln("{{ tag:s }} FAIL residue outcome")
| parse-error p |> std/io:print.ln("{{ tag:s }} FAIL parse {{ p.message:s }}")
| validation-error v |> std/io:print.ln("{{ tag:s }} FAIL invalid {{ v:s }}")
| shape-error sh |> std/io:print.ln("{{ tag:s }} FAIL shape {{ sh.message:s }}")
| exhausted _ |> std/io:print.ln("{{ tag:s }} FAIL exhausted")
| scope-not-found s2 |> std/io:print.ln("{{ tag:s }} FAIL noscope {{ s2:s }}")
| partial p |> std/io:print.ln("{{ tag:s }} FAIL unexpected partial")
// Same, but prints no report/message — for steps whose text would carry
// the minted (random) token.
tor step-quiet { br: *std/bridge:Bridge<session>, source: string<*>, tag: string }
step-quiet = std/bridge:run(br, source)
| result r |> std/io:print.ln("{{ tag:s }}: ok (holds {{ r.handles:d }})")
| unhandled-branch ub |> std/io:print.ln("{{ tag:s }} FAIL unhandled {{ ub.branch:s }}")
| defined d |> std/io:print.ln("{{ tag:s }} FAIL defined {{ d:s }}")
| dispatch-error e |> std/io:print.ln("{{ tag:s }} refused — {{ e.event_name:s }} did not run")
| event-denied ev |> std/io:print.ln("{{ tag:s }} FAIL denied {{ ev:s }}")
| residue _ |> std/io:print.ln("{{ tag:s }} FAIL residue outcome")
| parse-error p |> std/io:print.ln("{{ tag:s }} FAIL parse {{ p.message:s }}")
| validation-error v |> std/io:print.ln("{{ tag:s }} FAIL invalid {{ v:s }}")
| shape-error sh |> std/io:print.ln("{{ tag:s }} FAIL shape {{ sh.message:s }}")
| exhausted _ |> std/io:print.ln("{{ tag:s }} FAIL exhausted")
| scope-not-found s2 |> std/io:print.ln("{{ tag:s }} FAIL noscope {{ s2:s }}")
| partial p |> std/io:print.ln("{{ tag:s }} FAIL unexpected partial")
[with]std/bridge:create(id: "tok", scope: "res"): br
|> step(br, source: "mint() | ok h |>", tag: "mint")
|> step(br, source: "grab(r: r1) | ok _ |>", tag: "bound-grab")
|> step(br, source: "grab(r: \"h:Res:1\") | ok _ |>", tag: "seq-guess")
|> step(br, source: "grab(r: \"h:Res:ffffff\") | ok _ |>", tag: "hex-guess")
|> step(br, source: "release(r: r1) | ok _ |>", tag: "release")
|> step-quiet(br, source: "grab(r: r1) | ok _ |>", tag: "spent-grab")
Supporting Files
// A `*T` resource module for the token-dispatch pin: the wire never sees
// a pointer — mint() produces a *Res that packs as "h:Res:N", use()
// resolves the token back to the live struct, release() discharges it.
pub const Res = struct { v: u32 };
~pub tor mint {} -> *Res<opened!>
~proc mint|zig {
const r = @import("std").heap.page_allocator.create(Res) catch unreachable;
r.* = .{ .v = 42 };
return r;
}
~pub tor grab { r: *Res<opened> }
~proc grab|zig {
var buf: [32]u8 = undefined;
const s = @import("std").fmt.bufPrint(&buf, "used v={d}\n", .{r.v}) catch unreachable;
_ = @import("std").posix.write(1, s) catch {};
}
~pub tor release { r: *Res<!opened> }
~proc release|zig {
@import("std").heap.page_allocator.destroy(r);
}
Actual
mint: ok (holds 1)
used v=42
bound-grab: ok (holds 1)
seq-guess refused: 'r' wants a live <opened> — 'h:Res:1' names nothing the session holds. Mint one through a verb whose signature ends '-> <opened!>'
hex-guess refused: 'r' wants a live <opened> — 'h:Res:ffffff' names nothing the session holds. Mint one through a verb whose signature ends '-> <opened!>'
release: ok (holds 0)
spent-grab refused — grab did not run
Expected output
mint: ok (holds 1)
used v=42
bound-grab: ok (holds 1)
seq-guess refused: 'r' wants a live <opened> — 'h:Res:1' names nothing the session holds. Mint one through a verb whose signature ends '-> <opened!>'
hex-guess refused: 'r' wants a live <opened> — 'h:Res:ffffff' names nothing the session holds. Mint one through a verb whose signature ends '-> <opened!>'
release: ok (holds 0)
spent-grab refused — grab did not run
Flows
flow ~register click a branch to expand · @labels scroll to their anchor
register (scope: "res", source: reslib.res:mint -> mint(1)
reslib.res:grab -> grab(1)
reslib.res:release -> release(1))
subflow ~step click a branch to expand · @labels scroll to their anchor
run (br, source)
subflow ~step-quiet click a branch to expand · @labels scroll to their anchor
run (br, source)
flow ~create click a branch to expand · @labels scroll to their anchor
create (id: "tok", scope: "res")
Test Configuration
MUST_RUN
koru.json:
{
"paths": {
"std": "../../../../../koru_std",
"app": "{{ ENTRY }}",
"reslib": "{{ ENTRY }}/reslib"
}
}