Updated documentation to reflect actual implementation status: - docs/reference/language/repl.md: Corrected examples (variable persistence TODO) - docs/development/current/main/10-Now.md: Phase 288 completion noted - docs/development/current/main/30-Backlog.md: Updated with Phase 288.1 tasks - docs/development/current/main/phases/phase-288/: Added phase documentation Accurate REPL behavior examples: - x = 1 works (implicit local) - print(x) errors (persistence in Phase 288.1) - Expression auto-display deferred 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2.3 KiB
2.3 KiB
Phase 288.1 P1: REPL Session Persistence + Auto-Display (instruction sheet)
Objective
- Make REPL variables persist across input lines (
x = 1thenprint(x)works). - Add minimal expression auto-display and
_last-value binding (REPL-only). - Keep file mode semantics unchanged; quick smokes must remain green.
SSOT:
docs/reference/language/repl.md
Constraints (non-negotiable)
- No new env vars.
- No file-mode behavior changes.
- Keep REPL-specific state and logic isolated (Box-first).
Design (recommended)
Do not persist ValueId across evaluations. Persist runtime values (VMValue/handle) in ReplSessionBox, and bridge them via a REPL-only rewrite step.
Bridge approach: REPL-only AST rewrite
In REPL mode, rewrite variable reads/writes that are not declared in the current input line into calls against a REPL session object:
- Read
x→__repl.get("x") - Assignment
x = expr→__repl.set("x", expr) _is treated as a normal name in the session (written by auto-display).
This keeps the parser unchanged and avoids contaminating the normal MIR builder scope model.
Session API (REPL-only)
Provide a minimal host object __repl with:
get(name: String) -> Any(Fail-Fast if missing)set(name: String, value: Any) -> voidreset() -> void
Implementation options:
- Rust VM only (initially): inject
__replas a built-in box/object available only in--repl. - LLVM parity is not required for Phase 288.1; REPL is a dev tool.
Step-by-step
- Add a REPL-only
__replhost object and VM handlers forget/set/reset. - Implement AST rewrite in the REPL runner before compilation:
- Collect “declared names” in the current line (
local name, function params, etc.). - Rewrite remaining identifier reads/writes to
__repl.get/set.
- Collect “declared names” in the current line (
- Implement auto-display:
- If the input is a pure expression,
print(result)(or equivalent) in REPL only. - Store result into session name
_(skip ifvoid).
- If the input is a pure expression,
- Add conformance checks (manual is OK if no test harness exists yet):
x = 1(silent)print(x)prints1y(read) is NameError1 + 1prints2and_becomes2.resetclears variables (print(x)errors)
- Run regression gate:
./tools/smokes/v2/run.sh --profile quickmust stay0 FAILED.