Compare commits
3
Commits
d1955ad358
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75c1d466da
|
||
|
|
5202c96318
|
||
|
|
7000662539
|
No files matched your search
@@ -26,6 +26,7 @@ No version has been tagged yet. What programs mean is pplus-core's, and its chan
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- The Prove view's time limit is the reader's to set: 3 seconds for each routine as before, or 10, 30 or 120, kept in the browser. When the time, not the proof, stopped the checker (a slow or busy device), the view says so, says that what was not finished is open and not disproved, and offers to prove again with more. A proof rendered with Quarto takes `prove-seconds` on the shortcode or `pplus-prove-seconds` for the site, and the render warns when the time ran out.
|
||||||
- `THIRD_PARTY.md`, with the copyright notice of every package bundled into the editor, and a test that holds it to the bundle, the copied stylesheets, the fonts and the locks.
|
- `THIRD_PARTY.md`, with the copyright notice of every package bundled into the editor, and a test that holds it to the bundle, the copied stylesheets, the fonts and the locks.
|
||||||
- The Apache License 2.0, a NOTICE, contributing rules, a security policy, a code of conduct, and a citation file.
|
- The Apache License 2.0, a NOTICE, contributing rules, a security policy, a code of conduct, and a citation file.
|
||||||
- A footer with the license, the notices, the disclaimer about Modular, the build's commit, and "What this site stores and sends", each statement held to the code by a test.
|
- A footer with the license, the notices, the disclaimer about Modular, the build's commit, and "What this site stores and sends", each statement held to the code by a test.
|
||||||
@@ -34,6 +35,8 @@ No version has been tagged yet. What programs mean is pplus-core's, and its chan
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- A proved routine is no longer said to have run out of time when only the generated inputs that cross-check it were cut short (core `941af6b`): in a container running the tests on two processors the Quarto gallery's proved example got that warning. The tests that hold what a proof finds give it time to spare.
|
||||||
|
- The home page shows at once. It was blank until every module had loaded and the page's examples had been run, a fuzzer's report among them: first paint came after 1.3 seconds on a repeat visit and about 3 on a first one. The assembled site now carries the home page already drawn (`scripts/assemble-page.mjs`, `src/ui/prerender.ts`), painted with the HTML; the app takes its place when it has loaded, without running the fuzzer and the prover again. Measured on the assembled site served locally: first paint 0.1 to 0.2 seconds, the page with its controls at 0.2 to 0.3 (it was 1.2 to 1.4 for both). The inline script of `index.html` changed, and its hash in `docs/Caddyfile` with it.
|
||||||
- The deploy job publishes to `/srv/www/pplus`, the directory the site is served from, unless `SITE_SLUG` says otherwise. Its default was the repository's name, so the job published to `/srv/www/pplus-web` and the live site did not change.
|
- The deploy job publishes to `/srv/www/pplus`, the directory the site is served from, unless `SITE_SLUG` says otherwise. Its default was the repository's name, so the job published to `/srv/www/pplus-web` and the live site did not change.
|
||||||
- The deploy job's smoke test always runs on `main`: it asks the live site for its version after publishing, at `https://pplus.scient.ing` unless `SITE_URL` names another address. It ran only when that variable was set, and it was not.
|
- The deploy job's smoke test always runs on `main`: it asks the live site for its version after publishing, at `https://pplus.scient.ing` unless `SITE_URL` names another address. It ran only when that variable was set, and it was not.
|
||||||
- `docs/Caddyfile` served the page in place at a missing nested path, where its own files could not be found (a blank page). A missing page is sent to `/`; a missing file is a plain 404.
|
- `docs/Caddyfile` served the page in place at a missing nested path, where its own files could not be found (a blank page). A missing page is sent to `/`; a missing file is a plain 404.
|
||||||
|
|||||||
+1
-1
Submodule core updated: b10a5c87a3...941af6bc78.
+1
-1
@@ -23,7 +23,7 @@
|
|||||||
# X-Frame-Options here; framing is allowed from the course
|
# X-Frame-Options here; framing is allowed from the course
|
||||||
# origins, and from a local `quarto preview` of them.
|
# origins, and from a local `quarto preview` of them.
|
||||||
header {
|
header {
|
||||||
Content-Security-Policy "default-src 'self'; script-src 'self' 'sha256-I0FTUDEvZjevwnUsTxL/Wv6yjSk4+kJk+rHFqkJdfzU=' 'sha256-RDS2ylVnVHGfhqa7CxiLHKiZwFxVxLSwfQQ6NYsJmuM='; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self' data: blob:; connect-src 'self' https://godbolt.org; frame-src 'self'; worker-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'self' https://scient.ing https://*.scient.ing http://localhost:* http://127.0.0.1:*"
|
Content-Security-Policy "default-src 'self'; script-src 'self' 'sha256-H7kdvxp0TUI4FRNjpz2GbeB4zUUFSA0SVJWlzJL2bb8=' 'sha256-RDS2ylVnVHGfhqa7CxiLHKiZwFxVxLSwfQQ6NYsJmuM='; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self' data: blob:; connect-src 'self' https://godbolt.org; frame-src 'self'; worker-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'self' https://scient.ing https://*.scient.ing http://localhost:* http://127.0.0.1:*"
|
||||||
Referrer-Policy "no-referrer"
|
Referrer-Policy "no-referrer"
|
||||||
X-Content-Type-Options "nosniff"
|
X-Content-Type-Options "nosniff"
|
||||||
Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=(), clipboard-write=(self)"
|
Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=(), clipboard-write=(self)"
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ A student can save the state of their work under a name and come back to any sav
|
|||||||
|
|
||||||
**Work that takes the page down.** The engines stop a program that runs too long or makes values too large (core's [limits.md](../core/docs/limits.md)), but should a program still use up the tab's memory first, the browser kills the page. Saved work runs again as the page opens, so before it runs its save is marked busy in this tab (`src/core/guard.ts`, in `sessionStorage`), and the mark is cleared once the page has been idle for a moment and when it closes normally. A reload that finds the mark puts that save aside as a named version, "When the page stopped (time)", opens the problem as written, and says so; an embed drops the reader's edits instead. If a saved state makes the page fail in any other way, the page that says so offers the same: keep the work as a version and open the problem as written.
|
**Work that takes the page down.** The engines stop a program that runs too long or makes values too large (core's [limits.md](../core/docs/limits.md)), but should a program still use up the tab's memory first, the browser kills the page. Saved work runs again as the page opens, so before it runs its save is marked busy in this tab (`src/core/guard.ts`, in `sessionStorage`), and the mark is cleared once the page has been idle for a moment and when it closes normally. A reload that finds the mark puts that save aside as a named version, "When the page stopped (time)", opens the problem as written, and says so; an embed drops the reader's edits instead. If a saved state makes the page fail in any other way, the page that says so offers the same: keep the work as a version and open the problem as written.
|
||||||
|
|
||||||
|
The home page is the one page that is drawn before the app starts: the assembled site carries it prerendered (`docs/deploy.md`), and `homeView` then takes its place. A part of it that is costly to work out and holds no control is wrapped in `kept(key, build)` (`src/ui/prerender.ts`), which copies it from the prerendered page; give a new part of that kind the same wrapper, and never one with a listener, since a copy has none.
|
||||||
|
|
||||||
Nothing else is a route: `#/p/<problem>`, `#/s/<state>` and the other earlier forms open the home page, with a note at the foot of the page that there is no page at that address (`isUnknownRoute` in `src/core/state.ts`). A problem or library routine that does not exist, in the app or in an embed, is a page that says so (in the app it keeps the site's navigation and links the problem list); so is a link that does not open (below). `<view>` is `playground` (the whole workspace; `?area=dev` picks the area, Bridge by default or the problem's own), `trace`, `table`, `flow`, `data`, `life`, `proof`, `tests`, `problems`, `compiler`, `asm` (the machine numbers), or a pane name (`lingo`, `pseudo`, `speco`, `mojo`, `asm`) to show just that editor with its problems under it. Query parameters on an embed: `?t=12` parks the stepper, `?ro=1` makes the editor read-only; `area`, `panel`, `lang`, `build`, `machine`, `dock`, `docktab`, `editor`, `side`, `dockheight` and `theme` arrange the example as the playground's controls do (`applyEmbedParams` in `src/core/state.ts`).
|
Nothing else is a route: `#/p/<problem>`, `#/s/<state>` and the other earlier forms open the home page, with a note at the foot of the page that there is no page at that address (`isUnknownRoute` in `src/core/state.ts`). A problem or library routine that does not exist, in the app or in an embed, is a page that says so (in the app it keeps the site's navigation and links the problem list); so is a link that does not open (below). `<view>` is `playground` (the whole workspace; `?area=dev` picks the area, Bridge by default or the problem's own), `trace`, `table`, `flow`, `data`, `life`, `proof`, `tests`, `problems`, `compiler`, `asm` (the machine numbers), or a pane name (`lingo`, `pseudo`, `speco`, `mojo`, `asm`) to show just that editor with its problems under it. Query parameters on an embed: `?t=12` parks the stepper, `?ro=1` makes the editor read-only; `area`, `panel`, `lang`, `build`, `machine`, `dock`, `docktab`, `editor`, `side`, `dockheight` and `theme` arrange the example as the playground's controls do (`applyEmbedParams` in `src/core/state.ts`).
|
||||||
|
|
||||||
A reader's edits in an embed are saved in their browser, in that embed's own save (one per embedded example, shared by pages that embed the same one), never in the app's save for the problem. Once they have changed something, **Reset** appears beside "open in Programming+" and puts the author's version back. An embed keeps a save only while it holds edits, so a reader who has not changed an example always sees the author's current version. A read-only embed (`?ro=1`) saves nothing.
|
A reader's edits in an embed are saved in their browser, in that embed's own save (one per embedded example, shared by pages that embed the same one), never in the app's save for the problem. Once they have changed something, **Reset** appears beside "open in Programming+" and puts the author's version back. An embed keeps a save only while it holds edits, so a reader who has not changed an example always sees the author's current version. A read-only embed (`?ro=1`) saves nothing.
|
||||||
@@ -131,6 +133,7 @@ The **Share** button in the app produces the app link, a ready-to-paste `<iframe
|
|||||||
- **Mojo for every exercise with pseudo**: each has its Mojo in `core/library/mojo/local/`, so the Developer and Hardware areas always have something to show for it; `core/tests/mojo.test.mjs` runs each Mojo program in the interpreter and checks it prints what the exercise expects.
|
- **Mojo for every exercise with pseudo**: each has its Mojo in `core/library/mojo/local/`, so the Developer and Hardware areas always have something to show for it; `core/tests/mojo.test.mjs` runs each Mojo program in the interpreter and checks it prints what the exercise expects.
|
||||||
- **Panes**: the area's own (see the table above), dimmed when empty (a dimmed tab opens an empty pane to write in), as tabs over one editor (CodeMirror: search and replace with Ctrl+F, go to line with Ctrl+G, bracket matching, undo and redo; Tab indents, Ctrl+/ comments). The editor is never split: in the Bridge a short note in the pane head says the other tabs update as you type (lingo and matho update the pseudo, and the pseudo the Mojo made from it), and clicking a line marks the lines it became in the next tab down; Hardware does the same between Mojo and x86-64. Drag the dividers to resize (double-click resets); the widths, the dock tab, and what is folded are remembered in the share link.
|
- **Panes**: the area's own (see the table above), dimmed when empty (a dimmed tab opens an empty pane to write in), as tabs over one editor (CodeMirror: search and replace with Ctrl+F, go to line with Ctrl+G, bracket matching, undo and redo; Tab indents, Ctrl+/ comments). The editor is never split: in the Bridge a short note in the pane head says the other tabs update as you type (lingo and matho update the pseudo, and the pseudo the Mojo made from it), and clicking a line marks the lines it became in the next tab down; Hardware does the same between Mojo and x86-64. Drag the dividers to resize (double-click resets); the widths, the dock tab, and what is folded are remembered in the share link.
|
||||||
- **The side column** is the inspect panel. Its tabs are offered only when they mean something for the pane (Prove for the pseudo family) and dimmed, with the reason, when the run has nothing for them yet.
|
- **The side column** is the inspect panel. Its tabs are offered only when they mean something for the pane (Prove for the pseudo family) and dimmed, with the reason, when the run has nothing for them yet.
|
||||||
|
- **Prove has a time limit the reader sets.** The prover's work is counted, the same on every machine; behind that it stops at a time on the clock, 3 seconds for each routine, so a page never waits long. On a slow or busy device 3 seconds can run out before the proof does. Core's report says when (`ProofReport.clock`), and the view then says "Time ran out" on those routines, that what was not finished is open and not disproved, and offers to prove again with the next longer time. The setting itself is at the foot of the view: 3, 10 or 30 seconds or 2 minutes for each routine (`src/core/proveclock.ts`, kept in this browser as `pplus.proveclock`; `Session.setProofClock` proves again). More time never proves anything that is not true. The home page's own example is proved with no time on the clock, so it reads the same on every device; a page rendered with Quarto takes `prove-seconds` (`quarto/README.md`).
|
||||||
- **The Run view** (the first tab, in the Bridge and the Developer area; `src/core/runview.ts`, drawn by `src/ui/views/run.ts`) is the whole run read top to bottom, one row per step: its number, its line, what ran (indented by call depth, with what it printed), and a column for each variable you **follow**, holding its value after that step: in color where the step wrote it (with the position, `[5, 6]`, when it wrote one element), faded where it carries over, underlined where the step reads it, hatched where it is not in scope. The lifecycle of the value a variable names (Mojo: made ●, copied ⧉, moved in ⇢, moved out ⇥, destroyed ✕) is marked in the same cell; events of values no column names are noted beside the step. Above the rows, the followed variables as they stand at the stepper's position, with a ruler for a string or list and a grid for a table, the element just written and the one about to be read marked. **+ variables** opens a picker of every variable in the run, by routine; until you choose, it follows the variables of the routine that does the most work. The choice is kept per area (`layout.follow`). "Only steps that change something" hides the rest. Click a row to step there; the stepper keeps its row in view. It replaces the Variables panel, the trace table, the table of values and the Lifetimes tab, which each showed part of this.
|
- **The Run view** (the first tab, in the Bridge and the Developer area; `src/core/runview.ts`, drawn by `src/ui/views/run.ts`) is the whole run read top to bottom, one row per step: its number, its line, what ran (indented by call depth, with what it printed), and a column for each variable you **follow**, holding its value after that step: in color where the step wrote it (with the position, `[5, 6]`, when it wrote one element), faded where it carries over, underlined where the step reads it, hatched where it is not in scope. The lifecycle of the value a variable names (Mojo: made ●, copied ⧉, moved in ⇢, moved out ⇥, destroyed ✕) is marked in the same cell; events of values no column names are noted beside the step. Above the rows, the followed variables as they stand at the stepper's position, with a ruler for a string or list and a grid for a table, the element just written and the one about to be read marked. **+ variables** opens a picker of every variable in the run, by routine; until you choose, it follows the variables of the routine that does the most work. The choice is kept per area (`layout.follow`). "Only steps that change something" hides the rest. Click a row to step there; the stepper keeps its row in view. It replaces the Variables panel, the trace table, the table of values and the Lifetimes tab, which each showed part of this.
|
||||||
- **The Tests tab** is a fuzzer that shows its work (`core/src/common/fuzz.ts`, drawn by `src/ui/views/tests.ts`). For each routine (the pseudo's, with the speco woven in; or each Mojo function other than `main`) it lists **what each input must do** (finish within the step limit; raise no runtime error, or for Mojo no abort and no uncaught raise; keep every REQUIRE, ENSURE, INVARIANT, DECREASES and ASSERT, with inputs that break a REQUIRE skipped rather than failed; give the same answer when run again), **how the inputs were made** (each parameter's generator, with the values it tries first, and each strategy with how many inputs it made: edge cases in combination, every DNA string up to three letters for a routine that reads one, seeded random values, and mutations of the inputs that reached a line nothing earlier had reached, as a coverage-guided fuzzer does), each **failure** with the case that found it and every step of shrinking it to a smaller input that still fails the same way (the shrinking is greedy, so the input it ends on is the smallest it found, not always the smallest there is) (**Step through this input** puts that call in the call box and shows the run), the **lines reached** by how many inputs (a line no input reached is flagged), the **answers** given and how often, and **every case** run with its strategy, input, outcome, answer or error, and steps, filterable by outcome and strategy. The seed and the number of inputs (100 to 3,000) are chosen at the top; the same seed always makes the same inputs. `core/tests/fuzz.test.mjs` runs it on every exercise.
|
- **The Tests tab** is a fuzzer that shows its work (`core/src/common/fuzz.ts`, drawn by `src/ui/views/tests.ts`). For each routine (the pseudo's, with the speco woven in; or each Mojo function other than `main`) it lists **what each input must do** (finish within the step limit; raise no runtime error, or for Mojo no abort and no uncaught raise; keep every REQUIRE, ENSURE, INVARIANT, DECREASES and ASSERT, with inputs that break a REQUIRE skipped rather than failed; give the same answer when run again), **how the inputs were made** (each parameter's generator, with the values it tries first, and each strategy with how many inputs it made: edge cases in combination, every DNA string up to three letters for a routine that reads one, seeded random values, and mutations of the inputs that reached a line nothing earlier had reached, as a coverage-guided fuzzer does), each **failure** with the case that found it and every step of shrinking it to a smaller input that still fails the same way (the shrinking is greedy, so the input it ends on is the smallest it found, not always the smallest there is) (**Step through this input** puts that call in the call box and shows the run), the **lines reached** by how many inputs (a line no input reached is flagged), the **answers** given and how often, and **every case** run with its strategy, input, outcome, answer or error, and steps, filterable by outcome and strategy. The seed and the number of inputs (100 to 3,000) are chosen at the top; the same seed always makes the same inputs. `core/tests/fuzz.test.mjs` runs it on every exercise.
|
||||||
- **Views that follow the run**: the **Flowchart** shades by the run so far and marks the box that runs next; the **Data flow** lights up the names the next line reads and the name the last line wrote.
|
- **Views that follow the run**: the **Flowchart** shades by the run so far and marks the box that runs next; the **Data flow** lights up the names the next line reads and the name the last line wrote.
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ The site builds against pplus-core, the git submodule `core/`, at the commit thi
|
|||||||
|
|
||||||
`pixi run site` tests the app and assembles `site/`; `pixi run deploy [slug] [user@host]` does that and publishes it. CI (`.gitea/workflows/deploy.yml`) runs `pixi run ci` (the site's tests and core's `mojo-status-strict`) on every push and pull request, and on a push to `main` checks the chain of pointers (`pixi run release-check`), assembles and publishes.
|
`pixi run site` tests the app and assembles `site/`; `pixi run deploy [slug] [user@host]` does that and publishes it. CI (`.gitea/workflows/deploy.yml`) runs `pixi run ci` (the site's tests and core's `mojo-status-strict`) on every push and pull request, and on a push to `main` checks the chain of pointers (`pixi run release-check`), assembles and publishes.
|
||||||
|
|
||||||
The site is seven things: `index.html`, `styles.css`, `fonts/` (IBM Plex, served by the site so a visit asks no font host for anything; `fonts/README.md` says where the files came from), `styles/` (the course's widget styles, which the Hardware area's machine views use), `dist/`, `core/` (pplus-core's built `core/dist/`, which `index.html`'s import map names as `#core/`), and the Quarto extension (`quarto/_extensions/pplus`, without an engine copy), which the With Quarto page loads (`pplus.css`, `pplus.js`) and links to file by file. `scripts/assemble.sh` copies them into `site/` with a `VERSION` file holding the commit, a `build.json` naming the three commits the site was built from (below), and the license and notices (`LICENSE.md`, `NOTICE.md`, `THIRD_PARTY.md`, which the footer links), then `scripts/assemble-page.mjs` adds two things to `site/index.html`: the commit as `<meta name="pplus-version">`, which the footer shows, and a `<link rel="modulepreload">` for every module the page's imports reach, after the import map, so a first visit asks for all of them at once instead of one level of imports at a time (`tests/load.test.mjs` holds the list to the import graph and the inline scripts to their hashes). And `scripts/deploy.sh <slug> [user@host]` publishes `site/` to `/srv/www/<slug>` as an atomic release:
|
The site is seven things: `index.html`, `styles.css`, `fonts/` (IBM Plex, served by the site so a visit asks no font host for anything; `fonts/README.md` says where the files came from), `styles/` (the course's widget styles, which the Hardware area's machine views use), `dist/`, `core/` (pplus-core's built `core/dist/`, which `index.html`'s import map names as `#core/`), and the Quarto extension (`quarto/_extensions/pplus`, without an engine copy), which the With Quarto page loads (`pplus.css`, `pplus.js`) and links to file by file. `scripts/assemble.sh` copies them into `site/` with a `VERSION` file holding the commit, a `build.json` naming the three commits the site was built from (below), and the license and notices (`LICENSE.md`, `NOTICE.md`, `THIRD_PARTY.md`, which the footer links), then `scripts/assemble-page.mjs` adds three things to `site/index.html`: the commit as `<meta name="pplus-version">`, which the footer shows; a `<link rel="modulepreload">` for every module the page's imports reach, after the import map, so a first visit asks for all of them at once instead of one level of imports at a time; and the home page already drawn, inside `#app` (`tests/load.test.mjs` holds the list to the import graph, the inline scripts to their hashes, and the prerendered page to its place). **The home page is prerendered** because drawing it runs the engines on its own examples, a fuzzer's report among them, about a second of work that came after 150 modules had loaded: a visitor saw nothing for 1.3 to 3 seconds. The assembler draws it once in Node with the app's own `homeView` (on the small document the Quarto views use), so the browser paints it with the HTML and the stylesheet, in about a tenth of a second; when the app has loaded it draws the page again, with its controls, and puts it in the prerendered one's place, copying the two costly parts from it instead of working them out again (`src/ui/prerender.ts`). The prerendered page shows only on the home address: the page's first inline script marks it before the first paint, and without the mark it stays hidden, so an embed or a problem's address never shows the home page first. A checkout served as it is (`pixi run dev`) has no prerendered page and draws the home page as before. And `scripts/deploy.sh <slug> [user@host]` publishes `site/` to `/srv/www/<slug>` as an atomic release:
|
||||||
|
|
||||||
```
|
```
|
||||||
/srv/www/pplus -> symlink to the live release
|
/srv/www/pplus -> symlink to the live release
|
||||||
|
|||||||
+4
-1
@@ -18,7 +18,9 @@
|
|||||||
<link rel="stylesheet" href="./styles/course/tokens.css">
|
<link rel="stylesheet" href="./styles/course/tokens.css">
|
||||||
<link rel="stylesheet" href="./styles/course/kit.css">
|
<link rel="stylesheet" href="./styles/course/kit.css">
|
||||||
<link rel="stylesheet" href="./styles/course/asm86.css">
|
<link rel="stylesheet" href="./styles/course/asm86.css">
|
||||||
<script>try { var t = localStorage.getItem("pplus.theme"); if (t === "light" || t === "dark") document.documentElement.setAttribute("data-theme", t); } catch (e) { }</script>
|
<!-- before the first paint: whether the address is the home page, whose prerendered copy (scripts/assemble-page.mjs)
|
||||||
|
shows only then, and the reader's theme -->
|
||||||
|
<script>try { if (/^(#\/?(#.*)?)?$/.test(location.hash)) document.documentElement.setAttribute("data-home", ""); var t = localStorage.getItem("pplus.theme"); if (t === "light" || t === "dark") document.documentElement.setAttribute("data-theme", t); } catch (e) { }</script>
|
||||||
<link rel="icon"
|
<link rel="icon"
|
||||||
href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><style>rect{fill:%23f6c453}text{fill:%2316191f}@media (prefers-color-scheme:dark){rect{fill:%230e1117}text{fill:%23f0c05a}}</style><rect width='16' height='16' rx='3'/><text x='8' y='12' font-size='8' text-anchor='middle' font-family='monospace' font-weight='700'>P+</text></svg>">
|
href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><style>rect{fill:%23f6c453}text{fill:%2316191f}@media (prefers-color-scheme:dark){rect{fill:%230e1117}text{fill:%23f0c05a}}</style><rect width='16' height='16' rx='3'/><text x='8' y='12' font-size='8' text-anchor='middle' font-family='monospace' font-weight='700'>P+</text></svg>">
|
||||||
</head>
|
</head>
|
||||||
@@ -28,6 +30,7 @@
|
|||||||
<!-- replaced as soon as the app starts; shown only if it has not after a few seconds (styles.css, .boot-note) -->
|
<!-- replaced as soon as the app starts; shown only if it has not after a few seconds (styles.css, .boot-note) -->
|
||||||
<p class="boot-note">Programming+ did not start. It has to be served by a web server (<code>pixi run dev</code>,
|
<p class="boot-note">Programming+ did not start. It has to be served by a web server (<code>pixi run dev</code>,
|
||||||
or the site), not opened as a file, and its scripts must be allowed to run. Reload to try again.</p>
|
or the site), not opened as a file, and its scripts must be allowed to run. Reload to try again.</p>
|
||||||
|
<!--prerendered-home-->
|
||||||
</div>
|
</div>
|
||||||
<!-- pplus-core's modules (core/, a git submodule built into core/dist): the app imports them as #core/... -->
|
<!-- pplus-core's modules (core/, a git submodule built into core/dist): the app imports them as #core/... -->
|
||||||
<script type="importmap">{ "imports": { "#core/": "./core/dist/" } }</script>
|
<script type="importmap">{ "imports": { "#core/": "./core/dist/" } }</script>
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ syntax-definitions:
|
|||||||
pplus-engine: ../programming-plus # a built Programming+ (its folder, or its dist/)
|
pplus-engine: ../programming-plus # a built Programming+ (its folder, or its dist/)
|
||||||
pplus-url: "https://pplus.scient.ing" # where the live views point (this is the default)
|
pplus-url: "https://pplus.scient.ing" # where the live views point (this is the default)
|
||||||
pplus-strict: true # optional: a view that cannot be rendered, or a run that does not print its EXPECT lines, stops the render
|
pplus-strict: true # optional: a view that cannot be rendered, or a run that does not print its EXPECT lines, stops the render
|
||||||
|
pplus-prove-seconds: 30 # optional: the seconds the prover has for each routine of a rendered proof (default 3)
|
||||||
```
|
```
|
||||||
|
|
||||||
`mojo.xml` is generated from the same words as the Mojo pane's highlighter (the compiler's own token table, at the pinned Mojo version). A printed listing therefore colors `mut`, `deinit`, the transfer `^`, and removed words such as `fn` exactly as the pane does. If the project already has its own `pseudo.xml`, keep that and add only `lingo.xml`.
|
`mojo.xml` is generated from the same words as the Mojo pane's highlighter (the compiler's own token table, at the pinned Mojo version). A printed listing therefore colors `mut`, `deinit`, the transfer `^`, and removed words such as `fn` exactly as the pane does. If the project already has its own `pseudo.xml`, keep that and add only `lingo.xml`.
|
||||||
@@ -122,10 +123,13 @@ And these work with the rendered ones:
|
|||||||
| `height` | the live frame's height when it is put in place (default 520; 720 for translate and the machine's views, which open the whole playground) |
|
| `height` | the live frame's height when it is put in place (default 520; 720 for translate and the machine's views, which open the whole playground) |
|
||||||
| `follow` | steps: the variables to show, comma-separated |
|
| `follow` | steps: the variables to show, comma-separated |
|
||||||
| `max` | steps: the most steps kept (default 400; from 10 to 5000) |
|
| `max` | steps: the most steps kept (default 400; from 10 to 5000) |
|
||||||
|
| `prove-seconds` | proof: the seconds the prover has for each routine (default 3, or the site's `pplus-prove-seconds`) |
|
||||||
| `to`, `layout` | translate: the notations to show, comma-separated; `tabs` (default), `columns` or `grid` |
|
| `to`, `layout` | translate: the notations to show, comma-separated; `tabs` (default), `columns` or `grid` |
|
||||||
| `compiler` | run, for a Mojo file: `auto`, `on` or `off` |
|
| `compiler` | run, for a Mojo file: `auto`, `on` or `off` |
|
||||||
| `column` | Quarto's column for the view (`page`, `screen`, `margin`, ...) |
|
| `column` | Quarto's column for the view (`page`, `screen`, `margin`, ...) |
|
||||||
|
|
||||||
|
**A proof has a time limit.** The prover's work is counted and is the same on every machine, but it also stops at a time on the clock, 3 seconds for each routine as in the app, and a page is rendered once on whatever machine builds the site. If that machine is slow or busy, 3 seconds can run out before the proof does: the page then shows claims open that are provable, with a "Time ran out" note, and the render warns (`proof: time ran out on ...`). Give the prover more with `prove-seconds="30"` on the shortcode or `pplus-prove-seconds: 30` for the site; more time never proves anything that is not true. A result is kept in `.quarto/pplus/` by its request, so a new time renders again.
|
||||||
|
|
||||||
In a format other than HTML (a PDF, a Word file), a rendered view becomes Markdown. The run is printed as a code block; the steps, the table of values and the machine's counters as tables; the proof, tests and checker's findings as lists; and translate as one listing per notation. The flowchart, the data flow and the lifetimes say they are drawn in the HTML version. A view of the machine gives the registers the run has written by step `t` and names the cards drawn in the HTML version. Each view except translate is followed by a link to the app.
|
In a format other than HTML (a PDF, a Word file), a rendered view becomes Markdown. The run is printed as a code block; the steps, the table of values and the machine's counters as tables; the proof, tests and checker's findings as lists; and translate as one listing per notation. The flowchart, the data flow and the lifetimes say they are drawn in the HTML version. A view of the machine gives the registers the run has written by step `t` and names the cards drawn in the HTML version. Each view except translate is followed by a link to the app.
|
||||||
|
|
||||||
### The live views, arranged
|
### The live views, arranged
|
||||||
|
|||||||
@@ -314,6 +314,19 @@ body.quarto-dark .pplus-static,
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pplus-static .proof-timeout {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-left: 3px solid var(--warn, #b45309);
|
||||||
|
border-radius: var(--r);
|
||||||
|
padding: 6px 10px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pplus-static .proof-timeout p {
|
||||||
|
margin: 0 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
.pplus-static .proof-unit {
|
.pplus-static .proof-unit {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
-- listing pplus-hw: 0 leaves out the x86-64 listing beside the cards
|
-- listing pplus-hw: 0 leaves out the x86-64 listing beside the cards
|
||||||
-- column body | page | screen | ...: Quarto's column for the figure (pplus-hw's board is page-wide by default)
|
-- column body | page | screen | ...: Quarto's column for the figure (pplus-hw's board is page-wide by default)
|
||||||
-- stepper pplus-hw: 0 draws only step t (no stepper); max: the most steps drawn (a longer run is sampled)
|
-- stepper pplus-hw: 0 draws only step t (no stepper); max: the most steps drawn (a longer run is sampled)
|
||||||
|
-- prove-seconds proof: the seconds the prover has for each routine (default 3, or pplus-prove-seconds)
|
||||||
-- live click: a button that puts the live view in place of the rendered one
|
-- live click: a button that puts the live view in place of the rendered one
|
||||||
-- height the live frame's height in px when live="click" is pressed (default 520)
|
-- height the live frame's height in px when live="click" is pressed (default 520)
|
||||||
--
|
--
|
||||||
@@ -76,6 +77,8 @@
|
|||||||
-- looked for. none: render nothing with the page (each rendered view shows its listing and the live view)
|
-- looked for. none: render nothing with the page (each rendered view shows its listing and the live view)
|
||||||
-- pplus-node the node to run it with (default: node on the PATH)
|
-- pplus-node the node to run it with (default: node on the PATH)
|
||||||
-- pplus-strict true: a view that cannot be rendered, or a run that does not print its EXPECT lines (a program with EXPECT lines that does not run at all among them), stops the render
|
-- pplus-strict true: a view that cannot be rendered, or a run that does not print its EXPECT lines (a program with EXPECT lines that does not run at all among them), stops the render
|
||||||
|
-- pplus-prove-seconds the seconds the prover has for each routine in a rendered proof (default 3, the app's own); a
|
||||||
|
-- slow build machine can run out of 3 and show a claim open that is provable, and the render warns
|
||||||
-- pplus-cache false: render every view again each time (by default results are kept in .quarto/pplus/)
|
-- pplus-cache false: render every view again each time (by default results are kept in .quarto/pplus/)
|
||||||
|
|
||||||
local str = pandoc.utils.stringify
|
local str = pandoc.utils.stringify
|
||||||
@@ -614,6 +617,7 @@ local function static_view(view, kwargs, meta, extra)
|
|||||||
req.t = tonumber(kwarg(kwargs, "t") or "")
|
req.t = tonumber(kwarg(kwargs, "t") or "")
|
||||||
req.title = kwarg(kwargs, "title")
|
req.title = kwarg(kwargs, "title")
|
||||||
req.max = tonumber(kwarg(kwargs, "max") or "")
|
req.max = tonumber(kwarg(kwargs, "max") or "")
|
||||||
|
if view == "proof" then req.proveSeconds = tonumber(kwarg(kwargs, "prove-seconds") or meta_str(meta, "pplus-prove-seconds") or "") end
|
||||||
if kwarg(kwargs, "follow") then req.follow = split_list(kwarg(kwargs, "follow")) end
|
if kwarg(kwargs, "follow") then req.follow = split_list(kwarg(kwargs, "follow")) end
|
||||||
if kwarg(kwargs, "to") then req.to = split_list(kwarg(kwargs, "to")) end
|
if kwarg(kwargs, "to") then req.to = split_list(kwarg(kwargs, "to")) end
|
||||||
req.compiler = kwarg(kwargs, "compiler") or "auto"
|
req.compiler = kwarg(kwargs, "compiler") or "auto"
|
||||||
|
|||||||
@@ -3,16 +3,19 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// The assembled site's index.html, from the one in the repository: scripts/assemble.sh runs this on site/.
|
// The assembled site's index.html, from the one in the repository: scripts/assemble.sh runs this on site/.
|
||||||
// node scripts/assemble-page.mjs <site-dir>
|
// node scripts/assemble-page.mjs <site-dir>
|
||||||
// It adds two things a checkout served as it is (pixi run dev) does without:
|
// It adds three things a checkout served as it is (pixi run dev) does without:
|
||||||
// - <meta name="pplus-version">, the commit in site/VERSION, which the footer shows (no request needed);
|
// - <meta name="pplus-version">, the commit in site/VERSION, which the footer shows (no request needed);
|
||||||
// - a <link rel="modulepreload"> for every module the page's static import graph reaches. Without a bundler the
|
// - a <link rel="modulepreload"> for every module the page's static import graph reaches. Without a bundler the
|
||||||
// browser finds the modules one level of imports at a time, so a first visit waits for a chain of round trips
|
// browser finds the modules one level of imports at a time, so a first visit waits for a chain of round trips
|
||||||
// (six levels today); with the list it asks for them all at once. The links go after the import map, which a
|
// (six levels today); with the list it asks for them all at once. The links go after the import map, which a
|
||||||
// browser must have read before it loads any module.
|
// browser must have read before it loads any module;
|
||||||
|
// - the home page, already drawn, inside #app (src/ui/prerender.ts): a visitor sees it with the HTML and the
|
||||||
|
// stylesheet, not after every module has loaded and the page's examples have been run (about a second of work).
|
||||||
|
// It is drawn here by the app's own homeView, in Node, on the small document of src/quarto/dom.ts.
|
||||||
// Nothing else in the page changes, so the hashes of its inline scripts (docs/Caddyfile's CSP) still hold.
|
// Nothing else in the page changes, so the hashes of its inline scripts (docs/Caddyfile's CSP) still hold.
|
||||||
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
||||||
import { resolve, dirname, relative, join } from 'node:path';
|
import { resolve, dirname, relative, join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||||
|
|
||||||
const IMPORT = /(?:^|[;\n}])\s*(?:import|export)\s*(?:[\w*{}\s,$]*?\sfrom\s*)?['"]([^'"]+)['"]/g;
|
const IMPORT = /(?:^|[;\n}])\s*(?:import|export)\s*(?:[\w*{}\s,$]*?\sfrom\s*)?['"]([^'"]+)['"]/g;
|
||||||
|
|
||||||
@@ -43,14 +46,41 @@ export function modulePreloads(root, entry = 'dist/main.js') {
|
|||||||
return [...depth].filter(([f]) => f !== start).sort((a, b) => a[1] - b[1] || (a[0] < b[0] ? -1 : 1)).map(([f]) => `./${relative(root, f).split('\\').join('/')}`);
|
return [...depth].filter(([f]) => f !== start).sort((a, b) => a[1] - b[1] || (a[0] < b[0] ? -1 : 1)).map(([f]) => `./${relative(root, f).split('\\').join('/')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Where index.html takes the prerendered home page: a comment inside #app. */
|
||||||
|
export const HOME_MARK = '<!--prerendered-home-->';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The page with the version and the preloads in it.
|
* The home page as the app draws it, as HTML: the built app's own homeView, run here on the small document.
|
||||||
|
* @param {string} dist the built app's dist/ (it imports core through the package's #core/ mapping)
|
||||||
|
* @param {string | null} [version] the commit the footer names
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
export async function prerenderHome(dist, version = null) {
|
||||||
|
const at = (p) => pathToFileURL(join(dist, p)).href;
|
||||||
|
const { installDocument } = await import(at('quarto/dom.js'));
|
||||||
|
installDocument();
|
||||||
|
(await import(at('ui/footer.js'))).givePageVersion(version);
|
||||||
|
const { homeView } = await import(at('ui/home.js'));
|
||||||
|
return homeView().outerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The page with the version, the preloads and the prerendered home page in it.
|
||||||
* @param {string} html index.html as the repository has it
|
* @param {string} html index.html as the repository has it
|
||||||
* @param {{ version?: string | null, preloads?: string[] }} parts
|
* @param {{ version?: string | null, preloads?: string[], home?: string | null }} parts
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function assemblePage(html, { version = null, preloads = [] } = {}) {
|
export function assemblePage(html, { version = null, preloads = [], home = null } = {}) {
|
||||||
let out = html;
|
let out = html;
|
||||||
|
if (home) {
|
||||||
|
if (!out.includes(HOME_MARK)) throw new Error(`index.html has no ${HOME_MARK}: the prerendered home page goes there`);
|
||||||
|
// a function, so a $ in the page's text is not read as a replacement pattern
|
||||||
|
out = out.replace(HOME_MARK, () => `<div class="home-prerendered">${home}</div>`);
|
||||||
|
// the home page's Quarto example is styled by the extension's stylesheet, which the app adds when it draws the
|
||||||
|
// page (src/ui/quarto.ts, marked the same way so it is not added twice): without it here the prerendered page
|
||||||
|
// is a few lines taller than the one that takes its place
|
||||||
|
out = out.replace(/\n<\/head>/, '\n <link rel="stylesheet" href="./quarto/_extensions/pplus/pplus.css" data-pplus-ext="1">\n</head>');
|
||||||
|
}
|
||||||
if (version && /^[0-9a-f]{7,40}$/.test(version)) out = out.replace(/\n<\/head>/, `\n <meta name="pplus-version" content="${version}">\n</head>`);
|
if (version && /^[0-9a-f]{7,40}$/.test(version)) out = out.replace(/\n<\/head>/, `\n <meta name="pplus-version" content="${version}">\n</head>`);
|
||||||
const map = /<script type="importmap">[^<]*<\/script>\n/.exec(out);
|
const map = /<script type="importmap">[^<]*<\/script>\n/.exec(out);
|
||||||
if (!map) throw new Error('index.html has no import map: the preloads go after it');
|
if (!map) throw new Error('index.html has no import map: the preloads go after it');
|
||||||
@@ -64,6 +94,8 @@ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.ur
|
|||||||
const versionFile = join(site, 'VERSION');
|
const versionFile = join(site, 'VERSION');
|
||||||
const version = existsSync(versionFile) ? readFileSync(versionFile, 'utf8').trim() : null;
|
const version = existsSync(versionFile) ? readFileSync(versionFile, 'utf8').trim() : null;
|
||||||
const preloads = modulePreloads(site);
|
const preloads = modulePreloads(site);
|
||||||
writeFileSync(page, assemblePage(readFileSync(page, 'utf8'), { version, preloads }));
|
// drawn by the checkout's own build, which is what assemble.sh copied into the site
|
||||||
console.log(`index.html: ${preloads.length} module preloads${version ? `, version ${version.slice(0, 12)}` : ''}`);
|
const home = await prerenderHome(resolve(dirname(fileURLToPath(import.meta.url)), '..', 'dist'), version);
|
||||||
|
writeFileSync(page, assemblePage(readFileSync(page, 'utf8'), { version, preloads, home }));
|
||||||
|
console.log(`index.html: ${preloads.length} module preloads, the home page prerendered (${Math.round(home.length / 1024)} kB)${version ? `, version ${version.slice(0, 12)}` : ''}`);
|
||||||
}
|
}
|
||||||
@@ -50,6 +50,9 @@ for (const s of samples) for (const view of STATIC_VIEWS.filter((v) => v !== 'hw
|
|||||||
// the editor's token colors and the step colors, whichever a sample happened to show
|
// the editor's token colors and the step colors, whichever a sample happened to show
|
||||||
for (const c of ['tok-keyword', 'tok-builtin', 'tok-string', 'tok-number', 'tok-comment', 'tok-label', 'tok-op', 'tok-error', 'tok-punct', 'tok-convention', 'tok-transfer', 'tok-name']) used.add(c);
|
for (const c of ['tok-keyword', 'tok-builtin', 'tok-string', 'tok-number', 'tok-comment', 'tok-label', 'tok-op', 'tok-error', 'tok-punct', 'tok-convention', 'tok-transfer', 'tok-name']) used.add(c);
|
||||||
|
|
||||||
|
// the notice a rendered proof carries when the build machine ran out of the prover's time: no sample does (it is the machine's)
|
||||||
|
used.add('proof-timeout');
|
||||||
|
|
||||||
/* ---------- styles.css as rules ---------- */
|
/* ---------- styles.css as rules ---------- */
|
||||||
|
|
||||||
/** Top-level rules and @media blocks: { selector, body } or { media, rules }. Comments are dropped. */
|
/** Top-level rules and @media blocks: { selector, body } or { media, rules }. Comments are dropped. */
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
/**
|
||||||
|
* The time on the clock the Prove view gives each routine: 3 seconds unless the reader gives it more. The prover's
|
||||||
|
* work is counted and ends at the same point on every machine; the clock is the one part that depends on the
|
||||||
|
* machine, there so a page never waits long on one routine. On a slow or busy device 3 seconds can run out before
|
||||||
|
* the proof does, and a claim stays open that a faster machine proves. The report says when that happened
|
||||||
|
* (`ProofReport.clock`), the view says so, and this is the setting it offers. More time never makes anything
|
||||||
|
* proved that is not: it only lets the same checker finish.
|
||||||
|
*
|
||||||
|
* Kept in this browser's localStorage. DOM-free; the storage is a parameter, so the tests give one.
|
||||||
|
*/
|
||||||
|
type Store = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
||||||
|
const KEY = 'pplus.proveclock';
|
||||||
|
|
||||||
|
/** The choices, in milliseconds for each routine. The first is the default, and what a browser with no setting has. */
|
||||||
|
export const PROVE_CLOCKS: ReadonlyArray<{ ms: number; label: string }> = [
|
||||||
|
{ ms: 3000, label: '3 seconds' },
|
||||||
|
{ ms: 10000, label: '10 seconds' },
|
||||||
|
{ ms: 30000, label: '30 seconds' },
|
||||||
|
{ ms: 120000, label: '2 minutes' },
|
||||||
|
];
|
||||||
|
export const DEFAULT_PROVE_CLOCK = PROVE_CLOCKS[0].ms;
|
||||||
|
|
||||||
|
const defaultStore = (): Store | null => { try { return typeof localStorage === 'undefined' ? null : localStorage; } catch { return null; } };
|
||||||
|
|
||||||
|
/** How a budget reads in a sentence: "3 seconds", "2 minutes", and any other number of milliseconds in seconds. */
|
||||||
|
export function clockWords(ms: number): string {
|
||||||
|
const known = PROVE_CLOCKS.find((c) => c.ms === ms);
|
||||||
|
if (known) return known.label;
|
||||||
|
const s = Math.round(ms / 100) / 10;
|
||||||
|
return `${s} second${s === 1 ? '' : 's'}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The reader's setting: one of PROVE_CLOCKS, or the default when nothing (or anything else) is stored. */
|
||||||
|
export function loadProveClock(store: Store | null = defaultStore()): number {
|
||||||
|
try {
|
||||||
|
const ms = Number(store?.getItem(KEY));
|
||||||
|
return PROVE_CLOCKS.some((c) => c.ms === ms) ? ms : DEFAULT_PROVE_CLOCK;
|
||||||
|
} catch { return DEFAULT_PROVE_CLOCK; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Keep the setting (the default is kept by removing it), and return what was kept. */
|
||||||
|
export function saveProveClock(ms: number, store: Store | null = defaultStore()): number {
|
||||||
|
const kept = PROVE_CLOCKS.some((c) => c.ms === ms) ? ms : DEFAULT_PROVE_CLOCK;
|
||||||
|
try { if (kept === DEFAULT_PROVE_CLOCK) store?.removeItem(KEY); else store?.setItem(KEY, String(kept)); } catch { /* private mode or quota */ }
|
||||||
|
return kept;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The next longer choice after `ms`, or null at the longest. */
|
||||||
|
export function longerProveClock(ms: number): number | null {
|
||||||
|
return PROVE_CLOCKS.find((c) => c.ms > ms)?.ms ?? null;
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import { findPractices, findingsToDiagnostics, applyPractices, type PracticeFind
|
|||||||
import { checkMojo } from '#core/mojo/check.js';
|
import { checkMojo } from '#core/mojo/check.js';
|
||||||
import { GENERATED_HEADER } from '#core/sync/header.js';
|
import { GENERATED_HEADER } from '#core/sync/header.js';
|
||||||
import { SyncHub, isLinked, type Linked } from '#core/sync/hub.js';
|
import { SyncHub, isLinked, type Linked } from '#core/sync/hub.js';
|
||||||
|
import { DEFAULT_PROVE_CLOCK, loadProveClock, saveProveClock } from './proveclock.js';
|
||||||
|
|
||||||
/** One answer from godbolt, kept with exactly what it answered. */
|
/** One answer from godbolt, kept with exactly what it answered. */
|
||||||
export interface CompileRecord {
|
export interface CompileRecord {
|
||||||
@@ -73,6 +74,17 @@ export class Session extends Workspace {
|
|||||||
super(state);
|
super(state);
|
||||||
this.finder = opts.practices ?? findPractices;
|
this.finder = opts.practices ?? findPractices;
|
||||||
this.area = opts.area ?? null; this.storageId = opts.storageId; this.keep = opts.keep; this.original = opts.original ? structuredClone(opts.original) : null; this.stale = !!opts.stale;
|
this.area = opts.area ?? null; this.storageId = opts.storageId; this.keep = opts.keep; this.original = opts.original ? structuredClone(opts.original) : null; this.stale = !!opts.stale;
|
||||||
|
// the reader's time for a proof, from this browser (3 seconds where nothing is kept, as in a page rendered by Node)
|
||||||
|
this.proofBudgetMs = loadProveClock();
|
||||||
|
}
|
||||||
|
/** The time on the clock a proof has for each routine here, in milliseconds (src/core/proveclock.ts). */
|
||||||
|
proofClock(): number { return this.proofBudgetMs ?? DEFAULT_PROVE_CLOCK; }
|
||||||
|
/** Give proofs another time on the clock, keep it for this browser, and prove again. */
|
||||||
|
setProofClock(ms: number): void {
|
||||||
|
const kept = saveProveClock(ms);
|
||||||
|
if (kept === this.proofClock()) return;
|
||||||
|
this.proofBudgetMs = kept;
|
||||||
|
this.emit('run');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* The area the work is open in (from the route); the layout is kept per area. Null for a session that is not
|
* The area the work is open in (from the route); the layout is kept per area. Null for a session that is not
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ export function siteVersion(meta: string | null | undefined): string | null {
|
|||||||
*/
|
*/
|
||||||
export const SITE_DATA: readonly string[] = [
|
export const SITE_DATA: readonly string[] = [
|
||||||
'No accounts, no cookies, no analytics.',
|
'No accounts, no cookies, no analytics.',
|
||||||
'Your work, its saved versions, the answers Compile & run brought back, and your settings (the theme, the best-practices switches, whether messages show in the editor, whether you agreed to send to godbolt.org) are kept in this browser\'s localStorage, under names that start with "pplus". While saved work runs, this tab also keeps a mark in its sessionStorage, so a page that stops can put that work aside. Nothing is kept on a server: clearing this site\'s data in the browser removes it all, and Share → Download keeps a copy as a file.',
|
'Your work, its saved versions, the answers Compile & run brought back, and your settings (the theme, the best-practices switches, whether messages show in the editor, the time a proof may take, whether you agreed to send to godbolt.org) are kept in this browser\'s localStorage, under names that start with "pplus". While saved work runs, this tab also keeps a mark in its sessionStorage, so a page that stops can put that work aside. Nothing is kept on a server: clearing this site\'s data in the browser removes it all, and Share → Download keeps a copy as a file.',
|
||||||
'A shared link carries its work in the address after the #, which the browser does not send to any server. Opening one never saves over your own work on the same problem.',
|
'A shared link carries its work in the address after the #, which the browser does not send to any server. Opening one never saves over your own work on the same problem.',
|
||||||
'Compile & run sends the Mojo pane\'s text, the input box\'s lines and the build flags to godbolt.org (Compiler Explorer, a public service run by others, with its own privacy policy), and nothing else: no title, no other pane, nothing stored. The first time, it says so and asks; nothing is sent until you agree.',
|
'Compile & run sends the Mojo pane\'s text, the input box\'s lines and the build flags to godbolt.org (Compiler Explorer, a public service run by others, with its own privacy policy), and nothing else: no title, no other pane, nothing stored. The first time, it says so and asks; nothing is sent until you agree.',
|
||||||
'Nothing else leaves the browser. The page, its scripts and its fonts come from this site, and no other site is asked for anything. Links to other sites (the Mojo manual, where a method comes from) are followed only when you click them.',
|
'Nothing else leaves the browser. The page, its scripts and its fonts come from this site, and no other site is asked for anything. Links to other sites (the Mojo manual, where a method comes from) are followed only when you click them.',
|
||||||
|
|||||||
+7
-2
@@ -12,6 +12,7 @@ import { parseRoute, decodeState, loadLocal, migrateLocal, type PlayState, embed
|
|||||||
import { takeCrashed, settle, setAside, markBusy } from './core/guard.js';
|
import { takeCrashed, settle, setAside, markBusy } from './core/guard.js';
|
||||||
import { notice, messagePage } from './ui/notice.js';
|
import { notice, messagePage } from './ui/notice.js';
|
||||||
import { homeView } from './ui/home.js';
|
import { homeView } from './ui/home.js';
|
||||||
|
import { prerenderedHome } from './ui/prerender.js';
|
||||||
import { siteNav } from './ui/nav.js';
|
import { siteNav } from './ui/nav.js';
|
||||||
import { quartoView } from './ui/quarto.js';
|
import { quartoView } from './ui/quarto.js';
|
||||||
import { libraryView } from './ui/library.js';
|
import { libraryView } from './ui/library.js';
|
||||||
@@ -133,7 +134,9 @@ async function show(): Promise<void> {
|
|||||||
// the same static page with only the anchor changed: scroll, do not rebuild
|
// the same static page with only the anchor changed: scroll, do not rebuild
|
||||||
if (!shell && anchorOnly(location.hash, app.firstElementChild ? [...app.firstElementChild.classList] : null)) { scrollToAnchor(); return; }
|
if (!shell && anchorOnly(location.hash, app.firstElementChild ? [...app.firstElementChild.classList] : null)) { scrollToAnchor(); return; }
|
||||||
shell?.destroy(); shell = null;
|
shell?.destroy(); shell = null;
|
||||||
clear(app);
|
// the home page drawn by the assembler stays on screen until the one with its controls is ready to take its place
|
||||||
|
const prerendered = route.kind === 'home' ? prerenderedHome() : null;
|
||||||
|
if (!prerendered) clear(app);
|
||||||
document.body.classList.remove('is-embed');
|
document.body.classList.remove('is-embed');
|
||||||
let resolved: Resolved;
|
let resolved: Resolved;
|
||||||
try { resolved = await stateForRoute(); } catch (e: any) {
|
try { resolved = await stateForRoute(); } catch (e: any) {
|
||||||
@@ -150,7 +153,9 @@ async function show(): Promise<void> {
|
|||||||
if (!resolved && route.kind === 'library') { add(app, libraryView(route.id)); document.title = `${route.id ? `${route.id} · ` : ''}Library · Programming+`; window.scrollTo(0, 0); return; }
|
if (!resolved && route.kind === 'library') { add(app, libraryView(route.id)); document.title = `${route.id ? `${route.id} · ` : ''}Library · Programming+`; window.scrollTo(0, 0); return; }
|
||||||
if (!resolved && route.kind === 'quarto') { add(app, quartoView()); document.title = 'With Quarto · Programming+'; if (route.anchor) scrollToAnchor(true); else window.scrollTo(0, 0); return; }
|
if (!resolved && route.kind === 'quarto') { add(app, quartoView()); document.title = 'With Quarto · Programming+'; if (route.anchor) scrollToAnchor(true); else window.scrollTo(0, 0); return; }
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
add(app, homeView()); document.title = HOME_TITLE; scrollToAnchor(true);
|
const home = homeView();
|
||||||
|
if (prerendered) clear(app);
|
||||||
|
add(app, home); document.title = HOME_TITLE; scrollToAnchor(true);
|
||||||
if (isUnknownRoute(location.hash)) notice('There is no page at that address, so this is the home page. Links from before the three areas open here too.');
|
if (isUnknownRoute(location.hash)) notice('There is no page at that address, so this is the home page. Links from before the three areas open here too.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-2
@@ -72,6 +72,8 @@ export interface RenderRequest {
|
|||||||
/** hw: false leaves out the x86-64 listing; stepper false draws only the step `t`. */
|
/** hw: false leaves out the x86-64 listing; stepper false draws only the step `t`. */
|
||||||
listing?: boolean;
|
listing?: boolean;
|
||||||
stepper?: boolean;
|
stepper?: boolean;
|
||||||
|
/** proof: the seconds on the clock the prover has for each routine (default 3, the app's own). */
|
||||||
|
proveSeconds?: number;
|
||||||
/** A run of the Mojo file by a real compiler (render.mjs does it when `mojo` is on the PATH). */
|
/** A run of the Mojo file by a real compiler (render.mjs does it when `mojo` is on the PATH). */
|
||||||
compiled?: { stdout: string; stderr: string; status: number | null; version: string } | null;
|
compiled?: { stdout: string; stderr: string; status: number | null; version: string } | null;
|
||||||
}
|
}
|
||||||
@@ -130,7 +132,10 @@ function prepare(req: RenderRequest): Prepared {
|
|||||||
if (req.machine) state.machine = req.machine;
|
if (req.machine) state.machine = req.machine;
|
||||||
if (typeof req.t === 'number' && req.t >= 0) state.t = Math.floor(req.t);
|
if (typeof req.t === 'number' && req.t >= 0) state.t = Math.floor(req.t);
|
||||||
if (req.title) state.title = req.title;
|
if (req.title) state.title = req.title;
|
||||||
return { session: new Session(state), header, given, sources };
|
const session = new Session(state);
|
||||||
|
// a page is rendered once, on whatever machine builds the site: its author may give a proof more than the app's 3 seconds
|
||||||
|
if (typeof req.proveSeconds === 'number' && req.proveSeconds > 0) session.proofBudgetMs = Math.round(req.proveSeconds * 1000);
|
||||||
|
return { session, header, given, sources };
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
@@ -423,7 +428,11 @@ function proofOf(p: Prepared): RenderResult {
|
|||||||
const node = appView((h) => proofView(session, h, noHooks), 'view-proof');
|
const node = appView((h) => proofView(session, h, noHooks), 'view-proof');
|
||||||
const pr = session.proof();
|
const pr = session.proof();
|
||||||
const md = pr ? [`**${pr.report.counts.proved} proved, ${pr.report.counts.broken} broken, ${pr.report.counts.open} open.**`, '', ...pr.report.units.flatMap((u) => u.obligations.map((o) => `- ${o.status}: ${o.label} (line ${(o as any).specoLine ?? (o as any).pseudoLine ?? o.line})`))].join('\n') : '*The proof needs pseudocode that parses.*';
|
const md = pr ? [`**${pr.report.counts.proved} proved, ${pr.report.counts.broken} broken, ${pr.report.counts.open} open.**`, '', ...pr.report.units.flatMap((u) => u.obligations.map((o) => `- ${o.status}: ${o.label} (line ${(o as any).specoLine ?? (o as any).pseudoLine ?? o.line})`))].join('\n') : '*The proof needs pseudocode that parses.*';
|
||||||
return result('proof', 'pseudo', node, md, pr && pr.report.counts.broken ? [`proof: ${pr.report.counts.broken} claim(s) broken`] : []);
|
const warnings = pr && pr.report.counts.broken ? [`proof: ${pr.report.counts.broken} claim(s) broken`] : [];
|
||||||
|
// the machine that renders the page was too slow for the clock: the page would show claims open that are provable
|
||||||
|
const stopped = pr?.report.clock?.stopped ?? [];
|
||||||
|
if (stopped.length) warnings.push(`proof: time ran out on ${stopped.join(', ')} (${session.proofClock() / 1000} s for each routine): give it more with prove-seconds on the shortcode, or pplus-prove-seconds for the site`);
|
||||||
|
return result('proof', 'pseudo', node, md, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testsOf(p: Prepared): RenderResult {
|
function testsOf(p: Prepared): RenderResult {
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ export function requestFor(view: StaticView, attrs: Record<string, string>, file
|
|||||||
if (attrs.t && Number.isFinite(Number(attrs.t))) req.t = Number(attrs.t);
|
if (attrs.t && Number.isFinite(Number(attrs.t))) req.t = Number(attrs.t);
|
||||||
if (attrs.title) req.title = attrs.title;
|
if (attrs.title) req.title = attrs.title;
|
||||||
if (attrs.max && Number.isFinite(Number(attrs.max))) req.max = Number(attrs.max);
|
if (attrs.max && Number.isFinite(Number(attrs.max))) req.max = Number(attrs.max);
|
||||||
|
if (Number(attrs['prove-seconds']) > 0) req.proveSeconds = Number(attrs['prove-seconds']);
|
||||||
if (attrs.views) req.hw = list(attrs.views);
|
if (attrs.views) req.hw = list(attrs.views);
|
||||||
if (attrs.preset) req.preset = attrs.preset;
|
if (attrs.preset) req.preset = attrs.preset;
|
||||||
if (attrs.listing === '0') req.listing = false;
|
if (attrs.listing === '0') req.listing = false;
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ export function mountEmbed(session: Session, view: ViewId | LangId, params: URLS
|
|||||||
return ed;
|
return ed;
|
||||||
};
|
};
|
||||||
const hooks: PanelHooks = {
|
const hooks: PanelHooks = {
|
||||||
|
live: true,
|
||||||
reveal: (lang, line) => { const ed = editors.get(lang); if (ed) { ed.scrollToLine(line); ed.setDecorations({ linked: new Set([line]) }); setTimeout(() => ed.setDecorations({ linked: undefined }), 1200); } },
|
reveal: (lang, line) => { const ed = editors.get(lang); if (ed) { ed.scrollToLine(line); ed.setDecorations({ linked: new Set([line]) }); setTimeout(() => ed.setDecorations({ linked: undefined }), 1200); } },
|
||||||
fix: (lang, f) => editors.get(lang)?.applyFix(f),
|
fix: (lang, f) => editors.get(lang)?.applyFix(f),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,8 +11,13 @@ import { AREAS, AREA_ORDER } from '../core/areas.js';
|
|||||||
import { startFor } from './nav.js';
|
import { startFor } from './nav.js';
|
||||||
import { DISCLAIMER, LICENSE_FILES, SITE_DATA, SOURCE_URL, siteVersion } from '../core/site.js';
|
import { DISCLAIMER, LICENSE_FILES, SITE_DATA, SOURCE_URL, siteVersion } from '../core/site.js';
|
||||||
|
|
||||||
|
/** The commit, said by whoever draws the page outside a browser (the assembler, for the prerendered home page). */
|
||||||
|
let given: string | null = null;
|
||||||
|
export function givePageVersion(v: string | null): void { given = siteVersion(v); }
|
||||||
|
|
||||||
/** The commit the assembled page names (scripts/assemble-page.mjs), or null for a checkout served as it is. */
|
/** The commit the assembled page names (scripts/assemble-page.mjs), or null for a checkout served as it is. */
|
||||||
function pageVersion(): string | null {
|
function pageVersion(): string | null {
|
||||||
|
if (given) return given;
|
||||||
try { return siteVersion(document.querySelector('meta[name="pplus-version"]')?.getAttribute('content')); }
|
try { return siteVersion(document.querySelector('meta[name="pplus-version"]')?.getAttribute('content')); }
|
||||||
catch { return null; } // outside a browser (the small document of src/quarto/dom.ts knows no attribute selectors)
|
catch { return null; } // outside a browser (the small document of src/quarto/dom.ts knows no attribute selectors)
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-3
@@ -31,6 +31,7 @@ import { lineView } from './hw/lines.js';
|
|||||||
import { quartoTeaser } from './quarto.js';
|
import { quartoTeaser } from './quarto.js';
|
||||||
import { siteFooter } from './footer.js';
|
import { siteFooter } from './footer.js';
|
||||||
import { DESCRIPTION } from '../core/site.js';
|
import { DESCRIPTION } from '../core/site.js';
|
||||||
|
import { kept } from './prerender.js';
|
||||||
/** A register's value as short hex: what changed reads at a glance, without sixteen digits of zeros. */
|
/** A register's value as short hex: what changed reads at a glance, without sixteen digits of zeros. */
|
||||||
const hex64 = (v: bigint | number): string => `0x${BigInt.asUintN(64, BigInt(v)).toString(16)}`;
|
const hex64 = (v: bigint | number): string => `0x${BigInt.asUintN(64, BigInt(v)).toString(16)}`;
|
||||||
|
|
||||||
@@ -199,6 +200,10 @@ function whyMojo(): HTMLElement {
|
|||||||
|
|
||||||
/** Two real reports: count_base's Mojo, and a pseudo exercise with a bug the fuzzer finds. */
|
/** Two real reports: count_base's Mojo, and a pseudo exercise with a bug the fuzzer finds. */
|
||||||
function testsCard(): HTMLElement {
|
function testsCard(): HTMLElement {
|
||||||
|
// the fuzzer's two reports take about a second: worked out once, when the site is assembled (prerender.ts)
|
||||||
|
return kept('tests-card', testsCardBuilt);
|
||||||
|
}
|
||||||
|
function testsCardBuilt(): HTMLElement {
|
||||||
const report = (id: string, lang: LangId) => { const st = stateForProblem(problemById(id)!); st.lang = lang; return new Session(st).tests()[0]; };
|
const report = (id: string, lang: LangId) => { const st = stateForProblem(problemById(id)!); st.lang = lang; return new Session(st).tests()[0]; };
|
||||||
const ok = report('count-base', 'mojo');
|
const ok = report('count-base', 'mojo');
|
||||||
const bad = report('match-off-by-one', 'pseudo');
|
const bad = report('match-off-by-one', 'pseudo');
|
||||||
@@ -255,8 +260,14 @@ function notations(): HTMLElement {
|
|||||||
|
|
||||||
function specs(): HTMLElement {
|
function specs(): HTMLElement {
|
||||||
const proved = problemById('count-base-proved')!;
|
const proved = problemById('count-base-proved')!;
|
||||||
const pr = new Session(stateForProblem(proved)).proof();
|
// the site's own example, proved with no time on the clock: its work is small and counted, and what the home
|
||||||
const c = pr?.report.counts ?? { proved: 0, broken: 0, open: 0, total: 0 };
|
// page says of it must not depend on how fast or busy the reader's device is
|
||||||
|
const counts = kept('proof-counts', () => {
|
||||||
|
const session = new Session(stateForProblem(proved));
|
||||||
|
session.proofBudgetMs = Infinity;
|
||||||
|
const c = session.proof()?.report.counts ?? { proved: 0, broken: 0, open: 0, total: 0 };
|
||||||
|
return el('div', { class: 'proof-counts' }, el('span', { class: 'badge badge-proved' }, `${c.proved} proved`), el('span', { class: 'badge badge-broken' }, `${c.broken} broken`), el('span', { class: 'badge badge-open' }, `${c.open} open`));
|
||||||
|
});
|
||||||
return el('section', { class: 'spec-section' },
|
return el('section', { class: 'spec-section' },
|
||||||
el('div', { class: 'spec-text' },
|
el('div', { class: 'spec-text' },
|
||||||
el('h2', {}, 'Say what must be true, then check it'),
|
el('h2', {}, 'Say what must be true, then check it'),
|
||||||
@@ -265,7 +276,7 @@ function specs(): HTMLElement {
|
|||||||
el('div', { class: 'way way-speco' },
|
el('div', { class: 'way way-speco' },
|
||||||
el('h3', {}, 'speco'),
|
el('h3', {}, 'speco'),
|
||||||
sample(proved.sources.speco || '', 'speco', 8),
|
sample(proved.sources.speco || '', 'speco', 8),
|
||||||
el('div', { class: 'proof-counts' }, el('span', { class: 'badge badge-proved' }, `${c.proved} proved`), el('span', { class: 'badge badge-broken' }, `${c.broken} broken`), el('span', { class: 'badge badge-open' }, `${c.open} open`))));
|
counts));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function homeView(): HTMLElement {
|
export function homeView(): HTMLElement {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
/**
|
||||||
|
* The home page, drawn when the site is assembled. Drawing it runs the engines on its own examples (a fuzzer's
|
||||||
|
* report alone takes about a second), and until the page's 150 modules had loaded and that work was done a visitor
|
||||||
|
* saw nothing. So `scripts/assemble-page.mjs` draws the home page once, in Node, and puts the result inside
|
||||||
|
* `#app` as `.home-prerendered`: the browser paints it with the HTML and the stylesheet. When the app starts it
|
||||||
|
* draws the home page again and puts it in the prerendered one's place (src/main.ts), which gives the page its
|
||||||
|
* controls; the parts that are costly to work out and hold no control are taken from the prerendered page rather
|
||||||
|
* than worked out again (`kept`). The prerendered page shows only on the home address: the inline script in
|
||||||
|
* index.html marks it (`data-home`) before the first paint, and without the mark it stays hidden, so an embed or
|
||||||
|
* a problem's address never shows the home page first.
|
||||||
|
*/
|
||||||
|
export const PRERENDERED = 'home-prerendered';
|
||||||
|
|
||||||
|
/** The prerendered home page still in the document, or null (a checkout served as it is, a later visit to the home page). */
|
||||||
|
export function prerenderedHome(): Element | null {
|
||||||
|
try { return typeof document === 'undefined' ? null : document.querySelector(`.${PRERENDERED}`); } catch { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A part of the home page that is costly to work out and has nothing to press in it: built by `build` where the page
|
||||||
|
* is drawn first (the assembler, or a browser with no prerendered page), and copied from the prerendered page where
|
||||||
|
* there is one. The copy is what the same build's assembler worked out from the same catalog.
|
||||||
|
*/
|
||||||
|
export function kept<T extends HTMLElement>(key: string, build: () => T): T {
|
||||||
|
let pre: Element | null = null;
|
||||||
|
try { pre = prerenderedHome()?.querySelector(`[data-kept="${key}"]`) ?? null; } catch { pre = null; }
|
||||||
|
if (pre) return pre.cloneNode(true) as T;
|
||||||
|
const node = build();
|
||||||
|
node.setAttribute('data-kept', key);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
@@ -1061,6 +1061,7 @@ export class Shell {
|
|||||||
|
|
||||||
private hooks(): PanelHooks {
|
private hooks(): PanelHooks {
|
||||||
return {
|
return {
|
||||||
|
live: true,
|
||||||
reveal: (lang, line) => {
|
reveal: (lang, line) => {
|
||||||
this.setNarrow('code');
|
this.setNarrow('code');
|
||||||
if (lang !== this.session.state.lang) { this.session.setLang(lang); this.showPane(lang); }
|
if (lang !== this.session.state.lang) { this.session.setLang(lang); this.showPane(lang); }
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type { Diagnostic, LangId, QuickFix } from '#core/common/types.js';
|
|||||||
import { LANG_NAMES } from '#core/common/types.js';
|
import { LANG_NAMES } from '#core/common/types.js';
|
||||||
import type { Session } from '../../core/session.js';
|
import type { Session } from '../../core/session.js';
|
||||||
import { toMath } from '#core/services/speco.js';
|
import { toMath } from '#core/services/speco.js';
|
||||||
|
import { PROVE_CLOCKS, clockWords, longerProveClock } from '../../core/proveclock.js';
|
||||||
|
|
||||||
export const GUIDE_URL = 'https://biosc1540.scient.ing/programmingplus/reference/pseudocode/';
|
export const GUIDE_URL = 'https://biosc1540.scient.ing/programmingplus/reference/pseudocode/';
|
||||||
|
|
||||||
@@ -19,6 +20,8 @@ export interface PanelHooks {
|
|||||||
reveal(lang: LangId, line: number): void;
|
reveal(lang: LangId, line: number): void;
|
||||||
/** Apply a rewrite to a language's source. */
|
/** Apply a rewrite to a language's source. */
|
||||||
fix(lang: LangId, f: QuickFix): void;
|
fix(lang: LangId, f: QuickFix): void;
|
||||||
|
/** The view is on a live page (the app, an embed), where a control does something; a page rendered with Quarto is not. */
|
||||||
|
live?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SEV_ICON: Record<string, string> = { error: '●', warning: '▲', note: '○' };
|
const SEV_ICON: Record<string, string> = { error: '●', warning: '▲', note: '○' };
|
||||||
@@ -70,6 +73,16 @@ export function proofView(session: Session, root: HTMLElement, hooks: PanelHooks
|
|||||||
el('span', { class: 'badge badge-open' }, `${report.counts.open} open`),
|
el('span', { class: 'badge badge-open' }, `${report.counts.open} open`),
|
||||||
));
|
));
|
||||||
if (!report.counts.total) add(root, el('p', { class: 'muted' }, 'No claims to check. Add an ENSURE under a FUNCTION line, or a SPEC in the speco pane.'));
|
if (!report.counts.total) add(root, el('p', { class: 'muted' }, 'No claims to check. Add an ENSURE under a FUNCTION line, or a SPEC in the speco pane.'));
|
||||||
|
// the clock, not the proof, stopped the checker: say so, and offer the same proof with more time
|
||||||
|
const stopped = report.clock?.stopped ?? [];
|
||||||
|
if (stopped.length) {
|
||||||
|
const had = clockWords(report.clock!.budgetMs);
|
||||||
|
const more = hooks.live ? longerProveClock(session.proofClock()) : null;
|
||||||
|
add(root, el('div', { class: 'proof-timeout', role: 'status' },
|
||||||
|
el('p', {}, el('b', {}, 'Time ran out'), ` on ${stopped.length === 1 ? stopped[0] : `${stopped.length} routines (${stopped.join(', ')})`}: the checker had ${had} for each routine, and this device needed more. What it did not finish is shown open, not disproved.`),
|
||||||
|
more ? button(`Prove again with ${clockWords(more)}`, () => session.setProofClock(more), { class: 'btn btn-small' }) : null,
|
||||||
|
));
|
||||||
|
}
|
||||||
for (const u of report.units) {
|
for (const u of report.units) {
|
||||||
const sec = el('details', { class: 'proof-unit', open: true }, el('summary', {}, el('b', {}, u.name), ` · ${u.obligations.length} claim${u.obligations.length === 1 ? '' : 's'}`, u.partial ? el('span', { class: 'badge badge-open' }, 'partial: not every path was examined') : null));
|
const sec = el('details', { class: 'proof-unit', open: true }, el('summary', {}, el('b', {}, u.name), ` · ${u.obligations.length} claim${u.obligations.length === 1 ? '' : 's'}`, u.partial ? el('span', { class: 'badge badge-open' }, 'partial: not every path was examined') : null));
|
||||||
if (u.inferred.length) add(sec, el('p', { class: 'muted small' }, 'Invariants the checker found on its own: ', ...u.inferred.map((x) => el('code', { class: 'math' }, toMath(String(x)), ' '))));
|
if (u.inferred.length) add(sec, el('p', { class: 'muted small' }, 'Invariants the checker found on its own: ', ...u.inferred.map((x) => el('code', { class: 'math' }, toMath(String(x)), ' '))));
|
||||||
@@ -92,6 +105,13 @@ export function proofView(session: Session, root: HTMLElement, hooks: PanelHooks
|
|||||||
add(sec, list);
|
add(sec, list);
|
||||||
add(root, sec);
|
add(root, sec);
|
||||||
}
|
}
|
||||||
|
if (hooks.live) {
|
||||||
|
const clock = el('select', { class: 'select', id: 'proof-clock', onChange: () => session.setProofClock(Number(clock.value)) },
|
||||||
|
...PROVE_CLOCKS.map((c) => el('option', { value: String(c.ms), selected: c.ms === session.proofClock() }, c.label)));
|
||||||
|
add(root, el('p', { class: 'proof-clock small muted' },
|
||||||
|
el('label', { for: 'proof-clock' }, 'Time for each routine: '), clock,
|
||||||
|
' The checker stops at this time whether or not it is done, and the page waits while it works. More time never proves anything that is not true: it lets a slow device finish.'));
|
||||||
|
}
|
||||||
add(root, el('p', { class: 'small muted' }, 'Proved means: on every path the checker examined, the claim follows from what is known. Open means the checker could not finish the argument; usually a loop needs an invariant. Broken means a generated input violated it.'));
|
add(root, el('p', { class: 'small muted' }, 'Proved means: on every path the checker examined, the claim follows from what is known. Open means the checker could not finish the argument; usually a loop needs an invariant. Broken means a generated input violated it.'));
|
||||||
}
|
}
|
||||||
const off = session.onChange(render);
|
const off = session.onChange(render);
|
||||||
|
|||||||
+24
@@ -2329,6 +2329,23 @@ body.resizing textarea {
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.proof-timeout {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-left: 3px solid var(--warn, #b45309);
|
||||||
|
border-radius: var(--r);
|
||||||
|
padding: 6px 10px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proof-timeout p {
|
||||||
|
margin: 0 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proof-clock .select {
|
||||||
|
margin: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.proof-unit {
|
.proof-unit {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
@@ -4326,6 +4343,13 @@ button.asm-src:hover {
|
|||||||
.compile-input-note { max-width: 70ch; }
|
.compile-input-note { max-width: 70ch; }
|
||||||
.compile-send-note { max-width: 70ch; }
|
.compile-send-note { max-width: 70ch; }
|
||||||
/* index.html's note for a page whose scripts never ran (opened as a file, scripts blocked, offline on first load) */
|
/* index.html's note for a page whose scripts never ran (opened as a file, scripts blocked, offline on first load) */
|
||||||
|
/* the home page as the assembler drew it (src/ui/prerender.ts): shown at once on the home address (the inline script
|
||||||
|
of index.html says so before the first paint), and never on another address or where that script did not run */
|
||||||
|
.home-prerendered { display: none; }
|
||||||
|
html[data-home] .home-prerendered { display: block; }
|
||||||
|
/* with it on screen the note waits longer (the page is there, and its scripts may still be on their way) and takes
|
||||||
|
no room above the page: it comes up as a bar at the foot of the window */
|
||||||
|
html[data-home] #app:has(> .home-prerendered) .boot-note { animation-delay: 15s; position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 20; margin: 0 auto; padding: 10px 14px; border-radius: var(--r); background: var(--warn-bg); pointer-events: none; }
|
||||||
.boot-note { max-width: 640px; margin: 64px auto; padding: 0 16px; color: var(--ink-2); font: 16px/1.5 var(--sans); opacity: 0; animation: boot-note-show 0s 4s forwards; }
|
.boot-note { max-width: 640px; margin: 64px auto; padding: 0 16px; color: var(--ink-2); font: 16px/1.5 var(--sans); opacity: 0; animation: boot-note-show 0s 4s forwards; }
|
||||||
@keyframes boot-note-show { to { opacity: 1; } }
|
@keyframes boot-note-show { to { opacity: 1; } }
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ test('prove and tests work on the hub\'s pseudo, with the speco woven', () => {
|
|||||||
s.setSource('lingo', lingo + '\n'); // an edit in English
|
s.setSource('lingo', lingo + '\n'); // an edit in English
|
||||||
assert.equal(s.state.sync.authority, 'lingo');
|
assert.equal(s.state.sync.authority, 'lingo');
|
||||||
assert.match(s.source('pseudo'), /ENSURE/, 'the contracts are in the pseudo the English lowered to');
|
assert.match(s.source('pseudo'), /ENSURE/, 'the contracts are in the pseudo the English lowered to');
|
||||||
|
s.proofBudgetMs = Infinity; // no time on the clock: the same answer on a slow machine
|
||||||
const proof = s.proof();
|
const proof = s.proof();
|
||||||
assert.ok(proof && proof.report.counts.total > 0, 'there is something to prove');
|
assert.ok(proof && proof.report.counts.total > 0, 'there is something to prove');
|
||||||
assert.equal(proof.report.counts.broken, 0);
|
assert.equal(proof.report.counts.broken, 0);
|
||||||
|
|||||||
+41
-1
@@ -8,7 +8,7 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { createHash } from 'node:crypto';
|
import { createHash } from 'node:crypto';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { modulePreloads, assemblePage } from '../scripts/assemble-page.mjs';
|
import { modulePreloads, assemblePage, prerenderHome, HOME_MARK } from '../scripts/assemble-page.mjs';
|
||||||
|
|
||||||
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
||||||
const read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8');
|
const read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8');
|
||||||
@@ -60,3 +60,43 @@ test('the Caddy block caches nothing as immutable, revalidates the page and the
|
|||||||
assert.match(caddy, /header \/VERSION Cache-Control "no-store"/);
|
assert.match(caddy, /header \/VERSION Cache-Control "no-store"/);
|
||||||
assert.doesNotMatch(read('src/main.ts') + html, /serviceWorker/, 'no service worker (offline reload is a later decision)');
|
assert.doesNotMatch(read('src/main.ts') + html, /serviceWorker/, 'no service worker (offline reload is a later decision)');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the assembled page holds the home page already drawn, shown only on the home address', async () => {
|
||||||
|
// the app's own homeView, drawn in Node: what a visitor sees before any module has loaded
|
||||||
|
const home = await prerenderHome(path.join(ROOT, 'dist'), '0123456789abcdef0123456789abcdef01234567');
|
||||||
|
assert.match(home, /^<div class="home home-page">/);
|
||||||
|
assert.match(home, /<h1[ >]/);
|
||||||
|
assert.match(home, /id="problems"/);
|
||||||
|
// no script that runs (the CSP allows inline scripts by hash only); the Quarto example's stepper carries its steps as a JSON data block
|
||||||
|
assert.doesNotMatch(home, /<script(?![^>]*\btype="application\/json")/i);
|
||||||
|
assert.match(home, /0123456789ab/, 'the footer names the commit');
|
||||||
|
// the two parts that take the time, marked so the browser copies them instead of running the fuzzer and the prover again
|
||||||
|
assert.match(home, /data-kept="tests-card"[^>]*>.*no failures.*way/s);
|
||||||
|
assert.match(home, /data-kept="proof-counts"[^>]*>.*[1-9]\d* proved.*0 broken.*0 open/s);
|
||||||
|
// it goes inside #app, where the app puts the page it draws, and changes no inline script
|
||||||
|
assert.ok(html.includes(HOME_MARK), 'index.html has the place for it');
|
||||||
|
const out = assemblePage(html, { version: '0123456789abcdef0123456789abcdef01234567', preloads: ['./dist/a.js'], home: 'a $& b <p>home</p>' });
|
||||||
|
assert.match(out, /<div id="app">[\s\S]*<div class="home-prerendered">a \$& b <p>home<\/p><\/div>\s*<\/div>\s*<!-- pplus-core's modules/);
|
||||||
|
assert.deepEqual(inlineHashes(out), inlineHashes(html));
|
||||||
|
assert.throws(() => assemblePage(html.replace(HOME_MARK, ''), { home: 'x' }), /prerendered home page goes there/);
|
||||||
|
// shown only where the page's first script marked the home address: hidden by default, so an embed, a problem's
|
||||||
|
// address, or a page whose inline script did not run never shows the home page first
|
||||||
|
const css = read('styles.css');
|
||||||
|
assert.match(css, /\n\.home-prerendered \{ display: none; \}/);
|
||||||
|
assert.match(css, /\nhtml\[data-home\] \.home-prerendered \{ display: block; \}/);
|
||||||
|
const mark = /if \((\/.*?\/)\.test\(location\.hash\)\) document\.documentElement\.setAttribute\("data-home", ""\)/.exec(html);
|
||||||
|
assert.ok(mark, 'the inline script that marks the home address is not where this test looks');
|
||||||
|
const isHome = new Function(`return ${mark[1]}`)();
|
||||||
|
const { parseRoute, isUnknownRoute } = await import('../dist/core/state.js');
|
||||||
|
for (const hash of ['', '#', '#/', '#/#problems', '#/#reference', '#/#quarto-teaser']) {
|
||||||
|
assert.ok(isHome.test(hash), `${JSON.stringify(hash)} is the home page`);
|
||||||
|
assert.equal(parseRoute(hash).kind, 'home', hash);
|
||||||
|
assert.ok(!isUnknownRoute(hash), hash);
|
||||||
|
}
|
||||||
|
for (const hash of ['#/bridge/p/count-base', '#/dev/p/demo', '#/hw/p/asm-first-instructions', '#/library', '#/quarto', '#/quarto#install', '#/embed/trace/p/count-base', '#/bridge/s/abc', '#/p/count-base']) {
|
||||||
|
assert.ok(!isHome.test(hash), `${JSON.stringify(hash)} is not the home page`);
|
||||||
|
}
|
||||||
|
// and the app takes the prerendered page's place only once the page with its controls is built
|
||||||
|
const main = read('src/main.ts');
|
||||||
|
assert.match(main, /const home = homeView\(\);\s*if \(prerendered\) clear\(app\);\s*add\(app, home\)/);
|
||||||
|
});
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// The time a proof may take is the reader's to set (src/core/proveclock.ts): the Prove view says when the clock, not
|
||||||
|
// the proof, stopped the checker, offers more time, and proves again; a page rendered with Quarto takes its time
|
||||||
|
// from the shortcode or the site, and warns its author when it ran out.
|
||||||
|
import test from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { installDocument } from '../dist/quarto/dom.js';
|
||||||
|
|
||||||
|
installDocument();
|
||||||
|
const { PROVE_CLOCKS, DEFAULT_PROVE_CLOCK, loadProveClock, saveProveClock, longerProveClock, clockWords } = await import('../dist/core/proveclock.js');
|
||||||
|
const { Session } = await import('../dist/core/session.js');
|
||||||
|
const { problemById, stateForProblem } = await import('../dist/core/catalog.js');
|
||||||
|
const { proofView } = await import('../dist/ui/views/panels.js');
|
||||||
|
const { renderStatic } = await import('../dist/quarto/render.js');
|
||||||
|
|
||||||
|
const memory = () => { const m = new Map(); return { getItem: (k) => (m.has(k) ? m.get(k) : null), setItem: (k, v) => { m.set(k, String(v)); }, removeItem: (k) => { m.delete(k); }, m }; };
|
||||||
|
const hooks = (live) => ({ reveal() {}, fix() {}, live });
|
||||||
|
const draw = (session, live) => { const root = document.createElement('div'); proofView(session, root, hooks(live)); return root; };
|
||||||
|
const proved = () => new Session(stateForProblem(problemById('count-base-proved')), { storageId: null });
|
||||||
|
|
||||||
|
test('the setting is one of the listed times, 3 seconds unless the reader chose another, and kept under a pplus name', () => {
|
||||||
|
assert.equal(DEFAULT_PROVE_CLOCK, 3000);
|
||||||
|
assert.deepEqual(PROVE_CLOCKS.map((c) => c.ms), [3000, 10000, 30000, 120000]);
|
||||||
|
const store = memory();
|
||||||
|
assert.equal(loadProveClock(store), 3000);
|
||||||
|
assert.equal(saveProveClock(30000, store), 30000);
|
||||||
|
assert.deepEqual([...store.m.keys()], ['pplus.proveclock']);
|
||||||
|
assert.equal(loadProveClock(store), 30000);
|
||||||
|
// anything that is not a listed time is the default, stored or asked for
|
||||||
|
store.setItem('pplus.proveclock', '99999999');
|
||||||
|
assert.equal(loadProveClock(store), 3000);
|
||||||
|
assert.equal(saveProveClock(7, store), 3000);
|
||||||
|
assert.equal(store.m.size, 0, 'the default is kept by keeping nothing');
|
||||||
|
assert.equal(loadProveClock(null), 3000);
|
||||||
|
assert.equal(longerProveClock(3000), 10000);
|
||||||
|
assert.equal(longerProveClock(120000), null);
|
||||||
|
assert.equal(clockWords(120000), '2 minutes');
|
||||||
|
assert.equal(clockWords(1500), '1.5 seconds');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a proof the clock stopped says so, offers the next longer time, and is proved again with it', () => {
|
||||||
|
const s = proved();
|
||||||
|
assert.equal(s.proofClock(), 3000);
|
||||||
|
// a clock that has already run out, which is what 3 seconds are on a slow or busy device
|
||||||
|
s.proofBudgetMs = -1;
|
||||||
|
const cut = s.proof().report;
|
||||||
|
assert.ok(cut.clock.stopped.length >= 1, JSON.stringify(cut.clock));
|
||||||
|
assert.equal(cut.counts.broken, 0);
|
||||||
|
const view = draw(s, true);
|
||||||
|
const notice = view.querySelector('.proof-timeout');
|
||||||
|
assert.match(notice.textContent, /Time ran out on .*shown open, not disproved/);
|
||||||
|
assert.match(notice.querySelector('button').textContent, /^Prove again with 3 seconds$/);
|
||||||
|
assert.ok(view.querySelector('select#proof-clock'), 'and the setting itself is in the view');
|
||||||
|
// the setter proves again and tells the views
|
||||||
|
let told = 0;
|
||||||
|
s.onChange((what) => { if (what === 'run') told++; });
|
||||||
|
s.setProofClock(10000);
|
||||||
|
assert.equal(s.proofClock(), 10000);
|
||||||
|
assert.equal(told, 1);
|
||||||
|
assert.equal(s.proof().report.clock.budgetMs, 10000, 'proved again, with the new time');
|
||||||
|
assert.equal(draw(s, true).querySelector('select#proof-clock').value, '10000');
|
||||||
|
// what enough time gives is held with no clock at all, so this does not depend on how fast or busy the machine is
|
||||||
|
s.proofBudgetMs = Infinity;
|
||||||
|
const whole = s.proof().report;
|
||||||
|
assert.deepEqual(whole.clock.stopped, []);
|
||||||
|
assert.ok(whole.counts.proved > cut.counts.proved);
|
||||||
|
assert.equal(draw(s, true).querySelector('.proof-timeout'), null);
|
||||||
|
s.proofBudgetMs = 10000;
|
||||||
|
s.setProofClock(10000);
|
||||||
|
assert.equal(told, 1, 'the same time again is no change');
|
||||||
|
s.setProofClock(3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a view that is not live (a page rendered with Quarto) says the time ran out and offers no control', () => {
|
||||||
|
const s = proved();
|
||||||
|
s.proofBudgetMs = -1;
|
||||||
|
const view = draw(s, false);
|
||||||
|
assert.match(view.querySelector('.proof-timeout').textContent, /Time ran out/);
|
||||||
|
assert.equal(view.querySelector('button.btn'), null);
|
||||||
|
assert.equal(view.querySelector('select'), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a rendered proof takes its time from the request, and has no warning when the time was enough', () => {
|
||||||
|
const p = problemById('count-base-proved');
|
||||||
|
const files = { pseudo: p.sources.pseudo, speco: p.sources.speco };
|
||||||
|
const r = renderStatic({ view: 'proof', files, proveSeconds: 600 });
|
||||||
|
assert.match(r.html, /[1-9]\d* proved/);
|
||||||
|
assert.doesNotMatch(r.html, /Time ran out/);
|
||||||
|
assert.deepEqual(r.warnings, []);
|
||||||
|
});
|
||||||
@@ -27,6 +27,9 @@ test('the gallery\'s samples render as a page would get them, and every run in i
|
|||||||
const view = def.view ?? (s.attrs.view === 'dataflow' ? 'data' : s.attrs.view);
|
const view = def.view ?? (s.attrs.view === 'dataflow' ? 'data' : s.attrs.view);
|
||||||
const req = requestFor(view, s.attrs, files);
|
const req = requestFor(view, s.attrs, files);
|
||||||
if (def.hw) req.hw = [def.hw];
|
if (def.hw) req.hw = [def.hw];
|
||||||
|
// a proof with time to spare: the 3 seconds a page gets by default can run out on a loaded machine, and the
|
||||||
|
// render then warns (prove-seconds); what the sample proves is held here, not how fast this machine is
|
||||||
|
if (view === 'proof') req.proveSeconds = 600;
|
||||||
const r = renderStatic(req);
|
const r = renderStatic(req);
|
||||||
assert.deepEqual(r.warnings, [], `${s.name} ${JSON.stringify(s.attrs)}`);
|
assert.deepEqual(r.warnings, [], `${s.name} ${JSON.stringify(s.attrs)}`);
|
||||||
if (r.expect) assert.ok(r.expect.ok, `${s.name}: ${JSON.stringify(r.expect)}`);
|
if (r.expect) assert.ok(r.expect.ok, `${s.name}: ${JSON.stringify(r.expect)}`);
|
||||||
|
|||||||
@@ -116,7 +116,10 @@ test('every rendered view draws for a program that has what it needs, with the a
|
|||||||
assert.ok(r.markdown.length > 10, `${view} has a Markdown form`);
|
assert.ok(r.markdown.length > 10, `${view} has a Markdown form`);
|
||||||
}
|
}
|
||||||
assert.match(renderStatic({ view: 'flow', files }).html, /<svg[^>]*class="flow-svg"/);
|
assert.match(renderStatic({ view: 'flow', files }).html, /<svg[^>]*class="flow-svg"/);
|
||||||
assert.match(renderStatic({ view: 'proof', files }).html, /4 proved/);
|
// with time to spare: the 3 seconds a rendered proof has by default can run out on a slow machine (prove-seconds)
|
||||||
|
const proof = renderStatic({ view: 'proof', files, proveSeconds: 600 });
|
||||||
|
assert.match(proof.html, /4 proved/);
|
||||||
|
assert.deepEqual(proof.warnings, []);
|
||||||
const check = renderStatic({ view: 'check', files: { pseudo: problemById('five-bugs').sources.pseudo } });
|
const check = renderStatic({ view: 'check', files: { pseudo: problemById('five-bugs').sources.pseudo } });
|
||||||
assert.match(check.html, /problem-error/);
|
assert.match(check.html, /problem-error/);
|
||||||
assert.match(check.markdown, /\*\*error\*\*, pseudo line \d+: /);
|
assert.match(check.markdown, /\*\*error\*\*, pseudo line \d+: /);
|
||||||
|
|||||||
Reference in new issue
Block a user