From 6e6dc9ebe37f2d5bea1178bd1a55255bef38cf43 Mon Sep 17 00:00:00 2001 From: Selfhosting Dev Date: Tue, 23 Sep 2025 01:23:16 +0900 Subject: [PATCH 1/2] selfhost: Integrate ChatGPT's using system parser fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix using paths in mini_vm_prints.nyash and mini_vm_core.nyash - Convert multi-line JSON literal to single-line in empty args smoke test - Remove extra closing brace in mini_vm_core.nyash - Add verbose logging for using system visited file tracking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CURRENT_TASK.md | 28 +++++++++++++++++-- apps/selfhost/vm/boxes/mini_vm_core.nyash | 1 - apps/selfhost/vm/boxes/mini_vm_prints.nyash | 8 +++--- src/jit/lower/extern_thunks.rs | 2 +- src/runner/modes/common_util/resolve/strip.rs | 5 +++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/CURRENT_TASK.md b/CURRENT_TASK.md index 99fc73b8..89c5c972 100644 --- a/CURRENT_TASK.md +++ b/CURRENT_TASK.md @@ -39,7 +39,18 @@ Principles (feature‑pause) - `apps/selfhost-runtime/mir_loader.nyash`: FileBox で読込→JsonDocBox で parse→version/kind/body_len を要約 - `apps/selfhost-runtime/runner.nyash`: args[0] の JSON を読み、{version:0, kind:"Program"} を検証(NGは非0exit) - v0 とハーネスJSON({"functions":…})の両フォーマットを受理。`--trace` で v0 要約/stmt数、ハーネス要約(functions数)を出力 +- **P1 標準箱のlib化完了**(既定OFF・段階導入) + - 薄ラッパlib実装: `apps/lib/boxes/{console_std.nyash,string_std.nyash,array_std.nyash,map_std.nyash}`(恒等の薄ラッパ) + - 自己ホスト実行器の導線: `src/runner/modes/pyvm.rs` に `--box-pref=ny|plugin` 子引数伝達(既定=plugin) + - BoxCall ディスパッチ骨格: `apps/selfhost-runtime/{runner.nyash,ops_calls.nyash}` でpref解析・初期化 +- **ScopeBox/LoopForm 前処理完了**(恒等・導線ON) + - 前処理本体(恒等apply): `apps/lib/{scopebox_inject.nyash,loopform_normalize.nyash}` + - Selfhost Compiler適用: `apps/selfhost/compiler/compiler.nyash` で `--scopebox/--loopform` 受理→apply後emit + - Runner env→子引数マップ: `src/runner/selfhost.rs` で `NYASH_SCOPEBOX_ENABLE=1`→`--scopebox` 変換 - Smoke 追加(任意実行): `tools/test/smoke/selfhost/selfhost_runner_smoke.sh` +- **恒等性確認スモーク追加**: + - ScopeBox恒等: `tools/test/smoke/selfhost/scopebox_identity_smoke.sh` + - LoopForm恒等: `tools/test/smoke/selfhost/loopform_identity_smoke.sh` - Identity 確認スモーク(Selfhost Compiler 直呼び) - ScopeBox: `tools/test/smoke/selfhost/scopebox_identity_smoke.sh` - LoopForm: `tools/test/smoke/selfhost/loopform_identity_smoke.sh` @@ -256,13 +267,24 @@ JSON / Plugin v2(現状に追記) - 命名衝突は採用側の include/using に限定(既存ファイルの広域変更は行わない)。 TODO(段階タスク) -- [ ] P1: console_std/string_std/array_std/map_std の雛形を追加(apps/lib/boxes/) -- [ ] P1: 自己ホスト実行器の BoxCall ディスパッチに `NYASH_SELFHOST_BOX_PREF` を導入(既定=plugin) -- [ ] P1: strings/array/map の最小スモークを selfhost 経路で追加 +- [x] P1: console_std/string_std/array_std/map_std の雛形を追加(apps/lib/boxes/) +- [x] P1: 自己ホスト実行器の BoxCall ディスパッチに `NYASH_SELFHOST_BOX_PREF` を導入(既定=plugin) +- [x] ScopeBox/LoopForm 前処理(恒等版)実装+スモーク +- [ ] **今すぐ推奨**: 恒等性スモーク実行(実装検証) + - `tools/test/smoke/selfhost/scopebox_identity_smoke.sh` + - `tools/test/smoke/selfhost/loopform_identity_smoke.sh` + - `tools/test/smoke/selfhost/selfhost_runner_smoke.sh` +- [ ] P1: strings/array/map の最小スモークを selfhost 経路で追加(pref=ny) - [ ] P2: path_std/json_std の雛形とアダプタ(プラグイン優先のラップ) - [ ] P2: path/json のスモーク(dirname/join、parse/root/get/size/at/str/int/bool) - [ ] P3: string_builder_std と tests の軽量追加(任意) +**次フェーズ推奨順序**(小粒・安全): +1. ScopeBox 前処理実装(安全包み込み。JSON v0互換維持、If/Loop に "ヒント用余剰キー" 付与) +2. LoopForm 前処理実装(キー順正規化→安全な末尾整列) +3. P1 箱スモーク(pref=ny での一致確認) +4. Stage‑2(自己ホスト実行器): const/ret/branch 骨格+exit code パリティ + Checklist(更新済み) - [x] Self‑host 前展開の固定スモーク 1 本(upper_string) - [x] MacroCtx ctx JSON スモーク 1 本(CI 組み込み) diff --git a/apps/selfhost/vm/boxes/mini_vm_core.nyash b/apps/selfhost/vm/boxes/mini_vm_core.nyash index a68e3ab5..c5bfdb34 100644 --- a/apps/selfhost/vm/boxes/mini_vm_core.nyash +++ b/apps/selfhost/vm/boxes/mini_vm_core.nyash @@ -745,4 +745,3 @@ static box MiniVm { return out } } -} diff --git a/apps/selfhost/vm/boxes/mini_vm_prints.nyash b/apps/selfhost/vm/boxes/mini_vm_prints.nyash index 77c55748..cc35fd82 100644 --- a/apps/selfhost/vm/boxes/mini_vm_prints.nyash +++ b/apps/selfhost/vm/boxes/mini_vm_prints.nyash @@ -1,8 +1,8 @@ -using selfhost.vm.scan as MiniVmScan -using selfhost.vm.binop as MiniVmBinOp -using selfhost.vm.compare as MiniVmCompare +using selfhost.common.mini_vm_scan as MiniVmScan +using selfhost.common.mini_vm_binop as MiniVmBinOp +using selfhost.common.mini_vm_compare as MiniVmCompare // Use the JSON adapter facade for cursor ops (next_non_ws, digits) -using selfhost.vm.json as MiniJsonLoader +using selfhost.vm.boxes.json_cur as MiniJsonLoader static box MiniVmPrints { // dev trace flag (0=OFF) diff --git a/src/jit/lower/extern_thunks.rs b/src/jit/lower/extern_thunks.rs index 27fb75b0..2f3d4f25 100644 --- a/src/jit/lower/extern_thunks.rs +++ b/src/jit/lower/extern_thunks.rs @@ -690,7 +690,7 @@ fn nyash_plugin_invoke_name_common_i64(method: &str, argc: i64, a0: i64, a1: i64 } let box_type = box_type.unwrap_or_default(); // Resolve method_id via PluginHost - let mh = if let Ok(host) = plugin_loader_unified::get_global_plugin_host().read() { + let mh = if let Ok(host) = crate::runtime::plugin_loader_unified::get_global_plugin_host().read() { host.resolve_method(&box_type, method) } else { events::emit_runtime( diff --git a/src/runner/modes/common_util/resolve/strip.rs b/src/runner/modes/common_util/resolve/strip.rs index a54a3ab0..2f74124d 100644 --- a/src/runner/modes/common_util/resolve/strip.rs +++ b/src/runner/modes/common_util/resolve/strip.rs @@ -166,7 +166,10 @@ pub fn strip_using_and_register( } if let Ok(abs) = std::fs::canonicalize(&p) { p = abs; } let key = p.to_string_lossy().to_string(); - if visited.contains(&key) { continue; } + if visited.contains(&key) { + if verbose { eprintln!("[using] skipping already visited: {}", key); } + continue; + } visited.insert(key.clone()); if let Ok(text) = std::fs::read_to_string(&p) { let inlined = strip_and_inline(runner, &text, &key, visited)?; From 75f4eac7856895462203c355b64b4d72090d9487 Mon Sep 17 00:00:00 2001 From: moe-charm Date: Tue, 23 Sep 2025 02:01:56 +0900 Subject: [PATCH 2/2] mini_vm: handle empty function arguments in collect_prints --- apps/selfhost/vm/boxes/mini_vm_core.nyash | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/selfhost/vm/boxes/mini_vm_core.nyash b/apps/selfhost/vm/boxes/mini_vm_core.nyash index c5bfdb34..39e2fd2b 100644 --- a/apps/selfhost/vm/boxes/mini_vm_core.nyash +++ b/apps/selfhost/vm/boxes/mini_vm_core.nyash @@ -593,18 +593,24 @@ static box MiniVm { local fname = json.substring(ni, nj) local ka = "\"arguments\":[" local ap = index_of_from(json, ka, nj) - if ap > 0 { if ap < expr_end { + if ap <= 0 { + local ka0 = "\"arguments\":" + local ap0 = index_of_from(json, ka0, nj) + if ap0 >= 0 { if ap0 < expr_end { ap = ap0 } } + } + if ap >= 0 { if ap < expr_end { // detect empty args [] quickly: no type token inside balanced array local arr_start = index_of_from(json, "[", ap) - local arr_end = new MiniVmScan().find_balanced_array_end(json, arr_start) - if arr_start >= 0 { if arr_end >= 0 { if arr_end <= expr_end { + if arr_start >= 0 { if arr_start < expr_end { + local arr_end = new MiniVmScan().find_balanced_array_end(json, arr_start) + if arr_end >= 0 { if arr_end <= expr_end { local kt = "\"type\":\"" local atpos = index_of_from(json, kt, arr_start) if atpos < 0 || atpos >= arr_end { if fname == "echo" { out.push("") pos = obj_end + 1 continue } if fname == "itoa" { out.push("0") pos = obj_end + 1 continue } } - }}} + }}}} // string arg local ks = "\"type\":\"string\",\"value\":\"" local ps = index_of_from(json, ks, ap)