Runs a source string as a program at execute - #161
Merged
Merged
Conversation
johnnyt
force-pushed
the
pts-0zns-execute-program-mode
branch
from
October 1, 2026 12:49
79e53d2 to
d2be57b
Compare
execute and executeValue compile a source string with the statement program compiler, as the reference's execute/3 and execute_value/3 do; evaluate still compiles an expression, as evaluate/3 does. An expression's source runs as a one-statement program, so execute's answer for it is unchanged, and executeValue now answers its value. Tests pin the switch, the program grammar's refusals at both entry points against their compile transcript rows, and the unchanged answers over every corpus case with a source both grammars compile. A dated Amendment to ADR-0004 records the decision (ruled by the operator, 2026-10-01), and a Changed fragment names the host-visible effects. The README example that showed execute refusing an assignment now shows evaluate refusing it and execute running it.
The fixtures this branch added for execute, executeValue and evaluate now use the library's loans, patrons and fines.
johnnyt
force-pushed
the
pts-0zns-execute-program-mode
branch
from
October 1, 2026 14:23
d2be57b to
980187b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
executeandexecuteValuenow compile a source string as a statement program, as the reference'sexecute/3andexecute_value/3do atv9.4.2;evaluatestill compiles an expression, asevaluate/3does. Ruled by the operator, 2026-10-01: switch to match the reference, a named host-visible change.Bead: pts-0zns.
What changes
src/index.ts:programOftakes the compiler as an argument;evaluatepassescompile,executeandexecuteValuepasscompileProgram. The three doc comments say so.src/compile.ts: thecompileProgramdoc comment namesexecuteandexecuteValueas the entry points that run a program (it saidevaluate).docs/adr/0004-the-compiler-surface.md: a dated Amendment at the foot, at proposed, add-only. It supersedes, forexecuteandexecuteValueonly, the section "The three entry points take a source string" on compiling an expression, and is the "later change with its own record" the statement-grammar Amendment names.changelog.d/pts-0zns.md: a### Changedfragment.README.md: the source-string paragraph and its example (see Provenance).test/index.test.ts: the tests below.Host-visible effects
Each row was run through this package after the change and, for the after column, through
Predicator.execute_value/3in an export of the reference atv9.4.2, which answered the same:execute,executeValuex = 1assignment_in_expressionxexecute,executeValuescore 3trailing_token, "... after expression"trailing_token, "... after statement"execute,executeValueifstatement_keywordexpected_primaryat the end of inputexecuteValuescore > 1,scorebound to 5trueThe first row is a source the expression grammar refused that now runs; the second and third are a refusal that is now the program grammar's. The fourth follows from the same switch: an expression's source compiles to the expression's list followed by
["pop"], soexecuteValueanswers its value. All three effects stand, each as the reference answers it (ruled by the operator, 2026-10-01), and the fragment names all three.Tests changed, with old and new answers
execute("x = 1")andexecuteValue("x = 1")answeredassignment_in_expression; they now run (pinned in the new block).execute("x = 1"), which now runs; it uses3 = renewalsat both entry points, refused by the program grammar.executeValue("score > 1", { score: 5 })answered valueundefined; the test now pinsexecuteValue("loan.renewals > 1", { loan: { renewals: 2 } })at valuetrue, andexecuteon the same source still answers the context it was given.New: a source the expression grammar refused runs at both;
evaluatekeeps refusing an assignment; fourprogram_refusalrows of the compile transcript (stray-else/leading,not-a-location/literal,missing-block/if-token,after-statement/missing-separator) are answered verbatim at both entry points with their reasons; and for every corpus case with a source both grammars compile, the program is the expression's list plus["pop"],execute's answer andexecuteValue's context or failing arm match the expression's list, andevaluateis unchanged.Sabotage, each run and restored byte-equal, each caught on an assertion:
executeback tocompile;executeValueback tocompile;evaluatetocompileProgram; the refusal's message rewritten inprogramOf; a context handed back beside a refused source;executeValueanswering the absence for a source.Provenance
README.mdwas outside the brief's "leave it" scope only where it had to move: its executed example assertedexecute("x = 1")is refused, which is now false and would fail the README test. The paragraph and that example now sayevaluatecompiles an expression andexecute/executeValuea program; the parse/compile sentences elsewhere are untouched.positionstays the failing instruction's index rather than a source location (the reference runs a source with its positions tables).02d4a21); the branch was rebased onto it with no conflict. The third brought the export ofDecompileResult, with its own ADR-0004 Amendment at the foot, andexecuteTaggedon./tagged, with a sentence inexecute's doc comment pointing at it. The rebase onto5afceb8conflicted at the foot of ADR-0004 only; it was resolved keep-both, with this branch's Amendment after theDecompileResultAmendment and zero removed lines. Both sides changedexecute's doc comment in different paragraphs: git merged them, and the comment keeps both the program-mode wording and theexecuteTaggedpointer, which is true of both, sinceexecuteTaggedalso compiles a source string as a statement program. The full gate ran on the combined tree.Cure 1
The review asked that the fixtures this branch added use the library world. The new tests now use
loan.overdue,fines,patron.holds,3 = renewals,status = 'late'atevaluate, andloan.renewals > 1. Fixtures that were already on main are untouched. The six sabotage checks above were re-run on the cured tests: each was caught on an assertion and restored byte-equal.Record check
The Amendment adds 120 lines and removes none (
git diff origin/main -- docs/adr/). Each claim was checked on this branch: the code split atprogramOfand the three entry points insrc/index.ts;EvaluationError.positioninsrc/errors.ts; the four rows inconformance/transcript/compile.json; the reference anchorsevaluate/3(Parser.parse),execute_value/3(Parser.parse_program) andexecute_value_astinlib/predicator.exatv9.4.2.Gate
Full
mise exec -- pnpm run gategreen on the head after the rebase onto5afceb8(the combined tree): typecheck, lint, neutrality, 35 test files with 2837 tests passed, coverage, corpus:check, build, identity, resolution. The whole output is on the bead.