core 477dffe brings pseudo's sized types (INT8..UINT64, FLOAT32), exact numerical built-ins, USE IEEE, and USE for pplus-library, its new submodule: 16 routines checked at every level. - #/library (src/ui/library.ts): every routine by module with a count of how its checks ended; a routine's page shows its pseudo, cases and results, every check with its detail, each reference implementation with its note, tolerance and source, the Dafny proof and the sources. - Open in the Bridge: a routine opens as the problem lib:<id> (src/core/library.ts), its first case as the call, so it can be stepped through; the problem menu names it. - Library in the site nav; README, docs/app.md and AGENTS.md updated. - Two Quarto examples expected "X_BAR returned 3" for a FLOAT result; core now prints it in its type, 3.0. Gate: site 113 pass; core 332 pass; library-check no failing check. Manual check: #/library lists 16 routines with chips; a routine's page shows numbered pseudo, cases, checks; Open in the Bridge steps through NeedlemanWunschScore; no console errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
55 lines
2.7 KiB
TypeScript
55 lines
2.7 KiB
TypeScript
/**
|
|
* The library (pplus-library, through core's registry) as the site shows it: a routine opened in the Bridge, and
|
|
* a summary of what its checks found. DOM-free; src/ui/library.ts draws it.
|
|
*
|
|
* A library routine opens like a catalog problem, under the id `lib:<module>.<Name>` (#/bridge/p/lib:md.LennardJones):
|
|
* its pseudo in the pseudo pane and its first case as the call, so it can be stepped through line by line, which
|
|
* a program that only calls it never does.
|
|
*/
|
|
import { libraryModules, libraryRoutine, type LibraryRoutine } from '#core/library/registry.js';
|
|
import type { LibraryCheck } from '#core/library/types.js';
|
|
import { emptyState, type PlayState } from './state.js';
|
|
|
|
export const LIBRARY_PREFIX = 'lib:';
|
|
|
|
export function isLibraryId(id: string): boolean { return id.startsWith(LIBRARY_PREFIX); }
|
|
|
|
/** The state a library routine opens in: its pseudo, and its first case as the call. */
|
|
export function stateForLibraryRoutine(r: LibraryRoutine): PlayState {
|
|
const s = emptyState();
|
|
s.problem = `${LIBRARY_PREFIX}${r.id}`;
|
|
s.title = `${r.id}, from the library`;
|
|
s.sources = { pseudo: r.source };
|
|
s.lang = 'pseudo';
|
|
s.call = r.cases[0]?.call ?? null;
|
|
s.view = 'trace';
|
|
return s;
|
|
}
|
|
|
|
/** The state for a `lib:` problem id, or null when the library has no such routine. */
|
|
export function libraryState(id: string): PlayState | null {
|
|
if (!isLibraryId(id)) return null;
|
|
const r = libraryRoutine(id.slice(LIBRARY_PREFIX.length));
|
|
return r ? stateForLibraryRoutine(r) : null;
|
|
}
|
|
|
|
/** Every check of a routine, named as the page lists them: its own checks, each reference's runs, the proof. */
|
|
export function checksOf(r: LibraryRoutine): Array<{ name: string; check: LibraryCheck }> {
|
|
const out: Array<{ name: string; check: LibraryCheck }> = [];
|
|
const LABEL: Record<string, string> = { structure: 'One routine per file', pseudo: 'Cases run', prover: 'Prover', fuzz: 'Fuzzer', mojo: 'Generated Mojo' };
|
|
for (const k of ['structure', 'pseudo', 'prover', 'fuzz', 'mojo']) if (r.checks[k]) out.push({ name: LABEL[k], check: r.checks[k] });
|
|
for (const ref of r.references) for (const [how, c] of Object.entries(ref.checks)) out.push({ name: `${ref.lang} ${ref.level}, ${how}`, check: c });
|
|
if (r.proof) out.push({ name: `Proof (${r.proof.lang})`, check: r.proof.check });
|
|
return out;
|
|
}
|
|
|
|
/** How many checks of a routine ended each way. */
|
|
export function tally(r: LibraryRoutine): Record<LibraryCheck['status'], number> {
|
|
const t: Record<LibraryCheck['status'], number> = { pass: 0, fail: 0, open: 0, skipped: 0, unverified: 0 };
|
|
for (const { check } of checksOf(r)) t[check.status]++;
|
|
return t;
|
|
}
|
|
|
|
export { libraryModules, libraryRoutine };
|
|
export type { LibraryRoutine };
|