diff --git a/.github/actions/setup-ros2/action.yml b/.github/actions/setup-ros2/action.yml index 54b77b841a..ac2a0b0d15 100644 --- a/.github/actions/setup-ros2/action.yml +++ b/.github/actions/setup-ros2/action.yml @@ -9,6 +9,6 @@ runs: # see https://github.com/ros-tooling/setup-ros/issues/80 and https://github.com/ros2/rmw_cyclonedds/pull/134 run: sed -e 's/azure.archive.ubuntu.com/us.archive.ubuntu.com/g' -e t -e d /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/nonazure.list - name: Setup ROS2 - uses: ros-tooling/setup-ros@0.6.1 + uses: lhstrh/setup-ros@master with: required-ros-distributions: rolling diff --git a/.github/scripts/test-lfc.sh b/.github/scripts/test-lfc.sh index 096736f495..20c087db81 100755 --- a/.github/scripts/test-lfc.sh +++ b/.github/scripts/test-lfc.sh @@ -16,5 +16,54 @@ function test_with_links() { bin/lfc test/C/src/Minimal.lf +# -c,--clean Clean before building. +bin/lfc -c test/C/src/Minimal.lf +bin/lfc --clean test/C/src/Minimal.lf + +# --external-runtime-path Specify an external runtime library to +# be used by the compiled binary. + +# -f,--federated Treat main reactor as federated. +bin/lfc -f test/C/src/Minimal.lf +bin/lfc --federated test/C/src/Minimal.lf + +# --rti Specify address of RTI. +bin/lfc -f --rti rti test/C/src/Minimal.lf +bin/lfc --federated --rti rti test/C/src/Minimal.lf + +# -h,--help Display this information. +bin/lfc -h +bin/lfc --help + +# -l, --lint Enable linting during build. +bin/lfc -l test/Python/src/Minimal.lf +bin/lfc --lint test/Python/src/Minimal.lf + +# -n,--no-compile Do not invoke target compiler. +bin/lfc -n test/C/src/Minimal.lf +bin/lfc --no-compile test/C/src/Minimal.lf + +# -o,--output-path Specify the root output directory. +bin/lfc -o . test/C/src/Minimal.lf +bin/lfc --output-path . test/C/src/Minimal.lf + +# --runtime-version Specify the version of the runtime +# library used for compiling LF +# programs. +bin/lfc --runtime-version f157be30bbeab0e2a991f29f9c7f388ca39681a7 test/Cpp/src/Minimal.lf + +# -w,--workers Specify the default number of worker threads. +bin/lfc -w 2 test/C/src/Minimal.lf +bin/lfc --workers 2 test/C/src/Minimal.lf +bin/lfc --threading true test/C/src/Minimal.lf +bin/lfc --threading false test/C/src/Minimal.lf + +# --target-compiler Target compiler to invoke. +# (Added no-compile to avoid adding dependency.) +bin/lfc --target-compiler gcc --no-compile test/C/src/Minimal.lf + +# --version +bin/lfc --version + # Ensure that lfc is robust to symbolic links. test_with_links "lfc" diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 87d48f37f1..bb1a8823fc 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -21,7 +21,7 @@ jobs: run: runs-on: ubuntu-latest container: - image: zephyrprojectrtos/zephyr-build:v0.24.13 + image: zephyrprojectrtos/zephyr-build:latest options: -u root --entrypoint /bin/sh steps: - name: Install Java 17, Maven and set JAVA_HOME @@ -45,9 +45,7 @@ jobs: ref: ${{ inputs.compiler-ref }} fetch-depth: 0 - name: Try to get around git safe issues - run: | - git config --global --add safe.directory '/__w/lingua-franca/lingua-franca' - git config --global --add safe.directory '/__w/reactor-c/reactor-c' + run: git config --global --add safe.directory /__w/lingua-franca/lingua-franca - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Check out specific ref of reactor-c diff --git a/.github/workflows/ts-tests.yml b/.github/workflows/ts-tests.yml index 83c04d8cf7..24e40b7eef 100644 --- a/.github/workflows/ts-tests.yml +++ b/.github/workflows/ts-tests.yml @@ -28,7 +28,7 @@ jobs: if: ${{ runner.os == 'macOS' }} - name: Perform TypeScript tests run: | - ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#master" + ./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* - name: Report to CodeCov uses: codecov/codecov-action@v3.1.1 with: diff --git a/build.gradle b/build.gradle index 96f973aadd..ec53267287 100644 --- a/build.gradle +++ b/build.gradle @@ -42,8 +42,9 @@ subprojects { implementation group: 'com.google.inject', name: 'guice', version: guiceVersion // https://picocli.info/ implementation group: 'info.picocli', name: 'picocli', version: picocliVersion - } - dependencies { + // https://mvnrepository.com/artifact/com.google.code.gson/gson + implementation group: 'com.google.code.gson', name: 'gson', version: gsonVersion + // https://kotlinlang.org implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: kotlinVersion implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlinVersion } diff --git a/gradle.properties b/gradle.properties index fe695c4c7f..0ab81aa5a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ group=org.lflang version=0.4.1-SNAPSHOT [versions] -picocliVersion=4.7.0 googleJavaFormatVersion=1.15.0 guiceVersion=5.1.0 jacocoVersion=0.8.7 +gsonVersion=2.10.1 jupiterVersion=5.8.2 jUnitPlatformVersion=1.8.2 jUnitVersion=4.13.2 @@ -15,6 +15,7 @@ kotlinVersion=1.6.20 lsp4jVersion=0.14.0 mwe2LaunchVersion=2.12.2 openTest4jVersion=1.2.0 +picocliVersion=4.7.0 resourcesVersion=3.16.0 shadowJarVersion=7.1.2 spotlessVersion=6.11.0 diff --git a/lib/scripts/launch-fedsd.sh b/lib/scripts/launch-fedsd.sh deleted file mode 100755 index e09c60fc1e..0000000000 --- a/lib/scripts/launch-fedsd.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/bash - -#============================================================================ -# Description: Visualize federated trace data for RTI-federate interactions. -# Authors: Chadlia Jerad -# Edward A. Lee -# Usage: Usage: fedsd -r [rti.csv] -f [fed.csv ...] -#============================================================================ - -#============================================================================ -# Preamble -#============================================================================ - -# Copied from build.sh FIXME: How to avoid copying - -# Find the directory in which this script resides in a way that is compatible -# with MacOS, which has a `readlink` implementation that does not support the -# necessary `-f` flag to canonicalize by following every symlink in every -# component of the given name recursively. -# This solution, adapted from an example written by Geoff Nixon, is POSIX- -# compliant and robust to symbolic links. If a chain of more than 1000 links -# is encountered, we return. -find_dir() ( - start_dir=$PWD - cd "$(dirname "$1")" - link=$(readlink "$(basename "$1")") - count=0 - while [ "${link}" ]; do - if [[ "${count}" -lt 1000 ]]; then - cd "$(dirname "${link}")" - link=$(readlink "$(basename "$1")") - ((count++)) - else - return - fi - done - real_path="$PWD/$(basename "$1")" - cd "${start_dir}" - echo `dirname "${real_path}"` -) - -# Report fatal error and exit. -function fatal_error() { - 1>&2 echo -e "\e[1mfedsd: \e[31mfatal error: \e[0m$1" - exit 1 -} - -abs_path="$(find_dir "$0")" - -if [[ "${abs_path}" ]]; then - base=`dirname $(dirname ${abs_path})` -else - fatal_error "Unable to determine absolute path to $0." -fi - -# Get the lft files -lft_files_list=$@ - -if [ -z "$lft_files_list" ] -then - echo "Usage: fedsd [lft files]" - exit 1 -fi - -# Initialize variables -csv_files_list='' -extension='.csv' -rti_csv_file='' - -# Iterate over the lft file list to: -# - First, transform into csv -# - Second, construct the csv fiel name -# - Then construct the csv file list -# The csv file list does include the rti, it is put in a separate variable -for each_lft_file in $lft_files_list - do - # Tranform to csv - trace_to_csv $each_lft_file - # Get the file name - csv=${each_lft_file%.*} - if [ $csv == 'rti' ] - then - # Set the rti csv file - rti_csv_file='rti.csv' - else - # Construct the csv file name and add it to the list - csv_files_list="$csv$extension $csv_files_list" - fi - done - -# echo $lft_files_list -# echo $rti_csv_file -# echo $csv_files_list - -# FIXME: Check that python3 is in the path. -if [ $rti_csv_file == '' ] -then - # FIXME: Support the case where no rti file is given - python3 "${base}/util/tracing/visualization/fedsd.py" "-f" $csv_files_list -else - echo Building the communication diagram for the following trace files: $lft_files_list in trace_svg.html - python3 "${base}/util/tracing/visualization/fedsd.py" "-r" "$rti_csv_file" "-f" $csv_files_list -fi diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java index f3abd9d869..4cec8b2dd3 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/LfcCliTest.java @@ -26,17 +26,13 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.lflang.tests.TestUtils.TempDirBuilder.dirBuilder; import static org.lflang.tests.TestUtils.TempDirChecker.dirChecker; import static org.lflang.tests.TestUtils.isDirectory; import static org.lflang.tests.TestUtils.isRegularFile; -import com.google.inject.Injector; - import java.io.IOException; import java.nio.file.Path; -import java.util.Properties; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -44,12 +40,9 @@ import org.lflang.LocalStrings; import org.lflang.cli.Io; import org.lflang.cli.Lfc; -import org.lflang.generator.LFGeneratorContext.BuildParm; -import org.lflang.tests.TestUtils.TempDirBuilder; /** * @author Clément Fournier - * @author Atharva Patil */ public class LfcCliTest { @@ -62,6 +55,7 @@ public class LfcCliTest { } """; + @Test public void testHelpArg() { lfcTester.run("--help", "--version") @@ -92,63 +86,6 @@ public void testWrongCliArg() { }); } - @Test - public void testInvalidArgs(@TempDir Path tempDir) throws IOException { - dirBuilder(tempDir).file("src/File.lf", LF_PYTHON_FILE); - LfcOneShotTestFixture fixture = new LfcOneShotTestFixture(); - - // Invalid src file. - fixture.run(tempDir, "unknown.lf") - .verify(result -> { - result.checkStdErr(containsString("No such file or directory.")); - result.checkFailed(); - }); - - // Invalid output path. - fixture.run(tempDir, "--output-path", "unknown/output/path", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Output location does not exist.")); - result.checkFailed(); - }); - - // Invalid build type. - fixture.run(tempDir, "--build-type", "unknown-build-type", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid build type.")); - result.checkFailed(); - }); - - // Invalid logging level. - fixture.run(tempDir, "--logging", "unknown_level", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid log level.")); - result.checkFailed(); - }); - - // Invalid RTI path. - fixture.run(tempDir, "--rti", "unknown/rti/path", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid RTI path.")); - result.checkFailed(); - }); - - // Invalid scheduler. - fixture.run(tempDir, "--scheduler", "unknown-scheduler", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid scheduler.")); - result.checkFailed(); - }); - - // Invalid workers. - fixture.run(tempDir, "--workers", "notaninteger", "src/File.lf") - .verify(result -> { - result.checkStdErr(containsString("Invalid value for option '--workers'")); - result.checkStdErr(containsString("is not an int")); - result.checkFailed(); - }); - - } - @Test public void testGenInSrcDir(@TempDir Path tempDir) throws IOException { dirBuilder(tempDir).file("src/File.lf", LF_PYTHON_FILE); @@ -161,74 +98,17 @@ public void testGenInSrcDir(@TempDir Path tempDir) throws IOException { .check("bin", isDirectory()) .check("src-gen/File/File.py", isRegularFile()); }); - } - @Test - public void testGeneratorArgs(@TempDir Path tempDir) - throws IOException { - TempDirBuilder dir = dirBuilder(tempDir); - dir.file("src/File.lf", LF_PYTHON_FILE); - dir.mkdirs("path//to/rti"); - - String[] args = { - "src/File.lf", - "--output-path", "src", - "--build-type", "Release", - "--clean", - "--target-compiler", "gcc", - "--external-runtime-path", "src", - "--federated", - "--logging", "info", - "--lint", - "--no-compile", - "--quiet", - "--rti", "path/to/rti", - "--runtime-version", "rs", - "--scheduler", "GEDF_NP", - "--threading", "false", - "--workers", "1", - }; - LfcOneShotTestFixture fixture = new LfcOneShotTestFixture(); - - fixture.run(tempDir, args) - .verify(result -> { - // Don't validate execution because args are dummy args. - Properties properties = fixture.lfc.getGeneratorArgs(); - assertEquals(properties.getProperty(BuildParm.BUILD_TYPE.getKey()), "Release"); - assertEquals(properties.getProperty(BuildParm.CLEAN.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.TARGET_COMPILER.getKey()), "gcc"); - assertEquals(properties.getProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey()), "src"); - assertEquals(properties.getProperty(BuildParm.LOGGING.getKey()), "info"); - assertEquals(properties.getProperty(BuildParm.LINT.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.NO_COMPILE.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.QUIET.getKey()), "true"); - assertEquals(properties.getProperty(BuildParm.RTI.getKey()), "path/to/rti"); - assertEquals(properties.getProperty(BuildParm.RUNTIME_VERSION.getKey()), "rs"); - assertEquals(properties.getProperty(BuildParm.SCHEDULER.getKey()), "GEDF_NP"); - assertEquals(properties.getProperty(BuildParm.THREADING.getKey()), "false"); - assertEquals(properties.getProperty(BuildParm.WORKERS.getKey()), "1"); - }); } + static class LfcTestFixture extends CliToolTestFixture { + @Override protected void runCliProgram(Io io, String[] args) { Lfc.main(io, args); } } - static class LfcOneShotTestFixture extends CliToolTestFixture { - - private Lfc lfc; - - @Override - protected void runCliProgram(Io io, String[] args) { - // Injector used to obtain Main instance. - final Injector injector = Lfc.getInjector("lfc", io); - // Main instance. - this.lfc = injector.getInstance(Lfc.class); - lfc.doExecute(io, args); - } - } } diff --git a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java b/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java index 3a34e9cb81..2bbbada212 100644 --- a/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java +++ b/org.lflang.tests/src/org/lflang/tests/cli/LffCliTest.java @@ -130,7 +130,7 @@ public void testNoSuchFile(@TempDir Path tempDir) { result.checkFailed(); result.checkStdErr(containsString( - tempDir.resolve("nosuchdir") + ": No such file or directory.")); + tempDir.resolve("nosuchdir") + ": No such file or directory")); } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java index d7862e5d25..ae325ab94d 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/FormattingUnitTests.java @@ -34,7 +34,7 @@ public void testSimple() { @Test public void testAssignments() { - assertFormatsTo( + assertIsFormatted( """ target C @@ -43,15 +43,6 @@ public void testAssignments() { input in: int state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) } - """, - """ - target C - - reactor Destination { - input ok: bool - input in: int - state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} - } """ ); } @@ -65,34 +56,16 @@ public void testState() { reactor Destination { state one_init: tag_t( {= NEVER_TAG_INITIALIZER =}) state no_init: tag_t - state list_init(1,2) // this syntax is deprecated + state list_init(1,2) } """, """ target Python - reactor Destination { - state one_init: tag_t = {= NEVER_TAG_INITIALIZER =} - state no_init: tag_t - state list_init(1, 2) # this syntax is deprecated - } - """ - ); - } - - @Test - public void testCppInits() { - assertIsFormatted( - """ - target Cpp - reactor Destination { state one_init: tag_t({= NEVER_TAG_INITIALIZER =}) state no_init: tag_t - state assign: int = 0 - state paren: int(0) - state brace: std::vector{1, 2} - state paren_list: std::vector(1, 2) + state list_init(1, 2) } """ ); diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java index a78d41ac4d..60cfa39725 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java @@ -101,7 +101,7 @@ public void testLet() throws Exception { )); Assertions.assertNotNull(model); - final var ctypes = CTypes.getInstance(); + final var ctypes = new CTypes(new DefaultErrorReporter()); final var resource = model.eResource(); final var transformation = new DelayedConnectionTransformation(new CDelayBodyGenerator(ctypes), ctypes, resource, true, true); transformation.applyTransformation(ASTUtils.getAllReactors(resource)); @@ -115,9 +115,10 @@ public void testLet() throws Exception { TreeIterator it = model.eResource().getAllContents(); while (it.hasNext()) { EObject obj = it.next(); - if (!(obj instanceof Reactor reactor)) { + if (!(obj instanceof Reactor)) { continue; } + Reactor reactor = (Reactor) obj; if (reactor.isMain()) { mainDef = LfFactory.eINSTANCE.createInstantiation(); mainDef.setName(reactor.getName()); diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java index 67df93ed30..4c0d5dee08 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -1,30 +1,29 @@ /* Scoping unit tests. */ /************* - Copyright (c) 2019, The University of California at Berkeley. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ***************/ - +Copyright (c) 2019, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***************/ package org.lflang.tests.compiler; import java.util.LinkedList; @@ -64,7 +63,7 @@ /** * Collection of unit tests to ensure validation is done correctly. - * + * * @author Edward A. Lee * @author Marten Lohstroh * @author Matt Weber @@ -72,8 +71,7 @@ * @author Alexander Schulz-Rosengarten */ public class LinguaFrancaValidationTest { - - @Inject + @Inject ParseHelper parser; @Inject @@ -81,7 +79,6 @@ public class LinguaFrancaValidationTest { /** * Helper function to parse a Lingua Franca program and expect no errors. - * * @return A model representing the parsed string. */ private Model parseWithoutError(String s) throws Exception { @@ -95,7 +92,6 @@ private Model parseWithoutError(String s) throws Exception { /** * Helper function to parse a Lingua Franca program and expect errors. - * * @return A model representing the parsed string. */ private Model parseWithError(String s) throws Exception { @@ -103,72 +99,105 @@ private Model parseWithError(String s) throws Exception { Assertions.assertNotNull(model); Assertions.assertFalse(model.eResource().getErrors().isEmpty()); return model; - } + } /** * Ensure that duplicate identifiers for actions reported. */ @Test public void duplicateVariable() throws Exception { - String testCase = """ - target TypeScript; - main reactor Foo { - logical action bar; - physical action bar; - } - """; - validator.assertError(parseWithoutError(testCase), - LfPackage.eINSTANCE.getAction(), - null, - "Duplicate Variable 'bar' in Reactor 'Foo'"); +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor Foo { +// logical action bar; +// physical action bar; +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor Foo {", + " logical action bar;", + " physical action bar;", + "}"); + validator.assertError(parseWithoutError(testCase), + LfPackage.eINSTANCE.getAction(), + null, + "Duplicate Variable 'bar' in Reactor 'Foo'"); } /** - * Check that reactors in C++ cannot be named preamble + * Check that reactors in C++ cannot be named preamble */ @Test public void disallowReactorCalledPreamble() throws Exception { - Model model_no_errors = parser.parse(""" - target Cpp; - main reactor { - } - """); - - Model model_error_1 = parser.parse(""" - target Cpp; - main reactor Preamble { - } - """); - - Model model_error_2 = parser.parse(""" - target Cpp; - reactor Preamble { - } - main reactor Main { - } - """); - +// Java 17: +// Model model_no_errors = """ +// target Cpp; +// main reactor { +// } +// """ +// Java 11: + Model model_no_errors = parser.parse(String.join( + System.getProperty("line.separator"), + "target Cpp;", + "main reactor {", + "}" + )); + +// Java 17: +// Model model_error_1 = """ +// target Cpp; +// main reactor Preamble { +// } +// """ +// Java 11: + Model model_error_1 = parser.parse(String.join( + System.getProperty("line.separator"), + "target Cpp;", + "main reactor Preamble {", + "}" + )); + +// Java 17: +// Model model_error_2 = """ +// target Cpp; +// reactor Preamble { +// } +// main reactor Main { +// } +// """ +// Java 11: + Model model_error_2 = parser.parse(String.join( + System.getProperty("line.separator"), + "target Cpp;", + "reactor Preamble {", + "}", + "main reactor Main {", + "}" + )); + Assertions.assertNotNull(model_no_errors); Assertions.assertNotNull(model_error_1); Assertions.assertNotNull(model_error_2); - Assertions.assertTrue(model_no_errors.eResource().getErrors().isEmpty(), - "Encountered unexpected error while parsing: " - + model_no_errors.eResource().getErrors()); - Assertions.assertTrue(model_error_1.eResource().getErrors().isEmpty(), + Assertions.assertTrue(model_no_errors.eResource().getErrors().isEmpty(), + "Encountered unexpected error while parsing: " + model_no_errors.eResource().getErrors()); + Assertions.assertTrue(model_error_1.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing: " + model_error_1.eResource().getErrors()); - Assertions.assertTrue(model_error_2.eResource().getErrors().isEmpty(), + Assertions.assertTrue(model_error_2.eResource().getErrors().isEmpty(), "Encountered unexpected error while parsing: " + model_error_2.eResource().getErrors()); validator.assertNoIssues(model_no_errors); - validator.assertError(model_error_1, - LfPackage.eINSTANCE.getReactor(), - null, - "Reactor cannot be named 'Preamble'"); - validator.assertError(model_error_2, - LfPackage.eINSTANCE.getReactor(), - null, - "Reactor cannot be named 'Preamble'"); + validator.assertError(model_error_1, + LfPackage.eINSTANCE.getReactor(), + null, + "Reactor cannot be named 'Preamble'"); + validator.assertError(model_error_2, + LfPackage.eINSTANCE.getReactor(), + null, + "Reactor cannot be named 'Preamble'"); } @@ -177,39 +206,59 @@ public void disallowReactorCalledPreamble() throws Exception { */ @Test public void disallowUnderscoreInputs() throws Exception { - String testCase = """ - target TypeScript; - main reactor { - input __bar; - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor { +// input __bar; +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor {", + " input __bar;", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + @Test public void disallowMainWithDifferentNameThanFile() throws Exception { - String testCase = """ - target C; - main reactor Foo {} - """; +// Java 17: +// String testCase = """ +// target C; +// main reactor Foo {} +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor Foo {}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Name of main reactor must match the file name (or be omitted)"); } - + /** * Ensure that "__" is not allowed at the start of an output name. */ @Test public void disallowUnderscoreOutputs() throws Exception { - String testCase = """ - target TypeScript; - main reactor Foo { - output __bar; - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor Foo { +// output __bar; +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor Foo {", + " output __bar;", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); @@ -220,207 +269,324 @@ public void disallowUnderscoreOutputs() throws Exception { */ @Test public void disallowUnderscoreActions() throws Exception { - String testCase = """ - target TypeScript; - main reactor Foo { - logical action __bar; - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor Foo { +// logical action __bar; +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor Foo {", + " logical action __bar;", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of a timer name. */ @Test public void disallowUnderscoreTimers() throws Exception { - String testCase = """ - target TypeScript; - main reactor Foo { - timer __bar(0); - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor Foo { +// timer __bar(0); +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor Foo {", + " timer __bar(0);", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, - "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); + "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of a parameter name. */ @Test public void disallowUnderscoreParameters() throws Exception { - String testCase = """ - target TypeScript; - main reactor Foo(__bar) { - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor Foo(__bar) { +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor Foo(__bar) {", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getParameter(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of an state name. */ @Test public void disallowUnderscoreStates() throws Exception { - String testCase = """ - target TypeScript; - main reactor Foo { - state __bar; - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor Foo { +// state __bar; +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor Foo {", + " state __bar;", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __bar"); } - + /** * Ensure that "__" is not allowed at the start of a reactor definition name. */ @Test public void disallowUnderscoreReactorDef() throws Exception { - String testCase = """ - target TypeScript; - main reactor __Foo { - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// main reactor __Foo { +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "main reactor __Foo {", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __Foo"); } - + /** * Ensure that "__" is not allowed at the start of a reactor instantiation name. */ @Test public void disallowUnderscoreReactorInstantiation() throws Exception { - String testCase = """ - target TypeScript; - reactor Foo { - } - main reactor Bar { - __x = new Foo(); - } - """; +// Java 17: +// String testCase = """ +// target TypeScript; +// reactor Foo { +// } +// main reactor Bar { +// __x = new Foo(); +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target TypeScript;", + "reactor Foo {", + "}", + "main reactor Bar {", + " __x = new Foo();", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), null, "Names of objects (inputs, outputs, actions, timers, parameters, state, reactor definitions, and reactor instantiation) may not start with \"__\": __x"); } - + /** * Disallow connection to port that is effect of reaction. */ @Test public void connectionToEffectPort() throws Exception { - String testCase = """ - target C; - reactor Foo { - output out:int; - } - main reactor Bar { - output out:int; - x = new Foo(); - x.out -> out; - reaction(startup) -> out {= - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// reactor Foo { +// output out:int; +// } +// main reactor Bar { +// output out:int; +// x = new Foo(); +// x.out -> out; +// reaction(startup) -> out {= +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor Foo {", + " output out:int;", + "}", + "main reactor Bar {", + " output out:int;", + " x = new Foo();", + " x.out -> out;", + " reaction(startup) -> out {=", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Cannot connect: Port named 'out' is already effect of a reaction."); } - + /** * Disallow connection to port that is effect of reaction. */ @Test public void connectionToEffectPort2() throws Exception { - String testCase = """ - target C; - reactor Foo { - input inp:int; - output out:int; - } - main reactor { - output out:int; - x = new Foo(); - y = new Foo(); - - y.out -> x.inp; - reaction(startup) -> x.inp {= - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// reactor Foo { +// input inp:int; +// output out:int; +// } +// main reactor { +// output out:int; +// x = new Foo(); +// y = new Foo(); +// +// y.out -> x.inp; +// reaction(startup) -> x.inp {= +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor Foo {", + " input inp:int;", + " output out:int;", + "}", + "main reactor {", + " output out:int;", + " x = new Foo();", + " y = new Foo();", + "", + " y.out -> x.inp;", + " reaction(startup) -> x.inp {=", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Cannot connect: Port named 'inp' is already effect of a reaction."); } - + /** - * Allow connection to the port of a contained reactor if another port with same name is effect - * of a reaction. + * Allow connection to the port of a contained reactor if another port with same name is effect of a reaction. */ @Test public void connectionToEffectPort3() throws Exception { - String testCase = """ - target C; - - reactor Foo { - input in:int; - } - reactor Bar { - input in:int; - x1 = new Foo(); - x2 = new Foo(); - in -> x1.in; - reaction(startup) -> x2.in {= - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// +// reactor Foo { +// input in:int; +// } +// reactor Bar { +// input in:int; +// x1 = new Foo(); +// x2 = new Foo(); +// in -> x1.in; +// reaction(startup) -> x2.in {= +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "", + "reactor Foo {", + " input in:int;", + "}", + "reactor Bar {", + " input in:int;", + " x1 = new Foo();", + " x2 = new Foo();", + " in -> x1.in;", + " reaction(startup) -> x2.in {=", + " =}", + "}"); validator.assertNoErrors(parseWithoutError(testCase)); } /** - * Allow connection to the port of a contained reactor if another port with same name is effect - * of a reaction. + * Allow connection to the port of a contained reactor if another port with same name is effect of a reaction. */ @Test public void connectionToEffectPort3_5() throws Exception { - String testCase = """ - target C; - - reactor Foo { - input in:int; - } - main reactor { - input in:int; - x1 = new Foo(); - x2 = new Foo(); - in -> x1.in; - reaction(startup) -> x2.in {= - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// +// reactor Foo { +// input in:int; +// } +// main reactor { +// input in:int; +// x1 = new Foo(); +// x2 = new Foo(); +// in -> x1.in; +// reaction(startup) -> x2.in {= +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "", + "reactor Foo {", + " input in:int;", + "}", + "main reactor {", + " input in:int;", + " x1 = new Foo();", + " x2 = new Foo();", + " in -> x1.in;", + " reaction(startup) -> x2.in {=", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getVariable(), null, - "Main reactor cannot have inputs."); + "Main reactor cannot have inputs."); } /** - * Disallow connection to the port of a contained reactor if the same port is effect of a - * reaction. + * Disallow connection to the port of a contained reactor if the same port is effect of a reaction. */ @Test public void connectionToEffectPort4() throws Exception { - String testCase = """ - target C; - - reactor Foo { - input in:int; - } - main reactor { - input in:int; - x1 = new Foo(); - in -> x1.in; - reaction(startup) -> x1.in {= - =} - } - """; +// Java 17: +// String testCase = """ +// target C; + +// reactor Foo { +// input in:int; +// } +// main reactor { +// input in:int; +// x1 = new Foo(); +// in -> x1.in; +// reaction(startup) -> x1.in {= +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "", + "reactor Foo {", + " input in:int;", + "}", + "main reactor {", + " input in:int;", + " x1 = new Foo();", + " in -> x1.in;", + " reaction(startup) -> x1.in {=", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Cannot connect: Port named 'in' is already effect of a reaction."); } @@ -430,22 +596,39 @@ public void connectionToEffectPort4() throws Exception { */ @Test public void multipleConnectionsToInputTest() throws Exception { - String testCase = """ - target C; - reactor Source { - output out:int; - } - reactor Sink { - input in:int; - } - main reactor { - input in:int; - src = new Source(); - sink = new Sink(); - in -> sink.in; - src.out -> sink.in; - } - """; +// Java 17: +// String testCase = """ +// target C; +// reactor Source { +// output out:int; +// } +// reactor Sink { +// input in:int; +// } +// main reactor { +// input in:int; +// src = new Source(); +// sink = new Sink(); +// in -> sink.in; +// src.out -> sink.in; +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor Source {", + " output out:int;", + "}", + "reactor Sink {", + " input in:int;", + "}", + "main reactor {", + " input in:int;", + " src = new Source();", + " sink = new Sink();", + " in -> sink.in;", + " src.out -> sink.in;", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Cannot connect: Port named 'in' may only appear once on the right side of a connection."); } @@ -455,92 +638,146 @@ public void multipleConnectionsToInputTest() throws Exception { */ @Test public void detectInstantiationCycle() throws Exception { - String testCase = """ - target C; - reactor Contained { - x = new Contained(); - } - """; +// Java 17: +// String testCase = """ +// target C; +// reactor Contained { +// x = new Contained(); +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor Contained {", + " x = new Contained();", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), null, "Instantiation is part of a cycle: Contained"); } - - + + /** * Detect cycles in the instantiation graph. */ @Test public void detectInstantiationCycle2() throws Exception { - String testCase = """ - target C; - reactor Intermediate { - x = new Contained(); - } - reactor Contained { - x = new Intermediate(); - } - """; - - Model model = parseWithoutError(testCase); +// Java 17: +// String testCase = """ +// target C; +// reactor Intermediate { +// x = new Contained(); +// } +// +// reactor Contained { +// x = new Intermediate(); +// } +// """ +// Java 11: + Model model = parseWithoutError(String.join( + System.getProperty("line.separator"), + "target C;", + "reactor Intermediate {", + " x = new Contained();", + "}", + "", + "reactor Contained {", + " x = new Intermediate();", + "}" + )); validator.assertError(model, LfPackage.eINSTANCE.getInstantiation(), null, "Instantiation is part of a cycle: Intermediate, Contained."); validator.assertError(model, LfPackage.eINSTANCE.getInstantiation(), null, "Instantiation is part of a cycle: Intermediate, Contained."); } - + /** * Detect causality loop. */ @Test public void detectCausalityLoop() throws Exception { - - String testCase = """ - target C; - - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } - - main reactor { - a = new X() - b = new X() - a.y -> b.x - b.y -> a.x - } - """; - Model model = parseWithoutError(testCase); +// Java 17: +// String testCase = """ +// target C; +// +// reactor X { +// input x:int; +// output y:int; +// reaction(x) -> y {= +// =} +// } +// +// main reactor { +// a = new X() +// b = new X() +// a.y -> b.x +// b.y -> a.x +// } +// """ +// Java 11: + Model model = parseWithoutError(String.join( + System.getProperty("line.separator"), + "target C;", + "", + "reactor X {", + " input x:int;", + " output y:int;", + " reaction(x) -> y {=", + " =}", + "}", + "", + "main reactor {", + " a = new X()", + " b = new X()", + " a.y -> b.x", + " b.y -> a.x", + "}" + )); validator.assertError(model, LfPackage.eINSTANCE.getReaction(), null, "Reaction triggers involved in cyclic dependency in reactor X: x."); validator.assertError(model, LfPackage.eINSTANCE.getReaction(), - null, "Reaction effects involved in cyclic dependency in reactor X: y."); + null, "Reaction effects involved in cyclic dependency in reactor X: y."); } - + /** * Let cyclic dependencies be broken by "after" clauses. */ @Test public void afterBreaksCycle() throws Exception { - String testCase = """ - target C - - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } - - main reactor { - a = new X() - b = new X() - a.y -> b.x after 5 msec - b.y -> a.x - } - """; - +// Java 17: +// String testCase = """ +// target C +// +// reactor X { +// input x:int; +// output y:int; +// reaction(x) -> y {= +// =} +// } +// +// main reactor { +// a = new X() +// b = new X() +// a.y -> b.x after 5 msec +// b.y -> a.x +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C", + " ", + "reactor X {", + " input x:int;", + " output y:int;", + " reaction(x) -> y {=", + " =}", + "}", + "", + "main reactor {", + " a = new X()", + " b = new X()", + " a.y -> b.x after 5 msec", + " b.y -> a.x", + "}"); validator.assertNoErrors(parseWithoutError(testCase)); } @@ -550,23 +787,42 @@ public void afterBreaksCycle() throws Exception { */ @Test public void afterBreaksCycle2() throws Exception { - String testCase = """ - target C - - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } - - main reactor { - a = new X() - b = new X() - a.y -> b.x after 0 sec - b.y -> a.x - } - """; +// Java 17: +// String testCase = """ +// target C +// +// reactor X { +// input x:int; +// output y:int; +// reaction(x) -> y {= +// =} +// } +// +// main reactor { +// a = new X() +// b = new X() +// a.y -> b.x after 0 sec +// b.y -> a.x +// } +// """ +// Java 11: + + String testCase = String.join(System.getProperty("line.separator"), + "target C", + " ", + "reactor X {", + " input x:int;", + " output y:int;", + " reaction(x) -> y {=", + " =}", + "}", + "", + "main reactor {", + " a = new X()", + " b = new X()", + " a.y -> b.x after 0 sec", + " b.y -> a.x", + "}"); validator.assertNoErrors(parseWithoutError(testCase)); } @@ -576,23 +832,41 @@ public void afterBreaksCycle2() throws Exception { */ @Test public void afterBreaksCycle3() throws Exception { - String testCase = """ - target C - - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } - - main reactor { - a = new X() - b = new X() - a.y -> b.x after 0 - b.y -> a.x - } - """; +// Java 17: +// String testCase = """ +// target C +// +// reactor X { +// input x:int; +// output y:int; +// reaction(x) -> y {= +// =} +// } +// +// main reactor { +// a = new X() +// b = new X() +// a.y -> b.x after 0 +// b.y -> a.x +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C", + " ", + "reactor X {", + " input x:int;", + " output y:int;", + " reaction(x) -> y {=", + " =}", + "}", + "", + "main reactor {", + " a = new X()", + " b = new X()", + " a.y -> b.x after 0", + " b.y -> a.x", + "}"); validator.assertNoErrors(parseWithoutError(testCase)); } @@ -601,198 +875,311 @@ public void afterBreaksCycle3() throws Exception { */ @Test public void nonzeroAfterMustHaveUnits() throws Exception { - String testCase = """ - target C - - reactor X { - input x:int; - output y:int; - reaction(x) -> y {= - =} - } - - main reactor { - a = new X() - b = new X() - a.y -> b.x after 1 - } - """; +// Java 17: +// String testCase = """ +// target C +// +// reactor X { +// input x:int; +// output y:int; +// reaction(x) -> y {= +// =} +// } +// +// main reactor { +// a = new X() +// b = new X() +// a.y -> b.x after 1 +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C", + " ", + "reactor X {", + " input x:int;", + " output y:int;", + " reaction(x) -> y {=", + " =}", + "}", + "", + "main reactor {", + " a = new X()", + " b = new X()", + " a.y -> b.x after 1", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), null, "Missing time unit."); } + /** * Report non-zero time value without units. */ @Test public void nonZeroTimeValueWithoutUnits() throws Exception { - String testCase = """ - target C; - main reactor { - timer t(42, 1 sec); - reaction(t) {= - printf("Hello World.\\n"); - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// main reactor { +// timer t(42, 1 sec); +// reaction(t) {= +// printf("Hello World.\\n"); +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " timer t(42, 1 sec);", + " reaction(t) {=", + " printf(\"Hello World.\\n\");", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); - } - + } + /** * Report reference to non-time parameter in time argument. */ @Test public void parameterTypeMismatch() throws Exception { - String testCase = """ - target C; - main reactor (p:int(0)) { - timer t(p, 1 sec); - reaction(t) {= - printf("Hello World.\\n"); - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// main reactor (p:int(0)) { +// timer t(p, 1 sec); +// reaction(t) {= +// printf("Hello World.\\n"); +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor (p:int(0)) {", + " timer t(p, 1 sec);", + " reaction(t) {=", + " printf(\"Hello World.\\n\");", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Referenced parameter is not of time type."); } - + /** * Report inappropriate literal in time argument. */ @Test public void targetCodeInTimeArgument() throws Exception { - String testCase = """ - target C; - main reactor { - timer t({=foo()=}, 1 sec); - reaction(t) {= - printf("Hello World.\\n"); - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// main reactor { +// timer t({=foo()=}, 1 sec); +// reaction(t) {= +// printf("Hello World.\\n"); +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " timer t({=foo()=}, 1 sec);", + " reaction(t) {=", + " printf(\"Hello World.\\n\");", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Invalid time value."); - } - + } + /** * Report overflowing deadline. */ @Test public void overflowingDeadlineC() throws Exception { - String testCase = """ - target C; - main reactor { - timer t; - reaction(t) {= - printf("Hello World.\\n"); - =} deadline (40 hours) {= - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// main reactor { +// timer t; +// reaction(t) {= +// printf("Hello World.\\n"); +// =} deadline (40 hours) {= +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + "timer t;", + " reaction(t) {=", + " printf(\"Hello World.\\n\");", + " =} deadline (40 hours) {=", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getDeadline(), null, "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + - " nanoseconds."); - } - + " nanoseconds."); + } + /** * Report overflowing parameter. */ @Test public void overflowingParameterC() throws Exception { - String testCase = """ - target C; - main reactor(d:time(40 hours)) { - timer t; - reaction(t) {= - printf("Hello World.\\n"); - =} deadline (d) {= - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// main reactor(d:time(40 hours)) { +// timer t; +// reaction(t) {= +// printf("Hello World.\\n"); +// =} deadline (d) {= +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor(d:time(40 hours)) {", + "timer t;", + " reaction(t) {=", + " printf(\"Hello World.\\n\");", + " =} deadline (d) {=", + " =}", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getParameter(), null, "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } - - + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + } + + /** * Report overflowing assignment. */ @Test public void overflowingAssignmentC() throws Exception { - String testCase = """ - target C; - reactor Print(d:time(39 hours)) { - timer t; - reaction(t) {= - printf("Hello World.\\n"); - =} deadline (d) {= - =} - } - main reactor { - p = new Print(d=40 hours); - } - """; +// Java 17: +// String testCase = """ +// target C; +// reactor Print(d:time(39 hours)) { +// timer t; +// reaction(t) {= +// printf("Hello World.\\n"); +// =} deadline (d) {= +// =} +// } +// main reactor { +// p = new Print(d=40 hours); +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor Print(d:time(39 hours)) {", + " timer t;", + " reaction(t) {=", + " printf(\"Hello World.\\n\");", + " =} deadline (d) {=", + " =}", + "}", + "main reactor {", + " p = new Print(d=40 hours);", + "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAssignment(), null, "Time value used to specify a deadline exceeds the maximum of " + - TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); - } + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + } /** * Report missing trigger. */ @Test public void missingTrigger() throws Exception { - String testCase = """ - target C; - reactor X { - reaction() {= - // - =} - } - """; +// Java 17: +// String testCase = """ +// target C; +// reactor X { +// reaction() {= +// // +// =} +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor X {", + " reaction() {=", + " //", + " =}", + "}"); validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), null, "Reaction has no trigger."); } - + /** - * Test warnings and errors for the target dependent preamble visibility qualifiers + * Test warnings and errors for the target dependent preamble visibility qualifiers */ @Test public void testPreambleVisibility() throws Exception { for (Target target : Target.values()) { for (Visibility visibility : Visibility.values()) { - Model model_reactor_scope = parseWithoutError(""" - target %s; - reactor Foo { - %spreamble {==} - } - """.formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); - - Model model_file_scope = parseWithoutError(""" - target %s; - %spreamble {==} - reactor Foo { - } - """.formatted(target, visibility != Visibility.NONE ? visibility + " " : "")); - - Model model_no_preamble = parseWithoutError(""" - target %s; - reactor Foo { - } - """.formatted(target)); - +// Java 17: +// Model model_reactor_scope = """ +// target %s; +// reactor Foo { +// %spreamble {==} +// } +// """.formatted(target, visibility != java.beans.Visibility.NONE ? visibility + " " : ""); +// Java 11: + Model model_reactor_scope = parseWithoutError(String.join(System.getProperty("line.separator"), + String.format("target %s;", target), + "reactor Foo {", + String.format(" %spreamble {==}", visibility != Visibility.NONE ? visibility + " " : ""), + "}")); + +// Java 17: +// Model model_file_scope = """ +// target %s; +// %spreamble {==} +// reactor Foo { +// } +// """.formatted(target, visibility != java.beans.Visibility.NONE ? visibility + " " : ""); +// Java 11: + Model model_file_scope = parseWithoutError(String.join(System.getProperty("line.separator"), + String.format("target %s;", target), + String.format(" %spreamble {==}", visibility != Visibility.NONE ? visibility + " " : ""), + "reactor Foo {", + "}")); + +// Java 17: +// Model model_no_preamble = """ +// target %s; +// reactor Foo { +// } +// """.formatted(target); +// Java 11: + Model model_no_preamble = parseWithoutError(String.join(System.getProperty("line.separator"), + String.format("target %s;", target), + "reactor Foo {", + "}")); + validator.assertNoIssues(model_no_preamble); - + if (target == Target.CPP) { if (visibility == Visibility.NONE) { validator.assertError(model_file_scope, LfPackage.eINSTANCE.getPreamble(), null, "Preambles for the C++ target need a visibility qualifier (private or public)!"); validator.assertError(model_reactor_scope, LfPackage.eINSTANCE.getPreamble(), null, - "Preambles for the C++ target need a visibility qualifier (private or public)!"); + "Preambles for the C++ target need a visibility qualifier (private or public)!"); } else { validator.assertNoIssues(model_file_scope); validator.assertNoIssues(model_reactor_scope); @@ -811,30 +1198,46 @@ public void testPreambleVisibility() throws Exception { } } } - - + + /** * Tests for state and parameter declarations, including native lists. */ @Test public void stateAndParameterDeclarationsInC() throws Exception { - String testCase = """ - target C; - reactor Bar(a(0), // ERROR: type missing - b:int, // ERROR: uninitialized - t:time = 42, // ERROR: units missing - x:int = 0, - h:time = "bla", // ERROR: not a type - q:time(1 msec, 2 msec), // ERROR: not a list - y:int = t // ERROR: init using parameter - ) { - state offset:time = 42; // ERROR: units missing - state w:time = x; // ERROR: parameter is not a time - state foo:time = "bla"; // ERROR: assigned value not a time; - timer tick(1); // ERROR: not a time - } - """; - +// Java 17: +// String testCase = """ +// target C; +// reactor Bar(a(0), // ERROR: type missing +// b:int, // ERROR: uninitialized +// t:time(42), // ERROR: units missing +// x:int(0), +// h:time("bla"), // ERROR: not a type +// q:time(1 msec, 2 msec), // ERROR: not a list +// y:int(t) // ERROR: init using parameter +// ) { +// state offset:time(42); // ERROR: units missing +// state w:time(x); // ERROR: parameter is not a time +// state foo:time("bla"); // ERROR: assigned value not a time; +// timer tick(1); // ERROR: not a time +// } +// """ +// Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor Bar(a(0), // ERROR: type missing", + " b:int, // ERROR: uninitialized", + " t:time(42), // ERROR: units missing", + " x:int(0),", + " h:time(\"bla\"), // ERROR: not a type ", + " q:time(1 msec, 2 msec), // ERROR: not a list", + " y:int(t) // ERROR: init using parameter", + ") {", + " state offset:time(45); // ERROR: units missing", + " state w:time(x); // ERROR: parameter is not a time", + " state foo:time(\"bla\"); // ERROR: assigned value not a time", + " timer tick(1); // ERROR: not a time", + "}"); Model model = parseWithoutError(testCase); @@ -858,9 +1261,9 @@ reactor Bar(a(0), // ERROR: type missing "Invalid time value."); validator.assertError(model, LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); - } - - + } + + /** * Recognize valid IPV4 addresses, report invalid ones. */ @@ -872,44 +1275,69 @@ public void recognizeIPV4() throws Exception { // Correct IP addresses. for (String addr : correct) { - - String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """.formatted(addr, addr); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at foo@%s:4242 { +// y = new Y() at %s:2424; +// } +// """.formatted(addr, addr); +// Java 11: parseWithoutError( - testCase + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at foo@%s:4242 {", addr), + String.format(" y = new Y() at %s:2424; ", addr), + "}") ); } // IP addresses that don't parse. for (String addr : parseError) { - String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """.formatted(addr, addr); - parseWithError(testCase); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at foo@%s:4242 { +// y = new Y() at %s:2424; +// } +// """.formatted(addr, addr); +// Java 11: + parseWithError( + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at foo@%s:4242 {", addr), + String.format(" y = new Y() at %s:2424; ", addr), + "}") + ); } // IP addresses that parse but are invalid. for (String addr : validationError) { - Model model = parseWithoutError(""" - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """.formatted(addr, addr)); +// Java 17: +// Model model = """ +// target C; +// reactor Y {} +// federated reactor X at foo@%s:4242 { +// y = new Y() at %s:2424; +// } +// """.formatted(addr, addr); +// Java 11: + Model model = parseWithoutError( + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at foo@%s:4242 {", addr), + String.format(" y = new Y() at %s:2424; ", addr), + "}") + ); validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); } } - + /** * Recognize valid IPV6 addresses, report invalid ones. */ @@ -927,114 +1355,160 @@ public void recognizeIPV6() throws Exception { "::ffff:0.0.0.0", "::ffff:1.2.3.4", "::ffff:10.0.0.1", "1:2:3:4:5:6:77:88", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "2001:db8:3:4::192.0.2.33", "64:ff9b::192.0.2.33", "0:0:0:0:0:0:10.0.0.1"); - + List validationError = List.of("1:2:3:4:5:6:7:8:9", "1:2:3:4:5:6::7:8", "1:2:3:4:5:6:7:8:", "::1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7:8::", "1:2:3:4:5:6:7:88888", "2001:db8:3:4:5::192.0.2.33", "fe08::7:8interface", "fe08::7:8interface", "fe08::7:8i"); - + List parseError = List.of("fe08::7:8%", ":1:2:3:4:5:6:7:8"); - + // Correct IP addresses. for (String addr : correct) { - String testCase = """ - target C; - reactor Y {} - federated reactor at [foo@%s]:4242 { - y = new Y() at [%s]:2424; - } - """.formatted(addr, addr); - Model model = parseWithoutError(testCase); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at [foo@%s]:4242 { +// y = new Y() at [%s]:2424; +// } +// """.formatted(addr, addr); +// Java 11: + Model model = parseWithoutError( + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor at [foo@%s]:4242 {", addr), + String.format(" y = new Y() at [%s]:2424; ", addr), + "}") + ); validator.assertNoIssues(model); } - + // IP addresses that don't parse. for (String addr : parseError) { - String testCase = """ - target C; - reactor Y {} - federated reactor X at [foo@%s]:4242 { - y = new Y() at [%s]:2424; - } - """.formatted(addr, addr); - parseWithError(testCase); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at [foo@%s]:4242 { +// y = new Y() at [%s]:2424; +// } +// """.formatted(addr, addr); +// Java 11: + parseWithError( + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at [foo@%s]:4242 {", addr), + String.format(" y = new Y() at [%s]:2424; ", addr), + "}") + ); } // IP addresses that parse but are invalid. for (String addr : validationError) { - String testCase = """ - target C; - reactor Y {} - federated reactor X at [foo@%s]:4242 { - y = new Y() at [%s]:2424; - } - """.formatted(addr, addr); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at [foo@%s]:4242 { +// y = new Y() at [%s]:2424; +// } +// """.formatted(addr, addr); +// Java 11: Model model = parseWithoutError( - testCase + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at [foo@%s]:4242 {", addr), + String.format(" y = new Y() at [%s]:2424; ", addr), + "}") ); validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid IP address."); } } - + /** * Recognize valid host names and fully qualified names, report invalid ones. */ @Test public void recognizeHostNames() throws Exception { - + List correct = List.of("localhost"); // FIXME: add more - + List validationError = List.of("x.y.z"); // FIXME: add more - + List parseError = List.of("..xyz"); // FIXME: add more // Correct names. for (String addr : correct) { - String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """.formatted(addr, addr); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at foo@%s:4242 { +// y = new Y() at %s:2424; +// } +// """.formatted(addr, addr); +// Java 11: parseWithoutError( - testCase + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at foo@%s:4242 {", addr), + String.format(" y = new Y() at %s:2424; ", addr), + "}") ); } - + // Names that don't parse. for (String addr : parseError) { - String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """.formatted(addr, addr); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at foo@%s:4242 { +// y = new Y() at %s:2424; +// } +// """.formatted(addr, addr); +// Java 11: parseWithError( - testCase + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at foo@%s:4242 {", addr), + String.format(" y = new Y() at %s:2424; ", addr), + "}") ); } - + // Names that parse but are invalid. for (String addr : validationError) { - String testCase = """ - target C; - reactor Y {} - federated reactor X at foo@%s:4242 { - y = new Y() at %s:2424; - } - """.formatted(addr, addr); +// Java 17: +// String testCase = """ +// target C; +// reactor Y {} +// federated reactor X at foo@%s:4242 { +// y = new Y() at %s:2424; +// } +// """.formatted(addr, addr); +// Java 11: Model model = parseWithoutError( - testCase + String.join(System.getProperty("line.separator"), + "target C;", + "reactor Y {}", + String.format("federated reactor X at foo@%s:4242 {", addr), + String.format(" y = new Y() at %s:2424; ", addr), + "}") ); - validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, + validator.assertWarning(model, LfPackage.eINSTANCE.getHost(), null, "Invalid host name or fully qualified domain name."); } } - + /** * Maps a type to a list of known good values. */ @@ -1059,7 +1533,7 @@ public void recognizeHostNames() throws Exception { ); /** - * Maps a type to a list, each entry of which represents a list with + * Maps a type to a list, each entry of which represents a list with * three entries: a known wrong value, the suffix to add to the reported * name, and the type that it should be. */ @@ -1101,14 +1575,13 @@ public void recognizeHostNames() throws Exception { List.of("{trace-file-name: [1, 2, 3]}", ".trace-file-name", PrimitiveType.STRING) ) ); - + /** - * Given an array type, return a list of good or bad examples, + * Given an array type, return a list of good or bad examples, * depending on the value of the second parameter. */ private List synthesizeExamples(ArrayType type, boolean correct) { - Map> values = correct ? primitiveTypeToKnownGood - : primitiveTypeToKnownBad; + Map> values = correct ? primitiveTypeToKnownGood : primitiveTypeToKnownBad; List examples = new LinkedList<>(); if (correct) { // Produce an array that has an entry for each value. @@ -1119,9 +1592,9 @@ private List synthesizeExamples(ArrayType type, boolean correct) { } return examples; } - + /** - * Given an union type, return a list of good or bad examples, + * Given an union type, return a list of good or bad examples, * depending on the value of the second parameter. */ private List synthesizeExamples(UnionType type, boolean correct) { @@ -1137,15 +1610,15 @@ private List synthesizeExamples(UnionType type, boolean correct) { } else { // Return some obviously bad examples for the common // case where the options are from an ordinary Enum. - if (!type.options.stream().anyMatch(it -> it instanceof TargetPropertyType)) { + if (!type.options.stream().anyMatch(it -> (it instanceof TargetPropertyType))) { return List.of("foo", "\"bar\"", "1", "-1", "{x: 42}", "[1, 2, 3]"); } } return examples; } - + /** - * Given an union type, return a list of good or bad examples, + * Given an union type, return a list of good or bad examples, * depending on the value of the second parameter. */ private List synthesizeExamples(DictionaryType type, boolean correct) { @@ -1153,8 +1626,7 @@ private List synthesizeExamples(DictionaryType type, boolean correct) { // Produce a set of singleton dictionaries. // If incorrect examples are wanted, garble the key. for (DictionaryElement option : type.options) { - synthesizeExamples(option.getType(), correct).forEach(it -> examples.add( - "{" + option + (!correct ? "iamwrong: " : ": ") + it + "}")); + synthesizeExamples(option.getType(), correct).forEach(it -> examples.add("{" + option + (!correct ? "iamwrong: " : ": ") + it + "}")); } return examples; } @@ -1177,24 +1649,23 @@ private List synthesizeExamples(StringDictionaryType type, boolean corre } return examples; } - + /** * Synthesize a list of values that either conform to the given type or * do not, depending on whether the second argument 'correct' is true. - * Return an empty set if it is too complicated to generate examples + * Return an empty set if it is too complicated to generate examples * (e.g., because the resulting errors are more sophisticated). - *

+ * * Not all cases are covered by this function. Currently, the only cases not * covered are known bad examples for composite types, which should be added * to the compositeTypeToKnownBad map. - * + * * @param correct True to synthesize correct examples automatically, otherwise - * synthesize incorrect examples. + * synthesize incorrect examples. */ private List synthesizeExamples(TargetPropertyType type, boolean correct) { if (type instanceof PrimitiveType) { - Map> values = correct ? primitiveTypeToKnownGood - : primitiveTypeToKnownBad; + Map> values = correct ? primitiveTypeToKnownGood : primitiveTypeToKnownBad; List examples = values.get(type); Assertions.assertNotNull(examples); return examples; @@ -1213,21 +1684,29 @@ private List synthesizeExamples(TargetPropertyType type, boolean correct } return new LinkedList<>(); } - + /** * Create an LF program with the given key and value as a target property, * parse it, and return the resulting model. */ private Model createModel(TargetProperty key, String value) throws Exception { String target = key.supportedBy.get(0).getDisplayName(); - System.out.printf("%s: %s%n", key, value); - return parseWithoutError(""" - target %s {%s: %s}; - reactor Y {} - main reactor { - y = new Y() - } - """.formatted(target, key, value)); + System.out.println(String.format("%s: %s", key, value)); +// Java 17: +// Model model = """ +// target %s {%s: %s}; +// reactor Y {} +// main reactor { +// y = new Y() +// } +// """.formatted(target, key, value); +// Java 11: + return parseWithoutError(String.join(System.getProperty("line.separator"), + String.format("target %s {%s: %s};", target, key, value), + "reactor Y {}", + "main reactor {", + " y = new Y() ", + "}")); } /** @@ -1240,21 +1719,21 @@ public void checkTargetProperties() throws Exception { // we test that separately as it has better error messages return; } - System.out.printf("Testing target property %s which is %s%n", prop, prop.type); + System.out.println(String.format("Testing target property %s which is %s", prop, prop.type)); System.out.println("===="); System.out.println("Known good assignments:"); List knownCorrect = synthesizeExamples(prop.type, true); - + for (String it : knownCorrect) { Model model = createModel(prop, it); validator.assertNoErrors(model); // Also make sure warnings are produced when files are not present. if (prop.type == PrimitiveType.FILE) { validator.assertWarning(model, LfPackage.eINSTANCE.getKeyValuePair(), - null, String.format("Could not find file: '%s'.", StringUtil.removeQuotes(it))); + null, String.format("Could not find file: '%s'.", StringUtil.removeQuotes(it))); } } - + // Extra checks for filenames. (This piece of code was commented out in the original xtend file) // Temporarily disabled because we need a more sophisticated check that looks for files in different places. // if (prop.type == prop.type == ArrayType.FILE_ARRAY || @@ -1267,35 +1746,35 @@ public void checkTargetProperties() throws Exception { // null, '''Could not find file: '«it.withoutQuotes»'.''') // ] // } - + System.out.println("Known bad assignments:"); List knownIncorrect = synthesizeExamples(prop.type, false); if (!(knownIncorrect == null || knownIncorrect.isEmpty())) { for (String it : knownIncorrect) { if (prop.type instanceof StringDictionaryType) { validator.assertError(createModel(prop, it), - LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s.", prop), "' is required to be a string."); + LfPackage.eINSTANCE.getKeyValuePair(), null, + String.format("Target property '%s.", prop), "' is required to be a string."); } else { validator.assertError(createModel(prop, it), - LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s' is required to be %s.", prop, prop.type)); + LfPackage.eINSTANCE.getKeyValuePair(), null, + String.format("Target property '%s' is required to be %s.", prop.toString(), prop.type)); } } } else { // No type was synthesized. It must be a composite type. List> list = compositeTypeToKnownBad.get(prop.type); if (list == null) { - System.out.printf("No known incorrect values provided for target property '%s'. Aborting test.%n", prop); - Assertions.fail(); + System.out.println(String.format("No known incorrect values provided for target property '%s'. Aborting test.", prop)); + Assertions.assertTrue(false); } else { for (List it : list) { validator.assertError(createModel(prop, it.get(0).toString()), LfPackage.eINSTANCE.getKeyValuePair(), null, - String.format("Target property '%s%s' is required to be %s.", prop, it.get(1), it.get(2))); + String.format("Target property '%s%s' is required to be %s.", prop.toString(), it.get(1), it.get(2))); } } - } + } System.out.println("===="); } System.out.println("Done!"); @@ -1314,7 +1793,7 @@ public void checkCargoDependencyProperty() throws Exception { validator.assertError(createModel(prop, "{ dep: {/*empty*/} }"), LfPackage.eINSTANCE.getKeyValuePairs(), null, "Must specify one of 'version', 'path', or 'git'" ); - + // vvvvvvvvvvv validator.assertError(createModel(prop, "{ dep: { unknown_key: \"\"} }"), LfPackage.eINSTANCE.getKeyValuePair(), null, "Unknown key: 'unknown_key'" @@ -1405,228 +1884,358 @@ public void testUnusedImport() throws Exception { @Test public void testMissingInputType() throws Exception { - String testCase = """ - target C; - main reactor { - input i; - } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor { + // input i; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " input i;", + "}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Input must have a type."); } @Test public void testMissingOutputType() throws Exception { - String testCase = """ - target C; - main reactor { - output i; - } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor { + // output i; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " output i;", + "}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Output must have a type."); } @Test public void testMissingStateType() throws Exception { - String testCase = """ - target C; - main reactor { - state i; - } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor { + // state i; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " state i;", + "}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, "State must have a type."); } @Test public void testListWithParam() throws Exception { - String testCase = """ - target C; - main reactor (A:int(1)) { state i:int(A, 2, 3) } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor (A:int(1)) { state i:int(A, 2, 3) } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor (A:int(1)) { state i:int(A, 2, 3) }" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, "List items cannot refer to a parameter."); } @Test public void testCppMutableInput() throws Exception { - String testCase = """ - target Cpp; - main reactor { - mutable input i:int; - } - """; + // Java 17: + // String testCase = """ + // target Cpp; + // main reactor { + // mutable input i:int; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target Cpp;", + "main reactor {", + " mutable input i:int;", + "}" + ); validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "The mutable qualifier has no meaning for the C++ target and should be removed. " + - "In C++, any value can be made mutable by calling get_mutable_copy()."); + "In C++, any value can be made mutable by calling get_mutable_copy()."); } @Test public void testOverflowingSTP() throws Exception { - String testCase = """ - target C; - main reactor { - reaction(startup) {==} STP(2147483648) {==} - } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor { + // reaction(startup) {==} STP(2147483648) {==} + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " reaction(startup) {==} STP(2147483648) {==}", + "}" + ); // TODO: Uncomment and fix failing test. See issue #903 on Github. // validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getSTP(), null, - // "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + // "STP offset exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); } @Test public void testOverflowingDeadline() throws Exception { - String testCase = """ - target C; - main reactor { - reaction(startup) {==} STP(2147483648) {==} - } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor { + // reaction(startup) {==} STP(2147483648) {==} + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " reaction(startup) {==} deadline(2147483648) {==}", + "}" + ); // TODO: Uncomment and fix failing test. See issue #903 on Github. // validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getDeadline(), null, - // "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); + // "Deadline exceeds the maximum of " + TimeValue.MAX_LONG_DEADLINE + " nanoseconds."); } @Test public void testInvalidTargetParam() throws Exception { - String testCase = """ - target C { beefyDesktop: true } - main reactor {} - """; + // Java 17: + // String testCase = """ + // target C { beefyDesktop: true } + // main reactor {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C { beefyDesktop: true }", + "main reactor {}" + ); List issues = validator.validate(parseWithoutError(testCase)); - Assertions.assertTrue(issues.size() == 1 - && issues.get(0).getMessage().contains("Unrecognized target parameter: beefyDesktop")); + Assertions.assertTrue(issues.size() == 1 && issues.get(0).getMessage().contains("Unrecognized target parameter: beefyDesktop")); } @Test public void testTargetParamNotSupportedForTarget() throws Exception { - String testCase = """ - target Python { build: "" } - main reactor {} - """; + // Java 17: + // String testCase = """ + // target Python { build: "" } + // main reactor {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target Python { build: \"\" }", + "main reactor {}" + ); List issues = validator.validate(parseWithoutError(testCase)); - Assertions.assertTrue(issues.size() == 1 && issues.get(0).getMessage().contains( - "The target parameter: build" + - " is not supported by the Python target and will thus be ignored.")); + Assertions.assertTrue(issues.size() == 1 && issues.get(0).getMessage().contains("The target parameter: build" + + " is not supported by the Python target and will thus be ignored.")); } @Test public void testUnnamedReactor() throws Exception { - String testCase = """ - target C; - reactor {} - """; + // Java 17: + // String testCase = """ + // target C; + // reactor {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "reactor {}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Reactor must be named."); } @Test public void testMainHasInput() throws Exception { - String testCase = """ - target C; - main reactor { - input x:int; - } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor { + // input x:int; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " input x:int;", + "}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Main reactor cannot have inputs."); } @Test public void testFederatedHasInput() throws Exception { - - String testCase = """ - target C; - federated reactor { - input x:int; - } - """; + // Java 17: + // String testCase = """ + // target C; + // federated reactor { + // input x:int; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "federated reactor {", + " input x:int;", + "}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInput(), null, "Main reactor cannot have inputs."); } @Test public void testMainHasOutput() throws Exception { - - String testCase = """ - target C; - main reactor { - output x:int; - } - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor { + // output x:int; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {", + " output x:int;", + "}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Main reactor cannot have outputs."); } @Test public void testFederatedHasOutput() throws Exception { - - String testCase = """ - target C; - federated reactor { - output x:int; - } - """; + // Java 17: + // String testCase = """ + // target C; + // federated reactor { + // output x:int; + // } + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "federated reactor {", + " output x:int;", + "}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getOutput(), null, "Main reactor cannot have outputs."); } @Test public void testMultipleMainReactor() throws Exception { - - String testCase = """ - target C; - main reactor A {} - main reactor A {} - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor A {} + // main reactor A {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor A {}", + "main reactor A {}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMultipleMainReactorUnnamed() throws Exception { - - String testCase = """ - target C; - main reactor {} - main reactor {} - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor {} + // main reactor {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor {}", + "main reactor {}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMultipleFederatedReactor() throws Exception { - String testCase = """ - target C; - federated reactor A {} - federated reactor A {} - """; + // Java 17: + // String testCase = """ + // target C; + // federated reactor A {} + // federated reactor A {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "federated reactor A {}", + "federated reactor A {}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMultipleMainOrFederatedReactor() throws Exception { - - String testCase = """ - target C; - federated reactor A {} - federated reactor A {} - """; + // Java 17: + // String testCase = """ + // target C; + // federated reactor A {} + // federated reactor A {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor A {}", + "federated reactor A {}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, "Multiple definitions of main or federated reactor."); } @Test public void testMainReactorHasHost() throws Exception { - String testCase = """ - target C; - main reactor at 127.0.0.1{} - """; + // Java 17: + // String testCase = """ + // target C; + // main reactor at 127.0.0.1{} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target C;", + "main reactor at 127.0.0.1{}" + ); // TODO: Uncomment and fix test // List issues = validator.validate(parseWithoutError(testCase)); // Assertions.assertTrue(issues.size() == 1 && @@ -1636,11 +2245,16 @@ public void testMainReactorHasHost() throws Exception { @Test public void testUnrecognizedTarget() throws Exception { - - String testCase = """ - target Pjthon; - main reactor {} - """; + // Java 17: + // String testCase = """ + // target Pjthon; + // main reactor {} + // """ + // Java 11: + String testCase = String.join(System.getProperty("line.separator"), + "target Pjthon;", + "main reactor {}" + ); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTargetDecl(), null, "Unrecognized target: Pjthon"); } @@ -1682,132 +2296,132 @@ public void testWrongParamType() throws Exception { @Test public void testInitialMode() throws Exception { String testCase = """ - target C; - main reactor { - mode M {} - } - """; + target C; + main reactor { + mode M {} + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "Every modal reactor requires one initial mode."); + "Every modal reactor requires one initial mode."); } @Test public void testInitialModes() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM1 {} - initial mode IM2 {} - } - """; + target C; + main reactor { + initial mode IM1 {} + initial mode IM2 {} + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getReactor(), null, - "A modal reactor can only have one initial mode."); + "A modal reactor can only have one initial mode."); } @Test public void testModeStateNamespace() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - state s:int; - } - mode M { - state s:int; - } + target C; + main reactor { + initial mode IM { + state s:int; } - """; + mode M { + state s:int; + } + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, - "Duplicate state variable 's'. (State variables are currently scoped on reactor level not modes)"); + "Duplicate state variable 's'. (State variables are currently scoped on reactor level not modes)"); } @Test public void testModeTimerNamespace() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - timer t; - } - mode M { - timer t; - } + target C; + main reactor { + initial mode IM { + timer t; } - """; + mode M { + timer t; + } + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, - "Duplicate Timer 't'. (Timers are currently scoped on reactor level not modes)"); + "Duplicate Timer 't'. (Timers are currently scoped on reactor level not modes)"); } @Test public void testModeActionNamespace() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - logical action a; - } - mode M { - logical action a; - } + target C; + main reactor { + initial mode IM { + logical action a; } - """; + mode M { + logical action a; + } + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getAction(), null, - "Duplicate Action 'a'. (Actions are currently scoped on reactor level not modes)"); + "Duplicate Action 'a'. (Actions are currently scoped on reactor level not modes)"); } @Test public void testModeInstanceNamespace() throws Exception { String testCase = """ - target C; - reactor R {} - main reactor { - initial mode IM { - r = new R(); - } - mode M { - r = new R(); - } + target C; + reactor R {} + main reactor { + initial mode IM { + r = new R(); } - """; + mode M { + r = new R(); + } + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getInstantiation(), null, - "Duplicate Instantiation 'r'. (Instantiations are currently scoped on reactor level not modes)"); + "Duplicate Instantiation 'r'. (Instantiations are currently scoped on reactor level not modes)"); } @Test public void testMissingModeStateReset() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - reaction(startup) -> M {==} - } - mode M { - state s:int(0); - } + target C; + main reactor { + initial mode IM { + reaction(startup) -> M {==} } - """; + mode M { + state s:int(0); + } + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getMode(), null, - "State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction."); + "State variable is not reset upon mode entry. It is neither marked for automatic reset nor is there a reset reaction."); } @Test public void testMissingModeStateResetInstance() throws Exception { String testCase = """ - target C; - reactor R { - state s:int(0); + target C; + reactor R { + state s:int(0); + } + main reactor { + initial mode IM { + reaction(startup) -> M {==} } - main reactor { - initial mode IM { - reaction(startup) -> M {==} - } - mode M { - r = new R(); - } + mode M { + r = new R(); } - """; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getMode(), null, - "This reactor contains state variables that are not reset upon mode entry: " + "This reactor contains state variables that are not reset upon mode entry: " + "s in R" + ".\nThe state variables are neither marked for automatic reset nor have a dedicated reset reaction. " + "It is usafe to instatiate this reactor inside a mode entered with reset."); @@ -1816,13 +2430,13 @@ public void testMissingModeStateResetInstance() throws Exception { @Test public void testModeStateResetWithoutInitialValue() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - reset state s:int; - } + target C; + main reactor { + initial mode IM { + reset state s:int; } - """; + } + """; validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getStateVar(), null, "The state variable can not be automatically reset without an initial value."); } @@ -1830,18 +2444,18 @@ public void testModeStateResetWithoutInitialValue() throws Exception { @Test public void testUnspecifiedTransitionType() throws Exception { String testCase = """ - target C; - main reactor { - initial mode IM { - reaction(startup) -> M {==} - } - mode M { - reset state s:int(0); - } + target C; + main reactor { + initial mode IM { + reaction(startup) -> M {==} } - """; + mode M { + reset state s:int(0); + } + } + """; validator.assertWarning(parseWithoutError(testCase), LfPackage.eINSTANCE.getReaction(), null, - "You should specifiy a transition type! " + "You should specifiy a transition type! " + "Reset and history transitions have different effects on this target mode. " + "Currently, a reset type is implicitly assumed."); } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java index 24cb3554ff..d1ea81e5be 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java @@ -3,7 +3,6 @@ import static java.util.Collections.emptyList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.fail; import java.nio.file.Files; import java.nio.file.Path; @@ -29,15 +28,11 @@ public class RoundTripTests { @Test - public void roundTripTest() { + public void roundTripTest() throws Exception { for (Target target : Target.values()) { for (TestCategory category : TestCategory.values()) { for (LFTest test : TestRegistry.getRegisteredTests(target, category, false)) { - try { - run(test.getSrcPath()); - } catch (Throwable thrown) { - fail("Test case " + test.getSrcPath() + " failed", thrown); - } + run(test.getSrcPath()); } } } diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java b/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java deleted file mode 100644 index 593e302d25..0000000000 --- a/org.lflang.tests/src/org/lflang/tests/compiler/TargetConfigTests.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.lflang.tests.compiler; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import java.nio.file.Files; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtext.generator.JavaIoFileSystemAccess; -import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.extensions.InjectionExtension; -import org.eclipse.xtext.testing.util.ParseHelper; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.lflang.federated.generator.FedFileConfig; -import org.lflang.generator.GeneratorUtils; -import org.lflang.generator.LFGenerator; -import org.lflang.generator.LFGeneratorContext.Mode; -import org.lflang.generator.MainContext; -import org.lflang.lf.Model; -import org.lflang.tests.LFInjectorProvider; - -@ExtendWith(InjectionExtension.class) -@InjectWith(LFInjectorProvider.class) - -/** - * Tests for checking that target properties adequately translate into the target configuration. - */ -class TargetConfigTests { - - @Inject - ParseHelper parser; - - @Inject - LFGenerator generator; - - @Inject - JavaIoFileSystemAccess fileAccess; - - @Inject - Provider resourceSetProvider; - - private void assertHasTargetProperty(Model model, String name) { - Assertions.assertNotNull(model); - Assertions.assertTrue( - model.getTarget().getConfig().getPairs().stream().anyMatch( - p -> p.getName().equals(name) - ) - ); - } - - /** - * Check that tracing target property affects the target configuration. - * @throws Exception - */ - @Test - public void testParsing() throws Exception { - assertHasTargetProperty(parser.parse(""" - target C { - tracing: true - } - """), "tracing"); - } - - /** - * Check that when a federation has the "tracing" target property set, the generated federates - * will also have it set. - * @throws Exception - */ - @Test - public void testFederation() throws Exception { - fileAccess.setOutputPath("src-gen"); - - Model federation = parser.parse(""" - target C { - tracing: true - } - reactor Foo { - - } - federated reactor { - a = new Foo() - b = new Foo() - } - """, URI.createFileURI("tmp/src/Federation.lf"), resourceSetProvider.get()); - assertHasTargetProperty(federation, "tracing"); - - var resource = federation.eResource(); - var context = new MainContext(Mode.STANDALONE, resource, fileAccess, () -> false); - - if (GeneratorUtils.isHostWindows()) return; - - generator.doGenerate(resource, fileAccess, context); - - String lfSrc = Files.readAllLines( - ((FedFileConfig)context.getFileConfig()).getSrcPath().resolve("a.lf") - ).stream().reduce("\n", String::concat); - Model federate = parser.parse(lfSrc); - assertHasTargetProperty(federate, "tracing"); - } -} diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index b48bf1fc59..4f78b42ac8 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b48bf1fc59665ccf22e9f6fb7da93a31d046d090 +Subproject commit 4f78b42ac806c113aed0ecd6510e56a20c049b61 diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index e80cd36ce5..a37f0ade9e 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 +Subproject commit a37f0ade9ee0f97606528fd7ba67712495948373 diff --git a/org.lflang/src/lib/ts/package.json b/org.lflang/src/lib/ts/package.json index a1d65a6403..3c368c9481 100644 --- a/org.lflang/src/lib/ts/package.json +++ b/org.lflang/src/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", + "@lf-lang/reactor-ts": "0.3.2", "@babel/cli": "^7.8.4", "@babel/core": "^7.8.7", "@babel/node": "^7.8.7", diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 2be5f2970f..fe6fdfeb2b 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -251,14 +251,6 @@ public static boolean changeTargetName(Resource resource, String newTargetName) return true; } - /** - * Return the target of the file in which the given node lives. - */ - public static Target getTarget(EObject object) { - TargetDecl targetDecl = targetDecl(object.eResource()); - return Target.fromDecl(targetDecl); - } - /** * Add a new target property to the given resource. * @@ -789,7 +781,7 @@ public static Element toElement(int val) { /** * Translate the given type into its textual representation, but - * do not append any array specifications or type arguments. + * do not append any array specifications. * @param type AST node to render as string. * @return Textual representation of the given argument. */ @@ -801,12 +793,18 @@ public static String baseType(Type type) { if (type.isTime()) { return "time"; } else { - StringBuilder result = new StringBuilder(type.getId()); - - for (String s : convertToEmptyListIfNull(type.getStars())) { - result.append(s); + StringBuilder stars = new StringBuilder(); + List iterList = convertToEmptyListIfNull(type.getStars()); + for (String s : iterList) { + stars.append(s); + } + if (!IterableExtensions.isNullOrEmpty(type.getTypeParms())) { + List typeParamsStr = new ArrayList<>(); + type.getTypeParms().forEach(it -> typeParamsStr.add(toText(it))); + return String.format("%s<%s>", type.getId(), String.join(", ", typeParamsStr)); + } else { + return type.getId() + stars; } - return result.toString(); } } } diff --git a/org.lflang/src/org/lflang/InferredType.java b/org.lflang/src/org/lflang/InferredType.java index 3a9a8712aa..d035f2f05e 100644 --- a/org.lflang/src/org/lflang/InferredType.java +++ b/org.lflang/src/org/lflang/InferredType.java @@ -126,8 +126,7 @@ private String toTextHelper(Function toText) { } /** - * Convert the inferred type to its textual representation - * while ignoring any list qualifiers or type arguments. + * Convert the inferred type to its textual representation while ignoring any list qualifiers. * * @return Textual representation of this inferred type without list qualifiers */ diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 8aa7bf99b0..dfa604d7cd 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -139,7 +139,7 @@ TargetDecl: Initializer: parens?='(' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? ')' | braces?='{' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? '}' - | assign?='=' exprs+=Expression +// | assign?='=' exprs+=Expression // todo later ; @@ -223,7 +223,7 @@ Preamble: Instantiation: (attributes+=Attribute)* name=ID '=' 'new' (widthSpec=WidthSpec)? - reactorClass=[ReactorDecl] ('<' typeArgs+=Type (',' typeArgs+=Type)* '>')? '(' + reactorClass=[ReactorDecl] ('<' typeParms+=TypeParm (',' typeParms+=TypeParm)* '>')? '(' (parameters+=Assignment (',' parameters+=Assignment)*)? ')' (('at' host=Host ';') | ';'?); @@ -285,15 +285,13 @@ VarRefOrModeTransition returns VarRef: Assignment: lhs=[Parameter] - rhs=AssignmentInitializer + (equals='=')? rhs=AssignmentInitializer ; +// TODO Only allow = based parameter assignment AssignmentInitializer returns Initializer: - assign?='=' exprs+=Expression - // these syntaxes are legacy and now deprecated - // todo remove in future version. - | '='? parens?='(' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? ')' - // note: the previous syntax `= { expr* }` is now parsed as a BracedListExpression + exprs+=Expression + | parens?='(' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? ')' | braces?='{' (exprs+=Expression (',' exprs+=Expression)* (trailingComma?=',')?)? '}' ; @@ -312,13 +310,6 @@ Expression: | Time | ParameterReference | {CodeExpr} code=Code - | BracedListExpression -; - -// A list of expressions within braces. -// In C/C++, this is an array initializer, struct initializer, or std::initializer_list. -BracedListExpression: - '{' {BracedListExpression} (items+=Expression (',' items+=Expression)*)? ','? '}' ; ParameterReference: @@ -335,7 +326,7 @@ Port: // A type is in the target language, hence either an ID or target code. Type: time?='time' (arraySpec=ArraySpec)? - | id=DottedName ('<' typeArgs+=Type (',' typeArgs+=Type)* '>')? (stars+='*')* (arraySpec=ArraySpec)? + | id=DottedName ('<' typeParms+=Type (',' typeParms+=Type)* '>')? (stars+='*')* (arraySpec=ArraySpec)? | code=Code ; diff --git a/org.lflang/src/org/lflang/Target.java b/org.lflang/src/org/lflang/Target.java index 11247b6648..4842bc1672 100644 --- a/org.lflang/src/org/lflang/Target.java +++ b/org.lflang/src/org/lflang/Target.java @@ -486,7 +486,9 @@ public boolean supportsMultiports() { * on constants). */ public boolean supportsParameterizedWidths() { - return true; + return switch (this) { + case C, CCPP, CPP, Python, Rust, TS -> true; + }; } /** @@ -500,20 +502,6 @@ public boolean buildsUsingDocker() { }; } - /** - * Whether the target requires using an equal sign to assign a default value to a parameter, - * or initialize a state variable. All targets mandate an equal sign when passing - * arguments to a reactor constructor call, regardless of this method. - */ - public boolean mandatesEqualsInitializers() { - return this != CPP; - } - - /** Allow expressions of the form {@code {a, b, c}}. */ - public boolean allowsBracedListExpressions() { - return this == C || this == CCPP || this == CPP; - } - /** * Return a string that demarcates the beginning of a single-line comment. */ diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 23e99541da..446460d5c1 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Properties; import java.util.Set; import org.lflang.TargetProperty.BuildType; @@ -39,9 +38,7 @@ import org.lflang.TargetProperty.LogLevel; import org.lflang.TargetProperty.Platform; import org.lflang.TargetProperty.SchedulerOption; -import org.lflang.TargetProperty.UnionType; import org.lflang.generator.rust.RustTargetConfig; -import org.lflang.lf.KeyValuePair; import org.lflang.lf.TargetDecl; /** @@ -53,92 +50,12 @@ */ public class TargetConfig { - /** - * The target of this configuration (e.g., C, TypeScript, Python). - */ public final Target target; - /** - * Create a new target configuration based on the given target declaration AST node only. - * @param target AST node of a target declaration. - */ - public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if we can + public TargetConfig(TargetDecl target) { this.target = Target.fromDecl(target); } - /** - * Create a new target configuration based on the given commandline arguments and target - * declaration AST node. - * @param cliArgs Arguments passed on the commandline. - * @param target AST node of a target declaration. - * @param errorReporter An error reporter to report problems. - */ - public TargetConfig( - Properties cliArgs, - TargetDecl target, - ErrorReporter errorReporter - ) { - this(target); - if (target.getConfig() != null) { - List pairs = target.getConfig().getPairs(); - TargetProperty.set(this, pairs != null ? pairs : List.of(), errorReporter); - } - if (cliArgs.containsKey("no-compile")) { - this.noCompile = true; - } - if (cliArgs.containsKey("docker")) { - var arg = cliArgs.getProperty("docker"); - if (Boolean.parseBoolean(arg)) { - this.dockerOptions = new DockerOptions(); - } else { - this.dockerOptions = null; - } - // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. - } - if (cliArgs.containsKey("build-type")) { - this.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION.forName(cliArgs.getProperty("build-type")); - } - if (cliArgs.containsKey("logging")) { - this.logLevel = LogLevel.valueOf(cliArgs.getProperty("logging").toUpperCase()); - } - if (cliArgs.containsKey("workers")) { - this.workers = Integer.parseInt(cliArgs.getProperty("workers")); - } - if (cliArgs.containsKey("threading")) { - this.threading = Boolean.parseBoolean(cliArgs.getProperty("threading")); - } - if (cliArgs.containsKey("target-compiler")) { - this.compiler = cliArgs.getProperty("target-compiler"); - } - if (cliArgs.containsKey("tracing")) { - this.tracing = new TracingOptions(); - } - if (cliArgs.containsKey("scheduler")) { - this.schedulerType = SchedulerOption.valueOf( - cliArgs.getProperty("scheduler") - ); - this.setByUser.add(TargetProperty.SCHEDULER); - } - if (cliArgs.containsKey("target-flags")) { - this.compilerFlags.clear(); - if (!cliArgs.getProperty("target-flags").isEmpty()) { - this.compilerFlags.addAll(List.of( - cliArgs.getProperty("target-flags").split(" ") - )); - } - } - if (cliArgs.containsKey("runtime-version")) { - this.runtimeVersion = cliArgs.getProperty("runtime-version"); - } - if (cliArgs.containsKey("external-runtime-path")) { - this.externalRuntimePath = cliArgs.getProperty("external-runtime-path"); - } - if (cliArgs.containsKey(TargetProperty.KEEPALIVE.description)) { - this.keepalive = Boolean.parseBoolean( - cliArgs.getProperty(TargetProperty.KEEPALIVE.description)); - } - } - /** * Keep track of every target property that is explicitly set by the user. */ @@ -280,6 +197,9 @@ public TargetConfig( * * This is now a wrapped class to account for overloaded definitions * of defining platform (either a string or dictionary of values) + * + * @author Samuel Berkun + * @author Anirudh Rengarajan */ public PlatformOptions platformOptions = new PlatformOptions(); @@ -373,7 +293,7 @@ public static class ClockSyncOptions { public int attenuation = 10; /** - * Whether to collect statistics while performing clock synchronization. + * Whether or not to collect statistics while performing clock synchronization. * This setting is only considered when clock synchronization has been activated. * The default is true. */ diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 1bacb1f75e..f0de831bf4 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -383,6 +383,10 @@ public enum TargetProperty { (config, value, err) -> { config.logLevel = (LogLevel) UnionType.LOGGING_UNION .forName(ASTUtils.elementToSingleString(value)); + }, + (config, value, err) -> { + config.logLevel = (LogLevel) UnionType.LOGGING_UNION + .forName(ASTUtils.elementToSingleString(value)); }), /** @@ -576,7 +580,8 @@ public enum TargetProperty { }), /** - * Directive to enable tracing. + * Directive to generate a Dockerfile. This is either a boolean, + * true or false, or a dictionary of options. */ TRACING("tracing", UnionType.TRACING_UNION, Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Python), @@ -969,7 +974,7 @@ public static TargetDecl extractTargetDecl(Target target, TargetConfig config) { * @param config The configuration object to update. * @param properties AST node that holds all the target properties. */ - public static void update(TargetConfig config, List properties, ErrorReporter err) { + public static void update(TargetConfig config, List properties,ErrorReporter err) { properties.forEach(property -> { TargetProperty p = forName(property.getName()); if (p != null) { diff --git a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java index 85793084d3..ea16bfc96a 100644 --- a/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java +++ b/org.lflang/src/org/lflang/ast/DelayedConnectionTransformation.java @@ -21,7 +21,6 @@ import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Assignment; -import org.lflang.lf.Code; import org.lflang.lf.Connection; import org.lflang.lf.Expression; import org.lflang.lf.Initializer; @@ -114,9 +113,7 @@ private void insertGeneratedDelays(List reactors) { // Assume all the types are the same, so just use the first on the right. Type type = ((Port) connection.getRightPorts().get(0).getVariable()).getType(); Reactor delayClass = getDelayClass(type, connection.isPhysical()); - String generic = targetTypes.supportsGenerics() - ? targetTypes.getTargetType(type) : null; - + String generic = targetTypes.supportsGenerics() ? targetTypes.getTargetType(InferredType.fromAST(type)) : ""; Instantiation delayInstance = getDelayInstance(delayClass, connection, generic, !generator.generateAfterDelaysWithVariableWidth(), connection.isPhysical()); @@ -212,7 +209,7 @@ private static List rerouteViaDelay(Connection connection, * modification exceptions. * @param delayClass The class to create an instantiation for * @param connection The connection to create a delay instantiation foe - * @param genericArg A string that denotes the appropriate type parameter, + * @param generic A string that denotes the appropriate type parameter, * which should be null or empty if the target does not support generics. * @param defineWidthFromConnection If this is true and if the connection * is a wide connection, then instantiate a bank of delays where the width @@ -223,15 +220,13 @@ private static List rerouteViaDelay(Connection connection, * we will accept zero delay on the connection. */ private static Instantiation getDelayInstance(Reactor delayClass, - Connection connection, String genericArg, Boolean defineWidthFromConnection, Boolean isPhysical) { + Connection connection, String generic, Boolean defineWidthFromConnection, Boolean isPhysical) { Instantiation delayInstance = factory.createInstantiation(); delayInstance.setReactorClass(delayClass); - if (genericArg != null) { - Code code = factory.createCode(); - code.setBody(genericArg); - Type type = factory.createType(); - type.setCode(code); - delayInstance.getTypeArgs().add(type); + if (!StringExtensions.isNullOrEmpty(generic)) { + TypeParm typeParm = factory.createTypeParm(); + typeParm.setLiteral(generic); + delayInstance.getTypeParms().add(typeParm); } if (ASTUtils.hasMultipleConnections(connection)) { WidthSpec widthSpec = factory.createWidthSpec(); diff --git a/org.lflang/src/org/lflang/ast/FormattingUtils.java b/org.lflang/src/org/lflang/ast/FormattingUtils.java index 0e148f218b..bd9fbaf3d8 100644 --- a/org.lflang/src/org/lflang/ast/FormattingUtils.java +++ b/org.lflang/src/org/lflang/ast/FormattingUtils.java @@ -55,8 +55,8 @@ public static String render(EObject object, int lineLength) { } /** Return a function that renders AST nodes for the given target. */ - public static Function renderer(Target target) { - return object -> render(object, DEFAULT_LINE_LENGTH, target, true); + public static Function renderer(TargetDecl targetDecl) { + return object -> render(object, DEFAULT_LINE_LENGTH, Target.fromDecl(targetDecl), true); } /** diff --git a/org.lflang/src/org/lflang/ast/IsEqual.java b/org.lflang/src/org/lflang/ast/IsEqual.java index 33733a3314..b4614edcf0 100644 --- a/org.lflang/src/org/lflang/ast/IsEqual.java +++ b/org.lflang/src/org/lflang/ast/IsEqual.java @@ -16,7 +16,6 @@ import org.lflang.lf.Assignment; import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; -import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.Code; import org.lflang.lf.CodeExpr; @@ -333,7 +332,7 @@ public Boolean caseInstantiation(Instantiation object) { .equalAsObjects(Instantiation::getName) .equivalent(Instantiation::getWidthSpec) .equivalent(Instantiation::getReactorClass) - .listsEquivalent(Instantiation::getTypeArgs) + .listsEquivalent(Instantiation::getTypeParms) .listsEquivalent(Instantiation::getParameters) .equivalent(Instantiation::getHost) .conclusion; @@ -416,6 +415,7 @@ public Boolean caseVarRef(VarRef object) { public Boolean caseAssignment(Assignment object) { return new ComparisonMachine<>(object, Assignment.class) .equivalent(Assignment::getLhs) + .equalAsObjects(Assignment::getEquals) .equivalent(Assignment::getRhs) .conclusion; } @@ -437,18 +437,10 @@ public Boolean caseExpression(Expression object) { Literal.class, Time.class, ParameterReference.class, - Code.class, - BracedListExpression.class + Code.class ); } - @Override - public Boolean caseBracedListExpression(BracedListExpression object) { - return new ComparisonMachine<>(object, BracedListExpression.class) - .listsEquivalent(BracedListExpression::getItems) - .conclusion; - } - @Override public Boolean caseParameterReference(ParameterReference object) { return new ComparisonMachine<>(object, ParameterReference.class) @@ -480,7 +472,7 @@ public Boolean caseType(Type object) { .equalAsObjects(Type::isTime) .equivalent(Type::getArraySpec) .equalAsObjects(Type::getId) - .listsEquivalent(Type::getTypeArgs) + .listsEquivalent(Type::getTypeParms) .listsEqualAsObjects(Type::getStars) .equivalent(Type::getArraySpec) .equivalent(Type::getCode) diff --git a/org.lflang/src/org/lflang/ast/ToLf.java b/org.lflang/src/org/lflang/ast/ToLf.java index 5c1deba96e..7582ee3a59 100644 --- a/org.lflang/src/org/lflang/ast/ToLf.java +++ b/org.lflang/src/org/lflang/ast/ToLf.java @@ -21,7 +21,6 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.xbase.lib.StringExtensions; import org.lflang.ASTUtils; -import org.lflang.Target; import org.lflang.ast.MalleableString.Builder; import org.lflang.ast.MalleableString.Joiner; import org.lflang.lf.Action; @@ -30,7 +29,6 @@ import org.lflang.lf.Assignment; import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; -import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.Code; import org.lflang.lf.CodeExpr; @@ -48,7 +46,6 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; -import org.lflang.lf.LfFactory; import org.lflang.lf.Literal; import org.lflang.lf.Method; import org.lflang.lf.MethodArgument; @@ -299,8 +296,8 @@ public MalleableString caseType(Type type) { msb.append("time"); } else if (type.getId() != null) { msb.append(type.getId()); // TODO: Multiline dottedName? - if (type.getTypeArgs() != null) { - msb.append(list(", ", "<", ">", true, false, type.getTypeArgs())); + if (type.getTypeParms() != null) { + msb.append(list(", ", "<", ">", true, false, type.getTypeParms())); } msb.append("*".repeat(type.getStars().size())); } @@ -479,7 +476,7 @@ public MalleableString caseStateVar(StateVar object) { } msb.append("state ").append(object.getName()); msb.append(typeAnnotationFor(object.getType())); - msb.append(initializer(object.getInit())); + msb.append(initializer(object.getInit(), true)); return msb.get(); } @@ -693,7 +690,7 @@ public MalleableString caseInstantiation(Instantiation object) { msb.append(object.getName()).append(" = new"); if (object.getWidthSpec() != null) msb.append(doSwitch(object.getWidthSpec())); msb.append(" ").append(object.getReactorClass().getName()); - msb.append(list(", ", "<", ">", true, false, object.getTypeArgs())); + msb.append(list(", ", "<", ">", true, false, object.getTypeParms())); msb.append(list(false, object.getParameters())); // TODO: Delete the following case when the corresponding feature is removed if (object.getHost() != null) msb.append(" at ").append(doSwitch(object.getHost())); @@ -760,9 +757,7 @@ public MalleableString caseSerializer(Serializer object) { @Override public MalleableString caseKeyValuePairs(KeyValuePairs object) { // {KeyValuePairs} '{' (pairs+=KeyValuePair (',' (pairs+=KeyValuePair))* ','?)? '}' - if (object.getPairs().isEmpty()) { - return MalleableString.anyOf(""); - } + if (object.getPairs().isEmpty()) return MalleableString.anyOf(""); return new Builder() .append("{\n") .append(list(",\n", "", "\n", true, true, object.getPairs()).indent()) @@ -770,16 +765,6 @@ public MalleableString caseKeyValuePairs(KeyValuePairs object) { .get(); } - @Override - public MalleableString caseBracedListExpression(BracedListExpression object) { - if (object.getItems().isEmpty()) { - return MalleableString.anyOf("{}"); - } - // Note that this strips the trailing comma. There is no way - // to implement trailing commas with the current set of list() methods AFAIU. - return list(", ", "{", "}", false, false, object.getItems()); - } - @Override public MalleableString caseKeyValuePair(KeyValuePair object) { // name=Kebab ':' value=Element @@ -834,52 +819,35 @@ public MalleableString caseAssignment(Assignment object) { // )); Builder msb = new Builder(); msb.append(object.getLhs().getName()); - msb.append(initializer(object.getRhs())); + if (object.getEquals() != null) { + msb.append(" = "); + } + msb.append(initializer(object.getRhs(), false)); return msb.get(); } @Override public MalleableString caseInitializer(Initializer object) { - return initializer(object); + return initializer(object, false); } - /** - * Return true if the initializer should be output with an equals initializer. - * Old-style assignments with parentheses are also output that - * way to help with the transition. - */ - private boolean shouldOutputAsAssignment(Initializer init) { - return init.isAssign() - || init.getExprs().size() == 1 && ASTUtils.getTarget(init).mandatesEqualsInitializers(); - } - - private MalleableString initializer(Initializer init) { + private MalleableString initializer(Initializer init, boolean nothingIfEmpty) { if (init == null) { return MalleableString.anyOf(""); } - if (shouldOutputAsAssignment(init)) { - Expression expr = ASTUtils.asSingleExpr(init); - Objects.requireNonNull(expr); - return new Builder().append(" = ").append(doSwitch(expr)).get(); - } - if (ASTUtils.getTarget(init) == Target.C) { - // This turns C array initializers into a braced expression. - // C++ variants are not converted. - BracedListExpression list = LfFactory.eINSTANCE.createBracedListExpression(); - list.getItems().addAll(init.getExprs()); - return new Builder().append(" = ").append(doSwitch(list)).get(); - } String prefix; String suffix; if (init.isBraces()) { prefix = "{"; suffix = "}"; - } else { - assert init.isParens(); + } else if (init.isParens()) { prefix = "("; suffix = ")"; + } else { + // unparenthesized parameter assignment. + prefix = suffix = ""; } - return list(", ", prefix, suffix, false, false, init.getExprs()); + return list(", ", prefix, suffix, nothingIfEmpty, false, init.getExprs()); } @@ -894,7 +862,7 @@ public MalleableString caseParameter(Parameter object) { return builder .append(object.getName()) .append(typeAnnotationFor(object.getType())) - .append(initializer(object.getInit())) + .append(initializer(object.getInit(), true)) .get(); } diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 0b703ccbe8..c97be28c8f 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -10,7 +10,6 @@ import org.lflang.ASTUtils; import org.lflang.lf.ArraySpec; -import org.lflang.lf.BracedListExpression; import org.lflang.lf.Code; import org.lflang.lf.CodeExpr; import org.lflang.lf.Host; @@ -79,11 +78,6 @@ public String caseCode(Code code) { return ""; } - @Override - public String caseBracedListExpression(BracedListExpression object) { - return ToLf.instance.caseBracedListExpression(object).toString(); - } - @Override public String caseHost(Host host) { return ToLf.instance.caseHost(host).toString(); @@ -106,10 +100,9 @@ public String caseTime(Time t) { @Override public String caseType(Type type) { - if (type.getCode() != null) { - return caseCode(type.getCode()); - } - return ToLf.instance.caseType(type).toString(); + String base = ASTUtils.baseType(type); + String arr = (type.getArraySpec() != null) ? doSwitch(type.getArraySpec()) : ""; + return base + arr; } @Override diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/src/org/lflang/cli/CliBase.java index b825d91966..21323c34b8 100644 --- a/org.lflang/src/org/lflang/cli/CliBase.java +++ b/org.lflang/src/org/lflang/cli/CliBase.java @@ -4,12 +4,22 @@ import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; import java.util.stream.Collectors; import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; +import picocli.CommandLine.Spec; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; @@ -23,6 +33,10 @@ import org.lflang.LFRuntimeModule; import org.lflang.LFStandaloneSetup; import org.lflang.util.FileUtil; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonParseException; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; @@ -36,15 +50,35 @@ * @author Atharva Patil */ public abstract class CliBase implements Runnable { + /** + * Models a command specification, including the options, positional + * parameters and subcommands supported by the command. + */ + @Spec CommandSpec spec; /** * Options and parameters present in both Lfc and Lff. */ - @Parameters( + static class MutuallyExclusive { + @Parameters( arity = "1..", paramLabel = "FILES", description = "Paths of the files to run Lingua Franca programs on.") - protected List files; + protected List files; + + @Option( + names="--json", + description="JSON object containing CLI arguments.") + private String jsonString; + + @Option( + names="--json-file", + description="JSON file containing CLI arguments.") + private Path jsonFile; + } + + @ArgGroup(exclusive = true, multiplicity = "1") + MutuallyExclusive topLevelArg; @Option( names = {"-o", "--output-path"}, @@ -76,13 +110,13 @@ public abstract class CliBase implements Runnable { */ @Inject protected Io io; - + /** * Injected resource provider. */ @Inject private Provider resourceSetProvider; - + /** * Injected resource validator. */ @@ -97,11 +131,7 @@ protected static void cliMain( // Main instance. final CliBase main = injector.getInstance(toolClass); // Parse arguments and execute main logic. - main.doExecute(io, args); - } - - public void doExecute(Io io, String[] args) { - CommandLine cmd = new CommandLine(this) + CommandLine cmd = new CommandLine(main) .setOut(new PrintWriter(io.getOut())) .setErr(new PrintWriter(io.getErr())); int exitCode = cmd.execute(args); @@ -111,19 +141,51 @@ public void doExecute(Io io, String[] args) { /** * The entrypoint of Picocli applications - the first method called when * CliBase, which implements the Runnable interface, is instantiated. - * Lfc and Lff have their own specific implementations for this method. */ - public abstract void run(); + public void run() { + // If args are given in a json file, store its contents in jsonString. + if (topLevelArg.jsonFile != null) { + try { + topLevelArg.jsonString = new String( + Files.readAllBytes(topLevelArg.jsonFile)); + } catch (IOException e) { + reporter.printFatalErrorAndExit( + "No such file: " + topLevelArg.jsonFile); + } + } + + // If args are given in a json string, (1) unpack them into an args + // array, and (2) call cmd.execute on them, which assigns them to their + // correct instance variables, then (3) recurses into run(). + if (topLevelArg.jsonString != null) { + // Unpack args from json string. + String[] args = jsonStringToArgs(topLevelArg.jsonString); + // Execute application on unpacked args. + CommandLine cmd = spec.commandLine(); + int exitCode = cmd.execute(args); + io.callSystemExit(exitCode); + + // If args are already unpacked, invoke tool-specific logic. + } else { + runTool(); + } + } + + /* + * The entrypoint of tool-specific logic. + * Lfc and Lff have their own specific implementations for this method. + */ + public abstract void runTool(); - public static Injector getInjector(String toolName, Io io) { + protected static Injector getInjector(String toolName, Io io) { final ReportingBackend reporter = new ReportingBackend(io, toolName + ": "); // Injector used to obtain Main instance. return new LFStandaloneSetup( - new LFRuntimeModule(), - new LFStandaloneModule(reporter, io) - ).createInjectorAndDoEMFRegistration(); + new LFRuntimeModule(), + new LFStandaloneModule(reporter, io) + ).createInjectorAndDoEMFRegistration(); } /** @@ -139,14 +201,14 @@ protected Path toAbsolutePath(Path other) { * @return Validated input paths. */ protected List getInputPaths() { - List paths = files.stream() + List paths = topLevelArg.files.stream() .map(io.getWd()::resolve) .collect(Collectors.toList()); for (Path path : paths) { if (!Files.exists(path)) { reporter.printFatalErrorAndExit( - path + ": No such file or directory."); + path + ": No such file or directory"); } } @@ -164,11 +226,11 @@ protected Path getOutputRoot() { root = io.getWd().resolve(outputPath).normalize(); if (!Files.exists(root)) { // FIXME: Create it instead? reporter.printFatalErrorAndExit( - root + ": Output location does not exist."); + "Output location '" + root + "' does not exist."); } if (!Files.isDirectory(root)) { reporter.printFatalErrorAndExit( - root + ": Output location is not a directory."); + "Output location '" + root + "' is not a directory."); } } @@ -211,29 +273,26 @@ public void validateResource(Resource resource) { assert resource != null; List issues = this.validator.validate( - resource, CheckMode.ALL, CancelIndicator.NullImpl); + resource, CheckMode.ALL, CancelIndicator.NullImpl); for (Issue issue : issues) { // Issues may also relate to imported resources. - URI uri = issue.getUriToProblem(); - Path path = null; - if (uri != null) { - try { - path = FileUtil.toPath(uri); - } catch (IOException e) { - reporter.printError("Unable to convert '" + uri + "' to path." + e); - } + URI uri = issue.getUriToProblem(); + try { + issueCollector.accept( + new LfIssue( + issue.getMessage(), + issue.getSeverity(), + issue.getLineNumber(), + issue.getColumn(), + issue.getLineNumberEnd(), + issue.getColumnEnd(), + issue.getLength(), + FileUtil.toPath(uri))); + } catch (IOException e) { + reporter.printError( + "Unable to convert '" + uri + "' to path." + e); } - issueCollector.accept( - new LfIssue( - issue.getMessage(), - issue.getSeverity(), - issue.getLineNumber(), - issue.getColumn(), - issue.getLineNumberEnd(), - issue.getColumnEnd(), - issue.getLength(), - path)); } } @@ -252,4 +311,71 @@ public Resource getResource(Path path) { } } + /** + * Constructs an arguments array (specific to lingua franca cli tools) from + * a json string. + * + * The given json object takes the following form: + * { + * "src": "/home/lf-user/workspace/lf-test/src/main.lf", + * "out": "/home/lf-user/workspace/lf-test/src-gen", + * "properties": { + * "fast": true, + * "federated": true + * } + * } + */ + private String[] jsonStringToArgs(String jsonString) { + ArrayList argsList = new ArrayList<>(); + JsonObject jsonObject = new JsonObject(); + + // Parse JSON string and get top-level JSON object. + try { + jsonObject = JsonParser.parseString(jsonString).getAsJsonObject(); + } catch (JsonParseException e) { + reporter.printFatalErrorAndExit( + "Invalid JSON string:\n" + jsonString); + } + + // Append input paths. + JsonElement src = jsonObject.get("src"); + if (src == null) { + reporter.printFatalErrorAndExit( + "JSON Parse Exception: field \"src\" not found."); + } + argsList.add(src.getAsString()); + + // Append output path if given. + JsonElement out = jsonObject.get("out"); + if (out != null) { + argsList.add("--output-path"); + argsList.add(out.getAsString()); + } + + // If there are no other properties, return args array. + JsonElement properties = jsonObject.get("properties"); + if (properties != null) { + // Get the remaining properties. + Set> entrySet = properties + .getAsJsonObject() + .entrySet(); + + // Append the remaining properties to the args array. + for(Entry entry : entrySet) { + String property = entry.getKey(); + String value = entry.getValue().getAsString(); + + // Append option. + argsList.add("--" + property); + // Append argument for non-boolean options. + if (value != "true" || property == "threading") { + argsList.add(value); + } + } + } + + // Return as String[]. + String[] args = argsList.toArray(new String[argsList.size()]); + return args; + } } diff --git a/org.lflang/src/org/lflang/cli/Lfc.java b/org.lflang/src/org/lflang/cli/Lfc.java index b31e5a8246..18e2625b87 100644 --- a/org.lflang/src/org/lflang/cli/Lfc.java +++ b/org.lflang/src/org/lflang/cli/Lfc.java @@ -1,7 +1,6 @@ package org.lflang.cli; -import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Properties; @@ -15,7 +14,6 @@ import org.lflang.ASTUtils; import org.lflang.FileConfig; -import org.lflang.TargetProperty.UnionType; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.LFGeneratorContext.BuildParm; @@ -107,7 +105,7 @@ public class Lfc extends CliBase { @Option( names = {"-r", "--rti"}, description = "Specify the location of the RTI.") - private Path rti; + private String rti; @Option( names = "--runtime-version", @@ -156,11 +154,15 @@ public static void main(Io io, final String... args) { * Load the resource, validate it, and, invoke the code generator. */ @Override - public void run() { + public void runTool() { + // Check for json. + + // unpack json. + List paths = getInputPaths(); final Path outputRoot = getOutputRoot(); // Hard code the props based on the options we want. - Properties properties = this.getGeneratorArgs(); + Properties properties = this.filterPassOnProps(); try { // Invoke the generator on all input file paths. @@ -231,78 +233,45 @@ private Path getActualOutputPath(Path root, Path path) { * * @return Properties for the code generator. */ - public Properties getGeneratorArgs() { + protected Properties filterPassOnProps() { Properties props = new Properties(); if (buildType != null) { - // Validate build type. - if (UnionType.BUILD_TYPE_UNION.forName(buildType) == null) { - reporter.printFatalErrorAndExit( - buildType + ": Invalid build type."); - } props.setProperty(BuildParm.BUILD_TYPE.getKey(), buildType); } - if (clean) { props.setProperty(BuildParm.CLEAN.getKey(), "true"); } - if (externalRuntimePath != null) { - props.setProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey(), - externalRuntimePath.toString()); + props.setProperty(BuildParm.EXTERNAL_RUNTIME_PATH.getKey(), externalRuntimePath.toString()); } - if (lint) { props.setProperty(BuildParm.LINT.getKey(), "true"); } - if (logging != null) { - // Validate log level. - if (UnionType.LOGGING_UNION.forName(logging) == null) { - reporter.printFatalErrorAndExit( - logging + ": Invalid log level."); - } props.setProperty(BuildParm.LOGGING.getKey(), logging); } - if (noCompile) { props.setProperty(BuildParm.NO_COMPILE.getKey(), "true"); } - if (targetCompiler != null) { props.setProperty(BuildParm.TARGET_COMPILER.getKey(), targetCompiler); } - if (quiet) { props.setProperty(BuildParm.QUIET.getKey(), "true"); } - if (rti != null) { - // Validate RTI path. - if (!Files.exists(io.getWd().resolve(rti))) { - reporter.printFatalErrorAndExit( - rti + ": Invalid RTI path."); - } - props.setProperty(BuildParm.RTI.getKey(), rti.toString()); + props.setProperty(BuildParm.RTI.getKey(), rti); } - if (runtimeVersion != null) { props.setProperty(BuildParm.RUNTIME_VERSION.getKey(), runtimeVersion); } - if (scheduler != null) { - // Validate scheduler. - if (UnionType.SCHEDULER_UNION.forName(scheduler) == null) { - reporter.printFatalErrorAndExit( - scheduler + ": Invalid scheduler."); - } props.setProperty(BuildParm.SCHEDULER.getKey(), scheduler); } - if (threading != null) { props.setProperty(BuildParm.THREADING.getKey(), threading); } - if (workers != null) { props.setProperty(BuildParm.WORKERS.getKey(), workers.toString()); } diff --git a/org.lflang/src/org/lflang/cli/Lff.java b/org.lflang/src/org/lflang/cli/Lff.java index 1efc207128..62a019a2fb 100644 --- a/org.lflang/src/org/lflang/cli/Lff.java +++ b/org.lflang/src/org/lflang/cli/Lff.java @@ -51,7 +51,7 @@ public class Lff extends CliBase { @Option( names = "--no-recurse", description = "Do not format files in subdirectories of the" - + " specified paths.") + + " specified paths.") private boolean noRecurse = false; @Option( @@ -59,11 +59,6 @@ public class Lff extends CliBase { description = "Print more details on files affected.") private boolean verbose = false; - @Option( - names = {"--ignore-errors"}, - description = "Ignore validation errors in files and format them anyway.") - private boolean ignoreErrors = false; - /** * Main function of the formatter. * Caution: this will invoke System.exit. @@ -88,7 +83,7 @@ public static void main(Io io, final String... args) { * Validates all paths and invokes the formatter on the input paths. */ @Override - public void run() { + public void runTool() { List paths = getInputPaths(); final Path outputRoot = getOutputRoot(); @@ -152,13 +147,12 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { if (verbose) { reporter.printInfo("Skipped " + path + ": not an LF file"); } - return; + return; } validateResource(resource); - if (!ignoreErrors) { - exitIfCollectedErrors(); - } + // todo don't abort whole run if one file has errors + exitIfCollectedErrors(); final String formattedFileContents = FormattingUtils.render(resource.getContents().get(0), lineLength); @@ -169,30 +163,24 @@ private void formatSingleFile(Path path, Path inputRoot, Path outputRoot) { FileUtil.writeToFile(formattedFileContents, outputPath, true); } catch (IOException e) { if (e instanceof FileAlreadyExistsException) { - // Only happens if a subdirectory is named with + // Only happens if a subdirectory is named with // ".lf" at the end. reporter.printFatalErrorAndExit( "Error writing to " + outputPath - + ": file already exists. Make sure that no file or" + + ": file already exists. Make sure that no file or" + " directory within provided input paths have the" + " same relative paths."); } } } - if (!ignoreErrors) { - exitIfCollectedErrors(); - } - // Only errors are printed. Warnings are not helpful for LFF - // and since they don't prevent the file from being formatted, - // the position of the issue may be wrong in the formatted file. - // issueCollector.getAllIssues().forEach(reporter::printIssue); + exitIfCollectedErrors(); + issueCollector.getAllIssues().forEach(reporter::printIssue); if (verbose) { String msg = "Formatted " + io.getWd().relativize(path); - if (path != outputPath) { - msg += " -> " + io.getWd().relativize(outputPath); - } + if (path != outputPath) msg += + " -> " + io.getWd().relativize(outputPath); reporter.printInfo(msg); } } diff --git a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index 1497ee6644..cd013d6c57 100644 --- a/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/org.lflang/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -66,7 +66,6 @@ import org.lflang.AttributeUtils; import org.lflang.InferredType; import org.lflang.ast.FormattingUtils; -import org.lflang.ast.ToText; import org.lflang.diagram.synthesis.action.CollapseAllReactorsAction; import org.lflang.diagram.synthesis.action.ExpandAllReactorsAction; import org.lflang.diagram.synthesis.action.FilterCycleAction; @@ -1188,12 +1187,12 @@ private String createParameterLabel(ParameterInstance param) { b.append(param.getName()); String t = param.type.toOriginalText(); if (!StringExtensions.isNullOrEmpty(t)) { - b.append(": ").append(t); + b.append(":").append(t); } - if (param.getOverride() != null) { - b.append(" = "); - var init = param.getActualValue(); - b.append(FormattingUtils.render(init)); + if (!IterableExtensions.isNullOrEmpty(param.getInitialValue())) { + b.append("("); + b.append(IterableExtensions.join(param.getInitialValue(), ", ", ASTUtils::toOriginalText)); + b.append(")"); } return b.toString(); } diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtension.java b/org.lflang/src/org/lflang/federated/extensions/CExtension.java index a2ac48216f..d9ed222920 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtension.java @@ -45,19 +45,21 @@ import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; -import org.lflang.federated.launcher.RtiConfig; import org.lflang.federated.serialization.FedROS2CPPSerialization; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.GeneratorBase; import org.lflang.generator.GeneratorUtils; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; +import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CTypes; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; import org.lflang.lf.Output; import org.lflang.lf.Port; import org.lflang.lf.VarRef; +import org.lflang.util.FileUtil; /** * An extension class to the CGenerator that enables certain federated @@ -81,10 +83,18 @@ public void initializeTargetConfig( int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, - RtiConfig rtiConfig + LinkedHashMap federationRTIProperties ) throws IOException { + if(GeneratorUtils.isHostWindows()) { + errorReporter.reportError( + "Federated LF programs with a C target are currently not supported on Windows. " + + "Exiting code generation." + ); + // Return to avoid compiler errors + return; + } - CExtensionUtils.handleCompileDefinitions(federate, numOfFederates, rtiConfig); + CExtensionUtils.handleCompileDefinitions(federate, numOfFederates, federationRTIProperties); generateCMakeInclude(federate, fileConfig); @@ -167,7 +177,7 @@ protected void deserialize( CodeBuilder result, ErrorReporter errorReporter ) { - CTypes types = new CTypes(); + CTypes types = new CTypes(errorReporter); // Adjust the type of the action and the receivingPort. // If it is "string", then change it to "char*". // This string is dynamically allocated, and type 'string' is to be @@ -335,7 +345,7 @@ protected void serializeAndSend( String commonArgs, ErrorReporter errorReporter ) { - CTypes types = new CTypes(); + CTypes types = new CTypes(errorReporter); var lengthExpression = ""; var pointerExpression = ""; switch (connection.getSerializer()) { @@ -421,7 +431,7 @@ public String generateNetworkInputControlReactionBody( // Find the maximum STP for decentralized coordination if(coordination == CoordinationType.DECENTRALIZED) { - result.pr("max_STP = "+ CTypes.getInstance().getTargetTimeExpr(maxSTP) +";"); + result.pr("max_STP = "+ GeneratorBase.timeInTargetLanguage(maxSTP)+";"); } result.pr("// Wait until the port status is known"); result.pr("wait_until_port_status_known("+receivingPortID+", max_STP);"); @@ -478,11 +488,11 @@ public String getNetworkBufferType() { public String generatePreamble( FederateInstance federate, FedFileConfig fileConfig, - RtiConfig rtiConfig, + LinkedHashMap federationRTIProperties, ErrorReporter errorReporter ) throws IOException { // Put the C preamble in a `include/_federate.name + _preamble.h` file - String cPreamble = makePreamble(federate, fileConfig, rtiConfig, errorReporter); + String cPreamble = makePreamble(federate, fileConfig, federationRTIProperties, errorReporter); String relPath = "include" + File.separator + "_" + federate.name + "_preamble.h"; Path fedPreamblePath = fileConfig.getSrcPath().resolve(relPath); Files.createDirectories(fedPreamblePath.getParent()); @@ -499,7 +509,7 @@ public String generatePreamble( protected String makePreamble( FederateInstance federate, FedFileConfig fileConfig, - RtiConfig rtiConfig, + LinkedHashMap federationRTIProperties, ErrorReporter errorReporter) { var code = new CodeBuilder(); @@ -522,7 +532,7 @@ protected String makePreamble( code.pr(generateSerializationPreamble(federate, fileConfig)); - code.pr(generateExecutablePreamble(federate, rtiConfig, errorReporter)); + code.pr(generateExecutablePreamble(federate, federationRTIProperties, errorReporter)); code.pr(generateInitializeTriggers(federate, errorReporter)); @@ -572,12 +582,12 @@ private String generateInitializeTriggers(FederateInstance federate, ErrorReport * Generate code for an executed preamble. * */ - private String generateExecutablePreamble(FederateInstance federate, RtiConfig rtiConfig, ErrorReporter errorReporter) { + private String generateExecutablePreamble(FederateInstance federate, LinkedHashMap federationRTIProperties, ErrorReporter errorReporter) { CodeBuilder code = new CodeBuilder(); code.pr(generateCodeForPhysicalActions(federate, errorReporter)); - code.pr(generateCodeToInitializeFederate(federate, rtiConfig)); + code.pr(generateCodeToInitializeFederate(federate, federationRTIProperties)); code.pr(CExtensionUtils.allocateTriggersForFederate(federate)); @@ -590,10 +600,10 @@ void _lf_executable_preamble() { /** * Generate code to initialize the {@code federate}. - * @param rtiConfig + * @param federationRTIProperties Properties related to the RTI. * @return The generated code */ - private String generateCodeToInitializeFederate(FederateInstance federate, RtiConfig rtiConfig) { + private String generateCodeToInitializeFederate(FederateInstance federate, LinkedHashMap federationRTIProperties) { CodeBuilder code = new CodeBuilder(); code.pr("// ***** Start initializing the federated execution. */"); code.pr(String.join("\n", @@ -614,7 +624,7 @@ private String generateCodeToInitializeFederate(FederateInstance federate, RtiCo if (stpParam.isPresent()) { var globalSTP = ASTUtils.initialValue(stpParam.get(), List.of(federate.instantiation)).get(0); var globalSTPTV = ASTUtils.getLiteralTimeValue(globalSTP); - code.pr("lf_set_stp_offset("+ CTypes.getInstance().getTargetTimeExpr(globalSTPTV) +");"); + code.pr("lf_set_stp_offset("+ CGenerator.timeInTargetLanguage(globalSTPTV)+");"); } } @@ -662,12 +672,12 @@ private String generateCodeToInitializeFederate(FederateInstance federate, RtiCo code.pr(String.join("\n", "// Connect to the RTI. This sets _fed.socket_TCP_RTI and _lf_rti_socket_UDP.", - "connect_to_rti("+addDoubleQuotes(rtiConfig.getHost())+", "+ rtiConfig.getPort()+");" + "connect_to_rti("+addDoubleQuotes(federationRTIProperties.get("host").toString())+", "+ federationRTIProperties.get("port")+");" )); // Disable clock synchronization for the federate if it resides on the same host as the RTI, // unless that is overridden with the clock-sync-options target property. - if (CExtensionUtils.clockSyncIsOn(federate, rtiConfig)) { + if (CExtensionUtils.clockSyncIsOn(federate, federationRTIProperties)) { code.pr("synchronize_initial_physical_clock_with_rti(_fed.socket_TCP_RTI);"); } @@ -739,7 +749,7 @@ private String generateCodeForPhysicalActions(FederateInstance federate, ErrorRe } code.pr( "_fed.min_delay_from_physical_action_to_federate_output = " - + CTypes.getInstance().getTargetTimeExpr(minDelay) + ";"); + + GeneratorBase.timeInTargetLanguage(minDelay) + ";"); } } return code.getCode(); diff --git a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java index 124ffefb4f..a24bcbae58 100644 --- a/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java +++ b/org.lflang/src/org/lflang/federated/extensions/CExtensionUtils.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; @@ -16,7 +17,6 @@ import org.lflang.TimeValue; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; -import org.lflang.federated.launcher.RtiConfig; import org.lflang.federated.serialization.FedROS2CPPSerialization; import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.CodeBuilder; @@ -239,7 +239,7 @@ static boolean isSharedPtrType(InferredType type, CTypes types) { public static void handleCompileDefinitions( FederateInstance federate, int numOfFederates, - RtiConfig rtiConfig + LinkedHashMap federationRTIProperties ) { federate.targetConfig.setByUser.add(TargetProperty.COMPILE_DEFINITIONS); federate.targetConfig.compileDefinitions.put("FEDERATED", ""); @@ -250,7 +250,7 @@ public static void handleCompileDefinitions( handleAdvanceMessageInterval(federate); - initializeClockSynchronization(federate, rtiConfig); + initializeClockSynchronization(federate, federationRTIProperties); } /** @@ -276,9 +276,9 @@ private static void handleAdvanceMessageInterval(FederateInstance federate) { } } - static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { + static boolean clockSyncIsOn(FederateInstance federate, LinkedHashMap federationRTIProperties) { return federate.targetConfig.clockSync != ClockSyncMode.OFF - && (!rtiConfig.getHost().equals(federate.host) + && (!federationRTIProperties.get("host").toString().equals(federate.host) || federate.targetConfig.clockSyncOptions.localFederatesOn); } @@ -290,10 +290,10 @@ static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) { */ public static void initializeClockSynchronization( FederateInstance federate, - RtiConfig rtiConfig + LinkedHashMap federationRTIProperties ) { // Check if clock synchronization should be enabled for this federate in the first place - if (clockSyncIsOn(federate, rtiConfig)) { + if (clockSyncIsOn(federate, federationRTIProperties)) { System.out.println("Initial clock synchronization is enabled for federate " + federate.id ); @@ -430,16 +430,16 @@ public static String generateFederateNeighborStructure(FederateInstance federate // Use NEVER to encode no delay at all. code.pr("candidate_tmp = NEVER;"); } else { - var delayTime = - delay instanceof ParameterReference - // In that case use the default value. - ? CTypes.getInstance().getTargetTimeExpr(ASTUtils.getDefaultAsTimeValue(((ParameterReference) delay).getParameter())) - : CTypes.getInstance().getTargetExpr(delay, InferredType.time()); - + var delayTime = GeneratorBase.getTargetTime(delay); + if (delay instanceof ParameterReference) { + // The delay is given as a parameter reference. Find its value. + final var param = ((ParameterReference)delay).getParameter(); + delayTime = GeneratorBase.timeInTargetLanguage(ASTUtils.getDefaultAsTimeValue(param)); + } code.pr(String.join("\n", - "if (" + delayTime + " < candidate_tmp) {", - " candidate_tmp = " + delayTime + ";", - "}" + "if ("+delayTime+" < candidate_tmp) {", + " candidate_tmp = "+delayTime+";", + "}" )); } } diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java index 7aa13d6cfc..7fb42bf007 100644 --- a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtension.java @@ -1,15 +1,21 @@ package org.lflang.federated.extensions; import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; import org.lflang.ErrorReporter; +import org.lflang.FileConfig; import org.lflang.InferredType; +import org.lflang.Target; +import org.lflang.TargetConfig; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; -import org.lflang.federated.launcher.RtiConfig; +import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.LFGeneratorContext; import org.lflang.lf.Action; import org.lflang.lf.Reaction; @@ -27,7 +33,7 @@ public interface FedTargetExtension { * @param errorReporter Used to report errors. */ void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, - ErrorReporter errorReporter, RtiConfig rtiConfig) throws IOException; + ErrorReporter errorReporter, LinkedHashMap federationRTIProperties) throws IOException; /** * Generate code for the body of a reaction that handles the @@ -114,13 +120,13 @@ default void annotateReaction(Reaction reaction) {} * Add necessary preamble to the source to set up federated execution. * * @param federate - * @param rtiConfig + * @param federationRTIProperties * @param errorReporter * @return */ String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, - RtiConfig rtiConfig, + LinkedHashMap federationRTIProperties, ErrorReporter errorReporter) throws IOException; } diff --git a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java index 5caafc1c0c..f3ab17514d 100644 --- a/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java +++ b/org.lflang/src/org/lflang/federated/extensions/FedTargetExtensionFactory.java @@ -12,8 +12,8 @@ public class FedTargetExtensionFactory { /** * Given a target, return the appropriate extension. */ - public static FedTargetExtension getExtension(Target target) { - switch (target) { + public static FedTargetExtension getExtension(TargetDecl target) { + switch (Target.fromDecl(target)) { case CCPP: case C: return new CExtension(); case Python: return new PythonExtension(); diff --git a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java index e438b1b866..21b469228e 100644 --- a/org.lflang/src/org/lflang/federated/extensions/TSExtension.java +++ b/org.lflang/src/org/lflang/federated/extensions/TSExtension.java @@ -3,25 +3,23 @@ import static org.lflang.util.StringUtil.addDoubleQuotes; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.LinkedHashMap; import java.util.stream.Collectors; import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; +import org.lflang.Target; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; import org.lflang.federated.generator.FedASTUtils; import org.lflang.federated.generator.FedConnectionInstance; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; -import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.GeneratorBase; import org.lflang.generator.LFGeneratorContext; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.ts.TSTypes; +import org.lflang.generator.ts.TSExtensionsKt; import org.lflang.lf.Action; import org.lflang.lf.Expression; import org.lflang.lf.Output; @@ -30,7 +28,7 @@ public class TSExtension implements FedTargetExtension { @Override - public void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, RtiConfig rtiConfig) throws IOException { + public void initializeTargetConfig(LFGeneratorContext context, int numOfFederates, FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, LinkedHashMap federationRTIProperties) throws IOException { } @@ -90,10 +88,9 @@ public String getNetworkBufferType() { */ @Override public String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, - RtiConfig rtiConfig, + LinkedHashMap federationRTIProperties, ErrorReporter errorReporter) { var minOutputDelay = getMinOutputDelay(federate, fileConfig, errorReporter); - var upstreamConnectionDelays = getUpstreamConnectionDelays(federate); return """ preamble {= @@ -108,8 +105,7 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf networkMessageActions: [%s], rtiHost: "%s", rtiPort: %d, - sendsTo: [%s], - upstreamConnectionDelays: [%s] + sendsTo: [%s] } =}""".formatted( federate.dependsOn.keySet().stream() @@ -117,17 +113,16 @@ public String generatePreamble(FederateInstance federate, FedFileConfig fileConf .collect(Collectors.joining(",")), federate.id, minOutputDelay == null ? "undefined" - : "%s".formatted(TSTypes.getInstance().getTargetTimeExpr(minOutputDelay)), + : "%s".formatted(TSExtensionsKt.toTsTime(minOutputDelay)), federate.networkMessageActions .stream() .map(Variable::getName) .collect(Collectors.joining(",", "\"", "\"")), - rtiConfig.getHost(), - rtiConfig.getPort(), + federationRTIProperties.get("host"), + federationRTIProperties.get("port"), federate.sendsTo.keySet().stream() .map(e->String.valueOf(e.id)) - .collect(Collectors.joining(",")), - upstreamConnectionDelays.stream().collect(Collectors.joining(",")) + .collect(Collectors.joining(",")) ); } @@ -172,33 +167,4 @@ private TimeValue getMinOutputDelay(FederateInstance federate, FedFileConfig fil } return null; } - - private List getUpstreamConnectionDelays(FederateInstance federate) { - List candidates = new ArrayList<>(); - if (!federate.dependsOn.keySet().isEmpty()) { - for (FederateInstance upstreamFederate: federate.dependsOn.keySet()) { - String element = "["; - var delays = federate.dependsOn.get(upstreamFederate); - int cnt = 0; - if (delays != null) { - for (Expression delay : delays) { - if (delay == null) { - element += "TimeValue.NEVER()"; - } else { - element += "TimeValue.nsec(" + getNetworkDelayLiteral(delay) + ")"; - } - cnt++; - if (cnt != delays.size()) { - element += ", "; - } - } - } else { - element += "TimeValue.NEVER()"; - } - element += "]"; - candidates.add(element); - } - } - return candidates; - } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java index 7a7eb1f183..21fb3a0729 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java +++ b/org.lflang/src/org/lflang/federated/generator/FedASTUtils.java @@ -208,7 +208,7 @@ private static Action createNetworkAction(FedConnectionInstance connection) { Type action_type = factory.createType(); action_type.setId( FedTargetExtensionFactory.getExtension( - connection.srcFederate.targetConfig.target + connection.srcFederate.target ).getNetworkBufferType() ); action.setType(action_type); @@ -264,7 +264,7 @@ private static void addNetworkReceiverReaction( setReactionBankIndex(networkReceiverReaction, connection.getDstBank()); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.target) .annotateReaction(networkReceiverReaction); // The connection is 'physical' if it uses the ~> notation. @@ -298,7 +298,7 @@ private static void addNetworkReceiverReaction( networkReceiverReaction.setCode(factory.createCode()); networkReceiverReaction.getCode().setBody( FedTargetExtensionFactory.getExtension( - connection.dstFederate.targetConfig.target).generateNetworkReceiverBody( + connection.dstFederate.target).generateNetworkReceiverBody( networkAction, sourceRef, destRef, @@ -357,7 +357,7 @@ private static void addNetworkInputControlReaction( setReactionBankIndex(reaction, connection.getDstBank()); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.target) .annotateReaction(reaction); // Create a new action that will be used to trigger the @@ -397,7 +397,7 @@ private static void addNetworkInputControlReaction( reaction.getCode() .setBody( FedTargetExtensionFactory - .getExtension(connection.dstFederate.targetConfig.target) + .getExtension(connection.dstFederate.target) .generateNetworkInputControlReactionBody( receivingPortID, maxSTP, @@ -721,7 +721,7 @@ private static void addNetworkSenderReaction( Reaction networkSenderReaction = factory.createReaction(); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.target) .annotateReaction(networkSenderReaction); // If the sender or receiver is in a bank of reactors, then we want @@ -750,7 +750,7 @@ private static void addNetworkSenderReaction( networkSenderReaction.getTriggers().add(sourceRef); networkSenderReaction.setCode(factory.createCode()); networkSenderReaction.getCode().setBody( - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.target) .generateNetworkSenderBody( sourceRef, destRef, @@ -797,7 +797,7 @@ private static void addNetworkOutputControlReaction(FedConnectionInstance connec setReactionBankIndex(reaction, connection.getSrcBank()); // FIXME: do not create a new extension every time it is used - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.target) .annotateReaction(reaction); // We use an action at the top-level to manually @@ -845,7 +845,7 @@ private static void addNetworkOutputControlReaction(FedConnectionInstance connec reaction.setCode(factory.createCode()); reaction.getCode().setBody( - FedTargetExtensionFactory.getExtension(connection.srcFederate.targetConfig.target) + FedTargetExtensionFactory.getExtension(connection.srcFederate.target) .generateNetworkOutputControlReactionBody(newPortRef, connection)); ASTUtils.addReactionAttribute(reaction, "_unordered"); diff --git a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java index 9ae5c9d2cc..e86af3ab77 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedEmitter.java @@ -8,7 +8,6 @@ import java.util.Map; import org.lflang.ErrorReporter; -import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeMap; import org.lflang.generator.LFGeneratorContext; import org.lflang.lf.Reactor; @@ -21,18 +20,18 @@ public class FedEmitter { private final FedFileConfig fileConfig; private final Reactor originalMainReactor; private final ErrorReporter errorReporter; - private final RtiConfig rtiConfig; + private final LinkedHashMap federationRTIProperties; public FedEmitter( FedFileConfig fileConfig, Reactor originalMainReactor, ErrorReporter errorReporter, - RtiConfig rtiConfig + LinkedHashMap federationRTIProperties ) { this.fileConfig = fileConfig; this.originalMainReactor = originalMainReactor; this.errorReporter = errorReporter; - this.rtiConfig = rtiConfig; + this.federationRTIProperties = federationRTIProperties; } /** @@ -56,9 +55,9 @@ Map generateFederate( String federateCode = String.join( "\n", - new FedTargetEmitter().generateTarget(context, numOfFederates, federate, fileConfig, errorReporter, rtiConfig), + new FedTargetEmitter().generateTarget(context, numOfFederates, federate, fileConfig, errorReporter, federationRTIProperties), new FedImportEmitter().generateImports(federate, fileConfig), - new FedPreambleEmitter().generatePreamble(federate, fileConfig, rtiConfig, errorReporter), + new FedPreambleEmitter().generatePreamble(federate, fileConfig, federationRTIProperties, errorReporter), new FedReactorEmitter().generateReactorDefinitions(federate), new FedMainEmitter().generateMainReactor( federate, diff --git a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java index 42f5c60dc7..8e9df19d6e 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java +++ b/org.lflang/src/org/lflang/federated/generator/FedFileConfig.java @@ -27,8 +27,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; import org.eclipse.emf.ecore.resource.Resource; @@ -45,12 +43,10 @@ */ public class FedFileConfig extends FileConfig { - public FedFileConfig( - Resource resource, - Path srcGenBasePath, - boolean useHierarchicalBin - ) throws IOException { + public FedFileConfig(Resource resource, Path srcGenBasePath, boolean useHierarchicalBin) throws IOException { + // FIMXE: It is unclear to me that we need this class. super(resource, srcGenBasePath, useHierarchicalBin); + } public FedFileConfig(FileConfig fileConfig) throws IOException { @@ -93,44 +89,9 @@ public Path getFedGenPath() { return srcPkgPath.resolve("fed-gen").resolve(this.name); } - /** - * Return the path to the directory in which the executables of compiled federates are stored. - */ - public Path getFedBinPath() { return getFedGenPath().resolve("bin"); } - @Override public void doClean() throws IOException { super.doClean(); FileUtil.deleteDirectory(this.getFedGenPath()); } - - /** - * Relativize target properties that involve paths like files and cmake-include to be - * relative to the generated .lf file for the federate. - */ - public void relativizePaths(FedTargetConfig targetConfig) { - relativizePathList(targetConfig.protoFiles); - relativizePathList(targetConfig.fileNames); - relativizePathList(targetConfig.cmakeIncludes); - } - - /** - * Relativize each path in the given list. - * @param paths The paths to relativize. - */ - private void relativizePathList(List paths) { - List tempList = new ArrayList<>(); - paths.forEach(f -> tempList.add(relativizePath(f))); - paths.clear(); - paths.addAll(tempList); - } - - /** - * Relativize a single path. - * @param path The path to relativize. - */ - private String relativizePath(String path) { - Path resolvedPath = this.srcPath.resolve(path).toAbsolutePath(); - return this.getSrcPath().relativize(resolvedPath).toString(); - } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java index 18d5770165..a96c1d17a2 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedGenerator.java +++ b/org.lflang/src/org/lflang/federated/generator/FedGenerator.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -25,8 +26,10 @@ import org.eclipse.xtext.generator.JavaIoFileSystemAccess; import org.eclipse.xtext.resource.XtextResource; import org.eclipse.xtext.resource.XtextResourceSet; -import org.eclipse.xtext.util.RuntimeIOException; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Pair; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; import org.lflang.ASTUtils; import org.lflang.ErrorReporter; @@ -35,11 +38,12 @@ import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty.CoordinationType; -import org.lflang.federated.launcher.FedLauncherGenerator; -import org.lflang.federated.launcher.RtiConfig; +import org.lflang.federated.launcher.FedLauncher; +import org.lflang.federated.launcher.FedLauncherFactory; import org.lflang.generator.CodeMap; import org.lflang.generator.DockerData; import org.lflang.generator.FedDockerComposeGenerator; +import org.lflang.generator.GeneratorResult; import org.lflang.generator.GeneratorResult.Status; import org.lflang.generator.GeneratorUtils; import org.lflang.generator.IntegratedBuilder; @@ -56,40 +60,55 @@ import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Reactor; -import org.lflang.util.Averager; +import org.lflang.lf.TargetDecl; import com.google.inject.Injector; public class FedGenerator { + /** Average asynchronously reported numbers and do something with them. */ + private static class Averager { + private final int n; + private final int[] reports; + /** Create an averager of reports from {@code n} processes. */ + public Averager(int n) { + this.n = n; + reports = new int[n]; + } + + /** + * Receive {@code x} from process {@code id} and invoke {@code callback} + * on the mean of the numbers most recently reported by the processes. + */ + public synchronized void report(int id, int x, Procedure1 callback) { + assert 0 <= id && id < n; + reports[id] = x; + callback.apply(Arrays.stream(reports).sum() / n); + } + } + + private final FedFileConfig fileConfig; + private final ErrorReporter errorReporter; /** - * + * The current target configuration. */ - private final ErrorReporter errorReporter; - + private final TargetConfig targetConfig; /** * A list of federate instances. */ private final List federates = new ArrayList<>(); - - /** - * File configuration to be used during the LF code generation stage (not the target code - * generation stage of individual federates). - */ - private final FedFileConfig fileConfig; - /** - * Configuration of the RTI. + * A map from federate IDs to federate instances. */ - final RtiConfig rtiConfig = new RtiConfig(); - + private final Map federateByID = new LinkedHashMap<>(); /** - * Target configuration of the federation; drawn from the file - * in which the federated reactor is defined. + * The federation RTI properties, which defaults to 'localhost: 15045'. */ - private final TargetConfig targetConfig; - + final LinkedHashMap federationRTIProperties = CollectionLiterals.newLinkedHashMap( + Pair.of("host", "localhost"), + Pair.of("port", 0) // Indicator to use the default port, typically 15045. + ); /** * A map from instantiations to the federate instances for that * instantiation. @@ -105,26 +124,12 @@ public class FedGenerator { */ private Instantiation mainDef; - /** - * Create a new generator and initialize a file configuration, target configuration, and error - * reporter. - * @param context - */ public FedGenerator(LFGeneratorContext context) { this.fileConfig = (FedFileConfig) context.getFileConfig(); this.targetConfig = context.getTargetConfig(); this.errorReporter = context.getErrorReporter(); } - /** - * Produce LF code for each federate in a separate file, then invoke a target-specific code - * generator for each of those files. - * - * @param resource The resource that has the federated main reactor in it - * @param context The context in which to carry out the code generation. - * @return False if no errors have occurred, true otherwise. - * @throws IOException - */ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException { if (!federatedExecutionIsSupported(resource)) return true; cleanIfNeeded(context); @@ -138,26 +143,27 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws processCLIArguments(context); // Find the federated reactor - Reactor federation = FedASTUtils.findFederatedReactor(resource); + Reactor fedReactor = FedASTUtils.findFederatedReactor(resource); // Extract some useful information about the federation - analyzeFederates(federation, context); + analyzeFederates(fedReactor); // Find all the connections between federates. // For each connection between federates, replace it in the // AST with an action (which inherits the delay) and four reactions. // The action will be physical for physical connections and logical // for logical connections. - replaceFederateConnectionsWithProxies(federation); + replaceFederateConnectionsWithProxies(fedReactor); + + createLauncher(fileConfig, errorReporter, federationRTIProperties); FedEmitter fedEmitter = new FedEmitter( fileConfig, ASTUtils.toDefinition(mainDef.getReactorClass()), errorReporter, - rtiConfig + federationRTIProperties ); - - // Generate LF code for each federate. + // Generate code for each federate Map lf2lfCodeMapMap = new HashMap<>(); for (FederateInstance federate : federates) { lf2lfCodeMapMap.putAll(fedEmitter.generateFederate( @@ -165,64 +171,46 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws )); } - // Do not invoke target code generators if --no-compile flag is used. if (context.getTargetConfig().noCompile) { context.finish(Status.GENERATED, lf2lfCodeMapMap); return false; } - Map codeMapMap = compileFederates(context, lf2lfCodeMapMap, subContexts -> { - createDockerFiles(context, subContexts); - generateLaunchScript(); + Map codeMapMap = compileFederates(context, lf2lfCodeMapMap, (subContexts) -> { + if (context.getTargetConfig().dockerOptions == null) return; + final List services = new ArrayList(); + // 1. create a Dockerfile for each federate + subContexts.forEach((subContext) -> { + // Inherit Docker options from main context + subContext.getTargetConfig().dockerOptions = context.getTargetConfig().dockerOptions; + var dockerGenerator = dockerGeneratorFactory(subContext); + var dockerData = dockerGenerator.generateDockerData(); + try { + dockerData.writeDockerFile(); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + services.add(dockerData); + }); + // 2. create a docker-compose.yml for the federation + try { + // FIXME: https://issue.lf-lang.org/1559 + // It appears that the rtiHost information should come from federationRTIproperties, + // which is a kludge and not in scope here. + (new FedDockerComposeGenerator(context, "localhost")).writeDockerComposeFile(services); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } }); context.finish(Status.COMPILED, codeMapMap); return false; } - private void generateLaunchScript() { - new FedLauncherGenerator( - this.targetConfig, - this.fileConfig, - this.errorReporter - ).doGenerate(federates, rtiConfig); - } - - /** - * Generate a Dockerfile for each federate and a docker-compose.yml for the federation. - * @param context The main context in which the federation has been compiled. - * @param subContexts The subcontexts in which the federates have been compiled. - */ - private void createDockerFiles(LFGeneratorContext context, List subContexts) { - if (context.getTargetConfig().dockerOptions == null) return; - final List services = new ArrayList<>(); - // 1. create a Dockerfile for each federate - for (SubContext subContext : subContexts) {// Inherit Docker options from main context - subContext.getTargetConfig().dockerOptions = context.getTargetConfig().dockerOptions; - var dockerGenerator = dockerGeneratorFactory(subContext); - var dockerData = dockerGenerator.generateDockerData(); - try { - dockerData.writeDockerFile(); - } catch (IOException e) { - throw new RuntimeIOException(e); - } - services.add(dockerData); - } - // 2. create a docker-compose.yml for the federation - try { - new FedDockerComposeGenerator( - context, - rtiConfig.getHost() - ).writeDockerComposeFile(services); - } catch (IOException e) { - throw new RuntimeIOException(e); - } - } - /** * Check if a clean was requested from the standalone compiler and perform * the clean step. - * @param context Context in which the generator operates + * @param context */ private void cleanIfNeeded(LFGeneratorContext context) { if (context.getArgs().containsKey(BuildParm.CLEAN.getKey())) { @@ -234,25 +222,54 @@ private void cleanIfNeeded(LFGeneratorContext context) { } } + /** + * Create a launcher for the federation. + * @param fileConfig + * @param errorReporter + * @param federationRTIProperties + */ + public void createLauncher( + FedFileConfig fileConfig, + ErrorReporter errorReporter, + LinkedHashMap federationRTIProperties + ) { + FedLauncher launcher; + if (federates.size() == 0) { + // no federates, use target properties of main file + TargetDecl targetDecl = GeneratorUtils.findTarget(fileConfig.resource); + launcher = FedLauncherFactory.getLauncher(Target.fromDecl(targetDecl), + targetConfig, + fileConfig, + errorReporter); + } else { + launcher = FedLauncherFactory.getLauncher( + federates.get(0), // FIXME: This would not work for mixed-target programs. + fileConfig, + errorReporter + ); + } + try { + launcher.createLauncher( + federates, + federationRTIProperties + ); + } catch (IOException e) { + errorReporter.reportError(e.getMessage()); + } + + // System.out.println(PythonInfoGenerator.generateFedRunInfo(fileConfig)); + } + /** Return whether federated execution is supported for {@code resource}. */ private boolean federatedExecutionIsSupported(Resource resource) { - var target = Target.fromDecl(GeneratorUtils.findTargetDecl(resource)); - var targetOK = List.of( - Target.C, Target.Python, Target.TS, Target.CPP, Target.CCPP - ).contains(target); - if (!targetOK) { + var target = Target.fromDecl(GeneratorUtils.findTarget(resource)); + var ret = List.of(Target.C, Target.Python, Target.TS, Target.CPP, Target.CCPP).contains(target); + if (!ret) { errorReporter.reportError( "Federated execution is not supported with target " + target + "." ); } - if(target.equals(Target.C) && GeneratorUtils.isHostWindows()) { - errorReporter.reportError( - "Federated LF programs with a C target are currently not supported on Windows." - ); - targetOK = false; - } - - return targetOK; + return ret; } private Map compileFederates( @@ -278,7 +295,7 @@ private Map compileFederates( var compileThreadPool = Executors.newFixedThreadPool(numOfCompileThreads); System.out.println("******** Using "+numOfCompileThreads+" threads to compile the program."); Map codeMapMap = new ConcurrentHashMap<>(); - List subContexts = Collections.synchronizedList(new ArrayList<>()); + List subContexts = Collections.synchronizedList(new ArrayList()); Averager averager = new Averager(federates.size()); final var threadSafeErrorReporter = new SynchronizedErrorReporter(errorReporter); for (int i = 0; i < federates.size(); i++) { @@ -297,8 +314,8 @@ private Map compileFederates( } props.put("docker", "false"); - TargetConfig subConfig = new TargetConfig( - props, GeneratorUtils.findTargetDecl(subFileConfig.resource), subContextErrorReporter + TargetConfig subConfig = GeneratorUtils.getTargetConfig( + props, GeneratorUtils.findTarget(subFileConfig.resource), subContextErrorReporter ); SubContext subContext = new SubContext(context, IntegratedBuilder.VALIDATED_PERCENT_PROGRESS, 100) { @Override @@ -376,34 +393,34 @@ private void setFederationRTIProperties(LFGeneratorContext context) { String port = matcher.group(3); if (host != null) { - rtiConfig.setHost(host); + federationRTIProperties.put("host", host); } if (port != null) { - rtiConfig.setPort(Integer.parseInt(port)); + federationRTIProperties.put("port", port); } if (user != null) { - rtiConfig.setUser(user); + federationRTIProperties.put("user", user); } } /** * Analyze the federation and record various properties of it. * - * @param federation The federated reactor that contains all federates' instances. + * @param fedReactor The federated reactor that contains all federates' instances. */ - private void analyzeFederates(Reactor federation, LFGeneratorContext context) { + private void analyzeFederates(Reactor fedReactor) { // Create an instantiation for the fed reactor because there isn't one. // Creating a definition for the main reactor because there isn't one. mainDef = LfFactory.eINSTANCE.createInstantiation(); - mainDef.setName(federation.getName()); - mainDef.setReactorClass(federation); + mainDef.setName(fedReactor.getName()); + mainDef.setReactorClass(fedReactor); // Make sure that if no federation RTI properties were given in the // cmdline, then those specified in the lf file are not lost - if (rtiConfig.getHost().equals("localhost") && - federation.getHost() != null && - !federation.getHost().getAddr().equals("localhost")) { - rtiConfig.setHost(federation.getHost().getAddr()); + if (federationRTIProperties.get("host").equals("localhost") && + fedReactor.getHost() != null && + !fedReactor.getHost().getAddr().equals("localhost")) { + federationRTIProperties.put("host", fedReactor.getHost().getAddr()); } // Since federates are always within the main (federated) reactor, @@ -412,15 +429,15 @@ private void analyzeFederates(Reactor federation, LFGeneratorContext context) { List mainReactorContext = new ArrayList<>(); mainReactorContext.add(mainDef); - // Create a FederateInstance for each instance in the top-level reactor. - for (Instantiation instantiation : ASTUtils.allInstantiations(federation)) { + // Create a FederateInstance for each top-level reactor. + for (Instantiation instantiation : ASTUtils.allInstantiations(fedReactor)) { int bankWidth = ASTUtils.width(instantiation.getWidthSpec(), mainReactorContext); if (bankWidth < 0) { errorReporter.reportError(instantiation, "Cannot determine bank width! Assuming width of 1."); // Continue with a bank width of 1. bankWidth = 1; } - List federateInstances = getFederateInstances(instantiation, bankWidth, context); + List federateInstances = getFederateInstances(instantiation, bankWidth); if (federatesByInstantiation == null) { federatesByInstantiation = new LinkedHashMap<>(); } @@ -437,23 +454,17 @@ private void analyzeFederates(Reactor federation, LFGeneratorContext context) { * @param bankWidth The width specified for the instantiation. * @return A list of federate instance (of type @see FederateInstance). */ - private List getFederateInstances(Instantiation instantiation, int bankWidth, LFGeneratorContext context) { + private List getFederateInstances(Instantiation instantiation, int bankWidth) { // Create one federate instance for each instance in a bank of reactors. List federateInstances = new ArrayList<>(bankWidth); - for (int i = 0; i < bankWidth; i++) { // Assign an integer ID to the federate. int federateID = federates.size(); - var resource = instantiation.getReactorClass().eResource(); - var federateTargetConfig = new FedTargetConfig(context, resource); - FederateInstance federateInstance = new FederateInstance( - instantiation, - federateID, - i, - federateTargetConfig, - errorReporter); + FederateInstance federateInstance = new FederateInstance(instantiation, federateID, i, errorReporter); + federateInstance.bankIndex = i; federates.add(federateInstance); federateInstances.add(federateInstance); + federateByID.put(federateID, federateInstance); if (instantiation.getHost() != null) { federateInstance.host = instantiation.getHost().getAddr(); @@ -478,16 +489,16 @@ private List getFederateInstances(Instantiation instantiation, * Replace connections between federates in the AST with proxies that * handle sending and receiving data. * - * @param federation Reactor class of the federation. + * @param fedReactor */ - private void replaceFederateConnectionsWithProxies(Reactor federation) { + private void replaceFederateConnectionsWithProxies(Reactor fedReactor) { // Each connection in the AST may represent more than one connection between - // federation instances because of banks and multiports. We need to generate communication + // federate instances because of banks and multiports. We need to generate communication // for each of these. To do this, we create a ReactorInstance so that we don't have // to duplicate the rather complicated logic in that class. We specify a depth of 1, // so it only creates the reactors immediately within the top level, not reactors // that those contain. - ReactorInstance mainInstance = new ReactorInstance(federation, errorReporter); + ReactorInstance mainInstance = new ReactorInstance(fedReactor, errorReporter); for (ReactorInstance child : mainInstance.children) { for (PortInstance output : child.outputs) { @@ -496,7 +507,7 @@ private void replaceFederateConnectionsWithProxies(Reactor federation) { } // Remove the connections at the top level - federation.getConnections().clear(); + fedReactor.getConnections().clear(); // There will be AST transformations that invalidate some info // cached in ReactorInstance. FIXME: most likely not needed anymore diff --git a/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java index 95351237a7..86923c8914 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedImportEmitter.java @@ -54,7 +54,7 @@ String generateImports(FederateInstance federate, FedFileConfig fileConfig) { ); return new_import; }) - .map(FormattingUtils.renderer(federate.targetConfig.target)) + .map(FormattingUtils.renderer(federate.target)) .collect(Collectors.joining("\n"))); return importStatements.getCode(); diff --git a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java index 54e215264f..ee3b64ab4a 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedMainEmitter.java @@ -41,7 +41,7 @@ String generateMainReactor(FederateInstance federate, Reactor originalMainReacto "Modes at the top level are not supported under federated execution." ); } - var renderer = FormattingUtils.renderer(federate.targetConfig.target); + var renderer = FormattingUtils.renderer(federate.target); return String .join( diff --git a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java index 20771e7848..827a31fe33 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedPreambleEmitter.java @@ -8,7 +8,6 @@ import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.federated.extensions.FedTargetExtensionFactory; -import org.lflang.federated.launcher.RtiConfig; import org.lflang.generator.CodeBuilder; import org.lflang.lf.Model; import org.lflang.lf.Preamble; @@ -21,7 +20,7 @@ public FedPreambleEmitter() {} * Add necessary code to the source and necessary build support to * enable the requested serializations in 'enabledSerializations' */ - String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, RtiConfig rtiConfig, ErrorReporter errorReporter) + String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, LinkedHashMap federationRTIProperties, ErrorReporter errorReporter) throws IOException { CodeBuilder preambleCode = new CodeBuilder(); @@ -39,8 +38,8 @@ String generatePreamble(FederateInstance federate, FedFileConfig fileConfig, Rti )); } - preambleCode.pr(FedTargetExtensionFactory.getExtension(federate.targetConfig.target).generatePreamble( - federate, fileConfig, rtiConfig, errorReporter)); + preambleCode.pr(FedTargetExtensionFactory.getExtension(federate.target).generatePreamble( + federate, fileConfig, federationRTIProperties, errorReporter)); return preambleCode.getCode(); } diff --git a/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java index 976049601c..066b344417 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedReactorEmitter.java @@ -18,7 +18,7 @@ String generateReactorDefinitions(FederateInstance federate) { .getReactors() .stream() .filter(federate::contains) - .map(FormattingUtils.renderer(federate.targetConfig.target)) + .map(FormattingUtils.renderer(federate.target)) .collect(Collectors.joining("\n")); } } diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java b/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java deleted file mode 100644 index 9af20347c2..0000000000 --- a/org.lflang/src/org/lflang/federated/generator/FedTargetConfig.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.lflang.federated.generator; - -import static org.lflang.ASTUtils.convertToEmptyListIfNull; - -import org.lflang.ErrorReporter; -import org.lflang.TargetConfig; -import org.lflang.TargetProperty; -import org.lflang.generator.GeneratorUtils; -import org.lflang.generator.LFGeneratorContext; -import org.eclipse.emf.ecore.resource.Resource; - -/** - * Subclass of TargetConfig with a specialized constructor for creating configurations for federates. - * @author Marten Lohstroh - */ -public class FedTargetConfig extends TargetConfig { - - /** - * Create a configuration for a federate given a main context and the resource in which the class - * of the federate is specified. - * @param context The generator context. - * @param federateResource The resource in which to find the reactor class of the federate. - */ - public FedTargetConfig(LFGeneratorContext context, Resource federateResource) { - // Create target config based on the main .lf file - super( - context.getArgs(), - GeneratorUtils.findTargetDecl(context.getFileConfig().resource), - context.getErrorReporter() - ); - - mergeImportedConfig( - federateResource, - context.getFileConfig().resource, - context.getErrorReporter() - ); - - clearPropertiesToIgnore(); - - ((FedFileConfig)context.getFileConfig()).relativizePaths(this); - - } - - /** - * If the federate that target configuration applies to is imported, merge target properties - * declared in the file that it was imported from. - * @param federateResource The resource where the class of the federate is specified. - * @param mainResource The resource in which the federation (i.e., main reactor) is specified. - * @param errorReporter An error reporter to use when problems are encountered. - */ - private void mergeImportedConfig( - Resource federateResource, - Resource mainResource, - ErrorReporter errorReporter) { - // If the federate is imported, then update the configuration based on target properties - // in the imported file. - if (!federateResource.equals(mainResource)) { - var importedTargetDecl = GeneratorUtils.findTargetDecl(federateResource); - var targetProperties = importedTargetDecl.getConfig(); - if (targetProperties != null) { - // Merge properties - TargetProperty.update( - this, - convertToEmptyListIfNull(targetProperties.getPairs()), - errorReporter - ); - } - } - } - - /** - * Method for the removal of things that should not appear in the target config of a federate. - */ - private void clearPropertiesToIgnore() { - this.setByUser.remove(TargetProperty.CLOCK_SYNC); - this.setByUser.remove(TargetProperty.CLOCK_SYNC_OPTIONS); - } -} diff --git a/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java b/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java index 1616286048..7143eb18c5 100644 --- a/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java +++ b/org.lflang/src/org/lflang/federated/generator/FedTargetEmitter.java @@ -1,12 +1,19 @@ package org.lflang.federated.generator; +import static org.lflang.ASTUtils.convertToEmptyListIfNull; + import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; import org.lflang.ErrorReporter; +import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.ast.FormattingUtils; import org.lflang.federated.extensions.FedTargetExtensionFactory; -import org.lflang.federated.launcher.RtiConfig; +import org.lflang.generator.GeneratorUtils; import org.lflang.generator.LFGeneratorContext; public class FedTargetEmitter { @@ -17,28 +24,86 @@ String generateTarget( FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter, - RtiConfig rtiConfig + LinkedHashMap federationRTIProperties ) throws IOException { + federate.targetConfig = + GeneratorUtils.getTargetConfig( + context.getArgs(), + federate.target, + errorReporter + ); + // FIXME: Should we merge some properties with the main .lf file if the federate is imported? + // https://issue.lf-lang.org/1560 + var fedReactorClass = federate.instantiation.getReactorClass(); + if (!fedReactorClass.eResource().equals(fileConfig.resource)) { + // Merge some target properties of the main .lf file. + var target = GeneratorUtils.findTarget(fileConfig.resource); + if (target.getConfig() != null) { + // Merge properties + TargetProperty.update( + federate.targetConfig, + convertToEmptyListIfNull(target.getConfig().getPairs()), + errorReporter + ); + } + } + + relativizeTargetPaths(federate, fileConfig); + + clearFederatedTargetPropertiesI(federate); - // FIXME: First of all, this is not an initialization; there is all sorts of stuff happening - // in the C implementation of this method. Second, true initialization stuff should happen - // when the target config is constructed, not when we're doing code generation. - // See https://issues.lf-lang.org/1667 - FedTargetExtensionFactory.getExtension(federate.targetConfig.target) + FedTargetExtensionFactory.getExtension(federate.target) .initializeTargetConfig( context, numOfFederates, federate, fileConfig, errorReporter, - rtiConfig + federationRTIProperties ); - return FormattingUtils.renderer(federate.targetConfig.target).apply( + return FormattingUtils.renderer(federate.target).apply( TargetProperty.extractTargetDecl( - federate.targetConfig.target, + Target.fromDecl(federate.target), federate.targetConfig ) ); } + + /** + * Clear target properties that should not end up in the generated .lf file + * for {@code federate}. + */ + private void clearFederatedTargetPropertiesI(FederateInstance federate) { + federate.targetConfig.setByUser.remove(TargetProperty.CLOCK_SYNC); + federate.targetConfig.setByUser.remove(TargetProperty.CLOCK_SYNC_OPTIONS); + } + + + /** + * Relativize target properties that involve paths like files and cmake-include to be + * relative to the generated .lf file for the federate. + */ + private void relativizeTargetPaths(FederateInstance federate, FedFileConfig fileConfig) { + // FIXME: Should we relativize here or calculate absolute paths? + relativizePathList(federate.targetConfig.protoFiles, fileConfig); + + relativizePathList(federate.targetConfig.fileNames, fileConfig); + + relativizePathList(federate.targetConfig.cmakeIncludes, fileConfig); + } + + private void relativizePathList(List paths, FedFileConfig fileConfig) { + List tempList = new ArrayList<>(); + paths.forEach( f -> { + tempList.add(relativizePath(f, fileConfig)); + }); + paths.clear(); + paths.addAll(tempList); + } + + private String relativizePath(String path, FedFileConfig fileConfig) { + Path resolvedPath = fileConfig.srcPath.resolve(path).toAbsolutePath(); + return fileConfig.getSrcPath().relativize(resolvedPath).toString(); + } } diff --git a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java index 7ca5a19bca..fd309dc4a1 100644 --- a/org.lflang/src/org/lflang/federated/generator/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/generator/FederateInstance.java @@ -25,7 +25,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.federated.generator; -import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; @@ -40,8 +39,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.ASTUtils; import org.lflang.ErrorReporter; -import org.lflang.FileConfig; -import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TimeValue; import org.lflang.federated.serialization.SupportedSerializers; @@ -50,7 +47,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.PortInstance; import org.lflang.generator.ReactionInstance; import org.lflang.generator.ReactorInstance; -import org.lflang.generator.SubContext; import org.lflang.generator.TriggerInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -66,6 +62,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; +import org.lflang.lf.TargetDecl; import org.lflang.lf.Timer; import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; @@ -74,17 +71,17 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import com.google.common.base.Objects; -/** +/** * Instance of a federate, or marker that no federation has been defined * (if isSingleton() returns true) FIXME: this comment makes no sense. * Every top-level reactor (contained * directly by the main reactor) is a federate, so there will be one * instance of this class for each top-level reactor. - * + * * @author Edward A. Lee * @author Soroush Bateni */ -public class FederateInstance { // why does this not extend ReactorInstance? +public class FederateInstance { /** * Construct a new instance with the specified instantiation of @@ -100,14 +97,15 @@ public FederateInstance( Instantiation instantiation, int id, int bankIndex, - TargetConfig targetConfig, ErrorReporter errorReporter) { this.instantiation = instantiation; this.id = id; this.bankIndex = bankIndex; this.errorReporter = errorReporter; - this.targetConfig = targetConfig; - + this.target = GeneratorUtils.findTarget( + ASTUtils.toDefinition(instantiation.getReactorClass()).eResource() + ); + this.targetConfig = new TargetConfig(target); // FIXME: this is actually set in FedTargetEmitter. Why? if (instantiation != null) { this.name = instantiation.getName(); // If the instantiation is in a bank, then we have to append @@ -250,6 +248,11 @@ public Instantiation getInstantiation() { */ public List networkReactions = new ArrayList<>(); + /** + * Target of the federate. + */ + public TargetDecl target; + /** * Parsed target config of the federate. */ diff --git a/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java deleted file mode 100644 index c1a01bfa47..0000000000 --- a/org.lflang/src/org/lflang/federated/launcher/BuildConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.lflang.federated.launcher; - -import org.lflang.ErrorReporter; -import org.lflang.federated.generator.FedFileConfig; -import org.lflang.federated.generator.FederateInstance; - -/** - * A collection of methods used for building target code for federates. - */ -public abstract class BuildConfig { - - /** - * The federate that this configuration applies to. - */ - protected final FederateInstance federate; - - /** - * An error reporter to report problems. - */ - protected final ErrorReporter errorReporter; - - /** - * The file configuration of the federation that the federate belongs to. - */ - protected final FedFileConfig fileConfig; - - /** - * Create a new build configuration. - * - * @param federate The federate that this configuration applies to. - * @param fileConfig The file configuration of the federation that the federate belongs to. - * @param errorReporter An error reporter to report problems. - */ - public BuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - this.errorReporter = errorReporter; - this.federate = federate; - this.fileConfig = fileConfig; - } - - /** - * Return the compile command for the federate that this build configuration belongs to. - */ - public String compileCommand() { - throw new UnsupportedOperationException(); - } - - /** - * Return the command that will execute the federate that this build configuration belongs to - * locally, assuming that the current directory is the top-level project folder. - */ - public abstract String localExecuteCommand(); - - /** - * Return the command that will execute the federate that this build configuration belongs to - * remotely, assuming that the current directory is the top-level project folder. - */ - public String remoteExecuteCommand() { - throw new UnsupportedOperationException(); - } -} diff --git a/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/FedCLauncher.java similarity index 56% rename from org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java rename to org.lflang/src/org/lflang/federated/launcher/FedCLauncher.java index bd88a719b4..0b45444be9 100644 --- a/org.lflang/src/org/lflang/federated/launcher/CBuildConfig.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedCLauncher.java @@ -26,8 +26,10 @@ package org.lflang.federated.launcher; import java.io.File; +import java.io.IOException; import org.lflang.ErrorReporter; +import org.lflang.TargetConfig; import org.lflang.federated.generator.FedFileConfig; import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.c.CCompiler; @@ -37,25 +39,43 @@ * that are written in C. * * @author Soroush Bateni - * @author Marten Lohstroh */ -public class CBuildConfig extends BuildConfig { +public class FedCLauncher extends FedLauncher { - public CBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - super(federate, fileConfig, errorReporter); + /** + * Create an instance of FedCLauncher. + * + * @param targetConfig The current target configuration. + * @param fileConfig The current file configuration. + * @param errorReporter A error reporter for reporting any errors or warnings during the code generation + */ + public FedCLauncher( + TargetConfig targetConfig, + FedFileConfig fileConfig, + ErrorReporter errorReporter + ) { + super(targetConfig, fileConfig, errorReporter); } + /** + * Return the compile command for a federate. + * + * @param federate The federate to compile. + * @throws IOException + */ @Override - public String compileCommand() { + protected + String compileCommandForFederate(FederateInstance federate) { + TargetConfig localTargetConfig = targetConfig; String commandToReturn = ""; // FIXME: Hack to add platform support only for linux systems. // We need to fix the CMake build command for remote federates. String linuxPlatformSupport = "core" + File.separator + "platform" + File.separator + "lf_linux_support.c"; - if (!federate.targetConfig.compileAdditionalSources.contains(linuxPlatformSupport)) { - federate.targetConfig.compileAdditionalSources.add(linuxPlatformSupport); + if (!localTargetConfig.compileAdditionalSources.contains(linuxPlatformSupport)) { + localTargetConfig.compileAdditionalSources.add(linuxPlatformSupport); } - CCompiler cCompiler= new CCompiler(federate.targetConfig, fileConfig, errorReporter, false); + CCompiler cCompiler= new CCompiler(localTargetConfig, fileConfig, errorReporter, false); commandToReturn = String.join(" ", cCompiler.compileCCommand( fileConfig.name+"_"+federate.name, @@ -64,13 +84,28 @@ public String compileCommand() { return commandToReturn; } + /** + * Return the command that will execute a remote federate, assuming that the current + * directory is the top-level project folder. This is used to create a launcher script + * for federates. + * + * @param federate The federate to execute. + */ @Override - public String remoteExecuteCommand() { + protected + String executeCommandForRemoteFederate(FederateInstance federate) { return "bin/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; } + /** + * Return the command that will execute a local federate. + * This is used to create a launcher script for federates. + * + * @param federate The federate to execute. + */ @Override - public String localExecuteCommand() { - return fileConfig.getFedBinPath().resolve(federate.name)+" -i $FEDERATION_ID"; + protected + String executeCommandForLocalFederate(FedFileConfig fileConfig, FederateInstance federate) { + return fileConfig.getGenPath().resolve("bin/"+federate.name)+" -i $FEDERATION_ID"; } } diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncher.java similarity index 86% rename from org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java rename to org.lflang/src/org/lflang/federated/launcher/FedLauncher.java index 3ad08e2450..48a7149729 100644 --- a/org.lflang/src/org/lflang/federated/launcher/FedLauncherGenerator.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncher.java @@ -26,16 +26,15 @@ package org.lflang.federated.launcher; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import org.lflang.ErrorReporter; -import org.lflang.Target; import org.lflang.TargetConfig; import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.federated.generator.FedFileConfig; @@ -47,7 +46,8 @@ * @author Edward A. Lee * @author Soroush Bateni */ -public class FedLauncherGenerator { +public class FedLauncher { + protected TargetConfig targetConfig; protected FedFileConfig fileConfig; protected ErrorReporter errorReporter; @@ -57,12 +57,44 @@ public class FedLauncherGenerator { * @param fileConfig The current file configuration. * @param errorReporter A error reporter for reporting any errors or warnings during the code generation */ - public FedLauncherGenerator(TargetConfig targetConfig, FedFileConfig fileConfig, ErrorReporter errorReporter) { + public FedLauncher(TargetConfig targetConfig, FedFileConfig fileConfig, ErrorReporter errorReporter) { this.targetConfig = targetConfig; this.fileConfig = fileConfig; this.errorReporter = errorReporter; } + /** + * Return the compile command for a federate. + * + * @param federate The federate to compile. + */ + protected String compileCommandForFederate(FederateInstance federate) { + throw new UnsupportedOperationException("Don't know how to compile the federates."); + } + + /** + * Return the command that will execute a remote federate, assuming that the current + * directory is the top-level project folder. This is used to create a launcher script + * for federates. + * + * @param federate The federate to execute. + */ + protected String executeCommandForRemoteFederate(FederateInstance federate) { + throw new UnsupportedOperationException("Don't know how to execute the federates."); + } + + /** + * Return the command that will execute a local federate, assuming that the current + * directory is the top-level project folder. This is used to create a launcher script + * for federates. + * + * @param federate The federate to execute. + */ + protected String executeCommandForLocalFederate(FedFileConfig fileConfig, + FederateInstance federate) { + throw new UnsupportedOperationException("Don't know how to execute the federates."); + } + /** * Create the launcher shell scripts. This will create one or two files * in the output path (bin directory). The first has name equal to @@ -99,13 +131,13 @@ public FedLauncherGenerator(TargetConfig targetConfig, FedFileConfig fileConfig, * openssl version * * @param federates A list of federate instances in the federation - * @param rtiConfig + * @param federationRTIProperties Contains relevant properties of the RTI. * Can have values for 'host', 'dir', and 'user' */ - public void doGenerate( + public void createLauncher( List federates, - RtiConfig rtiConfig - ) { + LinkedHashMap federationRTIProperties + ) throws IOException { // NOTE: It might be good to use screen when invoking the RTI // or federates remotely, so you can detach and the process keeps running. // However, I was unable to get it working properly. @@ -122,10 +154,12 @@ public void doGenerate( StringBuilder distCode = new StringBuilder(); shCode.append(getSetupCode() + "\n"); String distHeader = getDistHeader(); - String host = rtiConfig.getHost(); - String target = host; + Object host = federationRTIProperties.get("host"); + Object target = host; - String user = rtiConfig.getUser(); + Path path = Path.of(federationRTIProperties.get("dir") == null ? "LinguaFrancaRemote" : federationRTIProperties.get("dir").toString()); + + Object user = federationRTIProperties.get("user"); if (user != null) { target = user + "@" + host; } @@ -165,18 +199,17 @@ public void doGenerate( // Index used for storing pids of federates int federateIndex = 0; for (FederateInstance federate : federates) { - var buildConfig = getBuildConfig(federate, fileConfig, errorReporter); if (federate.isRemote) { Path fedRelSrcGenPath = fileConfig.getOutPath().relativize(fileConfig.getSrcGenPath()).resolve(federate.name); if(distCode.length() == 0) distCode.append(distHeader + "\n"); String logFileName = String.format("log/%s_%s.log", fileConfig.name, federate.name); - String compileCommand = buildConfig.compileCommand(); + String compileCommand = compileCommandForFederate(federate); // FIXME: Should $FEDERATION_ID be used to ensure unique directories, executables, on the remote host? - distCode.append(getDistCode(rtiConfig.getDirectory(), federate, fedRelSrcGenPath, logFileName, fileConfig.getSrcGenPath(), compileCommand) + "\n"); - String executeCommand = buildConfig.remoteExecuteCommand(); - shCode.append(getFedRemoteLaunchCode(federate, rtiConfig.getDirectory(), logFileName, executeCommand, federateIndex++) + "\n"); + distCode.append(getDistCode(path, federate, fedRelSrcGenPath, logFileName, fileConfig.getSrcGenPath(), compileCommand) + "\n"); + String executeCommand = executeCommandForRemoteFederate(federate); + shCode.append(getFedRemoteLaunchCode(federate, path, logFileName, executeCommand, federateIndex++) + "\n"); } else { - String executeCommand = buildConfig.localExecuteCommand(); + String executeCommand = executeCommandForLocalFederate(fileConfig, federate); shCode.append(getFedLocalLaunchCode(federate, executeCommand, federateIndex++) + "\n"); } } @@ -199,11 +232,7 @@ public void doGenerate( // Create bin directory for the script. if (!Files.exists(fileConfig.binPath)) { - try { - Files.createDirectories(fileConfig.binPath); - } catch (IOException e) { - errorReporter.reportError("Unable to create directory: " + fileConfig.binPath); - } + Files.createDirectories(fileConfig.binPath); } System.out.println("##### Generating launcher for federation " @@ -217,19 +246,9 @@ public void doGenerate( file.delete(); } - FileOutputStream fOut = null; - try { - fOut = new FileOutputStream(file); - } catch (FileNotFoundException e) { - errorReporter.reportError("Unable to find file: " + file); - } - try { - fOut.write(shCode.toString().getBytes()); - fOut.close(); - } catch (IOException e) { - errorReporter.reportError("Unable to write to file: " + file); - } - + FileOutputStream fOut = new FileOutputStream(file); + fOut.write(shCode.toString().getBytes()); + fOut.close(); if (!file.setExecutable(true, false)) { errorReporter.reportWarning("Unable to make launcher script executable."); } @@ -241,17 +260,11 @@ public void doGenerate( file.delete(); } if (distCode.length() > 0) { - try { - fOut = new FileOutputStream(file); - fOut.write(distCode.toString().getBytes()); - fOut.close(); - if (!file.setExecutable(true, false)) { - errorReporter.reportWarning("Unable to make file executable: " + file); - } - } catch (FileNotFoundException e) { - errorReporter.reportError("Unable to find file: " + file); - } catch (IOException e) { - errorReporter.reportError("Unable to write to file " + file); + fOut = new FileOutputStream(file); + fOut.write(distCode.toString().getBytes()); + fOut.close(); + if (!file.setExecutable(true, false)) { + errorReporter.reportWarning("Unable to make distributor script executable."); } } } @@ -316,9 +329,6 @@ private String getRtiCommand(List federates, boolean isRemote) if (targetConfig.auth) { commands.add(" -a \\"); } - if (targetConfig.tracing != null) { - commands.add(" -t \\"); - } commands.addAll(List.of( " -n "+federates.size()+" \\", " -c "+targetConfig.clockSync.toString()+" \\" @@ -441,7 +451,7 @@ private String getUserHost(Object user, Object host) { private String getFedRemoteLaunchCode( FederateInstance federate, - Path path, + Object path, String logFileName, String executeCommand, int federateIndex @@ -472,24 +482,4 @@ private String getFedLocalLaunchCode(FederateInstance federate, String executeCo executeCommand, federateIndex); } - - /** - * Create a build configuration of the appropriate target. - * - * @param federate The federate to which the build configuration applies. - * @param fileConfig The file configuration of the federation to which the federate belongs. - * @param errorReporter An error reporter to report problems. - * @return - */ - private BuildConfig getBuildConfig( - FederateInstance federate, - FedFileConfig fileConfig, - ErrorReporter errorReporter) { - return switch(federate.targetConfig.target) { - case C, CCPP -> new CBuildConfig(federate, fileConfig, errorReporter); - case Python -> new PyBuildConfig(federate, fileConfig, errorReporter); - case TS -> new TsBuildConfig(federate, fileConfig, errorReporter); - case CPP, Rust -> throw new UnsupportedOperationException(); - }; - } } diff --git a/org.lflang/src/org/lflang/federated/launcher/FedLauncherFactory.java b/org.lflang/src/org/lflang/federated/launcher/FedLauncherFactory.java new file mode 100644 index 0000000000..c92cea1807 --- /dev/null +++ b/org.lflang/src/org/lflang/federated/launcher/FedLauncherFactory.java @@ -0,0 +1,64 @@ +package org.lflang.federated.launcher; + +import org.lflang.ErrorReporter; +import org.lflang.Target; +import org.lflang.TargetConfig; +import org.lflang.federated.generator.FedFileConfig; +import org.lflang.federated.generator.FederateInstance; + +/** + * Helper class to get the appropriate launcher generator. + * + * FIXME: This architecture needs to be redesigned for multi-target federations. + */ +public class FedLauncherFactory { + + public static FedLauncher getLauncher ( + FederateInstance federate, + FedFileConfig fileConfig, + ErrorReporter errorReporter + ) { + return getLauncher(Target.fromDecl(federate.target), federate.targetConfig, fileConfig, errorReporter); + } + + /** + * Return a launcher generator. + * @param target The target to generate for. + * @param targetConfig The target config of the federate. + * @param fileConfig The file config for the federate. + * @param errorReporter The error reporter to use. + * @return null if not supported, an instance of {@code #FedLauncher} otherwise. + */ + public static FedLauncher getLauncher( + Target target, + TargetConfig targetConfig, + FedFileConfig fileConfig, + ErrorReporter errorReporter + ) { + switch (target) { + case C: + case CCPP: + return new FedCLauncher( + targetConfig, + fileConfig, + errorReporter + ); + case CPP: + case Rust: + return null; + case TS: + return new FedTSLauncher( + targetConfig, + fileConfig, + errorReporter + ); + case Python: + return new FedPyLauncher( + targetConfig, + fileConfig, + errorReporter + ); + } + return null; + } +} diff --git a/org.lflang/src/org/lflang/federated/launcher/FedPyLauncher.java b/org.lflang/src/org/lflang/federated/launcher/FedPyLauncher.java new file mode 100644 index 0000000000..414caf2ee4 --- /dev/null +++ b/org.lflang/src/org/lflang/federated/launcher/FedPyLauncher.java @@ -0,0 +1,83 @@ +/************* + * Copyright (c) 2021, The University of California at Berkeley. + * Copyright (c) 2021, The University of Texas at Dallas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + ***************/ + +package org.lflang.federated.launcher; + +import org.lflang.ErrorReporter; +import org.lflang.TargetConfig; +import org.lflang.federated.generator.FedFileConfig; +import org.lflang.federated.generator.FederateInstance; + +/** + * Utility class that can be used to create a launcher for federated LF programs + * that are written in Python. + * + * @author Soroush Bateni + * + */ +public class FedPyLauncher extends FedLauncher { + /** + * Create an instance of FedPyLauncher. + * + * @param targetConfig The current target configuration. + * @param fileConfig The current file configuration. + * @param errorReporter A error reporter for reporting any errors or warnings during the code generation + */ + public FedPyLauncher( + TargetConfig targetConfig, + FedFileConfig fileConfig, + ErrorReporter errorReporter + ) { + super(targetConfig, fileConfig, errorReporter); + } + + /** + * Return the command that will execute a remote federate, assuming that the current + * directory is the top-level project folder. This is used to create a launcher script + * for federates. + * + * @param federate The federate to execute. + */ + @Override + protected + String executeCommandForRemoteFederate(FederateInstance federate) { + return "python3 src-gen/"+fileConfig.name+"/"+federate.name+"/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; + } + + /** + * Return the command that will execute a local federate, assuming that the current + * directory is the top-level project folder. This is used to create a launcher script + * for federates. + * + * @param federate The federate to execute. + */ + @Override + protected + String executeCommandForLocalFederate(FedFileConfig fileConfig, FederateInstance federate) { + return "python3 " + fileConfig.getSrcGenPath() + "/" + federate.name + "/" + federate.name+".py -i $FEDERATION_ID"; + } +} diff --git a/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/FedTSLauncher.java similarity index 68% rename from org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java rename to org.lflang/src/org/lflang/federated/launcher/FedTSLauncher.java index 87b7ffaeb1..67dbd134fa 100644 --- a/org.lflang/src/org/lflang/federated/launcher/TsBuildConfig.java +++ b/org.lflang/src/org/lflang/federated/launcher/FedTSLauncher.java @@ -36,24 +36,35 @@ * * @author Soroush Bateni * @author Hokeun Kim - * @author Marten Lohstroh */ -public class TsBuildConfig extends BuildConfig { +public class FedTSLauncher extends FedLauncher { - - public TsBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - super(federate, fileConfig, errorReporter); - } - - @Override - public String compileCommand() { - return null; + /** + * Create an instance of FedCLauncher. + * + * @param targetConfig The current target configuration. + * @param fileConfig The current file configuration. + * @param errorReporter A error reporter for reporting any errors or warnings during the code generation + */ + public FedTSLauncher( + TargetConfig targetConfig, + FedFileConfig fileConfig, + ErrorReporter errorReporter + ) { + super(targetConfig, fileConfig, errorReporter); } - + + /** + * Return the command that will execute a local federate, assuming that the current + * directory is the top-level project folder. This is used to create a launcher script + * for federates. + * + * @param federate The federate to execute. + */ @Override - public String localExecuteCommand() { + protected + String executeCommandForLocalFederate(FedFileConfig fileConfig, FederateInstance federate) { String jsFilename = federate.name + ".js"; return "node "+fileConfig.getSrcGenPath().resolve(federate.name).resolve("dist").resolve(jsFilename)+" -i $FEDERATION_ID"; } - } diff --git a/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java b/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java deleted file mode 100644 index 85d6dc4a0f..0000000000 --- a/org.lflang/src/org/lflang/federated/launcher/PyBuildConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.lflang.federated.launcher; - -import org.lflang.ErrorReporter; -import org.lflang.federated.generator.FedFileConfig; -import org.lflang.federated.generator.FederateInstance; - -public class PyBuildConfig extends BuildConfig { - - public PyBuildConfig(FederateInstance federate, FedFileConfig fileConfig, ErrorReporter errorReporter) { - super(federate, fileConfig, errorReporter); - } - - @Override - public String localExecuteCommand() { - return "python3 " + fileConfig.getSrcGenPath() + "/" + federate.name + "/" + federate.name+".py -i $FEDERATION_ID"; - } - - @Override - public String remoteExecuteCommand() { - return "python3 src-gen/"+fileConfig.name+"/"+federate.name+"/"+fileConfig.name+"_"+federate.name+" -i '$FEDERATION_ID'"; - } -} diff --git a/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java b/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java deleted file mode 100644 index 81c608d5b3..0000000000 --- a/org.lflang/src/org/lflang/federated/launcher/RtiConfig.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.lflang.federated.launcher; - -import java.nio.file.Path; - -/** - * Class for storing configuration settings pertaining to the RTI. - * @author Marten Lohstroh - */ -public class RtiConfig { - - private Path directory; - - /** - * The host on which the RTI process is to be spawned. - */ - private String host; - - /** - * The port on which to connect to the RTI process. - */ - private int port; - - /** - * The username used to gain access to the host where the RTI is to be spawned. - */ - private String user; - - /** - * Construct a new RTI configuration with all options set to their defaults. - */ - public RtiConfig() { - this.directory = Path.of("LinguaFrancaRemote"); - this.host = "localhost"; - this.port = 0; - } - - /** - * Return the directory to create on the remote host. - */ - public Path getDirectory() { - return directory; - } - - /** - * Return the host on which the RTI process is to be spawned. - */ - public String getHost() { - return host; - } - - /** - * Return the port on which to connect to the RTI process. - */ - public int getPort() { - return port; - } - - /** - * Return the username used to gain access to the host where the RTI is to be spawned. - */ - public String getUser() { - return user; - } - - /** - * Set the directory to create on the remote host. - */ - public void setDirectory(Path directory) { - this.directory = directory; - } - - /** - * Set the host on which the RTI process is to be spawned. - */ - public void setHost(String host) { - this.host = host; - } - - /** - * Set the port on which to connect to the RTI process. - */ - public void setPort(int port) { - this.port = port; - } - - /** - * Set the username used to gain access to the host where the RTI is to be spawned. - */ - public void setUser(String user) { - this.user = user; - } -} diff --git a/org.lflang/src/org/lflang/generator/CodeMap.java b/org.lflang/src/org/lflang/generator/CodeMap.java index d00fe9bc9a..12d5ea8f65 100644 --- a/org.lflang/src/org/lflang/generator/CodeMap.java +++ b/org.lflang/src/org/lflang/generator/CodeMap.java @@ -17,7 +17,6 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.util.LineAndColumn; -import org.lflang.lf.ParameterReference; import org.lflang.lf.impl.ParameterReferenceImpl; /** @@ -148,10 +147,6 @@ public static String tag(EObject astNode, String representation, boolean verbati oneBasedLfLineAndColumn.getLine(), oneBasedLfLineAndColumn.getColumn() ); final URI uri = bestEffortGetEResource(astNode).getURI(); - if (uri == null) { - // no EResource, no correspondence can be found - return representation; - } final Path lfPath = Path.of(uri.isFile() ? uri.toFileString() : uri.path()); if (verbatim) lfStart = lfStart.plus(node.getText().substring(0, indexOf(node.getText(), representation))); return new Correspondence( @@ -167,10 +162,12 @@ public static String tag(EObject astNode, String representation, boolean verbati * This is a dangerous operation which can cause an unrecoverable error. */ private static Resource bestEffortGetEResource(EObject astNode) { - if (astNode instanceof ParameterReference pri) { - return pri.getParameter().eResource(); - } - return astNode.eResource(); + if (astNode instanceof ParameterReferenceImpl pri) return pri.getParameter().eResource(); + Resource ret = astNode.eResource(); + if (ret != null) return ret; + throw new RuntimeException( + "Every non-null AST node should have an EResource, but \"" + astNode + "\" does not." + ); } /** diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index ba39a94d9f..95427b1175 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -47,15 +47,19 @@ import org.lflang.MainConflictChecker; import org.lflang.Target; import org.lflang.TargetConfig; +import org.lflang.TimeUnit; +import org.lflang.TimeValue; import org.lflang.ast.AstTransformation; import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Connection; +import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Mode; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; +import org.lflang.lf.Time; import org.lflang.validation.AbstractLFValidator; import com.google.common.base.Objects; @@ -171,7 +175,7 @@ public abstract class GeneratorBase extends AbstractLFValidator { /** * A list ot AST transformations to apply before code generation */ - private final List astTransformations = new ArrayList<>(); + private List astTransformations = new ArrayList(); /** * Create a new GeneratorBase object. @@ -263,6 +267,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { // to validate, which happens in setResources(). setReactorsAndInstantiationGraph(context.getMode()); + GeneratorUtils.validate(context, context.getFileConfig(), instantiationGraph, errorReporter); List allResources = GeneratorUtils.getResources(reactors); resources.addAll(allResources.stream() // FIXME: This filter reproduces the behavior of the method it replaces. But why must it be so complicated? Why are we worried about weird corner cases like this? .filter(it -> !Objects.equal(it, context.getFileConfig().resource) || mainDef != null && it == mainDef.getReactorClass().eResource()) @@ -414,6 +419,33 @@ public int getReactionBankIndex(Reaction reaction) { return reactionBankIndices.get(reaction); } + /** + * Given a representation of time that may possibly include units, return + * a string that the target language can recognize as a value. In this base + * class, if units are given, e.g. "msec", then we convert the units to upper + * case and return an expression of the form "MSEC(value)". Particular target + * generators will need to either define functions or macros for each possible + * time unit or override this method to return something acceptable to the + * target language. + * @param time A TimeValue that represents a time. + * @return A string, such as "MSEC(100)" for 100 milliseconds. + */ + public static String timeInTargetLanguage(TimeValue time) { + if (time != null) { + if (time.unit != null) { + return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; + } else { + return Long.valueOf(time.getMagnitude()).toString(); + } + } + return "0"; // FIXME: do this or throw exception? + } + + // note that this is moved out by #544 + public static String cMacroName(TimeUnit unit) { + return unit.getCanonicalName().toUpperCase(); + } + // ////////////////////////////////////////// // // Protected methods. @@ -643,4 +675,50 @@ public void printInfo(LFGeneratorContext.Mode mode) { */ public abstract Target getTarget(); + /** + * Get textual representation of a time in the target language. + * + * @param t A time AST node + * @return A time string in the target language + */ + // FIXME: this should be placed in ExpressionGenerator + public static String getTargetTime(Time t) { + TimeValue value = new TimeValue(t.getInterval(), TimeUnit.fromName(t.getUnit())); + return timeInTargetLanguage(value); + } + + /** + * Get textual representation of a value in the target language. + * + * If the value evaluates to 0, it is interpreted as a normal value. + * + * @param expr An AST node + * @return A string in the target language + */ + // FIXME: this should be placed in ExpressionGenerator + public static String getTargetValue(Expression expr) { + if (expr instanceof Time) { + return getTargetTime((Time)expr); + } + return ASTUtils.toText(expr); + } + + /** + * Get textual representation of a value in the target language. + * + * If the value evaluates to 0, it is interpreted as a time. + * + * @param expr A time AST node + * @return A time string in the target language + */ + // FIXME: this should be placed in ExpressionGenerator + public static String getTargetTime(Expression expr) { + if (expr instanceof Time) { + return getTargetTime((Time)expr); + } else if (ASTUtils.isZero(expr)) { + TimeValue value = TimeValue.ZERO; + return timeInTargetLanguage(value); + } + return ASTUtils.toText(expr); + } } diff --git a/org.lflang/src/org/lflang/generator/GeneratorUtils.java b/org.lflang/src/org/lflang/generator/GeneratorUtils.java index 92a57fd424..f51439c390 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/GeneratorUtils.java @@ -1,30 +1,50 @@ package org.lflang.generator; +import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Properties; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtext.xbase.lib.IteratorExtensions; +import org.eclipse.xtext.generator.IGeneratorContext; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.validation.CheckMode; +import org.eclipse.xtext.validation.IResourceValidator; +import org.eclipse.xtext.validation.Issue; import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.FileConfig; +import org.lflang.Target; import org.lflang.TargetConfig; -import org.lflang.TargetProperty; +import org.lflang.TargetConfig.DockerOptions; +import org.lflang.TargetProperty.BuildType; +import org.lflang.TargetProperty.LogLevel; +import org.lflang.TargetProperty.UnionType; import org.lflang.generator.LFGeneratorContext.Mode; +import org.lflang.TargetProperty; +import org.lflang.TargetProperty.SchedulerOption; +import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; +import org.lflang.lf.Import; import org.lflang.lf.Instantiation; import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; +import org.lflang.lf.Model; +import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.TargetDecl; +import org.lflang.util.FileUtil; /** * A helper class with functions that may be useful for code @@ -43,10 +63,81 @@ private GeneratorUtils() { /** * Return the target declaration found in the given resource. */ - public static TargetDecl findTargetDecl(Resource resource) { + public static TargetDecl findTarget(Resource resource) { return findAll(resource, TargetDecl.class).iterator().next(); } + /** + * Set the appropriate target properties based on the target properties of + * the main .lf file and the given command-line arguments, if applicable. + * @param args The commandline arguments to process. + * @param target The target properties AST node. + * @param errorReporter The error reporter to which errors should be sent. + */ + public static TargetConfig getTargetConfig( + Properties args, + TargetDecl target, + ErrorReporter errorReporter + ) { + final TargetConfig targetConfig = new TargetConfig(target); // FIXME: why not just do all of this in the constructor? + if (target.getConfig() != null) { + List pairs = target.getConfig().getPairs(); + TargetProperty.set(targetConfig, pairs != null ? pairs : List.of(), errorReporter); + } + if (args.containsKey("no-compile")) { + targetConfig.noCompile = true; + } + if (args.containsKey("docker")) { + var arg = args.getProperty("docker"); + if (Boolean.parseBoolean(arg)) { + targetConfig.dockerOptions = new DockerOptions(); + } else { + targetConfig.dockerOptions = null; + } + // FIXME: this is pretty ad-hoc and does not account for more complex overrides yet. + } + if (args.containsKey("build-type")) { + targetConfig.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION.forName(args.getProperty("build-type")); + } + if (args.containsKey("logging")) { + targetConfig.logLevel = LogLevel.valueOf(args.getProperty("logging").toUpperCase()); + } + if (args.containsKey("workers")) { + targetConfig.workers = Integer.parseInt(args.getProperty("workers")); + } + if (args.containsKey("threading")) { + targetConfig.threading = Boolean.parseBoolean(args.getProperty("threading")); + } + if (args.containsKey("target-compiler")) { + targetConfig.compiler = args.getProperty("target-compiler"); + } + if (args.containsKey("scheduler")) { + targetConfig.schedulerType = SchedulerOption.valueOf( + args.getProperty("scheduler") + ); + targetConfig.setByUser.add(TargetProperty.SCHEDULER); + } + if (args.containsKey("target-flags")) { + targetConfig.compilerFlags.clear(); + if (!args.getProperty("target-flags").isEmpty()) { + targetConfig.compilerFlags.addAll(List.of( + args.getProperty("target-flags").split(" ") + )); + } + } + if (args.containsKey("runtime-version")) { + targetConfig.runtimeVersion = args.getProperty("runtime-version"); + } + if (args.containsKey("external-runtime-path")) { + targetConfig.externalRuntimePath = args.getProperty("external-runtime-path"); + } + if (args.containsKey(TargetProperty.KEEPALIVE.description)) { + targetConfig.keepalive = Boolean.parseBoolean( + args.getProperty(TargetProperty.KEEPALIVE.description)); + } + return targetConfig; + } + /** * Look for physical actions in 'resource'. * If appropriate, set keepalive to true in @@ -65,9 +156,9 @@ public static void accommodatePhysicalActionsIfPresent( } for (Resource resource : resources) { for (Action action : findAll(resource, Action.class)) { - if (action.getOrigin() == ActionOrigin.PHYSICAL && + if (action.getOrigin() == ActionOrigin.PHYSICAL && // Check if the user has explicitly set keepalive to false - !targetConfig.setByUser.contains(TargetProperty.KEEPALIVE) && + !targetConfig.setByUser.contains(TargetProperty.KEEPALIVE) && !targetConfig.keepalive ) { // If not, set it to true @@ -97,7 +188,94 @@ public static void accommodatePhysicalActionsIfPresent( * {@code resource} */ public static Iterable findAll(Resource resource, Class nodeType) { - return () -> IteratorExtensions.filter(resource.getAllContents(), nodeType); + Iterator contents = resource.getAllContents(); + assert contents != null : "Although getAllContents is not marked as NotNull, it should be."; + EObject temp = null; + while (!nodeType.isInstance(temp) && contents.hasNext()) temp = contents.next(); + EObject next_ = temp; + return () -> new Iterator<>() { + EObject next = next_; + + @Override + public boolean hasNext() { + return nodeType.isInstance(next); + } + + @Override + public T next() { + // This cast is safe if hasNext() holds. + assert hasNext() : "next() was called on an Iterator when hasNext() was false."; + //noinspection unchecked + T current = (T) next; + next = null; + while (!nodeType.isInstance(next) && contents.hasNext()) next = contents.next(); + return current; + } + }; + } + + /** + * Validate the files containing reactors in the given + * {@code instantiationGraph}. If a file is imported by + * another file in the instantiation graph, propagate the + * resulting errors to the importing file. + * @param context The context providing the cancel + * indicator used by the validator. + * @param fileConfig The file system configuration. + * @param instantiationGraph A DAG containing all + * reactors of interest. + * @param errorReporter An error acceptor. + */ + public static void validate( + IGeneratorContext context, + FileConfig fileConfig, + InstantiationGraph instantiationGraph, + ErrorReporter errorReporter + ) { + // NOTE: This method was previously misnamed validateImports. + // It validates all files, including the main file that does the importing. + // Also, it is now the only invocation of validation during code generation, + // and yet it used to only report errors in the files doing the importing. + IResourceValidator validator = ((XtextResource) fileConfig.resource).getResourceServiceProvider() + .getResourceValidator(); + HashSet bad = new HashSet<>(); + HashSet visited = new HashSet<>(); + // The graph must be traversed in topological order so that errors will propagate through arbitrarily many + // levels. + for (Reactor reactor : instantiationGraph.nodesInTopologicalOrder()) { + Resource resource = reactor.eResource(); + if (visited.contains(resource)) continue; + visited.add(resource); + List issues = validator.validate(resource, CheckMode.ALL, context.getCancelIndicator()); + if ( + bad.contains(resource) || issues.size() > 0 + ) { + // Report the error on this resource. + Path path = null; + try { + path = FileUtil.toPath(resource); + } catch (IOException e) { + path = Paths.get("Unknown file"); // Not sure if this is what we want. + } + for (Issue issue : issues) { + errorReporter.reportError(path, issue.getLineNumber(), issue.getMessage()); + } + + // Report errors on resources that import this one. + for (Reactor downstreamReactor : instantiationGraph.getDownstreamAdjacentNodes(reactor)) { + for (Import importStatement : ((Model) downstreamReactor.eContainer()).getImports()) { + // FIXME: This will report the error on ALL import statements in + // file doing the importing, not just the one importing this resource. + // I have no idea how to determine which import statement is the right one. + errorReporter.reportError(importStatement, String.format( + "Unresolved compilation issues in '%s': " + + issues.toString(), importStatement.getImportURI() + )); + bad.add(downstreamReactor.eResource()); + } + } + } + } } /** diff --git a/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java b/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java deleted file mode 100644 index 2bb72789ff..0000000000 --- a/org.lflang/src/org/lflang/generator/LfExpressionVisitor.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2023, TU Dresden. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.lflang.generator; - -import org.lflang.lf.BracedListExpression; -import org.lflang.lf.Code; -import org.lflang.lf.CodeExpr; -import org.lflang.lf.Expression; -import org.lflang.lf.LfFactory; -import org.lflang.lf.Literal; -import org.lflang.lf.ParameterReference; -import org.lflang.lf.Time; - -/** - * A visitor for expressions in LF. - * - * @author Clément Fournier <clement.fournier@tu-dresden.de> - */ -public interface LfExpressionVisitor { - - - R visitLiteral(Literal expr, P param); - - R visitBracedListExpr(BracedListExpression expr, P param); - - R visitTimeLiteral(Time expr, P param); - - R visitCodeExpr(CodeExpr expr, P param); - - R visitParameterRef(ParameterReference expr, P param); - - /** - * Dispatch the visitor on the given expression type. - * - * @param e An expression that will be visited - * @param arg Argument for the visitor - * @param visitor Visitor - * @param

Type of parameter expected by the visitor - * @param Return type of the visitor - * @return The return value of the visitor - */ - static R dispatch(Expression e, P arg, LfExpressionVisitor visitor) { - if (e instanceof Literal) { - return visitor.visitLiteral((Literal) e, arg); - } else if (e instanceof BracedListExpression) { - return visitor.visitBracedListExpr((BracedListExpression) e, arg); - } else if (e instanceof Time) { - return visitor.visitTimeLiteral((Time) e, arg); - } else if (e instanceof CodeExpr) { - return visitor.visitCodeExpr((CodeExpr) e, arg); - } else if (e instanceof ParameterReference) { - return visitor.visitParameterRef((ParameterReference) e, arg); - } - - throw new IllegalArgumentException("Expression of type " + e.getClass() + " not handled"); - } - - /** Base visitor class where methods are defaulted to a common one. */ - abstract class DefaultLfVisitor implements LfExpressionVisitor { - - abstract R visitExpression(Expression expr, P param); - - @Override - public R visitLiteral(Literal expr, P param) { - return visitExpression(expr, param); - } - - @Override - public R visitBracedListExpr(BracedListExpression expr, P param) { - return visitExpression(expr, param); - } - - @Override - public R visitTimeLiteral(Time expr, P param) { - return visitExpression(expr, param); - } - - @Override - public R visitCodeExpr(CodeExpr expr, P param) { - return visitExpression(expr, param); - } - - @Override - public R visitParameterRef(ParameterReference expr, P param) { - return visitExpression(expr, param); - } - } - - /** - * A visitor that deep copies the expression. Can be extended - * to replace certain expressions during the copy. - * - * @param

Parameter type - */ - class LfExpressionDeepCopyVisitor

implements LfExpressionVisitor { - - @Override - public Expression visitLiteral(Literal expr, P param) { - Literal clone = LfFactory.eINSTANCE.createLiteral(); - clone.setLiteral(expr.getLiteral()); - return clone; - } - - @Override - public Expression visitBracedListExpr(BracedListExpression expr, P param) { - BracedListExpression clone = LfFactory.eINSTANCE.createBracedListExpression(); - for (Expression item : expr.getItems()) { - clone.getItems().add(dispatch(item, param, this)); - } - return clone; - } - - @Override - public Expression visitTimeLiteral(Time expr, P param) { - Time clone = LfFactory.eINSTANCE.createTime(); - clone.setUnit(expr.getUnit()); - clone.setInterval(expr.getInterval()); - return clone; - } - - @Override - public Expression visitParameterRef(ParameterReference expr, P param) { - ParameterReference clone = LfFactory.eINSTANCE.createParameterReference(); - clone.setParameter(expr.getParameter()); - return clone; - } - - @Override - public Expression visitCodeExpr(CodeExpr expr, P param) { - CodeExpr codeExpr = LfFactory.eINSTANCE.createCodeExpr(); - Code code = LfFactory.eINSTANCE.createCode(); - code.setBody(expr.getCode().getBody()); - codeExpr.setCode(code); - return codeExpr; - } - } - -} diff --git a/org.lflang/src/org/lflang/generator/MainContext.java b/org.lflang/src/org/lflang/generator/MainContext.java index 5ee53e5f83..e7d442e1d3 100644 --- a/org.lflang/src/org/lflang/generator/MainContext.java +++ b/org.lflang/src/org/lflang/generator/MainContext.java @@ -163,8 +163,8 @@ public void reportProgress(String message, int percentage) { * reflected in the target configuration. */ public void loadTargetConfig() { - this.targetConfig = new TargetConfig( - args, GeneratorUtils.findTargetDecl(fileConfig.resource), errorReporter + this.targetConfig = GeneratorUtils.getTargetConfig( + args, GeneratorUtils.findTarget(fileConfig.resource), errorReporter ); } } diff --git a/org.lflang/src/org/lflang/generator/ParameterInstance.java b/org.lflang/src/org/lflang/generator/ParameterInstance.java index 9287710e6b..9da4f1f247 100644 --- a/org.lflang/src/org/lflang/generator/ParameterInstance.java +++ b/org.lflang/src/org/lflang/generator/ParameterInstance.java @@ -30,12 +30,10 @@ import java.util.List; import java.util.Optional; -import org.lflang.ASTUtils; import org.lflang.InferredType; +import org.lflang.ASTUtils; import org.lflang.lf.Assignment; import org.lflang.lf.Expression; -import org.lflang.lf.Initializer; -import org.lflang.lf.LfFactory; import org.lflang.lf.Parameter; /** @@ -73,26 +71,13 @@ public ParameterInstance(Parameter definition, ReactorInstance parent) { //// Public Methods /** - * Get the initial value of this parameter. + * Get the initial value(s) of this parameter as a list of + * Value objects, where each Value is either an instance + * of Time, Literal, or Code. That is, references to other + * parameters have been replaced with their initial values. */ - private Initializer getInitialValue() { - return definition.getInit(); - } - - /** - * Return the (possibly overridden) value of this parameter - * in the containing instance. Parameter references are resolved - * to actual expressions. - */ - public Initializer getActualValue() { - Assignment override = getOverride(); - Initializer init; - if (override != null) { - init = override.getRhs(); - } else { - init = getInitialValue(); - } - return init; + public List getInitialValue() { + return parent.initialParameterValue(this.definition); } /** diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 709c4ac012..305ef420c4 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -26,9 +26,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator; -import static org.lflang.ASTUtils.belongsTo; -import static org.lflang.ASTUtils.getLiteralTimeValue; - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -36,7 +33,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.eclipse.emf.ecore.util.EcoreUtil; @@ -47,12 +43,10 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.TimeValue; import org.lflang.generator.TriggerInstance.BuiltinTriggerVariable; import org.lflang.lf.Action; -import org.lflang.lf.Assignment; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.Connection; import org.lflang.lf.Expression; -import org.lflang.lf.Initializer; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; @@ -452,50 +446,29 @@ public boolean hasCycles() { */ public Integer initialIntParameterValue(Parameter parameter) { return ASTUtils.initialValueInt(parameter, instantiations()); - } - - public Expression resolveParameters(Expression e) { - return LfExpressionVisitor.dispatch(e, this, ParameterInliner.INSTANCE); - } - - - private static final class ParameterInliner extends LfExpressionVisitor.LfExpressionDeepCopyVisitor { - static final ParameterInliner INSTANCE = new ParameterInliner(); + } - @Override - public Expression visitParameterRef(ParameterReference expr, ReactorInstance instance) { - if (!ASTUtils.belongsTo(expr.getParameter(), instance.definition)) { - throw new IllegalArgumentException("Parameter " - + expr.getParameter().getName() - + " is not a parameter of reactor instance " - + instance.getName() - + "." - ); - } - - Optional assignment = - instance.definition.getParameters().stream() - .filter(it -> it.getLhs().equals(expr.getParameter())) - .findAny(); // There is at most one - - if (assignment.isPresent()) { - // replace the parameter with its value. - Expression value = ASTUtils.asSingleExpr(assignment.get().getRhs()); - // recursively resolve parameters - return instance.getParent().resolveParameters(value); - } else { - // In that case use the default value. Default values - // cannot use parameter values, so they don't need to - // be recursively resolved. - Initializer init = expr.getParameter().getInit(); - Expression defaultValue = ASTUtils.asSingleExpr(init); - if (defaultValue == null) { - // this is a problem - return super.visitParameterRef(expr, instance); - } - return defaultValue; - } - } + /** + * Given a parameter definition for this reactor, return the initial value + * of the parameter. If the parameter is overridden when instantiating + * this reactor or any of its containing reactors, use that value. + * Otherwise, use the default value in the reactor definition. + * + * The returned list of Value objects is such that each element is an + * instance of Time, String, or Code, never Parameter. + * For most uses, this list has only one element, but parameter + * values can be lists of elements, so the returned value is a list. + * + * @param parameter The parameter definition (a syntactic object in the AST). + * + * @return A list of Value objects, or null if the parameter is not found. + * Return an empty list if no initial value is given. + * Each value is an instance of Literal if a literal value is given, + * a Time if a time value was given, or a Code, if a code value was + * given (text in the target language delimited by {= ... =} + */ + public List initialParameterValue(Parameter parameter) { + return ASTUtils.initialValue(parameter, instantiations()); } /** @@ -708,8 +681,14 @@ public String toString() { * precise time value assigned to this reactor instance. */ public TimeValue getTimeValue(Expression expr) { - Expression resolved = resolveParameters(expr); - return getLiteralTimeValue(resolved); + if (expr instanceof ParameterReference) { + final var param = ((ParameterReference)expr).getParameter(); + // Avoid a runtime error in validator for invalid programs. + if (lookupParameterInstance(param).getInitialValue().isEmpty()) return null; + return ASTUtils.getLiteralTimeValue(lookupParameterInstance(param).getInitialValue().get(0)); + } else { + return ASTUtils.getLiteralTimeValue(expr); + } } ////////////////////////////////////////////////////// @@ -767,8 +746,12 @@ protected void createReactionInstances() { /** * Returns the built-in trigger or create a new one if none exists. */ - protected TriggerInstance getOrCreateBuiltinTrigger(BuiltinTriggerRef trigger) { - return builtinTriggers.computeIfAbsent(trigger.getType(), ref -> TriggerInstance.builtinTrigger(trigger, this)); + protected TriggerInstance getOrCreateBuiltinTrigger(BuiltinTriggerRef trigger) { + if (!builtinTriggers.containsKey(trigger.getType())) { + builtinTriggers.put(trigger.getType(), + new TriggerInstance<>(trigger.getType(), trigger, this)); + } + return builtinTriggers.get(trigger.getType()); } //////////////////////////////////////// diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/src/org/lflang/generator/TargetTypes.java index 8d9788e19e..cb7f87d91e 100644 --- a/org.lflang/src/org/lflang/generator/TargetTypes.java +++ b/org.lflang/src/org/lflang/generator/TargetTypes.java @@ -8,7 +8,6 @@ import org.lflang.InferredType; import org.lflang.TimeValue; import org.lflang.lf.Action; -import org.lflang.lf.BracedListExpression; import org.lflang.lf.CodeExpr; import org.lflang.lf.Expression; import org.lflang.lf.Initializer; @@ -69,13 +68,6 @@ default String getTargetParamRef(ParameterReference expr, InferredType typeOrNul return escapeIdentifier(expr.getParameter().getName()); } - /** Translate the braced list expression into target language syntax. */ - default String getTargetBracedListExpr(BracedListExpression expr, InferredType typeOrNull) { - InferredType t = typeOrNull == null ? InferredType.undefined() : typeOrNull; - return expr.getItems().stream().map(e -> getTargetExpr(e, t)) - .collect(Collectors.joining(",", "{", "}")); - } - /** * Return an "undefined" type which is used as a default * when a type cannot be inferred. @@ -174,19 +166,10 @@ default String getTargetType(InferredType type) { return getTargetFixedSizeListType(type.baseType(), type.listSize); } else if (type.isVariableSizeList) { return getTargetVariableSizeListType(type.baseType()); - } else if (!type.astType.getTypeArgs().isEmpty()) { - List args = type.astType.getTypeArgs().stream().map(this::getTargetType).toList(); - return getGenericType(type.baseType(), args); } return type.toOriginalText(); } - /** Build a generic type. The type args list must not be empty. */ - default String getGenericType(String base, List args) { - assert !args.isEmpty() : "Empty type arguments for " + base; - return base + "<" + String.join(", ", args) + ">"; - } - /** * Return a string representing the type of the given * parameter. @@ -239,8 +222,10 @@ default String getTargetInitializer(Initializer init, Type type) { var targetValues = init.getExprs().stream().map(it -> getTargetExpr(it, inferredType)).collect(Collectors.toList()); if (inferredType.isFixedSizeList) { return getFixedSizeListInitExpression(targetValues, inferredType.listSize, init.isBraces()); - } else { + } else if (inferredType.isVariableSizeList) { return getVariableSizeListInitExpression(targetValues, init.isBraces()); + } else { + return getMissingExpr(inferredType); } } @@ -260,8 +245,6 @@ default String getTargetExpr(Expression expr, InferredType type) { return ASTUtils.addZeroToLeadingDot(((Literal) expr).getLiteral()); // here we don't escape } else if (expr instanceof CodeExpr) { return ASTUtils.toText(((CodeExpr) expr).getCode()); - } else if (expr instanceof BracedListExpression) { - return getTargetBracedListExpr((BracedListExpression) expr, type); } else { throw new IllegalStateException("Invalid value " + expr); } diff --git a/org.lflang/src/org/lflang/generator/TriggerInstance.java b/org.lflang/src/org/lflang/generator/TriggerInstance.java index 47212ff0e8..e0342ff853 100644 --- a/org.lflang/src/org/lflang/generator/TriggerInstance.java +++ b/org.lflang/src/org/lflang/generator/TriggerInstance.java @@ -30,19 +30,18 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import java.util.Set; import org.lflang.lf.BuiltinTrigger; -import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.TriggerRef; import org.lflang.lf.Variable; import org.lflang.lf.impl.VariableImpl; /** Instance of a trigger (port, action, or timer). - * + * * @author Marten Lohstroh * @author Edward A. Lee * @author Alexander Schulz-Rosengarten */ public class TriggerInstance extends NamedInstance { - + /** Construct a new instance with the specified definition * and parent. E.g., for a action instance, the definition * is Action, and for a port instance, it is Port. These are @@ -54,21 +53,33 @@ public class TriggerInstance extends NamedInstance { protected TriggerInstance(T definition, ReactorInstance parent) { super(definition, parent); } - + /** * Construct a new instance for a special builtin trigger. - * - * @param trigger The actual trigger definition. + * This constructor must be used with Variable or BuiltinTriggerVariable + * as generic type T. + * + * @param type The builtin trigger type. + * @param type The actual trigger definition. * @param parent The reactor instance that creates this instance. */ - static TriggerInstance builtinTrigger(BuiltinTriggerRef trigger, ReactorInstance parent) { - return new TriggerInstance<>(new BuiltinTriggerVariable(trigger), parent); + public TriggerInstance(BuiltinTrigger type, TriggerRef trigger, ReactorInstance parent) { + super((T)(new BuiltinTriggerVariable(type, trigger)), parent); + builtinTriggerType = type; } - + ///////////////////////////////////////////// //// Public Methods /** + * Return the built-in trigger type or null if this is not a + * built-in trigger. + */ + public BuiltinTrigger getBuiltinTriggerType() { + return builtinTriggerType; + } + + /** * Return the reaction instances that are triggered or read by this trigger. * If this port is an output, then the reaction instances * belong to the parent of the port's parent. If the port @@ -79,18 +90,18 @@ public Set getDependentReactions() { return dependentReactions; } - /** + /** * Return the reaction instances that may send data via this port. * If this port is an input, then the reaction instance * belongs to parent of the port's parent. If it is an output, - * the reaction instance belongs to the port's parent. + * the the reaction instance belongs to the port's parent. */ public Set getDependsOnReactions() { return dependsOnReactions; - } - - /** - * Return the name of this trigger. + }; + + /** + * Return the name of this trigger. * @return The name of this trigger. */ @Override @@ -102,52 +113,52 @@ public String getName() { * Return true if this trigger is "shutdown". */ public boolean isShutdown() { - return isBuiltInType(BuiltinTrigger.SHUTDOWN); + return builtinTriggerType == BuiltinTrigger.SHUTDOWN; } /** * Return true if this trigger is "startup"./ */ public boolean isStartup() { - return isBuiltInType(BuiltinTrigger.STARTUP); + return builtinTriggerType == BuiltinTrigger.STARTUP; } /** * Return true if this trigger is "startup"./ */ public boolean isReset() { - return isBuiltInType(BuiltinTrigger.RESET); + return builtinTriggerType == BuiltinTrigger.RESET; } - ///////////////////////////////////////////// - //// Private Methods - - private boolean isBuiltInType(BuiltinTrigger type) { - return this.definition instanceof BuiltinTriggerVariable - && ((BuiltinTriggerRef) ((BuiltinTriggerVariable) this.definition).definition).getType().equals(type); + /** + * Return true if this trigger is a builtin one. + */ + public boolean isBuiltinTrigger() { + return builtinTriggerType != null; } ///////////////////////////////////////////// //// Protected Fields - - - /** + + BuiltinTrigger builtinTriggerType = null; + + /** * Reaction instances that are triggered or read by this trigger. * If this port is an output, then the reaction instances * belong to the parent of the port's parent. If the port * is an input, then the reaction instances belong to the * port's parent. */ - Set dependentReactions = new LinkedHashSet<>(); + Set dependentReactions = new LinkedHashSet(); - /** + /** * Reaction instances that may send data via this port. * If this port is an input, then the reaction instance * belongs to parent of the port's parent. If it is an output, - * the reaction instance belongs to the port's parent. + * the the reaction instance belongs to the port's parent. */ - Set dependsOnReactions = new LinkedHashSet<>(); - + Set dependsOnReactions = new LinkedHashSet(); + ///////////////////////////////////////////// //// Special class for builtin triggers @@ -155,23 +166,23 @@ private boolean isBuiltInType(BuiltinTrigger type) { * This class allows to have BuiltinTriggers represented by a Variable type. */ static public class BuiltinTriggerVariable extends VariableImpl { - + /** The builtin trigger type represented by this variable. */ public final BuiltinTrigger type; - + /** The actual TriggerRef definition in the AST. */ public final TriggerRef definition; - - public BuiltinTriggerVariable(BuiltinTriggerRef trigger) { - this.type = trigger.getType(); + + public BuiltinTriggerVariable(BuiltinTrigger type, TriggerRef trigger) { + this.type = type; this.definition = trigger; } - + @Override public String getName() { return this.type.name().toLowerCase(); } - + @Override public void setName(String newName) { throw new UnsupportedOperationException( diff --git a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java index 1c4a1b45e8..e800328e18 100644 --- a/org.lflang/src/org/lflang/generator/c/CActionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CActionGenerator.java @@ -4,8 +4,10 @@ import java.util.ArrayList; import org.lflang.ASTUtils; import org.lflang.Target; +import org.lflang.federated.generator.FederateInstance; import org.lflang.generator.ActionInstance; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.GeneratorBase; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Action; import org.lflang.lf.Reactor; @@ -38,10 +40,9 @@ public static String generateInitializers( var triggerStructName = CUtil.reactorRef(action.getParent()) + "->_lf__" + action.getName(); var minDelay = action.getMinDelay(); var minSpacing = action.getMinSpacing(); - var offsetInitializer = triggerStructName+".offset = " + CTypes.getInstance().getTargetTimeExpr(minDelay) - + ";"; + var offsetInitializer = triggerStructName+".offset = " + GeneratorBase.timeInTargetLanguage(minDelay) + ";"; var periodInitializer = triggerStructName+".period = " + (minSpacing != null ? - CTypes.getInstance().getTargetTimeExpr(minSpacing) : + GeneratorBase.timeInTargetLanguage(minSpacing) : CGenerator.UNDEFINED_MIN_SPACING) + ";"; code.addAll(List.of( "// Initializing action "+action.getFullName(), diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 6710a0eb68..a2ae9899bf 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -194,6 +194,11 @@ CodeBuilder generateCMakeCode( if (targetConfig.platformOptions.platform != Platform.AUTO) { cMakeCode.pr("set(CMAKE_SYSTEM_NAME "+targetConfig.platformOptions.platform.getcMakeName()+")"); } + + cMakeCode.pr("# Target definitions\n"); + targetConfig.compileDefinitions.forEach((key, value) -> cMakeCode.pr( + "add_compile_definitions("+key+"="+value+")\n" + )); cMakeCode.newLine(); if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 34a7118135..faa6e5fb0c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -387,9 +387,9 @@ public CGenerator(LFGeneratorContext context, boolean ccppMode) { this( context, ccppMode, - new CTypes(), + new CTypes(context.getErrorReporter()), new CCmakeGenerator(context.getFileConfig(), List.of()), - new CDelayBodyGenerator(new CTypes()) + new CDelayBodyGenerator(new CTypes(context.getErrorReporter())) ); } @@ -1809,7 +1809,7 @@ private void generateSetDeadline(ReactorInstance instance) { var selfRef = CUtil.reactorRef(reaction.getParent())+"->_lf__reaction_"+reaction.index; if (reaction.declaredDeadline != null) { var deadline = reaction.declaredDeadline.maxDelay; - initializeTriggerObjects.pr(selfRef+".deadline = "+types.getTargetTimeExpr(deadline)+";"); + initializeTriggerObjects.pr(selfRef+".deadline = "+GeneratorBase.timeInTargetLanguage(deadline)+";"); } else { // No deadline. initializeTriggerObjects.pr(selfRef+".deadline = NEVER;"); } diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index 1534f0ea02..23906eae73 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -1,16 +1,15 @@ package org.lflang.generator.c; +import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; - -import org.lflang.InferredType; import org.lflang.generator.ParameterInstance; import org.lflang.ASTUtils; import org.lflang.generator.CodeBuilder; +import org.lflang.generator.GeneratorBase; import org.lflang.lf.Assignment; import org.lflang.lf.Expression; -import org.lflang.lf.Initializer; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; /** @@ -33,9 +32,46 @@ public static String getInitializer(ParameterInstance p) { return CUtil.bankIndex(p.getParent()); } - CTypes ctypes = CTypes.generateParametersIn(p.getParent().getParent()); - Initializer values = p.getActualValue(); - return ctypes.getTargetInitializer(values, p.getDefinition().getType()); + // Handle overrides in the intantiation. + // In case there is more than one assignment to this parameter, we need to + // find the last one. + Assignment lastAssignment = null; + for (Assignment assignment: p.getParent().getDefinition().getParameters()) { + if (assignment.getLhs() == p.getDefinition()) { + lastAssignment = assignment; + } + } + List list = new LinkedList<>(); + if (lastAssignment != null) { + // The parameter has an assignment. + // Right hand side can be a list. Collect the entries. + for (Expression expr: lastAssignment.getRhs().getExprs()) { + if (expr instanceof ParameterReference) { + // The parameter is being assigned a parameter value. + // Assume that parameter belongs to the parent's parent. + // This should have been checked by the validator. + final var param = ((ParameterReference) expr).getParameter(); + list.add(CUtil.reactorRef(p.getParent().getParent()) + "->" + param.getName()); + } else { + list.add(GeneratorBase.getTargetTime(expr)); + } + } + } else { + // there was no assignment in the instantiation. So just use the + // parameter's initial value. + for (Expression expr : p.getParent().initialParameterValue(p.getDefinition())) { + if (ASTUtils.isOfTimeType(p.getDefinition())) { + list.add(GeneratorBase.getTargetTime(expr)); + } else { + list.add(GeneratorBase.getTargetTime(expr)); + } + } + } + if (list.size() == 1) { + return list.get(0); + } else { + return "{" + String.join(", ", list) + "}"; + } } /** diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index 46910f4167..a0bcf28823 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -3,7 +3,6 @@ import java.util.LinkedList; import org.lflang.ASTUtils; -import org.lflang.InferredType; import org.lflang.generator.CodeBuilder; import org.lflang.generator.GeneratorBase; import org.lflang.generator.ModeInstance; @@ -127,7 +126,17 @@ private static String generateModalReset( * references are replaced with accesses to the self struct of the parent. */ private static String getInitializerExpr(StateVar state, ReactorInstance parent) { - var ctypes = CTypes.generateParametersIn(parent); - return ctypes.getTargetInitializer(state.getInit(), state.getType()); + var list = new LinkedList(); + for (Expression expr : state.getInit().getExprs()) { + if (expr instanceof ParameterReference) { + final var param = ((ParameterReference)expr).getParameter(); + list.add(CUtil.reactorRef(parent) + "->" + param.getName()); + } else { + list.add(GeneratorBase.getTargetTime(expr)); + } + } + return list.size() == 1 ? + list.get(0) : + "{" + String.join(", ", list) + "}"; } } diff --git a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java index 75623fdfe7..e0c2000e87 100644 --- a/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTimerGenerator.java @@ -1,7 +1,7 @@ package org.lflang.generator.c; import java.util.List; - +import org.lflang.generator.GeneratorBase; import org.lflang.generator.TimerInstance; /** @@ -18,8 +18,8 @@ public class CTimerGenerator { */ public static String generateInitializer(TimerInstance timer) { var triggerStructName = CUtil.reactorRef(timer.getParent()) + "->_lf__" + timer.getName(); - var offset = CTypes.getInstance().getTargetTimeExpr(timer.getOffset()); - var period = CTypes.getInstance().getTargetTimeExpr(timer.getPeriod()); + var offset = GeneratorBase.timeInTargetLanguage(timer.getOffset()); + var period = GeneratorBase.timeInTargetLanguage(timer.getPeriod()); var mode = timer.getMode(false); var modeRef = mode != null ? "&"+CUtil.reactorRef(mode.getParent())+"->_lf__modes["+mode.getParent().modes.indexOf(mode)+"];" : diff --git a/org.lflang/src/org/lflang/generator/c/CTypes.java b/org.lflang/src/org/lflang/generator/c/CTypes.java index ba5b3631a9..803d9e8432 100644 --- a/org.lflang/src/org/lflang/generator/c/CTypes.java +++ b/org.lflang/src/org/lflang/generator/c/CTypes.java @@ -1,18 +1,11 @@ package org.lflang.generator.c; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; +import org.lflang.ErrorReporter; import org.lflang.InferredType; -import org.lflang.TimeUnit; -import org.lflang.TimeValue; -import org.lflang.generator.ReactorInstance; import org.lflang.generator.TargetTypes; -import org.lflang.lf.Initializer; -import org.lflang.lf.ParameterReference; -import org.lflang.lf.Type; public class CTypes implements TargetTypes { @@ -20,9 +13,20 @@ public class CTypes implements TargetTypes { // For example, for "foo[10]", the first match will be "foo" and the second "[10]". // For "foo[]", the first match will be "foo" and the second "". static final Pattern arrayPattern = Pattern.compile("^\\s*(?:/\\*.*?\\*/)?\\s*(\\w+)\\s*\\[([0-9]*)]\\s*$"); - private static final CTypes INSTANCE = new CTypes(); - public CTypes() { + // FIXME: Instead of using the ErrorReporter, perhaps we should be raising assertion errors or + // UnsupportedOperationExceptions or some other non-recoverable errors. + private final ErrorReporter errorReporter; + + /** + * Initializes a {@code CTargetTypes} with the given + * error reporter. + * @param errorReporter The error reporter for any + * errors raised in the code + * generation process. + */ + public CTypes(ErrorReporter errorReporter) { + this.errorReporter = errorReporter; } @Override @@ -52,7 +56,7 @@ public String getTargetVariableSizeListType(String baseType) { @Override public String getTargetUndefinedType() { - return "/*undefined*/"; + return String.format("/* %s */", errorReporter.reportError("undefined type")); } /** @@ -74,33 +78,6 @@ public String getTargetType(InferredType type) { return result; } - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - throw new UnsupportedOperationException("No context defined"); - } - - @Override - public String getTargetTimeExpr(TimeValue time) { - if (time != null) { - if (time.unit != null) { - return cMacroName(time.unit) + "(" + time.getMagnitude() + ")"; - } else { - return Long.valueOf(time.getMagnitude()).toString(); - } - } - return "0"; // FIXME: do this or throw exception? - } - - @Override - public String getFixedSizeListInitExpression(List contents, int listSize, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); - } - - @Override - public String getVariableSizeListInitExpression(List contents, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "{ ", " }")); - } - /** * Return a variable declaration of the form "{@code type name}". * The type is as returned by {@link #getTargetType(InferredType)}, except with @@ -142,23 +119,4 @@ public String getVariableDeclaration( } return declaration; } - - // note that this is moved out by #544 - public static String cMacroName(TimeUnit unit) { - return unit.getCanonicalName().toUpperCase(); - } - - public static CTypes getInstance() { - return INSTANCE; - } - - - public static CTypes generateParametersIn(ReactorInstance instance) { - return new CTypes() { - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - return CUtil.reactorRef(instance) + "->" + expr.getParameter().getName(); - } - }; - } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt index 1fab68f39d..4aee21202f 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppInstanceGenerator.kt @@ -46,7 +46,7 @@ class CppInstanceGenerator( val Instantiation.cppType: String get() { return if (reactor.isGeneric) - """${reactor.name}<${typeArgs.joinToString(", ") { it.toText() }}>""" + """${reactor.name}<${typeParms.joinToString(", ") { it.toText() }}>""" else reactor.name } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt index 3c2224e031..a460290287 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt @@ -40,28 +40,32 @@ class CppParameterGenerator(private val reactor: Reactor) { val Parameter.typeAlias get(): String = "__lf_${name}_t" } + /** Generate all constructor initializers for parameters */ + fun generateInitializers() = + reactor.parameters.joinWithLn(prefix = "// parameters\n") { + ", ${it.name}(parameters.${it.name})" + } + /** Generate all parameter declarations as used in the parameter struct */ fun generateParameterStructDeclarations() = reactor.parameters.joinToString("\n", postfix = "\n") { with(it) { """ using $typeAlias = $targetType; - $typeAlias $name${ - if (init == null) "" else CppTypes.getCppInitializer( + const $typeAlias $name${ + if (init == null) "" else " = " + typeAlias + CppTypes.getCppInitializer( init, - inferredType, - typeAlias = typeAlias + inferredType ) }; """.trimIndent() } } - /** Generate alias declarations for each parameter for use in the inner reactor class. - * This is required to bring parameters into scope. + /** Generate using declarations for each parameter for use in the inner reactor class. + * This is required for C++ to bring templated parameters into scope. */ - fun generateInnerAliasDeclarations() = - reactor.parameters.joinToString(separator = "") { "const typename Parameters::${it.typeAlias}& ${it.name} = __lf_parameters.${it.name};\n" } + fun generateUsingDeclarations() = reactor.parameters.joinToString(separator = "") { "using Parameters::${it.name};\n" } /** Generate alias declarations for each parameter for use in the outer reactor class. * This is required for some code bodies (e.g. target code in parameter initializers) to have access to the local parameters. diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt index 50fff0bdb5..de8deb7a4f 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt @@ -94,9 +94,8 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi | private: ${" | "..reactions.generateReactionViewForwardDeclarations()} | - | class Inner: public lfutil::LFScope { - | const Parameters __lf_parameters; - ${" | "..parameters.generateInnerAliasDeclarations()} + | class Inner: public lfutil::LFScope, public Parameters { + ${" | "..parameters.generateUsingDeclarations()} ${" | "..state.generateDeclarations()} ${" | "..methods.generateDeclarations()} ${" | "..reactions.generateBodyDeclarations()} @@ -162,9 +161,9 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi return with(PrependOperator) { """ |${reactor.templateLine} - |${reactor.templateName}::Inner::Inner(::reactor::Reactor* reactor, Parameters&& parameters) + |${reactor.templateName}::Inner::Inner(::reactor::Reactor* reactor, Parameters&& __lf_parameters) | : LFScope(reactor) - ${" | , __lf_parameters(std::forward(parameters))"} + ${" | , Parameters(std::forward(__lf_parameters))"} ${" | "..state.generateInitializers()} |{} """.trimMargin() diff --git a/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt index 22e3c3045a..064f6758f8 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt @@ -59,13 +59,14 @@ class CppRos2NodeGenerator( | : Node("$nodeName", node_options) { | unsigned workers = ${if (targetConfig.workers != 0) targetConfig.workers else "std::thread::hardware_concurrency()"}; | bool fast{${targetConfig.fastMode}}; + | bool keepalive{${targetConfig.keepalive}}; | reactor::Duration lf_timeout{${targetConfig.timeout?.toCppCode() ?: "reactor::Duration::max()"}}; | | // provide a globally accessible reference to this node | // FIXME: this is pretty hacky... | lf_node = this; | - | lf_env = std::make_unique(workers, fast, lf_timeout); + | lf_env = std::make_unique(workers, keepalive, fast, lf_timeout); | | // instantiate the main reactor | lf_main_reactor = std::make_unique<${main.name}> ("${main.name}", lf_env.get(), ${main.name}::Parameters{}); diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt index 07cd3f8ba2..171b59c485 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt @@ -60,6 +60,7 @@ class CppStandaloneMainGenerator( | | unsigned workers = ${if (targetConfig.workers != 0) targetConfig.workers else "std::thread::hardware_concurrency()"}; | bool fast{${targetConfig.fastMode}}; + | bool keepalive{${targetConfig.keepalive}}; | reactor::Duration timeout = ${targetConfig.timeout?.toCppCode() ?: "reactor::Duration::max()"}; | | // the timeout variable needs to be tested beyond fitting the Duration-type @@ -68,6 +69,7 @@ class CppStandaloneMainGenerator( | .add_options() | ("w,workers", "the number of worker threads used by the scheduler", cxxopts::value(workers)->default_value(std::to_string(workers)), "'unsigned'") | ("o,timeout", "Time after which the execution is aborted.", cxxopts::value(timeout)->default_value(time_to_string(timeout)), "'FLOAT UNIT'") + | ("k,keepalive", "Continue execution even when there are no events to process.", cxxopts::value(keepalive)->default_value("${targetConfig.keepalive}")) | ("f,fast", "Allow logical time to run faster than physical time.", cxxopts::value(fast)->default_value("${targetConfig.fastMode}")) | ("help", "Print help"); | @@ -89,7 +91,7 @@ class CppStandaloneMainGenerator( | return parse_error ? -1 : 0; | } | - | reactor::Environment e{workers, fast, timeout}; + | reactor::Environment e{workers, keepalive, fast, timeout}; | | // instantiate the main reactor | ${generateMainReactorInstantiation()} diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt index 1d5050fee9..4b26328155 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt @@ -42,6 +42,6 @@ class CppStateGenerator(private val reactor: Reactor) { fun generateInitializers(): String = reactor.stateVars.filter { it.isInitialized } .joinWithLn(prefix = "// state variables\n") { - ", " + it.name + CppTypes.getCppInitializer(it.init, it.inferredType, disableEquals = true) + ", " + it.name + CppTypes.getCppInitializer(it.init, it.inferredType) } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt b/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt index 6a908392ab..e0a7103f20 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppTypes.kt @@ -28,7 +28,6 @@ import org.lflang.InferredType import org.lflang.TimeUnit import org.lflang.TimeValue import org.lflang.generator.TargetTypes -import org.lflang.joinWithCommas import org.lflang.lf.Initializer import org.lflang.lf.ParameterReference @@ -72,24 +71,14 @@ val TimeUnit?.cppUnit /** * Returns a C++ variable initializer. */ -fun CppTypes.getCppInitializer( - init: Initializer?, - inferredType: InferredType, - disableEquals: Boolean = false, - typeAlias: String? = null -): String = - if (init == null) { +fun CppTypes.getCppInitializer(init: Initializer?, inferredType: InferredType): String { + return if (init == null) { "/*uninitialized*/" - } else if (init.isAssign && !disableEquals) { - val e = init.exprs.single() - " = " + getTargetExpr(e, inferredType) - } else if (init.isParens && typeAlias != null && !disableEquals) { - " = $typeAlias" + init.exprs.joinWithCommas("(", ")", trailing = false) { - getTargetExpr(it, inferredType.componentType) - } } else { + assert(init.isBraces || init.isParens) val (prefix, postfix) = if (init.isBraces) Pair("{", "}") else Pair("(", ")") - init.exprs.joinWithCommas(prefix, postfix, trailing = false) { + init.exprs.joinToString(", ", prefix, postfix) { getTargetExpr(it, inferredType.componentType) } } +} \ No newline at end of file diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/src/org/lflang/generator/python/PyUtil.java index 9ca2f7222f..78375c910a 100644 --- a/org.lflang/src/org/lflang/generator/python/PyUtil.java +++ b/org.lflang/src/org/lflang/generator/python/PyUtil.java @@ -26,7 +26,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY package org.lflang.generator.python; -import org.lflang.InferredType; import org.lflang.generator.ReactorInstance; import org.lflang.generator.GeneratorBase; import org.lflang.generator.c.CUtil; @@ -144,6 +143,25 @@ public static String generateGILReleaseCode() { * @return A value string in the target language */ protected static String getPythonTargetValue(Expression expr) { - return PythonTypes.getInstance().getTargetExpr(expr, InferredType.undefined()); + String returnValue; + switch (ASTUtils.toOriginalText(expr)) { + case "false": + returnValue = "False"; + break; + case "true": + returnValue = "True"; + break; + default: + returnValue = GeneratorBase.getTargetValue(expr); + } + + // Parameters in Python are always prepended with a 'self.' + // predicate. Therefore, we need to append the returned value + // if it is a parameter. + if (expr instanceof ParameterReference) { + returnValue = "self." + returnValue; + } + + return returnValue; } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 3f82f20016..46bcc4f811 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -96,7 +96,7 @@ public class PythonGenerator extends CGenerator { public PythonGenerator(LFGeneratorContext context) { this(context, - new PythonTypes(), + new PythonTypes(context.getErrorReporter()), new CCmakeGenerator( context.getFileConfig(), List.of("lib/python_action.c", diff --git a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java index fe78d8187f..5617350062 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java @@ -8,7 +8,6 @@ import com.google.common.base.Objects; import org.lflang.ASTUtils; -import org.lflang.InferredType; import org.lflang.generator.GeneratorBase; import org.lflang.generator.ParameterInstance; import org.lflang.lf.Expression; @@ -96,7 +95,8 @@ private static List getAllParameters(ReactorDecl decl) { * @return Initialization code */ private static String generatePythonInitializer(Parameter p) { - return PythonTypes.getInstance().getTargetInitializer(p.getInit(), p.getType()); + List values = p.getInit().getExprs().stream().map(PyUtil::getPythonTargetValue).toList(); + return values.size() > 1 ? "(" + String.join(", ", values) + ")" : values.get(0); } /** @@ -110,8 +110,47 @@ private static String generatePythonInitializer(Parameter p) { * @return Initialization code */ public static String generatePythonInitializer(ParameterInstance p) { - PythonTypes pyTypes = PythonTypes.generateParametersIn(p.getParent().getParent()); - return pyTypes.getTargetInitializer(p.getActualValue(), p.getDefinition().getType()); + // Handle overrides in the instantiation. + // In case there is more than one assignment to this parameter, we need to + // find the last one. + Assignment lastAssignment = getLastAssignment(p); + List list = new LinkedList<>(); + if (lastAssignment != null) { + // The parameter has an assignment. + // Right hand side can be a list. Collect the entries. + for (Expression expr : lastAssignment.getRhs().getExprs()) { + if (expr instanceof ParameterReference) { + // The parameter is being assigned a parameter value. + // Assume that parameter belongs to the parent's parent. + // This should have been checked by the validator. + final var param = ((ParameterReference) expr).getParameter(); + list.add(PyUtil.reactorRef(p.getParent().getParent()) + "." + param.getName()); + } else { + list.add(GeneratorBase.getTargetTime(expr)); + } + } + } else { + for (Expression expr : p.getParent().initialParameterValue(p.getDefinition())) { + list.add(PyUtil.getPythonTargetValue(expr)); + } + } + return list.size() > 1 ? "(" + String.join(", ", list) + ")" : list.get(0); } + /** + * Returns the last assignment to "p" if there is one, + * or null if there is no assignment to "p" + * + * @param p The parameter instance to create initializer for + * @return The last assignment of the parameter instance + */ + private static Assignment getLastAssignment(ParameterInstance p) { + Assignment lastAssignment = null; + for (Assignment assignment : p.getParent().getDefinition().getParameters()) { + if (Objects.equal(assignment.getLhs(), p.getDefinition())) { + lastAssignment = assignment; + } + } + return lastAssignment; + } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonTypes.java b/org.lflang/src/org/lflang/generator/python/PythonTypes.java index 5b62ee5f97..c066494047 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonTypes.java +++ b/org.lflang/src/org/lflang/generator/python/PythonTypes.java @@ -1,20 +1,27 @@ package org.lflang.generator.python; -import java.util.List; import java.util.regex.Pattern; -import java.util.stream.Collectors; +import org.lflang.ErrorReporter; import org.lflang.InferredType; -import org.lflang.generator.ReactorInstance; import org.lflang.generator.c.CTypes; -import org.lflang.generator.c.CUtil; -import org.lflang.lf.ParameterReference; public class PythonTypes extends CTypes { // Regular expression pattern for pointer types. The star at the end has to be visible. static final Pattern pointerPatternVariable = Pattern.compile("^\\s*+(\\w+)\\s*\\*\\s*$"); - private static final PythonTypes INSTANCE = new PythonTypes(); + + /** + * Initializes a {@code CTargetTypes} with the given + * error reporter. + * + * @param errorReporter The error reporter for any + * errors raised in the code + * generation process. + */ + public PythonTypes(ErrorReporter errorReporter) { + super(errorReporter); + } @Override public String getTargetUndefinedType() { @@ -32,45 +39,16 @@ public String getTargetUndefinedType() { public String getPythonType(InferredType type) { var result = super.getTargetType(type); - result = switch (result) { - case "double" -> "float"; - case "string" -> "object"; - default -> result; - }; + switch(result){ + case "double": result = "float"; + case "string": result = "object"; + } var matcher = pointerPatternVariable.matcher(result); - if (matcher.find()) { + if(matcher.find()) { return matcher.group(1); } return result; } - - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - return "self." + expr.getParameter().getName(); - } - - @Override - public String getFixedSizeListInitExpression(List contents, int listSize, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); - } - - @Override - public String getVariableSizeListInitExpression(List contents, boolean withBraces) { - return contents.stream().collect(Collectors.joining(", ", "[ ", " ]")); - } - - public static PythonTypes getInstance() { - return INSTANCE; - } - - public static PythonTypes generateParametersIn(ReactorInstance instance) { - return new PythonTypes() { - @Override - public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull) { - return PyUtil.reactorRef(instance) + "." + expr.getParameter().getName(); - } - }; - } } diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 521d6fd2ea..499bf250ab 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -554,7 +554,7 @@ object RustModelBuilder { childLfName = container.name, lfName = variable.name, isInput = variable is Input, - dataType = container.reactor.instantiateType(formalType, it.container.typeArgs), + dataType = container.reactor.instantiateType(formalType, it.container.typeParms), widthSpecMultiport = variable.widthSpec?.toRustExpr(), widthSpecChild = container.widthSpec?.toRustExpr(), ) @@ -644,7 +644,7 @@ object RustModelBuilder { args = args, reactorLfName = this.reactorClass.name, loc = this.locationInfo(), - typeArgs = typeArgs.map { it.toText() }, + typeArgs = typeParms.map { it.toText() }, bankWidth = this.widthSpec ) } @@ -688,7 +688,7 @@ val Reactor.globalId: ReactorId * would be `generic.typeOfPort("port", listOf("String"))`. * */ -fun Reactor.instantiateType(formalType: TargetCode, typeArgs: List): TargetCode { +fun Reactor.instantiateType(formalType: TargetCode, typeArgs: List): TargetCode { val typeParams = typeParms assert(typeArgs.size == typeParams.size) diff --git a/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt index 0075950a1f..c65cd157c5 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSConstructorGenerator.kt @@ -23,7 +23,7 @@ class TSConstructorGenerator( ) { private fun initializeParameter(p: Parameter): String = - "${p.name}: ${TSTypes.getInstance().getTargetType(p)} = ${TSTypes.getInstance().getTargetInitializer(p)}" + "${p.name}: ${TSTypes.getTargetType(p)} = ${TSTypes.getTargetInitializer(p)}" private fun generateConstructorArguments(reactor: Reactor): String { val arguments = StringJoiner(", \n") diff --git a/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt index 61aac6750e..b0a011d042 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSDelayBodyGenerator.kt @@ -16,7 +16,7 @@ object TSDelayBodyGenerator : DelayBodyGenerator { */ private fun getActionType(action: Action): String { return if (action.type != null) { - TSTypes.getInstance().getTargetType(action.type) + TSTypes.getTargetType(action.type) } else { "Present" } diff --git a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java deleted file mode 100644 index cf89596a56..0000000000 --- a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.lflang.generator.ts; - -import org.lflang.generator.DockerGenerator; -import org.lflang.generator.LFGeneratorContext; - -/** - * Generates the docker file related code for the Typescript target. - * - * @author Hou Seng Wong - */ -public class TSDockerGenerator extends DockerGenerator { - - /** Construct a new Docker generator. */ - public TSDockerGenerator(LFGeneratorContext context) { - super(context); - } - - /** - * Return the content of the docker file for [tsFileName]. - */ - public String generateDockerFileContent() { - return """ - |FROM node:alpine - |WORKDIR /linguafranca/$name - |COPY . . - |ENTRYPOINT ["node", "dist/%s.js"] - """.formatted(context.getFileConfig().name); - } -} diff --git a/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.kt new file mode 100644 index 0000000000..1ca762340e --- /dev/null +++ b/org.lflang/src/org/lflang/generator/ts/TSDockerGenerator.kt @@ -0,0 +1,26 @@ +package org.lflang.generator.ts + +import org.lflang.generator.DockerGenerator +import org.lflang.generator.LFGeneratorContext + +/** + * Generates the docker file related code for the Typescript target. + * + * @author Hou Seng Wong + */ +class TSDockerGenerator(context: LFGeneratorContext) : DockerGenerator(context) { + + /** + * Returns the content of the docker file for [tsFileName]. + */ + override fun generateDockerFileContent(): String { + val name = context.fileConfig.name + val dockerFileContent = """ + |FROM node:alpine + |WORKDIR /linguafranca/$name + |COPY . . + |ENTRYPOINT ["node", "dist/$name.js"] + """ + return dockerFileContent.trimMargin() + } +} diff --git a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt index a28e462921..4ed12daa13 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt @@ -39,7 +39,7 @@ fun WidthSpec.toTSCode(): String = terms.joinToString(" + ") { * @return The TS type. */ val Port.tsPortType: String - get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "Present" + get() = type?.let { TSTypes.getTargetType(it) } ?: "Present" /** * Return a TS type for the specified action. @@ -48,7 +48,7 @@ val Port.tsPortType: String * @return The TS type. */ val Action.tsActionType: String - get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "Present" + get() = type?.let { TSTypes.getTargetType(it) } ?: "Present" -fun Expression.toTsTime(): String = TSTypes.getInstance().getTargetTimeExpr(this) -fun TimeValue.toTsTime(): String = TSTypes.getInstance().getTargetTimeExpr(this) +fun Expression.toTsTime(): String = TSTypes.getTargetTimeExpr(this) +fun TimeValue.toTsTime(): String = TSTypes.getTargetTimeExpr(this) diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 9262e44e64..21ea083e49 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -301,7 +301,7 @@ class TSGenerator( if (ret != 0) { val errors: String = pnpmInstall.errors.toString() errorReporter.reportError( - GeneratorUtils.findTargetDecl(resource), + GeneratorUtils.findTarget(resource), "ERROR: pnpm install command failed" + if (errors.isBlank()) "." else ":\n$errors") } installProtoBufsIfNeeded(true, path, context.cancelIndicator) @@ -318,10 +318,10 @@ class TSGenerator( if (npmInstall.run(context.cancelIndicator) != 0) { errorReporter.reportError( - GeneratorUtils.findTargetDecl(resource), + GeneratorUtils.findTarget(resource), "ERROR: npm install command failed: " + npmInstall.errors.toString()) errorReporter.reportError( - GeneratorUtils.findTargetDecl(resource), "ERROR: npm install command failed." + + GeneratorUtils.findTarget(resource), "ERROR: npm install command failed." + "\nFor installation instructions, see: https://www.npmjs.com/get-npm") return } @@ -429,7 +429,7 @@ class TSGenerator( return true } - override fun getTargetTypes(): TargetTypes = TSTypes.getInstance() + override fun getTargetTypes(): TargetTypes = TSTypes override fun getTarget(): Target { return Target.TS diff --git a/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt index 97e753f99b..81de5257de 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSInstanceGenerator.kt @@ -1,9 +1,13 @@ package org.lflang.generator.ts +import org.lflang.ErrorReporter import org.lflang.generator.getTargetInitializer import org.lflang.isBank import org.lflang.joinWithLn -import org.lflang.lf.* +import org.lflang.lf.Instantiation +import org.lflang.lf.Parameter +import org.lflang.lf.Reactor +import org.lflang.lf.TypeParm import org.lflang.reactor import org.lflang.toDefinition import org.lflang.toText @@ -13,6 +17,7 @@ import java.util.* * Generator for child reactor instantiations in TypeScript target. */ class TSInstanceGenerator( + private val errorReporter: ErrorReporter, reactor: Reactor ) { private val childReactors: List @@ -23,39 +28,39 @@ class TSInstanceGenerator( childReactors = reactor.instantiations } - private fun getTypeParams(typeParms: List): String = + private fun getTypeParams(typeParms: List): String = if (typeParms.isEmpty()) "" - else typeParms.joinToString(", ", "<", ">") { TSTypes.getInstance().getTargetType(it) } + else typeParms.joinToString(", ", "<", ">") { it.toText() } private fun getReactorParameterList(parameters: List): String = - parameters.joinToString(", ", "[__Reactor, ", "]") { TSTypes.getInstance().getTargetType(it) } + parameters.joinToString(", ", "[__Reactor, ", "]") { TSTypes.getTargetType(it) } fun generateClassProperties(): String = childReactors.joinWithLn { childReactor -> if (childReactor.isBank) { "${childReactor.name}: " + - "__Bank<${childReactor.reactorClass.name}${getTypeParams(childReactor.typeArgs)}, " + + "__Bank<${childReactor.reactorClass.name}${getTypeParams(childReactor.typeParms)}, " + "${getReactorParameterList(childReactor.reactor.parameters)}>" } else { "${childReactor.name}: " + - "${childReactor.reactorClass.name}${getTypeParams(childReactor.typeArgs)}" + "${childReactor.reactorClass.name}${getTypeParams(childReactor.typeParms)}" } } fun generateInstantiations(): String { val childReactorInstantiations = LinkedList() for (childReactor in childReactors) { - val childReactorArguments = StringJoiner(", ") + val childReactorArguments = StringJoiner(", "); childReactorArguments.add("this") for (parameter in childReactor.reactorClass.toDefinition().parameters) { - childReactorArguments.add(TSTypes.getInstance().getTargetInitializer(parameter, childReactor)) + childReactorArguments.add(TSTypes.getTargetInitializer(parameter, childReactor)) } if (childReactor.isBank) { childReactorInstantiations.add( "this.${childReactor.name} = " + - "new __Bank<${childReactor.reactorClass.name}${getTypeParams(childReactor.typeArgs)}, " + + "new __Bank<${childReactor.reactorClass.name}${getTypeParams(childReactor.typeParms)}, " + "${getReactorParameterList(childReactor.reactor.parameters)}>" + "(this, ${childReactor.widthSpec.toTSCode()}, " + "${childReactor.reactorClass.name}, " + diff --git a/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt index 838186a6dc..5ded5814b0 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSParameterGenerator.kt @@ -12,7 +12,7 @@ class TSParameterGenerator( fun generateClassProperties(): String = parameters.joinWithLn { - "${it.name}: __Parameter<${TSTypes.getInstance().getTargetType(it)}>;" + "${it.name}: __Parameter<${TSTypes.getTargetType(it)}>;" } fun generateInstantiations(): String = diff --git a/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt index 305369832e..c9fef820f0 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSParameterPreambleGenerator.kt @@ -69,7 +69,7 @@ class TSParameterPreambleGenerator( mainParameters.joinWithLn { parameter -> """ - |let __CL${parameter.name}: ${TSTypes.getInstance().getTargetType(parameter)} | undefined = undefined; + |let __CL${parameter.name}: ${TSTypes.getTargetType(parameter)} | undefined = undefined; |if (__processedCLArgs.${parameter.name} !== undefined) { | if (__processedCLArgs.${parameter.name} !== null) { | __CL${parameter.name} = __processedCLArgs.${parameter.name}; @@ -114,7 +114,7 @@ class TSParameterPreambleGenerator( var customArgType: String? = null var customTypeLabel: String? = null - val paramType = TSTypes.getInstance().getTargetType(parameter) + val paramType = TSTypes.getTargetType(parameter) if (paramType == "string") { mainParameters.add(parameter) customArgType = "String"; diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt index aca577aad0..4354ac1ea9 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt @@ -358,7 +358,7 @@ class TSReactionGenerator( // Underscores are added to parameter names to prevent conflict with prologue val name = param.name - reactSignature.add("__$name: __Parameter<${TSTypes.getInstance().getTargetType(param)}>") + reactSignature.add("__$name: __Parameter<${TSTypes.getTargetType(param)}>") reactFunctArgs.add("this.$name") reactPrologue.add("let $name = __$name.get();") } @@ -367,7 +367,7 @@ class TSReactionGenerator( for (state in reactor.stateVars) { // Underscores are added to state names to prevent conflict with prologue val name = state.name - reactSignature.add("__$name: __State<${TSTypes.getInstance().getTargetType(state)}>") + reactSignature.add("__$name: __State<${TSTypes.getTargetType(state)}>") reactFunctArgs.add("this.$name") reactPrologue.add("let $name = __$name.get();") reactEpilogue.add( diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt index 4d537f5a19..f89ec13f71 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt @@ -130,7 +130,7 @@ ${" |"..preamble.code.toText()} "export class $reactorName extends __Reactor {" } - val instanceGenerator = TSInstanceGenerator(reactor) + val instanceGenerator = TSInstanceGenerator(errorReporter, reactor) val timerGenerator = TSTimerGenerator(reactor.timers) val parameterGenerator = TSParameterGenerator(reactor.parameters) val stateGenerator = TSStateGenerator(reactor.stateVars) diff --git a/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt index 6ac2d8b28a..091da1d958 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSStateGenerator.kt @@ -15,7 +15,7 @@ class TSStateGenerator( fun generateClassProperties(): String { val stateClassProperties = LinkedList() for (stateVar in stateVars) { - stateClassProperties.add("${stateVar.name}: __State<${TSTypes.getInstance().getTargetType(stateVar)}>;"); + stateClassProperties.add("${stateVar.name}: __State<${TSTypes.getTargetType(stateVar)}>;"); } return stateClassProperties.joinToString("\n") } @@ -25,7 +25,7 @@ class TSStateGenerator( // Next handle states. for (stateVar in stateVars) { if (ASTUtils.isInitialized(stateVar)) { - stateInstantiations.add("this.${stateVar.name} = new __State(${TSTypes.getInstance().getTargetInitializer(stateVar)});"); + stateInstantiations.add("this.${stateVar.name} = new __State(${TSTypes.getTargetInitializer(stateVar)});"); } else { stateInstantiations.add("this.${stateVar.name} = new __State(undefined);"); } diff --git a/org.lflang/src/org/lflang/generator/ts/TSTypes.java b/org.lflang/src/org/lflang/generator/ts/TSTypes.java deleted file mode 100644 index e89fff00d4..0000000000 --- a/org.lflang/src/org/lflang/generator/ts/TSTypes.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.lflang.generator.ts; - -import java.util.List; - -import org.lflang.ASTUtils; -import org.lflang.TimeValue; -import org.lflang.generator.TargetTypes; -import org.lflang.generator.UnsupportedGeneratorFeatureException; -import org.lflang.lf.StateVar; - -public class TSTypes implements TargetTypes { - - private static TSTypes INSTANCE = new TSTypes(); - - private TSTypes() { - - } - - @Override - public String getTargetType(StateVar s) { - var type = TargetTypes.super.getTargetType(s); - if (!ASTUtils.isInitialized(s)) { - return "%s | undefined".formatted(type); - } else { - return type; - } - } - - @Override - public boolean supportsGenerics() { - return true; - } - - @Override - public String getTargetTimeType() { - return "TimeValue"; - } - - @Override - public String getTargetTagType() { - return "TimeValue"; - } - - @Override - public String getTargetUndefinedType() { - return "Present"; - } - - public String getTargetTimeExpr(TimeValue value) { - if (value.unit != null) { - return "TimeValue.%s(%s)".formatted(value.unit.getCanonicalName(), value.time); - } else { - // The value must be zero. - return "TimeValue.zero()"; - } - } - - @Override - public String getTargetFixedSizeListType(String baseType, int size) { - throw new UnsupportedGeneratorFeatureException("TypeScript does not support fixed-size array types."); - } - - @Override - public String getTargetVariableSizeListType(String baseType) { - return "Array<%s>".formatted(baseType); // same as "$baseType[]" - } - - public String getVariableSizeListInitExpression(List contents, boolean withBraces) { - return "[" + String.join(", ", contents) + "]"; - } - - public static TSTypes getInstance() { - return INSTANCE; - } -} diff --git a/org.lflang/src/org/lflang/generator/ts/TSTypes.kt b/org.lflang/src/org/lflang/generator/ts/TSTypes.kt new file mode 100644 index 0000000000..9b7b66f62f --- /dev/null +++ b/org.lflang/src/org/lflang/generator/ts/TSTypes.kt @@ -0,0 +1,57 @@ +package org.lflang.generator.ts + +import org.lflang.ASTUtils +import org.lflang.TimeValue +import org.lflang.generator.TargetTypes +import org.lflang.generator.UnsupportedGeneratorFeatureException +import org.lflang.joinWithCommas +import org.lflang.lf.StateVar + +object TSTypes : TargetTypes { + + override fun getTargetType(s: StateVar): String { + val type = super.getTargetType(s) + return if (!ASTUtils.isInitialized(s)) { + "$type | undefined" + } else { + type + } + } + + override fun supportsGenerics(): Boolean { + return true + } + + override fun getTargetTimeType(): String { + return "TimeValue" + } + + override fun getTargetTagType(): String { + return "TimeValue" + } + + override fun getTargetUndefinedType(): String { + return "Present" + } + + override fun getTargetTimeExpr(value: TimeValue): String { + return if (value.unit != null) { + "TimeValue.${value.unit.canonicalName}(${value.time})" + } else { + // The value must be zero. + "TimeValue.zero()" + } + } + + override fun getTargetFixedSizeListType(baseType: String?, size: Int): String { + throw UnsupportedGeneratorFeatureException("TypeScript does not support fixed-size array types.") + } + + override fun getTargetVariableSizeListType(baseType: String): String { + return "Array<$baseType>" // same as "$baseType[]" + } + + override fun getVariableSizeListInitExpression(contents: MutableList, withBraces: Boolean): String { + return contents.joinWithCommas("[", "]") + } +} diff --git a/org.lflang/src/org/lflang/util/Averager.java b/org.lflang/src/org/lflang/util/Averager.java deleted file mode 100644 index 81349c9db1..0000000000 --- a/org.lflang/src/org/lflang/util/Averager.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.lflang.util; - -import java.util.Arrays; - -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - -/** Average asynchronously reported numbers and do something with them. */ -public class Averager { - private final int n; - private final int[] reports; - - /** Create an averager of reports from {@code n} processes. */ - public Averager(int n) { - this.n = n; - reports = new int[n]; - } - - /** - * Receive {@code x} from process {@code id} and invoke {@code callback} - * on the mean of the numbers most recently reported by the processes. - */ - public synchronized void report(int id, int x, Procedure1 callback) { - assert 0 <= id && id < n; - reports[id] = x; - callback.apply(Arrays.stream(reports).sum() / n); - } -} diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index b9db8d3a67..b2c60bd07f 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -69,7 +69,6 @@ import org.lflang.lf.ActionOrigin; import org.lflang.lf.Assignment; import org.lflang.lf.Attribute; -import org.lflang.lf.BracedListExpression; import org.lflang.lf.BuiltinTrigger; import org.lflang.lf.BuiltinTriggerRef; import org.lflang.lf.CodeExpr; @@ -172,30 +171,6 @@ public void checkAction(Action action) { public void checkInitializer(Initializer init) { if (init.isBraces() && target != Target.CPP) { error("Brace initializers are only supported for the C++ target", Literals.INITIALIZER__BRACES); - } else if (init.isParens() && target.mandatesEqualsInitializers()) { - var message = "This syntax is deprecated in the " + target - + " target, use an equal sign instead of parentheses for assignment."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, Literals.INITIALIZER__PARENS); - } else if (!init.isAssign() && init.eContainer() instanceof Assignment) { - var feature = init.isBraces() ? Literals.INITIALIZER__BRACES - : Literals.INITIALIZER__PARENS; - var message = "This syntax is deprecated, do not use parentheses or braces but an equal sign."; - if (init.getExprs().size() == 1) { - message += " (run the formatter to fix this automatically)"; - } - warning(message, feature); - } - } - - @Check(CheckType.FAST) - public void checkBracedExpression(BracedListExpression expr) { - if (!target.allowsBracedListExpressions()) { - var message = "Braced expression lists are not a valid expression for the " + target - + " target."; - error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature()); } } @@ -648,7 +623,7 @@ public void checkParameter(Parameter param) { Reactor reactor = (Reactor) container; if (reactor.isMain()) { // we need to check for the cli parameters that are always taken - List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); + List cliParams = List.of("t", "threads", "o", "timeout", "k", "keepalive", "f", "fast", "help"); if (cliParams.contains(param.getName())) { error("Parameter '" + param.getName() + "' is already in use as command line argument by Lingua Franca,", @@ -1055,7 +1030,6 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { validateClockSyncTargetProperties(targetProperties); validateSchedulerTargetProperties(targetProperties); validateRos2TargetProperties(targetProperties); - validateKeepalive(targetProperties); } private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { @@ -1151,14 +1125,6 @@ private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { } } - private void validateKeepalive(KeyValuePairs targetProperties) { - KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); - if (keepalive != null && target == Target.CPP) { - warning("The keepalive property is inferred automatically by the C++ " + - "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); - } - } - private void validateRos2TargetProperties(KeyValuePairs targetProperties) { KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); KeyValuePair ros2Dependencies = getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); @@ -1620,12 +1586,9 @@ public void typeCheck(Initializer init, InferredType type, EStructuralFeature fe // list of times var exprs = init.getExprs(); if (exprs.isEmpty()) { - error("Expected at least one time value.", feature); + error("Expected exactly one time value.", feature); return; } - if (exprs.size() == 1 && exprs.get(0) instanceof BracedListExpression) { - exprs = ((BracedListExpression) exprs.get(0)).getItems(); - } for (var component : exprs) { checkExpressionIsTime(component, feature); } @@ -1635,7 +1598,7 @@ public void typeCheck(Initializer init, InferredType type, EStructuralFeature fe } } - private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { + public void checkExpressionIsTime(Initializer init, EStructuralFeature feature) { if (init == null) { return; } @@ -1647,7 +1610,7 @@ private void checkExpressionIsTime(Initializer init, EStructuralFeature feature) } } - private void checkExpressionIsTime(Expression value, EStructuralFeature feature) { + public void checkExpressionIsTime(Expression value, EStructuralFeature feature) { if (value == null || value instanceof Time) { return; } diff --git a/test/C/src/ActionDelay.lf b/test/C/src/ActionDelay.lf index 86e510080a..6a4deddda6 100644 --- a/test/C/src/ActionDelay.lf +++ b/test/C/src/ActionDelay.lf @@ -4,7 +4,7 @@ target C reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int = 0 + state y_state: int(0) logical action act(100 msec) reaction(y_in) -> act {= diff --git a/test/C/src/ActionIsPresent.lf b/test/C/src/ActionIsPresent.lf index b94108949e..4f8164bea8 100644 --- a/test/C/src/ActionIsPresent.lf +++ b/test/C/src/ActionIsPresent.lf @@ -1,9 +1,9 @@ // Tests the is_present variable for actions. target C -main reactor ActionIsPresent(offset: time = 1 nsec, period: time = 500 msec) { +main reactor ActionIsPresent(offset: time(1 nsec), period: time(500 msec)) { logical action a - state success: bool = false + state success: bool(false) reaction(startup, a) -> a {= if (!a->is_present) { diff --git a/test/C/src/After.lf b/test/C/src/After.lf index d3663457e4..f354d9d7c8 100644 --- a/test/C/src/After.lf +++ b/test/C/src/After.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time = 10 msec - state received: int = 0 + state expected_time: time(10 msec) + state received: int(0) input x: int reaction(x) {= diff --git a/test/C/src/AfterCycles.lf b/test/C/src/AfterCycles.lf index d7d621046b..3bc9622944 100644 --- a/test/C/src/AfterCycles.lf +++ b/test/C/src/AfterCycles.lf @@ -16,7 +16,7 @@ reactor Work { } main reactor AfterCycles { - state count: int = 0 + state count: int(0) s = new Source() w0 = new Work() w1 = new Work() diff --git a/test/C/src/AfterOverlapped.lf b/test/C/src/AfterOverlapped.lf index 0925dc5164..49d2c22bd2 100644 --- a/test/C/src/AfterOverlapped.lf +++ b/test/C/src/AfterOverlapped.lf @@ -8,8 +8,8 @@ import Count from "lib/Count.lf" reactor Test { input c: int - state i: int = 0 - state received: int = 0 + state i: int(0) + state received: int(0) reaction(c) {= self->received++; diff --git a/test/C/src/AfterZero.lf b/test/C/src/AfterZero.lf index 378114c730..85e1d2e000 100644 --- a/test/C/src/AfterZero.lf +++ b/test/C/src/AfterZero.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time = 0 - state received: int = 0 + state expected_time: time(0) + state received: int(0) input x: int reaction(x) {= diff --git a/test/C/src/Alignment.lf b/test/C/src/Alignment.lf index 551b7c8342..7420bd51c1 100644 --- a/test/C/src/Alignment.lf +++ b/test/C/src/Alignment.lf @@ -7,7 +7,7 @@ target C { reactor Source { output out: int - state count: int = 1 + state count: int(1) timer t(0, 100 msec) reaction(t) -> out {= lf_set(out, self->count++); =} @@ -16,8 +16,8 @@ reactor Source { reactor Sieve { input in: int output out: bool - state primes: int* = {= NULL =} - state last_prime: int = 0 + state primes: int*({= NULL =}) + state last_prime: int(0) reaction(startup) {= // There are 1229 primes between 1 and 10,000. @@ -74,7 +74,7 @@ reactor Sieve { reactor Destination { input ok: bool input in: int - state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =} + state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =}) reaction(ok, in) {= if (ok->is_present && in->is_present) { diff --git a/test/C/src/ArrayAsParameter.lf b/test/C/src/ArrayAsParameter.lf index a9df29cb03..d51778980e 100644 --- a/test/C/src/ArrayAsParameter.lf +++ b/test/C/src/ArrayAsParameter.lf @@ -3,9 +3,9 @@ // encode their own length. target C -reactor Source(sequence: int[] = {0, 1, 2}, n_sequence: int = 3) { +reactor Source(sequence: int[](0, 1, 2), n_sequence: int(3)) { output out: int - state count: int = 0 + state count: int(0) logical action next reaction(startup, next) -> out, next {= @@ -19,8 +19,8 @@ reactor Source(sequence: int[] = {0, 1, 2}, n_sequence: int = 3) { reactor Print { input in: int - state count: int = 1 - state received: int = 0 + state count: int(1) + state received: int(0) reaction(in) {= self->received++; @@ -41,7 +41,7 @@ reactor Print { } main reactor ArrayAsParameter { - s = new Source(sequence = {1, 2, 3, 4}, n_sequence = 4) + s = new Source(sequence = (1, 2, 3, 4), n_sequence = 4) p = new Print() s.out -> p.in } diff --git a/test/C/src/ArrayAsType.lf b/test/C/src/ArrayAsType.lf index c95e5bf385..ad326c9288 100644 --- a/test/C/src/ArrayAsType.lf +++ b/test/C/src/ArrayAsType.lf @@ -13,7 +13,7 @@ reactor Source { =} } -reactor Print(scale: int = 1) { // The scale parameter is just for testing. +reactor Print(scale: int(1)) { // The scale parameter is just for testing. input in: int[3] reaction(in) {= diff --git a/test/C/src/ArrayFree.lf b/test/C/src/ArrayFree.lf index 11b31c123f..eea521aa72 100644 --- a/test/C/src/ArrayFree.lf +++ b/test/C/src/ArrayFree.lf @@ -10,7 +10,7 @@ target C { import Source, Print from "ArrayPrint.lf" import Scale from "ArrayScale.lf" -reactor Free(scale: int = 2, size: int = 3) { +reactor Free(scale: int(2), size: int(3)) { mutable input in: int[] reaction(in) {= diff --git a/test/C/src/ArrayFreeMultiple.lf b/test/C/src/ArrayFreeMultiple.lf index 7b933ce518..b82bea9162 100644 --- a/test/C/src/ArrayFreeMultiple.lf +++ b/test/C/src/ArrayFreeMultiple.lf @@ -12,7 +12,7 @@ import Print from "ArrayPrint.lf" reactor Source { output out: int[] - state c: int = 0 + state c: int(0) timer t(0, 1 sec) reaction(t) -> out {= @@ -26,7 +26,7 @@ reactor Source { =} } -reactor Free(scale: int = 2) { +reactor Free(scale: int(2)) { mutable input in: int[] reaction(in) {= diff --git a/test/C/src/ArrayPrint.lf b/test/C/src/ArrayPrint.lf index 937bc51bea..33d75c6455 100644 --- a/test/C/src/ArrayPrint.lf +++ b/test/C/src/ArrayPrint.lf @@ -6,9 +6,9 @@ target C { fast: true } -reactor Source(size: int = 3) { +reactor Source(size: int(3)) { output out: int[] - state count: int = 0 + state count: int(0) timer t(0, 1 sec) reaction(t) -> out {= @@ -26,9 +26,9 @@ reactor Source(size: int = 3) { } // The scale parameter is just for testing. -reactor Print(scale: int = 1, size: int = 3) { +reactor Print(scale: int(1), size: int(3)) { input in: int[] - state count: int = 0 + state count: int(0) reaction(in) {= bool failed = false; // For testing. diff --git a/test/C/src/ArrayScale.lf b/test/C/src/ArrayScale.lf index 63edfc421c..257b0645c3 100644 --- a/test/C/src/ArrayScale.lf +++ b/test/C/src/ArrayScale.lf @@ -9,7 +9,7 @@ target C { import Print, Source from "ArrayPrint.lf" -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { mutable input in: int[] output out: int[] diff --git a/test/C/src/CharLiteralInitializer.lf b/test/C/src/CharLiteralInitializer.lf index 319af0224c..9ee206efbf 100644 --- a/test/C/src/CharLiteralInitializer.lf +++ b/test/C/src/CharLiteralInitializer.lf @@ -2,7 +2,7 @@ target C main reactor CharLiteralInitializer { - state c: char = 'x' + state c: char('x') reaction(startup) {= if (self->c != 'x') { diff --git a/test/C/src/Composition.lf b/test/C/src/Composition.lf index 7c024a9eba..c450bc0a64 100644 --- a/test/C/src/Composition.lf +++ b/test/C/src/Composition.lf @@ -5,10 +5,10 @@ target C { timeout: 10 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Source(period: time = 2 sec) { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= (self->count)++; diff --git a/test/C/src/CompositionAfter.lf b/test/C/src/CompositionAfter.lf index cb98ef7d7e..43f604de06 100644 --- a/test/C/src/CompositionAfter.lf +++ b/test/C/src/CompositionAfter.lf @@ -5,10 +5,10 @@ target C { timeout: 10 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor Source(period: time = 2 sec) { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= (self->count)++; @@ -30,7 +30,7 @@ reactor Test { =} } -main reactor CompositionAfter(delay: time = 5 sec) { +main reactor CompositionAfter(delay: time(5 sec)) { s = new Source() d = new Test() s.y -> d.x after delay diff --git a/test/C/src/CompositionInheritance.lf b/test/C/src/CompositionInheritance.lf index 06221e9788..f57c1a688e 100644 --- a/test/C/src/CompositionInheritance.lf +++ b/test/C/src/CompositionInheritance.lf @@ -5,11 +5,11 @@ target C { timeout: 10 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { input foo: int output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= printf("Hello World. At time %lld, my count is: %d.\n", lf_time_logical_elapsed(), self->count); @@ -30,7 +30,7 @@ reactor SourceExtended extends Source { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= (self->count)++; diff --git a/test/C/src/CountSelf.lf b/test/C/src/CountSelf.lf index 1ef27187ae..1a7a6d1ff2 100644 --- a/test/C/src/CountSelf.lf +++ b/test/C/src/CountSelf.lf @@ -6,7 +6,7 @@ target C { import TestCount from "lib/TestCount.lf" -reactor CountSelf2(delay: time = 100 msec) { +reactor CountSelf2(delay: time(100 msec)) { output out: int logical action a: int diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index c72dc16dcf..62116353a5 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -5,10 +5,10 @@ target C { timeout: 6 sec } -reactor Source(period: time = 3 sec) { +reactor Source(period: time(3 sec)) { output y: int timer t(0, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= if (2 * (self->count / 2) != self->count) { @@ -22,9 +22,9 @@ reactor Source(period: time = 3 sec) { =} } -reactor Destination(timeout: time = 1 sec) { +reactor Destination(timeout: time(1 sec)) { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= printf("Destination receives: %d\n", x->value); diff --git a/test/C/src/DeadlineHandledAbove.lf b/test/C/src/DeadlineHandledAbove.lf index 92d7e9dac8..d186bf9016 100644 --- a/test/C/src/DeadlineHandledAbove.lf +++ b/test/C/src/DeadlineHandledAbove.lf @@ -2,7 +2,7 @@ // container reacts to that output. target C -reactor Deadline(threshold: time = 100 msec) { +reactor Deadline(threshold: time(100 msec)) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time = 100 msec) { } main reactor DeadlineHandledAbove { - state violation_detected: bool = false + state violation_detected: bool(false) d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/C/src/DeadlineWithBanks.lf b/test/C/src/DeadlineWithBanks.lf index 18bc8c3682..266208cdac 100644 --- a/test/C/src/DeadlineWithBanks.lf +++ b/test/C/src/DeadlineWithBanks.lf @@ -11,7 +11,7 @@ target C { preamble {= volatile int global_cnt = 0; =} -reactor Bank(bank_index: int = 0) { +reactor Bank(bank_index: int(0)) { timer t(0, 100 msec) output out: int @@ -46,7 +46,7 @@ reactor Bank(bank_index: int = 0) { =} } -reactor Sink(dead: time = 0) { +reactor Sink(dead: time(0)) { input in: int reaction(in) {= =} deadline(dead) {= =} diff --git a/test/C/src/DeadlineZero.lf b/test/C/src/DeadlineZero.lf index 3ae49a9409..4e946bb63d 100644 --- a/test/C/src/DeadlineZero.lf +++ b/test/C/src/DeadlineZero.lf @@ -5,7 +5,7 @@ target C { reactor Detector { input trigger: int - state cnt: int = 0 + state cnt: int(0) reaction(trigger) {= printf("ERROR: failed to detect zero-duration deadline at iteration %d.\n", self->cnt); diff --git a/test/C/src/DelayArray.lf b/test/C/src/DelayArray.lf index 72eb734888..19e49e2464 100644 --- a/test/C/src/DelayArray.lf +++ b/test/C/src/DelayArray.lf @@ -4,7 +4,7 @@ target C { build-type: RelWithDebInfo } -reactor DelayPointer(delay: time = 100 msec) { +reactor DelayPointer(delay: time(100 msec)) { input in: int[] output out: int[] logical action a: int[] @@ -30,7 +30,7 @@ reactor Source { =} } -reactor Print(scale: int = 1) { // The scale parameter is just for testing. +reactor Print(scale: int(1)) { // The scale parameter is just for testing. input in: int[] reaction(in) {= diff --git a/test/C/src/DelayArrayWithAfter.lf b/test/C/src/DelayArrayWithAfter.lf index c94be3b9a1..42d7ff5275 100644 --- a/test/C/src/DelayArrayWithAfter.lf +++ b/test/C/src/DelayArrayWithAfter.lf @@ -7,7 +7,7 @@ target C { reactor Source { output out: int[] - state iteration: int = 1 + state iteration: int(1) timer t(0, 1 sec) reaction(t) -> out {= @@ -23,10 +23,10 @@ reactor Source { =} } -reactor Print(scale: int = 1) { // The scale parameter is just for testing. +reactor Print(scale: int(1)) { // The scale parameter is just for testing. input in: int[] - state iteration: int = 1 - state inputs_received: int = 0 + state iteration: int(1) + state inputs_received: int(0) reaction(in) {= self->inputs_received++; diff --git a/test/C/src/DelayInt.lf b/test/C/src/DelayInt.lf index 78ca793716..c7c27132bc 100644 --- a/test/C/src/DelayInt.lf +++ b/test/C/src/DelayInt.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target C -reactor Delay(delay: time = 100 msec) { +reactor Delay(delay: time(100 msec)) { input in: int output out: int logical action a: int @@ -18,8 +18,8 @@ reactor Delay(delay: time = 100 msec) { reactor Test { input in: int - state start_time: time = 0 - state received_value: bool = false + state start_time: time(0) + state received_value: bool(false) reaction(startup) {= // Record the logical time at the start. diff --git a/test/C/src/DelayPointer.lf b/test/C/src/DelayPointer.lf index c6313c199d..87455d32ec 100644 --- a/test/C/src/DelayPointer.lf +++ b/test/C/src/DelayPointer.lf @@ -1,7 +1,7 @@ // Test delaying a pointer type. target C -reactor DelayPointer2(delay: time = 100 msec) { +reactor DelayPointer2(delay: time(100 msec)) { input in: int* output out: int* logical action a: int* @@ -30,8 +30,8 @@ reactor Source { reactor Test { input in: int* - state start_time: time = 0 - state received_value: bool = false + state start_time: time(0) + state received_value: bool(false) reaction(startup) {= // Record the logical time at the start. diff --git a/test/C/src/DelayString.lf b/test/C/src/DelayString.lf index b14e680d72..1c77190581 100644 --- a/test/C/src/DelayString.lf +++ b/test/C/src/DelayString.lf @@ -2,7 +2,7 @@ // freed. target C -reactor DelayString2(delay: time = 100 msec) { +reactor DelayString2(delay: time(100 msec)) { input in: string output out: string logical action a: string @@ -17,7 +17,7 @@ reactor DelayString2(delay: time = 100 msec) { reactor Test { input in: string - state start_time: time = 0 + state start_time: time(0) reaction(in) {= printf("Received: %s.\n", in->value); diff --git a/test/C/src/DelayStruct.lf b/test/C/src/DelayStruct.lf index 9cd201aa11..a92acdc483 100644 --- a/test/C/src/DelayStruct.lf +++ b/test/C/src/DelayStruct.lf @@ -7,7 +7,7 @@ preamble {= #include "hello.h" =} -reactor DelayPointer(delay: time = 100 msec) { +reactor DelayPointer(delay: time(100 msec)) { input in: hello_t* output out: hello_t* logical action a: hello_t* @@ -38,7 +38,7 @@ reactor Source { =} } -reactor Print(expected: int = 42) { // expected parameter is for testing. +reactor Print(expected: int(42)) { // expected parameter is for testing. input in: hello_t* reaction(in) {= diff --git a/test/C/src/DelayStructWithAfter.lf b/test/C/src/DelayStructWithAfter.lf index 6693a437e6..14f24aaf88 100644 --- a/test/C/src/DelayStructWithAfter.lf +++ b/test/C/src/DelayStructWithAfter.lf @@ -20,7 +20,7 @@ reactor Source { =} } -reactor Print(expected: int = 42) { // expected parameter is for testing. +reactor Print(expected: int(42)) { // expected parameter is for testing. input in: hello_t* reaction(in) {= diff --git a/test/C/src/DelayStructWithAfterOverlapped.lf b/test/C/src/DelayStructWithAfterOverlapped.lf index 8161022653..671b1ca4b3 100644 --- a/test/C/src/DelayStructWithAfterOverlapped.lf +++ b/test/C/src/DelayStructWithAfterOverlapped.lf @@ -12,7 +12,7 @@ preamble {= reactor Source { output out: hello_t* timer t(0, 1 sec) - state s: int = 0 + state s: int(0) reaction(t) -> out {= self->s++; @@ -27,7 +27,7 @@ reactor Source { reactor Print { // expected parameter is for testing. input in: hello_t* - state s: int = 0 + state s: int(0) reaction(in) {= self->s++; diff --git a/test/C/src/DelayedAction.lf b/test/C/src/DelayedAction.lf index 28a3e81ac5..b37f6b9710 100644 --- a/test/C/src/DelayedAction.lf +++ b/test/C/src/DelayedAction.lf @@ -6,7 +6,7 @@ target C { main reactor DelayedAction { timer t(0, 1 sec) logical action a - state count: int = 0 + state count: int(0) reaction(t) -> a {= lf_schedule(a, MSEC(100)); =} diff --git a/test/C/src/DoubleInvocation.lf b/test/C/src/DoubleInvocation.lf index 973c8b18f6..4b60f26fa8 100644 --- a/test/C/src/DoubleInvocation.lf +++ b/test/C/src/DoubleInvocation.lf @@ -13,7 +13,7 @@ target C { reactor Ball { output position: int output velocity: int - state p: int = 200 + state p: int(200) timer trigger(0, 1 sec) reaction(trigger) -> position, velocity {= @@ -26,7 +26,7 @@ reactor Ball { reactor Print { input velocity: int input position: int - state previous: int = -1 + state previous: int(-1) reaction(startup) {= printf("####### Print startup\n"); diff --git a/test/C/src/DoublePort.lf b/test/C/src/DoublePort.lf index c8bf9811f8..97d18f1761 100644 --- a/test/C/src/DoublePort.lf +++ b/test/C/src/DoublePort.lf @@ -13,7 +13,7 @@ target C { import Count from "lib/Count.lf" reactor CountMicrostep { - state count: int = 1 + state count: int(1) output out: int logical action act: int timer t(0, 1 sec) diff --git a/test/C/src/DoubleReaction.lf b/test/C/src/DoubleReaction.lf index 8da6210825..fb6aaaabaa 100644 --- a/test/C/src/DoubleReaction.lf +++ b/test/C/src/DoubleReaction.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int input w: int - state s: int = 2 + state s: int(2) reaction(x, w) {= int sum = 0; diff --git a/test/C/src/DoubleTrigger.lf b/test/C/src/DoubleTrigger.lf index 68ad603168..201ac35d7c 100644 --- a/test/C/src/DoubleTrigger.lf +++ b/test/C/src/DoubleTrigger.lf @@ -8,7 +8,7 @@ target C { main reactor DoubleTrigger { timer t1 timer t2 - state s: int = 0 + state s: int(0) reaction(t1, t2) {= self->s++; diff --git a/test/C/src/FloatLiteral.lf b/test/C/src/FloatLiteral.lf index 576a20d1ac..6d55f6e988 100644 --- a/test/C/src/FloatLiteral.lf +++ b/test/C/src/FloatLiteral.lf @@ -6,10 +6,10 @@ main reactor { #include =} - state N: double = 6.0221409e+23 - state charge: double = -1.6021766E-19 - state minus_epsilon: double = -.01e0 - state expected: double = .964853323188E5 + state N: double(6.0221409e+23) + state charge: double(-1.6021766E-19) + state minus_epsilon: double(-.01e0) + state expected: double(.964853323188E5) reaction(startup) {= double F = - self->N * self->charge; diff --git a/test/C/src/Gain.lf b/test/C/src/Gain.lf index 7cac5eaae6..4096ec5973 100644 --- a/test/C/src/Gain.lf +++ b/test/C/src/Gain.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target C -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { input x: int output y: int @@ -10,7 +10,7 @@ reactor Scale(scale: int = 2) { reactor Test { input x: int - state received_value: bool = false + state received_value: bool(false) reaction(x) {= printf("Received %d.\n", x->value); diff --git a/test/C/src/GetMicroStep.lf b/test/C/src/GetMicroStep.lf index 0a428fd07d..4c7094c42e 100644 --- a/test/C/src/GetMicroStep.lf +++ b/test/C/src/GetMicroStep.lf @@ -2,7 +2,7 @@ target C main reactor GetMicroStep { - state s: int = 1 + state s: int(1) logical action l diff --git a/test/C/src/Hello.lf b/test/C/src/Hello.lf index ea37265a23..f47b66ecc4 100644 --- a/test/C/src/Hello.lf +++ b/test/C/src/Hello.lf @@ -8,9 +8,9 @@ target C { fast: true } -reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { - state count: int = 0 - state previous_time: time = 0 +reactor Reschedule(period: time(2 sec), message: string("Hello C")) { + state count: int(0) + state previous_time: time(0) timer t(1 sec, period) logical action a @@ -43,8 +43,8 @@ reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { } reactor Inside( - period: time = 1 sec, - message: string = "Composite default message." + period: time(1 sec), + message: string("Composite default message.") ) { third_instance = new Reschedule(period = period, message = message) } diff --git a/test/C/src/HelloWorld.lf b/test/C/src/HelloWorld.lf index 7de913c8ad..dc17cc0626 100644 --- a/test/C/src/HelloWorld.lf +++ b/test/C/src/HelloWorld.lf @@ -7,7 +7,7 @@ target C { } reactor HelloWorld2 { - state success: bool = false + state success: bool(false) reaction(startup) {= printf("Hello World.\n"); diff --git a/test/C/src/Hierarchy2.lf b/test/C/src/Hierarchy2.lf index 0a4f20d4bc..07fa4c73a0 100644 --- a/test/C/src/Hierarchy2.lf +++ b/test/C/src/Hierarchy2.lf @@ -14,7 +14,7 @@ reactor Source { reactor Count { output out: int timer t(0, 1 sec) - state i: int = 0 + state i: int(0) reaction(t) -> out {= (self->i)++; @@ -37,7 +37,7 @@ reactor Add { reactor Print { input in: int - state expected: int = 2 + state expected: int(2) reaction(in) {= printf("Received: %d.\n", in->value); diff --git a/test/C/src/IdentifierLength.lf b/test/C/src/IdentifierLength.lf index 8fa38b96f0..69f1fcfd75 100644 --- a/test/C/src/IdentifierLength.lf +++ b/test/C/src/IdentifierLength.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor A_Really_Long_Name_For_A_Source(period: time = 2 sec) { +reactor A_Really_Long_Name_For_A_Source(period: time(2 sec)) { output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor A_Really_Long_Name_For_A_Source(period: time = 2 sec) { reactor Another_Really_Long_Name_For_A_Test_Class { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= (self->count)++; diff --git a/test/C/src/ImportComposition.lf b/test/C/src/ImportComposition.lf index 22a1bfef87..023c9736b2 100644 --- a/test/C/src/ImportComposition.lf +++ b/test/C/src/ImportComposition.lf @@ -6,7 +6,7 @@ import ImportedComposition from "lib/ImportedComposition.lf" main reactor ImportComposition { a = new ImportedComposition() - state received: bool = false + state received: bool(false) reaction(startup) -> a.x {= lf_set(a.x, 42); =} diff --git a/test/C/src/InheritanceAction.lf b/test/C/src/InheritanceAction.lf index 680ffe2f75..3941882f2c 100644 --- a/test/C/src/InheritanceAction.lf +++ b/test/C/src/InheritanceAction.lf @@ -17,7 +17,7 @@ reactor SourceExtended extends Source { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= (self->count)++; diff --git a/test/C/src/ManualDelayedReaction.lf b/test/C/src/ManualDelayedReaction.lf index 72c57105ce..1402e00c62 100644 --- a/test/C/src/ManualDelayedReaction.lf +++ b/test/C/src/ManualDelayedReaction.lf @@ -9,7 +9,7 @@ target C { reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int = 0 + state y_state: int(0) physical action act(0 msec) // TODO: delay in act or the schedule call? diff --git a/test/C/src/Methods.lf b/test/C/src/Methods.lf index edbdd2f7f6..02f1f68c8e 100644 --- a/test/C/src/Methods.lf +++ b/test/C/src/Methods.lf @@ -1,7 +1,7 @@ target C main reactor { - state foo: int = 2 + state foo: int(2) method getFoo(): int {= return self->foo; =} diff --git a/test/C/src/MethodsRecursive.lf b/test/C/src/MethodsRecursive.lf index 5465e0c92c..73588e5115 100644 --- a/test/C/src/MethodsRecursive.lf +++ b/test/C/src/MethodsRecursive.lf @@ -2,7 +2,7 @@ target C main reactor { - state foo: int = 2 + state foo: int(2) method fib(n: int): int {= // Return the n-th Fibonacci number. if (n <= 1) return 1; diff --git a/test/C/src/MethodsSameName.lf b/test/C/src/MethodsSameName.lf index b274d153c8..d2978ba4db 100644 --- a/test/C/src/MethodsSameName.lf +++ b/test/C/src/MethodsSameName.lf @@ -2,7 +2,7 @@ target C reactor Foo { - state foo: int = 2 + state foo: int(2) method add(x: int) {= self->foo += x; =} @@ -16,7 +16,7 @@ reactor Foo { } main reactor { - state foo: int = 2 + state foo: int(2) a = new Foo() diff --git a/test/C/src/MovingAverage.lf b/test/C/src/MovingAverage.lf index a8309aa9d3..cd135dbd26 100644 --- a/test/C/src/MovingAverage.lf +++ b/test/C/src/MovingAverage.lf @@ -10,7 +10,7 @@ import TestDouble from "lib/Test.lf" reactor MASource { output out: double - state count: int = 0 + state count: int(0) timer clock(0, 200 msec) reaction(clock) -> out {= @@ -20,8 +20,8 @@ reactor MASource { } reactor MovingAverageImpl { - state delay_line: double[] = {0.0, 0.0, 0.0} - state index: int = 0 + state delay_line: double[](0.0, 0.0, 0.0) + state index: int(0) input in: double output out: double @@ -47,7 +47,7 @@ reactor MovingAverageImpl { main reactor MovingAverage { s = new MASource() m = new MovingAverageImpl() - p = new TestDouble(expected = {0.0, 0.25, 0.75, 1.5, 2.5, 3.5}) + p = new TestDouble(expected = (0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) s.out -> m.in m.out -> p.in } diff --git a/test/C/src/MultipleContained.lf b/test/C/src/MultipleContained.lf index 540052ba87..f3058c9dd4 100644 --- a/test/C/src/MultipleContained.lf +++ b/test/C/src/MultipleContained.lf @@ -6,7 +6,7 @@ reactor Contained { output trigger: int input in1: int input in2: int - state count: int = 0 + state count: int(0) reaction(startup) -> trigger {= lf_set(trigger, 42); =} diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf index 37b5ddba9f..8db9e5e6f9 100644 --- a/test/C/src/MultipleOutputs.lf +++ b/test/C/src/MultipleOutputs.lf @@ -20,7 +20,7 @@ reactor C { main reactor { c = new C() - state triggered: bool = true + state triggered: bool(true) reaction(c.z) {= lf_print("c.z = %d", c.z->value); diff --git a/test/C/src/NativeListsAndTimes.lf b/test/C/src/NativeListsAndTimes.lf index a1d09beb6c..eb3658f8a4 100644 --- a/test/C/src/NativeListsAndTimes.lf +++ b/test/C/src/NativeListsAndTimes.lf @@ -2,24 +2,22 @@ target C // This test passes if it is successfully compiled into valid target code. main reactor( - x: int = 0, - y: time = 0, // Units are missing but not required - z = 1 msec, // Type is missing but not required - p: int[] = {1, 2, 3, 4}, // List of integers - q: interval_t[] = {1 msec, 2 msec, 3 msec}, // list of time values - g: time[] = {1 msec, 2 msec} // List of time values + x: int(0), + y: time(0), // Units are missing but not required + z(1 msec), // Type is missing but not required + p: int[](1, 2, 3, 4), // List of integers + q: interval_t[](1 msec, 2 msec, 3 msec), // list of time values + g: time[](1 msec, 2 msec) // List of time values ) { - state s: time = y // Reference to explicitly typed time parameter - state t: time = z // Reference to implicitly typed time parameter + state s: time(y) // Reference to explicitly typed time parameter + state t: time(z) // Reference to implicitly typed time parameter state v: bool // Uninitialized boolean state variable state w: time // Uninitialized time state variable timer tick(0) // Units missing but not required timer tock(1 sec) // Implicit type time timer toe(z) // Implicit type time - state baz = p // Implicit type int[] - state period = z // Implicit type time - - state empty_list: int[] + state baz(p) // Implicit type int[] + state period(z) // Implicit type time reaction(tick) {= // Target code diff --git a/test/C/src/NestedTriggeredReactions.lf b/test/C/src/NestedTriggeredReactions.lf index df52d36a14..6cc5f911b1 100644 --- a/test/C/src/NestedTriggeredReactions.lf +++ b/test/C/src/NestedTriggeredReactions.lf @@ -3,7 +3,7 @@ target C reactor Container { input in: bool - state triggered: bool = false + state triggered: bool(false) contained = new Contained() @@ -21,7 +21,7 @@ reactor Container { reactor Contained { input in: bool - state triggered: bool = false + state triggered: bool(false) reaction(in) {= self->triggered = true; =} diff --git a/test/C/src/ParameterHierarchy.lf b/test/C/src/ParameterHierarchy.lf index 825f9f5a60..433948bd2b 100644 --- a/test/C/src/ParameterHierarchy.lf +++ b/test/C/src/ParameterHierarchy.lf @@ -1,24 +1,24 @@ // Test that parameter values pass down a deep hierarchy. target C -reactor Deep(p0: int = 0) { +reactor Deep(p: int(0)) { reaction(startup) {= - if (self->p0 != 42) { - lf_print_error_and_exit("Parameter value is %d. Should have been 42.", self->p0); + if (self->p != 42) { + lf_print_error_and_exit("Parameter value is %d. Should have been 42."); } else { lf_print("Success."); } =} } -reactor Intermediate(p1: int = 10) { - a0 = new Deep(p0 = p1) +reactor Intermediate(p: int(10)) { + a = new Deep(p = p) } -reactor Another(p2: int = 20) { - a1 = new Intermediate(p1 = p2) +reactor Another(p: int(20)) { + a = new Intermediate(p = p) } main reactor ParameterHierarchy { - a2 = new Another(p2 = 42) + a = new Intermediate(p = 42) } diff --git a/test/C/src/ParameterizedState.lf b/test/C/src/ParameterizedState.lf index 3d92345ca9..1965fa1929 100644 --- a/test/C/src/ParameterizedState.lf +++ b/test/C/src/ParameterizedState.lf @@ -1,7 +1,7 @@ target C -reactor Foo(bar: int = 42) { - state baz = bar +reactor Foo(bar: int(42)) { + state baz(bar) reaction(startup) {= printf("Baz: %d\n", self->baz); =} } diff --git a/test/C/src/PeriodicDesugared.lf b/test/C/src/PeriodicDesugared.lf index 46eb97db9c..6d9f8a8ab4 100644 --- a/test/C/src/PeriodicDesugared.lf +++ b/test/C/src/PeriodicDesugared.lf @@ -3,7 +3,7 @@ target C { timeout: 1 sec } -main reactor(offset: time = 0, period: time = 500 msec) { +main reactor(offset: time(0), period: time(500 msec)) { logical action init(offset) logical action recur(period) diff --git a/test/C/src/PingPong.lf b/test/C/src/PingPong.lf index 2f1699a51d..5ce6caaaaa 100644 --- a/test/C/src/PingPong.lf +++ b/test/C/src/PingPong.lf @@ -25,10 +25,10 @@ target C { fast: true } -reactor Ping(count: int = 10) { +reactor Ping(count: int(10)) { input receive: int output send: int - state pingsLeft: int = count + state pingsLeft: int(count) logical action serve reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} @@ -42,10 +42,10 @@ reactor Ping(count: int = 10) { =} } -reactor Pong(expected: int = 10) { +reactor Pong(expected: int(10)) { input receive: int output send: int - state count: int = 0 + state count: int(0) reaction(receive) -> send {= self->count++; diff --git a/test/C/src/ReadOutputOfContainedReactor.lf b/test/C/src/ReadOutputOfContainedReactor.lf index ce2129069b..6b94d4a44b 100644 --- a/test/C/src/ReadOutputOfContainedReactor.lf +++ b/test/C/src/ReadOutputOfContainedReactor.lf @@ -10,7 +10,7 @@ reactor Contained { main reactor ReadOutputOfContainedReactor { c = new Contained() - state count: int = 0 + state count: int(0) reaction(startup) c.out {= printf("Startup reaction reading output of contained reactor: %d.\n", c.out->value); diff --git a/test/C/src/ScheduleLogicalAction.lf b/test/C/src/ScheduleLogicalAction.lf index 762f8c6f52..e3c898ebb5 100644 --- a/test/C/src/ScheduleLogicalAction.lf +++ b/test/C/src/ScheduleLogicalAction.lf @@ -20,7 +20,7 @@ reactor foo { } reactor print { - state expected_time: time = 0 + state expected_time: time(0) input x: int reaction(x) {= diff --git a/test/C/src/SelfLoop.lf b/test/C/src/SelfLoop.lf index 855be46792..68ca61278e 100644 --- a/test/C/src/SelfLoop.lf +++ b/test/C/src/SelfLoop.lf @@ -7,7 +7,7 @@ reactor Self { input x: int output y: int logical action a: int - state expected: int = 43 + state expected: int(43) reaction(a) -> y {= printf("a = %d\n", a->value); diff --git a/test/C/src/SendingInside.lf b/test/C/src/SendingInside.lf index b1e8f25f93..fcb495305a 100644 --- a/test/C/src/SendingInside.lf +++ b/test/C/src/SendingInside.lf @@ -7,7 +7,7 @@ target C { reactor Printer { input x: int - state count: int = 1 + state count: int(1) reaction(x) {= printf("Inside reactor received: %d\n", x->value); @@ -20,7 +20,7 @@ reactor Printer { } main reactor SendingInside { - state count: int = 0 + state count: int(0) timer t(0, 1 sec) p = new Printer() diff --git a/test/C/src/SendsPointerTest.lf b/test/C/src/SendsPointerTest.lf index 1f17bd1388..c7336ff91f 100644 --- a/test/C/src/SendsPointerTest.lf +++ b/test/C/src/SendsPointerTest.lf @@ -13,7 +13,7 @@ reactor SendsPointer { =} } -reactor Print(expected: int = 42) { // expected parameter is for testing. +reactor Print(expected: int(42)) { // expected parameter is for testing. input in: int_pointer reaction(in) {= diff --git a/test/C/src/SetArray.lf b/test/C/src/SetArray.lf index f30457f9f8..605eed4081 100644 --- a/test/C/src/SetArray.lf +++ b/test/C/src/SetArray.lf @@ -17,7 +17,7 @@ reactor Source { =} } -reactor Print(scale: int = 1) { // The scale parameter is just for testing. +reactor Print(scale: int(1)) { // The scale parameter is just for testing. input in: int[] reaction(in) {= diff --git a/test/C/src/SetToken.lf b/test/C/src/SetToken.lf index b9af4bff20..c2295dbaa0 100644 --- a/test/C/src/SetToken.lf +++ b/test/C/src/SetToken.lf @@ -10,7 +10,7 @@ reactor Source { reaction(a) -> out {= lf_set_token(out, a->token); =} } -reactor Print(expected: int = 42) { // expected parameter is for testing. +reactor Print(expected: int(42)) { // expected parameter is for testing. input in: int* reaction(in) {= diff --git a/test/C/src/SimpleDeadline.lf b/test/C/src/SimpleDeadline.lf index 3e2d786eec..a59a6728e9 100644 --- a/test/C/src/SimpleDeadline.lf +++ b/test/C/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ // violation. target C -reactor Deadline(threshold: time = 100 msec) { +reactor Deadline(threshold: time(100 msec)) { input x: int output deadlineViolation: bool diff --git a/test/C/src/SlowingClock.lf b/test/C/src/SlowingClock.lf index d4a1e1d5f4..6655e87014 100644 --- a/test/C/src/SlowingClock.lf +++ b/test/C/src/SlowingClock.lf @@ -11,8 +11,8 @@ target C { main reactor SlowingClock { logical action a(100 msec) - state interval: time = 100 msec - state expected_time: time = 100 msec + state interval: time(100 msec) + state expected_time: time(100 msec) reaction(startup) -> a {= lf_schedule(a, 0); =} diff --git a/test/C/src/SlowingClockPhysical.lf b/test/C/src/SlowingClockPhysical.lf index 0e82730112..b3255428c2 100644 --- a/test/C/src/SlowingClockPhysical.lf +++ b/test/C/src/SlowingClockPhysical.lf @@ -11,8 +11,8 @@ target C { main reactor SlowingClockPhysical { physical action a(100 msec) - state interval: time = 100 msec - state expected_time: time = 100 msec + state interval: time(100 msec) + state expected_time: time(100 msec) reaction(startup) -> a {= self->expected_time = MSEC(100); diff --git a/test/C/src/Starvation.lf b/test/C/src/Starvation.lf index a1c1167850..38f2a247b6 100644 --- a/test/C/src/Starvation.lf +++ b/test/C/src/Starvation.lf @@ -6,10 +6,10 @@ */ target C -reactor SuperDenseSender(number_of_iterations: int = 10) { +reactor SuperDenseSender(number_of_iterations: int(10)) { logical action loop output out: int - state iterator: int = 0 + state iterator: int(0) reaction(startup, loop) -> out {= if (self->iterator < self->number_of_iterations) { @@ -34,7 +34,7 @@ reactor SuperDenseSender(number_of_iterations: int = 10) { =} } -reactor SuperDenseReceiver(number_of_iterations: int = 10) { +reactor SuperDenseReceiver(number_of_iterations: int(10)) { input in: int reaction(in) {= diff --git a/test/C/src/Stop.lf b/test/C/src/Stop.lf index 1731bced42..fcfa407d35 100644 --- a/test/C/src/Stop.lf +++ b/test/C/src/Stop.lf @@ -11,7 +11,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state reaction_invoked_correctly: bool = false + state reaction_invoked_correctly: bool(false) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/StopZero.lf b/test/C/src/StopZero.lf index e845c6de48..316cce5c6c 100644 --- a/test/C/src/StopZero.lf +++ b/test/C/src/StopZero.lf @@ -8,7 +8,7 @@ target C reactor Sender { output out: int - state reaction_invoked_correctly: bool = false + state reaction_invoked_correctly: bool(false) timer t(0, 1 usec) logical action act diff --git a/test/C/src/Stride.lf b/test/C/src/Stride.lf index 62b9077878..137855990d 100644 --- a/test/C/src/Stride.lf +++ b/test/C/src/Stride.lf @@ -5,8 +5,8 @@ target C { fast: true } -reactor Count(stride: int = 1) { - state count: int = 1 +reactor Count(stride: int(1)) { + state count: int(1) output y: int timer t(0, 100 msec) @@ -18,7 +18,7 @@ reactor Count(stride: int = 1) { reactor Display { input x: int - state expected: int = 1 // for testing. + state expected: int(1) // for testing. reaction(x) {= printf("Received: %d.\n", x->value); diff --git a/test/C/src/StructAsState.lf b/test/C/src/StructAsState.lf index 59ae495853..b57b15d07b 100644 --- a/test/C/src/StructAsState.lf +++ b/test/C/src/StructAsState.lf @@ -10,7 +10,7 @@ main reactor StructAsState { } hello_t; =} // Notice that target code delimiters are no longer necessary. - state s: hello_t = {"Earth", 42} + state s: hello_t("Earth", 42) reaction(startup) {= printf("State s.name=\"%s\", value=%d.\n", self->s.name, self->s.value); diff --git a/test/C/src/StructAsType.lf b/test/C/src/StructAsType.lf index 8674685530..9e43173110 100644 --- a/test/C/src/StructAsType.lf +++ b/test/C/src/StructAsType.lf @@ -23,7 +23,7 @@ reactor Source { =} } -reactor Print(expected: int = 42) { // expected parameter is for testing. +reactor Print(expected: int(42)) { // expected parameter is for testing. input in: hello_t reaction(in) {= diff --git a/test/C/src/StructAsTypeDirect.lf b/test/C/src/StructAsTypeDirect.lf index 29472f057b..f9d85799e9 100644 --- a/test/C/src/StructAsTypeDirect.lf +++ b/test/C/src/StructAsTypeDirect.lf @@ -17,7 +17,7 @@ reactor Source { =} } -reactor Print(expected: int = 42) { // expected parameter is for testing. +reactor Print(expected: int(42)) { // expected parameter is for testing. input in: hello_t reaction(in) {= diff --git a/test/C/src/StructParallel.lf b/test/C/src/StructParallel.lf index 3c8e61a3a2..0d3e78cc3e 100644 --- a/test/C/src/StructParallel.lf +++ b/test/C/src/StructParallel.lf @@ -11,9 +11,9 @@ preamble {= #include "hello.h" =} -reactor Check(expected: int = 42) { +reactor Check(expected: int(42)) { input in: hello_t* - state invoked: bool = false + state invoked: bool(false) reaction(in) {= printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); @@ -32,7 +32,7 @@ reactor Check(expected: int = 42) { =} } -reactor Print(scale: int = 2) { +reactor Print(scale: int(2)) { // Mutable keyword indicates that this reactor wants a writable copy of the // input. mutable input in: hello_t* diff --git a/test/C/src/StructPrint.lf b/test/C/src/StructPrint.lf index 6af0d60c4f..adaf7fbf24 100644 --- a/test/C/src/StructPrint.lf +++ b/test/C/src/StructPrint.lf @@ -20,7 +20,7 @@ reactor Print { =} } -reactor Check(expected: int = 42) { // expected parameter is for testing. +reactor Check(expected: int(42)) { // expected parameter is for testing. input in: hello_t* reaction(in) {= diff --git a/test/C/src/StructScale.lf b/test/C/src/StructScale.lf index 3b92bab002..076d0e7f3f 100644 --- a/test/C/src/StructScale.lf +++ b/test/C/src/StructScale.lf @@ -22,9 +22,9 @@ reactor Source { =} } -reactor TestInput(expected: int = 42) { // expected parameter is for testing. +reactor TestInput(expected: int(42)) { // expected parameter is for testing. input in: hello_t* - state invoked: bool = false + state invoked: bool(false) reaction(in) {= printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); @@ -43,7 +43,7 @@ reactor TestInput(expected: int = 42) { // expected parameter is for testing. =} } -reactor Print(scale: int = 2) { +reactor Print(scale: int(2)) { // Mutable keyword indicates that this reactor wants a writable copy of the // input. mutable input in: hello_t* diff --git a/test/C/src/SubclassesAndStartup.lf b/test/C/src/SubclassesAndStartup.lf index 2dbc1f688f..a8001a907d 100644 --- a/test/C/src/SubclassesAndStartup.lf +++ b/test/C/src/SubclassesAndStartup.lf @@ -1,7 +1,7 @@ target C reactor Super { - state count: int = 0 + state count: int(0) reaction(startup) {= printf("%s(Super) started\n", self->name); @@ -16,7 +16,7 @@ reactor Super { =} } -reactor SubA(name: string = "SubA") extends Super { +reactor SubA(name: string("SubA")) extends Super { reaction(startup) {= printf("%s started\n", self->name); if (self->count == 0) { @@ -26,7 +26,7 @@ reactor SubA(name: string = "SubA") extends Super { =} } -reactor SubB(name: string = "SubB") extends Super { +reactor SubB(name: string("SubB")) extends Super { reaction(startup) {= printf("%s started\n", self->name); if (self->count == 0) { diff --git a/test/C/src/TimeLimit.lf b/test/C/src/TimeLimit.lf index ae178d53b5..2497296efd 100644 --- a/test/C/src/TimeLimit.lf +++ b/test/C/src/TimeLimit.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int - state s: int = 1 + state s: int(1) reaction(x) {= // printf("%d\n", x->value); @@ -39,7 +39,7 @@ reactor Destination { =} } -main reactor TimeLimit(period: time = 1 sec) { +main reactor TimeLimit(period: time(1 sec)) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/C/src/TimeState.lf b/test/C/src/TimeState.lf index cb0a9627f3..790679ccda 100644 --- a/test/C/src/TimeState.lf +++ b/test/C/src/TimeState.lf @@ -1,7 +1,7 @@ target C -reactor Foo(bar: int = 42) { - state baz: time = 500 msec +reactor Foo(bar: int(42)) { + state baz: time(500 msec) reaction(startup) {= printf("Baz: %lld\n", self->baz); =} } diff --git a/test/C/src/Timeout.lf b/test/C/src/Timeout.lf index cb13eafba4..e0bb841b3e 100644 --- a/test/C/src/Timeout.lf +++ b/test/C/src/Timeout.lf @@ -11,7 +11,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool = false + state success: bool(false) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index 2b146bb57c..36a65d6031 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -12,7 +12,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool = false + state success: bool(false) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/ToReactionNested.lf b/test/C/src/ToReactionNested.lf index 11b3577c84..4f89c20e9c 100644 --- a/test/C/src/ToReactionNested.lf +++ b/test/C/src/ToReactionNested.lf @@ -12,8 +12,8 @@ reactor CountContainer { } main reactor { - state count: int = 1 - state received: bool = false + state count: int(1) + state received: bool(false) s = new CountContainer() diff --git a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf index bc62b214e9..544d269242 100644 --- a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf @@ -9,7 +9,7 @@ target C { reactor Source { output[2] out: int - state count: int = 0 + state count: int(0) timer t(0, 200 msec) reaction(t) -> out {= diff --git a/test/C/src/UnconnectedInput.lf b/test/C/src/UnconnectedInput.lf index 21e8cc5a69..f41524fa01 100644 --- a/test/C/src/UnconnectedInput.lf +++ b/test/C/src/UnconnectedInput.lf @@ -7,7 +7,7 @@ target C { reactor Source { output out: int timer t(0, 1 sec) - state s: int = 1 + state s: int(1) reaction(t) -> out {= lf_set(out, self->s++); =} } @@ -27,7 +27,7 @@ reactor Add { reactor Print { input in: int - state expected: int = 1 + state expected: int(1) reaction(in) {= printf("Received: %d.\n", in->value); diff --git a/test/C/src/arduino/DigitalReadSerial.lf b/test/C/src/arduino/DigitalReadSerial.lf index d79f86ad9b..febc640eb3 100644 --- a/test/C/src/arduino/DigitalReadSerial.lf +++ b/test/C/src/arduino/DigitalReadSerial.lf @@ -11,7 +11,7 @@ target C { main reactor DigitalReadSerial { timer t1(0, 1 msec) - state pushButton: int = 2 + state pushButton: int(2) reaction(startup) {= pinMode(self->pushButton, INPUT); =} diff --git a/test/C/src/arduino/Fade.lf b/test/C/src/arduino/Fade.lf index d23aabd646..0408fb5a1a 100644 --- a/test/C/src/arduino/Fade.lf +++ b/test/C/src/arduino/Fade.lf @@ -14,9 +14,9 @@ target C { main reactor Fade { timer t1(0, 30 msec) - state led: int = 9 - state brightness: int = 9 - state fadeAmount: int = 5 + state led: int(9) + state brightness: int(9) + state fadeAmount: int(5) reaction(startup) {= pinMode(self->led, OUTPUT); =} diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index ec2beae766..90c300a8b2 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -33,12 +33,12 @@ main reactor AsyncCallback { lf_thread_t threadId; =} timer t(0, 200 msec) - state thread_id: lf_thread_t = 0 - state expected_time: time = 100 msec - state toggle: bool = false + state thread_id: lf_thread_t(0) + state expected_time: time(100 msec) + state toggle: bool(false) physical action a(100 msec): int - state i: int = 0 + state i: int(0) reaction(t) -> a {= // start new thread, provide callback diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index f123bcdbdf..17cb113a99 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -28,12 +28,12 @@ main reactor { lf_thread_t threadId; =} timer t(0, 200 msec) - state thread_id: lf_thread_t = 0 - state expected_time: time = 100 msec - state toggle: bool = false + state thread_id: lf_thread_t(0) + state expected_time: time(100 msec) + state toggle: bool(false) physical action a(100 msec, 100 msec, "drop"): int - state i: int = 0 + state i: int(0) reaction(t) -> a {= // start new thread, provide callback diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index b7afeb2363..49dc3e75e9 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -28,12 +28,12 @@ main reactor { lf_thread_t threadId; =} timer t(0, 200 msec) - state thread_id: lf_thread_t = 0 - state expected_time: time = 100 msec - state toggle: bool = false + state thread_id: lf_thread_t(0) + state expected_time: time(100 msec) + state toggle: bool(false) physical action a(100 msec, 100 msec, "replace"): int - state i: int = 0 + state i: int(0) reaction(t) -> a {= // start new thread, provide callback diff --git a/test/C/src/concurrent/CompositionThreaded.lf b/test/C/src/concurrent/CompositionThreaded.lf index cf0bafeb82..decf56d687 100644 --- a/test/C/src/concurrent/CompositionThreaded.lf +++ b/test/C/src/concurrent/CompositionThreaded.lf @@ -5,10 +5,10 @@ target C { timeout: 10 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor Source(period: time = 2 sec) { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= (self->count)++; diff --git a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf index 545206de91..87359286ed 100644 --- a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -2,7 +2,7 @@ // container reacts to that output. target C -reactor Deadline(threshold: time = 100 msec) { +reactor Deadline(threshold: time(100 msec)) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time = 100 msec) { } main reactor { - state violation_detected: bool = false + state violation_detected: bool(false) d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index ac765fe6f7..fccb60001b 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -5,10 +5,10 @@ target C { timeout: 6 sec } -reactor Source(period: time = 3000 msec) { +reactor Source(period: time(3000 msec)) { output y: int timer t(0, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= if (2 * (self->count / 2) != self->count) { @@ -22,9 +22,9 @@ reactor Source(period: time = 3000 msec) { =} } -reactor Destination(timeout: time = 1 sec) { +reactor Destination(timeout: time(1 sec)) { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= printf("Destination receives: %d\n", x->value); diff --git a/test/C/src/concurrent/DelayIntThreaded.lf b/test/C/src/concurrent/DelayIntThreaded.lf index 449b17eb60..5c2c983508 100644 --- a/test/C/src/concurrent/DelayIntThreaded.lf +++ b/test/C/src/concurrent/DelayIntThreaded.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target C -reactor Delay(delay: time = 100 msec) { +reactor Delay(delay: time(100 msec)) { input in: int output out: int logical action a: int @@ -16,8 +16,8 @@ reactor Delay(delay: time = 100 msec) { reactor Test { input in: int - state start_time: time = 0 - state received_value: bool = false + state start_time: time(0) + state received_value: bool(false) reaction(startup) {= // Record the logical time at the start. diff --git a/test/C/src/concurrent/DoubleReactionThreaded.lf b/test/C/src/concurrent/DoubleReactionThreaded.lf index ba6c38ca19..66885ab7a0 100644 --- a/test/C/src/concurrent/DoubleReactionThreaded.lf +++ b/test/C/src/concurrent/DoubleReactionThreaded.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -19,7 +19,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int input w: int - state s: int = 2 + state s: int(2) reaction(x, w) {= int sum = 0; diff --git a/test/C/src/concurrent/GainThreaded.lf b/test/C/src/concurrent/GainThreaded.lf index d9d6ec7673..b59d2b00fb 100644 --- a/test/C/src/concurrent/GainThreaded.lf +++ b/test/C/src/concurrent/GainThreaded.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target C -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { input x: int output y: int @@ -10,7 +10,7 @@ reactor Scale(scale: int = 2) { reactor Test { input x: int - state received_value: bool = false + state received_value: bool(false) reaction(x) {= printf("Received %d.\n", x->value); diff --git a/test/C/src/concurrent/HelloThreaded.lf b/test/C/src/concurrent/HelloThreaded.lf index a8ea34dd05..72c7560ede 100644 --- a/test/C/src/concurrent/HelloThreaded.lf +++ b/test/C/src/concurrent/HelloThreaded.lf @@ -8,9 +8,9 @@ target C { fast: true } -reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { - state count: int = 0 - state previous_time: time = 0 +reactor Reschedule(period: time(2 sec), message: string("Hello C")) { + state count: int(0) + state previous_time: time(0) timer t(1 sec, period) logical action a @@ -43,8 +43,8 @@ reactor Reschedule(period: time = 2 sec, message: string = "Hello C") { } reactor Inside( - period: time = 1 sec, - message: string = "Composite default message." + period: time(1 sec), + message: string("Composite default message.") ) { third_instance = new Reschedule(period = period, message = message) } diff --git a/test/C/src/concurrent/PingPongThreaded.lf b/test/C/src/concurrent/PingPongThreaded.lf index 4fae17911e..0f2e60f065 100644 --- a/test/C/src/concurrent/PingPongThreaded.lf +++ b/test/C/src/concurrent/PingPongThreaded.lf @@ -25,10 +25,10 @@ target C { fast: true } -reactor Ping(count: int = 10) { +reactor Ping(count: int(10)) { input receive: int output send: int - state pingsLeft: int = count + state pingsLeft: int(count) logical action serve reaction(startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} @@ -42,10 +42,10 @@ reactor Ping(count: int = 10) { =} } -reactor Pong(expected: int = 10) { +reactor Pong(expected: int(10)) { input receive: int output send: int - state count: int = 0 + state count: int(0) reaction(receive) -> send {= self->count++; diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index e68b3956e8..7e5e8318b1 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -12,7 +12,7 @@ target C { reactor Scheduler { logical action act // List of microsteps. Size = 16 - state microstep_delay_list: uint32_t[] = { + state microstep_delay_list: uint32_t[]( 0, 1, 1, @@ -29,9 +29,8 @@ reactor Scheduler { 4, 4, 5 - } - - state times: int[] = { + ) + state times: int[]( 0, 0, 0, @@ -48,10 +47,10 @@ reactor Scheduler { 900 msec, 900 msec, 900 msec - } + ) // Size = 9 - state action_hit_list_microstep: int[] = {1, 2, 0, 1, 0, 2, 3, 4, 5} - state action_hit_list_times: int[] = { + state action_hit_list_microstep: int[](1, 2, 0, 1, 0, 2, 3, 4, 5) + state action_hit_list_times: int[]( 0, 0, 400 msec, @@ -61,9 +60,9 @@ reactor Scheduler { 800 msec, 900 msec, 900 msec - } + ) // Size = 9 - state action_hit_list_index: int = 0 + state action_hit_list_index: int(0) reaction(startup) -> act {= for (int i=0; i < 16; i++) { diff --git a/test/C/src/concurrent/ScheduleTwice.lf b/test/C/src/concurrent/ScheduleTwice.lf index e19f4d02d5..41512f3c7d 100644 --- a/test/C/src/concurrent/ScheduleTwice.lf +++ b/test/C/src/concurrent/ScheduleTwice.lf @@ -2,7 +2,7 @@ target C main reactor ScheduleTwice { logical action a: int - state rc_count: int = 0 + state rc_count: int(0) preamble {= #define VERBOSE =} diff --git a/test/C/src/concurrent/ScheduleTwiceThreaded.lf b/test/C/src/concurrent/ScheduleTwiceThreaded.lf index 499e0e4999..a368bec1ec 100644 --- a/test/C/src/concurrent/ScheduleTwiceThreaded.lf +++ b/test/C/src/concurrent/ScheduleTwiceThreaded.lf @@ -2,7 +2,7 @@ target C main reactor { logical action a: int - state rc_count: int = 0 + state rc_count: int(0) reaction(startup) -> a {= lf_schedule_int(a, MSEC(100), 42); diff --git a/test/C/src/concurrent/SendingInsideThreaded.lf b/test/C/src/concurrent/SendingInsideThreaded.lf index e5185ecfc8..e08a5dffb5 100644 --- a/test/C/src/concurrent/SendingInsideThreaded.lf +++ b/test/C/src/concurrent/SendingInsideThreaded.lf @@ -7,7 +7,7 @@ target C { reactor Printer { input x: int - state count: int = 1 + state count: int(1) reaction(x) {= printf("Inside reactor received: %d\n", x->value); @@ -20,7 +20,7 @@ reactor Printer { } main reactor SendingInsideThreaded { - state count: int = 0 + state count: int(0) timer t(0, 1 sec) p = new Printer() diff --git a/test/C/src/concurrent/StarvationThreaded.lf b/test/C/src/concurrent/StarvationThreaded.lf index a16b5e46b6..58d063647d 100644 --- a/test/C/src/concurrent/StarvationThreaded.lf +++ b/test/C/src/concurrent/StarvationThreaded.lf @@ -7,10 +7,10 @@ */ target C -reactor SuperDenseSender(number_of_iterations: int = 10) { +reactor SuperDenseSender(number_of_iterations: int(10)) { logical action loop output out: int - state iterator: int = 0 + state iterator: int(0) reaction(startup, loop) -> out {= if (self->iterator < self->number_of_iterations) { @@ -35,7 +35,7 @@ reactor SuperDenseSender(number_of_iterations: int = 10) { =} } -reactor SuperDenseReceiver(number_of_iterations: int = 10) { +reactor SuperDenseReceiver(number_of_iterations: int(10)) { input in: int reaction(in) {= diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index 1deb1c4ff6..aa69bda345 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -13,7 +13,7 @@ import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { input in: int - state reaction_invoked_correctly: bool = false + state reaction_invoked_correctly: bool(false) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/concurrent/StopZeroThreaded.lf b/test/C/src/concurrent/StopZeroThreaded.lf index 7afd4b0069..051c615566 100644 --- a/test/C/src/concurrent/StopZeroThreaded.lf +++ b/test/C/src/concurrent/StopZeroThreaded.lf @@ -8,7 +8,7 @@ target C reactor Sender { output out: int - state reaction_invoked_correctly: bool = false + state reaction_invoked_correctly: bool(false) timer t(0, 1 usec) logical action act diff --git a/test/C/src/concurrent/Threaded.lf b/test/C/src/concurrent/Threaded.lf index 01f67c1bd4..abfcff2c1b 100644 --- a/test/C/src/concurrent/Threaded.lf +++ b/test/C/src/concurrent/Threaded.lf @@ -16,7 +16,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= lf_set(out, self->s); @@ -40,8 +40,8 @@ reactor TakeTime { =} } -reactor Destination(width: int = 4) { - state s: int = 400000000 +reactor Destination(width: int(4)) { + state s: int(400000000) input[width] in: int reaction(in) {= @@ -58,7 +58,7 @@ reactor Destination(width: int = 4) { =} } -main reactor(width: int = 4) { +main reactor(width: int(4)) { a = new Source() t = new[width] TakeTime() (a.out)+ -> t.in diff --git a/test/C/src/concurrent/ThreadedMultiport.lf b/test/C/src/concurrent/ThreadedMultiport.lf index 2878393dac..b24ead7cd9 100644 --- a/test/C/src/concurrent/ThreadedMultiport.lf +++ b/test/C/src/concurrent/ThreadedMultiport.lf @@ -5,10 +5,10 @@ target C { flags: "" } -reactor Source(width: int = 4) { +reactor Source(width: int(4)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -18,7 +18,7 @@ reactor Source(width: int = 4) { =} } -reactor Computation(iterations: int = 100000000) { +reactor Computation(iterations: int(100000000)) { input in: int output out: int @@ -34,8 +34,8 @@ reactor Computation(iterations: int = 100000000) { =} } -reactor Destination(width: int = 4, iterations: int = 100000000) { - state s: int = 0 +reactor Destination(width: int(4), iterations: int(100000000)) { + state s: int(0) input[width] in: int reaction(in) {= @@ -61,7 +61,7 @@ reactor Destination(width: int = 4, iterations: int = 100000000) { =} } -main reactor ThreadedMultiport(width: int = 4, iterations: int = 100000000) { +main reactor ThreadedMultiport(width: int(4), iterations: int(100000000)) { a = new Source(width = width) t = new[width] Computation(iterations = iterations) b = new Destination(width = width, iterations = iterations) diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 4037e8c193..9db95faaf0 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -15,7 +15,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= lf_set(out, self->s); @@ -39,8 +39,8 @@ reactor TakeTime { =} } -reactor Destination(width: int = 4) { - state s: int = 400000000 +reactor Destination(width: int(4)) { + state s: int(400000000) input[width] in: int reaction(in) {= @@ -57,7 +57,7 @@ reactor Destination(width: int = 4) { =} } -main reactor ThreadedThreaded(width: int = 4) { +main reactor ThreadedThreaded(width: int(4)) { a = new Source() t = new[width] TakeTime() (a.out)+ -> t.in diff --git a/test/C/src/concurrent/TimeLimitThreaded.lf b/test/C/src/concurrent/TimeLimitThreaded.lf index 8d3824af47..97bb9cfec6 100644 --- a/test/C/src/concurrent/TimeLimitThreaded.lf +++ b/test/C/src/concurrent/TimeLimitThreaded.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -18,7 +18,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int - state s: int = 1 + state s: int(1) reaction(x) {= // printf("%d\n", x->value); @@ -38,7 +38,7 @@ reactor Destination { =} } -main reactor(period: time = 1 sec) { +main reactor(period: time(1 sec)) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index 3a7e2181d7..993366a2c0 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -12,7 +12,7 @@ import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool = false + state success: bool(false) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index 9b24ef080f..4a0bdd62a3 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -12,7 +12,7 @@ import Sender from "../lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool = false + state success: bool(false) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index 71da79c7ef..ff2f436e85 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -10,7 +10,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= lf_set(out, self->s); @@ -18,10 +18,10 @@ reactor Source { =} } -reactor TakeTime(bank_index: int = 0) { +reactor TakeTime(bank_index: int(0)) { input in: int output out: int - state event: char* = "No ID" + state event: char*("No ID") reaction(startup) {= // Construct an id string for a user trace event. @@ -57,9 +57,9 @@ reactor TakeTime(bank_index: int = 0) { =} } -reactor Destination(width: int = 4) { - state s: int = 400000000 - state count: int = 0 +reactor Destination(width: int(4)) { + state s: int(400000000) + state count: int(0) input[width] in: int reaction(startup) {= @@ -86,7 +86,7 @@ reactor Destination(width: int = 4) { =} } -main reactor(width: int = 4) { +main reactor(width: int(4)) { a = new Source() t = new[width] TakeTime() (a.out)+ -> t.in diff --git a/test/C/src/docker/federated/DistributedCountContainerized.lf b/test/C/src/docker/federated/DistributedCountContainerized.lf index 4a120c5e1e..9eb6898a9d 100644 --- a/test/C/src/docker/federated/DistributedCountContainerized.lf +++ b/test/C/src/docker/federated/DistributedCountContainerized.lf @@ -15,9 +15,7 @@ target C { import Count from "../../lib/Count.lf" import Print from "../../federated/DistributedCount.lf" -federated reactor DistributedCountContainerized( - offset: time = 200 msec -) at rti { +federated reactor DistributedCountContainerized(offset: time(200 msec)) at rti { c = new Count() p = new Print() c.out -> p.in after offset diff --git a/test/C/src/federated/BroadcastFeedback.lf b/test/C/src/federated/BroadcastFeedback.lf index 2bef908d2d..0c7146b8f7 100644 --- a/test/C/src/federated/BroadcastFeedback.lf +++ b/test/C/src/federated/BroadcastFeedback.lf @@ -9,7 +9,7 @@ target C { reactor SenderAndReceiver { output out: int input[2] in: int - state received: bool = false + state received: bool(false) reaction(startup) -> out {= lf_set(out, 42); =} diff --git a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf index d9edbc954b..1632f0332a 100644 --- a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -8,7 +8,7 @@ target C { reactor SenderAndReceiver { output out: int input[2] in: int - state received: bool = false + state received: bool(false) r = new Receiver() in -> r.in @@ -18,7 +18,7 @@ reactor SenderAndReceiver { reactor Receiver { input[2] in: int - state received: bool = false + state received: bool(false) reaction(in) {= if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) { diff --git a/test/C/src/federated/CycleDetection.lf b/test/C/src/federated/CycleDetection.lf index d22837bc1f..90ce0faba2 100644 --- a/test/C/src/federated/CycleDetection.lf +++ b/test/C/src/federated/CycleDetection.lf @@ -10,7 +10,7 @@ reactor CAReplica { input remote_update: int input query: int - state balance: int = 0 + state balance: int(0) output response: int diff --git a/test/C/src/federated/DecentralizedP2PComm.lf b/test/C/src/federated/DecentralizedP2PComm.lf index 0ca6a10e6f..5791ddd8a7 100644 --- a/test/C/src/federated/DecentralizedP2PComm.lf +++ b/test/C/src/federated/DecentralizedP2PComm.lf @@ -6,15 +6,15 @@ target C { } reactor Platform( - start: int = 0, - expected_start: int = 0, - stp_offset_param: time = 0 + start: int(0), + expected_start: int(0), + stp_offset_param: time(0) ) { input in: int output out: int timer t(0, 100 msec) - state count: int = start - state expected: int = expected_start + state count: int(start) + state expected: int(expected_start) reaction(t) -> out {= lf_set(out, self->count++); =} diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf index fca2149fcf..3b872b8408 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -11,10 +11,10 @@ target C { coordination: decentralized } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -29,7 +29,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int - state s: int = 1 + state s: int(1) reaction(x) {= lf_print("Received %d", x->value); @@ -48,7 +48,7 @@ reactor Destination { =} } -federated reactor(period: time = 10 usec) { +federated reactor(period: time(10 usec)) { c = new Clock(period = period) d = new Destination() c.y -> d.x diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 8468e1dc81..49562c7e77 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -12,10 +12,10 @@ target C { coordination: decentralized } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= (self->count)++; @@ -30,7 +30,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int - state s: int = 1 + state s: int(1) reaction(x) {= // printf("%d\n", x->value); @@ -46,7 +46,7 @@ reactor Destination { =} } -federated reactor(period: time = 10 usec) { +federated reactor(period: time(10 usec)) { c = new Clock(period = period) d = new Destination() c.y ~> d.x diff --git a/test/C/src/federated/DistributedBank.lf b/test/C/src/federated/DistributedBank.lf index 84acb00031..9dd1247980 100644 --- a/test/C/src/federated/DistributedBank.lf +++ b/test/C/src/federated/DistributedBank.lf @@ -6,7 +6,7 @@ target C { reactor Node { timer t(0, 100 msec) - state count: int = 0 + state count: int(0) reaction(t) {= lf_print("Hello world %d.", self->count++); =} diff --git a/test/C/src/federated/DistributedBankToMultiport.lf b/test/C/src/federated/DistributedBankToMultiport.lf index 796db0718e..b392b3e603 100644 --- a/test/C/src/federated/DistributedBankToMultiport.lf +++ b/test/C/src/federated/DistributedBankToMultiport.lf @@ -7,7 +7,7 @@ import Count from "../lib/Count.lf" reactor Destination { input[2] in: int - state count: int = 1 + state count: int(1) reaction(in) {= for (int i = 0; i < in_width; i++) { diff --git a/test/C/src/federated/DistributedCount.lf b/test/C/src/federated/DistributedCount.lf index 2ebdda169a..7ffd4eb8e2 100644 --- a/test/C/src/federated/DistributedCount.lf +++ b/test/C/src/federated/DistributedCount.lf @@ -14,7 +14,7 @@ import Count from "../lib/Count.lf" reactor Print { input in: int - state c: int = 1 + state c: int(1) reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); @@ -35,7 +35,7 @@ reactor Print { =} } -federated reactor DistributedCount(offset: time = 200 msec) { +federated reactor DistributedCount(offset: time(200 msec)) { c = new Count() p = new Print() c.out -> p.in after offset diff --git a/test/C/src/federated/DistributedCountDecentralized.lf b/test/C/src/federated/DistributedCountDecentralized.lf index 631dfab0c0..e7ee0a7d77 100644 --- a/test/C/src/federated/DistributedCountDecentralized.lf +++ b/test/C/src/federated/DistributedCountDecentralized.lf @@ -14,7 +14,7 @@ import Count from "../lib/Count.lf" reactor Print { input in: int - state c: int = 1 + state c: int(1) reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedCountDecentralizedLate.lf b/test/C/src/federated/DistributedCountDecentralizedLate.lf index 9fb6d3b064..fa85987e87 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLate.lf @@ -15,12 +15,12 @@ import Count from "../lib/Count.lf" reactor Print { input in: int // STP () - state success: int = 0 // STP(in, 30 msec); - state success_stp_violation: int = 0 + state success: int(0) // STP(in, 30 msec); + state success_stp_violation: int(0) // Force a timer to be invoke periodically to ensure logical time will // advance in the absence of incoming messages. timer t(0, 10 msec) - state c: int = 0 + state c: int(0) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf index 31ab87e110..26c20521e3 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -17,12 +17,12 @@ import Count from "../lib/Count.lf" reactor ImportantActuator { input in: int - state success: int = 0 - state success_stp_violation: int = 0 + state success: int(0) + state success_stp_violation: int(0) // Force a timer to be invoke periodically timer t(0, 10 msec) // to ensure logical time will advance in the absence of incoming messages. - state c: int = 0 + state c: int(0) reaction(in) {= tag_t current_tag = lf_tag(); @@ -79,7 +79,7 @@ reactor Receiver { // Force a timer to be invoke periodically timer t(0, 10 msec) // to ensure logical time will advance in the absence of incoming messages. - state c: int = 0 + state c: int(0) p = new Print() a = new ImportantActuator() in -> p.in diff --git a/test/C/src/federated/DistributedCountPhysical.lf b/test/C/src/federated/DistributedCountPhysical.lf index 9e1e15f775..67d90ec4c1 100644 --- a/test/C/src/federated/DistributedCountPhysical.lf +++ b/test/C/src/federated/DistributedCountPhysical.lf @@ -13,7 +13,7 @@ target C { reactor Count { timer t(200 msec, 1 sec) - state s: int = 0 + state s: int(0) output out: int reaction(t) -> out {= @@ -24,7 +24,7 @@ reactor Count { reactor Print { input in: int - state c: int = 0 + state c: int(0) reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf index b0da42218a..2d13891bae 100644 --- a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -12,7 +12,7 @@ import Count from "../lib/Count.lf" reactor Print { input in: int - state c: int = 1 + state c: int(1) reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf index e821e4fb70..6bc50fce88 100644 --- a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf @@ -14,7 +14,7 @@ target C { reactor Count { timer t(200 msec, 1 sec) - state s: int = 0 + state s: int(0) output out: int reaction(t) -> out {= @@ -25,7 +25,7 @@ reactor Count { reactor Print { input in: int - state c: int = 0 + state c: int(0) reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/DistributedDoublePort.lf b/test/C/src/federated/DistributedDoublePort.lf index 87de1ddb28..2490df67bf 100644 --- a/test/C/src/federated/DistributedDoublePort.lf +++ b/test/C/src/federated/DistributedDoublePort.lf @@ -14,7 +14,7 @@ target C { import Count from "../lib/Count.lf" reactor CountMicrostep { - state count: int = 1 + state count: int(1) output out: int logical action act: int timer t(0, 1 sec) diff --git a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf index acbbaf4035..078b15ed02 100644 --- a/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedLogicalActionUpstreamLong.lf @@ -11,8 +11,8 @@ import TestCount from "../lib/TestCount.lf" reactor WithLogicalAction { output out: int - state thread_id: lf_thread_t = 0 - state counter: int = 1 + state thread_id: lf_thread_t(0) + state counter: int(1) logical action act(0): int reaction(startup, act) -> act, out {= diff --git a/test/C/src/federated/DistributedLoopedAction.lf b/test/C/src/federated/DistributedLoopedAction.lf index 8218e73646..1a70412696 100644 --- a/test/C/src/federated/DistributedLoopedAction.lf +++ b/test/C/src/federated/DistributedLoopedAction.lf @@ -10,14 +10,11 @@ target C { import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver( - take_a_break_after: int = 10, - break_interval: time = 400 msec -) { +reactor Receiver(take_a_break_after: int(10), break_interval: time(400 msec)) { input in: int - state received_messages: int = 0 - state total_received_messages: int = 0 - state breaks: int = 0 + state received_messages: int(0) + state total_received_messages: int(0) + state breaks: int(0) timer t(0, 1 msec) // This will impact the performance // but forces the logical time to advance Comment this line for a more diff --git a/test/C/src/federated/DistributedLoopedActionDecentralized.lf b/test/C/src/federated/DistributedLoopedActionDecentralized.lf index 17842809fa..f1addfb63c 100644 --- a/test/C/src/federated/DistributedLoopedActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedActionDecentralized.lf @@ -20,14 +20,11 @@ target C { import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver( - take_a_break_after: int = 10, - break_interval: time = 400 msec -) { +reactor Receiver(take_a_break_after: int(10), break_interval: time(400 msec)) { input in: int - state received_messages: int = 0 - state total_received_messages: int = 0 - state breaks: int = 0 + state received_messages: int(0) + state total_received_messages: int(0) + state breaks: int(0) reaction(in) {= tag_t current_tag = lf_tag(); @@ -80,12 +77,12 @@ reactor Receiver( } reactor STPReceiver( - take_a_break_after: int = 10, - break_interval: time = 400 msec, - stp_offset: time = 0 + take_a_break_after: int(10), + break_interval: time(400 msec), + stp_offset: time(0) ) { input in: int - state last_time_updated_stp: time = 0 + state last_time_updated_stp: time(0) receiver = new Receiver(take_a_break_after = 10, break_interval = 400 msec) timer t(0, 1 msec) // Force advancement of logical time diff --git a/test/C/src/federated/DistributedLoopedPhysicalAction.lf b/test/C/src/federated/DistributedLoopedPhysicalAction.lf index 454577ff35..7b42628683 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalAction.lf @@ -16,10 +16,10 @@ target C { } } -reactor Sender(take_a_break_after: int = 10, break_interval: time = 550 msec) { +reactor Sender(take_a_break_after: int(10), break_interval: time(550 msec)) { output out: int physical action act - state sent_messages: int = 0 + state sent_messages: int(0) reaction(startup, act) -> act, out {= // Send a message on out @@ -35,14 +35,11 @@ reactor Sender(take_a_break_after: int = 10, break_interval: time = 550 msec) { =} } -reactor Receiver( - take_a_break_after: int = 10, - break_interval: time = 550 msec -) { +reactor Receiver(take_a_break_after: int(10), break_interval: time(550 msec)) { input in: int - state received_messages: int = 0 - state total_received_messages: int = 0 - state breaks: int = 0 + state received_messages: int(0) + state total_received_messages: int(0) + state breaks: int(0) timer t(0, 1 msec) // This will impact the performance // but forces the logical time to advance Comment this line for a more diff --git a/test/C/src/federated/DistributedMultiport.lf b/test/C/src/federated/DistributedMultiport.lf index 3853629731..28156d4b70 100644 --- a/test/C/src/federated/DistributedMultiport.lf +++ b/test/C/src/federated/DistributedMultiport.lf @@ -7,7 +7,7 @@ target C { reactor Source { output[4] out: int timer t(0, 100 msec) - state count: int = 0 + state count: int(0) reaction(t) -> out {= for (int i = 0; i < out_width; i++) { @@ -18,7 +18,7 @@ reactor Source { reactor Destination { input[4] in: int - state count: int = 0 + state count: int(0) reaction(in) {= for (int i = 0; i < in_width; i++) { diff --git a/test/C/src/federated/DistributedMultiportToBank.lf b/test/C/src/federated/DistributedMultiportToBank.lf index 0accaf8c60..503dec692e 100644 --- a/test/C/src/federated/DistributedMultiportToBank.lf +++ b/test/C/src/federated/DistributedMultiportToBank.lf @@ -6,7 +6,7 @@ target C { reactor Source { output[2] out: int timer t(0, 100 msec) - state count: int = 0 + state count: int(0) reaction(t) -> out {= for (int i = 0; i < out_width; i++) { @@ -18,7 +18,7 @@ reactor Source { reactor Destination { input in: int - state count: int = 0 + state count: int(0) reaction(in) {= lf_print("Received %d.", in->value); diff --git a/test/C/src/federated/DistributedMultiportToken.lf b/test/C/src/federated/DistributedMultiportToken.lf index dfb791d861..065f480e11 100644 --- a/test/C/src/federated/DistributedMultiportToken.lf +++ b/test/C/src/federated/DistributedMultiportToken.lf @@ -8,7 +8,7 @@ target C { reactor Source { output[4] out: char* timer t(0, 200 msec) - state count: int = 0 + state count: int(0) reaction(t) -> out {= for (int i = 0; i < out_width; i++) { diff --git a/test/C/src/federated/DistributedNetworkOrder.lf b/test/C/src/federated/DistributedNetworkOrder.lf index e18ea4ac04..0b9ca0cd17 100644 --- a/test/C/src/federated/DistributedNetworkOrder.lf +++ b/test/C/src/federated/DistributedNetworkOrder.lf @@ -32,7 +32,7 @@ reactor Sender { reactor Receiver { input in: int - state success: int = 0 + state success: int(0) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/federated/DistributedPhysicalActionUpstream.lf b/test/C/src/federated/DistributedPhysicalActionUpstream.lf index 47280a24b8..2cc6735884 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstream.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstream.lf @@ -30,7 +30,7 @@ preamble {= reactor WithPhysicalAction { output out: int - state thread_id: lf_thread_t = 0 + state thread_id: lf_thread_t(0) physical action act(0): int reaction(startup) -> act {= diff --git a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf index 66bbb964e1..0a6ee31e62 100644 --- a/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf +++ b/test/C/src/federated/DistributedPhysicalActionUpstreamLong.lf @@ -30,7 +30,7 @@ preamble {= reactor WithPhysicalAction { output out: int - state thread_id: lf_thread_t = 0 + state thread_id: lf_thread_t(0) physical action act(0): int reaction(startup) -> act {= diff --git a/test/C/src/federated/DistributedStop.lf b/test/C/src/federated/DistributedStop.lf index 2d4a616664..cf103d8beb 100644 --- a/test/C/src/federated/DistributedStop.lf +++ b/test/C/src/federated/DistributedStop.lf @@ -10,7 +10,7 @@ reactor Sender { output out: int timer t(0, 1 usec) logical action act - state reaction_invoked_correctly: bool = false + state reaction_invoked_correctly: bool(false) reaction(t, act) -> out, act {= lf_print("Sending 42 at (%lld, %u).", @@ -63,10 +63,10 @@ reactor Sender { } reactor Receiver( - stp_offset: time = 10 msec // Used in the decentralized variant of the test + stp_offset: time(10 msec) // Used in the decentralized variant of the test ) { input in: int - state reaction_invoked_correctly: bool = false + state reaction_invoked_correctly: bool(false) reaction(in) {= lf_print("Received %d at (%lld, %u).", diff --git a/test/C/src/federated/DistributedToken.lf b/test/C/src/federated/DistributedToken.lf index 1068bd5f85..c408af6ad2 100644 --- a/test/C/src/federated/DistributedToken.lf +++ b/test/C/src/federated/DistributedToken.lf @@ -26,11 +26,11 @@ target C { * @param root The root string. * @output message The message. */ -reactor MessageGenerator(root: string = "") { +reactor MessageGenerator(root: string("")) { // Output type char* instead of string is used for dynamically allocated // character arrays (as opposed to static constant strings). output message: char* - state count: int = 1 + state count: int(1) // Send first message after 1 sec so that the startup reactions do not // factor into the transport time measurement on the first message. timer t(1 sec, 1 sec) @@ -57,7 +57,7 @@ reactor MessageGenerator(root: string = "") { */ reactor PrintMessage { input message: char* - state count: int = 0 + state count: int(0) reaction(message) {= printf("PrintMessage: At (elapsed) logical time %lld, receiver receives: %s\n", diff --git a/test/C/src/federated/FeedbackDelay.lf b/test/C/src/federated/FeedbackDelay.lf index 997a4ad012..6495fde8db 100644 --- a/test/C/src/federated/FeedbackDelay.lf +++ b/test/C/src/federated/FeedbackDelay.lf @@ -7,8 +7,8 @@ reactor PhysicalPlant { input control: double output sensor: double timer t(0, 33 msec) - state last_sensor_time: time = 0 - state previous_sensor_time: time = 0 + state last_sensor_time: time(0) + state previous_sensor_time: time(0) reaction(t) -> sensor {= lf_set(sensor, 42); @@ -27,8 +27,8 @@ reactor Controller { input sensor: double output control: double - state latest_control: double = 0.0 - state first: bool = true + state latest_control: double(0.0) + state first: bool(true) output request_for_planning: double input planning: double diff --git a/test/C/src/federated/FeedbackDelaySimple.lf b/test/C/src/federated/FeedbackDelaySimple.lf index 0c9b147cda..2f00000e03 100644 --- a/test/C/src/federated/FeedbackDelaySimple.lf +++ b/test/C/src/federated/FeedbackDelaySimple.lf @@ -6,7 +6,7 @@ reactor Loop { input in: int output out: int timer t(0, 100 msec) - state count: int = 1 + state count: int(1) reaction(in) {= lf_print("Received %d.", in->value); diff --git a/test/C/src/federated/HelloDistributed.lf b/test/C/src/federated/HelloDistributed.lf index 6841bf91bc..14b446f26d 100644 --- a/test/C/src/federated/HelloDistributed.lf +++ b/test/C/src/federated/HelloDistributed.lf @@ -19,7 +19,7 @@ reactor Source { reactor Destination { input in: string - state received: bool = false + state received: bool(false) reaction(startup) {= lf_print("Destination started."); =} diff --git a/test/C/src/federated/LoopDistributedCentralized.lf b/test/C/src/federated/LoopDistributedCentralized.lf index 7fdc972b5a..9643d3f1f3 100644 --- a/test/C/src/federated/LoopDistributedCentralized.lf +++ b/test/C/src/federated/LoopDistributedCentralized.lf @@ -14,11 +14,11 @@ target C { logging: DEBUG } -reactor Looper(incr: int = 1, delay: time = 0 msec) { +reactor Looper(incr: int(1), delay: time(0 msec)) { input in: int output out: int physical action a(delay) - state count: int = 0 + state count: int(0) timer t(0, 1 sec) @@ -42,7 +42,7 @@ reactor Looper(incr: int = 1, delay: time = 0 msec) { =} } -federated reactor LoopDistributedCentralized(delay: time = 0) { +federated reactor LoopDistributedCentralized(delay: time(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralized2.lf b/test/C/src/federated/LoopDistributedCentralized2.lf index 82412e16fe..c81a0f012e 100644 --- a/test/C/src/federated/LoopDistributedCentralized2.lf +++ b/test/C/src/federated/LoopDistributedCentralized2.lf @@ -13,11 +13,11 @@ target C { timeout: 4 sec } -reactor Looper(incr: int = 1, delay: time = 0 msec) { +reactor Looper(incr: int(1), delay: time(0 msec)) { input in: int output out: int physical action a(delay) - state count: int = 0 + state count: int(0) timer t(0, 1 sec) @@ -41,11 +41,11 @@ reactor Looper(incr: int = 1, delay: time = 0 msec) { =} } -reactor Looper2(incr: int = 1, delay: time = 0 msec) { +reactor Looper2(incr: int(1), delay: time(0 msec)) { input in: int output out: int physical action a(delay) - state count: int = 0 + state count: int(0) timer t(0, 1 sec) @@ -69,7 +69,7 @@ reactor Looper2(incr: int = 1, delay: time = 0 msec) { =} } -federated reactor(delay: time = 0) { +federated reactor(delay: time(0)) { left = new Looper() right = new Looper2(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf index 44ce6e1681..e622e31979 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPhysicalAction.lf @@ -27,11 +27,11 @@ preamble {= } =} -reactor Looper(incr: int = 1, delay: time = 0 msec) { +reactor Looper(incr: int(1), delay: time(0 msec)) { input in: int output out: int physical action a(delay) - state count: int = 0 + state count: int(0) reaction(startup) -> a {= // Start the thread that listens for Enter or Return. @@ -62,7 +62,7 @@ reactor Looper(incr: int = 1, delay: time = 0 msec) { =} } -federated reactor(delay: time = 0) { +federated reactor(delay: time(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf index f9b088b7d1..a1e6e87b6e 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf @@ -14,11 +14,11 @@ target C { timeout: 5 sec } -reactor Looper(incr: int = 1, delay: time = 0 msec) { +reactor Looper(incr: int(1), delay: time(0 msec)) { input in: int output out: int - state count: int = 0 - state received_count: int = 0 + state count: int(0) + state received_count: int(0) timer t(0, 1 sec) reaction(t) -> out {= @@ -48,7 +48,7 @@ reactor Looper(incr: int = 1, delay: time = 0 msec) { =} } -federated reactor(delay: time = 0) { +federated reactor(delay: time(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 17177aadb3..ef18cadfbf 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -15,11 +15,11 @@ target C { timeout: 5 sec } -reactor Contained(incr: int = 1) { +reactor Contained(incr: int(1)) { timer t(0, 1 sec) input in: int - state count: int = 0 - state received_count: int = 0 + state count: int(0) + state received_count: int(0) reaction(t) {= self->count += self->incr; =} @@ -32,10 +32,10 @@ reactor Contained(incr: int = 1) { =} } -reactor Looper(incr: int = 1, delay: time = 0 msec) { +reactor Looper(incr: int(1), delay: time(0 msec)) { input in: int output out: int - state count: int = 0 + state count: int(0) timer t(0, 1 sec) c = new Contained(incr = incr) @@ -62,7 +62,7 @@ reactor Looper(incr: int = 1, delay: time = 0 msec) { =} } -federated reactor(delay: time = 0) { +federated reactor(delay: time(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedDecentralized.lf b/test/C/src/federated/LoopDistributedDecentralized.lf index ae64e6e71a..c2d4bcb297 100644 --- a/test/C/src/federated/LoopDistributedDecentralized.lf +++ b/test/C/src/federated/LoopDistributedDecentralized.lf @@ -23,11 +23,11 @@ preamble {= } =} -reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { +reactor Looper(incr: int(1), delay: time(0 msec), stp_offset: time(0)) { input in: int output out: int physical action a(stp_offset) - state count: int = 0 + state count: int(0) reaction(startup) -> a {= // Start the thread that listens for Enter or Return. @@ -69,7 +69,7 @@ reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { =} } -federated reactor LoopDistributedDecentralized(delay: time = 0) { +federated reactor LoopDistributedDecentralized(delay: time(0)) { left = new Looper(stp_offset = 900 usec) right = new Looper(incr = -1, stp_offset = 2400 usec) left.out -> right.in diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 31b7eb0f6e..bba7c7ffaa 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -27,13 +27,13 @@ preamble {= } =} -reactor Looper(incr: int = 1, delay: time = 0 msec) { +reactor Looper(incr: int(1), delay: time(0 msec)) { input in: int input in2: int output out: int output out2: int physical action a(delay) - state count: int = 0 + state count: int(0) timer t(0, 1 sec) reaction(startup) -> a {= @@ -82,7 +82,7 @@ reactor Looper(incr: int = 1, delay: time = 0 msec) { =} } -federated reactor(delay: time = 0) { +federated reactor(delay: time(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in diff --git a/test/C/src/federated/PhysicalSTP.lf b/test/C/src/federated/PhysicalSTP.lf index 492cd8875b..1824d9ec93 100644 --- a/test/C/src/federated/PhysicalSTP.lf +++ b/test/C/src/federated/PhysicalSTP.lf @@ -9,9 +9,9 @@ target C { import Count from "../lib/Count.lf" -reactor Print(STP_offset_param: time = 0) { +reactor Print(STP_offset_param: time(0)) { input in: int - state c: int = 1 + state c: int(1) reaction(in) {= interval_t elapsed_time = lf_time_logical_elapsed(); diff --git a/test/C/src/federated/PingPongDistributed.lf b/test/C/src/federated/PingPongDistributed.lf index e16de50ed2..a1d321cc6d 100644 --- a/test/C/src/federated/PingPongDistributed.lf +++ b/test/C/src/federated/PingPongDistributed.lf @@ -23,7 +23,7 @@ target C import Ping, Pong from "PingPongDistributedPhysical.lf" -federated reactor(count: int = 10) { +federated reactor(count: int(10)) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send -> pong.receive diff --git a/test/C/src/federated/PingPongDistributedPhysical.lf b/test/C/src/federated/PingPongDistributedPhysical.lf index d9ba517c59..95427c2a29 100644 --- a/test/C/src/federated/PingPongDistributedPhysical.lf +++ b/test/C/src/federated/PingPongDistributedPhysical.lf @@ -26,10 +26,10 @@ */ target C -reactor Ping(count: int = 10) { +reactor Ping(count: int(10)) { input receive: int output send: int - state pingsLeft: int = count + state pingsLeft: int(count) logical action serve reaction(startup, serve) -> send {= @@ -46,10 +46,10 @@ reactor Ping(count: int = 10) { =} } -reactor Pong(expected: int = 10) { +reactor Pong(expected: int(10)) { input receive: int output send: int - state count: int = 0 + state count: int(0) reaction(receive) -> send {= self->count++; @@ -71,7 +71,7 @@ reactor Pong(expected: int = 10) { =} } -federated reactor(count: int = 10) { +federated reactor(count: int(10)) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send ~> pong.receive diff --git a/test/C/src/federated/failing/SimpleFederatedAuthenticated.lf b/test/C/src/federated/SimpleFederatedAuthenticated.lf similarity index 100% rename from test/C/src/federated/failing/SimpleFederatedAuthenticated.lf rename to test/C/src/federated/SimpleFederatedAuthenticated.lf diff --git a/test/C/src/federated/TopLevelArtifacts.lf b/test/C/src/federated/TopLevelArtifacts.lf index 05932b1937..5fd4b0c376 100644 --- a/test/C/src/federated/TopLevelArtifacts.lf +++ b/test/C/src/federated/TopLevelArtifacts.lf @@ -15,7 +15,7 @@ import Count from "../lib/Count.lf" import TestCount from "../lib/TestCount.lf" federated reactor { - state successes: int = 0 + state successes: int(0) timer t(0, 1 sec) logical action act(0) diff --git a/test/C/src/federated/failing/ClockSync.lf b/test/C/src/federated/failing/ClockSync.lf index 1231ce9cbf..e843f0c549 100644 --- a/test/C/src/federated/failing/ClockSync.lf +++ b/test/C/src/federated/failing/ClockSync.lf @@ -29,7 +29,7 @@ target C { } /** Reactor that outputs periodically. */ -reactor Ticker(period: time = 1600 msec) { +reactor Ticker(period: time(1600 msec)) { output out: int timer tick(0, period) diff --git a/test/C/src/federated/failing/DistributedDoublePortLooped.lf b/test/C/src/federated/failing/DistributedDoublePortLooped.lf index 67a3300c74..4eca2cee76 100644 --- a/test/C/src/federated/failing/DistributedDoublePortLooped.lf +++ b/test/C/src/federated/failing/DistributedDoublePortLooped.lf @@ -19,7 +19,7 @@ reactor Foo { } reactor Count { - state count: int = 1 + state count: int(1) input in1: int input in2: int input in3: int @@ -37,7 +37,7 @@ reactor Count { } reactor CountMicrostep { - state count: int = 1 + state count: int(1) output out: int logical action act: int timer t(0, 1 msec) diff --git a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf index 56a873e1bc..04ea02c4e8 100644 --- a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf +++ b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf @@ -12,7 +12,7 @@ target C { } reactor Count { - state count: int = 1 + state count: int(1) input in: int output out: int timer t(0, 1 msec) @@ -26,7 +26,7 @@ reactor Count { } reactor CountMicrostep { - state count: int = 1 + state count: int(1) output out: int logical action act: int timer t(0, 1 msec) diff --git a/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf b/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf index 97fa16b016..19779de3d2 100644 --- a/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf +++ b/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf @@ -31,7 +31,7 @@ reactor Sender { reactor Receiver { input in: int - state success: int = 0 + state success: int(0) reaction(in) {= tag_t current_tag = lf_tag(); diff --git a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf index b991662a05..ee9fc56d83 100644 --- a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf +++ b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf @@ -11,11 +11,11 @@ target C { timeout: 4900 msec } -reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { +reactor Looper(incr: int(1), delay: time(0 msec), stp_offset: time(0)) { input in: int output out: int - state count: int = 0 - state received_count: int = 0 + state count: int(0) + state received_count: int(0) timer t(0, 1 sec) reaction(t) -> out {= @@ -57,7 +57,7 @@ reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { =} } -federated reactor(delay: time = 0) { +federated reactor(delay: time(0)) { left = new Looper(stp_offset = 5 msec) right = new Looper(incr = -1, stp_offset = 5 msec) left.out -> right.in diff --git a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf index 357b7f2f2d..6cf9236901 100644 --- a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf @@ -1,7 +1,6 @@ /** - * This tests that the precedence order of reaction invocation is kept in the - * hierarchy of reactors when a feedback loop is present in decentralized - * coordination. + * This tests that the precedence order of reaction invocation is kept + * in the hierarchy of reactors when a feedback loop is present in decentralized coordination. * * @author Edward A. Lee * @author Soroush Bateni @@ -12,39 +11,37 @@ target C { timeout: 4900 msec } -import Contained from "../LoopDistributedCentralizedPrecedenceHierarchy.lf" +import Contained from "../LoopDistributedCentralizedPrecedenceHierarchy.lf"; -reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { - input in: int - output out: int - state count: int = 0 - timer t(0, 1 sec) +reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { + input in:int; + output out:int; + state count:int(0); + timer t(0, 1 sec); - c = new Contained(incr = incr) - in -> c.in + c = new Contained(incr = incr); reaction(t) -> out {= lf_set(out, self->count); self->count += self->incr; =} - reaction(in) {= instant_t time_lag = lf_time_physical() - lf_time_logical(); char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 lf_readable_time(time_buffer, time_lag); lf_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} STP(stp_offset) {= + =} STP (stp_offset) {= instant_t time_lag = lf_time_physical() - lf_time_logical(); char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 lf_readable_time(time_buffer, time_lag); lf_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} deadline(10 msec) {= + =} deadline (10 msec) {= instant_t time_lag = lf_time_physical() - lf_time_logical(); char time_buffer[28]; // 28 bytes is enough for the largest 64 bit number: 9,223,372,036,854,775,807 lf_readable_time(time_buffer, time_lag); lf_print("Deadline miss. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); =} - + in->c.in; reaction(shutdown) {= lf_print("******* Shutdown invoked."); if (self->count != 5 * self->incr) { @@ -52,10 +49,9 @@ reactor Looper(incr: int = 1, delay: time = 0 msec, stp_offset: time = 0) { } =} } - -federated reactor(delay: time = 0) { - left = new Looper(stp_offset = 5 msec) - right = new Looper(incr = -1, stp_offset = 5 msec) - left.out -> right.in - right.out -> left.in +federated reactor (delay:time(0)) { + left = new Looper(stp_offset = 5 msec); + right = new Looper(incr = -1, stp_offset = 5 msec); + left.out -> right.in; + right.out -> left.in; } diff --git a/test/C/src/lib/Count.lf b/test/C/src/lib/Count.lf index 70291e783f..fc95ead637 100644 --- a/test/C/src/lib/Count.lf +++ b/test/C/src/lib/Count.lf @@ -1,7 +1,7 @@ target C -reactor Count(offset: time = 0, period: time = 1 sec) { - state count: int = 1 +reactor Count(offset: time(0), period: time(1 sec)) { + state count: int(1) output out: int timer t(offset, period) diff --git a/test/C/src/lib/InternalDelay.lf b/test/C/src/lib/InternalDelay.lf index fbbf2f0cb6..013b916ecc 100644 --- a/test/C/src/lib/InternalDelay.lf +++ b/test/C/src/lib/InternalDelay.lf @@ -1,6 +1,6 @@ target C -reactor InternalDelay(delay: int = 10 msec) { +reactor InternalDelay(delay: int(10 msec)) { input in: int output out: int logical action d: int diff --git a/test/C/src/lib/LoopedActionSender.lf b/test/C/src/lib/LoopedActionSender.lf index b996fe6ac5..2e24f1677f 100644 --- a/test/C/src/lib/LoopedActionSender.lf +++ b/test/C/src/lib/LoopedActionSender.lf @@ -11,10 +11,10 @@ target C * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { +reactor Sender(take_a_break_after: int(10), break_interval: time(400 msec)) { output out: int logical action act - state sent_messages: int = 0 + state sent_messages: int(0) reaction(startup, act) -> act, out {= // Send a message on out diff --git a/test/C/src/lib/Test.lf b/test/C/src/lib/Test.lf index 3ad7518d4e..ea341ae772 100644 --- a/test/C/src/lib/Test.lf +++ b/test/C/src/lib/Test.lf @@ -1,8 +1,8 @@ target C -reactor TestDouble(expected: double[] = {1.0, 1.0, 1.0, 1.0}) { +reactor TestDouble(expected: double[](1.0, 1.0, 1.0, 1.0)) { input in: double - state count: int = 0 + state count: int(0) reaction(in) {= printf("Received: %f\n", in->value); diff --git a/test/C/src/lib/TestCount.lf b/test/C/src/lib/TestCount.lf index d3f29aec6c..3db3fbb2fc 100644 --- a/test/C/src/lib/TestCount.lf +++ b/test/C/src/lib/TestCount.lf @@ -9,9 +9,9 @@ */ target C -reactor TestCount(start: int = 1, stride: int = 1, num_inputs: int = 1) { - state count: int = start - state inputs_received: int = 0 +reactor TestCount(start: int(1), stride: int(1), num_inputs: int(1)) { + state count: int(start) + state inputs_received: int(0) input in: int reaction(in) {= diff --git a/test/C/src/lib/TestCountMultiport.lf b/test/C/src/lib/TestCountMultiport.lf index 5a2db4b029..2a24922ef8 100644 --- a/test/C/src/lib/TestCountMultiport.lf +++ b/test/C/src/lib/TestCountMultiport.lf @@ -12,13 +12,13 @@ target C reactor TestCountMultiport( - start: int = 1, - stride: int = 1, - num_inputs: int = 1, - width: int = 2 + start: int(1), + stride: int(1), + num_inputs: int(1), + width: int(2) ) { - state count: int = start - state inputs_received: int = 0 + state count: int(start) + state inputs_received: int(0) input[width] in: int reaction(in) {= diff --git a/test/C/src/modal_models/ConvertCaseTest.lf b/test/C/src/modal_models/ConvertCaseTest.lf index 5475edaa35..494a3c273c 100644 --- a/test/C/src/modal_models/ConvertCaseTest.lf +++ b/test/C/src/modal_models/ConvertCaseTest.lf @@ -83,9 +83,9 @@ reactor Converter { } } -reactor InputFeeder(message: string = "") { +reactor InputFeeder(message: string("")) { output character: char - state idx: int = 0 + state idx: int(0) timer t(0, 250 msec) diff --git a/test/C/src/modal_models/Count3Modes.lf b/test/C/src/modal_models/Count3Modes.lf index 862915abed..5ef26ccde0 100644 --- a/test/C/src/modal_models/Count3Modes.lf +++ b/test/C/src/modal_models/Count3Modes.lf @@ -34,7 +34,7 @@ main reactor { timer stepper(0, 250 msec) counter = new CounterCycle() - state expected_value: int = 1 + state expected_value: int(1) // Trigger reaction(stepper) -> counter.next {= lf_set(counter.next, true); =} diff --git a/test/C/src/modal_models/MixedReactions.lf b/test/C/src/modal_models/MixedReactions.lf index 78ea39c95c..e0c9c7f0f7 100644 --- a/test/C/src/modal_models/MixedReactions.lf +++ b/test/C/src/modal_models/MixedReactions.lf @@ -8,8 +8,8 @@ target C { } main reactor { - state x: int = 0 - state first: bool = true + state x: int(0) + state first: bool(true) timer t(0, 100 msec) diff --git a/test/C/src/modal_models/ModalAfter.lf b/test/C/src/modal_models/ModalAfter.lf index 270fd88d05..038a368cc9 100644 --- a/test/C/src/modal_models/ModalAfter.lf +++ b/test/C/src/modal_models/ModalAfter.lf @@ -45,7 +45,7 @@ reactor Modal { } } -reactor Producer(mode_id: int = 0) { +reactor Producer(mode_id: int(0)) { output product: int timer t(0, 750 msec) @@ -56,7 +56,7 @@ reactor Producer(mode_id: int = 0) { =} } -reactor Consumer(mode_id: int = 0) { +reactor Consumer(mode_id: int(0)) { input product: int output report: int diff --git a/test/C/src/modal_models/ModalCycleBreaker.lf b/test/C/src/modal_models/ModalCycleBreaker.lf index cee4fabfec..680323a729 100644 --- a/test/C/src/modal_models/ModalCycleBreaker.lf +++ b/test/C/src/modal_models/ModalCycleBreaker.lf @@ -42,11 +42,11 @@ reactor Modal { } } -reactor Counter(period: time = 1 sec) { +reactor Counter(period: time(1 sec)) { output value: int timer t(0, period) - state curval: int = 0 + state curval: int(0) reaction(t) -> value {= lf_set(value, self->curval++); =} } diff --git a/test/C/src/modal_models/ModalStateReset.lf b/test/C/src/modal_models/ModalStateReset.lf index 61563162b6..cd963cfd8d 100644 --- a/test/C/src/modal_models/ModalStateReset.lf +++ b/test/C/src/modal_models/ModalStateReset.lf @@ -14,7 +14,7 @@ reactor Modal { output count1: int output count2: int - state counter0: int = 0 + state counter0: int(0) reaction(next) -> count0 {= printf("Counter0: %d\n", self->counter0); @@ -22,7 +22,7 @@ reactor Modal { =} initial mode One { - state counter1: int = 0 + state counter1: int(0) timer T1(0 msec, 250 msec) reaction(reset) {= self->counter1 = 0; =} @@ -39,7 +39,7 @@ reactor Modal { } mode Two { - state counter2: int = -2 + state counter2: int(-2) timer T2(0 msec, 250 msec) reaction(reset) {= self->counter2 = -2; =} diff --git a/test/C/src/modal_models/ModalStateResetAuto.lf b/test/C/src/modal_models/ModalStateResetAuto.lf index a2b6b105f0..24cfe9b187 100644 --- a/test/C/src/modal_models/ModalStateResetAuto.lf +++ b/test/C/src/modal_models/ModalStateResetAuto.lf @@ -14,7 +14,7 @@ reactor Modal { output count1: int output count2: int - state counter0: int = 0 + state counter0: int(0) reaction(next) -> count0 {= printf("Counter0: %d\n", self->counter0); @@ -22,7 +22,7 @@ reactor Modal { =} initial mode One { - state counter1: int = 0 + state counter1: int(0) timer T1(0 msec, 250 msec) reaction(T1) -> count1 {= printf("Counter1: %d\n", self->counter1); @@ -37,7 +37,7 @@ reactor Modal { } mode Two { - reset state counter2: int = -2 + reset state counter2: int(-2) timer T2(0 msec, 250 msec) reaction(T2) -> count2 {= printf("Counter2: %d\n", self->counter2); diff --git a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf index 60fa76dd1e..7e75afec13 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -28,11 +28,11 @@ reactor Modal { } } -reactor Counter(period: time = 1 sec) { +reactor Counter(period: time(1 sec)) { output value: int timer t(0, period) - reset state curval: int = 0 + reset state curval: int(0) reaction(t) -> value {= lf_set(value, self->curval++); =} } diff --git a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index dff82c602f..48b335d2b3 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -31,11 +31,11 @@ reactor Modal { } } -reactor Counter(period: time = 1 sec) { +reactor Counter(period: time(1 sec)) { output value: int timer t(0, period) - reset state curval: int = 0 + reset state curval: int(0) reaction(t) -> value {= lf_set(value, self->curval++); =} } diff --git a/test/C/src/modal_models/util/TraceTesting.lf b/test/C/src/modal_models/util/TraceTesting.lf index 247b3f1def..7d5a335db2 100644 --- a/test/C/src/modal_models/util/TraceTesting.lf +++ b/test/C/src/modal_models/util/TraceTesting.lf @@ -6,17 +6,17 @@ preamble {= =} reactor TraceTesting( - events_size: int = 0, - trace_size: int = 0, - trace: int[] = 0, - training: bool = false + events_size: int(0), + trace_size: int(0), + trace: int[](0), + training: bool(false) ) { input[events_size] events: int - state last_reaction_time: int = 0 - state trace_idx: int = 0 - state recorded_events: int* = 0 - state recorded_events_next: int = 0 + state last_reaction_time: int(0) + state trace_idx: int(0) + state recorded_events: int*(0) + state recorded_events_next: int(0) reaction(startup) {= self->last_reaction_time = lf_time_logical(); =} diff --git a/test/C/src/multiport/BankIndexInitializer.lf b/test/C/src/multiport/BankIndexInitializer.lf index d8a2c5766e..b9b8803943 100644 --- a/test/C/src/multiport/BankIndexInitializer.lf +++ b/test/C/src/multiport/BankIndexInitializer.lf @@ -3,15 +3,15 @@ target C preamble {= int table[] = {4, 3, 2, 1}; =} -reactor Source(bank_index: int = 0, value: int = 0) { +reactor Source(bank_index: int(0), value: int(0)) { output out: int reaction(startup) -> out {= lf_set(out, self->value); =} } -reactor Sink(width: int = 4) { +reactor Sink(width: int(4)) { input[width] in: int - state received: bool = false + state received: bool(false) reaction(in) {= for (int idx = 0; idx < in_width; idx++) { @@ -32,7 +32,7 @@ reactor Sink(width: int = 4) { =} } -main reactor(width: int = 4) { +main reactor(width: int(4)) { source = new[width] Source(value = {= table[bank_index] =}) sink = new Sink(width = width) source.out -> sink.in diff --git a/test/C/src/multiport/BankMultiportToReaction.lf b/test/C/src/multiport/BankMultiportToReaction.lf index 731cd6891b..c2eff34100 100644 --- a/test/C/src/multiport/BankMultiportToReaction.lf +++ b/test/C/src/multiport/BankMultiportToReaction.lf @@ -13,8 +13,8 @@ reactor DoubleCount { } main reactor { - state count: int = 1 - state received: bool = false + state count: int(1) + state received: bool(false) s = new[2] DoubleCount() diff --git a/test/C/src/multiport/BankReactionsInContainer.lf b/test/C/src/multiport/BankReactionsInContainer.lf index 98d7cf4e1f..6533e7ed0b 100644 --- a/test/C/src/multiport/BankReactionsInContainer.lf +++ b/test/C/src/multiport/BankReactionsInContainer.lf @@ -5,10 +5,10 @@ target C { timeout: 1 sec } -reactor R(bank_index: int = 0) { +reactor R(bank_index: int(0)) { output[2] out: int input[2] in: int - state received: bool = false + state received: bool(false) reaction(startup) -> out {= for (int i = 0; i < out_width; i++) { @@ -42,7 +42,7 @@ reactor R(bank_index: int = 0) { main reactor { s = new[2] R() - state received: bool = false + state received: bool(false) reaction(startup) -> s.in {= int count = 0; diff --git a/test/C/src/multiport/BankSelfBroadcast.lf b/test/C/src/multiport/BankSelfBroadcast.lf index e1ffb4b2dd..587087d550 100644 --- a/test/C/src/multiport/BankSelfBroadcast.lf +++ b/test/C/src/multiport/BankSelfBroadcast.lf @@ -7,10 +7,10 @@ */ target C -reactor A(bank_index: int = 0) { +reactor A(bank_index: int(0)) { input[4] in: int output out: int - state received: bool = false + state received: bool(false) reaction(startup) -> out {= lf_set(out, self->bank_index); =} diff --git a/test/C/src/multiport/BankToBank.lf b/test/C/src/multiport/BankToBank.lf index beb3a32fa8..19a784efd4 100644 --- a/test/C/src/multiport/BankToBank.lf +++ b/test/C/src/multiport/BankToBank.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(bank_index: int = 0) { +reactor Source(bank_index: int(0)) { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= lf_set(out, self->s); @@ -15,8 +15,8 @@ reactor Source(bank_index: int = 0) { =} } -reactor Destination(bank_index: int = 0) { - state s: int = 0 +reactor Destination(bank_index: int(0)) { + state s: int(0) input in: int reaction(in) {= @@ -37,7 +37,7 @@ reactor Destination(bank_index: int = 0) { =} } -main reactor BankToBank(width: int = 4) { +main reactor BankToBank(width: int(4)) { a = new[width] Source() b = new[width] Destination() a.out -> b.in diff --git a/test/C/src/multiport/BankToBankMultiport.lf b/test/C/src/multiport/BankToBankMultiport.lf index 681538f116..22c5821cc6 100644 --- a/test/C/src/multiport/BankToBankMultiport.lf +++ b/test/C/src/multiport/BankToBankMultiport.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int = 1) { +reactor Source(width: int(1)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -16,8 +16,8 @@ reactor Source(width: int = 1) { =} } -reactor Destination(width: int = 1) { - state s: int = 6 +reactor Destination(width: int(1)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -42,7 +42,7 @@ reactor Destination(width: int = 1) { =} } -main reactor BankToBankMultiport(bank_width: int = 4) { +main reactor BankToBankMultiport(bank_width: int(4)) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in diff --git a/test/C/src/multiport/BankToBankMultiportAfter.lf b/test/C/src/multiport/BankToBankMultiportAfter.lf index db0ff7771e..38daec6ccf 100644 --- a/test/C/src/multiport/BankToBankMultiportAfter.lf +++ b/test/C/src/multiport/BankToBankMultiportAfter.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int = 1) { +reactor Source(width: int(1)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -16,8 +16,8 @@ reactor Source(width: int = 1) { =} } -reactor Destination(width: int = 1) { - state s: int = 6 +reactor Destination(width: int(1)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -42,7 +42,7 @@ reactor Destination(width: int = 1) { =} } -main reactor(bank_width: int = 4) { +main reactor(bank_width: int(4)) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in after 200 msec diff --git a/test/C/src/multiport/BankToMultiport.lf b/test/C/src/multiport/BankToMultiport.lf index f72c104df7..ee0ad53dc3 100644 --- a/test/C/src/multiport/BankToMultiport.lf +++ b/test/C/src/multiport/BankToMultiport.lf @@ -1,15 +1,15 @@ // Test bank of reactors to multiport input with id parameter in the bank. target C -reactor Source(bank_index: int = 0) { +reactor Source(bank_index: int(0)) { output out: int reaction(startup) -> out {= lf_set(out, self->bank_index); =} } -reactor Sink(width: int = 4) { +reactor Sink(width: int(4)) { input[width] in: int - state received: bool = false + state received: bool(false) reaction(in) {= for (int i = 0; i < in_width; i++) { @@ -32,7 +32,7 @@ reactor Sink(width: int = 4) { =} } -main reactor BankToMultiport(width: int = 5) { +main reactor BankToMultiport(width: int(5)) { source = new[width] Source() sink = new Sink(width = width) source.out -> sink.in diff --git a/test/C/src/multiport/BankToReaction.lf b/test/C/src/multiport/BankToReaction.lf index 4e59352bd5..c5d68cfe41 100644 --- a/test/C/src/multiport/BankToReaction.lf +++ b/test/C/src/multiport/BankToReaction.lf @@ -6,7 +6,7 @@ target C { import Count from "../lib/Count.lf" main reactor { - state count: int = 1 + state count: int(1) s = new[2] Count() diff --git a/test/C/src/multiport/Broadcast.lf b/test/C/src/multiport/Broadcast.lf index e3471da5f6..dee0ad62ed 100644 --- a/test/C/src/multiport/Broadcast.lf +++ b/test/C/src/multiport/Broadcast.lf @@ -9,9 +9,9 @@ reactor Source { reaction(startup) -> out {= lf_set(out, 42); =} } -reactor Destination(bank_index: int = 0) { +reactor Destination(bank_index: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/BroadcastAfter.lf b/test/C/src/multiport/BroadcastAfter.lf index c1be635e55..b66979e182 100644 --- a/test/C/src/multiport/BroadcastAfter.lf +++ b/test/C/src/multiport/BroadcastAfter.lf @@ -9,9 +9,9 @@ reactor Source { reaction(startup) -> out {= lf_set(out, 42); =} } -reactor Destination(bank_index: int = 0) { +reactor Destination(bank_index: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/BroadcastMultipleAfter.lf b/test/C/src/multiport/BroadcastMultipleAfter.lf index 97d853e4ce..b83540e3d4 100644 --- a/test/C/src/multiport/BroadcastMultipleAfter.lf +++ b/test/C/src/multiport/BroadcastMultipleAfter.lf @@ -3,15 +3,15 @@ target C { fast: true } -reactor Source(value: int = 42) { +reactor Source(value: int(42)) { output out: int reaction(startup) -> out {= lf_set(out, self->value); =} } -reactor Destination(bank_index: int = 0) { +reactor Destination(bank_index: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/DualBanks.lf b/test/C/src/multiport/DualBanks.lf index 3cb5d38887..aa8faf4b75 100644 --- a/test/C/src/multiport/DualBanks.lf +++ b/test/C/src/multiport/DualBanks.lf @@ -1,8 +1,8 @@ target C -reactor Base(bank_index: int = 0) { +reactor Base(bank_index: int(0)) { input I: int - state received: bool = false + state received: bool(false) reaction(shutdown) {= if(!self->received) { diff --git a/test/C/src/multiport/DualBanksMultiport.lf b/test/C/src/multiport/DualBanksMultiport.lf index a5c2120a79..42c4adb11e 100644 --- a/test/C/src/multiport/DualBanksMultiport.lf +++ b/test/C/src/multiport/DualBanksMultiport.lf @@ -1,8 +1,8 @@ target C -reactor Base(bank_index: int = 0) { +reactor Base(bank_index: int(0)) { input[2] I: int - state received: bool = false + state received: bool(false) reaction(shutdown) {= if(!self->received) { diff --git a/test/C/src/multiport/FullyConnected.lf b/test/C/src/multiport/FullyConnected.lf index 758ecf1580..8a26fee83f 100644 --- a/test/C/src/multiport/FullyConnected.lf +++ b/test/C/src/multiport/FullyConnected.lf @@ -1,10 +1,10 @@ target C -reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { +reactor Node(num_nodes: size_t(4), bank_index: int(0)) { input[num_nodes] in: int output out: int - state received: bool = false + state received: bool(false) reaction(startup) -> out {= lf_print("Hello from node %d!", self->bank_index); @@ -35,7 +35,7 @@ reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { =} } -main reactor(num_nodes: size_t = 4) { +main reactor(num_nodes: size_t(4)) { nodes = new[num_nodes] Node(num_nodes = num_nodes) (nodes.out)+ -> nodes.in } diff --git a/test/C/src/multiport/FullyConnectedAddressable.lf b/test/C/src/multiport/FullyConnectedAddressable.lf index 91b0f5caac..ae99d5397e 100644 --- a/test/C/src/multiport/FullyConnectedAddressable.lf +++ b/test/C/src/multiport/FullyConnectedAddressable.lf @@ -1,12 +1,12 @@ // In this pattern, each node can send direct messages to individual other nodes target C -reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { +reactor Node(num_nodes: size_t(4), bank_index: int(0)) { input[num_nodes] in: int output[num_nodes] out: int - state received: int = 0 - state triggered: bool = false + state received: int(0) + state triggered: bool(false) reaction(startup) -> out {= int outChannel = (self->bank_index + 1) % self->num_nodes; @@ -45,7 +45,7 @@ reactor Node(num_nodes: size_t = 4, bank_index: int = 0) { =} } -main reactor(num_nodes: size_t = 4) { +main reactor(num_nodes: size_t(4)) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) diff --git a/test/C/src/multiport/FullyConnectedAddressableAfter.lf b/test/C/src/multiport/FullyConnectedAddressableAfter.lf index 1d30430deb..cd6dc4cf85 100644 --- a/test/C/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/C/src/multiport/FullyConnectedAddressableAfter.lf @@ -3,7 +3,7 @@ target C import Node from "FullyConnectedAddressable.lf" -main reactor(num_nodes: size_t = 4) { +main reactor(num_nodes: size_t(4)) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) after 200 msec diff --git a/test/C/src/multiport/MultiportFromBank.lf b/test/C/src/multiport/MultiportFromBank.lf index 1b49786060..b8ade7a354 100644 --- a/test/C/src/multiport/MultiportFromBank.lf +++ b/test/C/src/multiport/MultiportFromBank.lf @@ -5,7 +5,7 @@ target C { fast: true } -reactor Source(check_override: int = 0, bank_index: int = 0) { +reactor Source(check_override: int(0), bank_index: int(0)) { output out: int reaction(startup) -> out {= @@ -13,9 +13,9 @@ reactor Source(check_override: int = 0, bank_index: int = 0) { =} } -reactor Destination(port_width: int = 3) { +reactor Destination(port_width: int(3)) { input[port_width] in: int - state received: bool = false + state received: bool(false) reaction(in) {= for (int i = 0; i < in_width; i++) { @@ -37,7 +37,7 @@ reactor Destination(port_width: int = 3) { =} } -main reactor MultiportFromBank(width: int = 4) { +main reactor MultiportFromBank(width: int(4)) { a = new[width] Source(check_override = 1) b = new Destination(port_width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportFromBankHierarchy.lf b/test/C/src/multiport/MultiportFromBankHierarchy.lf index e8ee6194b5..c38046107c 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchy.lf @@ -7,13 +7,13 @@ target C { import Source, Destination from "MultiportFromBank.lf" -reactor Container(port_width: int = 3) { +reactor Container(port_width: int(3)) { output[port_width] out: int s = new[port_width] Source(check_override = 1) s.out -> out } -main reactor(width: int = 4) { +main reactor(width: int(4)) { a = new Container(port_width = width) b = new Destination(port_width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportFromHierarchy.lf b/test/C/src/multiport/MultiportFromHierarchy.lf index 8323210946..f38661345c 100644 --- a/test/C/src/multiport/MultiportFromHierarchy.lf +++ b/test/C/src/multiport/MultiportFromHierarchy.lf @@ -5,10 +5,10 @@ target C { fast: true } -reactor Source(width: int = 3) { +reactor Source(width: int(3)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -17,8 +17,8 @@ reactor Source(width: int = 3) { =} } -reactor Destination(width: int = 3) { - state s: int = 6 +reactor Destination(width: int(3)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -43,19 +43,19 @@ reactor Destination(width: int = 3) { =} } -reactor Container(width: int = 3) { +reactor Container(width: int(3)) { output[width] out: int src = new InsideContainer(width = width) src.out -> out } -reactor InsideContainer(width: int = 3) { +reactor InsideContainer(width: int(3)) { output[width] out: int src = new Source(width = width) src.out -> out } -main reactor MultiportFromHierarchy(width: int = 4) { +main reactor MultiportFromHierarchy(width: int(4)) { a = new Container(width = width) b = new Destination(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportFromReaction.lf b/test/C/src/multiport/MultiportFromReaction.lf index 33cbfffd83..acaa59e519 100644 --- a/test/C/src/multiport/MultiportFromReaction.lf +++ b/test/C/src/multiport/MultiportFromReaction.lf @@ -4,8 +4,8 @@ target C { fast: true } -reactor Destination(width: int = 1) { - state s: int = 6 +reactor Destination(width: int(1)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -30,9 +30,9 @@ reactor Destination(width: int = 1) { =} } -main reactor MultiportFromReaction(width: int = 4) { +main reactor MultiportFromReaction(width: int(4)) { timer t(0, 200 msec) - state s: int = 0 + state s: int(0) b = new Destination(width = width) reaction(t) -> b.in {= diff --git a/test/C/src/multiport/MultiportIn.lf b/test/C/src/multiport/MultiportIn.lf index b87a91a79b..80269896d8 100644 --- a/test/C/src/multiport/MultiportIn.lf +++ b/test/C/src/multiport/MultiportIn.lf @@ -8,7 +8,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= lf_set(out, self->s); @@ -24,7 +24,7 @@ reactor Computation { } reactor Destination { - state s: int = 0 + state s: int(0) input[4] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportInParameterized.lf b/test/C/src/multiport/MultiportInParameterized.lf index bf7ec93f6e..cd9bb27ad2 100644 --- a/test/C/src/multiport/MultiportInParameterized.lf +++ b/test/C/src/multiport/MultiportInParameterized.lf @@ -8,7 +8,7 @@ target C { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= lf_set(out, self->s); @@ -23,8 +23,8 @@ reactor Computation { reaction(in) -> out {= lf_set(out, in->value); =} } -reactor Destination(width: int = 1) { - state s: int = 0 +reactor Destination(width: int(1)) { + state s: int(0) input[width] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportMutableInput.lf b/test/C/src/multiport/MultiportMutableInput.lf index e1f8d579c2..d1b0994012 100644 --- a/test/C/src/multiport/MultiportMutableInput.lf +++ b/test/C/src/multiport/MultiportMutableInput.lf @@ -12,7 +12,7 @@ reactor Source { =} } -reactor Print(scale: int = 1) { // The scale parameter is just for testing. +reactor Print(scale: int(1)) { // The scale parameter is just for testing. input[2] in: int reaction(in) {= @@ -27,7 +27,7 @@ reactor Print(scale: int = 1) { // The scale parameter is just for testing. =} } -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { mutable input[2] in: int output[2] out: int diff --git a/test/C/src/multiport/MultiportMutableInputArray.lf b/test/C/src/multiport/MultiportMutableInputArray.lf index 90907e4f44..cd279bb6a2 100644 --- a/test/C/src/multiport/MultiportMutableInputArray.lf +++ b/test/C/src/multiport/MultiportMutableInputArray.lf @@ -26,7 +26,7 @@ reactor Source { =} } -reactor Print(scale: int = 1) { // The scale parameter is just for testing. +reactor Print(scale: int(1)) { // The scale parameter is just for testing. input[2] in: int[] reaction(in) {= @@ -52,7 +52,7 @@ reactor Print(scale: int = 1) { // The scale parameter is just for testing. =} } -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { mutable input[2] in: int[] output[2] out: int[] diff --git a/test/C/src/multiport/MultiportOut.lf b/test/C/src/multiport/MultiportOut.lf index 38365d217a..c2707d5d33 100644 --- a/test/C/src/multiport/MultiportOut.lf +++ b/test/C/src/multiport/MultiportOut.lf @@ -7,7 +7,7 @@ target C { reactor Source { timer t(0, 200 msec) output[4] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -31,7 +31,7 @@ reactor Computation { } reactor Destination { - state s: int = 0 + state s: int(0) input[4] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportToBank.lf b/test/C/src/multiport/MultiportToBank.lf index 86146b9818..c1f19d3553 100644 --- a/test/C/src/multiport/MultiportToBank.lf +++ b/test/C/src/multiport/MultiportToBank.lf @@ -4,7 +4,7 @@ target C { fast: true } -reactor Source(width: int = 2) { +reactor Source(width: int(2)) { output[width] out: int // Connected to a bank of Destination reactors input dummy: int // Not connected to anything @@ -24,9 +24,9 @@ reactor Source(width: int = 2) { =} } -reactor Destination(bank_index: int = 0) { +reactor Destination(bank_index: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); @@ -46,7 +46,7 @@ reactor Destination(bank_index: int = 0) { =} } -main reactor MultiportToBank(width: int = 3) { +main reactor MultiportToBank(width: int(3)) { a = new Source(width = width) b = new[width] Destination() a.out -> b.in diff --git a/test/C/src/multiport/MultiportToBankAfter.lf b/test/C/src/multiport/MultiportToBankAfter.lf index ba26142243..66e0fdf837 100644 --- a/test/C/src/multiport/MultiportToBankAfter.lf +++ b/test/C/src/multiport/MultiportToBankAfter.lf @@ -5,7 +5,7 @@ target C { fast: true } -reactor Source(width: int = 2) { +reactor Source(width: int(2)) { output[width] out: int reaction(startup) -> out {= @@ -15,9 +15,9 @@ reactor Source(width: int = 2) { =} } -reactor Destination(bank_index: int = 0) { +reactor Destination(bank_index: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); @@ -41,7 +41,7 @@ reactor Destination(bank_index: int = 0) { =} } -main reactor(width: int = 3) { +main reactor(width: int(3)) { a = new Source(width = width) b = new[width] Destination() a.out -> b.in after 1 sec // Width of the bank of delays will be inferred. diff --git a/test/C/src/multiport/MultiportToBankDouble.lf b/test/C/src/multiport/MultiportToBankDouble.lf index 444f02d170..a116ef9c00 100644 --- a/test/C/src/multiport/MultiportToBankDouble.lf +++ b/test/C/src/multiport/MultiportToBankDouble.lf @@ -24,9 +24,9 @@ reactor Source { =} } -reactor Destination(bank_index: int = 0) { +reactor Destination(bank_index: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); diff --git a/test/C/src/multiport/MultiportToBankHierarchy.lf b/test/C/src/multiport/MultiportToBankHierarchy.lf index fbdc531bf0..e4f231390f 100644 --- a/test/C/src/multiport/MultiportToBankHierarchy.lf +++ b/test/C/src/multiport/MultiportToBankHierarchy.lf @@ -5,7 +5,7 @@ target C { fast: true } -reactor Source(width: int = 2) { +reactor Source(width: int(2)) { output[width] out: int reaction(startup) -> out {= @@ -15,9 +15,9 @@ reactor Source(width: int = 2) { =} } -reactor Destination(bank_index: int = 0) { +reactor Destination(bank_index: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Destination %d received %d.\n", self->bank_index, in->value); @@ -37,13 +37,13 @@ reactor Destination(bank_index: int = 0) { =} } -reactor Container(width: int = 2) { +reactor Container(width: int(2)) { input[width] in: int c = new[width] Destination() in -> c.in } -main reactor MultiportToBankHierarchy(width: int = 3) { +main reactor MultiportToBankHierarchy(width: int(3)) { a = new Source(width = width) b = new Container(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToHierarchy.lf b/test/C/src/multiport/MultiportToHierarchy.lf index 41ca505077..24290b56a5 100644 --- a/test/C/src/multiport/MultiportToHierarchy.lf +++ b/test/C/src/multiport/MultiportToHierarchy.lf @@ -6,10 +6,10 @@ target C { fast: true } -reactor Source(width: int = 2) { +reactor Source(width: int(2)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -18,8 +18,8 @@ reactor Source(width: int = 2) { =} } -reactor Destination(width: int = 4) { - state s: int = 6 +reactor Destination(width: int(4)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -44,13 +44,13 @@ reactor Destination(width: int = 4) { =} } -reactor Container(width: int = 4) { +reactor Container(width: int(4)) { input[width] in: int dst = new Destination() in -> dst.in } -main reactor MultiportToHierarchy(width: int = 4) { +main reactor MultiportToHierarchy(width: int(4)) { a = new Source(width = width) b = new Container(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToMultiport.lf b/test/C/src/multiport/MultiportToMultiport.lf index 375fa080e2..bf4bbefde4 100644 --- a/test/C/src/multiport/MultiportToMultiport.lf +++ b/test/C/src/multiport/MultiportToMultiport.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int = 1) { +reactor Source(width: int(1)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -19,8 +19,8 @@ reactor Source(width: int = 1) { =} } -reactor Destination(width: int = 1) { - state s: int = 6 +reactor Destination(width: int(1)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -45,7 +45,7 @@ reactor Destination(width: int = 1) { =} } -main reactor MultiportToMultiport(width: int = 4) { +main reactor MultiportToMultiport(width: int(4)) { a = new Source(width = width) b = new Destination(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToMultiport2.lf b/test/C/src/multiport/MultiportToMultiport2.lf index 76858a2a86..29a8632399 100644 --- a/test/C/src/multiport/MultiportToMultiport2.lf +++ b/test/C/src/multiport/MultiportToMultiport2.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target C -reactor Source(width: int = 2) { +reactor Source(width: int(2)) { output[width] out: int reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: int = 2) { =} } -reactor Destination(width: int = 2) { +reactor Destination(width: int(2)) { input[width] in: int reaction(in) {= @@ -30,9 +30,9 @@ reactor Destination(width: int = 2) { } main reactor MultiportToMultiport2( - width1: int = 3, - width2: int = 2, - width3: int = 5 + width1: int(3), + width2: int(2), + width3: int(5) ) { a1 = new Source(width = width1) a2 = new Source(width = width2) diff --git a/test/C/src/multiport/MultiportToMultiport2After.lf b/test/C/src/multiport/MultiportToMultiport2After.lf index 49585ea1b0..b6f078a099 100644 --- a/test/C/src/multiport/MultiportToMultiport2After.lf +++ b/test/C/src/multiport/MultiportToMultiport2After.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target C -reactor Source(width: int = 2) { +reactor Source(width: int(2)) { output[width] out: int reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: int = 2) { =} } -reactor Destination(width: int = 2) { +reactor Destination(width: int(2)) { input[width] in: int reaction(in) {= diff --git a/test/C/src/multiport/MultiportToMultiportArray.lf b/test/C/src/multiport/MultiportToMultiportArray.lf index 9d86a4a522..100a57c393 100644 --- a/test/C/src/multiport/MultiportToMultiportArray.lf +++ b/test/C/src/multiport/MultiportToMultiportArray.lf @@ -8,7 +8,7 @@ target C { reactor Source { timer t(0, 200 msec) output[2] out: int[] - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < 2; i++) { @@ -24,7 +24,7 @@ reactor Source { } reactor Destination { - state s: int = 15 + state s: int(15) input[2] in: int[] reaction(in) {= diff --git a/test/C/src/multiport/MultiportToMultiportParameter.lf b/test/C/src/multiport/MultiportToMultiportParameter.lf index d1c96e5ddd..9dc7288a52 100644 --- a/test/C/src/multiport/MultiportToMultiportParameter.lf +++ b/test/C/src/multiport/MultiportToMultiportParameter.lf @@ -4,10 +4,10 @@ target C { fast: true } -reactor Source(width: int = 1) { +reactor Source(width: int(1)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < out_width; i++) { @@ -19,8 +19,8 @@ reactor Source(width: int = 1) { =} } -reactor Destination(width: int = 1) { - state s: int = 6 +reactor Destination(width: int(1)) { + state s: int(6) input[width] in: int // Width is one larger than that of the source. reaction(in) {= @@ -45,7 +45,7 @@ reactor Destination(width: int = 1) { =} } -main reactor(width: int = 4) { +main reactor(width: int(4)) { a = new Source(width = width) b = new Destination(width = width) a.out -> b.in diff --git a/test/C/src/multiport/MultiportToPort.lf b/test/C/src/multiport/MultiportToPort.lf index 1784f2503c..ccee46566c 100644 --- a/test/C/src/multiport/MultiportToPort.lf +++ b/test/C/src/multiport/MultiportToPort.lf @@ -16,9 +16,9 @@ reactor Source { =} } -reactor Destination(expected: int = 0) { +reactor Destination(expected: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= printf("Received: %d.\n", in->value); diff --git a/test/C/src/multiport/MultiportToReaction.lf b/test/C/src/multiport/MultiportToReaction.lf index 9281633079..62e2c302f2 100644 --- a/test/C/src/multiport/MultiportToReaction.lf +++ b/test/C/src/multiport/MultiportToReaction.lf @@ -4,9 +4,9 @@ target C { fast: true } -reactor Source(width: int = 1) { +reactor Source(width: int(1)) { timer t(0, 200 msec) - state s: int = 0 + state s: int(0) output[width] out: int reaction(t) -> out {= @@ -18,7 +18,7 @@ reactor Source(width: int = 1) { } main reactor MultiportToReaction { - state s: int = 6 + state s: int(6) b = new Source(width = 4) reaction(b.out) {= diff --git a/test/C/src/multiport/NestedBanks.lf b/test/C/src/multiport/NestedBanks.lf index bef08727f3..b80ff2e606 100644 --- a/test/C/src/multiport/NestedBanks.lf +++ b/test/C/src/multiport/NestedBanks.lf @@ -13,13 +13,13 @@ main reactor { (a.x)+ -> c.z, d.u, e.t } -reactor A(bank_index: int = 0) { +reactor A(bank_index: int(0)) { output[4] x: int b = new[2] B(a_bank_index = bank_index) b.y -> x } -reactor B(a_bank_index: int = 0, bank_index: int = 0) { +reactor B(a_bank_index: int(0), bank_index: int(0)) { output[2] y: int reaction(startup) -> y {= @@ -29,7 +29,7 @@ reactor B(a_bank_index: int = 0, bank_index: int = 0) { =} } -reactor C(bank_index: int = 0) { +reactor C(bank_index: int(0)) { input[2] z: int f = new F(c_bank_index = bank_index) g = new G(c_bank_index = bank_index) @@ -59,7 +59,7 @@ reactor E { =} } -reactor F(c_bank_index: int = 0) { +reactor F(c_bank_index: int(0)) { input w: int reaction(w) {= @@ -70,7 +70,7 @@ reactor F(c_bank_index: int = 0) { =} } -reactor G(c_bank_index: int = 0) { +reactor G(c_bank_index: int(0)) { input s: int reaction(s) {= diff --git a/test/C/src/multiport/NestedInterleavedBanks.lf b/test/C/src/multiport/NestedInterleavedBanks.lf index 8e3056bd88..9f03313972 100644 --- a/test/C/src/multiport/NestedInterleavedBanks.lf +++ b/test/C/src/multiport/NestedInterleavedBanks.lf @@ -4,7 +4,7 @@ */ target C -reactor A(bank_index: int = 0, outer_bank_index: int = 0) { +reactor A(bank_index: int(0), outer_bank_index: int(0)) { output[2] p: int reaction(startup) -> p {= @@ -15,7 +15,7 @@ reactor A(bank_index: int = 0, outer_bank_index: int = 0) { =} } -reactor B(bank_index: int = 0) { +reactor B(bank_index: int(0)) { output[4] q: int a = new[2] A(outer_bank_index = bank_index) interleaved (a.p) -> q diff --git a/test/C/src/multiport/ReactionToContainedBank.lf b/test/C/src/multiport/ReactionToContainedBank.lf index 30f3f5564c..3e0afa17d5 100644 --- a/test/C/src/multiport/ReactionToContainedBank.lf +++ b/test/C/src/multiport/ReactionToContainedBank.lf @@ -6,9 +6,9 @@ target C { import TestCount from "../lib/TestCount.lf" -main reactor ReactionToContainedBank(width: int = 2) { +main reactor ReactionToContainedBank(width: int(2)) { timer t(0, 100 msec) - state count: int = 1 + state count: int(1) test = new[width] TestCount(num_inputs = 11) diff --git a/test/C/src/multiport/ReactionToContainedBank2.lf b/test/C/src/multiport/ReactionToContainedBank2.lf index e03e884558..b7c7d1cf92 100644 --- a/test/C/src/multiport/ReactionToContainedBank2.lf +++ b/test/C/src/multiport/ReactionToContainedBank2.lf @@ -6,9 +6,9 @@ target C { import TestCount from "../lib/TestCount.lf" -reactor ReactionToContainedBank(width: int = 2) { +reactor ReactionToContainedBank(width: int(2)) { timer t(0, 100 msec) - state count: int = 1 + state count: int(1) test = new[width] TestCount(num_inputs = 11) @@ -20,7 +20,7 @@ reactor ReactionToContainedBank(width: int = 2) { =} } -main reactor(width: int = 2) { +main reactor(width: int(2)) { a = new ReactionToContainedBank(width = width) b = new ReactionToContainedBank(width = 4) } diff --git a/test/C/src/multiport/ReactionToContainedBankMultiport.lf b/test/C/src/multiport/ReactionToContainedBankMultiport.lf index d84b21c191..6a9e067ca1 100644 --- a/test/C/src/multiport/ReactionToContainedBankMultiport.lf +++ b/test/C/src/multiport/ReactionToContainedBankMultiport.lf @@ -7,9 +7,9 @@ target C { import TestCountMultiport from "../lib/TestCountMultiport.lf" -main reactor(width: int = 2) { +main reactor(width: int(2)) { timer t(0, 100 msec) - state count: int = 1 + state count: int(1) test = new[width] TestCountMultiport(num_inputs = 11, width = width) diff --git a/test/C/src/multiport/ReactionsToNested.lf b/test/C/src/multiport/ReactionsToNested.lf index 4270f55c2d..102df10f8b 100644 --- a/test/C/src/multiport/ReactionsToNested.lf +++ b/test/C/src/multiport/ReactionsToNested.lf @@ -4,9 +4,9 @@ target C { timeout: 1 sec } -reactor T(expected: int = 0) { +reactor T(expected: int(0)) { input z: int - state received: bool = false + state received: bool(false) reaction(z) {= lf_print("T received %d", z->value); diff --git a/test/C/src/multiport/Sparse.lf b/test/C/src/multiport/Sparse.lf index 537daabb4b..eaa75782cb 100644 --- a/test/C/src/multiport/Sparse.lf +++ b/test/C/src/multiport/Sparse.lf @@ -3,9 +3,9 @@ target C { timeout: 20 ms } -reactor SparseSource(width: int = 20) { +reactor SparseSource(width: int(20)) { output[width] out: int - state count: int = 0 + state count: int(0) timer t(0, 1 msec) reaction(t) -> out {= @@ -19,7 +19,7 @@ reactor SparseSource(width: int = 20) { =} } -reactor SparseSink(width: int = 20) { +reactor SparseSink(width: int(20)) { input[width] in: int reaction(in) {= @@ -43,7 +43,7 @@ reactor SparseSink(width: int = 20) { =} } -main reactor(width: int = 20) { +main reactor(width: int(20)) { s = new SparseSource(width = width) d = new SparseSink(width = width) s.out -> d.in diff --git a/test/C/src/multiport/SparseFallback.lf b/test/C/src/multiport/SparseFallback.lf index a7788858d8..195dca1f19 100644 --- a/test/C/src/multiport/SparseFallback.lf +++ b/test/C/src/multiport/SparseFallback.lf @@ -6,9 +6,9 @@ target C { timeout: 20 ms } -reactor SparseSource(width: int = 20) { +reactor SparseSource(width: int(20)) { output[width] out: int - state count: int = 0 + state count: int(0) timer t(0, 1 msec) reaction(t) -> out {= @@ -22,7 +22,7 @@ reactor SparseSource(width: int = 20) { =} } -reactor SparseSink(width: int = 20) { +reactor SparseSink(width: int(20)) { input[width] in: int reaction(in) {= @@ -46,7 +46,7 @@ reactor SparseSink(width: int = 20) { =} } -main reactor(width: int = 10) { +main reactor(width: int(10)) { s = new SparseSource(width = width) d = new SparseSink(width = width) s.out -> d.in diff --git a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf index 917982af39..c696261db7 100644 --- a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf +++ b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf @@ -10,7 +10,7 @@ target C { reactor Source { output a: int output b: int - state count: int = 0 + state count: int(0) timer t(0, 200 msec) reaction(t) -> a, b {= diff --git a/test/C/src/serialization/ROSBuiltInSerialization.lf b/test/C/src/serialization/ROSBuiltInSerialization.lf index 095aadacd2..d573b23cce 100644 --- a/test/C/src/serialization/ROSBuiltInSerialization.lf +++ b/test/C/src/serialization/ROSBuiltInSerialization.lf @@ -32,7 +32,7 @@ reactor Sender { output out: std_msgs::msg::Int32 // state serialized_msg_pcl:rclcpp::SerializedMessage({=0u=}); - state count: int = 0 + state count: int(0) timer t(0, 1 sec) @@ -45,7 +45,7 @@ reactor Sender { reactor Receiver { input in: std_msgs::msg::Int32 - state count: int = 0 + state count: int(0) reaction(in) {= // Print the ROS2 message data diff --git a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf index 97b5a12554..4726809c57 100644 --- a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf +++ b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf @@ -31,7 +31,7 @@ preamble {= reactor Sender { output out: std::shared_ptr - state count: int = 0 + state count: int(0) timer t(0, 1 sec) @@ -44,7 +44,7 @@ reactor Sender { reactor Receiver { input in: std::shared_ptr - state count: int = 0 + state count: int(0) reaction(in) {= // Print the ROS2 message data diff --git a/test/C/src/target/HelloWorldCCPP.lf b/test/C/src/target/HelloWorldCCPP.lf index 91d1cd61d1..0b0e54ed52 100644 --- a/test/C/src/target/HelloWorldCCPP.lf +++ b/test/C/src/target/HelloWorldCCPP.lf @@ -11,7 +11,7 @@ reactor HelloWorld { preamble {= #include =} - state success: bool = false + state success: bool(false) reaction(startup) {= std::cout << "Hello World." << std::endl; diff --git a/test/C/src/token/TokenContainedPrint.lf b/test/C/src/token/TokenContainedPrint.lf index 29e6005c4c..0d4b19379d 100644 --- a/test/C/src/token/TokenContainedPrint.lf +++ b/test/C/src/token/TokenContainedPrint.lf @@ -9,7 +9,7 @@ target C { import TokenPrint from "lib/Token.lf" main reactor { - state count: int = 0 + state count: int(0) timer t(0, 1 ms) p = new TokenPrint() diff --git a/test/C/src/token/TokenContainedPrintBank.lf b/test/C/src/token/TokenContainedPrintBank.lf index 991a94b5a7..b23eb1c109 100644 --- a/test/C/src/token/TokenContainedPrintBank.lf +++ b/test/C/src/token/TokenContainedPrintBank.lf @@ -10,7 +10,7 @@ target C { import TokenPrint from "lib/Token.lf" main reactor { - state count: int = 0 + state count: int(0) timer t(0, 1 ms) p = new[2] TokenPrint() diff --git a/test/C/src/token/TokenContainedSource.lf b/test/C/src/token/TokenContainedSource.lf index 66095b8a0b..9bf517bc18 100644 --- a/test/C/src/token/TokenContainedSource.lf +++ b/test/C/src/token/TokenContainedSource.lf @@ -9,9 +9,9 @@ target C { import TokenSource from "lib/Token.lf" -main reactor(scale: int = 1) { - state count: int = 0 - state input_received: bool = false +main reactor(scale: int(1)) { + state count: int(0) + state input_received: bool(false) s = new TokenSource() diff --git a/test/C/src/token/TokenContainedSourceBank.lf b/test/C/src/token/TokenContainedSourceBank.lf index 615695890b..f1faee87dd 100644 --- a/test/C/src/token/TokenContainedSourceBank.lf +++ b/test/C/src/token/TokenContainedSourceBank.lf @@ -10,9 +10,9 @@ target C { import TokenSource from "lib/Token.lf" -main reactor(scale: int = 1) { - state count: int = 0 - state input_received: bool = false +main reactor(scale: int(1)) { + state count: int(0) + state input_received: bool(false) s = new[2] TokenSource() diff --git a/test/C/src/token/lib/Token.lf b/test/C/src/token/lib/Token.lf index 7b8d2a83ee..4e49cd0006 100644 --- a/test/C/src/token/lib/Token.lf +++ b/test/C/src/token/lib/Token.lf @@ -20,7 +20,7 @@ preamble {= */ reactor TokenSource { output out: int_array_t* - state count: int = 0 + state count: int(0) timer t(0, 1 ms) reaction(startup) -> out {= @@ -42,10 +42,10 @@ reactor TokenSource { * value is a scaled version of the sequence of values produced by the * TokenSource, where the scaling factor is given by the scale parameter. */ -reactor TokenPrint(scale: int = 1) { +reactor TokenPrint(scale: int(1)) { input in: int_array_t* - state count: int = 0 - state input_received: bool = false + state count: int(0) + state input_received: bool(false) reaction(in) {= self->input_received = true; @@ -79,7 +79,7 @@ reactor TokenPrint(scale: int = 1) { * input is declared mutable so, if possible, the input token will be modified * rather than allocating a new token. */ -reactor TokenScale(scale: int = 2) { +reactor TokenScale(scale: int(2)) { mutable input in: int_array_t* output out: int_array_t* diff --git a/test/Cpp/src/ActionDelay.lf b/test/Cpp/src/ActionDelay.lf index 14210e1009..5bb1402e05 100644 --- a/test/Cpp/src/ActionDelay.lf +++ b/test/Cpp/src/ActionDelay.lf @@ -4,7 +4,7 @@ target Cpp reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int = 0 + state y_state: int{0} logical action act(100 msec): void reaction(y_in) -> act {= diff --git a/test/Cpp/src/ActionIsPresent.lf b/test/Cpp/src/ActionIsPresent.lf index e98c2a2a32..7b8267d606 100644 --- a/test/Cpp/src/ActionIsPresent.lf +++ b/test/Cpp/src/ActionIsPresent.lf @@ -1,10 +1,10 @@ // Tests the is_present variable for actions in cpp target Cpp -main reactor ActionIsPresent(offset: time = 1 nsec, period: time(500 msec)) { +main reactor ActionIsPresent(offset: time(1 nsec), period: time(500 msec)) { logical action a - state success: bool = false - state zero: time = 0 nsec + state success: bool(false) + state zero: time(0 nsec) reaction(startup, a) -> a {= if (!a.is_present()) { diff --git a/test/Cpp/src/ActionValues.lf b/test/Cpp/src/ActionValues.lf index 8d115c60fa..18d06b7b3c 100644 --- a/test/Cpp/src/ActionValues.lf +++ b/test/Cpp/src/ActionValues.lf @@ -2,8 +2,8 @@ target Cpp main reactor ActionValues { - state r1done: bool = false - state r2done: bool = false + state r1done: bool(false) + state r2done: bool(false) logical action act(100 msec): int reaction(startup) -> act {= diff --git a/test/Cpp/src/After.lf b/test/Cpp/src/After.lf index bbcc287b78..177ebfbe01 100644 --- a/test/Cpp/src/After.lf +++ b/test/Cpp/src/After.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time = 10 msec - state i: int = 0 + state expected_time: time(10 msec) + state i: int(0) input x: int reaction(x) {= diff --git a/test/Cpp/src/AfterOverlapped.lf b/test/Cpp/src/AfterOverlapped.lf index 6a85eaf5bc..926c4609c2 100644 --- a/test/Cpp/src/AfterOverlapped.lf +++ b/test/Cpp/src/AfterOverlapped.lf @@ -8,7 +8,7 @@ import Count from "lib/Count.lf" reactor Test { input c: int - state i: int = 0 + state i: int(0) reaction(c) {= std::cout << "Received " << *c.get() << '\n'; diff --git a/test/Cpp/src/AfterZero.lf b/test/Cpp/src/AfterZero.lf index 152b87cfc2..8baa157e99 100644 --- a/test/Cpp/src/AfterZero.lf +++ b/test/Cpp/src/AfterZero.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time: time = 0 - state i: int = 0 + state expected_time: time(0) + state i: int(0) input x: int reaction(x) {= diff --git a/test/Cpp/src/Alignment.lf b/test/Cpp/src/Alignment.lf index 1bd3562f41..45e52cb573 100644 --- a/test/Cpp/src/Alignment.lf +++ b/test/Cpp/src/Alignment.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { output out: int - state count: int = 1 + state count: int(1) timer t(0, 100 msec) reaction(t) -> out {= diff --git a/test/Cpp/src/ArrayAsParameter.lf b/test/Cpp/src/ArrayAsParameter.lf index 85cd0630bf..77795deb56 100644 --- a/test/Cpp/src/ArrayAsParameter.lf +++ b/test/Cpp/src/ArrayAsParameter.lf @@ -2,9 +2,9 @@ // passes to Print. target Cpp -reactor Source(sequence: std::vector = {0, 1, 2}) { +reactor Source(sequence: int[]{0, 1, 2}) { output out: size_t - state count: size_t = 0 + state count: size_t{0} logical action next: void reaction(startup, next) -> out, next {= @@ -18,7 +18,7 @@ reactor Source(sequence: std::vector = {0, 1, 2}) { reactor Print { input in: size_t - state count: size_t = 1 + state count: size_t{1} reaction(in) {= std::cout << "Received: " << *in.get() << '\n'; @@ -38,7 +38,7 @@ reactor Print { } main reactor ArrayAsParameter { - s = new Source(sequence = {1, 2, 3, 4}) + s = new Source(sequence = {= {1, 2, 3, 4} =}) p = new Print() s.out -> p.in } diff --git a/test/Cpp/src/ArrayPrint.lf b/test/Cpp/src/ArrayPrint.lf index 3bdf494107..420f7902db 100644 --- a/test/Cpp/src/ArrayPrint.lf +++ b/test/Cpp/src/ArrayPrint.lf @@ -18,7 +18,7 @@ reactor Source { =} } -reactor Print(scale: int = 1) { +reactor Print(scale: int(1)) { input in: int[3] reaction(in) {= diff --git a/test/Cpp/src/ArrayScale.lf b/test/Cpp/src/ArrayScale.lf index b52e7305b7..f5b2e56b30 100644 --- a/test/Cpp/src/ArrayScale.lf +++ b/test/Cpp/src/ArrayScale.lf @@ -5,7 +5,7 @@ target Cpp import Source, Print from "ArrayPrint.lf" -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { input in: int[3] output out: int[3] diff --git a/test/Cpp/src/CharLiteralInitializer.lf b/test/Cpp/src/CharLiteralInitializer.lf index e01e5973a6..2d0edb71b8 100644 --- a/test/Cpp/src/CharLiteralInitializer.lf +++ b/test/Cpp/src/CharLiteralInitializer.lf @@ -2,7 +2,7 @@ target Cpp main reactor CharLiteralInitializer { - state c: char = 'x' + state c: char('x') reaction(startup) {= if (c != 'x') { diff --git a/test/Cpp/src/Composition.lf b/test/Cpp/src/Composition.lf index 0a341d5e4f..6ac7364a51 100644 --- a/test/Cpp/src/Composition.lf +++ b/test/Cpp/src/Composition.lf @@ -5,10 +5,10 @@ target Cpp { timeout: 10 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= count++; @@ -18,7 +18,7 @@ reactor Source(period: time = 2 sec) { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= count++; diff --git a/test/Cpp/src/CompositionAfter.lf b/test/Cpp/src/CompositionAfter.lf index 15d68e13ea..06f71a6fbb 100644 --- a/test/Cpp/src/CompositionAfter.lf +++ b/test/Cpp/src/CompositionAfter.lf @@ -5,10 +5,10 @@ target Cpp { timeout: 10 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= count++; @@ -18,7 +18,7 @@ reactor Source(period: time = 2 sec) { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= count++; @@ -38,7 +38,7 @@ reactor Test { =} } -main reactor(delay: time = 5 sec) { +main reactor(delay: time(5 sec)) { s = new Source() d = new Test() s.y -> d.x after delay diff --git a/test/Cpp/src/CountTest.lf b/test/Cpp/src/CountTest.lf index 838d84a998..63a494bc61 100644 --- a/test/Cpp/src/CountTest.lf +++ b/test/Cpp/src/CountTest.lf @@ -7,7 +7,7 @@ import Count from "lib/Count.lf" reactor Test { input c: int - state i: int = 0 + state i: int(0) reaction(c) {= i++; diff --git a/test/Cpp/src/Deadline.lf b/test/Cpp/src/Deadline.lf index 19a41ff057..81eab8a004 100644 --- a/test/Cpp/src/Deadline.lf +++ b/test/Cpp/src/Deadline.lf @@ -5,13 +5,13 @@ target Cpp { timeout: 4 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { private preamble {= #include =} output y: int timer t(0, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= if (count % 2 == 1) { @@ -25,9 +25,9 @@ reactor Source(period: time = 2 sec) { =} } -reactor Destination(timeout: time = 1 sec) { +reactor Destination(timeout: time(1 sec)) { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= std::cout << "Destination receives: " << *x.get() << std::endl; diff --git a/test/Cpp/src/DeadlineHandledAbove.lf b/test/Cpp/src/DeadlineHandledAbove.lf index b2a6c7658a..76a790fcbf 100644 --- a/test/Cpp/src/DeadlineHandledAbove.lf +++ b/test/Cpp/src/DeadlineHandledAbove.lf @@ -2,7 +2,7 @@ // container reacts to that output. target Cpp -reactor Deadline(threshold: time = 100 msec) { +reactor Deadline(threshold: time(100 msec)) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time = 100 msec) { } main reactor DeadlineHandledAbove { - state violation_detected: bool = {= false =} + state violation_detected: bool({= false =}) d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/Cpp/src/DelayInt.lf b/test/Cpp/src/DelayInt.lf index f58e5ef45b..379e22a3ec 100644 --- a/test/Cpp/src/DelayInt.lf +++ b/test/Cpp/src/DelayInt.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target Cpp -reactor Delay(delay: time = 100 msec) { +reactor Delay(delay: time(100 msec)) { input in: int output out: int logical action d: int diff --git a/test/Cpp/src/DelayedAction.lf b/test/Cpp/src/DelayedAction.lf index 1ce1aea63f..0b2b748909 100644 --- a/test/Cpp/src/DelayedAction.lf +++ b/test/Cpp/src/DelayedAction.lf @@ -6,7 +6,7 @@ target Cpp { main reactor DelayedAction { timer t(0, 1 sec) logical action a: void - state count: int = 0 + state count: int(0) reaction(t) -> a {= a.schedule(100ms); =} diff --git a/test/Cpp/src/DoubleInvocation.lf b/test/Cpp/src/DoubleInvocation.lf index 956b54bb17..3315fafae4 100644 --- a/test/Cpp/src/DoubleInvocation.lf +++ b/test/Cpp/src/DoubleInvocation.lf @@ -14,7 +14,7 @@ target Cpp { reactor Ball { output position: int output velocity: int - state p: int = 200 + state p: int(200) timer trigger(0, 1 sec) reaction(trigger) -> position, velocity {= @@ -27,7 +27,7 @@ reactor Ball { reactor Print { input velocity: int input position: int - state previous: int = -1 + state previous: int(-1) reaction(startup) {= reactor::log::Info() << "####### Print startup"; diff --git a/test/Cpp/src/DoublePort.lf b/test/Cpp/src/DoublePort.lf index faaa474db5..00950b1331 100644 --- a/test/Cpp/src/DoublePort.lf +++ b/test/Cpp/src/DoublePort.lf @@ -13,7 +13,7 @@ target Cpp { import Count from "lib/Count.lf" reactor CountMicrostep { - state count: int = 1 + state count: int(1) output out: int logical action act: int timer t(0, 1 sec) diff --git a/test/Cpp/src/DoubleReaction.lf b/test/Cpp/src/DoubleReaction.lf index 1128d63f97..d5e8964089 100644 --- a/test/Cpp/src/DoubleReaction.lf +++ b/test/Cpp/src/DoubleReaction.lf @@ -5,10 +5,10 @@ target Cpp { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= count++; @@ -19,7 +19,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int input w: int - state s: int = 2 + state s: int(2) reaction(x, w) {= int sum = 0; diff --git a/test/Cpp/src/DoubleTrigger.lf b/test/Cpp/src/DoubleTrigger.lf index 5db4818048..c714d83e9c 100644 --- a/test/Cpp/src/DoubleTrigger.lf +++ b/test/Cpp/src/DoubleTrigger.lf @@ -5,7 +5,7 @@ target Cpp main reactor DoubleTrigger { timer t1 timer t2 - state s: int = 0 + state s: int(0) reaction(t1, t2) {= s++; diff --git a/test/Cpp/src/FloatLiteral.lf b/test/Cpp/src/FloatLiteral.lf index 6ad95f9e55..a65af798b4 100644 --- a/test/Cpp/src/FloatLiteral.lf +++ b/test/Cpp/src/FloatLiteral.lf @@ -2,10 +2,10 @@ target Cpp // This test verifies that floating-point literals are handled correctly. main reactor { - state N: double = 6.0221409e+23 - state charge: double = -1.6021766E-19 - state minus_epsilon: double = -.01e0 - state expected: double = .964853323188E5 + state N: double(6.0221409e+23) + state charge: double(-1.6021766E-19) + state minus_epsilon: double(-.01e0) + state expected: double(.964853323188E5) reaction(startup) {= auto F = - N * charge; diff --git a/test/Cpp/src/Gain.lf b/test/Cpp/src/Gain.lf index 4b123cc992..4a62a62a8e 100644 --- a/test/Cpp/src/Gain.lf +++ b/test/Cpp/src/Gain.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target Cpp -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { input x: int output y: int diff --git a/test/Cpp/src/GetMicroStep.lf b/test/Cpp/src/GetMicroStep.lf index 8370a21403..c8eb89a4fa 100644 --- a/test/Cpp/src/GetMicroStep.lf +++ b/test/Cpp/src/GetMicroStep.lf @@ -2,7 +2,7 @@ target Cpp main reactor GetMicroStep { - state s: {= reactor::mstep_t =} = 1 + state s: {= reactor::mstep_t =}(1) logical action l diff --git a/test/Cpp/src/Hello.lf b/test/Cpp/src/Hello.lf index f74acf6688..c63afbabe4 100644 --- a/test/Cpp/src/Hello.lf +++ b/test/Cpp/src/Hello.lf @@ -8,11 +8,8 @@ target Cpp { fast: true } -reactor HelloCpp( - period: time = 2 sec, - message: {= std::string =} = "Hello C++" -) { - state count: int = 0 +reactor HelloCpp(period: time(2 sec), message: {= std::string =}("Hello C++")) { + state count: int(0) state previous_time: {= reactor::TimePoint =} timer t(1 sec, period) logical action a: void @@ -40,8 +37,8 @@ reactor HelloCpp( } reactor Inside( - period: time = 1 sec, - message: std::string = "Composite default message." + period: time(1 sec), + message: std::string("Composite default message.") ) { third_instance = new HelloCpp(period = period, message = message) } diff --git a/test/Cpp/src/Hierarchy2.lf b/test/Cpp/src/Hierarchy2.lf index db81bf4971..4e78e3406e 100644 --- a/test/Cpp/src/Hierarchy2.lf +++ b/test/Cpp/src/Hierarchy2.lf @@ -14,7 +14,7 @@ reactor Source { reactor Count { output out: int timer t(0, 1 sec) - state i: int = 0 + state i: int(0) reaction(t) -> out {= i++; @@ -37,7 +37,7 @@ reactor Add { reactor Print { input in: int - state expected: int = 2 + state expected: int(2) reaction(in) {= auto value = *in.get(); diff --git a/test/Cpp/src/ImportComposition.lf b/test/Cpp/src/ImportComposition.lf index 0559edacd1..4b8649a243 100644 --- a/test/Cpp/src/ImportComposition.lf +++ b/test/Cpp/src/ImportComposition.lf @@ -16,7 +16,7 @@ main reactor ImportComposition { =} imp_comp = new ImportedComposition() - state received: bool = false + state received: bool(false) reaction(startup) -> imp_comp.x {= imp_comp.x.set(42); =} diff --git a/test/Cpp/src/ManualDelayedReaction.lf b/test/Cpp/src/ManualDelayedReaction.lf index 3c55bdcaf1..2d426bffb7 100644 --- a/test/Cpp/src/ManualDelayedReaction.lf +++ b/test/Cpp/src/ManualDelayedReaction.lf @@ -4,7 +4,7 @@ target Cpp reactor GeneratedDelay { input y_in: int output y_out: int - state y_state: int = 0 + state y_state: int(0) logical action act(100 msec): int diff --git a/test/Cpp/src/Methods.lf b/test/Cpp/src/Methods.lf index ff94460b62..fc4decbcbd 100644 --- a/test/Cpp/src/Methods.lf +++ b/test/Cpp/src/Methods.lf @@ -1,7 +1,7 @@ target Cpp main reactor { - state foo: int = 2 + state foo: int(2) const method getFoo(): int {= return foo; =} diff --git a/test/Cpp/src/MovingAverage.lf b/test/Cpp/src/MovingAverage.lf index af202ca0a0..160688c2ed 100644 --- a/test/Cpp/src/MovingAverage.lf +++ b/test/Cpp/src/MovingAverage.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { output out: double - state count: int = 0 + state count: int{0} timer clock(0, 200 msec) reaction(clock) -> out {= @@ -19,7 +19,7 @@ reactor Source { reactor MovingAverageImpl { state delay_line: double[3]{0.0, 0.0, 0.0} - state index: int = 0 + state index: int{0} input in: double output out: double @@ -44,7 +44,7 @@ reactor MovingAverageImpl { reactor Print { input in: double - state count: int = 0 + state count: int{0} reaction(in) {= std::cout << "Received: " << *in.get() << '\n'; diff --git a/test/Cpp/src/NativeListsAndTimes.lf b/test/Cpp/src/NativeListsAndTimes.lf index 5bf67c8fb4..5ec46d2930 100644 --- a/test/Cpp/src/NativeListsAndTimes.lf +++ b/test/Cpp/src/NativeListsAndTimes.lf @@ -2,29 +2,27 @@ target Cpp // This test passes if it is successfully compiled into valid target code. reactor Foo( - x: int = 0, - y: time = 0, // Units are missing but not required - z = 1 msec, // Type is missing but not required - p: int[]{1, 2, 3, 4}, // List of integers + x: int(0), + y: time(0), // Units are missing but not required + z(1 msec), // Type is missing but not required + p: int[]{1, 2, 3, 4}, // List of integers q: {= // list of time values std::vector =}{1 msec, 2 msec, 3 msec}, - g: time[]{1 msec, 2 msec}, // List of time values - g2: int[] = {} + g: time[]{1 msec, 2 msec} // List of time values ) { - state s: time = y // Reference to explicitly typed time parameter - state t: time = z // Reference to implicitly typed time parameter + state s: time(y) // Reference to explicitly typed time parameter + state t: time(z) // Reference to implicitly typed time parameter state v: bool // Uninitialized boolean state variable state w: time // Uninitialized time state variable timer tick(0) // Units missing but not required timer tock(1 sec) // Implicit type time timer toe(z) // Implicit type time - state baz = p // Implicit type int[] - state period = z // Implicit type time + state baz(p) // Implicit type int[] + state period(z) // Implicit type time state times: std::vector< // a list of lists std::vector<{= reactor::Duration =}> >{q, g} - state empty_list: int[] = {} reaction(tick) {= // Target code diff --git a/test/Cpp/src/NestedTriggeredReactions.lf b/test/Cpp/src/NestedTriggeredReactions.lf index 783dcefc7e..dcaa64b179 100644 --- a/test/Cpp/src/NestedTriggeredReactions.lf +++ b/test/Cpp/src/NestedTriggeredReactions.lf @@ -3,7 +3,7 @@ target Cpp reactor Container { input in: void - state triggered: bool = false + state triggered: bool{false} contained = new Contained() @@ -22,7 +22,7 @@ reactor Container { reactor Contained { input in: void - state triggered: bool = false + state triggered: bool{false} reaction(in) {= triggered = true; =} diff --git a/test/Cpp/src/ParameterHierarchy.lf b/test/Cpp/src/ParameterHierarchy.lf index c183cbca03..acd051a5ce 100644 --- a/test/Cpp/src/ParameterHierarchy.lf +++ b/test/Cpp/src/ParameterHierarchy.lf @@ -7,7 +7,7 @@ */ target Cpp -reactor Deep(p: int = 0) { +reactor Deep(p: int(0)) { reaction(startup) {= if(p != 42) { reactor::log::Error() << "Parameter value is: " << p << ". Should have been 42."; @@ -18,11 +18,11 @@ reactor Deep(p: int = 0) { =} } -reactor Intermediate(p: int = 10) { +reactor Intermediate(p: int(10)) { a = new Deep(p = p) } -reactor Another(p: int = 20) { +reactor Another(p: int(20)) { // also test forwarding parameters via target code blocks a = new Intermediate(p = {= p =}) } diff --git a/test/Cpp/src/ParameterizedState.lf b/test/Cpp/src/ParameterizedState.lf index 1c39043a75..be03a52b9a 100644 --- a/test/Cpp/src/ParameterizedState.lf +++ b/test/Cpp/src/ParameterizedState.lf @@ -1,7 +1,7 @@ target Cpp -reactor Foo(bar: int = 4) { - state baz = bar +reactor Foo(bar: int(4)) { + state baz(bar) reaction(startup) {= std::cout << "Baz: " << baz << std::endl; diff --git a/test/Cpp/src/ParametersOutOfOrder.lf b/test/Cpp/src/ParametersOutOfOrder.lf index 7ef28b914a..64dcbc6ef3 100644 --- a/test/Cpp/src/ParametersOutOfOrder.lf +++ b/test/Cpp/src/ParametersOutOfOrder.lf @@ -2,7 +2,7 @@ // definition order. Compilation without errors is success. target Cpp -reactor Foo(a: int = 0, b: std::string = "", c: float = 0.0) { +reactor Foo(a: int(0), b: std::string(""), c: float(0.0)) { reaction(startup) {= if (a != 42 || b != "bar" || c < 3.1) { reactor::log::Error() << "received an unexpected parameter!"; diff --git a/test/Cpp/src/PeriodicDesugared.lf b/test/Cpp/src/PeriodicDesugared.lf index 2823835687..2b6e92c750 100644 --- a/test/Cpp/src/PeriodicDesugared.lf +++ b/test/Cpp/src/PeriodicDesugared.lf @@ -3,10 +3,10 @@ target Cpp { timeout: 5 secs } -main reactor(offset: time = 50 msec, period: time = 500 msec) { +main reactor(offset: time(50 msec), period: time(500 msec)) { logical action init(offset): void logical action recur(period): void - state expected = offset + state expected(offset) reaction(startup) -> init {= std::cout << "Hello from Periodic!\n"; diff --git a/test/Cpp/src/Pipeline.lf b/test/Cpp/src/Pipeline.lf index cc86ef67a0..c4300f13c9 100644 --- a/test/Cpp/src/Pipeline.lf +++ b/test/Cpp/src/Pipeline.lf @@ -6,7 +6,7 @@ import Computation from "concurrent/Threaded.lf" reactor Print { input in: int - state count: int = 0 + state count: int(0) reaction(in) {= std::cout << "Received: " << *in.get() << '\n'; @@ -27,7 +27,7 @@ reactor Print { main reactor Pipeline { timer t(0, 200 msec) - state count: int = 0 + state count: int(0) c1 = new Computation() c2 = new Computation() diff --git a/test/Cpp/src/ReadOutputOfContainedReactor.lf b/test/Cpp/src/ReadOutputOfContainedReactor.lf index c7e85083b4..6cba642f04 100644 --- a/test/Cpp/src/ReadOutputOfContainedReactor.lf +++ b/test/Cpp/src/ReadOutputOfContainedReactor.lf @@ -10,7 +10,7 @@ reactor Contained { main reactor ReadOutputOfContainedReactor { c = new Contained() - state count: int = 0 + state count: int(0) reaction(startup) c.out {= std::cout << "Startup reaction reading output of contained " diff --git a/test/Cpp/src/ScheduleLogicalAction.lf b/test/Cpp/src/ScheduleLogicalAction.lf index 96fd5382b7..c8eaea1a30 100644 --- a/test/Cpp/src/ScheduleLogicalAction.lf +++ b/test/Cpp/src/ScheduleLogicalAction.lf @@ -26,7 +26,7 @@ reactor foo { } reactor print { - state expected_time: time = 0 + state expected_time: time(0) input x: int reaction(x) {= diff --git a/test/Cpp/src/SelfLoop.lf b/test/Cpp/src/SelfLoop.lf index 2be47e3d4e..be08cc771b 100644 --- a/test/Cpp/src/SelfLoop.lf +++ b/test/Cpp/src/SelfLoop.lf @@ -12,7 +12,7 @@ reactor Self { input x: int output y: int logical action a: int - state expected: int = 43 + state expected: int(43) reaction(a) -> y {= reactor::log::Info() << "a = " << *a.get(); diff --git a/test/Cpp/src/SendingInside.lf b/test/Cpp/src/SendingInside.lf index 2f73122bc8..2d947f686b 100644 --- a/test/Cpp/src/SendingInside.lf +++ b/test/Cpp/src/SendingInside.lf @@ -7,7 +7,7 @@ target Cpp { reactor Printer { input x: int - state count: int = 1 + state count: int(1) reaction(x) {= std::cout << "Inside reactor received: " << *x.get() << std::endl; @@ -20,7 +20,7 @@ reactor Printer { } main reactor SendingInside { - state count: int = 0 + state count: int(0) timer t(0, 1 sec) p = new Printer() diff --git a/test/Cpp/src/SimpleDeadline.lf b/test/Cpp/src/SimpleDeadline.lf index be10b55d43..17c354108a 100644 --- a/test/Cpp/src/SimpleDeadline.lf +++ b/test/Cpp/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ // violation. target Cpp -reactor Deadline(threshold: time = 100 msec) { +reactor Deadline(threshold: time(100 msec)) { private preamble {= #include =} diff --git a/test/Cpp/src/SlowingClock.lf b/test/Cpp/src/SlowingClock.lf index adbe93e418..41dda03dba 100644 --- a/test/Cpp/src/SlowingClock.lf +++ b/test/Cpp/src/SlowingClock.lf @@ -15,8 +15,8 @@ target Cpp { main reactor SlowingClock { logical action a(100 msec) - state interval: time = 100 msec - state expected_time: time = 100 msec + state interval: time(100 msec) + state expected_time: time(100 msec) reaction(startup) -> a {= a.schedule(0ns); =} diff --git a/test/Cpp/src/SlowingClockPhysical.lf b/test/Cpp/src/SlowingClockPhysical.lf index 919f9d6cdf..24f77cf2be 100644 --- a/test/Cpp/src/SlowingClockPhysical.lf +++ b/test/Cpp/src/SlowingClockPhysical.lf @@ -15,8 +15,8 @@ target Cpp { main reactor SlowingClockPhysical { physical action a - state interval: time = 100 msec - state expected_time: time = 100 msec + state interval: time(100 msec) + state expected_time: time(100 msec) reaction(startup) -> a {= expected_time=100ms; diff --git a/test/Cpp/src/Stride.lf b/test/Cpp/src/Stride.lf index 5f469e4c70..8adeaa69b0 100644 --- a/test/Cpp/src/Stride.lf +++ b/test/Cpp/src/Stride.lf @@ -5,8 +5,8 @@ target Cpp { fast: true } -reactor Count(stride: int = 1) { - state count: int = 0 +reactor Count(stride: int(1)) { + state count: int(0) output y: int timer t(0, 100 msec) diff --git a/test/Cpp/src/StructPrint.lf b/test/Cpp/src/StructPrint.lf index 4ee404b8bf..9e0bc35d45 100644 --- a/test/Cpp/src/StructPrint.lf +++ b/test/Cpp/src/StructPrint.lf @@ -19,8 +19,8 @@ reactor Source { } reactor Print( - expected_value: int = 42, - expected_name: {= std::string =} = "Earth" + expected_value: int(42), + expected_name: {= std::string =}("Earth") ) { input in: Hello diff --git a/test/Cpp/src/StructScale.lf b/test/Cpp/src/StructScale.lf index 776dad14b1..cf818f710f 100644 --- a/test/Cpp/src/StructScale.lf +++ b/test/Cpp/src/StructScale.lf @@ -9,7 +9,7 @@ public preamble {= #include "include/hello.h" =} -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { input in: Hello output out: Hello diff --git a/test/Cpp/src/TimeLimit.lf b/test/Cpp/src/TimeLimit.lf index 8b33dcd967..ec8d43af42 100644 --- a/test/Cpp/src/TimeLimit.lf +++ b/test/Cpp/src/TimeLimit.lf @@ -5,10 +5,10 @@ target Cpp { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= count++; @@ -19,7 +19,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int - state s: int = 1 + state s: int(1) reaction(x) {= //std::cout << "Received " << *x.get() << '\n'; @@ -39,7 +39,7 @@ reactor Destination { =} } -main reactor TimeLimit(period: time = 1 sec) { +main reactor TimeLimit(period: time(1 sec)) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/Cpp/src/TimeState.lf b/test/Cpp/src/TimeState.lf index aefac79b1c..28228c11ec 100644 --- a/test/Cpp/src/TimeState.lf +++ b/test/Cpp/src/TimeState.lf @@ -1,7 +1,7 @@ target Cpp -reactor Foo(bar: time = 42 msec) { - state baz = bar +reactor Foo(bar: time(42 msec)) { + state baz(bar) reaction(startup) {= std::cout << "Baz: " << baz << std::endl; =} } diff --git a/test/Cpp/src/Timeout_Test.lf b/test/Cpp/src/Timeout_Test.lf index c3fe1ffbf9..53ff8480dd 100644 --- a/test/Cpp/src/Timeout_Test.lf +++ b/test/Cpp/src/Timeout_Test.lf @@ -13,7 +13,7 @@ import Sender from "lib/LoopedActionSender.lf" reactor Consumer { input in: int - state success: bool = false + state success: bool(false) reaction(in) {= auto current{get_elapsed_logical_time()}; diff --git a/test/Cpp/src/ToReactionNested.lf b/test/Cpp/src/ToReactionNested.lf index 5b048bc0a7..ff391229a0 100644 --- a/test/Cpp/src/ToReactionNested.lf +++ b/test/Cpp/src/ToReactionNested.lf @@ -12,8 +12,8 @@ reactor CountContainer { } main reactor { - state count: int = 1 - state received: bool = false + state count: int(1) + state received: bool(false) s = new CountContainer() diff --git a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf index b8c304b164..d46507fce4 100644 --- a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf @@ -13,7 +13,7 @@ target Cpp { reactor Source { output[2] out: int - state count: int = 0 + state count: int(0) timer t(0, 200 msec) reaction(t) -> out {= diff --git a/test/Cpp/src/concurrent/AsyncCallback.lf b/test/Cpp/src/concurrent/AsyncCallback.lf index 1258f69ce5..29fedc41e8 100644 --- a/test/Cpp/src/concurrent/AsyncCallback.lf +++ b/test/Cpp/src/concurrent/AsyncCallback.lf @@ -1,6 +1,7 @@ // Test asynchronous callbacks that trigger a physical action. target Cpp { timeout: 2 sec, + keepalive: true, cmake-include: "AsyncCallback.cmake" } @@ -11,11 +12,11 @@ main reactor AsyncCallback { timer t(0, 200 msec) state thread: {= std::thread =} - state expected_time: time = 100 msec - state toggle: bool = false + state expected_time: time(100 msec) + state toggle: bool(false) physical action a: int - state i: int = 0 + state i: int(0) reaction(t) -> a {= // make sure to join the old thread first diff --git a/test/Cpp/src/concurrent/AsyncCallback2.lf b/test/Cpp/src/concurrent/AsyncCallback2.lf index c89b8ab712..ea493a32cd 100644 --- a/test/Cpp/src/concurrent/AsyncCallback2.lf +++ b/test/Cpp/src/concurrent/AsyncCallback2.lf @@ -1,6 +1,7 @@ // Test asynchronous callbacks that trigger a non-physical action. target Cpp { timeout: 2 sec, + keepalive: true, cmake-include: "AsyncCallback.cmake" } @@ -10,10 +11,10 @@ main reactor AsyncCallback2 { =} timer t(0, 200 msec) - state expected_time: time = 0 + state expected_time: time(0) logical action a: int - state i: int = 0 + state i: int(0) reaction(t) -> a {= // start new thread diff --git a/test/Cpp/src/concurrent/CompositionThreaded.lf b/test/Cpp/src/concurrent/CompositionThreaded.lf index 42817e8b1d..393b08e060 100644 --- a/test/Cpp/src/concurrent/CompositionThreaded.lf +++ b/test/Cpp/src/concurrent/CompositionThreaded.lf @@ -5,10 +5,10 @@ target Cpp { timeout: 10 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { output y: int timer t(1 sec, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= count++; @@ -18,7 +18,7 @@ reactor Source(period: time = 2 sec) { reactor Test { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= count++; diff --git a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf index bb380fe14c..eb88c997eb 100644 --- a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -2,7 +2,7 @@ // container reacts to that output. target Cpp -reactor Deadline(threshold: time = 100 msec) { +reactor Deadline(threshold: time(100 msec)) { input x: int output deadline_violation: bool @@ -16,7 +16,7 @@ reactor Deadline(threshold: time = 100 msec) { } main reactor { - state violation_detected: bool = {= false =} + state violation_detected: bool({= false =}) d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/Cpp/src/concurrent/DeadlineThreaded.lf b/test/Cpp/src/concurrent/DeadlineThreaded.lf index cb794f5050..ad87c5a052 100644 --- a/test/Cpp/src/concurrent/DeadlineThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineThreaded.lf @@ -5,13 +5,13 @@ target Cpp { timeout: 4 sec } -reactor Source(period: time = 2 sec) { +reactor Source(period: time(2 sec)) { private preamble {= #include =} output y: int timer t(0, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= if (count % 2 == 1) { @@ -25,9 +25,9 @@ reactor Source(period: time = 2 sec) { =} } -reactor Destination(timeout: time = 1 sec) { +reactor Destination(timeout: time(1 sec)) { input x: int - state count: int = 0 + state count: int(0) reaction(x) {= std::cout << "Destination receives: " << *x.get() << std::endl; diff --git a/test/Cpp/src/concurrent/DelayIntThreaded.lf b/test/Cpp/src/concurrent/DelayIntThreaded.lf index 319cae8b76..d935ae12e5 100644 --- a/test/Cpp/src/concurrent/DelayIntThreaded.lf +++ b/test/Cpp/src/concurrent/DelayIntThreaded.lf @@ -1,7 +1,7 @@ // This tests actions with payloads by delaying an input by a fixed amount. target Cpp -reactor Delay(delay: time = 100 msec) { +reactor Delay(delay: time(100 msec)) { input in: int output out: int logical action d: int diff --git a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf index d68f2e8b60..1c9c3041b6 100644 --- a/test/Cpp/src/concurrent/DoubleReactionThreaded.lf +++ b/test/Cpp/src/concurrent/DoubleReactionThreaded.lf @@ -5,10 +5,10 @@ target Cpp { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= count++; @@ -19,7 +19,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int input w: int - state s: int = 2 + state s: int(2) reaction(x, w) {= int sum = 0; diff --git a/test/Cpp/src/concurrent/GainThreaded.lf b/test/Cpp/src/concurrent/GainThreaded.lf index e88801f5a1..8e96f44ed1 100644 --- a/test/Cpp/src/concurrent/GainThreaded.lf +++ b/test/Cpp/src/concurrent/GainThreaded.lf @@ -1,7 +1,7 @@ // Example in the Wiki. target Cpp -reactor Scale(scale: int = 2) { +reactor Scale(scale: int(2)) { input x: int output y: int diff --git a/test/Cpp/src/concurrent/HelloThreaded.lf b/test/Cpp/src/concurrent/HelloThreaded.lf index 2c849b94dc..7515d76d38 100644 --- a/test/Cpp/src/concurrent/HelloThreaded.lf +++ b/test/Cpp/src/concurrent/HelloThreaded.lf @@ -8,11 +8,8 @@ target Cpp { fast: true } -reactor HelloCpp( - period: time = 2 sec, - message: {= std::string =} = "Hello C++" -) { - state count: int = 0 +reactor HelloCpp(period: time(2 sec), message: {= std::string =}("Hello C++")) { + state count: int(0) state previous_time: {= reactor::TimePoint =} timer t(1 sec, period) logical action a: void @@ -40,8 +37,8 @@ reactor HelloCpp( } reactor Inside( - period: time = 1 sec, - message: {= std::string =} = "Composite default message." + period: time(1 sec), + message: {= std::string =}("Composite default message.") ) { third_instance = new HelloCpp(period = period, message = message) } diff --git a/test/Cpp/src/concurrent/SendingInsideThreaded.lf b/test/Cpp/src/concurrent/SendingInsideThreaded.lf index 51ca511e26..a0e0fcc250 100644 --- a/test/Cpp/src/concurrent/SendingInsideThreaded.lf +++ b/test/Cpp/src/concurrent/SendingInsideThreaded.lf @@ -7,7 +7,7 @@ target Cpp { reactor Printer { input x: int - state count: int = 1 + state count: int(1) reaction(x) {= std::cout << "Inside reactor received: " << *x.get() << std::endl; @@ -20,7 +20,7 @@ reactor Printer { } main reactor { - state count: int = 0 + state count: int(0) timer t(0, 1 sec) p = new Printer() diff --git a/test/Cpp/src/concurrent/Threaded.lf b/test/Cpp/src/concurrent/Threaded.lf index 9ad4fcbe56..0a0d857030 100644 --- a/test/Cpp/src/concurrent/Threaded.lf +++ b/test/Cpp/src/concurrent/Threaded.lf @@ -13,7 +13,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= out.set(s); @@ -35,7 +35,7 @@ reactor Computation { } reactor Destination { - state s: int = 0 + state s: int(0) input in1: int input in2: int input in3: int diff --git a/test/Cpp/src/concurrent/ThreadedThreaded.lf b/test/Cpp/src/concurrent/ThreadedThreaded.lf index f8b21a6121..2a6680273b 100644 --- a/test/Cpp/src/concurrent/ThreadedThreaded.lf +++ b/test/Cpp/src/concurrent/ThreadedThreaded.lf @@ -13,7 +13,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= out.set(s); @@ -35,7 +35,7 @@ reactor Computation { } reactor Destination { - state s: int = 0 + state s: int(0) input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/concurrent/TimeLimitThreaded.lf b/test/Cpp/src/concurrent/TimeLimitThreaded.lf index 47371f72d7..5afcf05299 100644 --- a/test/Cpp/src/concurrent/TimeLimitThreaded.lf +++ b/test/Cpp/src/concurrent/TimeLimitThreaded.lf @@ -6,10 +6,10 @@ target Cpp { fast: true } -reactor Clock(offset: time = 0, period: time = 1 sec) { +reactor Clock(offset: time(0), period: time(1 sec)) { output y: int timer t(offset, period) - state count: int = 0 + state count: int(0) reaction(t) -> y {= count++; @@ -20,7 +20,7 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { reactor Destination { input x: int - state s: int = 1 + state s: int(1) reaction(x) {= //std::cout << "Received " << *x.get() << '\n'; @@ -40,7 +40,7 @@ reactor Destination { =} } -main reactor(period: time = 1 sec) { +main reactor(period: time(1 sec)) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/Cpp/src/enclave/EnclaveBank.lf b/test/Cpp/src/enclave/EnclaveBank.lf index 8894526927..b155bd9f57 100644 --- a/test/Cpp/src/enclave/EnclaveBank.lf +++ b/test/Cpp/src/enclave/EnclaveBank.lf @@ -4,10 +4,10 @@ target Cpp { } reactor Node( - bank_index: size_t = 0, - id: std::string = {= "node" + std::to_string(bank_index) =}, - period: time = 500 msec, - duration: time = 10 msec + bank_index: size_t(0), + id: std::string({= "node" + std::to_string(bank_index) =}), + period: time(500 msec), + duration: time(10 msec) ) { logical action a: void diff --git a/test/Cpp/src/enclave/EnclaveBankEach.lf b/test/Cpp/src/enclave/EnclaveBankEach.lf index c6cdeac564..c632d2ae79 100644 --- a/test/Cpp/src/enclave/EnclaveBankEach.lf +++ b/test/Cpp/src/enclave/EnclaveBankEach.lf @@ -5,10 +5,10 @@ target Cpp { } reactor Node( - bank_index: size_t = 0, - id: std::string = {= "node" + std::to_string(bank_index) =}, - period: {= reactor::Duration =} = {= 100ms * (bank_index+1) =}, - duration: {= reactor::Duration =} = {= 50ms + 100ms * bank_index =} + bank_index: size_t(0), + id: std::string({= "node" + std::to_string(bank_index) =}), + period: {= reactor::Duration =}({= 100ms * (bank_index+1) =}), + duration: {= reactor::Duration =}({= 50ms + 100ms * bank_index =}) ) { logical action a: void diff --git a/test/Cpp/src/enclave/EnclaveHelloWorld.lf b/test/Cpp/src/enclave/EnclaveHelloWorld.lf index 7ca051533b..ab28317cf9 100644 --- a/test/Cpp/src/enclave/EnclaveHelloWorld.lf +++ b/test/Cpp/src/enclave/EnclaveHelloWorld.lf @@ -1,10 +1,10 @@ target Cpp -reactor Hello(msg: std::string = "World") { +reactor Hello(msg: std::string("World")) { reaction(startup) {= reactor::log::Info() << "Hello " << msg << '!'; =} } -main reactor(msg1: std::string = "World", msg2: std::string = "Enclave") { +main reactor(msg1: std::string("World"), msg2: std::string("Enclave")) { hello1 = new Hello(msg = msg1) @enclave diff --git a/test/Cpp/src/enclave/EnclaveHierarchy.lf b/test/Cpp/src/enclave/EnclaveHierarchy.lf index 9063942575..87c811f859 100644 --- a/test/Cpp/src/enclave/EnclaveHierarchy.lf +++ b/test/Cpp/src/enclave/EnclaveHierarchy.lf @@ -4,9 +4,9 @@ target Cpp { } reactor Node( - id: std::string = "node", - period: time = 100 msec, - duration: time = 50 msec + id: std::string("node"), + period: time(100 msec), + duration: time(50 msec) ) { timer t(0, period) diff --git a/test/Cpp/src/enclave/EnclaveShutdown.lf b/test/Cpp/src/enclave/EnclaveShutdown.lf index 831adcde9c..7d25a53643 100644 --- a/test/Cpp/src/enclave/EnclaveShutdown.lf +++ b/test/Cpp/src/enclave/EnclaveShutdown.lf @@ -1,9 +1,9 @@ target Cpp reactor Node( - message: std::string = "Hello", - period: time = 1 sec, - stop: time = 3 sec + message: std::string("Hello"), + period: time(1 sec), + stop: time(3 sec) ) { timer t(0, period) timer s(stop) diff --git a/test/Cpp/src/enclave/EnclaveTimeout.lf b/test/Cpp/src/enclave/EnclaveTimeout.lf index dc87acbd26..c9dd51498f 100644 --- a/test/Cpp/src/enclave/EnclaveTimeout.lf +++ b/test/Cpp/src/enclave/EnclaveTimeout.lf @@ -2,7 +2,7 @@ target Cpp { timeout: 1 sec } -reactor Node(message: std::string = "Hello", period: time = 1 sec) { +reactor Node(message: std::string("Hello"), period: time(1 sec)) { timer t(0, period) reaction(t) {= reactor::log::Info() << message; =} diff --git a/test/Cpp/src/lib/Count.lf b/test/Cpp/src/lib/Count.lf index 7b56233019..aaf689b720 100644 --- a/test/Cpp/src/lib/Count.lf +++ b/test/Cpp/src/lib/Count.lf @@ -3,7 +3,7 @@ target Cpp reactor Count { output c: int timer t(0, 1 sec) - state i: int = 0 + state i: int(0) reaction(t) -> c {= i++; diff --git a/test/Cpp/src/lib/LoopedActionSender.lf b/test/Cpp/src/lib/LoopedActionSender.lf index 3c1cc13631..db35b7a606 100644 --- a/test/Cpp/src/lib/LoopedActionSender.lf +++ b/test/Cpp/src/lib/LoopedActionSender.lf @@ -13,10 +13,10 @@ target Cpp * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after: int = 10, break_interval: time = 400 msec) { +reactor Sender(take_a_break_after: int(10), break_interval: time(400 msec)) { output out: int logical action act - state sent_messages: int = 0 + state sent_messages: int(0) reaction(startup, act) -> act, out {= out.set(sent_messages); diff --git a/test/Cpp/src/multiport/BankSelfBroadcast.lf b/test/Cpp/src/multiport/BankSelfBroadcast.lf index 07da948506..a32e3a8eac 100644 --- a/test/Cpp/src/multiport/BankSelfBroadcast.lf +++ b/test/Cpp/src/multiport/BankSelfBroadcast.lf @@ -8,10 +8,10 @@ */ target Cpp -reactor A(bank_index: size_t = 0) { +reactor A(bank_index: size_t(0)) { input[4] in: size_t output out: size_t - state received: bool = false + state received: bool(false) reaction(startup) -> out {= out.set(bank_index); =} diff --git a/test/Cpp/src/multiport/BankToBank.lf b/test/Cpp/src/multiport/BankToBank.lf index f70cfd83e4..84fc29ea09 100644 --- a/test/Cpp/src/multiport/BankToBank.lf +++ b/test/Cpp/src/multiport/BankToBank.lf @@ -4,10 +4,10 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t = 0) { +reactor Source(bank_index: size_t(0)) { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= out.set(s); @@ -15,8 +15,8 @@ reactor Source(bank_index: size_t = 0) { =} } -reactor Destination(bank_index: size_t = 0) { - state s: int = 0 +reactor Destination(bank_index: size_t(0)) { + state s: int(0) input in: int reaction(in) {= @@ -37,7 +37,7 @@ reactor Destination(bank_index: size_t = 0) { =} } -main reactor BankToBank(width: int = 4) { +main reactor BankToBank(width: int(4)) { // FIXME: Should set the width to "width" rather than "4". a = new[4] Source() b = new[4] Destination() diff --git a/test/Cpp/src/multiport/BankToBankMultiport.lf b/test/Cpp/src/multiport/BankToBankMultiport.lf index bdb3e9a880..e5c26a4d2b 100644 --- a/test/Cpp/src/multiport/BankToBankMultiport.lf +++ b/test/Cpp/src/multiport/BankToBankMultiport.lf @@ -4,10 +4,10 @@ target Cpp { fast: true } -reactor Source(width: size_t = 1) { +reactor Source(width: size_t(1)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(size_t i = 0; i < out.size(); i++) { @@ -16,8 +16,8 @@ reactor Source(width: size_t = 1) { =} } -reactor Destination(width: size_t = 1) { - state s: int = 6 +reactor Destination(width: size_t(1)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -44,7 +44,7 @@ reactor Destination(width: size_t = 1) { =} } -main reactor(bank_width: size_t = 4) { +main reactor(bank_width: size_t(4)) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in diff --git a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf index 78d832a5ea..436a647f94 100644 --- a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf @@ -4,10 +4,10 @@ target Cpp { fast: true } -reactor Source(width: size_t = 1) { +reactor Source(width: size_t(1)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(size_t i = 0; i < out.size(); i++) { @@ -16,9 +16,9 @@ reactor Source(width: size_t = 1) { =} } -reactor Destination(width: size_t = 1) { - state s: int = 6 - state iterations: unsigned = 0 +reactor Destination(width: size_t(1)) { + state s: int(6) + state iterations: unsigned(0) input[width] in: int reaction(in) {= @@ -52,7 +52,7 @@ reactor Destination(width: size_t = 1) { =} } -main reactor(bank_width: size_t = 4) { +main reactor(bank_width: size_t(4)) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b.in after 200 msec diff --git a/test/Cpp/src/multiport/BankToMultiport.lf b/test/Cpp/src/multiport/BankToMultiport.lf index 6b1acf7591..d8132b2630 100644 --- a/test/Cpp/src/multiport/BankToMultiport.lf +++ b/test/Cpp/src/multiport/BankToMultiport.lf @@ -1,7 +1,7 @@ // Test bank of reactors to multiport input with id parameter in the bank. target Cpp -reactor Source(bank_index: size_t = 0) { +reactor Source(bank_index: size_t(0)) { output out: unsigned reaction(startup) -> out {= out.set(bank_index); =} @@ -9,7 +9,7 @@ reactor Source(bank_index: size_t = 0) { reactor Sink { input[4] in: unsigned - state received: bool = false + state received: bool(false) reaction(in) {= for (unsigned i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/Broadcast.lf b/test/Cpp/src/multiport/Broadcast.lf index 077ca75247..471bc92172 100644 --- a/test/Cpp/src/multiport/Broadcast.lf +++ b/test/Cpp/src/multiport/Broadcast.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= out.set(42); =} } -reactor Sink(bank_index: size_t = 0) { +reactor Sink(bank_index: size_t(0)) { input in: unsigned reaction(in) {= diff --git a/test/Cpp/src/multiport/BroadcastAfter.lf b/test/Cpp/src/multiport/BroadcastAfter.lf index 6cb7f84f4d..7f0ee66712 100644 --- a/test/Cpp/src/multiport/BroadcastAfter.lf +++ b/test/Cpp/src/multiport/BroadcastAfter.lf @@ -8,9 +8,9 @@ reactor Source { reaction(startup) -> out {= out.set(42); =} } -reactor Sink(bank_index: size_t = 0) { +reactor Sink(bank_index: size_t(0)) { input in: unsigned - state received: bool = false + state received: bool{false} reaction(in) {= std::cout << bank_index << " received " << *in.get() << '\n'; diff --git a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf index 065e9bf403..84051887ca 100644 --- a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf @@ -2,15 +2,15 @@ target Cpp { fast: true } -reactor Source(value: unsigned = 42) { +reactor Source(value: unsigned(42)) { output out: unsigned reaction(startup) -> out {= out.set(value); =} } -reactor Sink(bank_index: size_t = 0) { +reactor Sink(bank_index: size_t(0)) { input in: unsigned - state received: bool = false + state received: bool{false} reaction(in) {= std::cout << bank_index << " received " << *in.get() << '\n'; diff --git a/test/Cpp/src/multiport/FullyConnected.lf b/test/Cpp/src/multiport/FullyConnected.lf index 0b0a66405e..c925460402 100644 --- a/test/Cpp/src/multiport/FullyConnected.lf +++ b/test/Cpp/src/multiport/FullyConnected.lf @@ -1,10 +1,10 @@ target Cpp -reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { +reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { input[num_nodes] in: size_t output out: size_t - state received: bool = false + state received: bool{false} reaction(startup) -> out {= std::cout << "Hello from node " << bank_index << "!\n"; @@ -36,7 +36,7 @@ reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { =} } -main reactor(num_nodes: size_t = 4) { +main reactor(num_nodes: size_t(4)) { nodes = new[num_nodes] Node(num_nodes = num_nodes) (nodes.out)+ -> nodes.in } diff --git a/test/Cpp/src/multiport/FullyConnectedAddressable.lf b/test/Cpp/src/multiport/FullyConnectedAddressable.lf index 5385c44222..2a756c328f 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressable.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressable.lf @@ -1,11 +1,11 @@ // In this pattern, each node can send direct messages to individual other nodes target Cpp -reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { +reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { input[num_nodes] in: size_t output[num_nodes] out: size_t - state received: bool = false + state received: bool{false} reaction(startup) -> out {= std::cout << "Hello from node " << bank_index << "!\n"; @@ -41,7 +41,7 @@ reactor Node(bank_index: size_t = 0, num_nodes: size_t = 4) { =} } -main reactor(num_nodes: size_t = 4) { +main reactor(num_nodes: size_t(4)) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) diff --git a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf index c6fcb4c9e6..e331494b1b 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf @@ -3,7 +3,7 @@ target Cpp import Node from "FullyConnectedAddressable.lf" -main reactor(num_nodes: size_t = 4) { +main reactor(num_nodes: size_t(4)) { nodes1 = new[num_nodes] Node(num_nodes = num_nodes) nodes1.out -> interleaved (nodes1.in) after 200 msec diff --git a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf index 964e2e7095..bf00c15081 100644 --- a/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf +++ b/test/Cpp/src/multiport/IndexIntoMultiportOutput.lf @@ -8,7 +8,7 @@ */ target Cpp -reactor ReactorWithMultiport(width: size_t = 3) { +reactor ReactorWithMultiport(width: size_t(3)) { output[width] out: int reaction(startup) -> out {= @@ -18,7 +18,7 @@ reactor ReactorWithMultiport(width: size_t = 3) { =} } -reactor MultiportSplitter(width: size_t = 3) { +reactor MultiportSplitter(width: size_t(3)) { input[width] in: int output out0: int @@ -34,9 +34,9 @@ main reactor IndexIntoMultiportOutput { source.out -> splitter.in - state received0: bool = false - state received1: bool = false - state received2: bool = false + state received0: bool{false} + state received1: bool{false} + state received2: bool{false} reaction(splitter.out0) {= received0 = true; diff --git a/test/Cpp/src/multiport/Multiport.lf b/test/Cpp/src/multiport/Multiport.lf index a63924c67c..946282566f 100644 --- a/test/Cpp/src/multiport/Multiport.lf +++ b/test/Cpp/src/multiport/Multiport.lf @@ -21,7 +21,7 @@ reactor Test { main reactor Multiport { test = new Test() - state received: bool = false + state received: bool(false) reaction(startup) -> test.sink {= for (auto i = 0; i < 30; i++) { diff --git a/test/Cpp/src/multiport/MultiportFromBank.lf b/test/Cpp/src/multiport/MultiportFromBank.lf index b7339a9184..61d33e2a4c 100644 --- a/test/Cpp/src/multiport/MultiportFromBank.lf +++ b/test/Cpp/src/multiport/MultiportFromBank.lf @@ -5,15 +5,15 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t = 0) { +reactor Source(bank_index: size_t(0)) { output out: unsigned reaction(startup) -> out {= out.set(bank_index); =} } -reactor Destination(port_width: size_t = 2) { +reactor Destination(port_width: size_t(2)) { input[port_width] in: unsigned - state received: bool = false + state received: bool(false) reaction(in) {= for (size_t i = 0; i < in.size(); i++) { @@ -35,7 +35,7 @@ reactor Destination(port_width: size_t = 2) { =} } -main reactor(width: size_t = 4) { +main reactor(width: size_t(4)) { a = new[width] Source() b = new Destination(port_width = width) a.out -> b.in diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf index 673ef6889a..ec75a59be4 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf @@ -5,7 +5,7 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t = 0) { +reactor Source(bank_index: size_t(0)) { output out: unsigned reaction(startup) -> out {= out.set(bank_index); =} @@ -19,7 +19,7 @@ reactor Container { reactor Destination { input[3] in: unsigned - state received: bool = false + state received: bool(false) reaction(in) {= for (size_t i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf index fe27c74f35..fd0cb4c693 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -5,7 +5,7 @@ target Cpp { fast: true } -reactor Source(bank_index: size_t = 0) { +reactor Source(bank_index: size_t(0)) { output out: int reaction(startup) -> out {= out.set(bank_index); =} @@ -19,7 +19,7 @@ reactor Container { reactor Destination { input[3] in: int - state received: bool = false + state received: bool(false) reaction(in) {= for (int i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/MultiportFromHierarchy.lf b/test/Cpp/src/multiport/MultiportFromHierarchy.lf index fae914b609..c63285af13 100644 --- a/test/Cpp/src/multiport/MultiportFromHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromHierarchy.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output[4] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -18,7 +18,7 @@ reactor Source { } reactor Destination { - state s: int = 6 + state s: int(6) input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportIn.lf b/test/Cpp/src/multiport/MultiportIn.lf index 39fce6f8ff..31f06bd956 100644 --- a/test/Cpp/src/multiport/MultiportIn.lf +++ b/test/Cpp/src/multiport/MultiportIn.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= out.set(s++); =} } @@ -21,7 +21,7 @@ reactor Computation { } reactor Destination { - state s: int = 0 + state s: int(0) input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportOut.lf b/test/Cpp/src/multiport/MultiportOut.lf index 53f2a5bb23..b4d5e00425 100644 --- a/test/Cpp/src/multiport/MultiportOut.lf +++ b/test/Cpp/src/multiport/MultiportOut.lf @@ -7,7 +7,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output[4] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < 4; i++) { @@ -31,7 +31,7 @@ reactor Computation { } reactor Destination { - state s: int = 0 + state s: int(0) input[4] in: int reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToBank.lf b/test/Cpp/src/multiport/MultiportToBank.lf index fa2f79419f..898ccf7b97 100644 --- a/test/Cpp/src/multiport/MultiportToBank.lf +++ b/test/Cpp/src/multiport/MultiportToBank.lf @@ -10,7 +10,7 @@ reactor Source { =} } -reactor Sink(bank_index: size_t = 0) { +reactor Sink(bank_index: size_t(0)) { input in: unsigned reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToBankAfter.lf b/test/Cpp/src/multiport/MultiportToBankAfter.lf index c05730680f..546e569e24 100644 --- a/test/Cpp/src/multiport/MultiportToBankAfter.lf +++ b/test/Cpp/src/multiport/MultiportToBankAfter.lf @@ -10,7 +10,7 @@ reactor Source { =} } -reactor Sink(bank_index: size_t = 0) { +reactor Sink(bank_index: size_t(0)) { input in: unsigned reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf index f9cef6a676..11671f98bb 100644 --- a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf @@ -15,9 +15,9 @@ reactor Source { =} } -reactor Destination(bank_index: size_t = 0) { +reactor Destination(bank_index: size_t(0)) { input in: unsigned - state received: bool = false + state received: bool(false) reaction(in) {= std::cout << "Destination " << bank_index << " received " << *in.get() << ".\n"; diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index 573a0e06da..e0daa5a4c0 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -6,10 +6,10 @@ target Cpp { fast: true } -reactor Source(width: size_t = 4) { +reactor Source(width: size_t(4)) { timer t(0, 200 msec) output[width] out: int - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(size_t i = 0; i < 4; i++) { @@ -18,8 +18,8 @@ reactor Source(width: size_t = 4) { =} } -reactor Destination(width: size_t = 4) { - state s: int = 6 +reactor Destination(width: size_t(4)) { + state s: int(6) input[width] in: int reaction(in) {= @@ -45,13 +45,13 @@ reactor Destination(width: size_t = 4) { =} } -reactor Container(width: size_t = 4) { +reactor Container(width: size_t(4)) { input[width] in: int dst = new Destination() in -> dst.in } -main reactor MultiportToHierarchy(width: size_t = 4) { +main reactor MultiportToHierarchy(width: size_t(4)) { a = new Source(width = width) b = new Container(width = width) a.out -> b.in diff --git a/test/Cpp/src/multiport/MultiportToMultiport.lf b/test/Cpp/src/multiport/MultiportToMultiport.lf index 37a1ee5222..c7b673ea11 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport.lf @@ -12,7 +12,7 @@ reactor Source { reactor Sink { input[4] in: unsigned - state received: bool = false + state received: bool(false) reaction(in) {= for (unsigned i = 0; i < in.size(); i++) { diff --git a/test/Cpp/src/multiport/MultiportToMultiport2.lf b/test/Cpp/src/multiport/MultiportToMultiport2.lf index 165f3201ce..ac0151731f 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport2.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport2.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target Cpp -reactor Source(width: size_t = 2) { +reactor Source(width: size_t(2)) { output[width] out: size_t reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: size_t = 2) { =} } -reactor Destination(width: size_t = 2) { +reactor Destination(width: size_t(2)) { input[width] in: size_t reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToMultiport2After.lf b/test/Cpp/src/multiport/MultiportToMultiport2After.lf index 781275b2f4..b015bfe827 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport2After.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport2After.lf @@ -1,7 +1,7 @@ // Test multiport to multiport connections. See also MultiportToMultiport. target Cpp -reactor Source(width: size_t = 2) { +reactor Source(width: size_t(2)) { output[width] out: size_t reaction(startup) -> out {= @@ -11,7 +11,7 @@ reactor Source(width: size_t = 2) { =} } -reactor Destination(width: size_t = 2) { +reactor Destination(width: size_t(2)) { input[width] in: size_t reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToMultiportArray.lf b/test/Cpp/src/multiport/MultiportToMultiportArray.lf index 6c96d17150..077aab0f9d 100644 --- a/test/Cpp/src/multiport/MultiportToMultiportArray.lf +++ b/test/Cpp/src/multiport/MultiportToMultiportArray.lf @@ -8,7 +8,7 @@ target Cpp { reactor Source { timer t(0, 200 msec) output[2] out: int[3] - state s: int = 0 + state s: int(0) reaction(t) -> out {= for(int i = 0; i < 2; i++) { @@ -25,7 +25,7 @@ reactor Source { } reactor Destination { - state s: int = 15 + state s: int(15) input[2] in: int[3] reaction(in) {= diff --git a/test/Cpp/src/multiport/MultiportToPort.lf b/test/Cpp/src/multiport/MultiportToPort.lf index c2b0bd66ef..107198c9cc 100644 --- a/test/Cpp/src/multiport/MultiportToPort.lf +++ b/test/Cpp/src/multiport/MultiportToPort.lf @@ -16,9 +16,9 @@ reactor Source { =} } -reactor Destination(expected: int = 0) { +reactor Destination(expected: int(0)) { input in: int - state received: bool = false + state received: bool(false) reaction(in) {= std::cout << "Received: " << *in.get() << ".\n"; diff --git a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf index 6fa6dbb87b..c6bbcf1242 100644 --- a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf @@ -2,7 +2,7 @@ // multiport target Cpp -reactor Contained(bank_index: size_t = 0) { +reactor Contained(bank_index: size_t(0)) { output[3] out: unsigned reaction(startup) -> out {= @@ -14,7 +14,7 @@ reactor Contained(bank_index: size_t = 0) { main reactor { c = new[3] Contained() - state count: int = 0 + state count: int(0) reaction(startup) c.out {= for (size_t i = 0; i < c.size(); i++) { diff --git a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf index 18179b9086..81deaf91f2 100644 --- a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf @@ -2,7 +2,7 @@ // permutations. target Cpp -reactor Contained(bank_index: size_t = 0) { +reactor Contained(bank_index: size_t(0)) { output out: unsigned reaction(startup) -> out {= out.set(42 * bank_index); =} @@ -10,7 +10,7 @@ reactor Contained(bank_index: size_t = 0) { main reactor { c = new[4] Contained() - state count: int = 0 + state count: int(0) reaction(startup) c.out {= for (size_t i = 0; i < c.size(); i++) { diff --git a/test/Cpp/src/multiport/WidthGivenByCode.lf b/test/Cpp/src/multiport/WidthGivenByCode.lf index 10a2a59489..52c2f84b36 100644 --- a/test/Cpp/src/multiport/WidthGivenByCode.lf +++ b/test/Cpp/src/multiport/WidthGivenByCode.lf @@ -1,6 +1,6 @@ target Cpp -reactor Foo(a: size_t = 8, b: size_t = 2) { +reactor Foo(a: size_t{8}, b: size_t{2}) { input[{= a*b =}] in: size_t output[{= a/b =}] out: size_t diff --git a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf index b8f8d50958..3824664e35 100644 --- a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf @@ -1,9 +1,9 @@ // Test writing inputs to a contained reactor bank target Cpp -reactor Contained(bank_index: size_t = 0) { +reactor Contained(bank_index: size_t(0)) { input in: unsigned - state count: int = 0 + state count: int(0) reaction(in) {= unsigned result = *in.get(); diff --git a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf index 5ffe567dfb..49e0614842 100644 --- a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf @@ -1,9 +1,9 @@ // Test writing multiport inputs to a contained reactor bank target Cpp -reactor Contained(bank_index: size_t = 0) { +reactor Contained(bank_index: size_t(0)) { input[4] in: unsigned - state count: int = 0 + state count: int(0) reaction(in) {= for (size_t i = 0; i < 3; i++) { diff --git a/test/Cpp/src/properties/Fast.lf b/test/Cpp/src/properties/Fast.lf index 1d4ba25d2f..a12cbfaf01 100644 --- a/test/Cpp/src/properties/Fast.lf +++ b/test/Cpp/src/properties/Fast.lf @@ -5,7 +5,7 @@ target Cpp { main reactor { logical action a - state triggered: bool = false + state triggered: bool{false} reaction(startup) -> a {= a.schedule(2s); =} diff --git a/test/Cpp/src/properties/Keepalive.lf b/test/Cpp/src/properties/Keepalive.lf new file mode 100644 index 0000000000..1fe6c5e1bc --- /dev/null +++ b/test/Cpp/src/properties/Keepalive.lf @@ -0,0 +1,43 @@ +target Cpp { + keepalive: true, + cmake-include: "../concurrent/AsyncCallback.cmake" +} + +main reactor { + public preamble {= + #include + =} + + state thread: std::thread + + physical action a + state success: bool{false} + + reaction(startup) -> a {= + // start new thread + this->thread = std::thread([&] () { + // Simulate time passing before a callback occurs + std::this_thread::sleep_for(1s); + a.schedule(); + }); + =} + + reaction(a) {= + success = true; + environment()->sync_shutdown(); + =} + + reaction(shutdown) {= + if (success) { + std::cout << "SUCCESS!\n"; + } else { + std::cout << "ERROR: reaction was not invoked!\n"; + exit(1); + } + + // make sure to join the thread before shutting down + if(thread.joinable()) { + thread.join(); + } + =} +} diff --git a/test/Cpp/src/properties/Timeout.lf b/test/Cpp/src/properties/Timeout.lf index 57c55ad24c..50f647349f 100644 --- a/test/Cpp/src/properties/Timeout.lf +++ b/test/Cpp/src/properties/Timeout.lf @@ -5,7 +5,7 @@ target Cpp { main reactor { timer t(1 sec, 1 sec) - state triggered: bool = false + state triggered: bool{false} reaction(t) {= triggered = true; diff --git a/test/Cpp/src/properties/TimeoutZero.lf b/test/Cpp/src/properties/TimeoutZero.lf index 9d04fa8048..96409f692e 100644 --- a/test/Cpp/src/properties/TimeoutZero.lf +++ b/test/Cpp/src/properties/TimeoutZero.lf @@ -5,7 +5,7 @@ target Cpp { main reactor { timer t(0, 1 sec) - state triggered: bool = false + state triggered: bool{false} reaction(t) {= triggered = true; diff --git a/test/Cpp/src/target/AfterVoid.lf b/test/Cpp/src/target/AfterVoid.lf index 555e024e6b..0b9beadcff 100644 --- a/test/Cpp/src/target/AfterVoid.lf +++ b/test/Cpp/src/target/AfterVoid.lf @@ -12,8 +12,8 @@ reactor foo { } reactor print { - state expected_time: time = 10 msec - state i: int = 0 + state expected_time: time(10 msec) + state i: int(0) input x: void reaction(x) {= diff --git a/test/Cpp/src/target/BraceAndParenInitialization.lf b/test/Cpp/src/target/BraceAndParenInitialization.lf index 003b6d509d..8838187bc2 100644 --- a/test/Cpp/src/target/BraceAndParenInitialization.lf +++ b/test/Cpp/src/target/BraceAndParenInitialization.lf @@ -26,5 +26,8 @@ reactor Foo( } main reactor { - foo = new Foo(param_list_3 = {= std::vector(3, 5) =}, param_list_4 = {3, 5}) + foo = new Foo( + param_list_3 = {= std::vector(3, 5) =}, + param_list_4 = {= {3, 5} =} + ) } diff --git a/test/Cpp/src/target/CliParserGenericArguments.lf b/test/Cpp/src/target/CliParserGenericArguments.lf index 9a008ebcab..eb75ac2ef6 100644 --- a/test/Cpp/src/target/CliParserGenericArguments.lf +++ b/test/Cpp/src/target/CliParserGenericArguments.lf @@ -43,19 +43,19 @@ private preamble {= =} main reactor CliParserGenericArguments( - int_value: int = 10, - signed_value: signed = -10, - unsigned_value: unsigned = 11, - long_value: long = -100, - unsigned_long_value: {= unsigned_long =} = 42, - long_long_value: {= long_long =} = -42, - ull_value: {= uns_long_long =} = 42, - bool_value: bool = false, - char_value: char = 'T', - double_value: double = 4.2, - long_double_value: {= long_double =} = 4.2, - float_value: float = 10.5, - string_value: string = "This is a testvalue", + int_value: int(10), + signed_value: signed(-10), + unsigned_value: unsigned(11), + long_value: long(-100), + unsigned_long_value: {= unsigned_long =}(42), + long_long_value: {= long_long =}(-42), + ull_value: {= uns_long_long =}(42), + bool_value: bool(false), + char_value: char('T'), + double_value: double(4.2), + long_double_value: {= long_double =}(4.2), + float_value: float(10.5), + string_value: string("This is a testvalue"), custom_class_value: {= CustomClass =}("Peter") ) { reaction(startup) {= std::cout << "Hello World!\n"; =} diff --git a/test/Cpp/src/target/CombinedTypeNames.lf b/test/Cpp/src/target/CombinedTypeNames.lf index d55c70a823..28182b7bf7 100644 --- a/test/Cpp/src/target/CombinedTypeNames.lf +++ b/test/Cpp/src/target/CombinedTypeNames.lf @@ -3,11 +3,11 @@ target Cpp reactor Foo( - bar: {= unsigned int =} = 0, - baz: {= const unsigned int* =} = {= nullptr =} + bar: {= unsigned int =}(0), + baz: {= const unsigned int* =}({= nullptr =}) ) { - state s_bar: {= unsigned int =} = bar - state s_baz: {= const unsigned int* =} = baz + state s_bar: {= unsigned int =}(bar) + state s_baz: {= const unsigned int* =}(baz) reaction(startup) {= if (bar != 42 || s_bar != 42 || *baz != 42 || *s_baz != 42) { @@ -17,6 +17,6 @@ reactor Foo( =} } -main reactor(bar: {= unsigned int =} = 42) { +main reactor(bar: {= unsigned int =}(42)) { foo = new Foo(bar = bar, baz = {= &bar =}) } diff --git a/test/Cpp/src/target/GenericDelay.lf b/test/Cpp/src/target/GenericDelay.lf index 5efa81b011..135c04f417 100644 --- a/test/Cpp/src/target/GenericDelay.lf +++ b/test/Cpp/src/target/GenericDelay.lf @@ -2,7 +2,7 @@ target Cpp import Test from "../DelayInt.lf" -reactor Delay(delay: time = 0) { +reactor Delay(delay: time(0)) { output out: T input in: T logical action a(delay): T diff --git a/test/Cpp/src/target/GenericParameterAndState.lf b/test/Cpp/src/target/GenericParameterAndState.lf index 6803eb9509..d259bf3b22 100644 --- a/test/Cpp/src/target/GenericParameterAndState.lf +++ b/test/Cpp/src/target/GenericParameterAndState.lf @@ -1,7 +1,7 @@ target Cpp -reactor Foo(bar: T = 0, expected: T = 14542135) { - state baz: T = bar +reactor Foo(bar: T(0), expected: T(14542135)) { + state baz: T(bar) reaction(startup) {= if (bar != expected) { diff --git a/test/Cpp/src/target/InitializerSyntax.lf b/test/Cpp/src/target/InitializerSyntax.lf deleted file mode 100644 index 54ae268457..0000000000 --- a/test/Cpp/src/target/InitializerSyntax.lf +++ /dev/null @@ -1,89 +0,0 @@ -target Cpp - -public preamble {= - #include - struct TestType { - int x; - - // constructor #1 - TestType() : x(42) {} - // constructor #2 - TestType(int x) : x(x) {} - // constructor #3 - TestType(std::initializer_list l) : x(l.size()) {} - // constructor #4 - TestType(const TestType& t) : x(t.x + 10) { } - // constructor #5 - TestType(TestType&& t) : x(t.x + 20) { } - - TestType& operator=(const TestType& t) { - std::cout << "assign\n"; - this->x = t.x + 30; - return *this; - } - TestType& operator=(TestType&& t) { - this->x = t.x + 40; - return *this; - } - - ~TestType() = default; - }; -=} - -reactor TestReactor( - /** - * FIXME: should work without an explicit initialization, see - * https://github.com/lf-lang/lingua-franca/issues/623 - */ - // p_default: TestType, constructor #1 - p_default: TestType(), - p_empty: TestType(), // constructor #1 - p_value: TestType(24), // constructor #2 - p_init_empty: TestType{}, // constructor #1 - p_init_empty2: TestType({}), // constructor #1 - p_init_some: TestType{2, 6, 6, 3, 1}, // constructor #1 - p_assign_init_empty: TestType = {}, // constructor #1 - p_assign_init_some: TestType = {4, 2, 1} // constructor #3 -) { - state s_default: TestType // constructor #1 - state s_empty: TestType() // constructor #1 - state s_value: TestType(24) // constructor #2 - state s_init_empty: TestType{} // constructor #1 - state s_init_empty2: TestType({}) // constructor #3 - state s_init_some: TestType{3, 12, 40} // constructor #3 - state s_assign_init_empty: TestType = {} // constructor #3 - state s_assign_init_some: TestType = {4, 3, 2, 1} // constructor #3 - state s_copy1: TestType(p_default) // constructor #4 - state s_copy2: TestType{p_default} // constructor #4 - state s_copy3: TestType = p_default // constructor #4 - - reaction(startup) {= - reactor::validate(p_default.x == 62, "p_default should be default constructed and then moved"); - reactor::validate(p_empty.x == 62, "p_empty should be default constructed and then moved"); - reactor::validate(p_value.x == 44, "p_value should be constructed from 24 and then moved"); - reactor::validate(p_init_empty.x == 62, "p_init_empty should be default constructed and then moved"); - reactor::validate(p_init_empty2.x == 20, "p_init_empty2 should be constructed with 0 and then moved"); - reactor::validate(p_init_some.x == 25, "p_init_some should be constructed with 3 and then moved"); - reactor::validate(p_assign_init_empty.x == 62, "p_assign_init_empty should be default constructed and then moved"); - reactor::validate(p_assign_init_some.x == 23, "p_assign_init_some should be constructed with 4 and then moved"); - - reactor::validate(s_default.x == 42, "s_default should be default constructed"); - reactor::validate(s_empty.x == 42, "s_empty should be default constructed"); - reactor::validate(s_value.x == 24, "s_value should be constructed with 24"); - reactor::validate(s_init_empty.x == 42, "s_init_empty should be default constructed"); - reactor::validate(s_init_empty2.x == 0, "s_init_empty2 should be constructed with 0"); - reactor::validate(s_init_some.x == 3, "s_init_some should be constructed with 3"); - // NOTE: This is a strange corner case. Since the equal assignment will be translated to a () initializers (e.g. :foo(42)), - // the initialization here in LF behaves differently from what one might expect. When writing `Foo foo = {}`, - // the default constructor would be called instead of the initializer list constructor. - reactor::validate(s_assign_init_empty.x == 0, "s_assign_init_empty should be constructed with 0"); - reactor::validate(s_assign_init_some.x == 4, "s_assign_init_some should be constructed with 4"); - reactor::validate(s_copy1.x == 72, "s_copy1 should be copy constructed from p_default"); - reactor::validate(s_copy2.x == 72, "s_copy1 should be copy constructed from p_default"); - reactor::validate(s_copy3.x == 72, "s_copy1 should be copy constructed from p_default"); - =} -} - -main reactor { - test = new TestReactor() -} diff --git a/test/Cpp/src/target/PointerParameters.lf b/test/Cpp/src/target/PointerParameters.lf index a769f20da3..cb8675d014 100644 --- a/test/Cpp/src/target/PointerParameters.lf +++ b/test/Cpp/src/target/PointerParameters.lf @@ -2,7 +2,7 @@ // Compilation without errors is success. target Cpp -reactor Foo(ptr: int* = {= nullptr =}) { +reactor Foo(ptr: int*{{= nullptr =}}) { reaction(startup) {= if (ptr == nullptr || *ptr != 42) { reactor::log::Error() << "received an unexpected value!"; diff --git a/test/Python/src/ActionDelay.lf b/test/Python/src/ActionDelay.lf index 60efa42f57..7c325bb2cb 100644 --- a/test/Python/src/ActionDelay.lf +++ b/test/Python/src/ActionDelay.lf @@ -4,7 +4,7 @@ target Python reactor GeneratedDelay { input y_in output y_out - state y_state = 0 + state y_state(0) logical action act(100 msec) reaction(y_in) -> act {= diff --git a/test/Python/src/ActionIsPresent.lf b/test/Python/src/ActionIsPresent.lf index ceb52d10b8..259417110e 100644 --- a/test/Python/src/ActionIsPresent.lf +++ b/test/Python/src/ActionIsPresent.lf @@ -1,10 +1,10 @@ # Tests the is_present variable for actions. target Python -main reactor ActionIsPresent(offset = 1 nsec, period = 500 msec) { +main reactor ActionIsPresent(offset(1 nsec), period(500 msec)) { logical action a - state first_time = True - state success = False + state first_time(True) + state success(False) reaction(startup, a) -> a {= # The is_present field should be initially False diff --git a/test/Python/src/After.lf b/test/Python/src/After.lf index 0c8b931543..13b1970d5a 100644 --- a/test/Python/src/After.lf +++ b/test/Python/src/After.lf @@ -13,8 +13,8 @@ reactor foo { } reactor print { - state expected_time = 10 msec - state received = 0 + state expected_time(10 msec) + state received(0) input x reaction(x) {= diff --git a/test/Python/src/AfterCycles.lf b/test/Python/src/AfterCycles.lf index cd0f0dd98e..ef1500af27 100644 --- a/test/Python/src/AfterCycles.lf +++ b/test/Python/src/AfterCycles.lf @@ -16,7 +16,7 @@ reactor Work { } main reactor AfterCycles { - state count = 0 + state count(0) s = new Source() w0 = new Work() w1 = new Work() diff --git a/test/Python/src/AfterOverlapped.lf b/test/Python/src/AfterOverlapped.lf index 32657f1cdb..2876538189 100644 --- a/test/Python/src/AfterOverlapped.lf +++ b/test/Python/src/AfterOverlapped.lf @@ -8,8 +8,8 @@ import Count from "lib/Count.lf" reactor Test { input c - state i = 0 - state received = 0 + state i(0) + state received(0) reaction(c) {= self.received += 1 diff --git a/test/Python/src/ArrayAsParameter.lf b/test/Python/src/ArrayAsParameter.lf index 359e38b7a3..67af462358 100644 --- a/test/Python/src/ArrayAsParameter.lf +++ b/test/Python/src/ArrayAsParameter.lf @@ -3,7 +3,7 @@ target Python reactor Source(sequence(0, 1, 2)) { output out - state count = 0 + state count(0) logical action next reaction(startup, next) -> out, next {= @@ -16,8 +16,8 @@ reactor Source(sequence(0, 1, 2)) { reactor Print { input _in - state count = 1 - state received = 0 + state count(1) + state received(0) reaction(_in) {= self.received+=1 @@ -36,7 +36,7 @@ reactor Print { } main reactor ArrayAsParameter { - s = new Source(sequence(1, 2, 3, 4)) + s = new Source(sequence = (1, 2, 3, 4)) p = new Print() s.out -> p._in } diff --git a/test/Python/src/ArrayAsType.lf b/test/Python/src/ArrayAsType.lf index dc3b2f6e26..2025cecbd1 100644 --- a/test/Python/src/ArrayAsType.lf +++ b/test/Python/src/ArrayAsType.lf @@ -11,7 +11,7 @@ reactor Source { =} } -reactor Print(scale = 1) { # The scale parameter is just for testing. +reactor Print(scale(1)) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/ArrayFree.lf b/test/Python/src/ArrayFree.lf index 2ea2777c12..893fbc4358 100644 --- a/test/Python/src/ArrayFree.lf +++ b/test/Python/src/ArrayFree.lf @@ -7,7 +7,7 @@ target Python import Source, Print from "ArrayPrint.lf" import Scale from "ArrayScale.lf" -reactor Free(scale = 2) { +reactor Free(scale(2)) { mutable input _in reaction(_in) {= diff --git a/test/Python/src/ArrayPrint.lf b/test/Python/src/ArrayPrint.lf index 4420311b93..039debac0c 100644 --- a/test/Python/src/ArrayPrint.lf +++ b/test/Python/src/ArrayPrint.lf @@ -11,7 +11,7 @@ reactor Source { =} } -reactor Print(scale = 1) { # The scale parameter is just for testing. +reactor Print(scale(1)) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/ArrayScale.lf b/test/Python/src/ArrayScale.lf index 2b69aebe77..620b63e10f 100644 --- a/test/Python/src/ArrayScale.lf +++ b/test/Python/src/ArrayScale.lf @@ -6,7 +6,7 @@ target Python import Print, Source from "ArrayPrint.lf" -reactor Scale(scale = 2) { +reactor Scale(scale(2)) { mutable input _in output out diff --git a/test/Python/src/Composition.lf b/test/Python/src/Composition.lf index d1bef93ed2..3a737295bf 100644 --- a/test/Python/src/Composition.lf +++ b/test/Python/src/Composition.lf @@ -5,10 +5,10 @@ target Python { timeout: 10 sec } -reactor Source(period = 2 sec) { +reactor Source(period(2 sec)) { output y timer t(1 sec, period) - state count = 0 + state count(0) reaction(t) -> y {= self.count += 1 @@ -20,7 +20,7 @@ reactor Source(period = 2 sec) { reactor Test { input x - state count = 0 + state count(0) reaction(x) {= self.count += 1 diff --git a/test/Python/src/CompositionAfter.lf b/test/Python/src/CompositionAfter.lf index 00b95e3ab9..f21b7ae75e 100644 --- a/test/Python/src/CompositionAfter.lf +++ b/test/Python/src/CompositionAfter.lf @@ -5,10 +5,10 @@ target Python { timeout: 10 sec } -reactor Source(period = 2 sec) { +reactor Source(period(2 sec)) { output y timer t(1 sec, period) - state count = 0 + state count(0) reaction(t) -> y {= self.count += 1 @@ -18,7 +18,7 @@ reactor Source(period = 2 sec) { reactor Test { input x - state count = 0 + state count(0) reaction(x) {= self.count += 1 @@ -29,7 +29,7 @@ reactor Test { =} } -main reactor(delay = 5 sec) { +main reactor(delay(5 sec)) { s = new Source() d = new Test() s.y -> d.x after delay diff --git a/test/Python/src/CompositionInheritance.lf b/test/Python/src/CompositionInheritance.lf index 4b0e4a38c9..deac45b05a 100644 --- a/test/Python/src/CompositionInheritance.lf +++ b/test/Python/src/CompositionInheritance.lf @@ -5,11 +5,11 @@ target Python { timeout: 10 sec } -reactor Source(period = 2 sec) { +reactor Source(period(2 sec)) { input foo output y timer t(1 sec, period) - state count = 0 + state count(0) reaction(t) -> y {= print("Hello World. My count is: ", self.count) @@ -30,7 +30,7 @@ reactor SourceExtended extends Source { reactor Test { input x - state count = 0 + state count(0) reaction(x) {= self.count += 1 diff --git a/test/Python/src/CountSelf.lf b/test/Python/src/CountSelf.lf index 74219e6fe0..40f4778c71 100644 --- a/test/Python/src/CountSelf.lf +++ b/test/Python/src/CountSelf.lf @@ -4,7 +4,7 @@ target Python { fast: true } -reactor CountSelf2(delay = 100 msec) { +reactor CountSelf2(delay(100 msec)) { output out logical action a @@ -21,7 +21,7 @@ reactor CountSelf2(delay = 100 msec) { reactor Test { input _in - state count = 0 + state count(0) reaction(_in) {= print("Received: {:d}".format(_in.value)) diff --git a/test/Python/src/CountTest.lf b/test/Python/src/CountTest.lf index 06c4a6fdb6..2761d22a5b 100644 --- a/test/Python/src/CountTest.lf +++ b/test/Python/src/CountTest.lf @@ -7,7 +7,7 @@ import Count from "lib/Count.lf" reactor Test { input c - state i = 0 + state i(0) reaction(c) {= print("Received ", c.value) diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index ceab2b28e2..aeed5f0d5e 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -7,10 +7,10 @@ target Python { preamble {= import time =} -reactor Source(period = 3 sec) { +reactor Source(period(3 sec)) { output y timer t(0, period) - state count = 0 + state count(0) reaction(t) -> y {= if self.count % 2 != 0: @@ -24,9 +24,9 @@ reactor Source(period = 3 sec) { =} } -reactor Destination(timeout = 1 sec) { +reactor Destination(timeout(1 sec)) { input x - state count = 0 + state count(0) reaction(x) {= print("Destination receives: ", x.value) diff --git a/test/Python/src/DeadlineHandledAbove.lf b/test/Python/src/DeadlineHandledAbove.lf index 1259253cea..d3df675152 100644 --- a/test/Python/src/DeadlineHandledAbove.lf +++ b/test/Python/src/DeadlineHandledAbove.lf @@ -4,7 +4,7 @@ target Python preamble {= import time =} -reactor Deadline(threshold = 100 msec) { +reactor Deadline(threshold(100 msec)) { input x output deadline_violation @@ -18,7 +18,7 @@ reactor Deadline(threshold = 100 msec) { } main reactor DeadlineHandledAbove { - state violation_detected = False + state violation_detected(false) d = new Deadline(threshold = 10 msec) reaction(startup) -> d.x {= diff --git a/test/Python/src/DelayArray.lf b/test/Python/src/DelayArray.lf index 945b786cca..abcf367d45 100644 --- a/test/Python/src/DelayArray.lf +++ b/test/Python/src/DelayArray.lf @@ -1,7 +1,7 @@ # This tests delaying an array type. target Python -reactor DelayPointer(delay = 100 msec) { +reactor DelayPointer(delay(100 msec)) { # The Python target does not require explicit type allocation for types # other than time mutable input _in @@ -25,7 +25,7 @@ reactor Source { =} } -reactor Print(scale = 1) { # The scale parameter is just for testing. +reactor Print(scale(1)) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/DelayArrayWithAfter.lf b/test/Python/src/DelayArrayWithAfter.lf index 1e6ac1f317..e244690ec8 100644 --- a/test/Python/src/DelayArrayWithAfter.lf +++ b/test/Python/src/DelayArrayWithAfter.lf @@ -7,7 +7,7 @@ target Python { reactor Source { output out - state iteration = 1 + state iteration(1) timer t(0, 1 sec) reaction(t) -> out {= @@ -18,10 +18,10 @@ reactor Source { =} } -reactor Print(scale = 1) { # The scale parameter is just for testing. +reactor Print(scale(1)) { # The scale parameter is just for testing. input _in - state iteration = 1 - state inputs_received = 0 + state iteration(1) + state inputs_received(0) reaction(_in) {= self.inputs_received += 1 diff --git a/test/Python/src/DelayInt.lf b/test/Python/src/DelayInt.lf index fae554bd30..d12c8b968b 100644 --- a/test/Python/src/DelayInt.lf +++ b/test/Python/src/DelayInt.lf @@ -1,7 +1,7 @@ # This tests actions with payloads by delaying an input by a fixed amount. target Python -reactor Delay(delay = 100 msec) { +reactor Delay(delay(100 msec)) { input _in output out logical action a @@ -16,8 +16,8 @@ reactor Delay(delay = 100 msec) { reactor Test { input _in - state start_time = 0 - state received_value = False + state start_time(0) + state received_value(false) reaction(startup) {= # Record the logical time at the start. diff --git a/test/Python/src/DelayString.lf b/test/Python/src/DelayString.lf index d1201dec02..f315b0bec2 100644 --- a/test/Python/src/DelayString.lf +++ b/test/Python/src/DelayString.lf @@ -2,7 +2,7 @@ # freed. target Python -reactor DelayString2(delay = 100 msec) { +reactor DelayString2(delay(100 msec)) { input _in output out logical action a @@ -14,7 +14,7 @@ reactor DelayString2(delay = 100 msec) { reactor Test { input _in - state start_time = 0 + state start_time(0) reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/DelayStruct.lf b/test/Python/src/DelayStruct.lf index e578a42699..f16aedfe7c 100644 --- a/test/Python/src/DelayStruct.lf +++ b/test/Python/src/DelayStruct.lf @@ -5,7 +5,7 @@ target Python { preamble {= import hello =} -reactor DelayPointer(delay = 100 msec) { +reactor DelayPointer(delay(100 msec)) { input _in output out logical action a @@ -25,7 +25,7 @@ reactor Source { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor Print(expected = 42) { # expected parameter is for testing. +reactor Print(expected(42)) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/DelayStructWithAfter.lf b/test/Python/src/DelayStructWithAfter.lf index 5bb945cb3c..21dafab29e 100644 --- a/test/Python/src/DelayStructWithAfter.lf +++ b/test/Python/src/DelayStructWithAfter.lf @@ -11,7 +11,7 @@ reactor Source { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor Print(expected = 42) { # expected parameter is for testing. +reactor Print(expected(42)) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/DelayStructWithAfterOverlapped.lf b/test/Python/src/DelayStructWithAfterOverlapped.lf index 072012a106..f19c5cd1bd 100644 --- a/test/Python/src/DelayStructWithAfterOverlapped.lf +++ b/test/Python/src/DelayStructWithAfterOverlapped.lf @@ -10,7 +10,7 @@ preamble {= import hello =} reactor Source { output out timer t(0, 1 sec) - state s = 0 + state s(0) reaction(t) -> out {= self.s += 1 @@ -20,7 +20,7 @@ reactor Source { reactor Print { # expected parameter is for testing. input _in - state s = 0 + state s(0) reaction(_in) {= self.s += 1 diff --git a/test/Python/src/DelayedAction.lf b/test/Python/src/DelayedAction.lf index 06c488b9c5..3f6fb70608 100644 --- a/test/Python/src/DelayedAction.lf +++ b/test/Python/src/DelayedAction.lf @@ -6,7 +6,7 @@ target Python { main reactor DelayedAction { timer t(0, 1 sec) logical action a - state count = 0 + state count(0) reaction(t) -> a {= a.schedule(MSEC(100)) =} diff --git a/test/Python/src/DoubleInvocation.lf b/test/Python/src/DoubleInvocation.lf index aaecfa31cb..d14edd6332 100644 --- a/test/Python/src/DoubleInvocation.lf +++ b/test/Python/src/DoubleInvocation.lf @@ -13,7 +13,7 @@ target Python { reactor Ball { output position output velocity - state p = 200 + state p(200) timer trigger(0, 1 sec) reaction(trigger) -> position, velocity {= @@ -26,7 +26,7 @@ reactor Ball { reactor Print { input velocity input position - state previous = -1 + state previous(-1) reaction(startup) {= print("####### Print startup\n") diff --git a/test/Python/src/DoubleReaction.lf b/test/Python/src/DoubleReaction.lf index c20a032a9a..2061ab5a1c 100644 --- a/test/Python/src/DoubleReaction.lf +++ b/test/Python/src/DoubleReaction.lf @@ -5,10 +5,10 @@ target Python { fast: true } -reactor Clock(offset = 0, period = 1 sec) { +reactor Clock(offset(0), period(1 sec)) { output y timer t(offset, period) - state count = 0 + state count(0) reaction(t) -> y {= self.count += 1 @@ -19,7 +19,7 @@ reactor Clock(offset = 0, period = 1 sec) { reactor Destination { input x input w - state s = 2 + state s(2) reaction(x, w) {= sm = 0 diff --git a/test/Python/src/FloatLiteral.lf b/test/Python/src/FloatLiteral.lf index b55953d135..5ed6202429 100644 --- a/test/Python/src/FloatLiteral.lf +++ b/test/Python/src/FloatLiteral.lf @@ -2,10 +2,10 @@ target Python # This test verifies that floating-point literals are handled correctly. main reactor { - state N = 6.0221409e+23 - state charge = -1.6021766E-19 - state minus_epsilon = -.01e0 - state expected = .964853323188E5 + state N(6.0221409e+23) + state charge(-1.6021766E-19) + state minus_epsilon(-.01e0) + state expected(.964853323188E5) reaction(startup) {= F = - self.N * self.charge diff --git a/test/Python/src/Gain.lf b/test/Python/src/Gain.lf index d69d4d2a65..38459a9380 100644 --- a/test/Python/src/Gain.lf +++ b/test/Python/src/Gain.lf @@ -1,7 +1,7 @@ # Example in the Wiki. target Python -reactor Scale(scale = 2) { +reactor Scale(scale(2)) { input x output y @@ -10,7 +10,7 @@ reactor Scale(scale = 2) { reactor Test { input x - state received_value = 0 + state received_value(0) reaction(x) {= print("Received " + str(x.value)) diff --git a/test/Python/src/GetMicroStep.lf b/test/Python/src/GetMicroStep.lf index 124c692ef8..7b1da9bb40 100644 --- a/test/Python/src/GetMicroStep.lf +++ b/test/Python/src/GetMicroStep.lf @@ -5,7 +5,7 @@ target Python { main reactor GetMicroStep { preamble {= import sys =} - state s = 1 + state s(1) logical action l # timer t(0, 1 msec); diff --git a/test/Python/src/Hello.lf b/test/Python/src/Hello.lf index 271ed180ca..0da0d53f47 100644 --- a/test/Python/src/Hello.lf +++ b/test/Python/src/Hello.lf @@ -8,9 +8,9 @@ target Python { fast: true } -reactor Reschedule(period = 2 sec, message = "Hello Python") { - state count = 0 - state previous_time = 0 +reactor Reschedule(period(2 sec), message("Hello Python")) { + state count(0) + state previous_time(0) timer t(1 sec, period) logical action a @@ -38,7 +38,7 @@ reactor Reschedule(period = 2 sec, message = "Hello Python") { =} } -reactor Inside(period = 1 sec, message = "Composite default message.") { +reactor Inside(period(1 sec), message("Composite default message.")) { third_instance = new Reschedule(period = period, message = message) } diff --git a/test/Python/src/HelloWorld.lf b/test/Python/src/HelloWorld.lf index 523ff9ce2b..725a73d0ac 100644 --- a/test/Python/src/HelloWorld.lf +++ b/test/Python/src/HelloWorld.lf @@ -3,7 +3,7 @@ target Python { } reactor HelloWorld2 { - state success = False + state success(False) reaction(startup) {= print("Hello World.") diff --git a/test/Python/src/Hierarchy2.lf b/test/Python/src/Hierarchy2.lf index a1792712fa..07e67a765b 100644 --- a/test/Python/src/Hierarchy2.lf +++ b/test/Python/src/Hierarchy2.lf @@ -14,7 +14,7 @@ reactor Source { reactor Count { output out timer t(0, 1 sec) - state i = 0 + state i(0) reaction(t) -> out {= self.i += 1 @@ -39,7 +39,7 @@ reactor Add { reactor Print { input _in - state expected = 2 + state expected(2) reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/IdentifierLength.lf b/test/Python/src/IdentifierLength.lf index 62b31141a0..66edf11abf 100644 --- a/test/Python/src/IdentifierLength.lf +++ b/test/Python/src/IdentifierLength.lf @@ -6,11 +6,11 @@ target Python { } reactor A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_The_Maximum_For_The_Python_Target( - period = 2 sec + period(2 sec) ) { output y timer t(1 sec, period) - state count = 0 + state count(0) reaction(t) -> y {= self.count += 1 @@ -20,7 +20,7 @@ reactor A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_Th reactor Another_Really_Long_Name_For_A_Test_Class { input x - state count = 0 + state count(0) reaction(x) {= self.count += 1 diff --git a/test/Python/src/ImportComposition.lf b/test/Python/src/ImportComposition.lf index 369fbcab44..4e57dc6423 100644 --- a/test/Python/src/ImportComposition.lf +++ b/test/Python/src/ImportComposition.lf @@ -6,7 +6,7 @@ import ImportedComposition from "lib/ImportedComposition.lf" main reactor ImportComposition { a = new ImportedComposition() - state received = False + state received(false) reaction(startup) -> a.x {= a.x.set(42) =} diff --git a/test/Python/src/ManualDelayedReaction.lf b/test/Python/src/ManualDelayedReaction.lf index a9e39829eb..0d142405cd 100644 --- a/test/Python/src/ManualDelayedReaction.lf +++ b/test/Python/src/ManualDelayedReaction.lf @@ -9,7 +9,7 @@ target Python { reactor GeneratedDelay { input y_in output y_out - state y_state = 0 + state y_state(0) physical action act(0 msec) # TODO: delay in act or the schedule call? diff --git a/test/Python/src/Methods.lf b/test/Python/src/Methods.lf index 5e0023fe8f..cc29079dad 100644 --- a/test/Python/src/Methods.lf +++ b/test/Python/src/Methods.lf @@ -2,7 +2,7 @@ target Python main reactor { - state foo = 2 + state foo(2) method getFoo() {= return self.foo =} diff --git a/test/Python/src/MethodsRecursive.lf b/test/Python/src/MethodsRecursive.lf index 81afc86bea..ca3ea237e7 100644 --- a/test/Python/src/MethodsRecursive.lf +++ b/test/Python/src/MethodsRecursive.lf @@ -2,7 +2,7 @@ target Python main reactor { - state foo = 2 + state foo(2) method fib(n) {= # Return the n-th Fibonacci number. if n <= 1: diff --git a/test/Python/src/MethodsSameName.lf b/test/Python/src/MethodsSameName.lf index a80f521356..c4d6cdbc4c 100644 --- a/test/Python/src/MethodsSameName.lf +++ b/test/Python/src/MethodsSameName.lf @@ -2,7 +2,7 @@ target Python reactor Foo { - state foo = 2 + state foo(2) method add(x) {= self.foo += x =} @@ -16,7 +16,7 @@ reactor Foo { } main reactor { - state foo = 2 + state foo(2) a = new Foo() diff --git a/test/Python/src/MovingAverage.lf b/test/Python/src/MovingAverage.lf index 3dbd5636c3..505b6a043d 100644 --- a/test/Python/src/MovingAverage.lf +++ b/test/Python/src/MovingAverage.lf @@ -10,7 +10,7 @@ import TestDouble from "lib/Test.lf" reactor MASource { output out - state count = 0 + state count(0) timer clock(0, 200 msec) reaction(clock) -> out {= @@ -21,7 +21,7 @@ reactor MASource { reactor MovingAverageImpl { state delay_line(0.0, 0.0, 0.0) - state index = 0 + state index(0) input m_in output out @@ -45,7 +45,7 @@ reactor MovingAverageImpl { main reactor MovingAverage { s = new MASource() m = new MovingAverageImpl() - p = new TestDouble(expected(0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) + p = new TestDouble(expected = (0.0, 0.25, 0.75, 1.5, 2.5, 3.5)) s.out -> m.m_in m.out -> p.t_in } diff --git a/test/Python/src/MultipleContained.lf b/test/Python/src/MultipleContained.lf index 27950ccd88..0b055951c5 100644 --- a/test/Python/src/MultipleContained.lf +++ b/test/Python/src/MultipleContained.lf @@ -4,7 +4,7 @@ target Python reactor Contained { output trigger - state count = 0 + state count(0) input in1 input in2 diff --git a/test/Python/src/NativeListsAndTimes.lf b/test/Python/src/NativeListsAndTimes.lf index b7b52b3d0a..f8b60ed87d 100644 --- a/test/Python/src/NativeListsAndTimes.lf +++ b/test/Python/src/NativeListsAndTimes.lf @@ -2,22 +2,22 @@ target Python # This test passes if it is successfully compiled into valid target code. main reactor( - x = 0, - y = 0, # Units are missing but not required - z = 1 msec, # Type is missing but not required + x(0), + y(0), # Units are missing but not required + z(1 msec), # Type is missing but not required p(1, 2, 3, 4), # List of integers q(1 msec, 2 msec, 3 msec), # list of time values g(1 msec, 2 msec) # List of time values ) { - state s = y # Reference to explicitly typed time parameter - state t = z # Reference to implicitly typed time parameter + state s(y) # Reference to explicitly typed time parameter + state t(z) # Reference to implicitly typed time parameter state v # Uninitialized boolean state variable state w # Uninitialized time state variable timer tick(0) # Units missing but not required timer tock(1 sec) # Implicit type time timer toe(z) # Implicit type time - state baz = p # Implicit type int[] - state period = z # Implicit type time + state baz(p) # Implicit type int[] + state period(z) # Implicit type time state bar(1 msec, 2 msec, 3 msec) # list of time values state notype(1, 2, 3, 4) diff --git a/test/Python/src/ParameterizedState.lf b/test/Python/src/ParameterizedState.lf index e8805b027f..3511c8d2f5 100644 --- a/test/Python/src/ParameterizedState.lf +++ b/test/Python/src/ParameterizedState.lf @@ -1,7 +1,7 @@ target Python -reactor Foo(bar = 42) { - state baz = bar +reactor Foo(bar(42)) { + state baz(bar) reaction(startup) {= print("Baz: ", self.baz) =} } diff --git a/test/Python/src/PeriodicDesugared.lf b/test/Python/src/PeriodicDesugared.lf index b003ffc9f8..5dc7f7bb8f 100644 --- a/test/Python/src/PeriodicDesugared.lf +++ b/test/Python/src/PeriodicDesugared.lf @@ -3,7 +3,7 @@ target Python { timeout: 1 sec } -main reactor(offset = 0, period = 500 msec) { +main reactor(offset(0), period(500 msec)) { logical action init(offset) logical action recur(period) diff --git a/test/Python/src/PingPong.lf b/test/Python/src/PingPong.lf index f5f80511ae..25ffdea3a8 100644 --- a/test/Python/src/PingPong.lf +++ b/test/Python/src/PingPong.lf @@ -24,10 +24,10 @@ target Python { fast: true } -reactor Ping(count = 10) { +reactor Ping(count(10)) { input receive output send - state pingsLeft = count + state pingsLeft(count) logical action serve reaction(startup, serve) -> send {= @@ -43,10 +43,10 @@ reactor Ping(count = 10) { =} } -reactor Pong(expected = 10) { +reactor Pong(expected(10)) { input receive output send - state count = 0 + state count(0) reaction(receive) -> send {= self.count += 1 diff --git a/test/Python/src/Pipeline.lf b/test/Python/src/Pipeline.lf index 18436561b8..014680e3ca 100644 --- a/test/Python/src/Pipeline.lf +++ b/test/Python/src/Pipeline.lf @@ -17,8 +17,8 @@ reactor TakeTime { reactor Print { input _in - state count = 0 - state received = 0 + state count(0) + state received(0) reaction(_in) {= self.received += 1 @@ -38,7 +38,7 @@ reactor Print { main reactor Pipeline { timer t(0, 200 msec) - state count = 0 + state count(0) c1 = new TakeTime() c2 = new TakeTime() diff --git a/test/Python/src/ReadOutputOfContainedReactor.lf b/test/Python/src/ReadOutputOfContainedReactor.lf index 1cb73667ce..25c8a1a368 100644 --- a/test/Python/src/ReadOutputOfContainedReactor.lf +++ b/test/Python/src/ReadOutputOfContainedReactor.lf @@ -10,7 +10,7 @@ reactor Contained { main reactor ReadOutputOfContainedReactor { c = new Contained() - state count = 0 + state count(0) reaction(startup) c.out {= print("Startup reaction reading output of contained reactor: ", c.out.value) diff --git a/test/Python/src/ScheduleLogicalAction.lf b/test/Python/src/ScheduleLogicalAction.lf index 3f99c65777..10f8d4e3cd 100644 --- a/test/Python/src/ScheduleLogicalAction.lf +++ b/test/Python/src/ScheduleLogicalAction.lf @@ -20,7 +20,7 @@ reactor foo { } reactor print { - state expected_time = 0 + state expected_time(0) input x reaction(x) {= diff --git a/test/Python/src/SelfLoop.lf b/test/Python/src/SelfLoop.lf index 2b607b09c8..1653b893e3 100644 --- a/test/Python/src/SelfLoop.lf +++ b/test/Python/src/SelfLoop.lf @@ -7,7 +7,7 @@ reactor Self { input x output y logical action a - state expected = 43 + state expected(43) reaction(a) -> y {= print("a = ", a.value) diff --git a/test/Python/src/SendingInside.lf b/test/Python/src/SendingInside.lf index 8bcc66c005..08d05b8ed9 100644 --- a/test/Python/src/SendingInside.lf +++ b/test/Python/src/SendingInside.lf @@ -7,7 +7,7 @@ target Python { reactor Printer { input x - state count = 1 + state count(1) reaction(x) {= print("Inside reactor received: ", x.value) @@ -19,7 +19,7 @@ reactor Printer { } main reactor SendingInside { - state count = 0 + state count(0) timer t(0, 1 sec) p = new Printer() diff --git a/test/Python/src/SetArray.lf b/test/Python/src/SetArray.lf index 4766d529f7..356899ae8f 100644 --- a/test/Python/src/SetArray.lf +++ b/test/Python/src/SetArray.lf @@ -9,7 +9,7 @@ reactor Source { reaction(startup) -> out {= out.set([0,1,2]) =} } -reactor Print(scale = 1) { # The scale parameter is just for testing. +reactor Print(scale(1)) { # The scale parameter is just for testing. input _in reaction(_in) {= diff --git a/test/Python/src/SimpleDeadline.lf b/test/Python/src/SimpleDeadline.lf index a714124129..0385f95f74 100644 --- a/test/Python/src/SimpleDeadline.lf +++ b/test/Python/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ # violation. target Python -reactor Deadline(threshold = 100 msec) { +reactor Deadline(threshold(100 msec)) { input x output deadlineViolation diff --git a/test/Python/src/SlowingClock.lf b/test/Python/src/SlowingClock.lf index 972421437a..b566781677 100644 --- a/test/Python/src/SlowingClock.lf +++ b/test/Python/src/SlowingClock.lf @@ -10,8 +10,8 @@ target Python { main reactor SlowingClock { logical action a(100 msec) - state interval = 100 msec - state expected_time = 100 msec + state interval(100 msec) + state expected_time(100 msec) reaction(startup) -> a {= a.schedule(0) =} diff --git a/test/Python/src/SlowingClockPhysical.lf b/test/Python/src/SlowingClockPhysical.lf index dbb9da705f..b2533acf12 100644 --- a/test/Python/src/SlowingClockPhysical.lf +++ b/test/Python/src/SlowingClockPhysical.lf @@ -15,8 +15,8 @@ target Python { main reactor SlowingClockPhysical { # first offset and minimum interarrival time. physical action a(100 msec, 100 msec) - state interval = 100 msec - state expected_time = 100 msec + state interval(100 msec) + state expected_time(100 msec) reaction(startup) -> a {= self.expected_time = MSEC(100) diff --git a/test/Python/src/Stride.lf b/test/Python/src/Stride.lf index 86c68bab5a..95fe379ead 100644 --- a/test/Python/src/Stride.lf +++ b/test/Python/src/Stride.lf @@ -5,8 +5,8 @@ target Python { fast: true } -reactor Count(stride = 1) { - state count = 1 +reactor Count(stride(1)) { + state count(1) output y timer t(0, 100 msec) @@ -18,7 +18,7 @@ reactor Count(stride = 1) { reactor Display { input x - state expected = 1 # for testing. + state expected(1) # for testing. reaction(x) {= print("Received: ", x.value) diff --git a/test/Python/src/StructAsState.lf b/test/Python/src/StructAsState.lf index b6f38f8589..4fec8dfc0e 100644 --- a/test/Python/src/StructAsState.lf +++ b/test/Python/src/StructAsState.lf @@ -9,7 +9,7 @@ main reactor StructAsState { self.name = name self.value = value =} - state s = {= self.hello("Earth", 42) =} + state s({= self.hello("Earth", 42) =}) reaction(startup) {= print("State s.name=\"{:s}\", value={:d}.".format(self.s.name, self.s.value)) diff --git a/test/Python/src/StructAsType.lf b/test/Python/src/StructAsType.lf index 46951ec86a..d8955d0064 100644 --- a/test/Python/src/StructAsType.lf +++ b/test/Python/src/StructAsType.lf @@ -13,7 +13,7 @@ reactor Source { =} } -reactor Print(expected = 42) { # expected parameter is for testing. +reactor Print(expected(42)) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/StructAsTypeDirect.lf b/test/Python/src/StructAsTypeDirect.lf index 921b7e4390..50f4805a1f 100644 --- a/test/Python/src/StructAsTypeDirect.lf +++ b/test/Python/src/StructAsTypeDirect.lf @@ -16,7 +16,7 @@ reactor Source { =} } -reactor Print(expected = 42) { # expected parameter is for testing. +reactor Print(expected(42)) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/StructParallel.lf b/test/Python/src/StructParallel.lf index bac79a6abe..fb34a84981 100644 --- a/test/Python/src/StructParallel.lf +++ b/test/Python/src/StructParallel.lf @@ -8,7 +8,7 @@ import Source from "StructScale.lf" preamble {= import hello =} -reactor Check(expected = 42) { +reactor Check(expected(42)) { input _in reaction(_in) {= @@ -19,7 +19,7 @@ reactor Check(expected = 42) { =} } -reactor Print(scale = 2) { +reactor Print(scale(2)) { # Mutable keyword indicates that this reactor wants a writable copy of the # input. mutable input _in diff --git a/test/Python/src/StructPrint.lf b/test/Python/src/StructPrint.lf index 3c0138f937..f232c07a14 100644 --- a/test/Python/src/StructPrint.lf +++ b/test/Python/src/StructPrint.lf @@ -12,7 +12,7 @@ reactor Print { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor Check(expected = 42) { # expected parameter is for testing. +reactor Check(expected(42)) { # expected parameter is for testing. input _in reaction(_in) {= diff --git a/test/Python/src/StructScale.lf b/test/Python/src/StructScale.lf index 120c6fde65..e9ed86ff5b 100644 --- a/test/Python/src/StructScale.lf +++ b/test/Python/src/StructScale.lf @@ -12,7 +12,7 @@ reactor Source { reaction(startup) -> out {= out.set(hello.hello("Earth", 42)) =} } -reactor TestInput(expected = 42) { # expected parameter is for testing. +reactor TestInput(expected(42)) { # expected parameter is for testing. input _in reaction(_in) {= @@ -23,7 +23,7 @@ reactor TestInput(expected = 42) { # expected parameter is for testing. =} } -reactor Print(scale = 2) { +reactor Print(scale(2)) { # Mutable keyword indicates that this reactor wants a writable copy of the # input. mutable input _in diff --git a/test/Python/src/SubclassesAndStartup.lf b/test/Python/src/SubclassesAndStartup.lf index a98e580851..9dae1495be 100644 --- a/test/Python/src/SubclassesAndStartup.lf +++ b/test/Python/src/SubclassesAndStartup.lf @@ -1,7 +1,7 @@ target Python reactor Super { - state count = 0 + state count(0) reaction(startup) {= print("{:s}(Super) started".format(self.name)) @@ -15,7 +15,7 @@ reactor Super { =} } -reactor SubA(name = "SubA") extends Super { +reactor SubA(name("SubA")) extends Super { reaction(startup) {= print("{:s} started".format(self.name)) if self.count == 0: @@ -24,7 +24,7 @@ reactor SubA(name = "SubA") extends Super { =} } -reactor SubB(name = "SubB") extends Super { +reactor SubB(name("SubB")) extends Super { reaction(startup) {= print("{:s} started".format(self.name)) if self.count == 0: diff --git a/test/Python/src/TimeLimit.lf b/test/Python/src/TimeLimit.lf index beb7602db9..47577e9ed5 100644 --- a/test/Python/src/TimeLimit.lf +++ b/test/Python/src/TimeLimit.lf @@ -5,10 +5,10 @@ target Python { fast: true } -reactor Clock(offset = 0, period = 1 sec) { +reactor Clock(offset(0), period(1 sec)) { output y timer t(offset, period) - state count = 0 + state count(0) reaction(t) -> y {= self.count += 1 @@ -19,7 +19,7 @@ reactor Clock(offset = 0, period = 1 sec) { reactor Destination { input x - state s = 1 + state s(1) reaction(x) {= # print(x.value) @@ -37,7 +37,7 @@ reactor Destination { =} } -main reactor TimeLimit(period = 1 sec) { +main reactor TimeLimit(period(1 sec)) { timer stop(10 sec) c = new Clock(period = period) d = new Destination() diff --git a/test/Python/src/TimeState.lf b/test/Python/src/TimeState.lf index 72ad9f0ebd..c12318400b 100644 --- a/test/Python/src/TimeState.lf +++ b/test/Python/src/TimeState.lf @@ -1,7 +1,7 @@ target Python -reactor Foo(bar = 42) { - state baz = 500 msec +reactor Foo(bar(42)) { + state baz(500 msec) reaction(startup) {= print("Baz: ", self.baz) =} } diff --git a/test/Python/src/Timers.lf b/test/Python/src/Timers.lf index f6cbba747a..ad59feca99 100644 --- a/test/Python/src/Timers.lf +++ b/test/Python/src/Timers.lf @@ -6,7 +6,7 @@ target Python { main reactor { timer t(0, 1 sec) timer t2(0, 2 sec) - state counter = 0 + state counter(0) reaction(t2) {= self.counter += 2 =} diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf index b65f732652..c436a41cd9 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf @@ -10,7 +10,7 @@ target Python { reactor Source { output a output b - state count = 0 + state count(0) timer t(0, 200 msec) reaction(t) -> a, b {= diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf index b9a9184296..310c1d1d02 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf @@ -9,7 +9,7 @@ target Python { reactor Source { output[2] out - state count = 0 + state count(0) timer t(0, 200 msec) reaction(t) -> out {= diff --git a/test/Python/src/UnconnectedInput.lf b/test/Python/src/UnconnectedInput.lf index 66f459138b..ee40844a99 100644 --- a/test/Python/src/UnconnectedInput.lf +++ b/test/Python/src/UnconnectedInput.lf @@ -7,7 +7,7 @@ target Python { reactor Source { output out timer t(0, 1 sec) - state s = 1 + state s(1) reaction(t) -> out {= out.set(self.s) @@ -32,7 +32,7 @@ reactor Add { reactor Print { input _in - state expected = 1 + state expected(1) reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/concurrent/AsyncCallback.lf b/test/Python/src/concurrent/AsyncCallback.lf index 5ef4167bed..3769f09dc0 100644 --- a/test/Python/src/concurrent/AsyncCallback.lf +++ b/test/Python/src/concurrent/AsyncCallback.lf @@ -30,12 +30,12 @@ main reactor AsyncCallback { return None =} timer t(0, 200 msec) - state threads = {= list() =} - state expected_time = 100 msec - state toggle = False + state threads({= list() =}) + state expected_time(100 msec) + state toggle(false) physical action a(100 msec) - state i = 0 + state i(0) reaction(t) -> a {= # start new thread, provide callback diff --git a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf index 4e481d1d34..ff9a8613d6 100644 --- a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf +++ b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf @@ -34,12 +34,12 @@ main reactor { return None =} - state threads = {= list() =} - state expected_time = 100 msec - state toggle = False + state threads({= list() =}) + state expected_time(100 msec) + state toggle(false) physical action a(100 msec) - state i = 0 + state i(0) reaction(startup) -> a {= # start new thread, provide callback diff --git a/test/Python/src/docker/FilesPropertyContainerized.lf b/test/Python/src/docker/FilesPropertyContainerized.lf index c34736af48..2b592921e8 100644 --- a/test/Python/src/docker/FilesPropertyContainerized.lf +++ b/test/Python/src/docker/FilesPropertyContainerized.lf @@ -17,7 +17,7 @@ main reactor { except: lf_request_stop() =} - state passed = False + state passed(false) timer t(1 msec) reaction(t) {= self.passed = True =} diff --git a/test/Python/src/docker/federated/DistributedCountContainerized.lf b/test/Python/src/docker/federated/DistributedCountContainerized.lf index 5f8a348d24..50f1f5cb12 100644 --- a/test/Python/src/docker/federated/DistributedCountContainerized.lf +++ b/test/Python/src/docker/federated/DistributedCountContainerized.lf @@ -15,7 +15,7 @@ target Python { import Count from "../../lib/Count.lf" import Print from "../../federated/DistributedCount.lf" -federated reactor DistributedCountContainerized(offset = 200 msec) at rti { +federated reactor DistributedCountContainerized(offset(200 msec)) at rti { c = new Count() p = new Print() c.out -> p.in_ after offset diff --git a/test/Python/src/federated/BroadcastFeedback.lf b/test/Python/src/federated/BroadcastFeedback.lf index 75d313e61d..e7c8dcb527 100644 --- a/test/Python/src/federated/BroadcastFeedback.lf +++ b/test/Python/src/federated/BroadcastFeedback.lf @@ -8,7 +8,7 @@ target Python { reactor SenderAndReceiver { output out input[2] inp - state received = False + state received(False) reaction(startup) -> out {= out.set(42) =} diff --git a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf index ad2a11c10c..63cd79ad1f 100644 --- a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -8,7 +8,7 @@ target Python { reactor SenderAndReceiver { output out input[2] in_ - state received = False + state received(False) r = new Receiver() in_ -> r.in_ @@ -19,7 +19,7 @@ reactor SenderAndReceiver { reactor Receiver { preamble {= import sys =} input[2] in_ - state received = False + state received(False) reaction(in_) {= if in_[0].is_present and in_[1].is_present and in_[0].value == 42 and in_[1].value == 42: diff --git a/test/Python/src/federated/CycleDetection.lf b/test/Python/src/federated/CycleDetection.lf index cf9b6d6b54..faba30f7e1 100644 --- a/test/Python/src/federated/CycleDetection.lf +++ b/test/Python/src/federated/CycleDetection.lf @@ -10,7 +10,7 @@ reactor CAReplica { input remote_update input query - state balance = 0 + state balance(0) output response diff --git a/test/Python/src/federated/DecentralizedP2PComm.lf b/test/Python/src/federated/DecentralizedP2PComm.lf index 2725386915..29aee88ad5 100644 --- a/test/Python/src/federated/DecentralizedP2PComm.lf +++ b/test/Python/src/federated/DecentralizedP2PComm.lf @@ -5,13 +5,13 @@ target Python { coordination: decentralized } -reactor Platform(start = 0, expected_start = 0, stp_offset_param = 0) { +reactor Platform(start(0), expected_start(0), stp_offset_param(0)) { preamble {= import sys =} input in_ output out timer t(0, 100 msec) - state count = start - state expected = expected_start + state count(start) + state expected(expected_start) reaction(t) -> out {= out.set(self.count) diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 48ff7a4ca7..960a06c650 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -12,10 +12,10 @@ target Python { } # reason for failing: lf_tag() not supported by the python target -reactor Clock(offset = 0, period = 1 sec) { +reactor Clock(offset(0), period(1 sec)) { output y timer t(offset, period) - state count = 0 + state count(0) reaction(t) -> y {= self.count += 1 @@ -29,7 +29,7 @@ reactor Clock(offset = 0, period = 1 sec) { reactor Destination { preamble {= import sys =} input x - state s = 1 + state s(1) state startup_logical_time reaction(startup) {= self.startup_logical_time = lf.time.logical() =} @@ -50,7 +50,7 @@ reactor Destination { =} } -federated reactor(period = 10 usec) { +federated reactor(period(10 usec)) { c = new Clock(period = period) d = new Destination() c.y -> d.x diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 4eb881694f..c9de7270c6 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -12,10 +12,10 @@ target Python { coordination: decentralized } -reactor Clock(offset = 0, period = 1 sec) { +reactor Clock(offset(0), period(1 sec)) { output y timer t(offset, period) - state count = 0 + state count(0) reaction(t) -> y {= self.count += 1 @@ -28,7 +28,7 @@ reactor Clock(offset = 0, period = 1 sec) { reactor Destination { preamble {= import sys =} input x - state s = 1 + state s(1) reaction(x) {= if x.value != self.s: @@ -43,7 +43,7 @@ reactor Destination { =} } -federated reactor(period = 10 usec) { +federated reactor(period(10 usec)) { c = new Clock(period = period) d = new Destination() c.y ~> d.x diff --git a/test/Python/src/federated/DistributedBank.lf b/test/Python/src/federated/DistributedBank.lf index de9ea298e4..ace6b6b53c 100644 --- a/test/Python/src/federated/DistributedBank.lf +++ b/test/Python/src/federated/DistributedBank.lf @@ -7,7 +7,7 @@ target Python { reactor Node { preamble {= import sys =} timer t(0, 100 msec) - state count = 0 + state count(0) reaction(t) {= print("Hello world {}.".format(self.count)) diff --git a/test/Python/src/federated/DistributedBankToMultiport.lf b/test/Python/src/federated/DistributedBankToMultiport.lf index 493e73a3b1..f40a85fc65 100644 --- a/test/Python/src/federated/DistributedBankToMultiport.lf +++ b/test/Python/src/federated/DistributedBankToMultiport.lf @@ -8,7 +8,7 @@ import Count from "../lib/Count.lf" reactor Destination { preamble {= import sys =} input[2] in_ - state count = 1 + state count(1) reaction(in_) {= for i in range(len(in_)): diff --git a/test/Python/src/federated/DistributedCount.lf b/test/Python/src/federated/DistributedCount.lf index 7713256520..eb90b4d672 100644 --- a/test/Python/src/federated/DistributedCount.lf +++ b/test/Python/src/federated/DistributedCount.lf @@ -15,7 +15,7 @@ import Count from "../lib/Count.lf" reactor Print { preamble {= import sys =} input in_ - state c = 1 + state c(1) reaction(in_) {= elapsed_time = lf.time.logical_elapsed() @@ -36,7 +36,7 @@ reactor Print { =} } -federated reactor DistributedCount(offset = 200 msec) { +federated reactor DistributedCount(offset(200 msec)) { c = new Count() p = new Print() c.out -> p.in_ after offset diff --git a/test/Python/src/federated/DistributedCountDecentralized.lf b/test/Python/src/federated/DistributedCountDecentralized.lf index e86adf9946..232c3ef830 100644 --- a/test/Python/src/federated/DistributedCountDecentralized.lf +++ b/test/Python/src/federated/DistributedCountDecentralized.lf @@ -16,7 +16,7 @@ import Count from "../lib/Count.lf" reactor Print { preamble {= import sys =} input in_ - state c = 1 + state c(1) reaction(in_) {= print(f"At tag ({lf.time.logical_elapsed()}, {lf.tag().microstep}), received {in_.value}. " diff --git a/test/Python/src/federated/DistributedCountDecentralizedLate.lf b/test/Python/src/federated/DistributedCountDecentralizedLate.lf index e3a6899e78..617673aa0e 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLate.lf @@ -18,12 +18,12 @@ reactor Print { # STP () input in_ # STP(in, 30 msec); - state success = 0 - state success_stp_violation = 0 + state success(0) + state success_stp_violation(0) # Force a timer to be invoke periodically timer t(0, 10 usec) # to ensure logical time will advance in the absence of incoming messages. - state c = 0 + state c(0) reaction(in_) {= current_tag = lf.tag() diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf b/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf index c1c641827f..18a55f7e6b 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf @@ -28,12 +28,12 @@ import Count from "../lib/Count.lf" reactor ImportantActuator { input inp # Count messages that arrive without STP violation. - state success = 0 - state success_stp_violation = 0 + state success(0) + state success_stp_violation(0) # Force a timer to be invoked periodically timer t(0, 10 usec) # to ensure logical time will advance in the absence of incoming messages. - state c = 0 + state c(0) reaction(inp) {= current_tag = lf.tag() @@ -81,7 +81,7 @@ reactor Receiver { # Force a timer to be invoke periodically timer t(0, 10 msec) # to ensure logical time will advance in the absence of incoming messages. - state c = 0 + state c(0) p = new Print() a = new ImportantActuator() diff --git a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf index d806ab5453..e9a1bec87e 100644 --- a/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/Python/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -21,7 +21,7 @@ reactor Receiver { # Force a timer to be invoke periodically timer t(0, 10 msec) # to ensure logical time will advance in the absence of incoming messages. - state c = 0 + state c(0) p = new Print() a = new ImportantActuator() inp -> p.inp diff --git a/test/Python/src/federated/DistributedCountPhysical.lf b/test/Python/src/federated/DistributedCountPhysical.lf index 69bc2faee9..b957e06172 100644 --- a/test/Python/src/federated/DistributedCountPhysical.lf +++ b/test/Python/src/federated/DistributedCountPhysical.lf @@ -13,7 +13,7 @@ target Python { reactor Count { timer t(200 msec, 1 sec) - state s = 0 + state s(0) output out reaction(t) -> out {= @@ -25,7 +25,7 @@ reactor Count { reactor Print { preamble {= import sys =} input in_ - state c = 0 + state c(0) reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf index 105413d0a0..80c931184b 100644 --- a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -13,7 +13,7 @@ target Python { reactor Count { timer t(200 msec, 1 sec) - state s = 0 + state s(0) output out reaction(t) -> out {= @@ -25,7 +25,7 @@ reactor Count { reactor Print { preamble {= import sys =} input in_ - state c = 0 + state c(0) reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf index 0008479138..120bb6255c 100644 --- a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf @@ -14,7 +14,7 @@ target Python { reactor Count { timer t(200 msec, 1 sec) - state s = 0 + state s(0) output out reaction(t) -> out {= @@ -26,7 +26,7 @@ reactor Count { reactor Print { preamble {= import sys =} input in_ - state c = 0 + state c(0) reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/DistributedDoublePort.lf b/test/Python/src/federated/DistributedDoublePort.lf index 9eb24209e6..03ad2c4d08 100644 --- a/test/Python/src/federated/DistributedDoublePort.lf +++ b/test/Python/src/federated/DistributedDoublePort.lf @@ -14,7 +14,7 @@ target Python { import Count from "../lib/Count.lf" reactor CountMicrostep { - state count = 1 + state count(1) output out logical action act timer t(0, 1 sec) diff --git a/test/Python/src/federated/DistributedLoopedAction.lf b/test/Python/src/federated/DistributedLoopedAction.lf index 8f71d15363..83aa1de0a6 100644 --- a/test/Python/src/federated/DistributedLoopedAction.lf +++ b/test/Python/src/federated/DistributedLoopedAction.lf @@ -10,12 +10,12 @@ target Python { import Sender from "../lib/LoopedActionSender.lf" -reactor Receiver(take_a_break_after = 10, break_interval = 400 msec) { +reactor Receiver(take_a_break_after(10), break_interval(400 msec)) { preamble {= import sys =} input in_ - state received_messages = 0 - state total_received_messages = 0 - state breaks = 0 + state received_messages(0) + state total_received_messages(0) + state breaks(0) timer t(0, 1 msec) # This will impact the performance # but forces the logical time to advance Comment this line for a more diff --git a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf index d992e3d841..a2cce3742a 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf @@ -14,10 +14,10 @@ target Python { keepalive: true } -reactor Sender(take_a_break_after = 10, break_interval = 550 msec) { +reactor Sender(take_a_break_after(10), break_interval(550 msec)) { output out physical action act - state sent_messages = 0 + state sent_messages(0) reaction(startup, act) -> act, out {= # Send a message on out @@ -32,12 +32,12 @@ reactor Sender(take_a_break_after = 10, break_interval = 550 msec) { =} } -reactor Receiver(take_a_break_after = 10, break_interval = 550 msec) { +reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { preamble {= import sys =} input in_ - state received_messages = 0 - state total_received_messages = 0 - state breaks = 0 + state received_messages(0) + state total_received_messages(0) + state breaks(0) timer t(0, 1 msec) # This will impact the performance # but forces the logical time to advance Comment this line for a more # sensible log output. diff --git a/test/Python/src/federated/DistributedMultiport.lf b/test/Python/src/federated/DistributedMultiport.lf index 7250f838ef..729f8697d8 100644 --- a/test/Python/src/federated/DistributedMultiport.lf +++ b/test/Python/src/federated/DistributedMultiport.lf @@ -7,7 +7,7 @@ target Python { reactor Source { output[4] out timer t(0, 100 msec) - state count = 0 + state count(0) reaction(t) -> out {= for i in range(len(out)): @@ -19,7 +19,7 @@ reactor Source { reactor Destination { preamble {= import sys =} input[4] in_ - state count = 0 + state count(0) reaction(in_) {= for i in range(len(in_)): diff --git a/test/Python/src/federated/DistributedMultiportToBank.lf b/test/Python/src/federated/DistributedMultiportToBank.lf index 69c87b7f0c..cbd500394e 100644 --- a/test/Python/src/federated/DistributedMultiportToBank.lf +++ b/test/Python/src/federated/DistributedMultiportToBank.lf @@ -6,7 +6,7 @@ target Python { reactor Source { output[2] out timer t(0, 100 msec) - state count = 0 + state count(0) reaction(t) -> out {= for i in range(len(out)): @@ -18,7 +18,7 @@ reactor Source { reactor Destination { preamble {= import sys =} input in_ - state count = 0 + state count(0) reaction(in_) {= print("Received {}.".format(in_.value)) diff --git a/test/Python/src/federated/DistributedMultiportToken.lf b/test/Python/src/federated/DistributedMultiportToken.lf index 284e1c21a3..fdecd67c32 100644 --- a/test/Python/src/federated/DistributedMultiportToken.lf +++ b/test/Python/src/federated/DistributedMultiportToken.lf @@ -8,7 +8,7 @@ target Python { reactor Source { output[4] out timer t(0, 200 msec) - state count = 0 + state count(0) reaction(t) -> out {= for i in range(len(out)): diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index 06dfe96c36..b4a84b8bef 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -12,7 +12,7 @@ reactor Sender { output out timer t(0, 1 usec) logical action act - state reaction_invoked_correctly = False + state reaction_invoked_correctly(False) reaction(t, act) -> out, act {= tag = lf.tag() @@ -62,10 +62,10 @@ reactor Sender { } reactor Receiver( - stp_offset = 10 msec # Used in the decentralized variant of the test + stp_offset(10 msec) # Used in the decentralized variant of the test ) { input in_ - state reaction_invoked_correctly = False + state reaction_invoked_correctly(False) reaction(in_) {= tag = lf.tag() diff --git a/test/Python/src/federated/HelloDistributed.lf b/test/Python/src/federated/HelloDistributed.lf index ef99c3f793..5b8a2a55e4 100644 --- a/test/Python/src/federated/HelloDistributed.lf +++ b/test/Python/src/federated/HelloDistributed.lf @@ -19,7 +19,7 @@ reactor Source { reactor Destination { input _in - state received = False + state received(false) reaction(startup) {= print("Destination started.") =} diff --git a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 2719fd57ba..9dc86b3c60 100644 --- a/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/Python/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -14,11 +14,11 @@ target Python { timeout: 5 sec } -reactor Contained(incr = 1) { +reactor Contained(incr(1)) { timer t(0, 1 sec) input inp - state count = 0 - state received_count = 0 + state count(0) + state received_count(0) reaction(t) {= self.count += self.incr =} @@ -31,10 +31,10 @@ reactor Contained(incr = 1) { =} } -reactor Looper(incr = 1, delay = 0 msec) { +reactor Looper(incr(1), delay(0 msec)) { input inp output out - state count = 0 + state count(0) timer t(0, 1 sec) c = new Contained(incr = incr) @@ -59,7 +59,7 @@ reactor Looper(incr = 1, delay = 0 msec) { =} } -federated reactor(delay = 0) { +federated reactor(delay(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.inp diff --git a/test/Python/src/federated/PhysicalSTP.lf b/test/Python/src/federated/PhysicalSTP.lf index 5edc61df34..75e5071bca 100644 --- a/test/Python/src/federated/PhysicalSTP.lf +++ b/test/Python/src/federated/PhysicalSTP.lf @@ -9,10 +9,10 @@ target Python { import Count from "../lib/Count.lf" -reactor Print(STP_offset = 0) { +reactor Print(STP_offset(0)) { preamble {= import sys =} input in_ - state c = 1 + state c(1) reaction(in_) {= elapsed_time = lf.time.logical_elapsed() diff --git a/test/Python/src/federated/PingPongDistributed.lf b/test/Python/src/federated/PingPongDistributed.lf index 0f58cbf7db..a157baa22a 100644 --- a/test/Python/src/federated/PingPongDistributed.lf +++ b/test/Python/src/federated/PingPongDistributed.lf @@ -21,10 +21,10 @@ */ target Python -reactor Ping(count = 10) { +reactor Ping(count(10)) { input receive output send - state pingsLeft = count + state pingsLeft(count) logical action serve reaction(startup, serve) -> send {= @@ -41,12 +41,12 @@ reactor Ping(count = 10) { =} } -reactor Pong(expected = 10) { +reactor Pong(expected(10)) { preamble {= import sys =} input receive output send - state count = 0 + state count(0) reaction(receive) -> send {= self.count += 1 @@ -64,7 +64,7 @@ reactor Pong(expected = 10) { =} } -federated reactor(count = 10) { +federated reactor(count(10)) { ping = new Ping(count = count) pong = new Pong(expected = count) ping.send ~> pong.receive diff --git a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf index 12367332f4..9068ebfae8 100644 --- a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf +++ b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf @@ -16,11 +16,11 @@ target Python { timeout: 5 sec } -reactor Looper(incr = 1, delay = 0 msec) { +reactor Looper(incr(1), delay(0 msec)) { input in_ output out - state count = 0 - state received_count = 0 + state count(0) + state received_count(0) timer t(0, 1 sec) reaction(t) -> out {= @@ -50,7 +50,7 @@ reactor Looper(incr = 1, delay = 0 msec) { =} } -federated reactor(delay = 0) { +federated reactor(delay(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in_ diff --git a/test/Python/src/federated/failing/LoopDistributedDouble.lf b/test/Python/src/federated/failing/LoopDistributedDouble.lf index 4ccee4acd6..8788d09288 100644 --- a/test/Python/src/federated/failing/LoopDistributedDouble.lf +++ b/test/Python/src/federated/failing/LoopDistributedDouble.lf @@ -24,13 +24,13 @@ preamble {= } =} -reactor Looper(incr = 1, delay = 0 msec) { +reactor Looper(incr(1), delay(0 msec)) { input in_ input in2 output out output out2 physical action a(delay) - state count = 0 + state count(0) timer t(0, 1 sec) reaction(startup) -> a {= @@ -79,7 +79,7 @@ reactor Looper(incr = 1, delay = 0 msec) { =} } -federated reactor(delay = 0) { +federated reactor(delay(0)) { left = new Looper() right = new Looper(incr = -1) left.out -> right.in_ diff --git a/test/Python/src/lib/Count.lf b/test/Python/src/lib/Count.lf index 26b53ce13b..bcfae967b6 100644 --- a/test/Python/src/lib/Count.lf +++ b/test/Python/src/lib/Count.lf @@ -1,7 +1,7 @@ target Python -reactor Count(offset = 0, period = 1 sec) { - state count = 1 +reactor Count(offset(0), period(1 sec)) { + state count(1) output out timer t(offset, period) diff --git a/test/Python/src/lib/InternalDelay.lf b/test/Python/src/lib/InternalDelay.lf index a9796aa8d9..f2ac5449c0 100644 --- a/test/Python/src/lib/InternalDelay.lf +++ b/test/Python/src/lib/InternalDelay.lf @@ -1,6 +1,6 @@ target Python -reactor InternalDelay(delay = 10 msec) { +reactor InternalDelay(delay(10 msec)) { input in_ output out logical action d diff --git a/test/Python/src/lib/LoopedActionSender.lf b/test/Python/src/lib/LoopedActionSender.lf index 9d4048d0ea..3a01219ec8 100644 --- a/test/Python/src/lib/LoopedActionSender.lf +++ b/test/Python/src/lib/LoopedActionSender.lf @@ -11,10 +11,10 @@ target Python * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after = 10, break_interval = 400 msec) { +reactor Sender(take_a_break_after(10), break_interval(400 msec)) { output out logical action act - state sent_messages = 0 + state sent_messages(0) reaction(startup, act) -> act, out {= # Send a message on out diff --git a/test/Python/src/lib/Test.lf b/test/Python/src/lib/Test.lf index 301ed9c8e6..f6bbf867ee 100644 --- a/test/Python/src/lib/Test.lf +++ b/test/Python/src/lib/Test.lf @@ -2,7 +2,7 @@ target Python reactor TestDouble(expected(1.0, 1.0, 1.0, 1.0)) { input t_in - state count = 0 + state count(0) reaction(t_in) {= print("Received: ", t_in.value) diff --git a/test/Python/src/lib/TestCount.lf b/test/Python/src/lib/TestCount.lf index de611cbc69..dfe11cd5b9 100644 --- a/test/Python/src/lib/TestCount.lf +++ b/test/Python/src/lib/TestCount.lf @@ -9,10 +9,10 @@ */ target Python -reactor TestCount(start = 1, stride = 1, num_inputs = 1) { +reactor TestCount(start(1), stride(1), num_inputs(1)) { preamble {= import sys =} - state count = start - state inputs_received = 0 + state count(start) + state inputs_received(0) input in_ reaction(in_) {= diff --git a/test/Python/src/lib/TestCountMultiport.lf b/test/Python/src/lib/TestCountMultiport.lf index c30572e4d5..d9b711ce89 100644 --- a/test/Python/src/lib/TestCountMultiport.lf +++ b/test/Python/src/lib/TestCountMultiport.lf @@ -11,10 +11,10 @@ */ target Python -reactor TestCountMultiport(start = 1, stride = 1, num_inputs = 1, width = 2) { +reactor TestCountMultiport(start(1), stride(1), num_inputs(1), width(2)) { preamble {= import sys =} - state count = start - state inputs_received = 0 + state count(start) + state inputs_received(0) input[width] inp reaction(inp) {= diff --git a/test/Python/src/modal_models/ConvertCaseTest.lf b/test/Python/src/modal_models/ConvertCaseTest.lf index f3bdee59fe..f391660322 100644 --- a/test/Python/src/modal_models/ConvertCaseTest.lf +++ b/test/Python/src/modal_models/ConvertCaseTest.lf @@ -67,9 +67,9 @@ reactor Converter { } } -reactor InputFeeder(message = "") { +reactor InputFeeder(message("")) { output character - state idx = 0 + state idx(0) timer t(0, 250 msec) diff --git a/test/Python/src/modal_models/Count3Modes.lf b/test/Python/src/modal_models/Count3Modes.lf index 7e2e9d98e2..e512e7d54a 100644 --- a/test/Python/src/modal_models/Count3Modes.lf +++ b/test/Python/src/modal_models/Count3Modes.lf @@ -34,7 +34,7 @@ main reactor { timer stepper(0, 250 msec) counter = new CounterCycle() - state expected_value = 1 + state expected_value(1) reaction(stepper) -> counter.next {= counter.next.set(True) =} # Trigger diff --git a/test/Python/src/modal_models/ModalAfter.lf b/test/Python/src/modal_models/ModalAfter.lf index 19c84f33d5..c86002c9fa 100644 --- a/test/Python/src/modal_models/ModalAfter.lf +++ b/test/Python/src/modal_models/ModalAfter.lf @@ -45,7 +45,7 @@ reactor Modal { } } -reactor Producer(mode_id = 0) { +reactor Producer(mode_id(0)) { output product timer t(0, 750 msec) @@ -56,7 +56,7 @@ reactor Producer(mode_id = 0) { =} } -reactor Consumer(mode_id = 0) { +reactor Consumer(mode_id(0)) { input product output report diff --git a/test/Python/src/modal_models/ModalCycleBreaker.lf b/test/Python/src/modal_models/ModalCycleBreaker.lf index 1ceb2eb5d0..baafdf8378 100644 --- a/test/Python/src/modal_models/ModalCycleBreaker.lf +++ b/test/Python/src/modal_models/ModalCycleBreaker.lf @@ -39,11 +39,11 @@ reactor Modal { } } -reactor Counter(period = 1 sec) { +reactor Counter(period(1 sec)) { output value timer t(0, period) - state curval = 0 + state curval(0) reaction(t) -> value {= value.set(self.curval) diff --git a/test/Python/src/modal_models/ModalStateReset.lf b/test/Python/src/modal_models/ModalStateReset.lf index 11b7425b63..9bd969b15c 100644 --- a/test/Python/src/modal_models/ModalStateReset.lf +++ b/test/Python/src/modal_models/ModalStateReset.lf @@ -14,7 +14,7 @@ reactor Modal { output count1 output count2 - state counter0 = 0 + state counter0(0) reaction(next) -> count0 {= print(f"Counter0: {self.counter0}") @@ -23,7 +23,7 @@ reactor Modal { =} initial mode One { - state counter1 = 0 + state counter1(0) timer T1(0 msec, 250 msec) reaction(reset) {= self.counter1 = 0 =} @@ -41,7 +41,7 @@ reactor Modal { } mode Two { - state counter2 = -2 + state counter2(-2) timer T2(0 msec, 250 msec) reaction(reset) {= self.counter2 = -2 =} diff --git a/test/Python/src/modal_models/ModalStateResetAuto.lf b/test/Python/src/modal_models/ModalStateResetAuto.lf index 492e12259b..be664676db 100644 --- a/test/Python/src/modal_models/ModalStateResetAuto.lf +++ b/test/Python/src/modal_models/ModalStateResetAuto.lf @@ -14,7 +14,7 @@ reactor Modal { output count1 output count2 - state counter0 = 0 + state counter0(0) reaction(next) -> count0 {= print(f"Counter0: {self.counter0}") @@ -23,7 +23,7 @@ reactor Modal { =} initial mode One { - state counter1 = 0 + state counter1(0) timer T1(0 msec, 250 msec) reaction(T1) -> count1 {= print(f"Counter1: {self.counter1}") @@ -39,7 +39,7 @@ reactor Modal { } mode Two { - reset state counter2 = -2 + reset state counter2(-2) timer T2(0 msec, 250 msec) reaction(T2) -> count2 {= print(f"Counter2: {self.counter2}") diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf index 3dd42f67ce..5654dd9b1e 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -28,11 +28,11 @@ reactor Modal { } } -reactor Counter(period = 1 sec) { +reactor Counter(period(1 sec)) { output value timer t(0, period) - reset state curval = 0 + reset state curval(0) reaction(t) -> value {= value.set(self.curval) diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index 86f5668357..80c4247972 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -31,11 +31,11 @@ reactor Modal { } } -reactor Counter(period = 1 sec) { +reactor Counter(period(1 sec)) { output value timer t(0, period) - reset state curval = 0 + reset state curval(0) reaction(t) -> value {= value.set(self.curval) diff --git a/test/Python/src/modal_models/util/TraceTesting.lf b/test/Python/src/modal_models/util/TraceTesting.lf index 305ff31a5b..1014ac3c8d 100644 --- a/test/Python/src/modal_models/util/TraceTesting.lf +++ b/test/Python/src/modal_models/util/TraceTesting.lf @@ -1,13 +1,13 @@ /** Utility reactor to record and test execution traces. */ target Python -reactor TraceTesting(events_size = 0, trace = {= [] =}, training = False) { +reactor TraceTesting(events_size(0), trace({= [] =}), training(False)) { input[events_size] events - state last_reaction_time = 0 - state trace_idx = 0 - state recorded_events = {= [] =} - state recorded_events_next = 0 + state last_reaction_time(0) + state trace_idx(0) + state recorded_events({= [] =}) + state recorded_events_next(0) reaction(startup) {= self.last_reaction_time = lf.time.logical() =} diff --git a/test/Python/src/multiport/BankIndexInitializer.lf b/test/Python/src/multiport/BankIndexInitializer.lf index 52ef58bb1d..6754f31d97 100644 --- a/test/Python/src/multiport/BankIndexInitializer.lf +++ b/test/Python/src/multiport/BankIndexInitializer.lf @@ -3,15 +3,15 @@ target Python preamble {= table = [4, 3, 2, 1] =} -reactor Source(bank_index = 0, value = 0) { +reactor Source(bank_index(0), value(0)) { output out reaction(startup) -> out {= out.set(self.value) =} } -reactor Sink(width = 4) { +reactor Sink(width(4)) { input[width] _in - state received = False + state received(false) reaction(_in) {= for (idx, port) in enumerate(_in): @@ -30,7 +30,7 @@ reactor Sink(width = 4) { =} } -main reactor(width = 4) { +main reactor(width(4)) { source = new[width] Source(value = {= table[bank_index] =}) sink = new Sink(width = width) source.out -> sink._in diff --git a/test/Python/src/multiport/BankReactionsInContainer.lf b/test/Python/src/multiport/BankReactionsInContainer.lf index 7316463c3d..3a72418405 100644 --- a/test/Python/src/multiport/BankReactionsInContainer.lf +++ b/test/Python/src/multiport/BankReactionsInContainer.lf @@ -5,10 +5,10 @@ target Python { timeout: 1 sec } -reactor R(bank_index = 0) { +reactor R(bank_index(0)) { output[2] out input[2] inp - state received = False + state received(false) reaction(startup) -> out {= for (i, p) in enumerate(out): @@ -37,7 +37,7 @@ reactor R(bank_index = 0) { main reactor { s = new[2] R() - state received = False + state received(false) reaction(startup) -> s.inp {= count = 0 diff --git a/test/Python/src/multiport/BankToBank.lf b/test/Python/src/multiport/BankToBank.lf index 6e3ddc734d..e94b7dd717 100644 --- a/test/Python/src/multiport/BankToBank.lf +++ b/test/Python/src/multiport/BankToBank.lf @@ -4,10 +4,10 @@ target Python { fast: true } -reactor Source(bank_index = 0) { +reactor Source(bank_index(0)) { timer t(0, 200 msec) output out - state s = 0 + state s(0) reaction(t) -> out {= out.set(self.s) @@ -15,8 +15,8 @@ reactor Source(bank_index = 0) { =} } -reactor Destination(bank_index = 0) { - state s = 0 +reactor Destination(bank_index(0)) { + state s(0) input _in reaction(_in) {= @@ -35,7 +35,7 @@ reactor Destination(bank_index = 0) { =} } -main reactor BankToBank(width = 4) { +main reactor BankToBank(width(4)) { a = new[width] Source() b = new[width] Destination() a.out -> b._in diff --git a/test/Python/src/multiport/BankToBankMultiport.lf b/test/Python/src/multiport/BankToBankMultiport.lf index f335e53858..de2f05a55d 100644 --- a/test/Python/src/multiport/BankToBankMultiport.lf +++ b/test/Python/src/multiport/BankToBankMultiport.lf @@ -4,10 +4,10 @@ target Python { fast: true } -reactor Source(width = 1) { +reactor Source(width(1)) { timer t(0, 200 msec) output[width] out - state s = 0 + state s(0) reaction(t) -> out {= for port in out: @@ -16,8 +16,8 @@ reactor Source(width = 1) { =} } -reactor Destination(width = 1) { - state s = 6 +reactor Destination(width(1)) { + state s(6) input[width] _in reaction(_in) {= @@ -43,7 +43,7 @@ reactor Destination(width = 1) { =} } -main reactor BankToBankMultiport(bank_width = 4) { +main reactor BankToBankMultiport(bank_width(4)) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b._in diff --git a/test/Python/src/multiport/BankToBankMultiportAfter.lf b/test/Python/src/multiport/BankToBankMultiportAfter.lf index 9d6e946122..eb7f025772 100644 --- a/test/Python/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Python/src/multiport/BankToBankMultiportAfter.lf @@ -6,7 +6,7 @@ target Python { import Source, Destination from "BankToBankMultiport.lf" -main reactor BankToBankMultiportAfter(bank_width = 4) { +main reactor BankToBankMultiportAfter(bank_width(4)) { a = new[bank_width] Source(width = 4) b = new[bank_width] Destination(width = 4) a.out -> b._in after 200 msec diff --git a/test/Python/src/multiport/BankToMultiport.lf b/test/Python/src/multiport/BankToMultiport.lf index 769e0ea2fc..110295400d 100644 --- a/test/Python/src/multiport/BankToMultiport.lf +++ b/test/Python/src/multiport/BankToMultiport.lf @@ -1,15 +1,15 @@ # Test bank of reactors to multiport input with id parameter in the bank. target Python -reactor Source(bank_index = 0) { +reactor Source(bank_index(0)) { output out reaction(startup) -> out {= out.set(self.bank_index) =} } -reactor Sink(width = 4) { +reactor Sink(width(4)) { input[width] _in - state received = False + state received(false) reaction(_in) {= for (idx, port) in enumerate(_in): @@ -28,7 +28,7 @@ reactor Sink(width = 4) { =} } -main reactor BankToMultiport(width = 5) { +main reactor BankToMultiport(width(5)) { source = new[width] Source() sink = new Sink(width = width) source.out -> sink._in diff --git a/test/Python/src/multiport/Broadcast.lf b/test/Python/src/multiport/Broadcast.lf index 2e507d607f..ebc4de3067 100644 --- a/test/Python/src/multiport/Broadcast.lf +++ b/test/Python/src/multiport/Broadcast.lf @@ -3,15 +3,15 @@ target Python { fast: true } -reactor Source(value = 42) { +reactor Source(value(42)) { output out reaction(startup) -> out {= out.set(self.value) =} } -reactor Destination(bank_index = 0, delay = 0) { +reactor Destination(bank_index(0), delay(0)) { input _in - state received = False + state received(false) reaction(_in) {= print(f"Destination {self.bank_index} received {_in.value}.") diff --git a/test/Python/src/multiport/BroadcastMultipleAfter.lf b/test/Python/src/multiport/BroadcastMultipleAfter.lf index 9fc327e6fd..7777406c38 100644 --- a/test/Python/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Python/src/multiport/BroadcastMultipleAfter.lf @@ -5,9 +5,9 @@ target Python { import Source from "Broadcast.lf" -reactor Destination(bank_index = 0, delay = 0) { +reactor Destination(bank_index(0), delay(0)) { input _in - state received = False + state received(false) reaction(_in) {= print(f"Destination {self.bank_index} received {_in.value}.") diff --git a/test/Python/src/multiport/MultiportFromBank.lf b/test/Python/src/multiport/MultiportFromBank.lf index 92d9363df5..05dc165fa1 100644 --- a/test/Python/src/multiport/MultiportFromBank.lf +++ b/test/Python/src/multiport/MultiportFromBank.lf @@ -5,7 +5,7 @@ target Python { fast: true } -reactor Source(check_override = 0, bank_index = 0) { +reactor Source(check_override(0), bank_index(0)) { output out reaction(startup) -> out {= @@ -15,7 +15,7 @@ reactor Source(check_override = 0, bank_index = 0) { reactor Destination { input[3] _in - state received = 0 + state received(0) reaction(_in) {= for (idx, port) in enumerate(_in): diff --git a/test/Python/src/multiport/MultiportFromBankHierarchy.lf b/test/Python/src/multiport/MultiportFromBankHierarchy.lf index 27ecb3c80b..ac62f5829f 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchy.lf @@ -7,7 +7,7 @@ target Python { import Destination from "MultiportFromBank.lf" -reactor Source(bank_index = 0) { +reactor Source(bank_index(0)) { output out reaction(startup) -> out {= out.set(self.bank_index) =} diff --git a/test/Python/src/multiport/MultiportFromHierarchy.lf b/test/Python/src/multiport/MultiportFromHierarchy.lf index 4116587f01..dc7a9a2f68 100644 --- a/test/Python/src/multiport/MultiportFromHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromHierarchy.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[4] out - state s = 0 + state s(0) reaction(t) -> out {= for port in out: @@ -18,7 +18,7 @@ reactor Source { } reactor Destination { - state s = 6 + state s(6) input[4] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportFromReaction.lf b/test/Python/src/multiport/MultiportFromReaction.lf index 05b280b126..f005711683 100644 --- a/test/Python/src/multiport/MultiportFromReaction.lf +++ b/test/Python/src/multiport/MultiportFromReaction.lf @@ -4,8 +4,8 @@ target Python { fast: true } -reactor Destination(width = 1) { - state s = 6 +reactor Destination(width(1)) { + state s(6) input[width] _in reaction(_in) {= @@ -31,7 +31,7 @@ reactor Destination(width = 1) { main reactor MultiportFromReaction { timer t(0, 200 msec) - state s = 0 + state s(0) b = new Destination(width = 4) reaction(t) -> b._in {= diff --git a/test/Python/src/multiport/MultiportIn.lf b/test/Python/src/multiport/MultiportIn.lf index 35bdee7341..146dfa6727 100644 --- a/test/Python/src/multiport/MultiportIn.lf +++ b/test/Python/src/multiport/MultiportIn.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output out - state s = 0 + state s(0) reaction(t) -> out {= out.set(self.s) @@ -24,7 +24,7 @@ reactor Computation { } reactor Destination { - state s = 0 + state s(0) input[4] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportInParameterized.lf b/test/Python/src/multiport/MultiportInParameterized.lf index 28b15808e3..c4906d7a9c 100644 --- a/test/Python/src/multiport/MultiportInParameterized.lf +++ b/test/Python/src/multiport/MultiportInParameterized.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output out - state s = 0 + state s(0) reaction(t) -> out {= out.set(self.s) @@ -23,8 +23,8 @@ reactor Computation { reaction(_in) -> out {= out.set(_in.value) =} } -reactor Destination(width = 1) { - state s = 0 +reactor Destination(width(1)) { + state s(0) input[width] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportMutableInput.lf b/test/Python/src/multiport/MultiportMutableInput.lf index f931900ef7..d17e1cd8bf 100644 --- a/test/Python/src/multiport/MultiportMutableInput.lf +++ b/test/Python/src/multiport/MultiportMutableInput.lf @@ -12,7 +12,7 @@ reactor Source { =} } -reactor Print(scale = 1) { # The scale parameter is just for testing. +reactor Print(scale(1)) { # The scale parameter is just for testing. input[2] _in reaction(_in) {= @@ -26,7 +26,7 @@ reactor Print(scale = 1) { # The scale parameter is just for testing. =} } -reactor Scale(scale = 2) { +reactor Scale(scale(2)) { mutable input[2] _in output[2] out diff --git a/test/Python/src/multiport/MultiportMutableInputArray.lf b/test/Python/src/multiport/MultiportMutableInputArray.lf index 9efa3eeebf..76fa5203a6 100644 --- a/test/Python/src/multiport/MultiportMutableInputArray.lf +++ b/test/Python/src/multiport/MultiportMutableInputArray.lf @@ -13,7 +13,7 @@ reactor Source { =} } -reactor Print(scale = 1) { # The scale parameter is just for testing. +reactor Print(scale(1)) { # The scale parameter is just for testing. input[2] _in reaction(_in) {= @@ -25,7 +25,7 @@ reactor Print(scale = 1) { # The scale parameter is just for testing. =} } -reactor Scale(scale = 2) { +reactor Scale(scale(2)) { mutable input[2] _in output[2] out diff --git a/test/Python/src/multiport/MultiportOut.lf b/test/Python/src/multiport/MultiportOut.lf index 3d29c5188a..0a48f355e6 100644 --- a/test/Python/src/multiport/MultiportOut.lf +++ b/test/Python/src/multiport/MultiportOut.lf @@ -7,7 +7,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[4] out - state s = 0 + state s(0) reaction(t) -> out {= for port in out: @@ -25,7 +25,7 @@ reactor Computation { } reactor Destination { - state s = 0 + state s(0) input[4] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToBank.lf b/test/Python/src/multiport/MultiportToBank.lf index 12d68d6662..61b1cabc8b 100644 --- a/test/Python/src/multiport/MultiportToBank.lf +++ b/test/Python/src/multiport/MultiportToBank.lf @@ -13,9 +13,9 @@ reactor Source { =} } -reactor Destination(bank_index = 0) { +reactor Destination(bank_index(0)) { input _in - state received = 0 + state received(0) reaction(_in) {= print("Destination " + str(self.bank_index) + " received " + str(_in.value)) diff --git a/test/Python/src/multiport/MultiportToBankAfter.lf b/test/Python/src/multiport/MultiportToBankAfter.lf index 85fc91e513..aeb8a9d0d7 100644 --- a/test/Python/src/multiport/MultiportToBankAfter.lf +++ b/test/Python/src/multiport/MultiportToBankAfter.lf @@ -7,9 +7,9 @@ target Python { import Source from "MultiportToBank.lf" -reactor Destination(bank_index = 0) { +reactor Destination(bank_index(0)) { input _in - state received = False + state received(false) reaction(_in) {= print("Destination {:d} received {:d}.".format(self.bank_index, _in.value)) diff --git a/test/Python/src/multiport/MultiportToBankHierarchy.lf b/test/Python/src/multiport/MultiportToBankHierarchy.lf index f70fa8ad92..b36ae9b40b 100644 --- a/test/Python/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportToBankHierarchy.lf @@ -7,9 +7,9 @@ target Python { import Source from "MultiportToBank.lf" -reactor Destination(bank_index = 0) { +reactor Destination(bank_index(0)) { input _in - state received = False + state received(false) reaction(_in) {= print("Destination {:d} received {:d}.\n".format(self.bank_index, _in.value)) diff --git a/test/Python/src/multiport/MultiportToHierarchy.lf b/test/Python/src/multiport/MultiportToHierarchy.lf index 2a9e25a5e6..6dbf76775f 100644 --- a/test/Python/src/multiport/MultiportToHierarchy.lf +++ b/test/Python/src/multiport/MultiportToHierarchy.lf @@ -9,7 +9,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[4] out - state s = 0 + state s(0) reaction(t) -> out {= for port in out: @@ -18,8 +18,8 @@ reactor Source { =} } -reactor Destination(width = 4) { - state s = 6 +reactor Destination(width(4)) { + state s(6) input[width] _in reaction(_in) {= @@ -42,7 +42,7 @@ reactor Destination(width = 4) { =} } -reactor Container(width = 4) { +reactor Container(width(4)) { input[width] _in dst = new Destination() _in -> dst._in diff --git a/test/Python/src/multiport/MultiportToMultiport.lf b/test/Python/src/multiport/MultiportToMultiport.lf index b16e832e7e..6fd4bbb231 100644 --- a/test/Python/src/multiport/MultiportToMultiport.lf +++ b/test/Python/src/multiport/MultiportToMultiport.lf @@ -6,10 +6,10 @@ target Python { import Destination from "MultiportToHierarchy.lf" -reactor Source(width = 1) { +reactor Source(width(1)) { timer t(0, 200 msec) output[width] out - state s = 0 + state s(0) reaction(t) -> out {= for i in range(len(out)): diff --git a/test/Python/src/multiport/MultiportToMultiport2.lf b/test/Python/src/multiport/MultiportToMultiport2.lf index cb6da65f35..5b06d8d7d8 100644 --- a/test/Python/src/multiport/MultiportToMultiport2.lf +++ b/test/Python/src/multiport/MultiportToMultiport2.lf @@ -1,7 +1,7 @@ # Test multiport to multiport connections. See also MultiportToMultiport. target Python -reactor Source(width = 2) { +reactor Source(width(2)) { output[width] out reaction(startup) -> out {= @@ -10,7 +10,7 @@ reactor Source(width = 2) { =} } -reactor Destination(width = 2) { +reactor Destination(width(2)) { input[width] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToMultiport2After.lf b/test/Python/src/multiport/MultiportToMultiport2After.lf index 0e7ee9aef2..d8d85805ce 100644 --- a/test/Python/src/multiport/MultiportToMultiport2After.lf +++ b/test/Python/src/multiport/MultiportToMultiport2After.lf @@ -3,7 +3,7 @@ target Python import Source from "MultiportToMultiport2.lf" -reactor Destination(width = 2) { +reactor Destination(width(2)) { input[width] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToMultiportArray.lf b/test/Python/src/multiport/MultiportToMultiportArray.lf index 5eb043570d..e22f3541b0 100644 --- a/test/Python/src/multiport/MultiportToMultiportArray.lf +++ b/test/Python/src/multiport/MultiportToMultiportArray.lf @@ -8,7 +8,7 @@ target Python { reactor Source { timer t(0, 200 msec) output[2] out - state s = 0 + state s(0) reaction(t) -> out {= for port in out: @@ -18,7 +18,7 @@ reactor Source { } reactor Destination { - state s = 15 + state s(15) input[2] _in reaction(_in) {= diff --git a/test/Python/src/multiport/MultiportToMultiportParameter.lf b/test/Python/src/multiport/MultiportToMultiportParameter.lf index b47905bb6e..933abfd846 100644 --- a/test/Python/src/multiport/MultiportToMultiportParameter.lf +++ b/test/Python/src/multiport/MultiportToMultiportParameter.lf @@ -7,7 +7,7 @@ target Python { import Source from "MultiportToMultiport.lf" import Destination from "MultiportToHierarchy.lf" -main reactor MultiportToMultiportParameter(width = 4) { +main reactor MultiportToMultiportParameter(width(4)) { a = new Source(width = width) b = new Destination(width = width) a.out -> b._in diff --git a/test/Python/src/multiport/MultiportToPort.lf b/test/Python/src/multiport/MultiportToPort.lf index ebfbf81991..52bb7b7c67 100644 --- a/test/Python/src/multiport/MultiportToPort.lf +++ b/test/Python/src/multiport/MultiportToPort.lf @@ -15,9 +15,9 @@ reactor Source { =} } -reactor Destination(expected = 0) { +reactor Destination(expected(0)) { input _in - state received = False + state received(false) reaction(_in) {= print("Received: ", _in.value) diff --git a/test/Python/src/multiport/MultiportToReaction.lf b/test/Python/src/multiport/MultiportToReaction.lf index b45ee9ac9e..6d03ba28ee 100644 --- a/test/Python/src/multiport/MultiportToReaction.lf +++ b/test/Python/src/multiport/MultiportToReaction.lf @@ -4,9 +4,9 @@ target Python { fast: true } -reactor Source(width = 1) { +reactor Source(width(1)) { timer t(0, 200 msec) - state s = 0 + state s(0) output[width] out reaction(t) -> out {= @@ -17,7 +17,7 @@ reactor Source(width = 1) { } main reactor { - state s = 6 + state s(6) b = new Source(width = 4) reaction(b.out) {= diff --git a/test/Python/src/multiport/NestedBanks.lf b/test/Python/src/multiport/NestedBanks.lf index 1e863043e6..8e49b76aef 100644 --- a/test/Python/src/multiport/NestedBanks.lf +++ b/test/Python/src/multiport/NestedBanks.lf @@ -13,13 +13,13 @@ main reactor { (a.x)+ -> c.z, d.u, e.t } -reactor A(bank_index = 0) { +reactor A(bank_index(0)) { output[4] x b = new[2] B(a_bank_index = bank_index) b.y -> x } -reactor B(a_bank_index = 0, bank_index = 0) { +reactor B(a_bank_index(0), bank_index(0)) { output[2] y reaction(startup) -> y {= @@ -29,7 +29,7 @@ reactor B(a_bank_index = 0, bank_index = 0) { =} } -reactor C(bank_index = 0) { +reactor C(bank_index(0)) { input[2] z f = new F(c_bank_index = bank_index) g = new G(c_bank_index = bank_index) @@ -57,7 +57,7 @@ reactor E { =} } -reactor F(c_bank_index = 0) { +reactor F(c_bank_index(0)) { input w reaction(w) {= @@ -68,7 +68,7 @@ reactor F(c_bank_index = 0) { =} } -reactor G(c_bank_index = 0) { +reactor G(c_bank_index(0)) { input s reaction(s) {= diff --git a/test/Python/src/multiport/NestedInterleavedBanks.lf b/test/Python/src/multiport/NestedInterleavedBanks.lf index 9be37badcd..5d615a3397 100644 --- a/test/Python/src/multiport/NestedInterleavedBanks.lf +++ b/test/Python/src/multiport/NestedInterleavedBanks.lf @@ -4,7 +4,7 @@ */ target Python -reactor A(bank_index = 0, outer_bank_index = 0) { +reactor A(bank_index(0), outer_bank_index(0)) { output[2] p reaction(startup) -> p {= @@ -14,7 +14,7 @@ reactor A(bank_index = 0, outer_bank_index = 0) { =} } -reactor B(bank_index = 0) { +reactor B(bank_index(0)) { output[4] q a = new[2] A(outer_bank_index = bank_index) interleaved (a.p) -> q diff --git a/test/Python/src/multiport/ReactionsToNested.lf b/test/Python/src/multiport/ReactionsToNested.lf index 2c207dffb0..9870cb1b68 100644 --- a/test/Python/src/multiport/ReactionsToNested.lf +++ b/test/Python/src/multiport/ReactionsToNested.lf @@ -4,9 +4,9 @@ target Python { timeout: 1 sec } -reactor T(expected = 0) { +reactor T(expected(0)) { input z - state received = False + state received(false) reaction(z) {= print(f"T received {z.value}.") diff --git a/test/Python/src/target/AfterNoTypes.lf b/test/Python/src/target/AfterNoTypes.lf index 44aaa89c73..3ff3983da5 100644 --- a/test/Python/src/target/AfterNoTypes.lf +++ b/test/Python/src/target/AfterNoTypes.lf @@ -13,8 +13,8 @@ reactor Foo { } reactor Print { - state expected_time = 10 msec - state received = 0 + state expected_time(10 msec) + state received(0) input x reaction(x) {= diff --git a/test/Rust/src/ActionDelay.lf b/test/Rust/src/ActionDelay.lf index 75c7ab909f..8612eabbb2 100644 --- a/test/Rust/src/ActionDelay.lf +++ b/test/Rust/src/ActionDelay.lf @@ -4,7 +4,7 @@ target Rust main reactor ActionDelay { logical action act0 logical action act1(100 msec) - state count: u32 = 0 + state count: u32(0) reaction(startup) -> act0, act1 {= ctx.schedule(act0, after!(100 ms)); diff --git a/test/Rust/src/ActionImplicitDelay.lf b/test/Rust/src/ActionImplicitDelay.lf index 9a3a900d93..1278472528 100644 --- a/test/Rust/src/ActionImplicitDelay.lf +++ b/test/Rust/src/ActionImplicitDelay.lf @@ -3,7 +3,7 @@ target Rust main reactor ActionImplicitDelay { logical action act(40 msec) - state count: u64 = 1 + state count: u64(1) reaction(startup) -> act {= ctx.schedule(act, Asap); =} diff --git a/test/Rust/src/ActionIsPresent.lf b/test/Rust/src/ActionIsPresent.lf index 3a1e556c5a..efe6158e43 100644 --- a/test/Rust/src/ActionIsPresent.lf +++ b/test/Rust/src/ActionIsPresent.lf @@ -3,8 +3,8 @@ target Rust main reactor ActionIsPresent { logical action a - state success: bool = false - state tried: bool = false + state success: bool(false) + state tried: bool(false) reaction(startup, a) -> a {= if !ctx.is_present(a) { diff --git a/test/Rust/src/ActionScheduleMicrostep.lf b/test/Rust/src/ActionScheduleMicrostep.lf index 53bf8781b9..5ded693d2c 100644 --- a/test/Rust/src/ActionScheduleMicrostep.lf +++ b/test/Rust/src/ActionScheduleMicrostep.lf @@ -3,7 +3,7 @@ target Rust main reactor ActionScheduleMicrostep { logical action act - state count: u32 = 1 + state count: u32(1) reaction(startup) -> act {= assert_tag_is!(ctx, T0); diff --git a/test/Rust/src/ActionValues.lf b/test/Rust/src/ActionValues.lf index 007da1fb5a..635516c3d0 100644 --- a/test/Rust/src/ActionValues.lf +++ b/test/Rust/src/ActionValues.lf @@ -2,8 +2,8 @@ target Rust main reactor ActionValues { - state r1done: bool = false - state r2done: bool = false + state r1done: bool(false) + state r2done: bool(false) logical action act(100 msec): i32 reaction(startup) -> act {= diff --git a/test/Rust/src/ActionValuesCleanup.lf b/test/Rust/src/ActionValuesCleanup.lf index f4bab7a2b5..615bd68a90 100644 --- a/test/Rust/src/ActionValuesCleanup.lf +++ b/test/Rust/src/ActionValuesCleanup.lf @@ -20,7 +20,7 @@ main reactor ActionValuesCleanup { =} logical action act: FooDrop - state count: u32 = 0 + state count: u32(0) reaction(startup) -> act {= ctx.schedule_with_v(act, Some(FooDrop { }), Asap) diff --git a/test/Rust/src/CtorParamDefault.lf b/test/Rust/src/CtorParamDefault.lf index a7d2d868bc..2a4f4b8074 100644 --- a/test/Rust/src/CtorParamDefault.lf +++ b/test/Rust/src/CtorParamDefault.lf @@ -1,7 +1,7 @@ target Rust -reactor Print(value: i32 = 42) { - state v: i32 = value +reactor Print(value: i32(42)) { + state v: i32(value) reaction(startup) {= assert_eq!(42, self.v); diff --git a/test/Rust/src/CtorParamMixed.lf b/test/Rust/src/CtorParamMixed.lf index 5de7a3dc4c..cb8536fe0a 100644 --- a/test/Rust/src/CtorParamMixed.lf +++ b/test/Rust/src/CtorParamMixed.lf @@ -1,13 +1,13 @@ target Rust reactor Print( - value: i32 = 42, - name: String = {= "xxx".into() =}, - other: bool = false + value: i32(42), + name: String({= "xxx".into() =}), + other: bool(false) ) { - state value = value - state name = name - state other = other + state value(value) + state name(name) + state other(other) reaction(startup) {= assert_eq!(42, self.value); diff --git a/test/Rust/src/CtorParamSimple.lf b/test/Rust/src/CtorParamSimple.lf index bbf38c04a0..8594adde3d 100644 --- a/test/Rust/src/CtorParamSimple.lf +++ b/test/Rust/src/CtorParamSimple.lf @@ -1,7 +1,7 @@ target Rust -reactor Print(value: i32 = 42) { - state v: i32 = value +reactor Print(value: i32(42)) { + state v: i32(value) reaction(startup) {= assert_eq!(self.v, 23); diff --git a/test/Rust/src/DependencyOnChildPort.lf b/test/Rust/src/DependencyOnChildPort.lf index ed8b6b2120..e5c9336c11 100644 --- a/test/Rust/src/DependencyOnChildPort.lf +++ b/test/Rust/src/DependencyOnChildPort.lf @@ -9,7 +9,7 @@ reactor Box { } main reactor { - state done: bool = false + state done: bool(false) box0 = new Box() box1 = new Box() diff --git a/test/Rust/src/DependencyUseOnLogicalAction.lf b/test/Rust/src/DependencyUseOnLogicalAction.lf index 6278ec76f7..bf51944c8b 100644 --- a/test/Rust/src/DependencyUseOnLogicalAction.lf +++ b/test/Rust/src/DependencyUseOnLogicalAction.lf @@ -10,7 +10,7 @@ main reactor { timer t(0, 2 msec) - state tick: u32 = 0 + state tick: u32(0) reaction(startup) -> clock, a {= ctx.schedule(a, after!(3 ms)); // out of order on purpose diff --git a/test/Rust/src/FloatLiteral.lf b/test/Rust/src/FloatLiteral.lf index b1dd37ca5e..645581c844 100644 --- a/test/Rust/src/FloatLiteral.lf +++ b/test/Rust/src/FloatLiteral.lf @@ -2,10 +2,10 @@ target Rust // This test verifies that floating-point literals are handled correctly. main reactor { - state N: f64 = 6.0221409e+23 - state charge: f64 = -1.6021766E-19 - state minus_epsilon: f64 = -.01e0 - state expected: f64 = .964853323188E5 + state N: f64(6.0221409e+23) + state charge: f64(-1.6021766E-19) + state minus_epsilon: f64(-.01e0) + state expected: f64(.964853323188E5) reaction(startup) {= let F = - self.N * self.charge; diff --git a/test/Rust/src/MainReactorParam.lf b/test/Rust/src/MainReactorParam.lf index 0c9f189548..36a78d7699 100644 --- a/test/Rust/src/MainReactorParam.lf +++ b/test/Rust/src/MainReactorParam.lf @@ -1,8 +1,8 @@ target Rust -main reactor(one: u64 = 1152921504606846976, two: u64 = {= 1 << 60 =}) { - state one = one - state two = two +main reactor(one: u64(1152921504606846976), two: u64({= 1 << 60 =})) { + state one(one) + state two(two) reaction(startup) {= assert_eq!(self.one, self.two); =} } diff --git a/test/Rust/src/MovingAverage.lf b/test/Rust/src/MovingAverage.lf index 3dcbb69c98..228c69bd17 100644 --- a/test/Rust/src/MovingAverage.lf +++ b/test/Rust/src/MovingAverage.lf @@ -7,7 +7,7 @@ target Rust { reactor Source { output out: f64 - state count: u32 = 0 + state count: u32(0) timer clock(0, 10 msec) reaction(clock) -> out {= @@ -17,8 +17,9 @@ reactor Source { } reactor MovingAverageImpl { - state delay_line: {= [f64 ; 4] =} = {= [ 0.0 ; 4 ] =} - state index: usize = 0 + // fixme inaccessible ({=[0.0 ; 4]=}); + state delay_line: f64[4](0.0, 0.0, 0.0, 0.0) + state index: usize(0) input in_: f64 output out: f64 @@ -38,7 +39,7 @@ reactor MovingAverageImpl { reactor Print { input in_: f64 - state count: usize = 0 + state count: usize(0) preamble {= const EXPECTED: [ f64 ; 6 ] = [0.0, 0.25, 0.75, 1.5, 2.5, 3.5]; diff --git a/test/Rust/src/NativeListsAndTimes.lf b/test/Rust/src/NativeListsAndTimes.lf index 79fd56e004..3e378c2e43 100644 --- a/test/Rust/src/NativeListsAndTimes.lf +++ b/test/Rust/src/NativeListsAndTimes.lf @@ -2,18 +2,18 @@ target Rust // This test passes if it is successfully compiled into valid target code. reactor Foo( - x: i32 = 0, - y: time = 0, // Units are missing but not required - z = 1 msec, // Type is missing but not required + x: i32(0), + y: time(0), // Units are missing but not required + z(1 msec), // Type is missing but not required p: i32[](1, 2, 3, 4), // List of integers - p2: i32[] = {= vec![1] =}, // List of integers with single element + p2: i32[]({= vec![1] =}), // List of integers with single element // todo // p2: i32[](1), // List of integers with single element p3: // i32[](), // Empty list of integers List of time values q: Vec(1 msec, 2 msec, 3 msec), g: time[](1 msec, 2 msec) // List of time values ) { - state s: time = y // Reference to explicitly typed time parameter - state t: time = z // Reference to implicitly typed time parameter + state s: time(y) // Reference to explicitly typed time parameter + state t: time(z) // Reference to implicitly typed time parameter state v: bool // Uninitialized boolean state variable state w: time // Uninitialized time state variable timer tick(0) // Units missing but not required @@ -29,7 +29,7 @@ reactor Foo( */ // state baz(p); // Implicit type i32[] fixme this interplays badly with // syntax for array init Implicit type time - state period = z + state period(z) state times: Vec>(q, g) // a list of lists /** diff --git a/test/Rust/src/PortConnectionInSelfInChild.lf b/test/Rust/src/PortConnectionInSelfInChild.lf index 7fd66783f1..c72b4edae0 100644 --- a/test/Rust/src/PortConnectionInSelfInChild.lf +++ b/test/Rust/src/PortConnectionInSelfInChild.lf @@ -3,7 +3,7 @@ target Rust reactor Child { input inp: i32 - state done: bool = false + state done: bool(false) reaction(inp) {= assert_eq!(ctx.get(inp), Some(76600)); diff --git a/test/Rust/src/PortConnectionInSelfOutSelf.lf b/test/Rust/src/PortConnectionInSelfOutSelf.lf index 2e33b0e498..6d012b3d62 100644 --- a/test/Rust/src/PortConnectionInSelfOutSelf.lf +++ b/test/Rust/src/PortConnectionInSelfOutSelf.lf @@ -18,7 +18,7 @@ reactor TestCase { reactor Sink { input inp: i32 - state done: bool = false + state done: bool(false) reaction(inp) {= assert_eq!(ctx.get(inp), Some(76600)); diff --git a/test/Rust/src/PortConnectionOutChildOutSelf.lf b/test/Rust/src/PortConnectionOutChildOutSelf.lf index 4d58153d97..54adbb56eb 100644 --- a/test/Rust/src/PortConnectionOutChildOutSelf.lf +++ b/test/Rust/src/PortConnectionOutChildOutSelf.lf @@ -19,7 +19,7 @@ reactor Parent { reactor Sink { input inp: i32 - state done: bool = false + state done: bool(false) reaction(inp) {= assert_eq!(ctx.get(inp), Some(76600)); @@ -33,7 +33,7 @@ reactor Sink { main reactor { parent = new Parent() - state done: bool = false + state done: bool(false) reaction(parent.out) {= assert_eq!(ctx.get(parent__out), Some(76600)); diff --git a/test/Rust/src/PortRefCleanup.lf b/test/Rust/src/PortRefCleanup.lf index 30573ceee9..65a5b415cf 100644 --- a/test/Rust/src/PortRefCleanup.lf +++ b/test/Rust/src/PortRefCleanup.lf @@ -14,8 +14,8 @@ main reactor { timer t1(0) timer t2(15 msec) - state reaction_num: u32 = 0 - state done: bool = false + state reaction_num: u32(0) + state done: bool(false) reaction(t1) -> boxr.inp {= ctx.set(boxr__inp, 150); diff --git a/test/Rust/src/PortValueCleanup.lf b/test/Rust/src/PortValueCleanup.lf index 9a11372cfb..be837c2908 100644 --- a/test/Rust/src/PortValueCleanup.lf +++ b/test/Rust/src/PortValueCleanup.lf @@ -11,8 +11,8 @@ reactor Sink { timer t2(15 msec) input in: u32 - state reaction_num: u32 = 0 - state done: bool = false + state reaction_num: u32(0) + state done: bool(false) reaction(in, t2) {= if self.reaction_num == 0 { diff --git a/test/Rust/src/ReservedKeywords.lf b/test/Rust/src/ReservedKeywords.lf index 5d30ba63a4..f1facfe8ea 100644 --- a/test/Rust/src/ReservedKeywords.lf +++ b/test/Rust/src/ReservedKeywords.lf @@ -8,14 +8,14 @@ reactor box { in -> struct - state foo: bool = true // not escaped + state foo: bool(true) // not escaped reaction(in) {= ctx.get(r#in); =} } -main reactor ReservedKeywords(struct: u32 = 0) { +main reactor ReservedKeywords(struct: u32(0)) { box = new box() timer t1(0) diff --git a/test/Rust/src/StateInitializerVisibility.lf b/test/Rust/src/StateInitializerVisibility.lf index d192f0ca98..cef728ccfa 100644 --- a/test/Rust/src/StateInitializerVisibility.lf +++ b/test/Rust/src/StateInitializerVisibility.lf @@ -3,8 +3,8 @@ target Rust main reactor { - state foo: u32 = 123 - state x: u32 = {= *&foo =} + state foo: u32(123) + state x: u32({= *&foo =}) reaction(startup) {= assert_eq!(self.x, self.foo); diff --git a/test/Rust/src/Stop.lf b/test/Rust/src/Stop.lf index c43f8c30ff..d2f380f634 100644 --- a/test/Rust/src/Stop.lf +++ b/test/Rust/src/Stop.lf @@ -13,13 +13,13 @@ target Rust { * @param break_interval: Determines how long the reactor should take a break * after sending take_a_break_after messages. */ -reactor Sender(take_a_break_after: u32 = 10, break_interval: time = 400 msec) { +reactor Sender(take_a_break_after: u32(10), break_interval: time(400 msec)) { output out: u32 logical action act - state sent_messages: u32 = 0 + state sent_messages: u32(0) - state take_a_break_after = take_a_break_after - state break_interval = break_interval + state take_a_break_after(take_a_break_after) + state break_interval(break_interval) reaction(startup, act) -> act, out {= // Send a message on out @@ -40,7 +40,7 @@ reactor Sender(take_a_break_after: u32 = 10, break_interval: time = 400 msec) { reactor Consumer { input in_: u32 - state reaction_invoked_correctly: bool = false + state reaction_invoked_correctly: bool(false) reaction(in_) {= let current_tag = ctx.get_tag(); diff --git a/test/Rust/src/StopIdempotence.lf b/test/Rust/src/StopIdempotence.lf index 1f79347758..ce9d17514f 100644 --- a/test/Rust/src/StopIdempotence.lf +++ b/test/Rust/src/StopIdempotence.lf @@ -4,7 +4,7 @@ target Rust { } main reactor StopIdempotence { - state count: u32 = 0 + state count: u32(0) reaction(startup) {= ctx.request_stop(Asap); // requested for (T0, 1) diff --git a/test/Rust/src/StopTimeoutExact.lf b/test/Rust/src/StopTimeoutExact.lf index 2b9eb85cda..37e9616fb7 100644 --- a/test/Rust/src/StopTimeoutExact.lf +++ b/test/Rust/src/StopTimeoutExact.lf @@ -9,7 +9,7 @@ target Rust { main reactor StopTimeoutExact { timer t(0, 10 msec) // the fifth triggering will coincide with the timeout - state reacted_on_shutdown: bool = false + state reacted_on_shutdown: bool(false) reaction(t) {= if ctx.get_tag() == tag!(T0 + 50 ms) { diff --git a/test/Rust/src/StructAsState.lf b/test/Rust/src/StructAsState.lf index 9b35e7a3fb..955affcc8b 100644 --- a/test/Rust/src/StructAsState.lf +++ b/test/Rust/src/StructAsState.lf @@ -15,7 +15,7 @@ main reactor StructAsState { * - state s: Hello(name: "Earth".into(), value: 42); * - state s: Hello { name: "Earth".into(), value: 42 }; */ - state s: Hello = {= Hello { name: "Earth".into(), value: 42 } =} + state s: Hello({= Hello { name: "Earth".into(), value: 42 } =}) reaction(startup) {= println!("State s.name=\"{}\", s.value={}.", self.s.name, self.s.value); diff --git a/test/Rust/src/StructAsType.lf b/test/Rust/src/StructAsType.lf index 0c8ed51456..76cee15f8e 100644 --- a/test/Rust/src/StructAsType.lf +++ b/test/Rust/src/StructAsType.lf @@ -18,9 +18,9 @@ reactor Source { =} } -reactor Print(expected: i32 = 42) { // expected parameter is for testing. +reactor Print(expected: i32(42)) { // expected parameter is for testing. input inp: {= super::source::Hello =} - state expected: i32 = expected + state expected: i32(expected) reaction(inp) {= ctx.use_ref_opt(inp, |hello| { diff --git a/test/Rust/src/TimeState.lf b/test/Rust/src/TimeState.lf index efffb00c2f..bbd80f730f 100644 --- a/test/Rust/src/TimeState.lf +++ b/test/Rust/src/TimeState.lf @@ -1,7 +1,7 @@ target Rust reactor Foo { - state baz: time = 500 msec + state baz: time(500 msec) reaction(startup) {= assert_eq!(500, self.baz.as_millis()); =} } diff --git a/test/Rust/src/TimerDefaults.lf b/test/Rust/src/TimerDefaults.lf index bbc920bf4a..3de189b62b 100644 --- a/test/Rust/src/TimerDefaults.lf +++ b/test/Rust/src/TimerDefaults.lf @@ -1,7 +1,7 @@ target Rust main reactor TimerDefaults { - state i: i32 = 0 + state i: i32(0) timer t reaction(t) {= diff --git a/test/Rust/src/TimerIsPresent.lf b/test/Rust/src/TimerIsPresent.lf index 1e87c11f51..84327c06a6 100644 --- a/test/Rust/src/TimerIsPresent.lf +++ b/test/Rust/src/TimerIsPresent.lf @@ -8,8 +8,8 @@ main reactor { timer b(1 msec, 5 msec) timer c(1 msec) - state success: bool = false - state tick: u32 = 0 + state success: bool(false) + state tick: u32(0) reaction(startup, a, b, c) {= match self.tick { diff --git a/test/Rust/src/TimerPeriodic.lf b/test/Rust/src/TimerPeriodic.lf index c6dce10a73..fc62900e7c 100644 --- a/test/Rust/src/TimerPeriodic.lf +++ b/test/Rust/src/TimerPeriodic.lf @@ -3,7 +3,7 @@ target Rust { } main reactor TimerPeriodic { - state i: i32 = 0 + state i: i32(0) timer t2(0, 3 msec) reaction(t2) {= diff --git a/test/Rust/src/Timers.lf b/test/Rust/src/Timers.lf index 1ef5fc0ae5..1043aad497 100644 --- a/test/Rust/src/Timers.lf +++ b/test/Rust/src/Timers.lf @@ -6,7 +6,7 @@ target Rust { main reactor Timers { timer t(0, 1 sec) timer t2(0, 2 sec) - state counter: i32 = 0 + state counter: i32(0) reaction(t2) {= self.counter += 2; =} diff --git a/test/Rust/src/TypeVarLengthList.lf b/test/Rust/src/TypeVarLengthList.lf index 37ff36df56..9dbf082f1f 100644 --- a/test/Rust/src/TypeVarLengthList.lf +++ b/test/Rust/src/TypeVarLengthList.lf @@ -3,7 +3,7 @@ target Rust // this thing must compile needs to be modified when // https://github.com/lf-lang/lingua-franca/discussions/492 is implemented main reactor TypeVarLengthList { - state l0: i32[] = {= Vec::new() =} // generates l0: Vec::new() + state l0: i32[]({= Vec::new() =}) // generates l0: Vec::new() // generates l1: vec![1, 2] /** * - state l2: i32[](1); // generates l2: 1 // doesn't compile... diff --git a/test/Rust/src/concurrent/AsyncCallback.lf b/test/Rust/src/concurrent/AsyncCallback.lf index dccbcf37c0..053d8ae33d 100644 --- a/test/Rust/src/concurrent/AsyncCallback.lf +++ b/test/Rust/src/concurrent/AsyncCallback.lf @@ -4,17 +4,17 @@ target Rust { cargo-features: ["cli"] } -main reactor AsyncCallback(period: time = 10 msec) { +main reactor AsyncCallback(period: time(10 msec)) { preamble {= use std::thread; =} timer t(0, period) state thread: Option> - state expected_time: time = period - state period: time = period - state toggle: bool = false + state expected_time: time(period) + state period: time(period) + state toggle: bool(false) physical action act - state i: u32 = 0 + state i: u32(0) reaction(t) -> act {= let act = act.clone(); diff --git a/test/Rust/src/generics/CtorParamGeneric.lf b/test/Rust/src/generics/CtorParamGeneric.lf index 1c8b1cab24..93646e1746 100644 --- a/test/Rust/src/generics/CtorParamGeneric.lf +++ b/test/Rust/src/generics/CtorParamGeneric.lf @@ -2,10 +2,10 @@ target Rust reactor Generic<{= T: Default + Eq + Sync + std::fmt::Debug =}>( - value: T = {= Default::default() =} + value: T({= Default::default() =}) ) { input in: T - state v: T = value + state v: T(value) reaction(in) {= ctx.use_ref_opt(r#in, |i| { diff --git a/test/Rust/src/generics/CtorParamGenericInst.lf b/test/Rust/src/generics/CtorParamGenericInst.lf index 86f696185c..63c38b2e16 100644 --- a/test/Rust/src/generics/CtorParamGenericInst.lf +++ b/test/Rust/src/generics/CtorParamGenericInst.lf @@ -5,10 +5,10 @@ target Rust reactor Generic2< {= T: Default + Eq + Sync + std::fmt::Debug + Send + 'static =} >( - value: T = {= Default::default() =} + value: T({= Default::default() =}) ) { input in: T - state v: T = value + state v: T(value) reaction(in) {= ctx.use_ref_opt(r#in, |i| { @@ -21,7 +21,7 @@ reactor Generic2< reactor Generic< {= T: Default + Eq + Sync + std::fmt::Debug + Copy + Send + 'static =} >( - value: T = {= Default::default() =} + value: T({= Default::default() =}) ) { input in: T diff --git a/test/Rust/src/generics/GenericComplexType.lf b/test/Rust/src/generics/GenericComplexType.lf deleted file mode 100644 index 67453e6530..0000000000 --- a/test/Rust/src/generics/GenericComplexType.lf +++ /dev/null @@ -1,22 +0,0 @@ -// tests that the time type can be nested in type arguments. -target Rust - -reactor R { - input in: Vec