Skip to content

Commit

Permalink
Fixed instructions for setting parameters from a table
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee committed Jul 7, 2024
1 parent 949897f commit a191911
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 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 @@ -204,7 +204,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

0 comments on commit a191911

Please sign in to comment.