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
 
@@ -41,18 +41,27 @@ pub enum Polarity {
 
    Getter, // input port (from the perspective of the component)
 
}
 

	
 
#[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 {
 
    type D: ProtocolDescription;
 
    fn pre_sync_run<C: MonoContext<D = Self::D, S = Self>>(
 
        &mut self,
src/protocol/mod.rs
Show inline comments
 
@@ -44,32 +44,32 @@ impl ProtocolDescription for ProtocolDescriptionImpl {
 
                let mut vec: Vec<u8> = Vec::new();
 
                err.write(&source, &mut vec).unwrap();
 
                Err(String::from_utf8_lossy(&vec).to_string())
 
            }
 
        }
 
    }
 
    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))),
 
            }
 
        }
 
        ComponentStateImpl { prompt: Prompt::new(&self.heap, self.main.upcast(), &args) }
src/runtime/ffi.rs
Show inline comments
 
@@ -126,13 +126,13 @@ pub unsafe extern "C" fn connector_configure(connector: *mut Connector, pdl: *mu
 
/// Provides a binding annotation for the port with the given index with "native":
 
/// (The port is exposed for reading and writing from the application)
 
/// Returns:
 
/// # 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 {
 
    // use PortBindErr::*;
 
    let mut b = Box::from_raw(connector); // unsafe!
 
    let ret = match b.bind_port(proto_port_index, PortBinding::Native) {
 
@@ -149,13 +149,13 @@ pub unsafe extern "C" fn port_bind_native(
 
/// Provides a binding annotation for the port with the given index with "native":
 
/// (The port is exposed for reading and writing from the application)
 
/// Returns:
 
/// # 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,
 
) -> c_int {
 
    if let Some(addr) = try_parse_addr(address) {
 
        // use PortBindErr::*;
 
@@ -181,13 +181,13 @@ pub unsafe extern "C" fn port_bind_passive(
 
/// Returns:
 
/// - 0 for success
 
/// - 1 if the port was already bound and was left unchanged
 
/// # 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,
 
) -> c_int {
 
    if let Some(addr) = try_parse_addr(address) {
 
        // use PortBindErr::*;
0 comments (0 inline, 0 general)