Files
@ 7cf6df93d16d
Branch filter:
Location: CSY/reowolf/src/runtime2/component/component.rs - annotation
7cf6df93d16d
1.9 KiB
application/rls-services+xml
Move builtin definitions to std lib
7cf6df93d16d 7cf6df93d16d 5babd5401b1e 7cf6df93d16d 5babd5401b1e 5babd5401b1e 5babd5401b1e 5babd5401b1e 5babd5401b1e 5babd5401b1e 5babd5401b1e 5babd5401b1e 93081320c9fa 5babd5401b1e 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 93081320c9fa 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 7cf6df93d16d 5babd5401b1e | use crate::protocol::eval::*;
use crate::protocol::*;
use crate::runtime2::*;
use super::{CompCtx, CompPDL};
pub enum CompScheduling {
Immediate,
Requeue,
Sleep,
Exit,
}
/// Generic representation of a component (as viewed by a scheduler).
pub(crate) trait Component {
/// Called if the component is created by another component and the messages
/// are being transferred between the two.
fn adopt_message(&mut self, comp_ctx: &mut CompCtx, message: DataMessage);
/// Called if the component receives a new message. The component is
/// responsible for deciding where that messages goes.
fn handle_message(&mut self, sched_ctx: &mut SchedulerCtx, comp_ctx: &mut CompCtx, message: Message);
/// Called if the component's routine should be executed. The return value
/// can be used to indicate when the routine should be run again.
fn run(&mut self, sched_ctx: &mut SchedulerCtx, comp_ctx: &mut CompCtx) -> Result<CompScheduling, EvalError>;
}
/// Creates a new component based on its definition. Meaning that if it is a
/// user-defined component then we set up the PDL code state. Otherwise we
/// construct a custom component. This does NOT take care of port and message
/// management.
pub(crate) fn create_component(
protocol: &ProtocolDescription,
definition_id: ProcedureDefinitionId, type_id: TypeId,
arguments: ValueGroup, num_ports: usize
) -> Box<dyn Component> {
let definition = &protocol.heap[definition_id];
debug_assert!(definition.kind == ProcedureKind::Primitive || definition.kind == ProcedureKind::Composite);
if definition.source.is_builtin() {
// Builtin component
todo!("implement")
} else {
// User-defined component
let prompt = Prompt::new(
&protocol.types, &protocol.heap,
definition_id, type_id, arguments
);
let component = CompPDL::new(prompt, num_ports);
return Box::new(component);
}
}
|