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

Implement draft #13

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Python/src/ConcurrentAdder/ConcurrentAdder.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target Python {
timeout: 5 sec
}

reactor Counter(stride(1), period(1 sec)) {
state count(0);
// timer triggers reaction
timer t(0, period);
output out;
reaction(t) -> out {=
out.set(self.count)
self.count += self.stride
=}
}

reactor Adder(bank_value(1)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be bank_index rather than bank_value?

input _in;
output out;
reaction(_in) -> out {=
out.set(_in.value + self.bank_value)
=}
}

reactor Printer(N(4)) {
input[N] _in;
reaction(_in) {=
for i in range(self.N):
print(f"Result {_in[i].value}")
=}
}

main reactor(stride(10), period(1 sec), N(4)) {
c = new Counter(stride=stride, period=period);
a = new[4] Adder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be

     a = new[N] Adder();

p = new Printer(N=N);
(c.out)+ -> a._in;
a.out -> p._in;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

27 changes: 27 additions & 0 deletions Python/src/HelloWorld/HelloWorld.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
target Python {
timeout: 3 sec
}

reactor Counter(stride(1)) {
state count(0)
timer t(0, 1 sec)
output out
reaction(t) -> out {=
out.set(self.count)
self.count += self.stride
=}
}

reactor Printer {
input _in
reaction(_in) {=
# using thread-safe print function provided by the runtime
print(f"Hello World! {_in.value}.")
=}
}

main reactor {
c = new Counter(stride = 1)
p = new Printer()
c.out -> p._in
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

73 changes: 73 additions & 0 deletions Python/src/SharedList/SharedList.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'''
This is a shared itemlist for multiple people
to appendItem or deltetItem at the same time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to appendItem or deltetItem at the same time
to appendItem or deltetItem at the same time.


Simulate when multiple clients append or delete items from the
same sharedItem list.
'''
target Python {
timeout: 1 sec
}

reactor List {
state itemList;
timer t(0, 2 sec);
output out;
reaction(t) -> out {=
self.itemList = ["bear", "oski", "frosty"]
out.set(self.itemList)
=}
}

reactor AddItem(index(0), item("cal")) {
input itemList;
output out;
reaction(itemList) -> out {=
# do nothing if index out of range
n = len(itemList.value)
if 0 <= self.index < n:
itemList.value.insert(self.index, self.item)
out.set(itemList.value)
=}
}

reactor DeleteItem(index(0)) {
input itemList;
output out;
reaction(itemList) -> out {=
n = len(itemList.value)
if 0 <= self.index < n:
del itemList.value[self.index]
out.set(itemList.value)
=}
}

reactor UpdateItem(index(0), item("update")) {
input itemList;
output out;
reaction(itemList) -> out {=
itemList.value[self.index] = self.item
out.set(itemList.value)
=}
}

reactor Printer(N(3)) {
input[N] _in;
reaction(_in) {=
for i in range(self.N):
print(_in[i].value)
=}
}

main reactor {
l = new List();
add_item = new AddItem();
delete_item = new DeleteItem(index = 1);
upadate_item = new UpdateItem();
p = new Printer();
l.out -> add_item.itemList;
l.out -> delete_item.itemList;
l.out -> upadate_item.itemList;
add_item.out, delete_item.out, upadate_item.out -> p._in;
}