Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs v0.9.0 #293

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions versioned_docs/version-0.9.0/assets/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin
src-gen
include
1 change: 1 addition & 0 deletions versioned_docs/version-0.9.0/assets/code/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include/
22 changes: 22 additions & 0 deletions versioned_docs/version-0.9.0/assets/code/c/src/Alignment.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/Asynchronous.lf
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);
=}
}
11 changes: 11 additions & 0 deletions versioned_docs/version-0.9.0/assets/code/c/src/BankIndex.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target C;
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(
table: int[] = {4, 3, 2, 1}
) {
a = new[4] A(value = {= self->table[bank_index] =});
}
21 changes: 21 additions & 0 deletions versioned_docs/version-0.9.0/assets/code/c/src/CheckDeadline.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/ChildBank.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/ChildParentBank.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/ChildParentBank2.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/Contained.lf
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!");
}
=}
}
11 changes: 11 additions & 0 deletions versioned_docs/version-0.9.0/assets/code/c/src/Count.lf
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++);
=}
}
24 changes: 24 additions & 0 deletions versioned_docs/version-0.9.0/assets/code/c/src/Cycle.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/CycleReordered.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/CycleWithDelay.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/Deadline.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/DeadlineTest.lf
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 versioned_docs/version-0.9.0/assets/code/c/src/Decentralized.lf
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;
}
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;
}
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;
}
Loading
Loading