Phase 7.4: Complete async MIR implementation with comprehensive tests

Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-13 11:59:22 +00:00
parent f6e6e5bae4
commit cefac9051e
2 changed files with 405 additions and 2 deletions

View File

@ -178,8 +178,10 @@ impl VM {
let mut should_return = None;
// Execute instructions in this block
println!("Executing block {} with {} instructions", current_block, block.instructions.len());
for (index, instruction) in block.instructions.iter().enumerate() {
self.pc = index;
println!(" Instruction {}: {:?}", index, instruction);
match self.execute_instruction(instruction)? {
ControlFlow::Continue => continue,
@ -194,6 +196,8 @@ impl VM {
}
}
println!("Block execution finished. should_return: {:?}, next_block: {:?}", should_return.is_some(), next_block.is_some());
// Handle control flow
if let Some(return_value) = should_return {
return Ok(return_value);
@ -209,6 +213,7 @@ impl VM {
/// Execute a single instruction
fn execute_instruction(&mut self, instruction: &MirInstruction) -> Result<ControlFlow, VMError> {
println!("Executing instruction: {:?}", instruction);
match instruction {
MirInstruction::Const { dst, value } => {
let vm_value = VMValue::from(value);
@ -247,8 +252,11 @@ impl VM {
MirInstruction::Return { value } => {
let return_value = if let Some(val_id) = value {
self.get_value(*val_id)?
let val = self.get_value(*val_id)?;
println!("Return: returning value from {:?} = {:?}", val_id, val);
val
} else {
println!("Return: returning void (no value specified)");
VMValue::Void
};
Ok(ControlFlow::Return(return_value))
@ -463,10 +471,14 @@ impl VM {
// Phase 7: Async/Future Operations
MirInstruction::FutureNew { dst, value } => {
let initial_value = self.get_value(*value)?;
println!("FutureNew: initial_value = {:?}", initial_value);
let future = crate::boxes::future::FutureBox::new();
// Convert VMValue to NyashBox and set it in the future
future.set_result(initial_value.to_nyash_box());
let nyash_box = initial_value.to_nyash_box();
println!("FutureNew: converted to NyashBox type = {}", nyash_box.type_name());
future.set_result(nyash_box);
self.values.insert(*dst, VMValue::Future(future));
println!("FutureNew: stored Future in dst = {:?}", dst);
Ok(ControlFlow::Continue)
},
@ -484,12 +496,16 @@ impl VM {
MirInstruction::Await { dst, future } => {
let future_val = self.get_value(*future)?;
println!("Await: future_val = {:?}", future_val);
if let VMValue::Future(ref future_box) = future_val {
// This blocks until the future is ready
let result = future_box.get();
println!("Await: future.get() returned type = {}", result.type_name());
println!("Await: future.get() string = {}", result.to_string_box().value);
// Convert NyashBox back to VMValue
let vm_value = VMValue::from_nyash_box(result);
println!("Await: converted back to VMValue = {:?}", vm_value);
self.values.insert(*dst, vm_value);
Ok(ControlFlow::Continue)
} else {