diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 62481340e1b64cfaf42180b4dc1041409f4d733b..fade25ccafb1caa91db843d4930698c93c605a4c 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -52,6 +52,7 @@ pub enum ComponentCreationError { InvalidNumArguments, InvalidArgumentType(usize), UnownedPort, + InSync, } impl std::fmt::Debug for ProtocolDescription { @@ -283,10 +284,11 @@ impl ProtocolDescription { // TODO: @temp Should just become a concrete thing that is passed in pub trait RunContext { - fn did_put(&mut self, port: PortId) -> bool; - fn get(&mut self, port: PortId) -> Option; // None if still waiting on message + fn performed_put(&mut self, port: PortId) -> bool; + fn performed_get(&mut self, port: PortId) -> Option; // None if still waiting on message fn fires(&mut self, port: PortId) -> Option; // None if not yet branched - fn get_channel(&mut self) -> Option<(Value, Value)>; // None if not yet prepared + fn performed_fork(&mut self) -> Option; // None if not yet forked + fn created_channel(&mut self) -> Option<(Value, Value)>; // None if not yet prepared } #[derive(Debug)] @@ -299,8 +301,9 @@ pub enum RunResult { // Can only occur inside sync blocks BranchInconsistent, // branch has inconsistent behaviour BranchMissingPortState(PortId), // branch doesn't know about port firing - BranchMissingPortValue(PortId), // branch hasn't received message on input port yet + BranchGet(PortId), // branch hasn't received message on input port yet BranchAtSyncEnd, + BranchFork, BranchPut(PortId, ValueGroup), } @@ -328,8 +331,10 @@ impl ComponentState { return RR::NewComponent(definition_id, monomorph_idx, args), EC::NewChannel => return RR::NewChannel, + EC::NewFork => + return RR::BranchFork, EC::BlockFires(port_id) => return RR::BranchMissingPortState(port_id), - EC::BlockGet(port_id) => return RR::BranchMissingPortValue(port_id), + EC::BlockGet(port_id) => return RR::BranchGet(port_id), EC::Put(port_id, value) => { let value_group = ValueGroup::from_store(&self.prompt.store, &[value]); return RR::BranchPut(port_id, value_group); @@ -397,6 +402,7 @@ impl ComponentState { // to the runtime unreachable!(); }, + EvalContinuation::NewFork => unreachable!(), // Outside synchronous blocks, no fires/get/put happens EvalContinuation::BlockFires(_) => unreachable!(), EvalContinuation::BlockGet(_) => unreachable!(), @@ -430,6 +436,7 @@ impl ComponentState { // Not possible to create component in sync block EvalContinuation::NewComponent(_, _, _) => unreachable!(), EvalContinuation::NewChannel => unreachable!(), + EvalContinuation::NewFork => unreachable!(), EvalContinuation::BlockFires(port) => { return SyncBlocker::CouldntCheckFiring(port); }, @@ -462,7 +469,7 @@ impl ComponentState { } impl RunContext for EvalContext<'_> { - fn did_put(&mut self, port: PortId) -> bool { + fn performed_put(&mut self, port: PortId) -> bool { match self { EvalContext::None => unreachable!(), EvalContext::Nonsync(_) => unreachable!(), @@ -472,7 +479,7 @@ impl RunContext for EvalContext<'_> { } } - fn get(&mut self, port: PortId) -> Option { + fn performed_get(&mut self, port: PortId) -> Option { match self { EvalContext::None => unreachable!(), EvalContext::Nonsync(_) => unreachable!(), @@ -511,7 +518,7 @@ impl RunContext for EvalContext<'_> { } } - fn get_channel(&mut self) -> Option<(Value, Value)> { + fn created_channel(&mut self) -> Option<(Value, Value)> { match self { EvalContext::None => unreachable!(), EvalContext::Nonsync(context) => { @@ -523,6 +530,11 @@ impl RunContext for EvalContext<'_> { EvalContext::Sync(_) => unreachable!(), } } + + fn performed_fork(&mut self) -> Option { + // Never actually used in the old runtime + return None; + } } // TODO: @remove once old runtime has disappeared