From 363f9a35b50768b604eee2b06d7dd07e065b49c7 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 8 Jul 2022 11:32:53 +0200 Subject: [PATCH 1/3] Cpp: fix triggering of reactions in multiple nested reactors The reactor-cpp runtime did not correctly handle multiple reactions in different nested reactors that are triggered by the same port upstream port. This change pulls in a fix in reactor-cpp and adds an LF test. Related reactor-cpp PR: https://github.com/lf-lang/reactor-cpp/pull/16 --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- test/Cpp/src/NestedTriggeredReactions.lf | 47 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/Cpp/src/NestedTriggeredReactions.lf diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index 58e89f04e9..6e70c18391 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit 58e89f04e9e858e1e7abcf8afba0dfa92307aa18 +Subproject commit 6e70c18391089ba40c33555e7472cea3efdded43 diff --git a/test/Cpp/src/NestedTriggeredReactions.lf b/test/Cpp/src/NestedTriggeredReactions.lf new file mode 100644 index 0000000000..a9719b702a --- /dev/null +++ b/test/Cpp/src/NestedTriggeredReactions.lf @@ -0,0 +1,47 @@ +target Cpp; + +reactor Container { + input in: void + + state triggered: bool{false} + + contained = new Contained(); + + in -> contained.in + + reaction (in) {= + triggered = true; + =} + + reaction (shutdown) {= + if (!triggered) { + reactor::log::Error() << "The Container reaction was not triggered!"; + exit(1); + } + =} +} + +reactor Contained { + input in: void + + state triggered: bool{false} + + reaction (in) {= + triggered = true; + =} + + reaction (shutdown) {= + if (!triggered) { + reactor::log::Error() << "The Contained reaction was not triggered!"; + exit(1); + } + =} +} + +main reactor { + container = new Container() + + reaction(startup) -> container.in {= + container.in.set(); + =} +} \ No newline at end of file From d47bc5ef95b298b6630e44a700821be2352b7c39 Mon Sep 17 00:00:00 2001 From: eal Date: Wed, 13 Jul 2022 07:39:32 -0400 Subject: [PATCH 2/3] Added C version of NestedTriggeredReactions.lf --- test/C/src/NestedTriggeredReactions.lf | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/C/src/NestedTriggeredReactions.lf diff --git a/test/C/src/NestedTriggeredReactions.lf b/test/C/src/NestedTriggeredReactions.lf new file mode 100644 index 0000000000..40137e2c37 --- /dev/null +++ b/test/C/src/NestedTriggeredReactions.lf @@ -0,0 +1,46 @@ +target C; + + reactor Container { + input in: bool; + + state triggered: bool(false); + + contained = new Contained(); + + in -> contained.in; + + reaction (in) {= + self->triggered = true; + =} + + reaction (shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("The Container reaction was not triggered!"); + } + =} + } + + reactor Contained { + input in: bool; + + state triggered: bool(false); + + reaction (in) {= + self->triggered = true; + =} + + reaction (shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("The Contained reaction was not triggered!"); + } + =} + } + + main reactor { + container = new Container(); + + reaction(startup) -> container.in {= + lf_set(container.in, true); + =} + } + \ No newline at end of file From bcaa1b0f14a47ed8e28704f9baf6164c0c8c7277 Mon Sep 17 00:00:00 2001 From: eal Date: Wed, 13 Jul 2022 07:46:05 -0400 Subject: [PATCH 3/3] Fixed mistake identified by @Soroosh129 --- test/C/src/Hierarchy.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/Hierarchy.lf b/test/C/src/Hierarchy.lf index bb41461ef3..dc300b85ce 100644 --- a/test/C/src/Hierarchy.lf +++ b/test/C/src/Hierarchy.lf @@ -41,5 +41,5 @@ main reactor Hierarchy { print2 = new Print(); source.out -> container.in; container.out -> print.in; - container.out -> print2.in; + container.out2 -> print2.in; }