Move the engine core into core/, a project of its own (pplus-core)
What programs mean (the languages, translators, Mojo checker and
interpreter, prover, fuzzer, machine model, catalog problems and the Mojo
corpus with godbolt's stored answers) was mixed into the site's tree, so a
change to the prover and a change to a button went through the same gate
and the same docs. This moves all of it under core/, laid out as its own
repository, ready to be extracted with its history and pinned here as a
git submodule.
- core/: src/{engines,services,sync,mojo,exercises,curriculum,common},
mojo/, syntax/mojo.xml, its tests (with Workspace and workForProblem in
place of the site's Session), scripts (corpus pipeline, play, the
exercise and probe starters, engines export/diff), and its docs
(engines, trust, mojo-corpus, exercises, coverage). Its own pixi.toml,
package.json, README, AGENTS.md and CI workflow.
- core/tests/boundary.test.mjs: library modules use no DOM, import no
page widget, and import nothing outside src/.
- core/scripts/cli.mjs: pixi run cli check|run|prove|fuzz|translate.
- core/scripts/dafny.py: Dafny 4.11.0 pinned by version and SHA-256 per
platform, fetched into .tools/ (pixi run dafny-fetch, pixi run dafny).
- The site imports core only as #core/<path>.js: an import map in
index.html, "imports" in package.json for node, core's declarations for
tsc. The site's TypeScript builds core first (npm run build).
- assemble.sh, the Quarto engine copy, the render cache key, check-pages,
quarto-export and quarto-css read core/dist and core/mojo; quarto-css
copies core's syntax/mojo.xml into the extension.
- Site tests that covered engines moved to core; the rest keep Session.
- README, AGENTS.md, docs/app.md, docs/deploy.md and the CI workflow
describe the split (checkout with submodules; core's tests and corpus
status run against the pinned commit).
Gate: site 110 pass; core 307 pass; corpus status --strict passes.
Manual check: the assembled site opens Bridge (count-base-proved),
Developer and Hardware (count-base) with the editor, the stepper and the
board, and no module errors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
This commit is contained in:
1567 files changed
+3670
-981
No files matched your search
@@ -0,0 +1,129 @@
|
||||
// The reference is only trustworthy if its examples run through the real parsers.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { REFERENCE, PSEUDO_REF, LINGO_REF, SPECO_REF, ASM_REF, MATHO_REF, explain, SPECO_SYMBOLS } from '../dist/common/reference.js';
|
||||
import { parseMatho } from '../dist/services/matho.js';
|
||||
import { studyOf } from '../dist/services/pseudo.js';
|
||||
import { readLingo } from '../dist/services/lingo.js';
|
||||
import { parseSpeco, toAscii, toMath } from '../dist/services/speco.js';
|
||||
import { parseAsm } from '../dist/services/asm.js';
|
||||
import { KEYWORDS, BUILTINS } from '../dist/engines/pseudo/lang.js';
|
||||
import { OPS } from '../dist/engines/asm86/interp.js';
|
||||
|
||||
test('every pseudocode statement example parses and checks', () => {
|
||||
const sec = PSEUDO_REF.sections.find((s) => s.id === 'pseudo-statements');
|
||||
for (const e of sec.entries) {
|
||||
const st = studyOf(e.example);
|
||||
const errs = st.diagnostics.filter((d) => d.severity === 'error');
|
||||
assert.equal(errs.length, 0, `${e.term}: ${errs.map((d) => `L${d.line} ${d.message}`).join(' | ')}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('every keyword in the engine has a meaning in the reference, and vice versa', () => {
|
||||
const sec = PSEUDO_REF.sections.find((s) => s.id === 'pseudo-keywords');
|
||||
const listed = new Set(sec.entries.map((e) => e.term));
|
||||
for (const k of KEYWORDS) assert.ok(listed.has(k), `keyword ${k} is missing from the reference`);
|
||||
for (const e of sec.entries) assert.ok(e.meaning.length > 10, `${e.term} has no meaning`);
|
||||
for (const b of Object.keys(BUILTINS)) assert.ok(explain('pseudo', b), `built-in ${b} has no hover`);
|
||||
});
|
||||
|
||||
test('every lingo sentence example reads (inside a minimal routine where needed)', () => {
|
||||
const failures = [];
|
||||
// kinds for every name the examples mention, so a fragment reads the same way it does on the page
|
||||
const kinds = 'T is a text. P is a text. S is a text. w is a text. A is a whole number. Score is a whole number.';
|
||||
const setup = [
|
||||
'Start with Count at 0.', 'Start with Best at 0.', 'Start with Run at 0.', 'Start with Left at 3.', 'Start with window at "AC".',
|
||||
'Start with an empty list called Starts.', 'Start with an empty tally called Counts.', 'Start with an empty text called R.',
|
||||
];
|
||||
const defs = "The complement of b is 'T' when b is 'A', and 'N' otherwise.";
|
||||
for (const sec of LINGO_REF.sections.filter((s) => s.id.startsWith('lingo-forms'))) {
|
||||
for (const e of sec.entries) {
|
||||
if (!e.example) continue;
|
||||
const ex = e.example.trim();
|
||||
const examples = ex.includes(' ') && !/^To /.test(ex) && !/ when /.test(ex) ? ex.split(/\s{2,}/) : [ex];
|
||||
for (const one of examples) {
|
||||
let src;
|
||||
const head = 'To test T, P, S, w, A, B and Score:';
|
||||
const pre = setup.map((l) => ' ' + l).join('\n');
|
||||
if (/^The answer is/.test(one)) src = `${head}\n${pre}\n Start with i at 0.\n ${one}\n\n${kinds}`;
|
||||
else if (/^To /.test(one)) src = `${one}\n${pre}\n The answer is Count.\n\n${kinds}`;
|
||||
else if (/ when /.test(one) || /^The .* is /.test(one)) src = `To test P, T, S and b:\n Start with i at 0.\n If b is 'A', add 1 to i.\n The answer is the length of T plus the length of P plus the length of S plus i.\n\n${one}${/[.:]$/.test(one) ? '' : '.'}\n\nP is a text. T is a text. S is a text. b is a letter.`;
|
||||
else if (/^(For|Repeat)/.test(one)) src = `${head}\n${pre}\n${/^For (each|every) .*\bi\b/.test(one) ? '' : ' Start with i at 0.\n'} ${one}\n Add 1 to Count.\n The answer is Count.\n\n${kinds}`;
|
||||
else if (/^If /.test(one) && /:$/.test(one)) src = `${head}\n${pre}\n ${one}\n Add 1 to Count.\n The answer is Count.\n\n${kinds}`;
|
||||
else if (sec.title === 'Tests') src = `${head}\n${pre}\n For each position i of T:\n Set b to the letter of T at i.\n ${/^If /.test(one) ? one : `If ${one}, add 1 to Count.`}\n The answer is Count.\n\n${kinds}`;
|
||||
else if (sec.title === 'Values') src = `${head}\n${pre}\n For each position i of T:\n Set X to ${one}.\n The answer is Count.\n\n${kinds}`;
|
||||
else src = `${head}\n${pre}\n Start with i at 0.\n${/\bb\b/.test(one) && !/\bB\b/.test(one) ? ' Set b to the letter of T at i.\n' : ''} ${one}\n The answer is Count.\n\n${/complement/.test(one) ? defs + '\n\n' : ''}${kinds}${/^Swap/.test(one) ? ' B is a whole number.' : ''}`;
|
||||
const r = readLingo(src);
|
||||
const tolerated = ['pronoun', 'kind-clash', 'unset-read', 'borrowed-input', 'which-letter', 'never-read', 'unreachable'];
|
||||
const errs = r.diagnostics.filter((d) => d.severity === 'error' && !tolerated.includes(d.id));
|
||||
if (errs.length) failures.push(`${e.term} → "${one}": ${errs.map((d) => d.id + ': ' + d.message.slice(0, 100)).join(' | ')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.deepEqual(failures, []);
|
||||
});
|
||||
|
||||
test('every lingo ambiguity example raises exactly the question it documents', () => {
|
||||
const sec = LINGO_REF.sections.find((s) => s.id === 'lingo-questions');
|
||||
for (const e of sec.entries) {
|
||||
const r = readLingo(e.example);
|
||||
assert.ok(r.diagnostics.some((d) => d.id === e.term), `${e.term}: got ${r.diagnostics.map((d) => d.id).join(', ')}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('every speco example parses, and the symbol table round-trips', () => {
|
||||
const sec = SPECO_REF.sections.find((s) => s.id === 'speco-forms');
|
||||
for (const e of sec.entries) {
|
||||
const m = parseSpeco(e.example);
|
||||
assert.ok(m.ok, `${e.term}: ${m.diagnostics.map((d) => d.message).join(' | ')}`);
|
||||
}
|
||||
for (const s of SPECO_SYMBOLS) {
|
||||
if (s.math.length !== 1) continue;
|
||||
assert.equal(toAscii(`A ${s.math} B`), `A ${s.ascii} B`);
|
||||
assert.equal(toMath(`A ${s.ascii} B`), `A ${s.math} B`);
|
||||
}
|
||||
});
|
||||
|
||||
test('every instruction has a gloss and a hover; setup examples parse', () => {
|
||||
for (const op of Object.keys(OPS)) assert.ok(explain('asm', op)?.body, `${op} has no gloss`);
|
||||
for (const e of ASM_REF.sections.find((s) => s.id === 'asm-registers').entries) assert.ok(explain('asm', e.term), e.term);
|
||||
assert.ok(parseAsm(' mov rax, [rbx]\n ret\n').ok);
|
||||
assert.ok(REFERENCE.length === 5);
|
||||
});
|
||||
|
||||
test('every pseudo idiom runs and prints what its note says', async () => {
|
||||
const { runPseudo } = await import('../dist/services/pseudo.js');
|
||||
const { KEYWORDS: KW, BUILTINS: BI, CONTEXTUAL } = await import('../dist/engines/pseudo/lang.js');
|
||||
const sec = PSEUDO_REF.sections.find((s) => s.id === 'pseudo-idioms');
|
||||
assert.ok(sec.entries.length >= 8);
|
||||
for (const e of sec.entries) {
|
||||
const st = studyOf(e.example);
|
||||
const errs = st.diagnostics.filter((d) => d.severity === 'error');
|
||||
assert.equal(errs.length, 0, `${e.term}: ${errs.map((d) => `L${d.line} ${d.message}`).join(' | ')}`);
|
||||
const tr = runPseudo(st, { input: [], maxSteps: 200000 });
|
||||
assert.equal(tr.error, null, `${e.term}: ${tr.error?.message}`);
|
||||
const out = tr.output.filter((l) => !/^\w+ returned /.test(l));
|
||||
assert.deepEqual(out, [e.note], e.term);
|
||||
}
|
||||
const reserved = PSEUDO_REF.sections.find((s) => s.id === 'pseudo-reserved');
|
||||
const words = new Set(reserved.entries.map((e) => e.term));
|
||||
for (const k of KW) assert.ok(words.has(k), `reserved list misses keyword ${k}`);
|
||||
for (const k of Object.keys(CONTEXTUAL)) assert.ok(words.has(k), `reserved list misses ${k}`);
|
||||
for (const k of Object.keys(BI)) assert.ok(words.has(k), `reserved list misses built-in ${k}`);
|
||||
});
|
||||
|
||||
test('every matho example translates to pseudo that checks, and every refusal is refused', () => {
|
||||
const forms = MATHO_REF.sections.find((s) => s.id === 'matho-forms');
|
||||
for (const e of forms.entries) {
|
||||
const r = parseMatho(e.example);
|
||||
const errs = r.diagnostics.filter((d) => d.severity === 'error');
|
||||
assert.ok(r.ok, `${e.term}: ${errs.map((d) => `L${d.line} ${d.id}: ${d.message}`).join(' | ')}\n${r.program.pseudo}`);
|
||||
const st = studyOf(r.program.pseudo);
|
||||
assert.ok(st.ok, `${e.term}: the pseudo does not check: ${st.diagnostics.filter((d) => d.severity === 'error').map((d) => d.message).join(' | ')}`);
|
||||
}
|
||||
for (const src of ['y = \\int_0^1 x dx', 's = \\sum_{i=0}^{\\infty} x_i', 'y = \\lim_{x \\to 0} x', 'y = \\partial f', 'y = a \\pm b', 'a = b = c']) {
|
||||
const r = parseMatho(src);
|
||||
assert.equal(r.ok, false, `${src} should be refused`);
|
||||
assert.ok(r.diagnostics.some((d) => d.severity === 'error' && /matho-(refused|pm|chain)/.test(d.id)), src);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user