Skip to content

Commit

Permalink
Merge pull request #2284 from lf-lang/cpp-generic-composition
Browse files Browse the repository at this point in the history
Fixed code generation for nested generic reactor instances
  • Loading branch information
lhstrh authored May 15, 2024
2 parents 2c7940d + 69aee12 commit 4f8d889
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class CppInstanceGenerator(
// by iterating over the reactor parameters we make sure that the parameters are assigned in declaration order
return reactor.parameters.mapNotNull {
if (it.name in assignments) ".${it.name} = ${assignments[it.name]}" else null
}.joinToString(", ", "$reactorType::Parameters{", "}")
}.joinToString(", ", "typename $reactorType::Parameters{", "}")
}

private fun generateInitializer(inst: Instantiation): String? = with(inst) {
Expand Down
33 changes: 33 additions & 0 deletions test/Cpp/src/target/GenericComposition.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
target Cpp {
timeout: 1 sec
}

reactor Counter<T> {
state count: T(0)
timer t(0, 1 sec)
output out: T

reaction(t) -> out {=
out.set(count);
count += 1;
=}
}

reactor Printer<T> {
input in: T

reaction(in) {=
auto msg = *in.get();
std::cout << msg << std::endl;
=}
}

reactor MyWrapper<T> {
c = new Counter<T>()
p = new Printer<T>()
c.out -> p.in
}

main reactor {
m = new MyWrapper<int>()
}

0 comments on commit 4f8d889

Please sign in to comment.