From 55a1680b26729fd86a73d0c63645bbbc35111df4 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 30 Jul 2024 10:24:56 -0400 Subject: [PATCH] Get all preambles in Python, add test, update C test, and align reactor-c --- .../python/PythonReactorGenerator.java | 3 ++- core/src/main/resources/lib/c/reactor-c | 2 +- test/C/src/PreambleInherited.lf | 3 +++ test/Python/src/PreambleInherited.lf | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/Python/src/PreambleInherited.lf diff --git a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java index 10c7e400df..99dbae7349 100644 --- a/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java +++ b/core/src/main/java/org/lflang/generator/python/PythonReactorGenerator.java @@ -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)); diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 76ec485017..1fae32cdcf 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 76ec485017ae682a7f00aa9bc5609410c638c703 +Subproject commit 1fae32cdcf4277b94ae07e2aeea011179d7afc85 diff --git a/test/C/src/PreambleInherited.lf b/test/C/src/PreambleInherited.lf index 771185bdbc..2a2240a606 100644 --- a/test/C/src/PreambleInherited.lf +++ b/test/C/src/PreambleInherited.lf @@ -12,6 +12,9 @@ reactor A { } reactor B extends A { + reaction(startup) {= + printf("FOO 2: %d\n", FOO); + =} } main reactor { diff --git a/test/Python/src/PreambleInherited.lf b/test/Python/src/PreambleInherited.lf new file mode 100644 index 0000000000..3c27e03b52 --- /dev/null +++ b/test/Python/src/PreambleInherited.lf @@ -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() +}