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,194 @@
|
||||
// The programs the sync translators are held to: every exercise with pseudo, every program in tests/corpus/,
|
||||
// and small fixtures that each exercise one construct. Shared by the translator tests and the coverage report.
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { EXERCISES } from '../../dist/exercises/index.js';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
export const corpusDir = path.join(here, '..', 'corpus');
|
||||
|
||||
/** One construct each, with the call that runs it. */
|
||||
export const FIXTURES = {
|
||||
'fixture:loop-step': [`FUNCTION EVERY_THIRD(L : LIST OF INTEGER) RETURNS INTEGER
|
||||
DECLARE Total : INTEGER
|
||||
Total <- 0
|
||||
FOR I <- 0 TO LENGTH(L) STEP 3
|
||||
Total <- Total + L[I]
|
||||
NEXT I
|
||||
RETURN Total
|
||||
ENDFUNCTION`, 'EVERY_THIRD([1, 2, 3, 4, 5, 6, 7])'],
|
||||
'fixture:loop-down': [`FUNCTION COUNTDOWN(N : INTEGER) RETURNS INTEGER
|
||||
DECLARE Total : INTEGER
|
||||
Total <- 0
|
||||
FOR I <- N TO 0 STEP -1
|
||||
Total <- Total * 2 + I
|
||||
NEXT I
|
||||
RETURN Total
|
||||
ENDFUNCTION`, 'COUNTDOWN(4)'],
|
||||
'fixture:break-continue': [`FUNCTION FIRST_BIG(L : LIST OF INTEGER, M : INTEGER) RETURNS INTEGER
|
||||
DECLARE Found : INTEGER
|
||||
Found <- -1
|
||||
FOR I <- 0 TO LENGTH(L)
|
||||
IF L[I] < 0 THEN
|
||||
CONTINUE
|
||||
ENDIF
|
||||
IF L[I] > M THEN
|
||||
Found <- L[I]
|
||||
BREAK
|
||||
ENDIF
|
||||
NEXT I
|
||||
RETURN Found
|
||||
ENDFUNCTION`, 'FIRST_BIG([1, -5, 7, 20], 6)'],
|
||||
'fixture:early-return': [`FUNCTION HAS_NEG(L : LIST OF INTEGER) RETURNS BOOL
|
||||
FOR EACH X IN L
|
||||
IF X < 0 THEN
|
||||
RETURN TRUE
|
||||
ENDIF
|
||||
NEXT X
|
||||
RETURN FALSE
|
||||
ENDFUNCTION`, 'HAS_NEG([1, 2, -3])'],
|
||||
'fixture:min-max': [`FUNCTION SPAN(L : LIST OF INTEGER) RETURNS INTEGER
|
||||
DECLARE Lo : INTEGER
|
||||
DECLARE Hi : INTEGER
|
||||
Lo <- L[0]
|
||||
Hi <- L[0]
|
||||
FOR EACH X IN L
|
||||
Lo <- MIN(Lo, X)
|
||||
Hi <- MAX(Hi, X + 0)
|
||||
NEXT X
|
||||
RETURN Hi - Lo
|
||||
ENDFUNCTION`, 'SPAN([4, 9, 2, 7])'],
|
||||
'fixture:string-build': [`FUNCTION DOUBLED(T : STRING) RETURNS STRING
|
||||
DECLARE Out : STRING
|
||||
Out <- ""
|
||||
FOR EACH C IN T
|
||||
Out <- Out & C & C
|
||||
NEXT C
|
||||
RETURN Out
|
||||
ENDFUNCTION`, 'DOUBLED("GATTACA")'],
|
||||
'fixture:slice': [`FUNCTION HEAD3(T : STRING) RETURNS STRING
|
||||
RETURN SLICE(T, 0, 3)
|
||||
ENDFUNCTION`, 'HEAD3("GATTACA")'],
|
||||
'fixture:set': [`FUNCTION DISTINCT(T : STRING) RETURNS INTEGER
|
||||
DECLARE Seen : SET OF CHAR
|
||||
FOR EACH C IN T
|
||||
ADD(Seen, C)
|
||||
NEXT C
|
||||
RETURN LENGTH(Seen)
|
||||
ENDFUNCTION`, 'DISTINCT("GATTACA")'],
|
||||
'fixture:routine-calls': [`FUNCTION DOUBLE(N : INTEGER) RETURNS INTEGER
|
||||
RETURN N * 2
|
||||
ENDFUNCTION
|
||||
FUNCTION QUAD(N : INTEGER) RETURNS INTEGER
|
||||
RETURN DOUBLE(DOUBLE(N))
|
||||
ENDFUNCTION`, 'QUAD(3)'],
|
||||
'fixture:procedure': [`PROCEDURE NOTE_SQUARE(N : INTEGER)
|
||||
OUTPUT N, " ", N * N
|
||||
ENDPROCEDURE
|
||||
PROCEDURE RUN(N : INTEGER)
|
||||
CALL NOTE_SQUARE(N)
|
||||
CALL NOTE_SQUARE(N + 1)
|
||||
ENDPROCEDURE`, 'RUN(3)'],
|
||||
'fixture:case': [`FUNCTION GRADE(S : INTEGER) RETURNS STRING
|
||||
DECLARE G : STRING
|
||||
CASE OF S
|
||||
90 TO 101 : G <- "A"
|
||||
80 TO 90 : G <- "B"
|
||||
OTHERWISE : G <- "C"
|
||||
ENDCASE
|
||||
RETURN G
|
||||
ENDFUNCTION`, 'GRADE(85)'],
|
||||
'fixture:float-literal': [`FUNCTION HALF(N : INTEGER) RETURNS FLOAT
|
||||
DECLARE X : FLOAT
|
||||
X <- 0.5
|
||||
RETURN X * N
|
||||
ENDFUNCTION`, 'HALF(3)'],
|
||||
'fixture:div-mod': [`FUNCTION DIGITS(N : INTEGER) RETURNS INTEGER
|
||||
DECLARE M : INTEGER
|
||||
DECLARE C : INTEGER
|
||||
M <- N
|
||||
C <- 0
|
||||
WHILE M > 0
|
||||
M <- M DIV 10
|
||||
C <- C + 1
|
||||
ENDWHILE
|
||||
RETURN C + N MOD 7
|
||||
ENDFUNCTION`, 'DIGITS(12345)'],
|
||||
'fixture:forall': [`FUNCTION SORTED_UP(L : LIST OF INTEGER) RETURNS BOOL
|
||||
RETURN FORALL K IN [0, LENGTH(L) - 1) : L[K] <= L[K + 1]
|
||||
ENDFUNCTION`, 'SORTED_UP([1, 2, 3])'],
|
||||
'fixture:comments': [`// compute it
|
||||
FUNCTION TWICE(N : INTEGER) RETURNS INTEGER
|
||||
// set up
|
||||
DECLARE R : INTEGER
|
||||
R <- N * 2 // doubled
|
||||
RETURN R
|
||||
ENDFUNCTION`, 'TWICE(4)'],
|
||||
'fixture:list-item': [`FUNCTION BUMP(L : LIST OF INTEGER) RETURNS LIST OF INTEGER
|
||||
DECLARE Out : LIST OF INTEGER
|
||||
FOR EACH X IN L
|
||||
APPEND(Out, X + 1)
|
||||
NEXT X
|
||||
Out[0] <- 99
|
||||
RETURN Out
|
||||
ENDFUNCTION`, 'BUMP([1, 2, 3])'],
|
||||
'fixture:value-set-in-branch': [`FUNCTION SIGN_WORD(N : INTEGER) RETURNS STRING
|
||||
DECLARE W : STRING
|
||||
IF N < 0 THEN
|
||||
W <- "minus"
|
||||
ELSEIF N == 0 THEN
|
||||
W <- "zero"
|
||||
ELSE
|
||||
W <- "plus"
|
||||
ENDIF
|
||||
RETURN W
|
||||
ENDFUNCTION`, 'SIGN_WORD(-4)'],
|
||||
};
|
||||
|
||||
/** Every program: { id, name, pseudo, call, input }. */
|
||||
export function programs() {
|
||||
const out = [];
|
||||
for (const e of EXERCISES) if (e.sources.pseudo) out.push({ id: `ex:${e.id}`, name: e.id, pseudo: e.sources.pseudo, call: e.call ?? null, input: [] });
|
||||
for (const f of fs.readdirSync(corpusDir).filter((x) => x.endsWith('.pseudo')).sort()) {
|
||||
const src = fs.readFileSync(path.join(corpusDir, f), 'utf8');
|
||||
out.push({ id: f, name: f, pseudo: src, call: null, input: [...src.matchAll(/^\/\/ INPUT: (.*)$/gm)].map((m) => m[1]) });
|
||||
}
|
||||
for (const [id, [pseudo, call]] of Object.entries(FIXTURES)) out.push({ id, name: id, pseudo, call, input: [] });
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Remove // comments and blank lines: the lowering strips comments, so a round trip never brings them back. */
|
||||
export const stripComments = (t) => t.split('\n').map((l) => l.replace(/\s*\/\/.*$/, '')).filter((l) => l.trim()).join('\n');
|
||||
|
||||
/** [matho source, a call that runs its last function]. The same sets tests/matho.test.mjs runs. */
|
||||
export const EQUATIONS = {
|
||||
'mean-and-variance': ['\\bar{x} = \\frac{1}{n} \\sum_{i=0}^{n-1} x_i\n\\sigma^2 = \\frac{1}{n - 1} \\sum_{i=0}^{n-1} (x_i - \\bar{x})^2', 'SIGMA_SQUARED(4, [2.0, 4.0, 4.0, 6.0])'],
|
||||
'mean': ['\\bar{x} = \\frac{1}{n} \\sum_{i=0}^{n-1} x_i', 'X_BAR(4, [2.0, 4.0, 4.0, 6.0])'],
|
||||
'sum-from-one': ['\\bar{x} = \\frac{1}{n} \\sum_{i=1}^{n} x_i', 'X_BAR(4, [1.0, 2.0, 3.0, 4.0])'],
|
||||
'sum-no-bounds': ['S = \\sum_i x_i^2', 'S([1.0, 2.0, 3.0])'],
|
||||
'binomial': ['P(k) = \\binom{n}{k} p^k (1 - p)^{n - k}', 'P(2, 4, 0.5)'],
|
||||
'height': ['h(t) = v_0 t - \\frac{1}{2} g t^2', 'H(2.0, 10.0, 9.81)'],
|
||||
'kinetic': ['\\mathrm{KE} = \\frac{1}{2} m v^2', 'KE(3.0, 4.0)'],
|
||||
'gravity': ['F = \\frac{G m_1 m_2}{r^2}', 'F(2.0, 3.0, 4.0, 2.0)'],
|
||||
'omega': ['\\omega = 2 \\pi f', 'OMEGA(0.5)'],
|
||||
'normal-density': ['f(x) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}}', 'F(0.0, 1.0, 0.0)'],
|
||||
'ph': ['\\text{pH} = -\\log_{10} [H]', 'PH(0.001)'],
|
||||
'log2': ['b = \\log_2 n', 'B(8.0)'],
|
||||
'ln-and-log': ['y = \\ln x + \\log x', 'Y(10.0)'],
|
||||
'factorial': ['n! = \\prod_{k=1}^{n} k', 'FACTORIAL(5)'],
|
||||
'choose': ['c = \\frac{n!}{k! (n-k)!}', 'C(5, 2)'],
|
||||
'cosine': ['\\cos\\theta = \\frac{\\vec{a} \\cdot \\vec{b}}{\\|\\vec{a}\\| \\, \\|\\vec{b}\\|}', 'COS_THETA([1.0, 0.0], [1.0, 0.0])'],
|
||||
'distance': ['d = \\sqrt{\\sum_{i=0}^{n-1} (p_i - q_i)^2}', 'D(2, [0.0, 0.0], [3.0, 4.0])'],
|
||||
'matrix-row': ['y_i = \\sum_{j=0}^{n-1} A_{ij} x_j', 'Y(1, 2, [[1.0, 2.0], [3.0, 4.0]], [1.0, 1.0])'],
|
||||
'nested-sums': ['s = \\sum_{i=0}^{n-1} \\sum_{j=0}^{m-1} a_{ij}', 'S(2, 2, [[1.0, 2.0], [3.0, 4.0]])'],
|
||||
'relu': ['\\mathrm{relu}(x) = \\begin{cases} 0 & \\text{if } x < 0 \\\\ x & \\text{otherwise} \\end{cases}', 'RELU(-2.0)'],
|
||||
'piecewise': ['f(x) = \\begin{cases} 0 & x < 0 \\\\ x & 0 \\le x < 1 \\\\ 2 - x & 1 \\le x \\le 2 \\\\ 0 & \\text{otherwise} \\end{cases}', 'F(1.5)'],
|
||||
'calls-an-earlier-equation': ['g(x) = x^2 + 1\nh(x) = 2 g(x) + c', 'H(3.0, 1.0)'],
|
||||
'sum-over-a-set': ['m = \\sum_{x \\in S} x', 'M([1.0, 2.0, 3.5])'],
|
||||
'floor': ['h = \\lfloor n / 2 \\rfloor', 'H(7)'],
|
||||
'ceiling': ['h = \\lceil n / 2 \\rceil', 'H(7)'],
|
||||
'absolute': ['d = |a - b|', 'D(2.0, 5.0)'],
|
||||
'max-min': ['m = \\max(a, b) - \\min(a, b)', 'M(2.0, 5.0)'],
|
||||
'mod': ['r = a \\bmod b', 'R(7, 3)'],
|
||||
};
|
||||
Reference in new issue
Block a user