Files
scriptc/tests/library-mode/teach/lib.ts
Chris Tate e1f93475cb Deliver runtime-detected library traps structured, with codes, entry symbols, and profile overlays
- The library trap funnel (scr_library.c) now assembles every detected trap into the ratified 0x01 text 0x1F code 0x1F symbol [0x1F remediation] form: the baseline human line rides unchanged as field 0, and 0x01-led messages (facade-authored throws, the compile-time SC4012 contract trap) still pass verbatim.
- Trap kinds classify over the runtime's own message conventions into a new SC4013-SC4019 runtime code family (escaped exception, range, type, syntax, OOM, internal invariant, residual), documented beside SC4012 in the diagnostics registry; no arithmetic kind exists because no runtime site can fire one.
- Every generated entry prologue (init, reset, collect, each export, both emissions) records its external symbol in a SCR_LIB-only static slot the funnel reads, so the structured message names the trapping entry as the host linked it; profile teachings/remediations for the family land as a program-TU overlay table both backends emit identically.
- K5/K7/init-trap fixtures now pin the structured layout with the spec's parse rule (default text, code, entry symbol, fields=3 on a no-teachings profile), and new K12 tests pin the SC4014 teaching/remediation overlay plus the undeclared-code default; the verbatim and text-leads-printable pins stay.
- The default executable lane is byte-identical (signature-stripped cmp over a stash/rebuild pair); all library suites and the diagnostics suite are green on both emissions.
2026-07-23 19:57:38 -05:00

49 lines
2.0 KiB
TypeScript

// K11 fixture: the structured trap-teaching channel.
//
// `wrap` carries a bytes parameter, so its wrapper owns the inbound-length
// host-contract trap (code SC4012): the profile above supplies the teaching
// and remediation the compiler assembles around the code and the trapping
// symbol — the probe drives the trap with an impossible length and parses
// the exact byte layout back out of the sink.
//
// `teach` and `teachStr` throw facade-authored STRUCTURED teachings (an
// Error message and a bare thrown string, each beginning with the 0x01
// marker): the ratified verbatim rule says these ride the escaped-exception
// channel byte-for-byte — never an "Uncaught " prefix, never an added
// newline. The embedded code is embedder-prefixed (NS space), exactly the
// code-space ruling.
//
// `boomRuntime` and `failRuntime` trap and throw the ordinary way — the
// RUNTIME-detected family: the funnel assembles their sink messages into
// the structured form unconditionally. This profile declares a teaching
// and remediation for the range code (SC4014), so `boomRuntime`'s message
// overlays both; the escaped-exception code (SC4013) declares neither, so
// `failRuntime`'s message keeps the baseline "Uncaught ..." line as its
// text and carries NO remediation field. The probe also pins that the
// human text still LEADS the buffer with a printable byte — the plain-text
// degradation the 0x01 marker's unambiguity rests on.
export function wrap(b: Uint8Array): number {
return b.length;
}
export function teach(): number {
throw new Error(
"\u0001tag 99 does not name a bare message arm of this core\u001fNS1207\u001fkv_dispatch\u001frebuild the app so the compiled core and the host shim come from one build",
);
}
export function teachStr(): number {
throw "\u0001string-thrown teaching\u001fNS0002\u001fkv_teach_str";
}
export function boomRuntime(i: number): number {
const xs = [1, 2, 3];
return xs[i]!;
}
export function failRuntime(): number {
throw new Error("kaput");
}
console.log("teach ready");