diff --git a/src/protocol/eval/executor.rs b/src/protocol/eval/executor.rs index 68dc3eec80a2ebb90159a4d62401f7eb6c5a727d..aded401d18af5b9c3253fe43f2183f73167db1b4 100644 --- a/src/protocol/eval/executor.rs +++ b/src/protocol/eval/executor.rs @@ -200,6 +200,7 @@ pub enum EvalContinuation { SyncBlockEnd, NewComponent(DefinitionId, i32, ValueGroup), NewChannel, + NewFork, BlockFires(PortId), BlockGet(PortId), Put(PortId, Value), @@ -886,6 +887,33 @@ impl Prompt { Ok(EvalContinuation::SyncBlockEnd) }, + Statement::Fork(stmt) => { + if stmt.right_body.is_none() { + // No reason to fork + cur_frame.position = stmt.left_body.upcast(); + } else { + // Need to fork + if let Some(go_left) = ctx.get_fork() { + // Runtime has created a fork + if go_left { + cur_frame.position = stmt.left_body.upcast(); + } else { + cur_frame.position = stmt.right_body.unwrap().upcast(); + } + } else { + // Request the runtime to create a fork of the current + // branch + return Ok(EvalContinuation::NewFork); + } + } + + Ok(EvalContinuation::Stepping) + }, + Statement::EndFork(stmt) => { + cur_frame.position = stmt.next; + + Ok(EvalContinuation::Stepping) + } Statement::Return(_stmt) => { debug_assert!(heap[cur_frame.definition].is_function()); debug_assert_eq!(cur_frame.expr_values.len(), 1, "expected one expr value for return statement");