Files
hakorune/CURRENT_TASK.md
Selfhosting Dev c8063c9e41 pyvm: split op handlers into ops_core/ops_box/ops_ctrl; add ops_flow + intrinsic; delegate vm.py without behavior change
net-plugin: modularize constants (consts.rs) and sockets (sockets.rs); remove legacy commented socket code; fix unused imports
mir: move instruction unit tests to tests/mir_instruction_unit.rs (file lean-up); no semantic changes
runner/pyvm: ensure using pre-strip; misc docs updates

Build: cargo build ok; legacy cfg warnings remain as before
2025-09-21 08:53:00 +09:00

192 lines
10 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Current Task — Freeze Polish (Concise)
Updated: 20250921
## Compressed Snapshot (Short)
- Strings (UTF8/CP vs Byte): baseline done
- [x] PyVM CP smokes (length/indexOf/lastIndexOf/substring)
- [x] ASCII Byte smoke
- [x] Rust CP gate (`NYASH_STR_CP=1`) for length/indexOf/lastIndexOf
- [x] Docs: blueprint updated with CP gate
- MiniVM BinOp(+): stabilization in progresssafe pathのみで緑化へ
- [x] Removed global digit-sum fallbacksハング源を除去
- [x] Added typed/token/value-pair probes仕様不変
- [x] Expressionbounded extractorPrint.expression の `{…}` で value×2 決定的抽出)
- [x] Main.fastpath: BinaryOp('+') を早期に 2 値抽出→加算→即 return
- [x] PyVM: `__me__` ディスパッチ同一Box内メソッド呼びの安全化
- [x] PyVM: `String.substring` の None 引数を安全化None→既定値
- [ ] MiniVM 内の me 呼びを完全撤去(関数呼びに統一)/ substring 前の index ガード徹底
- [ ] 代表スモークint+int=46を緑化print_prints_in_slice の無限ループ回避を含む)
- CI: keep min-gate light (MacroCtx/selfhost-preexpand/UTF8/ScopeBox) — all green
This page is trimmed to reflect the active work only. The previous long form has been archived at `CURRENT_TASK_restored.md`.
Principles (freeze)
- Selfhosting first. Macro normalization preMIR; PyVM semantics are authoritative.
- New features are paused; allow only bug fixes, docs, smokes/goldens, CI polish.
- Keep changes minimal/local; no spec changes unless to fix critical issues.
### Delta (since last update)
- Docs
- Added strings blueprint: `docs/blueprints/strings-utf8-byte.md`
- Refreshed docs index with clear "Start here" links (blueprints/strings, EBNF, strings reference)
- Clarified operator/loop sugar policy in `guides/language-core-and-sugar.md` ("!" adopted, dowhile not adopted)
- CI/Smokes
- Added UTF8 CP smoke (PyVM): `tools/test/smoke/strings/utf8_cp_smoke.sh` using `apps/tests/strings/utf8_cp_demo.nyash` (green)
- Wired into mingate CI alongside MacroCtx smoke (green)
- Runtime (Rust)
- StringBox.length: CP/Byte gate via env `NYASH_STR_CP=1` (default remains byte length; freezesafe)
- StringBox.indexOf/lastIndexOf: CP gate via env `NYASH_STR_CP=1`既定はByte index; PyVMはCP挙動
Notes / Risks
- 現在の赤は 2 系統の複合が原因:
1) Nyash 側の `||` 連鎖短絡による digit 判定崩れ(→ if チェーン化で解消)
2) 同一 Box 内の `me.*` 呼びが PyVM で未解決(→ `__me__` ディスパッチ導入)。
付随して、`substring(None, …)` 例外や `print_prints_in_slice` のステップ超過が発生。
ここを「me 撤去index ガード+ループ番兵」で仕上げる。
### Design DecisionStrings & Delegation
- Keep `StringBox` as the canonical text type (UTF8 / Code Point semantics). Do NOT introduce a separate "AnsiStringBox".
- Separate bytes explicitly via `ByteCursorBox`/buffer types (byte semantics only).
- Unify operations through a cursor/strategy interface (length/indexOf/lastIndexOf/substring). `StringBox` delegates to `Utf8Cursor` internally; byte paths use `ByteCursor` explicitly.
- Gate for transition (Rust only): `NYASH_STR_CP=1` enables CP semantics where legacy byte behavior exists.
## Implementation Order12 days
1) Strings CP/Byte baselinefoundation
- [x] CP smokePyVM: length/indexOf/lastIndexOf/substringapps/tests/strings/utf8_cp_demo.nyash
- [x] ASCII byte smokePyVM: length/indexOf/substringapps/tests/strings/byte_ascii_demo.nyash
- [x] Rust CP gate: length/indexOf/lastIndexOf → `NYASH_STR_CP=1` でCP既定はByte
- [x] Docs note: CP gate env (`NYASH_STR_CP=1`) を strings blueprint に明記
2) MiniVM BinOp(+安定化StageB 内部置換)
- [x] 広域フォールバック(全数値合算)を削除(安全化)
- [x] typed/token/value-pair の局所探索を導入(非破壊)
- [x] 式境界Print.expression`{…}` 内で `value`×2 を確実抽出→加算(決定化)
- [x] Main.fastpath を追加(先頭で確定→即 return
- [x] PyVM`__me__` ディスパッチ追加/`substring` None ガード
- [ ] MiniVMme 呼びの全面撤去(関数呼びへ統一)
- [ ] `substring` 呼び前の index>=0 ガード徹底・`print_prints_in_slice` に番兵を追加
- [ ] 代表スモークint+int=46を緑化
3) JSON ローダ分離(導線のみ・互換維持)
- [ ] MiniJsonLoader薄ラッパ経由に集約→後で `apps/libs/json_cur.nyash` に差し替え可能に
- [ ] スモークは現状維持(既存の stdin/argv 供給で緑)
4) Nyash 箱の委譲(内部・段階導入)
- [ ] StringBox 公開API → Utf8CursorBoxlength/indexOf/substringへ委譲互換を保つ
- [ ] Byte 系は ByteCursorBox を明示利用(混線防止)
5) CI/Docs polish軽量維持
- [x] README/blueprint に CP gate を追記
- [ ] Min-gate は軽量を維持MacroCtx/前展開/UTF8/Scope系のみ
## MiniVMStageB 進行中)
目的: Nyash で書かれた極小VMMiniVMを段階育成し、PyVM 依存を徐々に薄める。まずは “読む→解釈→出力” の最小パイプを安定化。
現状(達成)
- stdin ローダ(ゲート): `NYASH_MINIVM_READ_STDIN=1`
- Print(Literal/FunctionCall)、BinaryOp("+") の最小実装とスモーク
- Compare 6種<, <=, >, >=, ==, !=)と int+int の厳密抽出
- Ifリテラル条件片側分岐の走査
次にやる(順)
0) BinOp(+: me 撤去index ガード徹底print_prints 番兵(ハング防止)
1) JSON ローダの分離(`apps/libs/json_cur.nyash` 採用準備)
2) if/loop の代表スモークを 12 本追加PyVM と出力一致)
3) MiniVM を関数形式へ移行(トップレベル MVP から段階置換)
受け入れStageB
- stdin/argv から供給した JSON 入力で Print/分岐が正しく動作(スモーク緑)
## UTF8 計画UTF8 First, Bytes Separate
目的: String の公開 API を UTF8 カーソルへ委譲し、文字列処理の一貫性と可観測性を確保(性能最適化は後続)。
現状
- Docs: `docs/reference/language/strings.md`
- MVP Box: `apps/libs/utf8_cursor.nyash`, `apps/libs/byte_cursor.nyash`
段階導入(内部置換のみ)
1) StringBox の公開 API を段階的に `Utf8CursorBox` 委譲(`length/indexOf/substring`
2) MiniVM/macro 内の簡易走査を `Utf8CursorBox`/`ByteCursorBox` に置換(機能同値、内部のみ)
3) Docs/スモークの更新(出力は不変;必要時のみ観測ログを追加)
Nyash スクリプトの基本ボックス(標準 libs
- 既存: `json_cur.nyash`, `string_ext.nyash`, `array_ext.nyash`, `string_builder.nyash`, `test_assert.nyash`, `utf8_cursor.nyash`, `byte_cursor.nyash`
- 追加候補(凍結順守: libs 配下・任意採用・互換保持)
- MapExtBoxkeys/values/entries
- PathBox minidirname/join の最小)
- PrintfExt`StringBuilderBox` 補助)
## CI/Gates — Green vs Pending
Alwayson期待値: 緑)
- rustcheck: `cargo check --all-targets`
- pyvmsmoke: `tools/pyvm_stage2_smoke.sh`
- macrogolden: identity/strings/array/map/loopformkeyorder insensitive
- macrosmokeslite:
- match guardliteral OR / type minimal
- MIR hintsScope/Join/Loop
- ScopeBoxnoop
- MacroCtx ctx JSON追加済み
- selfhostpreexpandsmoke: upper_stringauto engage 確認)
Pending / Skipped未導入・任意
- Match guard: 追加ゴールデンtype最小形
- LoopForm: break/continue 降下の観測スモーク
- MiniVM StageB: JSON ローダ分離 + if/loop 代表スモーク
- MiniVM StageB: BinOp(+緑化me 撤去index ガード+番兵)
- UTF8 委譲: StringBox→Utf8CursorBox の段階置換(内部のみ;ゲート)
- UTF8 CP gate (Rust): indexOf/lastIndexOf envgated CP semantics既定OFF
- LLVM 重テスト: 手動/任意ジョブのみ(常時スキップ)
## 80/20 Plan小粒で高効果
Checklist更新済み
- [x] Selfhost 前展開の固定スモーク 1 本upper_string
- [x] MacroCtx ctx JSON スモーク 1 本CI 組み込み)
- [ ] Match 正規化: 追加テストは当面維持(必要時にのみ追加)
- [x] プロファイル運用ガイド追記(`--profile dev|lite`
- [ ] LLVM 重テストは常時スキップ(手動/任意ジョブのみ)
- [ ] 警告掃除は次回リファクタで一括(今回は非破壊)
Acceptance
- 上記 2 本preexpand/MacroCtx常時緑、既存 smokes/goldens 緑
- README/ガイドにプロファイル説明が反映済み
- UTF8 CP smoke is green under PyVM; Rust CP gate remains optin
## SelfHosting — Stage A要約
Scope最小
- JSON v0 ローダ(ミニセット)/ MiniVM最小命令/ スモーク 2 本print / if
Progress
- [x] MiniVM MVPprint literal / if branch
- [x] PyVM P1: `String.indexOf` 追加
- [x] Entry 統一(`Main.main`/ ネスト関数リフト
Nextクリーン経路
- [ ] MiniVM: 関数形式+簡易 JSON ローダへ段階移行
- [ ] Docs: invariants/constraints/testingmatrix へ反映追加
### Guardrailsactive
- 参照実行: PyVM が常時緑、マクロ正規化は preMIR で一度だけ
- 前展開: `NYASH_MACRO_SELFHOST_PRE_EXPAND=auto`dev/CI
- テスト: VM/goldens は軽量維持、IR は任意ジョブ
## PostFreeze BacklogDocs only
- Language: Scope reuse blocksdesign — docs/proposals/scope-reuse.md
- Language: Flow blocks & `->` pipingdesign — docs/design/flow-blocks.md
- Guards: Range/CharClass sugarreference — docs/reference/language/match-guards.md
- Strings: `toDigitOrNull` / `toIntOrNull`design note — docs/reference/language/strings.md
## Nyash VM めど後 — 機能追加リンク(備忘)
- スコープ再利用ブロックMVP 提案): docs/proposals/scope-reuse.md
- 矢印フロー × 匿名ブロック(設計草案): docs/design/flow-blocks.md
- Match Guard の Range/CharClass参照・設計: docs/reference/language/match-guards.md
- String 便利関数toDigit/Int; 設計): docs/reference/language/strings.md
Trigger: nyash_vm の安定主要スモーク緑・自己ホスト経路が日常運用。達成後に検討→MVP 実装へ。