refactor: Gemini/ChatGPT collaborative refactoring + build fixes
Major changes: - Split runner module: 1358→580 lines (via Gemini) - Create new modules: dispatch.rs, selfhost.rs, pipeline.rs, pipe_io.rs - Fix build errors from incomplete method migrations - Add warning to CLAUDE.md about JIT/Cranelift not working - Create interpreter.rs mode module - Refactor loop builder into separate module Build status: - ✅ Executable builds successfully - ✅ Basic execution works (tested with print) - ⚠️ 106 warnings remain (to be cleaned up next) - ⚠️ execute_mir_mode still in mod.rs (needs further migration) Note: ChatGPT correctly fixed runner.execute_mir_mode() calls that I incorrectly changed to super::modes::mir:: 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -7,12 +7,11 @@ use crate::runner::json_v0_bridge;
|
||||
use nyash_rust::parser::NyashParser;
|
||||
use std::{fs, process};
|
||||
|
||||
impl NyashRunner {
|
||||
/// Thin file dispatcher: select backend and delegate to mode executors
|
||||
pub(crate) fn run_file(&self, filename: &str) {
|
||||
/// Thin file dispatcher: select backend and delegate to mode executors
|
||||
pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
|
||||
// Selfhost pipeline (Ny -> JSON v0) behind env gate
|
||||
if std::env::var("NYASH_USE_NY_COMPILER").ok().as_deref() == Some("1") {
|
||||
if self.try_run_selfhost_pipeline(filename) {
|
||||
if runner.try_run_selfhost_pipeline(filename) {
|
||||
return;
|
||||
} else if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[ny-compiler] fallback to default path (MVP unavailable for this input)");
|
||||
@ -20,7 +19,7 @@ impl NyashRunner {
|
||||
}
|
||||
|
||||
// Direct v0 bridge when requested via CLI/env
|
||||
let use_ny_parser = self.config.parser_ny || std::env::var("NYASH_USE_NY_PARSER").ok().as_deref() == Some("1");
|
||||
let use_ny_parser = runner.config.parser_ny || std::env::var("NYASH_USE_NY_PARSER").ok().as_deref() == Some("1");
|
||||
if use_ny_parser {
|
||||
let code = match fs::read_to_string(filename) {
|
||||
Ok(content) => content,
|
||||
@ -31,7 +30,7 @@ impl NyashRunner {
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
println!("🚀 Nyash MIR Interpreter - (parser=ny) Executing file: {} 🚀", filename);
|
||||
}
|
||||
self.execute_mir_module(&module);
|
||||
runner.execute_mir_module(&module);
|
||||
return;
|
||||
}
|
||||
Err(e) => { eprintln!("❌ Direct bridge parse error: {}", e); process::exit(1); }
|
||||
@ -39,7 +38,7 @@ impl NyashRunner {
|
||||
}
|
||||
|
||||
// AST dump mode
|
||||
if self.config.dump_ast {
|
||||
if runner.config.dump_ast {
|
||||
println!("🧠 Nyash AST Dump - Processing file: {}", filename);
|
||||
let code = match fs::read_to_string(filename) {
|
||||
Ok(content) => content,
|
||||
@ -54,35 +53,39 @@ impl NyashRunner {
|
||||
}
|
||||
|
||||
// MIR dump/verify
|
||||
if self.config.dump_mir || self.config.verify_mir {
|
||||
if runner.config.dump_mir || runner.config.verify_mir {
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
println!("🚀 Nyash MIR Compiler - Processing file: {} 🚀", filename);
|
||||
}
|
||||
self.execute_mir_mode(filename);
|
||||
runner.execute_mir_mode(filename);
|
||||
return;
|
||||
}
|
||||
|
||||
// WASM / AOT (feature-gated)
|
||||
if self.config.compile_wasm {
|
||||
if runner.config.compile_wasm {
|
||||
#[cfg(feature = "wasm-backend")]
|
||||
{ self.execute_wasm_mode(filename); return; }
|
||||
{ super::modes::wasm::execute_wasm_mode(runner, filename); return; }
|
||||
#[cfg(not(feature = "wasm-backend"))]
|
||||
{ eprintln!("❌ WASM backend not available. Please rebuild with: cargo build --features wasm-backend"); process::exit(1); }
|
||||
}
|
||||
if self.config.compile_native {
|
||||
if runner.config.compile_native {
|
||||
#[cfg(feature = "cranelift-jit")]
|
||||
{ self.execute_aot_mode(filename); return; }
|
||||
{
|
||||
use super::super::modes::aot;
|
||||
aot::execute_aot_mode(runner, filename);
|
||||
return;
|
||||
}
|
||||
#[cfg(not(feature = "cranelift-jit"))]
|
||||
{ eprintln!("❌ Native AOT compilation requires Cranelift. Please rebuild: cargo build --features cranelift-jit"); process::exit(1); }
|
||||
}
|
||||
|
||||
// Backend selection
|
||||
match self.config.backend.as_str() {
|
||||
match runner.config.backend.as_str() {
|
||||
"mir" => {
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
println!("🚀 Nyash MIR Interpreter - Executing file: {} 🚀", filename);
|
||||
}
|
||||
self.execute_mir_mode(filename);
|
||||
runner.execute_mir_mode(filename);
|
||||
}
|
||||
#[cfg(feature = "cranelift-jit")]
|
||||
"jit-direct" => {
|
||||
@ -91,7 +94,8 @@ impl NyashRunner {
|
||||
}
|
||||
#[cfg(feature = "cranelift-jit")]
|
||||
{
|
||||
crate::runner::modes::cranelift::execute_jit_direct_mode(self, filename);
|
||||
// Use independent JIT-direct runner method (no VM execute loop)
|
||||
runner.run_file_jit_direct(filename);
|
||||
}
|
||||
#[cfg(not(feature = "cranelift-jit"))]
|
||||
{
|
||||
@ -103,22 +107,24 @@ impl NyashRunner {
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
println!("⚡ Nyash LLVM Backend - Executing file: {} ⚡", filename);
|
||||
}
|
||||
self.execute_llvm_mode(filename);
|
||||
runner.execute_llvm_mode(filename);
|
||||
}
|
||||
_ => {
|
||||
if std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1") {
|
||||
println!("🦀 Nyash Rust Implementation - Executing file: {} 🦀", filename);
|
||||
if let Some(fuel) = self.config.debug_fuel {
|
||||
if let Some(fuel) = runner.config.debug_fuel {
|
||||
println!("🔥 Debug fuel limit: {} iterations", fuel);
|
||||
} else {
|
||||
println!("🔥 Debug fuel limit: unlimited");
|
||||
}
|
||||
println!("====================================================");
|
||||
}
|
||||
self.execute_nyash_file(filename);
|
||||
super::modes::interpreter::execute_nyash_file(filename, runner.config.debug_fuel.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NyashRunner {
|
||||
pub(crate) fn execute_mir_module(&self, module: &crate::mir::MirModule) {
|
||||
use crate::backend::MirInterpreter;
|
||||
use crate::box_trait::{IntegerBox, BoolBox, StringBox};
|
||||
|
||||
Reference in New Issue
Block a user