Files
hakorune/src/main.rs
nyash-codex f9d100ce01 chore: Phase 25.1 完了 - LoopForm v2/Stage1 CLI/環境変数削減 + Phase 26-D からの変更
Phase 25.1 完了成果:
-  LoopForm v2 テスト・ドキュメント・コメント完備
  - 4ケース(A/B/C/D)完全テストカバレッジ
  - 最小再現ケース作成(SSAバグ調査用)
  - SSOT文書作成(loopform_ssot.md)
  - 全ソースに [LoopForm] コメントタグ追加

-  Stage-1 CLI デバッグ環境構築
  - stage1_cli.hako 実装
  - stage1_bridge.rs ブリッジ実装
  - デバッグツール作成(stage1_debug.sh/stage1_minimal.sh)
  - アーキテクチャ改善提案文書

-  環境変数削減計画策定
  - 25変数の完全調査・分類
  - 6段階削減ロードマップ(25→5、80%削減)
  - 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG)

Phase 26-D からの累積変更:
- PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等)
- MIRビルダーリファクタリング
- 型伝播・最適化パス改善
- その他約300ファイルの累積変更

🎯 技術的成果:
- SSAバグ根本原因特定(条件分岐内loop変数変更)
- Region+next_iパターン適用完了(UsingCollectorBox等)
- LoopFormパターン文書化・テスト化完了
- セルフホスティング基盤強化

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: ChatGPT <noreply@openai.com>
Co-Authored-By: Task Assistant <task@anthropic.com>
2025-11-21 06:25:17 +09:00

87 lines
3.5 KiB
Rust

/*!
Minimal CLI entry point for Nyash.
Delegates to the library crate (`nyash_rust`) for all functionality.
*/
use nyash_rust::cli::CliConfig;
use nyash_rust::config::env as env_config;
use nyash_rust::runner::NyashRunner;
/// Thin entry point - delegates to CLI parsing and runner execution
fn main() {
// Optional: enable backtrace on stack overflow for deep debug runs.
// Guarded by env to keep default behavior unchanged.
if std::env::var("NYASH_DEBUG_STACK_OVERFLOW").ok().as_deref() == Some("1") {
unsafe {
let _ = backtrace_on_stack_overflow::enable();
}
}
// hv1 direct (primary): earliest possible check before any bootstrap/log init
// If NYASH_VERIFY_JSON is present and route is requested, execute and exit.
// This avoids plugin host/registry initialization and keeps output minimal.
let has_json = std::env::var("NYASH_VERIFY_JSON").is_ok();
let route = nyash_rust::config::env::verify_primary_is_hakovm();
// Force flag may allow hv1-inline without route
let force_hv1_flag = nyash_rust::config::env::env_bool("HAKO_VERIFY_V1_FORCE_HAKOVM");
if has_json && (route || force_hv1_flag) {
let json = std::env::var("NYASH_VERIFY_JSON").unwrap_or_default();
// Option A: force hv1 inline (dev) — bypass parser entirely
if force_hv1_flag {
let rc = nyash_rust::runner::hv1_inline::run_json_v1_inline(&json);
println!("{}", rc);
std::process::exit(rc);
}
// Minimal runner (no plugin init here); config parse is cheap and has no side effects.
let cfg = CliConfig::parse();
let runner = NyashRunner::new(cfg);
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
eprintln!("[hv1-direct] early-exit (main)");
}
let rc = nyash_rust::runner::core_executor::run_json_v0(&runner, &json);
println!("{}", rc);
std::process::exit(rc);
}
// Bootstrap env overrides from nyash.toml [env] early (管理棟)
env_config::bootstrap_from_toml_env();
// Parse command-line arguments
let config = CliConfig::parse();
// Deprecation notice when invoked via legacy binary name
if let Ok(exe) = std::env::current_exe() {
if let Some(name) = exe.file_name().and_then(|s| s.to_str()) {
if name.eq_ignore_ascii_case("nyash") {
eprintln!("[deprecate] 'nyash' binary is deprecated. Please use 'hakorune'.");
}
}
}
// Legacy binary deprecation: prefer 'hakorune'
if let Ok(exe) = std::env::current_exe() {
if let Some(name) = exe.file_name().and_then(|s| s.to_str()) {
let allow_legacy = std::env::var("HAKO_ALLOW_NYASH").ok().as_deref() == Some("1")
|| std::env::var("NYASH_ALLOW_NYASH").ok().as_deref() == Some("1");
if name.eq_ignore_ascii_case("nyash") && !allow_legacy {
eprintln!("[deprecate] 'nyash' binary is deprecated. Please use 'hakorune'.");
std::process::exit(2);
}
}
}
// Create and run the execution coordinator
let runner = NyashRunner::new(config);
runner.run();
}
#[cfg(test)]
mod tests {
use super::*;
use nyash_rust::box_trait::{BoxCore, NyashBox, StringBox};
#[test]
fn test_main_functionality() {
// Smoke: library module path wiring works
let string_box = StringBox::new("test".to_string());
assert_eq!(string_box.to_string_box().value, "test");
let _ = (); // CLI wiring exists via nyash_rust::cli
}
}