lf-lang / lingua-franca

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

Native support for multi dimensional data types #215

Open cmnrd opened 4 years ago

cmnrd commented 4 years ago

LF has a syntax for list types. For instance:

state foo:time[10]; // fixed size list of type time
state bar:int[]; // variable sized list of type int

List are treated differently in the targets. I believe C translates a list to an array. In C++, variable sized lists are translated to std::vector and fixed size lists to std::array. I am not sure what TS does, but I assume it also uses some kind of native list type.

Currently, LF only supports one dimension and it is not possible to define a matrix. Do you think we should also allow something like this?

state foo:time[10][3][8]; // fixed size matrix of type time
state bar:int[][]; // variable sized matrix of type int
state baz:time[][3][]; // mixed ??

I don't have a strong opinion about this. Extending the syntax seems simple, but it has the potential to cause some unforeseen problems down the road. Also note that the native target language types can always be used directly in (such as nested std::vector in C++). So we can write something like this:

state bar:{=std::vector<std::vector<int>>=};

But this does not work well for the time type.

edwardalee commented 4 years ago

In the C target, the time type is instant_t or interval_t. You can use these inside {= ... =}.

lhstrh commented 4 years ago

Yeah, if you use target types, you have to use the target type corresponding to time.

I believe the initial motivation for supporting lists came from the desire to be able to use clean list initializers for parameters, without having to surround them with {= =}. I guess using delimiters in type declarations of state variables is a little less bothersome. We could add support for higher dimensions, but I would consider this a low priority issue for now.