Files
hakorune/src/runner/modes/llvm/fallback_executor.rs
tomoaki f740e6542f feat(phase285): Complete weak reference implementation (VM + LLVM harness)
Phase 285LLVM-1.1 to 1.4 + weak reference infrastructure:

**LLVM Harness** (Phase 285LLVM-1.x):
- 285LLVM-1.1: User Box registration & debug output
- 285LLVM-1.2: WeakRef basic operations (identity deferred)
- 285LLVM-1.3: InstanceBox field access (getField/setField)
- 285LLVM-1.4: print Handle resolution (type tag propagation)

**VM Runtime** (nyash_kernel):
- FFI functions: nyrt_weak_new, nyrt_weak_to_strong, nyrt_weak_drop
  (crates/nyash_kernel/src/lib.rs: +209 lines)
- WeakRef plugin invoke support
  (crates/nyash_kernel/src/plugin/invoke.rs: +250 lines)
- weak_handles.rs: WeakRef handle registry (NEW)

**LLVM Python Backend**:
- WeakRef instruction lowering (weak.py: NEW)
- Entry point integration (entry.py: +93 lines)
- Instruction lowering (instruction_lower.py: +13 lines)
- LLVM harness runner script (tools/run_llvm_harness.sh: NEW)

**MIR & Runtime**:
- WeakRef emission & validation
- MIR JSON export for weak instructions
- Environment variable support (NYASH_WEAK_*, HAKO_WEAK_*)

**Documentation**:
- CLAUDE.md: Phase 285 completion notes
- LANGUAGE_REFERENCE_2025.md: Weak reference syntax
- 10-Now.md & 30-Backlog.md: Phase 285 status updates

Total: +864 lines, 24 files changed

SSOT: docs/reference/language/lifecycle.md
Related: Phase 285W-Syntax-0, Phase 285W-Syntax-0.1
2025-12-25 00:11:34 +09:00

65 lines
2.8 KiB
Rust

//! Fallback executor for LLVM mode (mock/legacy)
//!
//! Handles fallback execution when LLVM backends are not available.
use nyash_rust::{mir::MirModule, mir::MirInstruction};
use super::error::LlvmRunError;
/// Fallback executor Box
///
/// **Responsibility**: Execute fallback path (feature check + mock)
/// **Input**: &MirModule
/// **Output**: Result<i32, LlvmRunError> (Ok(exit_code) on success, Err on failure)
pub struct FallbackExecutorBox;
impl FallbackExecutorBox {
/// Execute fallback path (feature check + mock)
///
/// Fail-fast: if the user explicitly requested the llvmlite harness
/// but this binary was built without the `llvm-harness` feature,
/// do not silently fall back to mock.
///
/// Otherwise, executes mock execution that inspects the MIR
/// and returns a deterministic exit code based on Return instructions.
pub fn execute(module: &MirModule) -> Result<i32, LlvmRunError> {
// Fail-fast: if the user explicitly requested the llvmlite harness
// but this binary was built without the `llvm-harness` feature,
// do not silently fall back to mock.
if crate::config::env::env_bool("NYASH_LLVM_USE_HARNESS") {
return Err(LlvmRunError::fatal(
"LLVM harness requested (NYASH_LLVM_USE_HARNESS=1), but this binary was built without `--features llvm` (llvm-harness).\n\
Fix:\n cargo build --release -p nyash-rust --features llvm --bin hakorune\n\
Then ensure prerequisites:\n cargo build --release -p nyash-llvm-compiler\n cargo build --release -p nyash_kernel\n\
Tip: tools/run_llvm_harness.sh <program.hako>"
));
}
crate::console_println!("🔧 Mock LLVM Backend Execution:");
crate::console_println!(" Build with --features llvm for real backend.");
// NamingBox SSOT: Select entry (arity-aware, Main.main → main fallback)
let entry = crate::runner::modes::common_util::entry_selection::select_entry_function(module);
if let Some(main_func) = module.functions.get(&entry) {
for (_bid, block) in &main_func.blocks {
for inst in &block.instructions {
match inst {
MirInstruction::Return { value: Some(_) } => {
crate::console_println!("✅ Mock exit code: 42");
return Ok(42);
}
MirInstruction::Return { value: None } => {
crate::console_println!("✅ Mock exit code: 0");
return Ok(0);
}
_ => {}
}
}
}
}
crate::console_println!("✅ Mock exit code: 0");
Ok(0)
}
}