-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2420 from lf-lang/mutable
Fixed parameterized mutable inputs
- Loading branch information
Showing
5 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule reactor-c
updated
3 files
+17 −3 | core/lf_token.c | |
+10 −6 | core/reactor_common.c | |
+0 −14 | include/core/lf_token.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
=} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]."); | ||
} | ||
=} | ||
} |