docs(repl): record Phase 288.1 contract and results

更新内容:
- docs/reference/language/repl.md
  - Phase 288.1 完了ステータスに更新
  - Implementation Architecture セクション追加(AST rewrite 方式説明)
  - AST Rewriter の動作フロー追加(Variable/Assignment 変換ロジック)
  - ExternCall Bridge の仕組み追加(__repl.get/set → VMValue)
  - Expression Detection ロジック追加(wrapper AST 判定)
  - 動作例を完全に更新(全機能が動作済み)

- docs/development/current/main/phases/phase-288/README.md
  - Phase 288.1 完了セクション追加
  - 変更ファイル一覧(8ファイル, +592行)記録
  - 確認コマンド 4種 記録(変数永続化/式表示/_変数/リセット)
  - 回帰テスト結果記録(154/154 PASS)

- docs/development/current/main/10-Now.md
  - "Phase 288.1 完了" に更新
  - 次の候補(REPL UX 改善 / JoinIR 設計作業)を追記

- CURRENT_TASK.md
  - 1段落サマリー更新(288.1 完了、次の方向性)

Phase 288.1 成果(SSOT記録):
 変数永続化(session → eval bridge)
 式自動表示(pure expression auto-output)
 _ 変数(last displayed value)
 Fail-Fast 未定義エラー + ヒント
 セッションリセット(.reset)
 154/154 smoke tests PASS(file mode 不変)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-25 23:05:20 +09:00
parent 46fbe12ce6
commit 55d30c9845
4 changed files with 160 additions and 46 deletions

View File

@ -2,20 +2,42 @@
## Current Focus (next)
- Phase 288.1dev-tools: REPL session persistence + auto-display
- 目的: `hakorune --repl` で変数が行を跨いで生きる暗黙local式の自動表示`_` を含む)
- 入口: `docs/development/current/main/phases/phase-288/README.md`
- 手順: `docs/development/current/main/phases/phase-288/P1-INSTRUCTIONS.md`
**2025-12-25: Phase 288.1 完了**
- REPL session persistence + auto-display 実装完了
- AST rewrite 方式__repl.get/set ExternCall
- 154/154 smoke tests PASSfile mode 不変)
- 詳細: `docs/development/current/main/phases/phase-288/README.md`
- Phase 284design-first: Return as ExitKind SSOTpatternに散らさない
- 目的: `return``ExitKind` + `compose::*` / `emit_frag()` に収束させ、pattern側の個別実装を増やさない
- 入口: `docs/development/current/main/phases/phase-284/README.md`
- 手順: `docs/development/current/main/phases/phase-284/P0-INSTRUCTIONS.md`
- 次: Phase 285design-firstBox lifecycle SSOT`docs/development/current/main/phases/phase-285/README.md`
- 次の次: Phase 286design-firstJoinIR line absorption`docs/development/current/main/phases/phase-286/README.md`
**次の候補**:
1. **Phase 288.2+** (REPL UX improvements): Multi-line input, syntax highlighting, history
2. **Phase 284** (design-first): Return as ExitKind SSOT
- 入口: `docs/development/current/main/phases/phase-284/README.md`
- 手順: `docs/development/current/main/phases/phase-284/P0-INSTRUCTIONS.md`
3. **JoinIR/slot improvements**: Phase 285/286 継続
- Phase 285: Box lifecycle SSOT
- Phase 286: JoinIR line absorption
## Recently Completed
### 2025-12-25: Phase 288.1REPL Session Persistence + Auto-Display
-**Phase 288.1完了**: REPL variable persistence + expression auto-display
- 詳細: `docs/development/current/main/phases/phase-288/README.md`
- 実装方式: AST Rewrite + ExternCall Bridge
- 達成内容:
- ✅ AST Rewriter 実装(~430行、`src/runner/repl/ast_rewriter.rs`
- ✅ __repl.get/set ExternCall handlers 実装
- ✅ Rc<RefCell<ReplSessionBox>> session sharing
- ✅ Expression auto-display + `_` variable
- ✅ Fail-fast undefined variable errors
- 検証結果:
- ✅ Variable persistence: `x = 42` then `print(x)``42`
- ✅ Expression display: `1 + 1``2`
-`_` variable: `10 * 2``20`, then `_``20`
- ✅ Session reset: `.reset` clears all variables
- ✅ 154/154 smoke tests PASS (no regressions)
- Files: 8 files, +592 lines (REPL-isolated)
### 2025-12-24: Phase 285LLVM-1.3LLVM InstanceBox Field Access
-**Phase 285LLVM-1.3完了**: InstanceBox field access (getField/setField) implementation

View File

@ -1,6 +1,6 @@
# Phase 288: REPL mode (design-first, file-mode unaffected)
Status: ✅ P0P3 complete (2025-12-25) / ⏳ 288.1 next
Status: ✅ Phase 288.1 complete (2025-12-25)
Goal: Add an interactive REPL for Nyash while keeping file mode semantics unchanged and keeping the language SSOT stable.
@ -22,12 +22,68 @@ SSOT:
-**P3 (UX)**: print() 出力表示、Main box wrapperVM entry point 修正)、.reset 実装
-**Box化**: `src/runner/repl/` モジュール分離ReplRunnerBox、runner/mod.rs -118行 (commit: 3445ef7a7)
## Next (Phase 288.1)
## Completed (Phase 288.1) - Session Persistence + Auto-Display
The MVP intentionally deferred these:
**AST Rewriter** (~430 lines, `src/runner/repl/ast_rewriter.rs`):
- Transforms undeclared variables: `x``__repl.get("x")`
- Transforms assignments: `x = 42``__repl.set("x", 42)`
- Respects `local` declarations, reserved names (`me`, `true`, `false`, `null`)
- Special handling: skips nested scopes, Main wrapper
- Session variable **persistence across lines** (bridge session → compilation/runtime)
- Expression auto-display + `_` last-value binding
**ExternCall Bridge**:
- MIR builder: `__repl.get/set``ExternCall` lowering (`src/mir/builder/calls/build.rs` +41 lines)
- VM handler: `ExternCall("__repl", "get"/"set")` implementation (`src/backend/mir_interpreter/handlers/externals.rs` +54 lines)
- Fail-fast undefined variable errors with hints
**Session Management**:
- `Rc<RefCell<ReplSessionBox>>` pattern for proper persistence
- VM receives session via `set_repl_session()` (`src/backend/mir_interpreter/mod.rs` +12 lines)
- Session survives across REPL lines
**Expression Auto-Display**:
- Detects pure expressions vs statements (wrapper AST check)
- Auto-displays non-Void expression results
- Stores displayed values in `_` variable
**Testing**:
- All 154 smoke tests pass (no regressions)
- Variable persistence: `x = 42` then `print(x)``42`
- Expression display: `1 + 1``2`
- `_` variable: `10 * 2``20`, then `_``20`
- Fail-fast: undefined variables error with hints
- Session reset: `.reset` clears all variables
**Files Modified** (8 files, +592 lines):
- `src/runner/repl/ast_rewriter.rs` (NEW, +430 lines)
- `src/runner/repl/repl_runner.rs` (+84/-35 lines)
- `src/backend/mir_interpreter/handlers/externals.rs` (+54 lines)
- `src/mir/builder/calls/build.rs` (+41 lines)
- `src/backend/mir_interpreter/mod.rs` (+12 lines)
- `src/runner/repl/repl_session.rs` (+11/-9 lines)
- `src/runner/repl/mod.rs` (+2 lines)
- `src/runner/mod.rs` (+2/-1 lines)
**Confirmation Commands**:
```bash
# Variable persistence
echo -e 'x = 42\nprint(x)\n.exit' | ./target/release/hakorune --repl
# Expression auto-display + _
echo -e '1 + 1\n_\n.exit' | ./target/release/hakorune --repl
# Fail-fast undefined
echo -e 'print(y)\n.exit' | ./target/release/hakorune --repl
# Session reset
echo -e 'x = 1\n.reset\nprint(x)\n.exit' | ./target/release/hakorune --repl
# Regression test
./tools/smokes/v2/run.sh --profile quick # 154/154 PASS
```
## Next
Further UX improvements (deferred):
- Multi-line input handling (continuations)
Entry: `docs/development/current/main/phases/phase-288/P1-INSTRUCTIONS.md`
- Syntax highlighting
- Command history persistence