-
Notifications
You must be signed in to change notification settings - Fork 19
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 #272 from lf-lang/v0.8.0
Docs v0.8.0
- Loading branch information
Showing
358 changed files
with
24,710 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin | ||
src-gen | ||
include |
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 @@ | ||
include/ |
22 changes: 22 additions & 0 deletions
22
versioned_docs/version-0.8.0/assets/code/c/src/Alignment.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
target C { | ||
timeout: 3 secs | ||
} | ||
|
||
main reactor Alignment { | ||
state s: int = 0 | ||
timer t1(100 msec, 100 msec) | ||
timer t2(200 msec, 200 msec) | ||
timer t4(400 msec, 400 msec) | ||
|
||
reaction(t1) {= | ||
self->s += 1; | ||
=} | ||
|
||
reaction(t2) {= | ||
self->s -= 2; | ||
=} | ||
|
||
reaction(t4) {= | ||
printf("s = %d\n", self->s); | ||
=} | ||
} |
31 changes: 31 additions & 0 deletions
31
versioned_docs/version-0.8.0/assets/code/c/src/Asynchronous.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
target C { | ||
keepalive: true // Do not exit when event queue is empty. | ||
} | ||
|
||
preamble {= | ||
#include "platform.h" // Defines lf_sleep() and thread functions. | ||
=} | ||
|
||
main reactor { | ||
preamble {= | ||
// Schedule an event roughly every 200 msec. | ||
void* external(void* a) { | ||
while (true) { | ||
lf_sleep(MSEC(200)); | ||
lf_schedule(a, 0); | ||
} | ||
} | ||
=} | ||
state thread_id: lf_thread_t = 0 | ||
physical action a(100 msec): int | ||
|
||
reaction(startup) -> a {= | ||
// Start a thread to schedule physical actions. | ||
lf_thread_create(&self->thread_id, &external, a); | ||
=} | ||
|
||
reaction(a) {= | ||
interval_t elapsed_time = lf_time_logical_elapsed(); | ||
printf("Action triggered at logical time %lld nsec after start.\n", elapsed_time); | ||
=} | ||
} |
12 changes: 12 additions & 0 deletions
12
versioned_docs/version-0.8.0/assets/code/c/src/BankIndex.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
target C; | ||
preamble {= | ||
int table[] = {4, 3, 2, 1}; | ||
=} | ||
reactor A(bank_index:int = 0, value:int = 0) { | ||
reaction (startup) {= | ||
printf("bank_index: %d, value: %d\n", self->bank_index, self->value); | ||
=} | ||
} | ||
main reactor { | ||
a = new[4] A(value = {= table[bank_index] =}); | ||
} |
21 changes: 21 additions & 0 deletions
21
versioned_docs/version-0.8.0/assets/code/c/src/CheckDeadline.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
target C; | ||
|
||
reactor Count { | ||
output out:int; | ||
reaction(startup) -> out {= | ||
int count = 0; | ||
while (!lf_check_deadline(self, true)) { | ||
count++; | ||
} | ||
lf_set(out, count); | ||
=} deadline (3 msec) {= | ||
printf("Stopped counting.\n"); | ||
=} | ||
} | ||
|
||
main reactor { | ||
c = new Count(); | ||
reaction(c.out) {= | ||
printf("Counted to %d\n", c.out->value); | ||
=} | ||
} |
16 changes: 16 additions & 0 deletions
16
versioned_docs/version-0.8.0/assets/code/c/src/ChildBank.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
target C; | ||
reactor Child ( | ||
bank_index:int = 0 | ||
) { | ||
reaction(startup) {= | ||
printf("My bank index: %d.\n", self->bank_index); | ||
=} | ||
} | ||
reactor Parent ( | ||
bank_index:int = 0 | ||
) { | ||
c = new[2] Child(); | ||
} | ||
main reactor { | ||
p = new[2] Parent(); | ||
} |
18 changes: 18 additions & 0 deletions
18
versioned_docs/version-0.8.0/assets/code/c/src/ChildParentBank.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
target C | ||
|
||
reactor Child(bank_index: int = 0, parent_bank_index: int = 0) { | ||
reaction(startup) {= | ||
printf( | ||
"My bank index: %d. My parent's bank index: %d.\n", | ||
self->bank_index, self->parent_bank_index | ||
); | ||
=} | ||
} | ||
|
||
reactor Parent(bank_index: int = 0) { | ||
c = new[2] Child(parent_bank_index=bank_index) | ||
} | ||
|
||
main reactor { | ||
p = new[2] Parent() | ||
} |
23 changes: 23 additions & 0 deletions
23
versioned_docs/version-0.8.0/assets/code/c/src/ChildParentBank2.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
target C | ||
|
||
reactor Child(bank_index: int = 0, parent_bank_index: int = 0) { | ||
output out: int | ||
|
||
reaction(startup) -> out {= | ||
lf_set(out, self->parent_bank_index * 2 + self->bank_index); | ||
=} | ||
} | ||
|
||
reactor Parent(bank_index: int = 0) { | ||
c = new[2] Child(parent_bank_index=bank_index) | ||
|
||
reaction(c.out) {= | ||
for (int i=0; i < c_width; i++) { | ||
printf("Received %d from child %d.\n", c[i].out->value, i); | ||
} | ||
=} | ||
} | ||
|
||
main reactor { | ||
p = new[2] Parent() | ||
} |
13 changes: 13 additions & 0 deletions
13
versioned_docs/version-0.8.0/assets/code/c/src/Contained.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
target C | ||
|
||
import Overwriting from "Overwriting.lf" | ||
|
||
main reactor { | ||
s = new Overwriting() | ||
|
||
reaction(s.y) {= | ||
if (s.y->value != 0 && s.y->value != 1) { | ||
lf_print_error_and_exit("Outputs should only be 0 or 1!"); | ||
} | ||
=} | ||
} |
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,11 @@ | ||
target C | ||
|
||
reactor Count { | ||
state count: int = 0 | ||
output y: int | ||
timer t(0, 100 msec) | ||
|
||
reaction(t) -> y {= | ||
lf_set(y, self->count++); | ||
=} | ||
} |
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,24 @@ | ||
target C; | ||
reactor A { | ||
input x:int; | ||
output y:int; | ||
reaction(x) -> y {= | ||
// ... something here ... | ||
=} | ||
} | ||
reactor B { | ||
input x:int; | ||
output y:int; | ||
reaction(x) {= | ||
// ... something here ... | ||
=} | ||
reaction(startup) -> y {= | ||
// ... something here ... | ||
=} | ||
} | ||
main reactor { | ||
a = new A(); | ||
b = new B(); | ||
a.y -> b.x; | ||
b.y -> a.x; | ||
} |
24 changes: 24 additions & 0 deletions
24
versioned_docs/version-0.8.0/assets/code/c/src/CycleReordered.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
target C; | ||
reactor A { | ||
input x:int; | ||
output y:int; | ||
reaction(x) -> y {= | ||
// ... something here ... | ||
=} | ||
} | ||
reactor B { | ||
input x:int; | ||
output y:int; | ||
reaction(startup) -> y {= | ||
// ... something here ... | ||
=} | ||
reaction(x) {= | ||
// ... something here ... | ||
=} | ||
} | ||
main reactor { | ||
a = new A(); | ||
b = new B(); | ||
a.y -> b.x; | ||
b.y -> a.x; | ||
} |
24 changes: 24 additions & 0 deletions
24
versioned_docs/version-0.8.0/assets/code/c/src/CycleWithDelay.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
target C; | ||
reactor A { | ||
input x:int; | ||
output y:int; | ||
reaction(x) -> y {= | ||
// ... something here ... | ||
=} | ||
} | ||
reactor B { | ||
input x:int; | ||
output y:int; | ||
reaction(x) {= | ||
// ... something here ... | ||
=} | ||
reaction(startup) -> y {= | ||
// ... something here ... | ||
=} | ||
} | ||
main reactor { | ||
a = new A(); | ||
b = new B(); | ||
a.y -> b.x after 0; | ||
b.y -> a.x; | ||
} |
11 changes: 11 additions & 0 deletions
11
versioned_docs/version-0.8.0/assets/code/c/src/Deadline.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
target C; | ||
reactor Deadline { | ||
input x:int; | ||
output d:int; // Produced if the deadline is violated. | ||
reaction(x) -> d {= | ||
printf("Normal reaction.\n"); | ||
=} deadline(10 msec) {= | ||
printf("Deadline violation detected.\n"); | ||
lf_set(d, x->value); | ||
=} | ||
} |
26 changes: 26 additions & 0 deletions
26
versioned_docs/version-0.8.0/assets/code/c/src/DeadlineTest.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
target C | ||
|
||
import Deadline from "Deadline.lf" | ||
|
||
preamble {= | ||
#include "platform.h" | ||
=} | ||
|
||
main reactor { | ||
logical action a | ||
d = new Deadline() | ||
|
||
reaction(startup) -> d.x, a {= | ||
lf_set(d.x, 0); | ||
lf_schedule(a, 0); | ||
=} | ||
|
||
reaction(a) -> d.x {= | ||
lf_set(d.x, 0); | ||
lf_sleep(MSEC(20)); | ||
=} | ||
|
||
reaction(d.d) {= | ||
printf("Deadline reactor produced an output.\n"); | ||
=} | ||
} |
10 changes: 10 additions & 0 deletions
10
versioned_docs/version-0.8.0/assets/code/c/src/Decentralized.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
target C { | ||
timeout: 5 sec, | ||
coordination: decentralized | ||
} | ||
import Count, Print from "Federated.lf" | ||
federated reactor { | ||
c = new Count(); | ||
p = new Print(); | ||
c.out -> p.in; | ||
} |
46 changes: 46 additions & 0 deletions
46
versioned_docs/version-0.8.0/assets/code/c/src/DecentralizedFeeback.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
target C { | ||
timeout: 5 sec, | ||
coordination: decentralized | ||
} | ||
reactor CountPrint { | ||
input in:int; | ||
output out:int; | ||
state c:int(0); | ||
timer t(0, 1 sec); | ||
reaction(t) -> out {= | ||
lf_set(out, self->c++); | ||
=} | ||
reaction(in) {= | ||
lf_print("***** CountPrint Received: %d at tag (%lld, %u)", | ||
in->value, lf_time_logical_elapsed(), lf_tag().microstep | ||
); | ||
=} STP(10 msec) {= | ||
lf_print_warning("CountPrint: Safe to process violation!"); | ||
lf_print("Intended time: %lld", in->intended_tag.time - lf_time_start()); | ||
=} | ||
} | ||
|
||
reactor PrintCount { | ||
input in:int; | ||
output out:int; | ||
timer t(0, 999 msec); | ||
state c:int(0); | ||
reaction(in) {= | ||
lf_print("***** PrintCount Received: %d at tag (%lld, %u)", | ||
in->value, lf_time_logical_elapsed(), lf_tag().microstep | ||
); | ||
=} STP(10 msec) {= | ||
lf_print_warning("PrintCount: Safe to process violation!"); | ||
lf_print("Intended time: %lld", in->intended_tag.time - lf_time_start()); | ||
=} | ||
reaction(t) -> out {= | ||
lf_set(out, self->c++); | ||
=} | ||
} | ||
|
||
federated reactor { | ||
c = new CountPrint(); | ||
p = new PrintCount(); | ||
c.out -> p.in; | ||
p.out -> c.in; | ||
} |
40 changes: 40 additions & 0 deletions
40
versioned_docs/version-0.8.0/assets/code/c/src/DecentralizedFeebackSTP.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
target C { | ||
timeout: 5 sec, | ||
coordination: decentralized | ||
} | ||
reactor CountPrint(STP_offset:time(10 msec)) { | ||
input in:int; | ||
output out:int; | ||
state c:int(0); | ||
timer t(0, 1 sec); | ||
reaction(t) -> out {= | ||
lf_set(out, self->c++); | ||
=} | ||
reaction(in) {= | ||
lf_print("***** CountPrint Received: %d at tag (%lld, %u)", | ||
in->value, lf_time_logical_elapsed(), lf_tag().microstep | ||
); | ||
=} | ||
} | ||
|
||
reactor PrintCount(STP_offset:time(10 msec)) { | ||
input in:int; | ||
output out:int; | ||
timer t(0, 1 sec); | ||
state c:int(0); | ||
reaction(in) {= | ||
lf_print("***** PrintCount Received: %d at tag (%lld, %u)", | ||
in->value, lf_time_logical_elapsed(), lf_tag().microstep | ||
); | ||
=} | ||
reaction(t) -> out {= | ||
lf_set(out, self->c++); | ||
=} | ||
} | ||
|
||
federated reactor { | ||
c = new CountPrint(); | ||
p = new PrintCount(); | ||
c.out -> p.in; | ||
p.out -> c.in; | ||
} |
Oops, something went wrong.