Changeset - 3f0b1a4ef61f
[Not reviewed]
0 3 0
Christopher Esterhuyse - 5 years ago 2020-02-05 17:11:01
christopheresterhuyse@gmail.com
api change
3 files changed with 33 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/common.rs
Show inline comments
 
@@ -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<D = Self>;
 

	
 
    fn parse(pdl: &[u8]) -> Result<Self, String>;
 
    fn main_interface_polarities(&self) -> Vec<Polarity>;
 
    fn new_main_component(&self, interface: &[Key]) -> Self::S;
 
    fn new_main_component(
 
        &self,
 
        identifier: &[u8],
 
        ports: &[(Polarity, Key)],
 
    ) -> Result<Self::S, NewMainErr>;
 
}
 

	
 
pub trait ComponentState: Sized + Clone {
src/protocol/mod.rs
Show inline comments
 
@@ -47,26 +47,26 @@ impl ProtocolDescription for ProtocolDescriptionImpl {
 
            }
 
        }
 
    }
 
    fn main_interface_polarities(&self) -> Vec<Polarity> {
 
        let def = &self.heap[self.main];
 
        let mut result = Vec::new();
 
        for &param 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<Polarity> {
 
    //     let def = &self.heap[self.main];
 
    //     let mut result = Vec::new();
 
    //     for &param 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))),
src/runtime/ffi.rs
Show inline comments
 
@@ -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,
0 comments (0 inline, 0 general)