diff --git a/src/protocol/ast.rs b/src/protocol/ast.rs index 5278ba7082d2068751b6a24eb002b51d53c1b266..fce70b5b8456ac9fe9a3a23c835a7130a1b5fc62 100644 --- a/src/protocol/ast.rs +++ b/src/protocol/ast.rs @@ -1098,8 +1098,7 @@ impl ProcedureSource { } -/// Generic storage for functions, primitive components and composite -/// components. +/// Generic storage for functions and components. // Note that we will have function definitions for builtin functions as well. In // that case the span, the identifier span and the body are all invalid. #[derive(Debug)] diff --git a/src/protocol/parser/pass_definitions.rs b/src/protocol/parser/pass_definitions.rs index fa5d495991b9892f9ffaf71abd3045ce444a3ba8..74ceba8ad07b0c8073a3f030854c00d27b93894a 100644 --- a/src/protocol/parser/pass_definitions.rs +++ b/src/protocol/parser/pass_definitions.rs @@ -292,7 +292,7 @@ impl PassDefinitions { Ok(()) } - + fn visit_component_definition( &mut self, module: &Module, iter: &mut TokenIter, ctx: &mut PassCtx ) -> Result<(), ParseError> { @@ -1663,8 +1663,14 @@ impl PassDefinitions { // TODO: Once we start generating bytecode this is unnecessary let procedure_id = proc_def.this; let method = match proc_def.source { - ProcedureSource::FuncUserDefined => Method::UserFunction, - ProcedureSource::CompUserDefined => Method::UserComponent, + // Bit of a hack, at this point the source is not yet known, except if it is a + // builtin. So we check for the "kind" + ProcedureSource::FuncUserDefined | ProcedureSource::CompUserDefined => { + match proc_def.kind { + ProcedureKind::Function => Method::UserFunction, + ProcedureKind::Component => Method::UserComponent, + } + }, ProcedureSource::FuncGet => Method::Get, ProcedureSource::FuncPut => Method::Put, ProcedureSource::FuncFires => Method::Fires, diff --git a/src/protocol/tests/parser_validation.rs b/src/protocol/tests/parser_validation.rs index a3fc6900e3388a8fff3c4f2dc2fa6d2c91b93097..b1d30a38873182dc12dc8d480f57ff36828efd4a 100644 --- a/src/protocol/tests/parser_validation.rs +++ b/src/protocol/tests/parser_validation.rs @@ -596,7 +596,7 @@ fn test_correct_select_statement() { Tester::new_single_source_expect_ok( "guard variable decl", " - primitive f() { + comp f() { channel unused -> input; u32 outer_value = 0; @@ -612,12 +612,12 @@ fn test_correct_select_statement() { Tester::new_single_source_expect_ok( "empty select", - "primitive f() { sync select {} }" + "comp f() { sync select {} }" ); Tester::new_single_source_expect_ok( "mixed uses", " - primitive f() { + comp f() { channel unused_output -> input; u32 outer_value = 0; sync select { @@ -644,7 +644,7 @@ fn test_correct_select_statement() { fn test_incorrect_select_statement() { Tester::new_single_source_expect_err( "outside sync", - "primitive f() { select {} }" + "comp f() { select {} }" ).error(|e| { e .assert_num(1) .assert_occurs_at(0, "select") @@ -653,7 +653,7 @@ fn test_incorrect_select_statement() { Tester::new_single_source_expect_err( "variable in previous block", - "primitive f() { + "comp f() { channel tx -> rx; u32 a = 0; // this one will be shadowed sync select { auto a = get(rx) -> {} } @@ -666,7 +666,7 @@ fn test_incorrect_select_statement() { Tester::new_single_source_expect_err( "put inside arm", - "primitive f() { + "comp f() { channel a -> b; sync select { put(a) -> {} } }" @@ -725,7 +725,7 @@ fn test_incorrect_goto_statement() { Tester::new_single_source_expect_err( "goto jumping outside sync", - "primitive f() { + "comp f() { sync { goto exit; } exit: u32 v = 0; }" @@ -738,7 +738,7 @@ fn test_incorrect_goto_statement() { Tester::new_single_source_expect_err( "goto jumping to select case", - "primitive f(in i) { + "comp f(in i) { sync select { hello: auto a = get(i) -> i += 1 } @@ -750,7 +750,7 @@ fn test_incorrect_goto_statement() { Tester::new_single_source_expect_err( "goto jumping into select case skipping variable", - "primitive f(in i) { + "comp f(in i) { goto waza; sync select { auto a = get(i) -> { @@ -797,7 +797,7 @@ fn test_incorrect_while_statement() { Tester::new_single_source_expect_err( "break outside of sync", - "primitive f() { + "comp f() { outer: while (true) { //mark sync while(true) { break outer; } } diff --git a/src/runtime/tests/api_component.rs b/src/runtime/tests/api_component.rs index 67271d2986bb610f91a18425edff20de76b0b0f2..f4a9d851bff955e1a025343399ae0a8483670adb 100644 --- a/src/runtime/tests/api_component.rs +++ b/src/runtime/tests/api_component.rs @@ -8,7 +8,7 @@ use super::*; #[test] fn test_put_and_get() { const CODE: &'static str = " - primitive handler(in request, out response, u32 loops) { + comp handler(in request, out response, u32 loops) { u32 index = 0; while (index < loops) { sync { @@ -52,7 +52,7 @@ fn test_put_and_get() { #[test] fn test_getting_from_component() { const CODE: &'static str =" - primitive loop_sender(out numbers, u32 cur, u32 last) { + comp loop_sender(out numbers, u32 cur, u32 last) { while (cur < last) { sync { put(numbers, cur); @@ -91,7 +91,7 @@ fn test_getting_from_component() { #[test] fn test_putting_to_component() { const CODE: &'static str = " - primitive loop_receiver(in numbers, u32 cur, u32 last) { + comp loop_receiver(in numbers, u32 cur, u32 last) { while (cur < last) { sync { auto number = get(numbers); @@ -126,7 +126,7 @@ fn test_putting_to_component() { #[test] fn test_doing_nothing() { const CODE: &'static str = " - primitive getter(in input, u32 num_loops) { + comp getter(in input, u32 num_loops) { u32 index = 0; while (index < num_loops) { sync {} diff --git a/src/runtime/tests/data_transmission.rs b/src/runtime/tests/data_transmission.rs index d86dee7f3c8ff915d9a56d49c9281cc5ca30f768..505ee96500575b6100fe24621335602514ac00fc 100644 --- a/src/runtime/tests/data_transmission.rs +++ b/src/runtime/tests/data_transmission.rs @@ -9,7 +9,7 @@ fn test_doing_nothing() { // If this thing does not get into an infinite loop, (hence: the runtime // exits), then the test works const CODE: &'static str =" - primitive silent_willy(u32 loops) { + comp silent_willy(u32 loops) { u32 index = 0; while (index < loops) { sync { index += 1; } @@ -28,7 +28,7 @@ fn test_doing_nothing() { #[test] fn test_single_put_and_get() { const CODE: &'static str = " - primitive putter(out sender, u32 loops) { + comp putter(out sender, u32 loops) { u32 index = 0; while (index < loops) { sync { @@ -38,7 +38,7 @@ fn test_single_put_and_get() { } } - primitive getter(in receiver, u32 loops) { + comp getter(in receiver, u32 loops) { u32 index = 0; while (index < loops) { sync { @@ -69,7 +69,7 @@ fn test_single_put_and_get() { #[test] fn test_combined_put_and_get() { const CODE: &'static str = " - primitive put_then_get(out output, in input, u32 num_loops) { + comp put_then_get(out output, in input, u32 num_loops) { u32 index = 0; while (index < num_loops) { sync { @@ -81,7 +81,7 @@ fn test_combined_put_and_get() { } } - composite constructor(u32 num_loops) { + comp constructor(u32 num_loops) { channel output_a -> input_a; channel output_b -> input_b; new put_then_get(output_a, input_b, num_loops); @@ -99,7 +99,7 @@ fn test_combined_put_and_get() { #[test] fn test_multi_put_and_get() { const CODE: &'static str = " - primitive putter_static(out vals, u32 num_loops) { + comp putter_static(out vals, u32 num_loops) { u32 index = 0; while (index < num_loops) { sync { @@ -112,7 +112,7 @@ fn test_multi_put_and_get() { } } - primitive getter_dynamic(in vals, u32 num_loops) { + comp getter_dynamic(in vals, u32 num_loops) { u32 loop_index = 0; while (loop_index < num_loops) { sync { diff --git a/src/runtime/tests/network_shapes.rs b/src/runtime/tests/network_shapes.rs index a15dcd0ebd7ec07beb24e75c668455d63ad7cfe8..507f09acebdd9ab76eccd0c94ee530a73b57cd70 100644 --- a/src/runtime/tests/network_shapes.rs +++ b/src/runtime/tests/network_shapes.rs @@ -5,7 +5,7 @@ use super::*; #[test] fn test_star_shaped_request() { const CODE: &'static str = " - primitive edge(in input, out output, u32 loops) { + comp edge(in input, out output, u32 loops) { u32 index = 0; while (index < loops) { sync { @@ -16,7 +16,7 @@ fn test_star_shaped_request() { } } - primitive center(out[] requests, in[] responses, u32 loops) { + comp center(out[] requests, in[] responses, u32 loops) { u32 loop_index = 0; auto num_edges = length(requests); @@ -39,7 +39,7 @@ fn test_star_shaped_request() { } } - composite constructor(u32 num_edges, u32 num_loops) { + comp constructor(u32 num_edges, u32 num_loops) { auto requests = {}; auto responses = {}; @@ -70,7 +70,7 @@ fn test_star_shaped_request() { #[test] fn test_conga_line_request() { const CODE: &'static str = " - primitive start(out req, in resp, u32 num_nodes, u32 num_loops) { + comp start(out req, in resp, u32 num_nodes, u32 num_loops) { u32 loop_index = 0; u32 initial_value = 1337; while (loop_index < num_loops) { @@ -83,7 +83,7 @@ fn test_conga_line_request() { } } - primitive middle( + comp middle( in req_in, out req_forward, in resp_in, out resp_forward, u32 num_loops @@ -100,7 +100,7 @@ fn test_conga_line_request() { } } - primitive end(in req_in, out resp_out, u32 num_loops) { + comp end(in req_in, out resp_out, u32 num_loops) { u32 loop_index = 0; while (loop_index < num_loops) { sync { @@ -111,7 +111,7 @@ fn test_conga_line_request() { } } - composite constructor(u32 num_nodes, u32 num_loops) { + comp constructor(u32 num_nodes, u32 num_loops) { channel initial_req -> req_in; channel resp_out -> final_resp; new start(initial_req, final_resp, num_nodes, num_loops); diff --git a/src/runtime/tests/speculation.rs b/src/runtime/tests/speculation.rs index ff1d8d0b1111ff2e7764063380bc3921b0ff2b65..d5bf5c0d021c40371bf6d85a0c7692287101218c 100644 --- a/src/runtime/tests/speculation.rs +++ b/src/runtime/tests/speculation.rs @@ -8,7 +8,7 @@ fn test_maybe_do_nothing() { // somehow not allowed. Note that we "check" by seeing if the test finishes. // Only the branches in which ports fire increment the loop index const CODE: &'static str = " - primitive only_puts(out output, u32 num_loops) { + comp only_puts(out output, u32 num_loops) { u32 index = 0; while (index < num_loops) { sync { put(output, true); } @@ -16,7 +16,7 @@ fn test_maybe_do_nothing() { } } - primitive might_put(out output, u32 num_loops) { + comp might_put(out output, u32 num_loops) { u32 index = 0; while (index < num_loops) { sync { @@ -26,7 +26,7 @@ fn test_maybe_do_nothing() { } } - primitive only_gets(in input, u32 num_loops) { + comp only_gets(in input, u32 num_loops) { u32 index = 0; while (index < num_loops) { sync { auto res = get(input); assert(res); } @@ -34,7 +34,7 @@ fn test_maybe_do_nothing() { } } - primitive might_get(in input, u32 num_loops) { + comp might_get(in input, u32 num_loops) { u32 index = 0; while (index < num_loops) { sync fork { auto res = get(input); assert(res); index += 1; } or {} diff --git a/src/runtime/tests/sync_failure.rs b/src/runtime/tests/sync_failure.rs index 2960280107bae342e742ad3988d1f629f30e6a54..e4f3205d2081570dd4b0b314d18b3cc30aef7a1d 100644 --- a/src/runtime/tests/sync_failure.rs +++ b/src/runtime/tests/sync_failure.rs @@ -9,14 +9,14 @@ fn test_local_sync_failure() { // If the component exits cleanly, then the runtime exits cleanly, and the // test will finish const CODE: &'static str = " - primitive immediate_failure_inside_sync() { + comp immediate_failure_inside_sync() { u32[] only_allows_index_0 = { 1 }; while (true) sync { // note the infinite loop auto value = only_allows_index_0[1]; } } - primitive immediate_failure_outside_sync() { + comp immediate_failure_outside_sync() { u32[] only_allows_index_0 = { 1 }; auto never_gonna_get = only_allows_index_0[1]; while (true) sync {} @@ -35,7 +35,7 @@ fn test_local_sync_failure() { const SHARED_SYNC_CODE: &'static str = " enum Location { BeforeSync, AfterPut, AfterGet, AfterSync, Never } -primitive failing_at_location(in input, out output, Location loc) { +comp failing_at_location(in input, out output, Location loc) { u32[] failure_array = {}; while (true) { if (loc == Location::BeforeSync) failure_array[0]; @@ -50,21 +50,21 @@ primitive failing_at_location(in input, out output, Location loc) { } } -composite constructor_pair_a(Location loc) { +comp constructor_pair_a(Location loc) { channel output_a -> input_a; channel output_b -> input_b; new failing_at_location(input_b, output_a, loc); new failing_at_location(input_a, output_b, Location::Never); } -composite constructor_pair_b(Location loc) { +comp constructor_pair_b(Location loc) { channel output_a -> input_a; channel output_b -> input_b; new failing_at_location(input_b, output_a, Location::Never); new failing_at_location(input_a, output_b, loc); } -composite constructor_ring(u32 ring_size, u32 fail_a, Location loc_a, u32 fail_b, Location loc_b) { +comp constructor_ring(u32 ring_size, u32 fail_a, Location loc_a, u32 fail_b, Location loc_b) { channel output_first -> input_old; channel output_cur -> input_new; diff --git a/src/runtime2/component/component.rs b/src/runtime2/component/component.rs index 525613092199b6baf777c0a2e24ebe76e8f20631..ab2d1b6d3efa109c2e0ed1c753f9ff6937c4bf1f 100644 --- a/src/runtime2/component/component.rs +++ b/src/runtime2/component/component.rs @@ -735,7 +735,6 @@ pub(crate) fn default_handle_start_exit( // Iterating over ports by index to work around borrowing rules for port_index in 0..comp_ctx.num_ports() { let port = comp_ctx.get_port_by_index_mut(port_index); - println!("DEBUG: Considering port:\n{:?}", port); if port.state.is_closed() || port.state.is_set(PortStateFlag::Transmitted) || port.close_at_sync_end { // Already closed, or in the process of being closed continue; diff --git a/src/runtime2/tests/error_handling.rs b/src/runtime2/tests/error_handling.rs index ed2632d8cda214f382c891410a3843ada855c689..202b90a85ca830aaf150dddfb2b26f655019cc11 100644 --- a/src/runtime2/tests/error_handling.rs +++ b/src/runtime2/tests/error_handling.rs @@ -3,7 +3,7 @@ use super::*; #[test] fn test_unconnected_component_error() { compile_and_create_component(" - primitive interact_with_noone() { + comp interact_with_noone() { u8[] array = { 5 }; auto value = array[1]; }", "interact_with_noone", no_args()); @@ -12,14 +12,14 @@ fn test_unconnected_component_error() { #[test] fn test_connected_uncommunicating_component_error() { compile_and_create_component(" - primitive crashing_and_burning(out unused) { + comp crashing_and_burning(out unused) { u8[] array = { 1337 }; auto value = array[1337]; } - primitive sitting_idly_waiting(in never_providing) { + comp sitting_idly_waiting(in never_providing) { sync auto a = get(never_providing); } - composite constructor() { + comp constructor() { // Test one way // channel a -> b; // new sitting_idly_waiting(b); @@ -35,17 +35,17 @@ fn test_connected_uncommunicating_component_error() { #[test] fn test_connected_communicating_component_error() { compile_and_create_component(" - primitive send_and_fail(out tx) { + comp send_and_fail(out tx) { u8[] array = {}; sync { put(tx, 0); array[0] = 5; } } - primitive receive_once(in rx) { + comp receive_once(in rx) { sync auto a = get(rx); } - composite constructor() { + comp constructor() { channel a -> b; new send_and_fail(a); new receive_once(b); @@ -60,12 +60,12 @@ fn test_connected_communicating_component_error() { #[test] fn test_failing_after_successful_sync() { compile_and_create_component(" - primitive put_and_fail(out tx) { sync put(tx, 1); u8 a = {}[0]; } - primitive get_and_fail(in rx) { sync auto a = get(rx); u8 a = {}[0]; } - primitive put_and_exit(out tx) { sync put(tx, 2); } - primitive get_and_exit(in rx) { sync auto a = get(rx); } + comp put_and_fail(out tx) { sync put(tx, 1); u8 a = {}[0]; } + comp get_and_fail(in rx) { sync auto a = get(rx); u8 a = {}[0]; } + comp put_and_exit(out tx) { sync put(tx, 2); } + comp get_and_exit(in rx) { sync auto a = get(rx); } - composite constructor() { + comp constructor() { { channel a -> b; new put_and_fail(a); diff --git a/src/runtime2/tests/internet.rs b/src/runtime2/tests/internet.rs index 601a6e486d9eb5ef61df9a328b2ff0074ff411ce..abb4204bf432e7c207110f3f37c9c2d75b41a429 100644 --- a/src/runtime2/tests/internet.rs +++ b/src/runtime2/tests/internet.rs @@ -7,17 +7,17 @@ fn test_stdlib_file() { compile_and_create_component(" import std.internet as inet; - primitive fake_listener_once(out tx) { + comp fake_listener_once(out tx) { channel cmd_tx -> cmd_rx; channel data_tx -> data_rx; - new fake_client(cmd_rx, data_tx); + new fake_socket(cmd_rx, data_tx); sync put(tx, inet::TcpConnection{ tx: cmd_tx, rx: data_rx, }); } - primitive fake_socket(in cmds, out tx) { + comp fake_socket(in cmds, out tx) { auto to_send = {}; auto shutdown = false; @@ -25,10 +25,10 @@ fn test_stdlib_file() { auto keep_going = true; sync { while (keep_going) { - let cmd = get(cmds); + auto cmd = get(cmds); if (let inet::Cmd::Send(data) = cmd) { to_send = data; - } else if (let inet::Cmd::Receive(data) = cmd) { + } else if (let inet::Cmd::Receive = cmd) { put(tx, to_send); } else if (let inet::Cmd::Finish = cmd) { keep_going = false; @@ -41,7 +41,7 @@ fn test_stdlib_file() { } } - primitive fake_client(inet::TcpConnection conn) { + comp fake_client(inet::TcpConnection conn) { sync put(conn.tx, inet::Cmd::Send({1, 3, 3, 7})); sync { put(conn.tx, inet::Cmd::Receive); @@ -52,7 +52,7 @@ fn test_stdlib_file() { sync put(conn.tx, inet::Cmd::Shutdown); } - composite constructor() { + comp constructor() { channel conn_tx -> conn_rx; new fake_listener_once(conn_tx); diff --git a/src/runtime2/tests/messaging.rs b/src/runtime2/tests/messaging.rs index fc4a0dd65f241980bcc60e866ee705620648a501..07e2464760f1ad941dc69079be7bfa61e688bddf 100644 --- a/src/runtime2/tests/messaging.rs +++ b/src/runtime2/tests/messaging.rs @@ -4,7 +4,7 @@ use super::*; #[test] fn test_component_communication() { let pd = ProtocolDescription::parse(b" - primitive sender(out o, u32 outside_loops, u32 inside_loops) { + comp sender(out o, u32 outside_loops, u32 inside_loops) { u32 outside_index = 0; while (outside_index < outside_loops) { u32 inside_index = 0; @@ -16,7 +16,7 @@ fn test_component_communication() { } } - primitive receiver(in i, u32 outside_loops, u32 inside_loops) { + comp receiver(in i, u32 outside_loops, u32 inside_loops) { u32 outside_index = 0; while (outside_index < outside_loops) { u32 inside_index = 0; @@ -29,7 +29,7 @@ fn test_component_communication() { } } - composite constructor() { + comp constructor() { channel o_orom -> i_orom; channel o_mrom -> i_mrom; channel o_ormm -> i_ormm; @@ -58,7 +58,7 @@ fn test_component_communication() { #[test] fn test_send_to_self() { compile_and_create_component(" - primitive insane_in_the_membrane() { + comp insane_in_the_membrane() { channel a -> b; sync { put(a, 1); @@ -72,7 +72,7 @@ fn test_send_to_self() { #[test] fn test_intermediate_messenger() { let pd = ProtocolDescription::parse(b" - primitive receiver(in rx, u32 num) { + comp receiver(in rx, u32 num) { auto index = 0; while (index < num) { sync { auto v = get(rx); } @@ -80,7 +80,7 @@ fn test_intermediate_messenger() { } } - primitive middleman(in rx, out tx, u32 num) { + comp middleman(in rx, out tx, u32 num) { auto index = 0; while (index < num) { sync { put(tx, get(rx)); } @@ -88,7 +88,7 @@ fn test_intermediate_messenger() { } } - primitive sender(out tx, u32 num) { + comp sender(out tx, u32 num) { auto index = 0; while (index < num) { sync put(tx, 1337); @@ -96,7 +96,7 @@ fn test_intermediate_messenger() { } } - composite constructor_template() { + comp constructor_template() { auto num = 0; channel tx_a -> rx_a; channel tx_b -> rx_b; @@ -105,7 +105,7 @@ fn test_intermediate_messenger() { new receiver(rx_b, 3); } - composite constructor() { + comp constructor() { new constructor_template(); new constructor_template(); new constructor_template(); diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index d145eddbcfaffa2ec557fe8c29f1c4fb17a18d56..110d7de0d7e3fb8ed0d9d2d13e2e15c271a6e5c0 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -35,7 +35,7 @@ pub(crate) fn no_args() -> ValueGroup { ValueGroup::new_stack(Vec::new()) } #[test] fn test_component_creation() { let pd = ProtocolDescription::parse(b" - primitive nothing_at_all() { + comp nothing_at_all() { s32 a = 5; auto b = 5 + a; } @@ -55,7 +55,7 @@ fn test_simple_select() { return (); } - primitive receiver(in in_a, in in_b, u32 num_sends) { + comp receiver(in in_a, in in_b, u32 num_sends) { auto num_from_a = 0; auto num_from_b = 0; while (num_from_a + num_from_b < 2 * num_sends) { @@ -74,7 +74,7 @@ fn test_simple_select() { } } - primitive sender(out tx, u32 num_sends) { + comp sender(out tx, u32 num_sends) { auto index = 0; while (index < num_sends) { sync { @@ -84,7 +84,7 @@ fn test_simple_select() { } } - composite constructor() { + comp constructor() { auto num_sends = 1; channel tx_a -> rx_a; channel tx_b -> rx_b; @@ -100,7 +100,7 @@ fn test_simple_select() { #[test] fn test_unguarded_select() { let pd = ProtocolDescription::parse(b" - primitive constructor_outside_select() { + comp constructor_outside_select() { u32 index = 0; while (index < 5) { sync select { auto v = () -> print(\"hello\"); } @@ -108,7 +108,7 @@ fn test_unguarded_select() { } } - primitive constructor_inside_select() { + comp constructor_inside_select() { u32 index = 0; while (index < 5) { sync select { auto v = () -> index += 1; } @@ -123,7 +123,7 @@ fn test_unguarded_select() { #[test] fn test_empty_select() { let pd = ProtocolDescription::parse(b" - primitive constructor() { + comp constructor() { u32 index = 0; while (index < 5) { sync select {} @@ -140,7 +140,7 @@ fn test_random_u32_temporary_thingo() { let pd = ProtocolDescription::parse(b" import std.random::random_u32; - primitive random_taker(in generator, u32 num_values) { + comp random_taker(in generator, u32 num_values) { auto i = 0; while (i < num_values) { sync { @@ -150,7 +150,7 @@ fn test_random_u32_temporary_thingo() { } } - composite constructor() { + comp constructor() { channel tx -> rx; auto num_values = 25; new random_u32(tx, 1, 100, num_values); @@ -166,7 +166,7 @@ fn test_tcp_socket_http_request() { let _pd = ProtocolDescription::parse(b" import std.internet::*; - primitive requester(out cmd_tx, in data_rx) { + comp requester(out cmd_tx, in data_rx) { print(\"*** TCPSocket: Sending request\"); sync { put(cmd_tx, Cmd::Send(b\"GET / HTTP/1.1\\r\\n\\r\\n\")); @@ -215,7 +215,7 @@ fn test_tcp_socket_http_request() { } } - composite main() { + comp main() { channel cmd_tx -> cmd_rx; channel data_tx -> data_rx; new tcp_client({142, 250, 179, 163}, 80, cmd_rx, data_tx); // port 80 of google @@ -237,7 +237,7 @@ fn test_sending_receiving_union() { Shutdown, } - primitive database(in rx, out tx) { + comp database(in rx, out tx) { auto stored = {}; auto done = false; while (!done) { @@ -257,7 +257,7 @@ fn test_sending_receiving_union() { } } - primitive client(out tx, in rx, u32 num_rounds) { + comp client(out tx, in rx, u32 num_rounds) { auto round = 0; while (round < num_rounds) { auto set_value = b\"hello there\"; @@ -279,7 +279,7 @@ fn test_sending_receiving_union() { sync put(tx, Cmd::Shutdown); } - composite main() { + comp main() { auto num_rounds = 5; channel cmd_tx -> cmd_rx; channel data_tx -> data_rx; diff --git a/src/runtime2/tests/transfer_ports.rs b/src/runtime2/tests/transfer_ports.rs index e84a5b2bb5880230bc0048c5bee8ccd04270a2c5..d8d8f27a394c5c18b1bf73eb33d625b3a5093379 100644 --- a/src/runtime2/tests/transfer_ports.rs +++ b/src/runtime2/tests/transfer_ports.rs @@ -3,16 +3,16 @@ use super::*; #[test] fn test_transfer_precreated_port_with_owned_peer() { compile_and_create_component(" - primitive port_sender(out> tx) { + comp port_sender(out> tx) { channel a -> b; sync put(tx, b); } - primitive port_receiver(in> rx) { + comp port_receiver(in> rx) { sync auto a = get(rx); } - composite constructor() { + comp constructor() { channel a -> b; new port_sender(a); new port_receiver(b); @@ -20,18 +20,55 @@ fn test_transfer_precreated_port_with_owned_peer() { ", "constructor", no_args()); } +#[test] +fn test_transfer_precreated_in_struct_with_owned_peer() { + compile_and_create_component(" + struct PortPair { + out tx, + in rx, + } + + comp port_sender(out> tx) { + channel created_tx_a -> created_rx_a; + channel created_tx_b -> created_rx_b; + sync put(tx, PortPair{ tx: created_tx_a, rx: created_rx_b }); + sync { + auto val = get(created_rx_a); + put(created_tx_b, val); + } + } + + comp port_receiver(in> rx) { + channel fake_tx -> fake_rx; + auto conn = PortPair{ tx: fake_tx, rx: fake_rx }; + sync conn = get(rx); + sync { + put(conn.tx, 5); + auto val = get(conn.rx); + while (val != 5) {} + } + } + + comp constructor() { + channel tx -> rx; + new port_sender(tx); + new port_receiver(rx); + } + ", "constructor", no_args()); +} + #[test] fn test_transfer_precreated_port_with_foreign_peer() { compile_and_create_component(" - primitive port_sender(out> tx, in to_send) { + comp port_sender(out> tx, in to_send) { sync put(tx, to_send); } - primitive port_receiver(in> rx) { + comp port_receiver(in> rx) { sync auto a = get(rx); } - composite constructor() { + comp constructor() { channel tx -> rx; channel forgotten -> to_send; new port_sender(tx, to_send); @@ -43,18 +80,18 @@ fn test_transfer_precreated_port_with_foreign_peer() { #[test] fn test_transfer_synccreated_port() { compile_and_create_component(" - primitive port_sender(out> tx) { + comp port_sender(out> tx) { sync { channel a -> b; put(tx, b); } } - primitive port_receiver(in> rx) { + comp port_receiver(in> rx) { sync auto a = get(rx); } - composite constructor() { + comp constructor() { channel a -> b; new port_sender(a); new port_receiver(b); @@ -65,20 +102,20 @@ fn test_transfer_synccreated_port() { #[test] fn test_transfer_precreated_port_with_owned_peer_and_communication() { compile_and_create_component(" - primitive port_sender(out> tx) { + comp port_sender(out> tx) { channel a -> b; sync put(tx, b); sync put(a, 1337); } - primitive port_receiver(in> rx) { + comp port_receiver(in> rx) { channel a -> b; // this is stupid, but we need to have a variable to use sync b = get(rx); u32 value = 0; sync value = get(b); while (value != 1337) {} } - composite constructor() { + comp constructor() { channel a -> b; new port_sender(a); new port_receiver(b); @@ -89,15 +126,15 @@ fn test_transfer_precreated_port_with_owned_peer_and_communication() { #[test] fn test_transfer_precreated_port_with_foreign_peer_and_communication() { compile_and_create_component(" - primitive port_sender(out> tx, in to_send) { + comp port_sender(out> tx, in to_send) { sync put(tx, to_send); } - primitive message_transmitter(out tx) { + comp message_transmitter(out tx) { sync put(tx, 1337); } - primitive port_receiver(in> rx) { + comp port_receiver(in> rx) { channel unused -> b; sync b = get(rx); u32 value = 0; @@ -105,7 +142,7 @@ fn test_transfer_precreated_port_with_foreign_peer_and_communication() { while (value != 1337) {} } - composite constructor() { + comp constructor() { channel port_tx -> port_rx; channel value_tx -> value_rx; new port_sender(port_tx, value_rx); @@ -118,7 +155,7 @@ fn test_transfer_precreated_port_with_foreign_peer_and_communication() { #[test] fn test_transfer_precreated_port_with_owned_peer_back_and_forth() { compile_and_create_component(" - primitive port_send_and_receive(out> tx, in> rx) { + comp port_send_and_receive(out> tx, in> rx) { channel a -> b; sync { put(tx, b); @@ -126,7 +163,7 @@ fn test_transfer_precreated_port_with_owned_peer_back_and_forth() { } } - primitive port_receive_and_send(in> rx, out> tx) { + comp port_receive_and_send(in> rx, out> tx) { channel unused -> transferred; // same problem as in different tests sync { transferred = get(rx); @@ -134,7 +171,7 @@ fn test_transfer_precreated_port_with_owned_peer_back_and_forth() { } } - composite constructor() { + comp constructor() { channel port_tx_forward -> port_rx_forward; channel port_tx_backward -> port_rx_backward; @@ -146,7 +183,7 @@ fn test_transfer_precreated_port_with_owned_peer_back_and_forth() { #[test] fn test_transfer_precreated_port_with_foreign_peer_back_and_forth_and_communication() { compile_and_create_component(" - primitive port_send_and_receive(out> tx, in> rx, in to_transfer) { + comp port_send_and_receive(out> tx, in> rx, in to_transfer) { sync { put(tx, to_transfer); to_transfer = get(rx); @@ -157,7 +194,7 @@ fn test_transfer_precreated_port_with_foreign_peer_back_and_forth_and_communicat } } - primitive port_receive_and_send(in> rx, out> tx) { + comp port_receive_and_send(in> rx, out> tx) { channel unused -> transferred; sync { transferred = get(rx); @@ -165,11 +202,11 @@ fn test_transfer_precreated_port_with_foreign_peer_back_and_forth_and_communicat } } - primitive value_sender(out tx) { + comp value_sender(out tx) { sync put(tx, 1337); } - composite constructor() { + comp constructor() { channel port_tx_forward -> port_rx_forward; channel port_tx_backward -> port_rx_backward; channel message_tx -> message_rx; diff --git a/std/std.internet.pdl b/std/std.internet.pdl index ea2f6078695f9c8dd8c2aae3490107cd5848fb86..9650baee4fa36a7b6f62e7e71c1f3d753a2132d8 100644 --- a/std/std.internet.pdl +++ b/std/std.internet.pdl @@ -7,15 +7,15 @@ union Cmd { Shutdown, } -primitive tcp_client(u8[] ip, u16 port, in cmds, out rx) { +comp tcp_client(u8[] ip, u16 port, in cmds, out rx) { #builtin } struct TcpConnection { - in tx, - out rx, + out tx, + in rx, } -/* primitive tcp_listener(u8[] ip, u16 port, out rx) { +/* comp tcp_listener(u8[] ip, u16 port, out rx) { #builtin } */ \ No newline at end of file diff --git a/std/std.random.pdl b/std/std.random.pdl index 840e195232766dd8441b9ecb3ae89210e339739d..dda37f9a4394f97bcca45e4b9e5923bd28447146 100644 --- a/std/std.random.pdl +++ b/std/std.random.pdl @@ -1,3 +1,3 @@ #module std.random -primitive random_u32(out generator, u32 min, u32 max, u32 num_sends) { #builtin } +comp random_u32(out generator, u32 min, u32 max, u32 num_sends) { #builtin } diff --git a/testdata/basic-modules/consumer.pdl b/testdata/basic-modules/consumer.pdl index ccaf12cf83958ecccc7eed5abdd616f83793f013..0a33aa253d87be472883c815398ce02eb9748164 100644 --- a/testdata/basic-modules/consumer.pdl +++ b/testdata/basic-modules/consumer.pdl @@ -1,6 +1,6 @@ #module consumer -primitive consumer(in input) { +comp consumer(in input) { sync { print("C: going to receive a value"); auto v = get(input); diff --git a/testdata/basic-modules/main.pdl b/testdata/basic-modules/main.pdl index 0c2b7f8c50c7d568047f1681b1f81c4aa5a6449b..0134a0096bd406726fae8885e715d10993d5eb33 100644 --- a/testdata/basic-modules/main.pdl +++ b/testdata/basic-modules/main.pdl @@ -1,7 +1,7 @@ import consumer as c; import producer::producer; -composite main() { +comp main() { channel output -> input; new c::consumer(input); new producer(output); diff --git a/testdata/basic-modules/producer.pdl b/testdata/basic-modules/producer.pdl index dc4747d7687a4ed6bb25a62b97d769223a01b657..668fd138e0916045474d7238865f78c104c6f040 100644 --- a/testdata/basic-modules/producer.pdl +++ b/testdata/basic-modules/producer.pdl @@ -1,6 +1,6 @@ #module producer -primitive producer(out output) { +comp producer(out output) { sync { print("P: Going to send a value!"); put(output, 1337); diff --git a/testdata/basic/testing.pdl b/testdata/basic/testing.pdl index af02505f5fbca31617368760f4b7727e70ec8e49..751533f88e36890462d541c804f3b9a4fd2d923d 100644 --- a/testdata/basic/testing.pdl +++ b/testdata/basic/testing.pdl @@ -1,4 +1,4 @@ -primitive consumer(in input) { +comp consumer(in input) { sync { print("C: going to receive a value"); auto v = get(input); @@ -7,7 +7,7 @@ primitive consumer(in input) { print("C: I am now exiting"); } -primitive producer(out output) { +comp producer(out output) { sync { print("P: Going to send a value!"); put(output, 1337); @@ -16,7 +16,7 @@ primitive producer(out output) { print("P: I am exiting"); } -composite main() { +comp main() { channel output -> input; new consumer(input); new producer(output);