You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/installation.md
+1-3Lines changed: 1 addition & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,4 @@ Regular and nightly release builds of the command line tools can be downloaded f
149
149
150
150
### From Source
151
151
152
-
Please refer to the [Lingua Franca GitHub repository](https://github.com/lf-lang/lingua-franca) for build instructions.
153
-
154
-
If you'd like to contribute to Lingua Franca, you can find details about the recommended developer setup here.
152
+
If you would like to build from source or contribute to Lingua Franca, you can find further instructions in the [developer section](./developer/downloading-and-building.mdx).
Copy file name to clipboardExpand all lines: docs/reference/target-language-details.mdx
+36-6Lines changed: 36 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1118,12 +1118,6 @@ reactor Source {
1118
1118
1119
1119
The first reaction specifies the destructor and copy constructor (the latter of which will be used if any downstream reactor has a mutable input or wishes to make a writable copy).
1120
1120
1121
-
**IMPORTANT:** The array constructed should be sent to only one output port using `lf_set`. If you need to send it to more than one output port or to use it as the payload of an action, you should use `lf_set_token`.
1122
-
1123
-
:::warning
1124
-
**FIXME:** Show how to do this.
1125
-
:::
1126
-
1127
1121
A reactor receiving this array is straightforward. It just references the array elements as usual in C, as illustrated by this example:
1128
1122
1129
1123
```lf-c
@@ -1142,6 +1136,10 @@ reactor Print() {
1142
1136
1143
1137
The deallocation of memory for the data will occur automatically after the last reactor that receives a pointer to the data has finished using it, using the destructor specified by `lf_set_destructor` or `free` if none specified.
1144
1138
1139
+
Sometimes, it is not necessary to explicitly provide a destructor or copy constructor for a data type.
1140
+
Suppose your output port has type `foo*` for some data type `foo`.
1141
+
If the dynamically allocated memory pointed to has size `sizeof(foo)` and resides in contiguous memory, then the default destructor and copy constructor will suffice.
1142
+
1145
1143
Occasionally, you will want an input or output type to be a pointer, but you don't want the automatic memory allocation and deallocation. A simple example is a string type, which in C is `char*`. Consider the following (erroneous) reactor:
1146
1144
1147
1145
```lf-c
@@ -1186,6 +1184,38 @@ reactor SendsPointer {
1186
1184
1187
1185
The above technique can be used to abuse the reactor model of computation by communicating pointers to shared variables. This is generally a bad idea unless those shared variables are immutable. The result will likely be nondeterministic. Also, communicating pointers across machines that do not share memory will not work at all.
1188
1186
1187
+
Finally, sometimes, you will want to use the same dynamically allocated data structure for multiple purposes over time.
1188
+
In this case, you can explicitly create a token to carry the data, and the token mechanism will take care of reference counting and freeing the allocated memory only after all users are done with it.
1189
+
For example, suppose that your reaction wishes to produce an output and schedule an action with the same payload.
The call to `lf_new_token` creates a token with the `int_array_t` struct as its payload (technically, it creates a token with an array of length 1, where the one element is the dynamically allocated array).
1217
+
The cast in `(lf_port_base_t*)out` is necessary to suppress warnings because C does not support inheritance.
1218
+
1189
1219
### Mutable Inputs
1190
1220
1191
1221
Although it cannot be enforced in C, a receiving reactor should not modify the values provided by an input. Inputs are logically _immutable_ because there may be several recipients. Any recipient that wishes to modify the input should make a copy of it. Fortunately, a utility is provided for this pattern. Consider the [ArrayScale](https://github.com/lf-lang/lingua-franca/blob/master/test/C/src/ArrayScale.lf) example, here modified to use the above `int_array_t` data type:
0 commit comments