diff --git a/core/src/main/java/org/lflang/generator/c/CUtil.java b/core/src/main/java/org/lflang/generator/c/CUtil.java index 64e63bfe95..dae1425342 100644 --- a/core/src/main/java/org/lflang/generator/c/CUtil.java +++ b/core/src/main/java/org/lflang/generator/c/CUtil.java @@ -755,7 +755,7 @@ private static List multiportWidthTerms(Variable variable) { if (!((Port) variable).getWidthSpec().isOfVariableLength()) { for (WidthTerm term : ((Port) variable).getWidthSpec().getTerms()) { if (term.getParameter() != null) { - result.add(getTargetReference(term.getParameter())); + result.add("self->" + getTargetReference(term.getParameter())); } else { result.add(String.valueOf(term.getWidth())); } diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 815696c5d5..693c5f5bdb 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 815696c5d53775755e55dc8da4c6fb99f218efe1 +Subproject commit 693c5f5bdbc6918cebc619c3ae46a22af719b741 diff --git a/test/C/src/Mutable.lf b/test/C/src/Mutable.lf new file mode 100644 index 0000000000..575473986f --- /dev/null +++ b/test/C/src/Mutable.lf @@ -0,0 +1,43 @@ +target C + +reactor S(width: int = 4) { + output[width] out: int + + reaction(startup) -> out {= + for(int i = 0; i < self->width; i++) { + lf_set(out[i], 0); + } + =} +} + +reactor R(width: int = 4) { + mutable input[width] in: int + output[width] out: int + + reaction(in) -> out {= + for(int i = 0; i < self->width; i++) { + in[i]->value = (i + 1) * 2; + lf_set(out[i], in[i]->value); + } + =} +} + +main reactor { + s = new S(width=2) + r = new R(width=2) + s.out -> r.in + + reaction(r.out) {= + lf_print("Received from R %d, %d", r.out[0]->value, r.out[1]->value); + if (r.out[0]->value != 2 || r.out[1]->value != 4) { + lf_print_error_and_exit("Expected 2 and 4."); + } + =} + + reaction(s.out) {= + lf_print("Received from S %d, %d", s.out[0]->value, s.out[1]->value); + if (s.out[0]->value != 0 || s.out[1]->value != 0) { + lf_print_error_and_exit("Expected zeros."); + } + =} +} diff --git a/test/C/src/enclave/EnclaveRequestStop.lf b/test/C/src/enclave/EnclaveRequestStop.lf index aea05a874d..91df3b1a60 100644 --- a/test/C/src/enclave/EnclaveRequestStop.lf +++ b/test/C/src/enclave/EnclaveRequestStop.lf @@ -1,6 +1,6 @@ /** Test that enclaves all stop at the time requested by the first enclave to request a stop. */ target C { - timeout: 1 sec + timeout: 10 sec } reactor Stop(stop_time: time = 5 s) { diff --git a/test/C/src/token/MutableToken.lf b/test/C/src/token/MutableToken.lf new file mode 100644 index 0000000000..724b8a6579 --- /dev/null +++ b/test/C/src/token/MutableToken.lf @@ -0,0 +1,50 @@ +target C { + timeout: 0 s, + files: ["include/array.h"] +} + +import TokenSource from "lib/Token.lf" + +preamble {= + #include "array.h" +=} + +reactor R(width: int = 4) { + mutable input[width] in: int_array_t* + output[width] out: int_array_t* + + reaction(in) -> out {= + for(int i = 0; i < self->width; i++) { + for (int j = 0; j < in[i]->value->length; j++) { + in[i]->value->data[j] = in[i]->value->data[j] * 2; + } + lf_set_token(out[i], in[i]->token); + } + =} +} + +main reactor { + s = new[2] TokenSource() + r = new R(width=2) + s.out -> r.in + + reaction(r.out) {= + lf_print("Received from R [%d, %d, %d], [%d, %d, %d]", + r.out[0]->value->data[0], r.out[0]->value->data[1], r.out[0]->value->data[2], + r.out[1]->value->data[0], r.out[1]->value->data[1], r.out[1]->value->data[2]); + if (r.out[0]->value->data[0] != 0 || r.out[0]->value->data[1] != 2 || r.out[0]->value->data[2] != 4 + || r.out[1]->value->data[0] != 0 || r.out[1]->value->data[1] != 2 || r.out[1]->value->data[2] != 4) { + lf_print_error_and_exit("Expected [0, 2, 4]."); + } + =} + + reaction(s.out) {= + lf_print("Received from S [%d, %d, %d], [%d, %d, %d]", + s[0].out->value->data[0], s[0].out->value->data[1], s[0].out->value->data[2], + s[1].out->value->data[0], s[1].out->value->data[1], s[1].out->value->data[2]); + if (s[0].out->value->data[0] != 0 || s[0].out->value->data[1] != 1 || s[0].out->value->data[2] != 2 + || s[1].out->value->data[0] != 0 || s[1].out->value->data[1] != 1 || s[1].out->value->data[2] != 2) { + lf_print_error_and_exit("Expected [0, 2, 4]."); + } + =} +}