Skip to content

Commit

Permalink
Merge pull request #274 from lf-lang/preamble
Browse files Browse the repository at this point in the history
Fixed instructions for setting parameters from a table
  • Loading branch information
edwardalee authored Jul 8, 2024
2 parents fc09e34 + 68f692f commit 606e363
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
9 changes: 4 additions & 5 deletions docs/assets/code/c/src/BankIndex.lf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
target C;
preamble {=
int table[] = {4, 3, 2, 1};
=}
reactor A(bank_index:int = 0, value:int = 0) {
reaction (startup) {=
printf("bank_index: %d, value: %d\n", self->bank_index, self->value);
=}
}
main reactor {
a = new[4] A(value = {= table[bank_index] =});
main reactor(
table: int[] = {4, 3, 2, 1}
) {
a = new[4] A(value = {= self->table[bank_index] =});
}
9 changes: 4 additions & 5 deletions docs/assets/code/py/src/BankIndex.lf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
target Python;
preamble {=
table = [4, 3, 2, 1]
=}
reactor A(bank_index = 0, value = 0) {
reaction (startup) {=
print("bank_index: {:d}, value: {:d}".format(self.bank_index, self.value))
=}
}
main reactor {
a = new[4] A(value = {= table[bank_index] =})
main reactor(
table = [4, 3, 2, 1]
) {
a = new[4] A(value = {= self.table[bank_index] =})
}
2 changes: 1 addition & 1 deletion docs/writing-reactors/multiports-and-banks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ import Py_BankIndex from '../assets/code/py/src/BankIndex.lf';

<NoSelectorTargetCodeBlock c={C_BankIndex} py={Py_BankIndex} lf />

The global `table` defined in the `preamble` is used to initialize the `value` parameter of each bank member. The result of running this is something like:
The parameter `table` defined in the `main reactor` is used to initialize the `value` parameter of each bank member. The result of running this is something like:

```
bank_index: 0, value: 4
Expand Down
9 changes: 4 additions & 5 deletions versioned_docs/version-0.8.0/assets/code/c/src/BankIndex.lf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
target C;
preamble {=
int table[] = {4, 3, 2, 1};
=}
reactor A(bank_index:int = 0, value:int = 0) {
reaction (startup) {=
printf("bank_index: %d, value: %d\n", self->bank_index, self->value);
=}
}
main reactor {
a = new[4] A(value = {= table[bank_index] =});
main reactor(
table: int[] = {4, 3, 2, 1}
) {
a = new[4] A(value = {= self->table[bank_index] =});
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ import Py_BankIndex from '../assets/code/py/src/BankIndex.lf';

<NoSelectorTargetCodeBlock c={C_BankIndex} py={Py_BankIndex} lf />

<ShowOnly py>
The global `table` defined in the `preamble` is used to initialize the `value` parameter of each bank member. The result of running this is something like:
</ShowOnly>
<ShowOnly c>
The parameter `table` defined in the `main reactor` is used to initialize the `value` parameter of each bank member. The result of running this is something like:
</ShowOnly>

```
bank_index: 0, value: 4
Expand Down

0 comments on commit 606e363

Please sign in to comment.