-
Notifications
You must be signed in to change notification settings - Fork 63
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 #2369 from lf-lang/cpp-time-expressions
Ability to use of target code expressions for time values in C++
- Loading branch information
Showing
3 changed files
with
71 additions
and
10 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
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
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,53 @@ | ||
target Cpp { | ||
timeout: 1 s | ||
} | ||
|
||
public preamble {= | ||
inline reactor::Duration get_delay() { return 200ms; } | ||
=} | ||
|
||
reactor Foo(foo: time = {= get_delay() =}) { | ||
timer t(0, foo) | ||
|
||
state timer_triggered: bool = false | ||
|
||
reaction(t) {= | ||
timer_triggered = true; | ||
if (get_elapsed_logical_time() % 200ms != reactor::Duration::zero()) { | ||
std::cerr << "ERROR: timer triggered at an unexpected time\n"; | ||
exit(4); | ||
} | ||
=} | ||
|
||
reaction(shutdown) {= | ||
if (!timer_triggered) { | ||
std::cerr << "ERROR: timer did not trigger\n"; | ||
exit(1); | ||
} | ||
=} | ||
} | ||
|
||
main reactor { | ||
foo = new Foo() | ||
|
||
state timer_triggered: bool = false | ||
|
||
timer t(0, {= get_delay() + 200ms =}) | ||
|
||
reaction(t) {= | ||
timer_triggered = true; | ||
if (get_elapsed_logical_time() % 400ms != reactor::Duration::zero()) { | ||
std::cerr << "ERROR: timer triggered at an unexpected time\n"; | ||
exit(4); | ||
} | ||
=} | ||
|
||
reaction(shutdown) {= | ||
if (!timer_triggered) { | ||
std::cerr << "ERROR: timer did not trigger\n"; | ||
exit(2); | ||
} | ||
|
||
std::cout << "Success\n"; | ||
=} | ||
} |