-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Implement draft #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)) { | ||||||||
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(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to be
|
||||||||
p = new Printer(N=N); | ||||||||
(c.out)+ -> a._in; | ||||||||
a.out -> p._in; | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
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 | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
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; | ||||||
} | ||||||
|
There was a problem hiding this comment.
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 thanbank_value
?