Implement Phase 6 Box reference operations in MIR/VM - RefNew/RefGet/RefSet/WeakNew/WeakLoad/Barrier*

Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-13 09:45:22 +00:00
parent 65ce7a5f8c
commit 84d2aac8da
9 changed files with 416 additions and 4 deletions

View File

@ -192,6 +192,10 @@ impl MirBuilder {
}
},
ASTNode::FieldAccess { object, field, .. } => {
self.build_field_access(*object.clone(), field.clone())
},
_ => {
Err(format!("Unsupported AST node type: {:?}", ast))
}
@ -657,6 +661,29 @@ impl MirBuilder {
}
}
/// Build field access: object.field
fn build_field_access(&mut self, object: ASTNode, field: String) -> Result<ValueId, String> {
// First, build the object expression to get its ValueId
let object_value = self.build_expression(object)?;
// Create a reference to the object
let ref_id = self.value_gen.next();
self.emit_instruction(MirInstruction::RefNew {
dst: ref_id,
box_val: object_value,
})?;
// Get the field from the reference
let result_id = self.value_gen.next();
self.emit_instruction(MirInstruction::RefGet {
dst: result_id,
reference: ref_id,
field,
})?;
Ok(result_id)
}
/// Start a new basic block
fn start_new_block(&mut self, block_id: BasicBlockId) -> Result<(), String> {
if let Some(ref mut function) = self.current_function {