This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #67 from lf-lang/formatting
Proper formatting of templates
- Loading branch information
Showing
10 changed files
with
264 additions
and
267 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
62 changes: 30 additions & 32 deletions
62
org.lflang.ui/src/org/lflang/ui/wizard/templates/c/src/Interactive.lf
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 |
---|---|---|
@@ -1,46 +1,44 @@ | ||
/** | ||
* Simple demonstration of the sensor simulator (used in the Rhythm examples). | ||
* This has no audio output, but just tests the ncurses interface. | ||
* Simple demonstration of the sensor simulator (used in the Rhythm examples). This has no audio | ||
* output, but just tests the ncurses interface. | ||
*/ | ||
target C { | ||
keepalive: true, | ||
cmake-include: [ | ||
"include/ncurses-cmake-extension.txt", // Adds support for ncurses | ||
"/lib/c/reactor-c/util/sensor_simulator.cmake" | ||
], | ||
files: [ | ||
"/lib/c/reactor-c/util/sensor_simulator.c", | ||
"/lib/c/reactor-c/util/sensor_simulator.h" | ||
] | ||
keepalive: true, | ||
cmake-include: [ | ||
"include/ncurses-cmake-extension.txt", // Adds support for ncurses | ||
"/lib/c/reactor-c/util/sensor_simulator.cmake"], | ||
files: ["/lib/c/reactor-c/util/sensor_simulator.c", "/lib/c/reactor-c/util/sensor_simulator.h"] | ||
} | ||
|
||
preamble {= | ||
#include "sensor_simulator.h" | ||
#include "sensor_simulator.h" | ||
=} | ||
|
||
main reactor { | ||
preamble {= | ||
const char* messages[] = {"Hello", "World"}; | ||
int num_messages = 2; | ||
=} | ||
timer t(0, 1 sec) | ||
timer r(0, 2 sec) | ||
physical action key: char* | ||
preamble {= | ||
const char* messages[] = {"Hello", "World"}; | ||
int num_messages = 2; | ||
=} | ||
timer t(0, 1 sec) | ||
timer r(0, 2 sec) | ||
physical action key: char* | ||
|
||
reaction(startup) -> key {= | ||
lf_print("Starting sensor simulator."); | ||
start_sensor_simulator(messages, num_messages, 16, NULL, LOG_LEVEL_INFO); | ||
register_sensor_key('\0', key); | ||
=} | ||
reaction(startup) -> key {= | ||
lf_print("Starting sensor simulator."); | ||
start_sensor_simulator(messages, num_messages, 16, NULL, LOG_LEVEL_INFO); | ||
register_sensor_key('\0', key); | ||
=} | ||
|
||
reaction(t) {= show_tick("*"); =} | ||
reaction(t) {= | ||
show_tick("*"); | ||
=} | ||
|
||
reaction(r) {= | ||
lf_print("Elapsed logical time: %lld.", lf_time_logical_elapsed()); | ||
show_tick("."); | ||
=} | ||
reaction(r) {= | ||
lf_print("Elapsed logical time: %lld.", lf_time_logical_elapsed()); | ||
show_tick("."); | ||
=} | ||
|
||
reaction(key) {= | ||
lf_print("You typed '%s' at elapsed time %lld.", key->value, lf_time_logical_elapsed()); | ||
=} | ||
reaction(key) {= | ||
lf_print("You typed '%s' at elapsed time %lld.", key->value, lf_time_logical_elapsed()); | ||
=} | ||
} |
3 changes: 2 additions & 1 deletion
3
org.lflang.ui/src/org/lflang/ui/wizard/templates/c/src/Main.lf
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Other options: Python, Cpp, TypeScript, Rust. | ||
target C | ||
|
||
main reactor { // Import and/or declare reactor classes. | ||
// Import and/or declare reactor classes. | ||
main reactor { | ||
} |
85 changes: 42 additions & 43 deletions
85
org.lflang.ui/src/org/lflang/ui/wizard/templates/c/src/Parallel.lf
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 |
---|---|---|
@@ -1,62 +1,61 @@ | ||
/** | ||
* Each instance of TakeTime takes 200 ms wall clock time to transport the input | ||
* to the output. Four of them are instantiated. Note that without parallel | ||
* execution, there is no way this program can keep up with real time since in | ||
* every 200 msec cycle it has 800 msec of work to do. Given 4 workers, however, | ||
* this program can complete 800 msec of work in about 225 msec. | ||
* Each instance of TakeTime takes 200 ms wall clock time to transport the input to the output. Four | ||
* of them are instantiated. Note that without parallel execution, there is no way this program can | ||
* keep up with real time since in every 200 msec cycle it has 800 msec of work to do. Given 4 | ||
* workers, however, this program can complete 800 msec of work in about 225 msec. | ||
*/ | ||
target C { | ||
timeout: 2 sec, | ||
workers: 1 // Change to 4 to see speed up. | ||
timeout: 2 sec, | ||
workers: 1 // Change to 4 to see speed up. | ||
} | ||
|
||
reactor Source { | ||
timer t(0, 200 msec) | ||
output out: int | ||
state s: int = 0 | ||
timer t(0, 200 msec) | ||
output out: int | ||
state s: int = 0 | ||
|
||
reaction(t) -> out {= | ||
lf_set(out, self->s); | ||
self->s++; | ||
=} | ||
reaction(t) -> out {= | ||
lf_set(out, self->s); | ||
self->s++; | ||
=} | ||
} | ||
|
||
reactor TakeTime { | ||
input in: int | ||
output out: int | ||
input in: int | ||
output out: int | ||
|
||
reaction(in) -> out {= | ||
lf_sleep(MSEC(200)); | ||
int offset = 0; | ||
for (int i = 0; i < 100000000; i++) { | ||
offset++; | ||
} | ||
lf_set(out, in->value + offset); | ||
=} | ||
reaction(in) -> out {= | ||
lf_sleep(MSEC(200)); | ||
int offset = 0; | ||
for (int i = 0; i < 100000000; i++) { | ||
offset++; | ||
} | ||
lf_set(out, in->value + offset); | ||
=} | ||
} | ||
|
||
reactor Destination(width: int = 4) { | ||
state s: int = 400000000 | ||
input[width] in: int | ||
state s: int = 400000000 | ||
input[width] in: int | ||
|
||
reaction(in) {= | ||
int sum = 0; | ||
for (int i = 0; i < in_width; i++) { | ||
sum += in[i]->value; | ||
} | ||
printf("Sum of received: %d.\n", sum); | ||
if (sum != self->s) { | ||
printf("ERROR: Expected %d.\n", self->s); | ||
exit(1); | ||
} | ||
self->s += in_width; | ||
=} | ||
reaction(in) {= | ||
int sum = 0; | ||
for (int i = 0; i < in_width; i++) { | ||
sum += in[i]->value; | ||
} | ||
printf("Sum of received: %d.\n", sum); | ||
if (sum != self->s) { | ||
printf("ERROR: Expected %d.\n", self->s); | ||
exit(1); | ||
} | ||
self->s += in_width; | ||
=} | ||
} | ||
|
||
main reactor Parallel(width: int = 4) { | ||
a = new Source() | ||
t = new[width] TakeTime() | ||
(a.out)+ -> t.in | ||
b = new Destination(width = width) | ||
t.out -> b.in | ||
a = new Source() | ||
t = new[width] TakeTime() | ||
(a.out)+ -> t.in | ||
b = new Destination(width=width) | ||
t.out -> b.in | ||
} |
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
Oops, something went wrong.