feat(phase-9.78): Improve MIR generation for built-in Box types and enhance LLVM mock

- Fix MIR builder to handle built-in Box types (IntegerBox, StringBox, etc.) specially
- Generate MIR with actual constant values instead of ref_new instructions
- Enhance LLVM mock compiler with MIR interpreter foundation
- Add value storage HashMap for future MIR instruction interpretation

This enables proper MIR generation where 'new IntegerBox(42)' becomes '%0 = const 42'
instead of '%0 = ref_new "IntegerBox"'. This is essential for future LLVM code generation.

Example MIR improvement:
Before:
  %1 = const "IntegerBox"
  %0 = ref_new %1

After:
  %0 = const 42

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-18 19:29:24 +09:00
parent e0ae7f0a1c
commit 9d78ecd089
3 changed files with 150 additions and 41 deletions

View File

@ -716,9 +716,63 @@ impl MirBuilder {
}
/// Build new expression: new ClassName(arguments)
fn build_new_expression(&mut self, class: String, _arguments: Vec<ASTNode>) -> Result<ValueId, String> {
// For Phase 6.1, we'll create a simple RefNew without processing arguments
// In a full implementation, arguments would be used for constructor calls
fn build_new_expression(&mut self, class: String, arguments: Vec<ASTNode>) -> Result<ValueId, String> {
// Special handling for built-in Box types that have single literal arguments
match class.as_str() {
"IntegerBox" => {
if arguments.len() == 1 {
if let ASTNode::Literal { value: LiteralValue::Integer(n), .. } = &arguments[0] {
// For built-in boxes, just return the value directly
// The VM/interpreter will handle boxing when needed
let dst = self.value_gen.next();
self.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Integer(*n),
})?;
return Ok(dst);
}
}
}
"StringBox" => {
if arguments.len() == 1 {
if let ASTNode::Literal { value: LiteralValue::String(s), .. } = &arguments[0] {
let dst = self.value_gen.next();
self.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::String(s.clone()),
})?;
return Ok(dst);
}
}
}
"FloatBox" => {
if arguments.len() == 1 {
if let ASTNode::Literal { value: LiteralValue::Float(f), .. } = &arguments[0] {
let dst = self.value_gen.next();
self.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Float(*f),
})?;
return Ok(dst);
}
}
}
"BoolBox" => {
if arguments.len() == 1 {
if let ASTNode::Literal { value: LiteralValue::Bool(b), .. } = &arguments[0] {
let dst = self.value_gen.next();
self.emit_instruction(MirInstruction::Const {
dst,
value: ConstValue::Bool(*b),
})?;
return Ok(dst);
}
}
}
_ => {}
}
// For other classes, use the original implementation
let dst = self.value_gen.next();
// For now, create a "box type" value representing the class