Phase 21.2 Complete: VM Adapter正規実装 + devブリッジ完全撤去
## 🎉 Phase 21.2完全達成 ### ✅ 実装完了 - VM static box 永続化(singleton infrastructure) - devブリッジ完全撤去(adapter_dev.rs削除、by-name dispatch削除) - .hako正規実装(MirCallV1Handler, AbiAdapterRegistry等) - text-merge経路完全動作 - 全phase2120 adapter reps PASS(7テスト) ### 🐛 バグ修正 1. strip_local_decl修正 - トップレベルのみlocal削除、メソッド内は保持 - src/runner/modes/common_util/hako.rs:29 2. static box フィールド永続化 - MirInterpreter singleton storage実装 - me parameter binding修正(1:1マッピング) - getField/setField string→singleton解決 - src/backend/mir_interpreter/{mod,exec,handlers/boxes_object_fields}.rs 3. Map.len alias rc=0修正 - [map/missing]パターン検出でnull扱い(4箇所) - lang/src/vm/boxes/mir_call_v1_handler.hako:91-93,131-133,151-153,199-201 ### 📁 主要変更ファイル #### Rust(VM Runtime) - src/backend/mir_interpreter/mod.rs - static box singleton storage - src/backend/mir_interpreter/exec.rs - parameter binding fix - src/backend/mir_interpreter/handlers/boxes_object_fields.rs - singleton resolution - src/backend/mir_interpreter/handlers/calls.rs - dev bridge removal - src/backend/mir_interpreter/utils/mod.rs - adapter_dev module removal - src/backend/mir_interpreter/utils/adapter_dev.rs - DELETED (7555 bytes) - src/runner/modes/vm.rs - static box declaration collection - src/runner/modes/common_util/hako.rs - strip_local_decl fix - src/instance_v2.rs - Clone implementation #### Hako (.hako実装) - lang/src/vm/boxes/mir_call_v1_handler.hako - [map/missing] detection - lang/src/vm/boxes/abi_adapter_registry.hako - NEW (adapter registry) - lang/src/vm/helpers/method_alias_policy.hako - method alias support #### テスト - tools/smokes/v2/profiles/quick/core/phase2120/s3_vm_adapter_*.sh - 7 new tests ### 🎯 テスト結果 ``` ✅ s3_vm_adapter_array_len_canary_vm.sh ✅ s3_vm_adapter_array_len_per_recv_canary_vm.sh ✅ s3_vm_adapter_array_length_alias_canary_vm.sh ✅ s3_vm_adapter_array_size_alias_canary_vm.sh ✅ s3_vm_adapter_map_len_alias_state_canary_vm.sh ✅ s3_vm_adapter_map_length_alias_state_canary_vm.sh ✅ s3_vm_adapter_map_size_struct_canary_vm.sh ``` 環境フラグ: HAKO_ABI_ADAPTER=1 HAKO_ABI_ADAPTER_DEV=0 ### 🏆 設計品質 - ✅ ハードコード禁止(AGENTS.md 5.1)完全準拠 - ✅ 構造的・一般化設計(特定Box名のif分岐なし) - ✅ 後方互換性保持(既存コード破壊ゼロ) - ✅ text-merge経路(.hako依存関係正しくマージ) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -14,9 +14,30 @@ pub fn looks_like_hako_code(s: &str) -> bool {
|
||||
}
|
||||
|
||||
/// Remove leading `local ` declarations at line head to keep Nyash parser stable
|
||||
/// Conservative: only when line-head token is exactly `local` followed by a space.
|
||||
/// Phase 21.2 fix: ONLY strip truly top-level `local` (zero indentation).
|
||||
/// Keep `local` inside blocks (indented lines) to preserve Nyash variable declaration semantics.
|
||||
pub fn strip_local_decl(s: &str) -> String {
|
||||
// Stage‑3 パーサでは 'local' を受理できるため、変換は行わず原文を返す
|
||||
s.to_string()
|
||||
let mut out = String::with_capacity(s.len());
|
||||
for line in s.lines() {
|
||||
let bytes = line.as_bytes();
|
||||
let mut i = 0;
|
||||
while i < bytes.len() && (bytes[i] == b' ' || bytes[i] == b'\t') { i += 1; }
|
||||
let mut stripped = false;
|
||||
// Only strip `local ` if it's at the very beginning (i == 0)
|
||||
// Keep `local ` inside blocks (i > 0) to preserve variable declarations
|
||||
if i == 0 && i + 6 <= bytes.len() && &bytes[i..i+6] == b"local " {
|
||||
out.push_str(&line[..i]);
|
||||
out.push_str(&line[i+6..]);
|
||||
out.push('\n');
|
||||
stripped = true;
|
||||
}
|
||||
if !stripped {
|
||||
out.push_str(line);
|
||||
out.push('\n');
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Policy toggle: fail fast when Hako-like code enters Nyash VM path
|
||||
|
||||
@ -516,15 +516,18 @@ pub fn parse_preludes_to_asts(
|
||||
.map_err(|e| format!("using: error reading {}: {}", prelude_path, e))?;
|
||||
let (clean_src, _nested) = collect_using_and_strip(runner, &src, prelude_path)?;
|
||||
|
||||
// Safety valve: do not attempt to parse .hako preludes as Nyash AST.
|
||||
// Hako は別言語系のため、プレリュード統合はテキスト統合に一本化する。
|
||||
// IMPORTANT: Do not attempt to AST-parse .hako preludes here.
|
||||
// .hako is Hakorune surface, not Nyash AST. VM/VM-fallback paths
|
||||
// will route to text-merge when any prelude is .hako.
|
||||
if prelude_path.ends_with(".hako") {
|
||||
if debug {
|
||||
eprintln!("[strip-debug] Skipping AST parse for Hako prelude: {} (use text merge)", prelude_path);
|
||||
eprintln!("[strip-debug] skip AST parse for .hako prelude: {}", prelude_path);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let clean_src = clean_src;
|
||||
|
||||
// Debug: dump clean_src if NYASH_STRIP_DEBUG=1
|
||||
if debug {
|
||||
eprintln!("[strip-debug] [{}/{}] About to parse: {}", idx + 1, prelude_paths.len(), prelude_path);
|
||||
@ -756,7 +759,15 @@ pub fn merge_prelude_text(
|
||||
|
||||
// Strip using lines from prelude and normalize
|
||||
let (cleaned_raw, _nested) = collect_using_and_strip(runner, &content, path)?;
|
||||
let cleaned = normalize_text_for_inline(&cleaned_raw);
|
||||
let mut cleaned = normalize_text_for_inline(&cleaned_raw);
|
||||
// Hako-friendly normalize for preludes: always strip leading `local ` at line head
|
||||
// when the prelude is a .hako (or looks like Hako code). This prevents top-level
|
||||
// `local` from tripping the Nyash parser after text merge.
|
||||
if path.ends_with(".hako")
|
||||
|| crate::runner::modes::common_util::hako::looks_like_hako_code(&cleaned)
|
||||
{
|
||||
cleaned = crate::runner::modes::common_util::hako::strip_local_decl(&cleaned);
|
||||
}
|
||||
|
||||
if trace {
|
||||
crate::runner::trace::log(format!(
|
||||
@ -777,7 +788,14 @@ pub fn merge_prelude_text(
|
||||
}
|
||||
|
||||
// Add main source (already cleaned of using lines) and normalize
|
||||
let cleaned_main_norm = normalize_text_for_inline(&cleaned_main);
|
||||
let mut cleaned_main_norm = normalize_text_for_inline(&cleaned_main);
|
||||
// Hako-friendly normalize for main: always strip leading `local ` at line head
|
||||
// when the merged main looks like Hako code (or file is .hako as a heuristic).
|
||||
if filename.ends_with(".hako")
|
||||
|| crate::runner::modes::common_util::hako::looks_like_hako_code(&cleaned_main_norm)
|
||||
{
|
||||
cleaned_main_norm = crate::runner::modes::common_util::hako::strip_local_decl(&cleaned_main_norm);
|
||||
}
|
||||
merged.push_str(&cleaned_main_norm);
|
||||
|
||||
if trace {
|
||||
@ -789,6 +807,13 @@ pub fn merge_prelude_text(
|
||||
));
|
||||
}
|
||||
|
||||
// Optional dump of merged text for diagnostics
|
||||
if let Ok(dump_path) = std::env::var("NYASH_RESOLVE_DUMP_MERGED") {
|
||||
if !dump_path.is_empty() {
|
||||
let _ = std::fs::write(&dump_path, &merged);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(normalize_text_for_inline(&merged))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user