lf-lang / lingua-franca

Intuitive concurrent programming in any language
https://www.lf-lang.org
Other
234 stars 62 forks source link

Parse target variable STP (STAA) #2374

Open Depetrol opened 2 months ago

Depetrol commented 2 months ago

Currently Lingua Franca syntax allows passing target variable as STP:

reaction() {=
      ...
    =} STP({=FOREVER=}) {=
      ...
    =}

The above code is currently accepted by lfc as valid code, but the generated code is

staa_lst[0]->STAA = SEC(0);

This is because the function findMaxSTP() in FedASTUtils.java has the following code

return STPList.stream()
        .map(ASTUtils::getLiteralTimeValue)
        .filter(Objects::nonNull)
        .reduce(TimeValue.ZERO, TimeValue::max);

that filters out null values produced by getLiteralTimeValue when the STP parameter is target code.

This cannot be simply fixed by inserting the expression verbatim because the value of STP parameter is currently used in compile time to determine the max. A fix could be to move finding the max STP to runtime, but this introduces larger change to the codebase.