-
-
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 #1964 from lf-lang/modes-statevar-reset-time
Fix compilation error in code for reset state variables with time type
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Modal Reactor Test. Tests state variable with type time. Model by Edward Lee. | ||
* https://github.com/lf-lang/lingua-franca/issues/1938 | ||
*/ | ||
target C { | ||
timeout: 3 s, | ||
fast: true | ||
} | ||
|
||
reactor C { | ||
input trigger: bool | ||
reset state t: time = 0 s | ||
|
||
reaction(trigger) {= | ||
lf_print("t = %ld", self->t); | ||
if (self->t != SEC(0)) { | ||
lf_print("Error: Missing reset"); | ||
} | ||
|
||
self->t = lf_time_logical(); | ||
=} | ||
} | ||
|
||
main reactor { | ||
timer t(0, 1 s) | ||
|
||
initial mode A { | ||
c = new C() | ||
reaction(t) -> reset(B), c.trigger {= | ||
lf_print("In A"); | ||
lf_set(c.trigger, true); | ||
lf_set_mode(B); | ||
=} | ||
} | ||
|
||
mode B { | ||
reaction(t) -> reset(A) {= | ||
lf_print("In B"); | ||
lf_set_mode(A); | ||
=} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf
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,42 @@ | ||
/** | ||
* Modal Reactor Test. Tests state variable initialized via parameter. Model by Edward Lee. | ||
* https://github.com/lf-lang/lingua-franca/issues/1938 | ||
*/ | ||
target C { | ||
timeout: 3 s, | ||
fast: true | ||
} | ||
|
||
reactor C(init: int = 0) { | ||
input trigger: bool | ||
reset state i: int = init | ||
|
||
reaction(trigger) {= | ||
lf_print("i = %d", self->i); | ||
if (self->i != -1) { | ||
lf_print("Error: Missing reset"); | ||
} | ||
|
||
self->i += 10; | ||
=} | ||
} | ||
|
||
main reactor { | ||
timer t(0, 1 s) | ||
|
||
initial mode A { | ||
c = new C(init=-1) | ||
reaction(t) -> reset(B), c.trigger {= | ||
lf_print("In A"); | ||
lf_set(c.trigger, true); | ||
lf_set_mode(B); | ||
=} | ||
} | ||
|
||
mode B { | ||
reaction(t) -> reset(A) {= | ||
lf_print("In B"); | ||
lf_set_mode(A); | ||
=} | ||
} | ||
} |