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:
Moe Charm
2025-08-17 13:49:35 +09:00
parent bb3f2e8032
commit 3df87fb1ce
41 changed files with 4444 additions and 68 deletions

View File

@ -435,10 +435,31 @@ impl VM {
// Phase 6: Box reference operations
MirInstruction::RefNew { dst, box_val } => {
// For now, a reference is just the same as the box value
// In a real implementation, this would create a proper reference
// Get the box type/value from the previous Const instruction
let box_value = self.get_value(*box_val)?;
self.values.insert(*dst, box_value);
// If this is a Box type name (like "StringBox", "IntegerBox"), create an appropriate default value
// In the context of Everything is Box, this should create the actual Box instance
let ref_value = match &box_value {
VMValue::String(type_name) => {
match type_name.as_str() {
"StringBox" => {
// For StringBox, we need the actual string content from previous context
// For now, create an empty string - this should be improved to use the actual value
VMValue::String(String::new())
},
"IntegerBox" => VMValue::Integer(0),
"BoolBox" => VMValue::Bool(false),
_ => {
// If it's a regular string (not a type name), use it as-is
VMValue::String(type_name.clone())
}
}
},
_ => box_value, // For non-string values, use as-is
};
self.values.insert(*dst, ref_value);
Ok(ControlFlow::Continue)
},