fix(phase-4.3c-3): Fix StringBox literal handling in MIR builder
Phase 4-3c-3 Complete: WASM host functions now correctly output string content ## Changes: - Fixed MIR builder to handle StringBox with string literal arguments - Special case for to generate proper string constants - Removed debug output after successful verification - WASM now correctly outputs "Hello MIR!" instead of "StringBox" ## Test Results: - MIR generation: ✅ Generates correctly - WASM compilation: ✅ String data correctly placed at offset 4096 - WASM execution: ✅ Outputs "Hello MIR\!" as expected ## Technical Details: - Modified build_new_expression() to detect StringBox with literal arguments - Generates Const instruction with actual string content - Host function reads StringBox memory layout correctly This completes the WASM string output functionality for Phase 4. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
51
src/bin/nyash-wasm-run.rs
Normal file
51
src/bin/nyash-wasm-run.rs
Normal file
@ -0,0 +1,51 @@
|
||||
/*!
|
||||
* Nyash WASM Runner - Execute Nyash WASM modules with host functions
|
||||
*
|
||||
* Phase 4-3c: Standalone WASM executor for testing
|
||||
*/
|
||||
|
||||
use nyash_rust::backend::wasm::{WasmExecutor, WasmError};
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() != 2 {
|
||||
eprintln!("Usage: {} <file.wat>", args[0]);
|
||||
eprintln!("");
|
||||
eprintln!("Execute a Nyash WASM module with host functions");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let wat_file = &args[1];
|
||||
|
||||
if !Path::new(wat_file).exists() {
|
||||
eprintln!("❌ File not found: {}", wat_file);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
println!("🚀 Nyash WASM Runner - Executing: {} 🚀", wat_file);
|
||||
println!("");
|
||||
|
||||
// Create executor
|
||||
let executor = WasmExecutor::new()?;
|
||||
|
||||
// Execute WAT file
|
||||
match executor.execute_wat_file(wat_file) {
|
||||
Ok(output) => {
|
||||
if !output.is_empty() {
|
||||
println!("📝 Program output:");
|
||||
println!("{}", output);
|
||||
}
|
||||
println!("");
|
||||
println!("✅ Execution completed successfully!");
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("❌ Execution error: {}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user