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 1 commit
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
}
}

54 changes: 54 additions & 0 deletions Python/src/SharedList/SharedList.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'''
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

reactor ItemList {
state itemList;
timer t(0, 1 sec);
output out;
reaction(t) -> out {=
out.set(self.itemList)
=}
}

reactor AddItem {
// a int type
input index;

// a string type
input value;

// a list data structure in Python
input itemList;

output out;
reaction(index, value, itemList) -> out {=
out.set(itemList.insert(index, value))
=}
}

reactor DeleteItem {

}


# Print current items on the SharedList
reactor Printer {
input _in;
reaction(_in) {=
for item in _in.itemList:
print(item)
=}
}

main reactor {
l = new ItemList();
p = new Printer();
l.out -> p._in
}