diff --git a/src/common.rs b/src/common.rs index f2b5a9841d9ee1e0932f4ff1613058e1e2333993..1ff11a20ccb6325adb7d29720b5c100ea6213c23 100644 --- a/src/common.rs +++ b/src/common.rs @@ -44,12 +44,21 @@ pub enum Polarity { #[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Copy, Clone, Debug)] pub struct Key(u64); +pub enum NewMainErr { + NoSuchComponent, + NonPortTypeParameters, + WrongNumberOfArguments { expected: usize }, + WrongPortPolarity { index: usize }, +} pub trait ProtocolDescription: Sized { type S: ComponentState; fn parse(pdl: &[u8]) -> Result; - fn main_interface_polarities(&self) -> Vec; - fn new_main_component(&self, interface: &[Key]) -> Self::S; + fn new_main_component( + &self, + identifier: &[u8], + ports: &[(Polarity, Key)], + ) -> Result; } pub trait ComponentState: Sized + Clone { diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index c3deda22f0cfdfe0559ccda1054ada090fc6ae46..97986eb6333fd7cc9a11578f68d3aa8fac07799d 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -47,26 +47,26 @@ impl ProtocolDescription for ProtocolDescriptionImpl { } } } - fn main_interface_polarities(&self) -> Vec { - let def = &self.heap[self.main]; - let mut result = Vec::new(); - for ¶m in def.parameters().iter() { - let param = &self.heap[param]; - let type_annot = &self.heap[param.type_annotation]; - let ptype = &type_annot.the_type.primitive; - if ptype == &PrimitiveType::Input { - result.push(Polarity::Getter) - } else if ptype == &PrimitiveType::Output { - result.push(Polarity::Putter) - } else { - unreachable!() - } - } - result - } - fn new_main_component(&self, interface: &[Key]) -> ComponentStateImpl { + // fn main_interface_polarities(&self) -> Vec { + // let def = &self.heap[self.main]; + // let mut result = Vec::new(); + // for ¶m in def.parameters().iter() { + // let param = &self.heap[param]; + // let type_annot = &self.heap[param.type_annotation]; + // let ptype = &type_annot.the_type.primitive; + // if ptype == &PrimitiveType::Input { + // result.push(Polarity::Getter) + // } else if ptype == &PrimitiveType::Output { + // result.push(Polarity::Putter) + // } else { + // unreachable!() + // } + // } + // result + // } + fn new_main_component(&self, ports: &[Key]) -> ComponentStateImpl { let mut args = Vec::new(); - for (&x, y) in interface.iter().zip(self.main_interface_polarities()) { + for (&x, y) in ports.iter().zip(self.main_interface_polarities()) { match y { Polarity::Getter => args.push(Value::Input(InputValue(x))), Polarity::Putter => args.push(Value::Output(OutputValue(x))), diff --git a/src/runtime/ffi.rs b/src/runtime/ffi.rs index ddada037c9be6a85e0a518b9d59c6ea85b68a27b..39dd2eb5dfbac74e050db218eaa4be8e52d6ab78 100644 --- a/src/runtime/ffi.rs +++ b/src/runtime/ffi.rs @@ -129,7 +129,7 @@ pub unsafe extern "C" fn connector_configure(connector: *mut Connector, pdl: *mu /// # Safety /// TODO #[no_mangle] -pub unsafe extern "C" fn port_bind_native( +pub unsafe extern "C" fn connector_bind_native( connector: *mut Connector, proto_port_index: usize, ) -> c_int { @@ -152,7 +152,7 @@ pub unsafe extern "C" fn port_bind_native( /// # Safety /// TODO #[no_mangle] -pub unsafe extern "C" fn port_bind_passive( +pub unsafe extern "C" fn connector_bind_passive( connector: *mut Connector, proto_port_index: c_uint, address: *const c_char, @@ -184,7 +184,7 @@ pub unsafe extern "C" fn port_bind_passive( /// # Safety /// TODO #[no_mangle] -pub unsafe extern "C" fn port_bind_active( +pub unsafe extern "C" fn connector_bind_active( connector: *mut Connector, proto_port_index: c_uint, address: *const c_char,