refactor(naming): 箱理論 - Entry選択ロジック統一&NamingBox統合
Phase 25.4 メンテナンス: Task A延長線上の箱化リファクタリング
## 📦 箱化内容
### 1. Entry選択ロジック統一箱
- 新規作成: `src/runner/modes/common_util/entry_selection.rs`
- 3箇所の重複ロジックを `select_entry_function()` に集約
- `selfhost/json.rs:48-59` (11行削減)
- `pyvm.rs:32-43` (11行削減)
- `pyvm.rs:102-113` (11行削減)
- `llvm.rs:292` (直接アクセス→統一関数呼び出し)
### 2. NamingBox SSOT 統合
- arity-aware優先フォールバック実装
1. `Main.main/0` (arity付き、NYASH_BUILD_STATIC_MAIN_ENTRY=1時)
2. `Main.main` (legacy、arity無し、現行デフォルト)
3. `main` (top-level、NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1時)
4. `"Main.main"` (デフォルトフォールバック)
## 技術的成果
- **重複削減**: 33行の重複ロジック→1箇所に集約
- **NamingBox統一**: 全Entry選択が `src/mir/naming.rs` 経由
- **将来対応**: arity付き名前に自動対応(互換性維持)
## テスト結果
✅ cargo test mir_static_box_naming: 2 passed
✅ cargo test stage1_cli_entry_ssa_smoke: 2 passed
## 参考
- Phase 25.4-A完了commit: fa9cea51
- 箱理論原則: 重複ロジックを箱化→境界を明確化→一元管理
🎉 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -29,18 +29,8 @@ pub fn run_pyvm_harness(module: &crate::mir::MirModule, tag: &str) -> Result<i32
|
||||
tag,
|
||||
mir_json_path.display()
|
||||
);
|
||||
// Determine entry function (prefer Main.main; top-level main only if allowed)
|
||||
let allow_top = crate::config::env::entry_allow_toplevel_main();
|
||||
let entry = if module.functions.contains_key("Main.main") {
|
||||
"Main.main"
|
||||
} else if allow_top && module.functions.contains_key("main") {
|
||||
"main"
|
||||
} else if module.functions.contains_key("main") {
|
||||
eprintln!("[entry] Warning: using top-level 'main' without explicit allow; set NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 to silence.");
|
||||
"main"
|
||||
} else {
|
||||
"Main.main"
|
||||
};
|
||||
// NamingBox SSOT: Select entry (arity-aware, Main.main → main fallback)
|
||||
let entry = super::entry_selection::select_entry_function(&module);
|
||||
// Optional: Mini‑VM stdin loader — when enabled, read entire stdin and pass as argv[0]
|
||||
let mut cmd = std::process::Command::new(py3);
|
||||
crate::runner::child_env::apply_core_wrapper_env(&mut cmd);
|
||||
@ -58,7 +48,7 @@ pub fn run_pyvm_harness(module: &crate::mir::MirModule, tag: &str) -> Result<i32
|
||||
"--in",
|
||||
&mir_json_path.display().to_string(),
|
||||
"--entry",
|
||||
entry,
|
||||
&entry,
|
||||
"--args-env",
|
||||
"NYASH_SCRIPT_ARGS_JSON",
|
||||
])
|
||||
@ -99,18 +89,8 @@ pub fn run_pyvm_harness_lib(module: &nyash_rust::mir::MirModule, tag: &str) -> R
|
||||
tag,
|
||||
mir_json_path.display()
|
||||
);
|
||||
// Determine entry function (prefer Main.main; top-level main only if allowed)
|
||||
let allow_top = crate::config::env::entry_allow_toplevel_main();
|
||||
let entry = if module.functions.contains_key("Main.main") {
|
||||
"Main.main"
|
||||
} else if allow_top && module.functions.contains_key("main") {
|
||||
"main"
|
||||
} else if module.functions.contains_key("main") {
|
||||
eprintln!("[entry] Warning: using top-level 'main' without explicit allow; set NYASH_ENTRY_ALLOW_TOPLEVEL_MAIN=1 to silence.");
|
||||
"main"
|
||||
} else {
|
||||
"Main.main"
|
||||
};
|
||||
// NamingBox SSOT: Select entry (arity-aware, Main.main → main fallback)
|
||||
let entry = super::entry_selection::select_entry_function(&module);
|
||||
let mut cmd = std::process::Command::new(py3);
|
||||
crate::runner::child_env::apply_core_wrapper_env(&mut cmd);
|
||||
if std::env::var("NYASH_MINIVM_READ_STDIN").ok().as_deref() == Some("1") {
|
||||
@ -126,7 +106,7 @@ pub fn run_pyvm_harness_lib(module: &nyash_rust::mir::MirModule, tag: &str) -> R
|
||||
"--in",
|
||||
&mir_json_path.display().to_string(),
|
||||
"--entry",
|
||||
entry,
|
||||
&entry,
|
||||
"--args-env",
|
||||
"NYASH_SCRIPT_ARGS_JSON",
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user