feat(phase-9.77): Implement BoxCall instructions and fix wasmtime version

Phase 9.77 WASM Emergency Recovery Progress:
-  Task 1.1: Implement BoxCall instruction for toString(), print(), equals(), clone(), log()
-  Task 1.2: Update wasmtime 18.0 → 35.0.0 and add runtime imports
- 🔄 Task 1.3: Working on UTF-8 encoding error fix

Changes:
- Add generate_box_call() method in codegen.rs with 5 helper methods
- Update wasmtime dependency to 35.0.0 for AOT compatibility
- Add BoxCall runtime imports (box_to_string, box_print, box_equals, box_clone)
- Implement wat_to_wasm() with UTF-8 validation and debug output
- Update CURRENT_TASK.md with Copilot handoff notes

Current issue: 'Generated WASM is not valid UTF-8' error source unknown
Next: Copilot to investigate error origin and complete Task 1.3

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-16 21:21:51 +09:00
parent fa1a3ad644
commit cde961defc
9 changed files with 288 additions and 5 deletions

View File

@ -61,9 +61,36 @@ impl WasmBackend {
// Generate WAT (WebAssembly Text) first for debugging
let wat_text = self.compile_to_wat(mir_module)?;
// Convert WAT to WASM binary using wabt
wabt::wat2wasm(&wat_text)
.map_err(|e| WasmError::WasmValidationError(format!("WAT to WASM conversion failed: {}", e)))
// Phase 9.77 Task 1.3: Fix UTF-8 encoding error in WAT→WASM conversion
self.wat_to_wasm(&wat_text)
}
/// Convert WAT text to WASM binary with proper UTF-8 handling
fn wat_to_wasm(&self, wat_source: &str) -> Result<Vec<u8>, WasmError> {
// Debug: Print WAT source for analysis
eprintln!("🔍 WAT Source Debug (length: {}):", wat_source.len());
eprintln!("WAT Content:\n{}", wat_source);
// UTF-8 validation to prevent encoding errors
if !wat_source.is_ascii() {
eprintln!("❌ WAT source contains non-ASCII characters");
return Err(WasmError::WasmValidationError(
"WAT source contains non-ASCII characters".to_string()
));
}
eprintln!("✅ WAT source is ASCII-compatible");
// Convert to bytes as required by wabt::wat2wasm
eprintln!("🔄 Converting WAT to WASM bytes...");
let wasm_bytes = wabt::wat2wasm(wat_source.as_bytes())
.map_err(|e| {
eprintln!("❌ wabt::wat2wasm failed: {}", e);
WasmError::WasmValidationError(format!("WAT to WASM conversion failed: {}", e))
})?;
eprintln!("✅ WASM conversion successful, {} bytes generated", wasm_bytes.len());
Ok(wasm_bytes)
}
/// Compile MIR module to WAT text format (for debugging)