Files @ 42785e82880a
Branch filter:

Location: CSY/reowolf/src/runtime2/tests/mod.rs - annotation

42785e82880a 1.6 KiB application/rls-services+xml Show Source Show as Raw Download as Raw
MH
WIP: Fix bug where components were not properly destroyed
use crate::protocol::*;
use crate::protocol::eval::*;
use crate::runtime2::runtime::*;
use crate::runtime2::component::{CompCtx, CompPDL};

fn create_component(rt: &Runtime, module_name: &str, routine_name: &str, args: ValueGroup) {
    let prompt = rt.inner.protocol.new_component(
        module_name.as_bytes(), routine_name.as_bytes(), args
    ).expect("create prompt");
    let reserved = rt.inner.start_create_pdl_component();
    let ctx = CompCtx::new(&reserved);
    let (key, _) = rt.inner.finish_create_pdl_component(reserved, CompPDL::new(prompt, 0), ctx, false);
    rt.inner.enqueue_work(key);
}

fn no_args() -> ValueGroup { ValueGroup::new_stack(Vec::new()) }

#[test]
fn test_component_creation() {
    let pd = ProtocolDescription::parse(b"
    primitive nothing_at_all() {
        s32 a = 5;
        auto b = 5 + a;
    }
    ").expect("compilation");
    let rt = Runtime::new(1, pd);

    for i in 0..20 {
        create_component(&rt, "", "nothing_at_all", no_args());
    }
}

#[test]
fn test_component_communication() {
    let pd = ProtocolDescription::parse(b"
    primitive sender(out<u32> o) {
        print(\"sender\");
        sync put(o, 1);
    }
    primitive receiver(in<u32> i) {
        print(\"receiver\");
        sync auto a = get(i);
    }
    composite constructor() {
        channel o -> i;
        print(\"creating sender\");
        new sender(o);
        print(\"creating receiver\");
        new receiver(i);
        print(\"done\");
    }
    ").expect("compilation");
    let rt = Runtime::new(1, pd);

    create_component(&rt, "", "constructor", no_args());
}