Skip to content

Commit

Permalink
Merge pull request #2381 from lf-lang/python-preamble
Browse files Browse the repository at this point in the history
Fix to get get all preambles in Python + updated tests
  • Loading branch information
lhstrh authored Jul 31, 2024
2 parents a088c1a + 55a1680 commit 2948f1f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public static String generatePythonClass(
pythonClasses.pr(generatePythonClassHeader(className));
// Generate preamble code
pythonClasses.indent();
pythonClasses.pr(PythonPreambleGenerator.generatePythonPreambles(reactor.getPreambles()));
pythonClasses.pr(
PythonPreambleGenerator.generatePythonPreambles(ASTUtils.allPreambles(reactor)));
// Handle runtime initializations
pythonClasses.pr(generatePythonConstructor(decl, types));
pythonClasses.pr(PythonParameterGenerator.generatePythonGetters(decl));
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/c/reactor-c
Submodule reactor-c updated 0 files
3 changes: 3 additions & 0 deletions test/C/src/PreambleInherited.lf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ reactor A {
}

reactor B extends A {
reaction(startup) {=
printf("FOO 2: %d\n", FOO);
=}
}

main reactor {
Expand Down
18 changes: 18 additions & 0 deletions test/Python/src/PreambleInherited.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
target Python

reactor Base {
preamble {=
def initiation(self):
print("Hello World\n")
=}
}

reactor Extended extends Base {
reaction(startup) {=
self.initiation()
=}
}

main reactor {
e = new Extended()
}

0 comments on commit 2948f1f

Please sign in to comment.