From 14e8c9b3d325bd5dd473bebe40a8b74a00ab29fc Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 10:49:30 +0100 Subject: [PATCH 01/58] add basic expression syntax --- org.lflang/src/org/lflang/LinguaFranca.xtext | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 6e071503cd..b623a4cba5 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -304,6 +304,17 @@ Parameter: Value: (parameter=[Parameter] | time=Time | literal=Literal | code=Code); +Expression: + Literal + | Time + | ParameterReference + | Code +; + +ParameterReference: + parameter=[Parameter] +; + Time: (interval=INT unit=TimeUnit) ; From 9a1427bc1d91fd260a02fd41400d5f713c704849 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 12:53:52 +0100 Subject: [PATCH 02/58] replace Value with Expressions in the grammar --- org.lflang/src/org/lflang/LinguaFranca.xtext | 33 +++++++++----------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index b623a4cba5..659a82ded0 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -117,10 +117,10 @@ TargetDecl: /** * Declaration of a state variable. Types are optional, but may be required * during validation (depending on the target language). Initialization is also - * optional. A state variable can be initialized by assigning a `Value` or list - * of these. Note that a `Value` may also be a reference to a parameter. + * optional. A state variable can be initialized by assigning a `Expression` or list + * of these. Note that a `Expression` may also be a reference to a parameter. * The following checks must be carried out during validation: - * - if the list of initialization values has more than one element in it, a + * - if the list of initialization expressions has more than one element in it, a * type must be specified; * - if the `time` type is specified, there can only be a single initialization * element, which has to denote a time or a reference to a parameter that @@ -131,8 +131,8 @@ TargetDecl: StateVar: 'state' name=ID ( (':' (type=Type))? - ((parens+='(' (init+=Value (',' init+=Value)*)? parens+=')') - | (braces+='{' (init+=Value (',' init+=Value)*)? braces+='}') + ((parens+='(' (init+=Expression (',' init+=Expression)*)? parens+=')') + | (braces+='{' (init+=Expression (',' init+=Expression)*)? braces+='}') )? ) ';'? ; @@ -160,7 +160,7 @@ Output: // E.g. (0) or (NOW) or (NOW, ONCE) or (100, 1000) // The latter means fire with period 1000, offset 100. Timer: - 'timer' name=ID ('(' offset=Value (',' period=Value)? ')')? ';'?; + 'timer' name=ID ('(' offset=Expression (',' period=Expression)? ')')? ';'?; Boolean: TRUE | FALSE @@ -189,7 +189,7 @@ Mode: // the tags of two subsequently scheduled events. Action: (origin=ActionOrigin)? 'action' name=ID - ('(' minDelay=Value (',' minSpacing=Value (',' policy=STRING)? )? ')')? + ('(' minDelay=Expression (',' minSpacing=Expression (',' policy=STRING)? )? ')')? (':' type=Type)? ';'?; Reaction: @@ -205,10 +205,10 @@ TriggerRef: VarRef | startup?='startup' | shutdown?='shutdown'; Deadline: - 'deadline' '(' delay=Value ')' code=Code; + 'deadline' '(' delay=Expression ')' code=Code; STP: - 'STP' '(' value=Value ')' code=Code; + 'STP' '(' value=Expression ')' code=Code; Mutation: ('mutation') @@ -285,10 +285,10 @@ VarRefOrModeTransition returns VarRef: Assignment: (lhs=[Parameter] ( - (equals='=' rhs+=Value) + (equals='=' rhs+=Expression) | ((equals='=')? ( - parens+='(' (rhs+=Value (',' rhs+=Value)*)? parens+=')' - | braces+='{' (rhs+=Value (',' rhs+=Value)*)? braces+='}')) + parens+='(' (rhs+=Expression (',' rhs+=Expression)*)? parens+=')' + | braces+='{' (rhs+=Expression (',' rhs+=Expression)*)? braces+='}')) )); /** @@ -296,16 +296,13 @@ Assignment: */ Parameter: name=ID (':' (type=Type))? - ((parens+='(' (init+=Value (',' init+=Value)*)? parens+=')') - | (braces+='{' (init+=Value (',' init+=Value)*)? braces+='}') + ((parens+='(' (init+=Expression (',' init+=Expression)*)? parens+=')') + | (braces+='{' (init+=Expression (',' init+=Expression)*)? braces+='}') )? ; -Value: - (parameter=[Parameter] | time=Time | literal=Literal | code=Code); - Expression: - Literal + {Literal} literal = Literal | Time | ParameterReference | Code From a4989a5ecf5e9a5b7a6f1f02c1bdf387608a9aeb Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 13:22:53 +0100 Subject: [PATCH 03/58] Use Expression instead of Value in ASTUtils --- org.lflang/src/org/lflang/ASTUtils.java | 161 ++++++++++++------------ 1 file changed, 79 insertions(+), 82 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 7a31ab9366..680753d30a 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -68,15 +68,18 @@ import org.lflang.lf.Connection; import org.lflang.lf.Delay; import org.lflang.lf.Element; +import org.lflang.lf.Expression; import org.lflang.lf.ImportedReactor; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.LfPackage; +import org.lflang.lf.Literal; import org.lflang.lf.Mode; import org.lflang.lf.Model; import org.lflang.lf.Output; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Port; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; @@ -87,7 +90,6 @@ import org.lflang.lf.Timer; import org.lflang.lf.Type; import org.lflang.lf.TypeParm; -import org.lflang.lf.Value; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; @@ -439,13 +441,13 @@ private static Instantiation getDelayInstance(Reactor delayClass, } Assignment assignment = factory.createAssignment(); assignment.setLhs(delayClass.getParameters().get(0)); - Value value = factory.createValue(); if (delay.getParameter() != null) { - value.setParameter(delay.getParameter()); + var expr = factory.createParameterReference(); + expr.setParameter(delay.getParameter()); + assignment.getRhs().add(expr); } else { - value.setTime(delay.getTime()); + assignment.getRhs().add(delay.getTime()); } - assignment.getRhs().add(value); delayInstance.getParameters().add(assignment); delayInstance.setName("delay"); // This has to be overridden. return delayInstance; @@ -495,14 +497,13 @@ private static Reactor getDelayClass(Type type, GeneratorBase generator) { Time defaultTime = factory.createTime(); defaultTime.setUnit(null); defaultTime.setInterval(0); - Value defaultValue = factory.createValue(); - defaultValue.setTime(defaultTime); - delayParameter.getInit().add(defaultValue); + delayParameter.getInit().add(defaultTime); // Name the newly created action; set its delay and type. action.setName("act"); - action.setMinDelay(factory.createValue()); - action.getMinDelay().setParameter(delayParameter); + var paramRef = factory.createParameterReference(); + paramRef.setParameter(delayParameter); + action.setMinDelay(paramRef); action.setOrigin(ActionOrigin.LOGICAL); if (generator.getTargetTypes().supportsGenerics()) { @@ -895,26 +896,24 @@ public static String toText(Time t) { } /** - * Convert a value to its textual representation as it would + * Convert an expression to its textual representation as it would * appear in LF code. * - * @param v The value to be converted + * @param expr The expression to be converted * @return A textual representation */ - public static String toText(Value v) { - if (v.getParameter() != null) { - return v.getParameter().getName(); - } - if (v.getTime()!= null) { - return toText(v.getTime()); - } - if (v.getLiteral() != null) { - return v.getLiteral(); - } - if (v.getCode() != null) { - return toText(v.getCode()); + public static String toText(Expression expr) { + if (expr instanceof ParameterReference) { + return ((ParameterReference) expr).getParameter().getName(); + } else if (expr instanceof Time ) { + return toText((Time) expr); + } else if (expr instanceof Literal) { + return ((Literal) expr).getLiteral(); + } else if (expr instanceof Code) { + return toText((Code) expr); + } else { + throw new RuntimeException("Unknown expression type!"); } - return ""; } public static String toText(Delay d) { @@ -1043,22 +1042,22 @@ public static boolean isZero(String literal) { public static boolean isZero(Code code) { return code != null && isZero(toUntaggedText(code)); } - + /** - * Report whether the given value is zero or not. - * @param value AST node to inspect. + * Report whether the given expression is zero or not. + * + * @param expr AST node to inspect. * @return True if the given value denotes the constant `0`, false otherwise. */ - public static boolean isZero(Value value) { - if (value.getLiteral() != null) { - return isZero(value.getLiteral()); - } else if (value.getCode() != null) { - return isZero(value.getCode()); + public static boolean isZero(Expression expr) { + if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isZero((Code) expr); } return false; } - - + /** * Report whether the given string literal is an integer number or not. * @param literal AST node to inspect. @@ -1084,36 +1083,34 @@ public static boolean isInteger(Code code) { } /** - * Report whether the given value is an integer number or not. - * @param value AST node to inspect. + * Report whether the given expression is an integer number or not. + * @param expr AST node to inspect. * @return True if the given value is an integer, false otherwise. */ - public static boolean isInteger(Value value) { - if (value.getLiteral() != null) { - return isInteger(value.getLiteral()); - } else if (value.getCode() != null) { - return isInteger(value.getCode()); + public static boolean isInteger(Expression expr) { + if (expr instanceof Literal) { + return isInteger(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isInteger((Code) expr); } return false; } /** - * Report whether the given value denotes a valid time or not. - * @param value AST node to inspect. + * Report whether the given expression denotes a valid time or not. + * @param expr AST node to inspect. * @return True if the argument denotes a valid time, false otherwise. */ - public static boolean isValidTime(Value value) { - if (value != null) { - if (value.getParameter() != null) { - return isOfTimeType(value.getParameter()); - } else if (value.getTime() != null) { - return isValidTime(value.getTime()); - } else if (value.getLiteral() != null) { - return isZero(value.getLiteral()); - } else if (value.getCode() != null) { - return isZero(value.getCode()); + public static boolean isValidTime(Expression expr) { + if (expr instanceof ParameterReference) { + return isOfTimeType(((ParameterReference)expr).getParameter()); + } else if (expr instanceof Time) { + return isValidTime((Time) expr); + } else if (expr instanceof Literal) { + return isZero(((Literal) expr).getLiteral()); + } else if (expr instanceof Code) { + return isZero((Code) expr); } - } return false; } @@ -1138,11 +1135,11 @@ public static boolean isValidTime(Time t) { * "undefined" type if neither can be inferred. * * @param type Explicit type declared on the declaration - * @param initList A list of values used to initialize a parameter or + * @param initList A list of expressions used to initialize a parameter or * state variable. * @return The inferred type, or "undefined" if none could be inferred. */ - public static InferredType getInferredType(Type type, List initList) { + public static InferredType getInferredType(Type type, List initList) { if (type != null) { return InferredType.fromAST(type); } else if (initList == null) { @@ -1152,10 +1149,10 @@ public static InferredType getInferredType(Type type, List initList) { if (initList.size() == 1) { // If there is a single element in the list, and it is a proper // time value with units, we infer the type "time". - Value init = initList.get(0); - if (init.getParameter() != null) { - return getInferredType(init.getParameter()); - } else if (ASTUtils.isValidTime(init) && !ASTUtils.isZero(init)) { + Expression expr = initList.get(0); + if (expr instanceof ParameterReference) { + return getInferredType(((ParameterReference)expr).getParameter()); + } else if (ASTUtils.isValidTime(expr) && !ASTUtils.isZero(expr)) { return InferredType.time(); } } else if (initList.size() > 1) { @@ -1166,11 +1163,11 @@ public static InferredType getInferredType(Type type, List initList) { var allValidTime = true; var foundNonZero = false; - for (var init : initList) { - if (!ASTUtils.isValidTime(init)) { + for (var expr : initList) { + if (!ASTUtils.isValidTime(expr)) { allValidTime = false; } - if (!ASTUtils.isZero(init)) { + if (!ASTUtils.isZero(expr)) { foundNonZero = true; } } @@ -1276,13 +1273,13 @@ public static String generateVarRef(VarRef reference) { } /** - * Assuming that the given value denotes a valid time literal, + * Assuming that the given expression denotes a valid time literal, * return a time value. */ - public static TimeValue getLiteralTimeValue(Value v) { - if (v.getTime() != null) { - return toTimeValue(v.getTime()); - } else if (v.getLiteral() != null && v.getLiteral().equals("0")) { + public static TimeValue getLiteralTimeValue(Expression expr) { + if (expr instanceof Time) { + return toTimeValue((Time)expr); + } else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) { return TimeValue.ZERO; } else { return null; @@ -1326,8 +1323,7 @@ public static boolean isOfTimeType(Parameter param) { /** * Given a parameter, return its initial value. - * The initial value is a list of instances of Value, where each - * Value is either an instance of Time, Literal, or Code. + * The initial value is a list of instances of Expressions. * * If the instantiations argument is null or an empty list, then the * value returned is simply the default value given when the parameter @@ -1398,7 +1394,7 @@ public static boolean isOfTimeType(Parameter param) { * instantiation of the reactor class that is parameterized by the * respective parameter or if the chain of instantiations is not nested. */ - public static List initialValue(Parameter parameter, List instantiations) { + public static List initialValue(Parameter parameter, List instantiations) { // If instantiations are given, then check to see whether this parameter gets overridden in // the first of those instantiations. if (instantiations != null && instantiations.size() > 0) { @@ -1424,9 +1420,9 @@ public static List initialValue(Parameter parameter, List } if (lastAssignment != null) { // Right hand side can be a list. Collect the entries. - List result = new ArrayList<>(); - for (Value value: lastAssignment.getRhs()) { - if (value.getParameter() != null) { + List result = new ArrayList<>(); + for (Expression expr: lastAssignment.getRhs()) { + if (expr instanceof ParameterReference) { if (instantiations.size() > 1 && instantiation.eContainer() != instantiations.get(1).getReactorClass() ) { @@ -1437,10 +1433,10 @@ public static List initialValue(Parameter parameter, List + "." ); } - result.addAll(initialValue(value.getParameter(), + result.addAll(initialValue(((ParameterReference)expr).getParameter(), instantiations.subList(1, instantiations.size()))); } else { - result.add(value); + result.add(expr); } } return result; @@ -1499,14 +1495,15 @@ public static boolean belongsTo(EObject eobject, Reactor reactor) { * respective parameter or if the chain of instantiations is not nested. */ public static Integer initialValueInt(Parameter parameter, List instantiations) { - List values = initialValue(parameter, instantiations); + List expressions = initialValue(parameter, instantiations); int result = 0; - for (Value value: values) { - if (value.getLiteral() == null) { + for (Expression expr: expressions) { + if (!(expr instanceof Literal)) { return null; } try { - result += Integer.decode(value.getLiteral()); + // FIXME: why does this sum the values in the list?? + result += Integer.decode(((Literal) expr).getLiteral()); } catch (NumberFormatException ex) { return null; } @@ -1767,7 +1764,7 @@ public static boolean isInitialized(StateVar v) { */ public static boolean isParameterized(StateVar s) { return s.getInit() != null && - IterableExtensions.exists(s.getInit(), it -> it.getParameter() != null); + IterableExtensions.exists(s.getInit(), it -> it instanceof ParameterReference); } /** From 50ded1d13b7ee6c909476b75bab828c6d64c3c66 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 13:38:43 +0100 Subject: [PATCH 04/58] fix various occurrences of Value in Kotlin code --- org.lflang/src/org/lflang/AstExtensions.kt | 28 ++------------- .../src/org/lflang/generator/TargetTypes.java | 36 ++++++++++--------- .../org/lflang/generator/cpp/CppExtensions.kt | 32 ++++++++++++----- .../org/lflang/generator/rust/RustTypes.kt | 6 ++-- 4 files changed, 49 insertions(+), 53 deletions(-) diff --git a/org.lflang/src/org/lflang/AstExtensions.kt b/org.lflang/src/org/lflang/AstExtensions.kt index efeb0994c8..e73a937a31 100644 --- a/org.lflang/src/org/lflang/AstExtensions.kt +++ b/org.lflang/src/org/lflang/AstExtensions.kt @@ -28,7 +28,6 @@ import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.resource.Resource import org.eclipse.xtext.nodemodel.util.NodeModelUtils import org.lflang.lf.* -import java.nio.file.Path /** * If this reactor declaration is an import, then @@ -184,19 +183,13 @@ fun TriggerRef.toText(): String = /** - * Convert a value to its textual representation as it would + * Convert an expression to its textual representation as it would * appear in LF code. * * @receiver The value to be converted * @return A textual representation */ -fun Value.toText(): String = - parameter?.name - ?: time?.toText() - ?: literal - ?: code?.toText() - ?: "" - +fun Expression.toText(): String = ASTUtils.toText(this) /** * Convert a time to its textual representation as it would @@ -226,16 +219,6 @@ fun ArraySpec.toText(): String = */ fun Type.toText(): String = baseType + arraySpec?.toText().orEmpty() -/** - * Produce a unique identifier within a reactor based on a - * given based name. If the name does not exists, it is returned; - * if does exist, an index is appended that makes the name unique. - * @receiver The reactor to find a unique identifier within. - * @param name The name to base the returned identifier on. - */ -fun Reactor.getUniqueIdentifier(name: String): String = - ASTUtils.getUniqueIdentifier(this, name) - /** * Translate the given type into its textual representation, but * do not append any array specifications. @@ -265,11 +248,7 @@ val Code.isZero: Boolean get() = this.toText().isZero * @receiver AST node to inspect. * @return True if the given value denotes the constant `0`, false otherwise. */ -val Value.isZero: Boolean - get() = - this.literal?.isZero - ?: this.code?.isZero - ?: false +val Expression.isZero: Boolean get() = ASTUtils.isZero(this) /** * Given a parameter, return an inferred type. Only two types can be @@ -391,7 +370,6 @@ val Reaction.containingReactor get() = this.eContainer() as Reactor val Port.isInput get() = this is Input val Assignment.isInitWithBraces get() = braces.isNotEmpty() -val StateVar.isInitWithBraces get() = braces.isNotEmpty() val Parameter.isInitWithBraces get() = braces.isNotEmpty() /** diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/src/org/lflang/generator/TargetTypes.java index 82925c4a95..19a9ebfea8 100644 --- a/org.lflang/src/org/lflang/generator/TargetTypes.java +++ b/org.lflang/src/org/lflang/generator/TargetTypes.java @@ -6,23 +6,25 @@ import org.lflang.ASTUtils; import org.lflang.InferredType; -import org.lflang.ASTUtils; import org.lflang.TimeUnit; import org.lflang.TimeValue; import org.lflang.lf.Action; +import org.lflang.lf.Code; +import org.lflang.lf.Expression; +import org.lflang.lf.Literal; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Port; import org.lflang.lf.StateVar; import org.lflang.lf.Time; import org.lflang.lf.Type; -import org.lflang.lf.Value; /** * Information about the types of a target language. Contains * utilities to convert LF expressions and types to the target * language. Each code generator is expected to use at least one * language-specific instance of this interface. - * + *

* TODO currently, {@link GeneratorBase} implements this interface, * it should instead contain an instance. * @@ -128,7 +130,7 @@ default String getMissingExpr(InferredType type) { * initializer list. If both are absent, then the undefined * type is returned. */ - default String getTargetType(Type type, List init) { + default String getTargetType(Type type, List init) { return getTargetType(ASTUtils.getInferredType(type, init)); } @@ -205,7 +207,7 @@ default String getTargetType(Port p) { * @param type Declared type of the expression (nullable) * @param initWithBraces Whether the initializer uses the braced form. */ - default String getTargetInitializer(List init, Type type, boolean initWithBraces) { + default String getTargetInitializer(List init, Type type, boolean initWithBraces) { Objects.requireNonNull(init); var inferredType = ASTUtils.getInferredType(type, init); if (init.size() == 1) { @@ -223,22 +225,22 @@ default String getTargetInitializer(List init, Type type, boolean initWit /** - * Returns the representation of the given value in target code. + * Returns the representation of the given expression in target code. * The given type, if non-null, may inform the code generation. */ - default String getTargetExpr(Value value, InferredType type) { - if (ASTUtils.isZero(value) && type != null && type.isTime) { + default String getTargetExpr(Expression expr, InferredType type) { + if (ASTUtils.isZero(expr) && type != null && type.isTime) { return getTargetTimeExpr(TimeValue.ZERO); - } else if (value.getParameter() != null) { - return escapeIdentifier(value.getParameter().getName()); - } else if (value.getTime() != null) { - return getTargetTimeExpr(value.getTime()); - } else if (value.getLiteral() != null) { - return ASTUtils.addZeroToLeadingDot(value.getLiteral()); // here we don't escape - } else if (value.getCode() != null) { - return ASTUtils.toText(value.getCode()); + } else if (expr instanceof ParameterReference) { + return escapeIdentifier(((ParameterReference) expr).getParameter().getName()); + } else if (expr instanceof Time) { + return getTargetTimeExpr((Time) expr); + } else if (expr instanceof Literal) { + return ASTUtils.addZeroToLeadingDot(((Literal) expr).getLiteral()); // here we don't escape + } else if (expr instanceof Code) { + return ASTUtils.toText((Code) expr); } else { - throw new IllegalStateException("Invalid value " + value); + throw new IllegalStateException("Invalid value " + expr); } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt index 31eb1356af..330d0a579b 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt @@ -1,10 +1,26 @@ package org.lflang.generator.cpp import org.eclipse.emf.ecore.resource.Resource -import org.lflang.* -import org.lflang.lf.* -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter +import org.lflang.InferredType +import org.lflang.TargetProperty +import org.lflang.TimeValue +import org.lflang.indexInContainer +import org.lflang.isBank +import org.lflang.isGeneric +import org.lflang.isMultiport +import org.lflang.lf.Expression +import org.lflang.lf.LfPackage +import org.lflang.lf.Parameter +import org.lflang.lf.Port +import org.lflang.lf.Preamble +import org.lflang.lf.Reaction +import org.lflang.lf.Reactor +import org.lflang.lf.TriggerRef +import org.lflang.lf.VarRef +import org.lflang.lf.Visibility +import org.lflang.lf.WidthSpec +import org.lflang.toText +import org.lflang.unreachable /************* * Copyright (c) 2019-2021, TU Dresden. @@ -58,8 +74,8 @@ fun TimeValue.toCppCode() = CppTypes.getTargetTimeExpr(this) * @param outerContext A flag indicating whether to generate code for the scope of the outer reactor class. * This should be set to false if called from code generators for the inner class. */ -fun Value.toTime(outerContext: Boolean = false): String = - if (outerContext && this.parameter != null) "__lf_inner.${parameter.name}" +fun Expression.toTime(outerContext: Boolean = false): String = + if (outerContext && this is Parameter) "__lf_inner.${this.name}" else CppTypes.getTargetExpr(this, InferredType.time()) /** @@ -67,7 +83,7 @@ fun Value.toTime(outerContext: Boolean = false): String = * * If the value evaluates to 0, it is interpreted as a normal value. */ -fun Value.toCppCode(): String = CppTypes.getTargetExpr(this, null) +fun Expression.toCppCode(): String = CppTypes.getTargetExpr(this, null) /** Get the textual representation of a width in C++ code */ fun WidthSpec.toCppCode(): String = terms.joinToString(" + ") { @@ -78,7 +94,7 @@ fun WidthSpec.toCppCode(): String = terms.joinToString(" + ") { if ((variable as Port).isMultiport) "(${container.name}.size() * ${container.name}[0]->${variable.name}.size())" else "${container.name}.size()" } else { - if ((variable as Port).isMultiport) "${name}.size()" + if ((variable as Port).isMultiport) "$name.size()" else "1" } } diff --git a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt index 2401c966e4..fcaf913961 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt @@ -52,10 +52,10 @@ object RustTypes : TargetTypes { if (ident in RustKeywords) "r#$ident" else ident - override fun getTargetExpr(value: Value, type: InferredType?): String = when { + override fun getTargetExpr(expr: Value, type: InferredType?): String = when { // wrap in a block to enable writing several statements - value.code != null -> value.code.toText().inBlock() - else -> super.getTargetExpr(value, type) + expr.code != null -> expr.code.toText().inBlock() + else -> super.getTargetExpr(expr, type) } override fun getTargetTimeExpr(timeValue: TimeValue): TargetCode = with(timeValue) { From 4fe7f28cc782a9c8762d7b4b18a387d7862f9d29 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 14:02:19 +0100 Subject: [PATCH 05/58] fix all kotlin code --- .../lflang/generator/cpp/CppStateGenerator.kt | 7 +++--- .../org/lflang/generator/rust/RustModel.kt | 25 +++++++++---------- .../org/lflang/generator/rust/RustTypes.kt | 12 ++++----- .../lflang/generator/ts/TSActionGenerator.kt | 9 ++++--- .../org/lflang/generator/ts/TSGenerator.kt | 4 +-- .../generator/ts/TSReactionGenerator.kt | 9 ++++--- .../lflang/generator/ts/TSTimerGenerator.kt | 7 +++--- 7 files changed, 37 insertions(+), 36 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt index d7e62102dd..da6ccfbf89 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt @@ -27,6 +27,7 @@ package org.lflang.generator.cpp import org.lflang.inferredType import org.lflang.isInitialized import org.lflang.isOfTimeType +import org.lflang.lf.ParameterReference import org.lflang.lf.Reactor import org.lflang.lf.StateVar @@ -40,9 +41,9 @@ class CppStateGenerator(private val reactor: Reactor) { */ private fun getInitializerList(state: StateVar) = state.init.map { when { - it.parameter != null -> it.parameter.name - state.isOfTimeType -> it.toTime() - else -> it.toCppCode() + it is ParameterReference -> it.parameter.name + state.isOfTimeType -> it.toTime() + else -> it.toCppCode() } } diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 20f7e3eff5..2d47becd69 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -309,13 +309,13 @@ sealed class ReactorComponent { * Since there's no reasonable common supertype we use [Variable], but maybe we should * have another interface. */ - fun from(v: Variable): ReactorComponent? = when (v) { + fun from(v: Variable): ReactorComponent = when (v) { is Port -> PortData.from(v) is Action -> ActionData( lfName = v.name, isLogical = v.isLogical, dataType = RustTypes.getTargetType(v.type), - minDelay = v.minDelay?.time?.let(RustTypes::getTargetTimeExpr) + minDelay = (v.minDelay as? Time)?.let(RustTypes::getTargetTimeExpr) ) is Timer -> TimerData( lfName = v.name, @@ -325,17 +325,16 @@ sealed class ReactorComponent { else -> throw UnsupportedGeneratorFeatureException("Dependency on ${v.javaClass.simpleName} $v") } - private fun Value?.toTimerTimeValue(): TargetCode = + private fun Expression?.toTimerTimeValue(): TargetCode = when { - this == null -> "Duration::from_millis(0)" - parameter != null -> "${parameter.name}.clone()" - literal != null -> - literal.toIntOrNull() - ?.let { TimeValue(it.toLong(), DEFAULT_TIME_UNIT_IN_TIMER).toRustTimeExpr() } - ?: throw InvalidLfSourceException("Not an integer literal", this) - time != null -> time.toRustTimeExpr() - code != null -> code.toText().inBlock() - else -> RustTypes.getTargetExpr(this, InferredType.time()) + this == null -> "Duration::from_millis(0)" + this is ParameterReference -> "${parameter.name}.clone()" + this is Literal -> literal.toIntOrNull() + ?.let { TimeValue(it.toLong(), DEFAULT_TIME_UNIT_IN_TIMER).toRustTimeExpr() } + ?: throw InvalidLfSourceException("Not an integer literal", this) + this is Time -> toRustTimeExpr() + this is Code -> toText().inBlock() + else -> RustTypes.getTargetExpr(this, InferredType.time()) } } } @@ -500,7 +499,7 @@ object RustModelBuilder { val components = mutableMapOf() val allComponents: List = reactor.allComponents() for (component in allComponents) { - val irObj = ReactorComponent.from(component) ?: continue + val irObj = ReactorComponent.from(component) components[irObj.lfName] = irObj } diff --git a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt index fcaf913961..f555aff7fb 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt @@ -24,13 +24,14 @@ package org.lflang.generator.rust +import org.lflang.ASTUtils.toText import org.lflang.InferredType import org.lflang.TimeValue import org.lflang.generator.TargetCode import org.lflang.generator.TargetTypes import org.lflang.inBlock -import org.lflang.lf.Value -import org.lflang.toText +import org.lflang.lf.Code +import org.lflang.lf.Expression object RustTypes : TargetTypes { @@ -52,10 +53,9 @@ object RustTypes : TargetTypes { if (ident in RustKeywords) "r#$ident" else ident - override fun getTargetExpr(expr: Value, type: InferredType?): String = when { - // wrap in a block to enable writing several statements - expr.code != null -> expr.code.toText().inBlock() - else -> super.getTargetExpr(expr, type) + override fun getTargetExpr(expr: Expression, type: InferredType?): String = when (expr) { + is Code -> toText(expr).inBlock() + else -> super.getTargetExpr(expr, type) } override fun getTargetTimeExpr(timeValue: TimeValue): TargetCode = with(timeValue) { diff --git a/org.lflang/src/org/lflang/generator/ts/TSActionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSActionGenerator.kt index d3bb1a2f0a..bcb2aa644e 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSActionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSActionGenerator.kt @@ -1,8 +1,9 @@ package org.lflang.generator.ts import org.lflang.lf.Action +import org.lflang.lf.Expression +import org.lflang.lf.ParameterReference import org.lflang.lf.Type -import org.lflang.lf.Value import java.util.* /** @@ -13,7 +14,7 @@ class TSActionGenerator ( private val tsGenerator: TSGenerator, private val actions: List ) { - private fun Value.getTargetValue(): String = tsGenerator.getTargetValueW(this) + private fun Expression.getTargetValue(): String = tsGenerator.getTargetValueW(this) private fun Type.getTargetType(): String = tsGenerator.getTargetTypeW(this) /** @@ -63,8 +64,8 @@ class TSActionGenerator ( if (action.minDelay != null) { // Actions in the TypeScript target are constructed // with an optional minDelay argument which defaults to 0. - if (action.minDelay.parameter != null) { - actionArgs+= ", " + action.minDelay.parameter.name + if (action.minDelay is ParameterReference) { + actionArgs+= ", " + (action.minDelay as ParameterReference).parameter.name } else { actionArgs+= ", " + action.minDelay.getTargetValue() } diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 93418b36da..dfe0449b5e 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -49,11 +49,11 @@ import org.lflang.generator.GeneratorUtils.canGenerate import org.lflang.inferredType import org.lflang.lf.Action import org.lflang.lf.Delay +import org.lflang.lf.Expression import org.lflang.lf.Instantiation import org.lflang.lf.Parameter import org.lflang.lf.StateVar import org.lflang.lf.Type -import org.lflang.lf.Value import org.lflang.lf.VarRef import org.lflang.scoping.LFGlobalScopeProvider import org.lflang.util.FileUtil @@ -127,7 +127,7 @@ class TSGenerator( // Wrappers to expose GeneratorBase methods. fun federationRTIPropertiesW() = federationRTIProperties - fun getTargetValueW(v: Value): String = VG.getTargetValue(v, false) + fun getTargetValueW(expr: Expression): String = VG.getTargetValue(expr, false) fun getTargetTypeW(p: Parameter): String = TSTypes.getTargetType(p.inferredType) fun getTargetTypeW(state: StateVar): String = TSTypes.getTargetType(state) fun getTargetTypeW(t: Type): String = TSTypes.getTargetType(t) diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt index 02e54732fb..96b9a0d364 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt @@ -26,7 +26,7 @@ class TSReactionGenerator( private val reactor : Reactor, private val federate: FederateInstance ) { - private fun Value.getTargetValue(): String = tsGenerator.getTargetValueW(this) + private fun Expression.getTargetExpression(): String = tsGenerator.getTargetValueW(this) private fun Parameter.getTargetType(): String = tsGenerator.getTargetTypeW(this) private fun StateVar.getTargetType(): String = tsGenerator.getTargetTypeW(this) private fun Type.getTargetType(): String = tsGenerator.getTargetTypeW(this) @@ -78,10 +78,11 @@ class TSReactionGenerator( reactSignature: StringJoiner ): String { var deadlineArgs = "" - if (reaction.deadline.delay.parameter != null) { - deadlineArgs += "this.${reaction.deadline.delay.parameter.name}.get()"; + val delay = reaction.deadline.delay + if (delay is ParameterReference) { + deadlineArgs += "this.${delay.parameter.name}.get()"; } else { - deadlineArgs += reaction.deadline.delay.getTargetValue() + deadlineArgs += delay.getTargetExpression() } return with(PrependOperator) { diff --git a/org.lflang/src/org/lflang/generator/ts/TSTimerGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSTimerGenerator.kt index 4039716297..0d47872142 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSTimerGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSTimerGenerator.kt @@ -1,8 +1,7 @@ -package org.lflang.generator.ts; +package org.lflang.generator.ts -import org.lflang.generator.PrependOperator +import org.lflang.lf.Expression import org.lflang.lf.Timer -import org.lflang.lf.Value import java.util.* /** @@ -13,7 +12,7 @@ class TSTimerGenerator ( private val tsGenerator: TSGenerator, private val timers: List ) { - private fun Value.getTargetValue(): String = tsGenerator.getTargetValueW(this) + private fun Expression.getTargetValue(): String = tsGenerator.getTargetValueW(this) fun generateClassProperties(): String { val timerClassProperties = LinkedList() From 12e8e0441e7a31990054122575c1d3e37d98d8e1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 14:59:29 +0100 Subject: [PATCH 06/58] update all occurences of Value in Java code --- org.lflang/src/org/lflang/ModelInfo.java | 10 +- .../src/org/lflang/federated/FedASTUtils.java | 20 ++-- .../org/lflang/generator/GeneratorBase.java | 30 ++--- .../lflang/generator/ParameterInstance.java | 4 +- .../org/lflang/generator/ReactorInstance.java | 17 +-- .../org/lflang/generator/ValueGenerator.java | 46 ++++---- .../generator/c/CParameterGenerator.java | 18 +-- .../org/lflang/generator/python/PyUtil.java | 15 +-- .../python/PythonParameterGenerator.java | 22 ++-- .../python/PythonStateGenerator.java | 3 - .../org/lflang/validation/LFValidator.java | 110 +++++++++--------- 11 files changed, 150 insertions(+), 145 deletions(-) diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/src/org/lflang/ModelInfo.java index dda094baaf..79fc222cfb 100644 --- a/org.lflang/src/org/lflang/ModelInfo.java +++ b/org.lflang/src/org/lflang/ModelInfo.java @@ -39,9 +39,11 @@ import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Assignment; import org.lflang.lf.Deadline; +import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.Model; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; import org.lflang.lf.STP; @@ -162,7 +164,7 @@ private void collectOverflowingNodes() { } // If any of the upstream parameters overflow, report this deadline. - if (detectOverflow(new HashSet<>(), deadline.getDelay().getParameter())) { + if (detectOverflow(new HashSet<>(), ((ParameterReference)deadline.getDelay()).getParameter())) { this.overflowingDeadlines.add(deadline); } } @@ -211,10 +213,10 @@ private boolean detectOverflow(Set visited, Parameter current) { // Find assignments that override the current parameter. for (var assignment : instantiation.getParameters()) { if (assignment.getLhs().equals(current)) { - Parameter parameter = assignment.getRhs().get(0).getParameter(); - if (parameter != null) { + Expression expr = assignment.getRhs().get(0); + if (expr instanceof ParameterReference) { // Check for overflow in the referenced parameter. - overflow = detectOverflow(visited, parameter) || overflow; + overflow = detectOverflow(visited, ((ParameterReference)expr).getParameter()) || overflow; } else { // The right-hand side of the assignment is a // constant; check whether it is too large. diff --git a/org.lflang/src/org/lflang/federated/FedASTUtils.java b/org.lflang/src/org/lflang/federated/FedASTUtils.java index 55a05f2bc2..a51a16e071 100644 --- a/org.lflang/src/org/lflang/federated/FedASTUtils.java +++ b/org.lflang/src/org/lflang/federated/FedASTUtils.java @@ -38,7 +38,6 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.lflang.ASTUtils; import org.lflang.InferredType; -import org.lflang.ASTUtils; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TimeValue; import org.lflang.federated.serialization.SupportedSerializers; @@ -48,13 +47,13 @@ import org.lflang.lf.ActionOrigin; import org.lflang.lf.Connection; import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; -import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.Type; -import org.lflang.lf.Value; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; @@ -126,8 +125,7 @@ private static Action createNetworkAction( // provided using after is enforced by setting // the minDelay. if (connection.getDelay() != null) { - action.setMinDelay(factory.createValue()); - action.getMinDelay().setTime(connection.getDelay().getTime()); + action.setMinDelay(connection.getDelay().getTime()); } } else { action.setOrigin(ActionOrigin.LOGICAL); @@ -367,7 +365,7 @@ private static TimeValue findMaxSTP(Variable port, FederateInstance instance, GeneratorBase generator, Reactor reactor) { // Find a list of STP offsets (if any exists) - List STPList = new LinkedList<>(); + List STPList = new LinkedList<>(); // First, check if there are any connections to contained reactors that // need to be handled @@ -405,10 +403,11 @@ private static TimeValue findMaxSTP(Variable port, // If STP offset is determined, add it // If not, assume it is zero if (r.getStp() != null) { - if (r.getStp().getValue().getParameter() != null) { + if (r.getStp().getValue() instanceof ParameterReference) { List instantList = new ArrayList<>(); instantList.add(instance.instantiation); - STPList.addAll(ASTUtils.initialValue(r.getStp().getValue().getParameter(), instantList)); + final var param = ((ParameterReference)r.getStp().getValue()).getParameter(); + STPList.addAll(ASTUtils.initialValue(param, instantList)); } else { STPList.add(r.getStp().getValue()); } @@ -442,10 +441,11 @@ private static TimeValue findMaxSTP(Variable port, // If STP offset is determined, add it // If not, assume it is zero if (r.getStp() != null) { - if (r.getStp().getValue() instanceof Parameter) { + if (r.getStp().getValue() instanceof ParameterReference) { List instantList = new ArrayList<>(); instantList.add(childPort.getContainer()); - STPList.addAll(ASTUtils.initialValue(r.getStp().getValue().getParameter(), instantList)); + final var param = ((ParameterReference)r.getStp().getValue()).getParameter(); + STPList.addAll(ASTUtils.initialValue(param, instantList)); } else { STPList.add(r.getStp().getValue()); } diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index 46cfca5fab..2c5b5c8a6e 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -68,6 +68,7 @@ import org.lflang.lf.Action; import org.lflang.lf.Connection; import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; import org.lflang.lf.Model; @@ -75,7 +76,6 @@ import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.Time; -import org.lflang.lf.Value; import org.lflang.lf.VarRef; import org.lflang.validation.AbstractLFValidator; @@ -1275,6 +1275,7 @@ public void printInfo(LFGeneratorContext.Mode mode) { * @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); @@ -1284,15 +1285,16 @@ public static String getTargetTime(Time t) { * Get textual representation of a value in the target language. * * If the value evaluates to 0, it is interpreted as a normal value. - * - * @param v A time AST node + * + * @param expr A time AST node * @return A time string in the target language */ - public static String getTargetValue(Value v) { - if (v.getTime() != null) { - return getTargetTime(v.getTime()); + // FIXME: this should be placed in ExpressionGenerator + public static String getTargetValue(Expression expr) { + if (expr instanceof Time) { + return getTargetTime((Time)expr); } - return ASTUtils.toText(v); + return ASTUtils.toText(expr); } /** @@ -1300,19 +1302,21 @@ public static String getTargetValue(Value v) { * * If the value evaluates to 0, it is interpreted as a time. * - * @param v A time AST node + * @param expr A time AST node * @return A time string in the target language */ - public static String getTargetTime(Value v) { - if (v.getTime() != null) { - return getTargetTime(v.getTime()); - } else if (ASTUtils.isZero(v)) { + // 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(v); + return ASTUtils.toText(expr); } + // FIXME: this should be placed in ExpressionGenerator public static String getTargetTime(Delay d) { if (d.getParameter() != null) { return ASTUtils.toText(d); diff --git a/org.lflang/src/org/lflang/generator/ParameterInstance.java b/org.lflang/src/org/lflang/generator/ParameterInstance.java index 84c3ccac7b..1b0a09c69d 100644 --- a/org.lflang/src/org/lflang/generator/ParameterInstance.java +++ b/org.lflang/src/org/lflang/generator/ParameterInstance.java @@ -33,8 +33,8 @@ import org.lflang.InferredType; import org.lflang.ASTUtils; import org.lflang.lf.Assignment; +import org.lflang.lf.Expression; import org.lflang.lf.Parameter; -import org.lflang.lf.Value; /** * Representation of a compile-time instance of a parameter. @@ -76,7 +76,7 @@ public ParameterInstance(Parameter definition, ReactorInstance parent) { * of Time, Literal, or Code. That is, references to other * parameters have been replaced with their initial values. */ - public List getInitialValue() { + 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 1693a25913..49599aff1e 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -41,18 +41,19 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Action; import org.lflang.lf.Connection; import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Mode; import org.lflang.lf.Output; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Port; import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.Timer; import org.lflang.lf.TriggerRef; -import org.lflang.lf.Value; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; @@ -433,7 +434,7 @@ public Integer initialIntParameterValue(Parameter parameter) { * 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) { + public List initialParameterValue(Parameter parameter) { return ASTUtils.initialValue(parameter, instantiations()); } @@ -641,17 +642,17 @@ public String toString() { } /** - * Assuming that the given value denotes a valid time, return a time value. + * Assuming that the given expression denotes a valid time, return a time value. * * If the value is given as a parameter reference, this will look up the * precise time value assigned to this reactor instance. */ - public TimeValue getTimeValue(Value v) { - Parameter p = v.getParameter(); - if (p != null) { - return ASTUtils.getLiteralTimeValue(lookupParameterInstance(p).getInitialValue().get(0)); + public TimeValue getTimeValue(Expression expr) { + if (expr instanceof ParameterReference) { + final var param = ((ParameterReference)expr).getParameter(); + return ASTUtils.getLiteralTimeValue(lookupParameterInstance(param).getInitialValue().get(0)); } else { - return ASTUtils.getLiteralTimeValue(v); + return ASTUtils.getLiteralTimeValue(expr); } } diff --git a/org.lflang/src/org/lflang/generator/ValueGenerator.java b/org.lflang/src/org/lflang/generator/ValueGenerator.java index 2272c24884..3c14fe82ab 100644 --- a/org.lflang/src/org/lflang/generator/ValueGenerator.java +++ b/org.lflang/src/org/lflang/generator/ValueGenerator.java @@ -4,17 +4,17 @@ import java.util.ArrayList; import java.util.stream.Collectors; -import org.lflang.ASTUtils; import org.lflang.ASTUtils; import org.lflang.TimeValue; import org.lflang.lf.Assignment; import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.StateVar; import org.lflang.lf.Time; import org.lflang.TimeUnit; -import org.lflang.lf.Value; /** * Encapsulates logic for representing {@code Value}s in a @@ -65,11 +65,11 @@ public List getInitializerList(StateVar state) { // FIXME: Previously, we returned null if it was not initialized, which would have caused an // NPE in TSStateGenerator. Is this the desired behavior? if (!ASTUtils.isInitialized(state)) return list; - for (Value v : state.getInit()) { - if (v.getParameter() != null) { - list.add(getTargetReference.apply(v.getParameter())); + for (Expression expr : state.getInit()) { + if (expr instanceof ParameterReference) { + list.add(getTargetReference.apply(((ParameterReference)expr).getParameter())); } else { - list.add(getTargetValue(v, ASTUtils.isOfTimeType(state))); + list.add(getTargetValue(expr, ASTUtils.isOfTimeType(state))); } } return list; @@ -84,8 +84,8 @@ public List getInitializerList(StateVar state) { public List getInitializerList(Parameter param) { List list = new ArrayList<>(); if (param == null) return list; - for (Value v : param.getInit()) - list.add(getTargetValue(v, ASTUtils.isOfTimeType(param))); + for (Expression expr : param.getInit()) + list.add(getTargetValue(expr, ASTUtils.isOfTimeType(param))); return list; } @@ -109,8 +109,8 @@ public List getInitializerList(Parameter param, Instantiation i) { // Case 1: The parameter was overwritten in the instantiation List list = new ArrayList<>(); if (assignments.get(0) == null) return list; - for (Value init : assignments.get(0).getRhs()) - list.add(getTargetValue(init, ASTUtils.isOfTimeType(param))); + for (Expression expr : assignments.get(0).getRhs()) + list.add(getTargetValue(expr, ASTUtils.isOfTimeType(param))); return list; } @@ -144,32 +144,32 @@ public String getTargetTime(Delay d) { * Return the time specified by {@code v}, expressed as * code that is valid for some target languages. */ - public String getTargetTime(Value v) { - return getTargetValue(v, true); + public String getTargetTime(Expression expr) { + return getTargetValue(expr, true); } /** - * Get textual representation of a value in the target language. + * Get textual representation of an expression in the target language. * - * If the value evaluates to 0, it is interpreted as a normal value. + * If the value evaluates to 0, it is interpreted as a literal. * - * @param v A time AST node + * @param expr A time AST node * @return A time string in the target language */ - public String getTargetValue(Value v) { - return ASTUtils.toText(v); + public String getTargetValue(Expression expr) { + return ASTUtils.toText(expr); } /** - * Get textual representation of a value in the target language. + * Get textual representation of an expression in the target language. * - * @param v A time AST node + * @param expr A time AST node * @param isTime Whether {@code v} is expected to be a time * @return A time string in the target language */ - public String getTargetValue(Value v, boolean isTime) { - if (v.getTime() != null) return getTargetTime(v.getTime()); - if (isTime && ASTUtils.isZero(v)) return timeInTargetLanguage.apply(TimeValue.ZERO); - return ASTUtils.toText(v); + public String getTargetValue(Expression expr, boolean isTime) { + if (expr instanceof Time) return getTargetTime((Time)expr); + if (isTime && ASTUtils.isZero(expr)) return timeInTargetLanguage.apply(TimeValue.ZERO); + return ASTUtils.toText(expr); } } diff --git a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java index 54d47005a5..4a670b28cf 100644 --- a/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CParameterGenerator.java @@ -6,7 +6,8 @@ import org.lflang.ASTUtils; import org.lflang.generator.GeneratorBase; import org.lflang.lf.Assignment; -import org.lflang.lf.Value; +import org.lflang.lf.Expression; +import org.lflang.lf.ParameterReference; public class CParameterGenerator { /** @@ -34,24 +35,25 @@ public static String getInitializer(ParameterInstance p) { if (lastAssignment != null) { // The parameter has an assignment. // Right hand side can be a list. Collect the entries. - for (Value value: lastAssignment.getRhs()) { - if (value.getParameter() != null) { + for (Expression expr: lastAssignment.getRhs()) { + 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. - list.add(CUtil.reactorRef(p.getParent().getParent()) + "->" + value.getParameter().getName()); + final var param = ((ParameterReference) expr).getParameter(); + list.add(CUtil.reactorRef(p.getParent().getParent()) + "->" + param.getName()); } else { - list.add(GeneratorBase.getTargetTime(value)); + list.add(GeneratorBase.getTargetTime(expr)); } } } else { // there was no assignment in the instantiation. So just use the // parameter's initial value. - for (Value i : p.getParent().initialParameterValue(p.getDefinition())) { + for (Expression expr : p.getParent().initialParameterValue(p.getDefinition())) { if (ASTUtils.isOfTimeType(p.getDefinition())) { - list.add(GeneratorBase.getTargetTime(i)); + list.add(GeneratorBase.getTargetTime(expr)); } else { - list.add(GeneratorBase.getTargetTime(i)); + list.add(GeneratorBase.getTargetTime(expr)); } } } diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/src/org/lflang/generator/python/PyUtil.java index b75cabf960..bded281f60 100644 --- a/org.lflang/src/org/lflang/generator/python/PyUtil.java +++ b/org.lflang/src/org/lflang/generator/python/PyUtil.java @@ -29,7 +29,8 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.ReactorInstance; import org.lflang.generator.GeneratorBase; import org.lflang.generator.c.CUtil; -import org.lflang.lf.Value; +import org.lflang.lf.Expression; +import org.lflang.lf.ParameterReference; import java.io.IOException; import java.nio.file.Path; @@ -144,12 +145,12 @@ public static String generateGILReleaseCode() { * Python equivalent. * Examples: * true/false -> True/False - * @param v A value + * @param expr A value * @return A value string in the target language */ - protected static String getPythonTargetValue(Value v) { - String returnValue = ""; - switch (ASTUtils.toText(v)) { + protected static String getPythonTargetValue(Expression expr) { + String returnValue; + switch (ASTUtils.toText(expr)) { case "false": returnValue = "False"; break; @@ -157,13 +158,13 @@ protected static String getPythonTargetValue(Value v) { returnValue = "True"; break; default: - returnValue = GeneratorBase.getTargetValue(v); + 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 (v.getParameter() != null) { + if (expr instanceof ParameterReference) { returnValue = "self." + returnValue; } diff --git a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java index fafabdc0ec..7a75c42c52 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonParameterGenerator.java @@ -8,16 +8,11 @@ import com.google.common.base.Objects; import org.lflang.ASTUtils; -import org.lflang.ASTUtils; -import org.lflang.generator.CodeBuilder; import org.lflang.generator.GeneratorBase; import org.lflang.generator.ParameterInstance; -import org.lflang.generator.ReactorInstance; -import org.lflang.generator.c.CUtil; -import org.lflang.generator.c.CParameterGenerator; +import org.lflang.lf.Expression; +import org.lflang.lf.ParameterReference; import org.lflang.lf.ReactorDecl; -import org.lflang.lf.Value; -import org.lflang.lf.Reactor; import org.lflang.lf.Assignment; import org.lflang.lf.Parameter; @@ -120,19 +115,20 @@ public static String generatePythonInitializer(ParameterInstance p) { if (lastAssignment != null) { // The parameter has an assignment. // Right hand side can be a list. Collect the entries. - for (Value value : lastAssignment.getRhs()) { - if (value.getParameter() != null) { + for (Expression expr : lastAssignment.getRhs()) { + 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. - list.add(PyUtil.reactorRef(p.getParent().getParent()) + "." + value.getParameter().getName()); + final var param = ((ParameterReference) expr).getParameter(); + list.add(PyUtil.reactorRef(p.getParent().getParent()) + "." + param.getName()); } else { - list.add(GeneratorBase.getTargetTime(value)); + list.add(GeneratorBase.getTargetTime(expr)); } } } else { - for (Value i : p.getParent().initialParameterValue(p.getDefinition())) { - list.add(PyUtil.getPythonTargetValue(i)); + for (Expression expr : p.getParent().initialParameterValue(p.getDefinition())) { + list.add(PyUtil.getPythonTargetValue(expr)); } } return list.size() > 1 ? "(" + String.join(", ", list) + ")" : list.get(0); diff --git a/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java index 7441f53225..e204817aa5 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonStateGenerator.java @@ -5,11 +5,8 @@ import java.util.stream.Collectors; import org.lflang.ASTUtils; -import org.lflang.ASTUtils; -import org.lflang.generator.GeneratorBase; import org.lflang.lf.ReactorDecl; import org.lflang.lf.StateVar; -import org.lflang.lf.Value; public class PythonStateGenerator { /** diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 52e3b41435..ef1d531773 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -28,13 +28,12 @@ import static org.lflang.ASTUtils.inferPortWidth; import static org.lflang.ASTUtils.isGeneric; -import static org.lflang.ASTUtils.isInteger; +import static org.lflang.ASTUtils.isOfTimeType; import static org.lflang.ASTUtils.isParameterized; import static org.lflang.ASTUtils.isValidTime; import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; import static org.lflang.ASTUtils.toText; -import static org.lflang.ASTUtils.isOfTimeType; import java.io.IOException; import java.util.ArrayList; @@ -55,7 +54,7 @@ import org.eclipse.xtext.validation.Check; import org.eclipse.xtext.validation.CheckType; import org.eclipse.xtext.validation.ValidationMessageAcceptor; -import org.lflang.ASTUtils; + import org.lflang.ASTUtils; import org.lflang.ModelInfo; import org.lflang.Target; @@ -67,8 +66,10 @@ 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.Deadline; +import org.lflang.lf.Expression; import org.lflang.lf.Host; import org.lflang.lf.IPV4Host; import org.lflang.lf.IPV6Host; @@ -79,11 +80,13 @@ import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; import org.lflang.lf.LfPackage.Literals; +import org.lflang.lf.Literal; import org.lflang.lf.Mode; import org.lflang.lf.Model; import org.lflang.lf.NamedHost; import org.lflang.lf.Output; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Port; import org.lflang.lf.Preamble; import org.lflang.lf.Reaction; @@ -93,11 +96,11 @@ import org.lflang.lf.Serializer; import org.lflang.lf.StateVar; import org.lflang.lf.TargetDecl; +import org.lflang.lf.Time; import org.lflang.lf.Timer; import org.lflang.lf.TriggerRef; import org.lflang.lf.Type; import org.lflang.lf.TypedVariable; -import org.lflang.lf.Value; import org.lflang.lf.VarRef; import org.lflang.lf.Variable; import org.lflang.lf.Visibility; @@ -159,22 +162,20 @@ public void checkAssignment(Assignment assignment) { // If the left-hand side is a time parameter, make sure the assignment has units if (isOfTimeType(assignment.getLhs())) { if (assignment.getRhs().size() > 1) { - error("Incompatible type.", Literals.ASSIGNMENT__RHS); + error("Incompatible type.", Literals.ASSIGNMENT__RHS); } else if (assignment.getRhs().size() > 0) { - Value v = assignment.getRhs().get(0); - if (!isValidTime(v)) { - if (v.getParameter() == null) { - // This is a value. Check that units are present. - error( - "Missing time unit.", Literals.ASSIGNMENT__RHS); + Expression expr = assignment.getRhs().get(0); + if (!isValidTime(expr)) { + if (expr instanceof Literal) { + error("Missing time unit.", Literals.ASSIGNMENT__RHS); + } else if (expr instanceof ParameterReference) { + final var param = ((ParameterReference) expr).getParameter(); + error("Cannot assign parameter: " + param.getName() + " to " + + assignment.getLhs().getName() + + ". The latter is a time parameter, but the former is not.", + Literals.ASSIGNMENT__RHS); } else { - // This is a reference to another parameter. Report problem. - error( - "Cannot assign parameter: " + - v.getParameter().getName() + " to " + - assignment.getLhs().getName() + - ". The latter is a time parameter, but the former is not.", - Literals.ASSIGNMENT__RHS); + error("This is not a valid time expression.", Literals.ASSIGNMENT__RHS); } } } @@ -587,8 +588,8 @@ public void checkOutput(Output output) { public void checkParameter(Parameter param) { checkName(param.getName(), Literals.PARAMETER__NAME); - for (Value it : param.getInit()) { - if (it.getParameter() != null) { + for (Expression expr : param.getInit()) { + if (expr instanceof ParameterReference) { // Initialization using parameters is forbidden. error("Parameter cannot be initialized using parameter.", Literals.PARAMETER__INIT); @@ -609,10 +610,10 @@ public void checkParameter(Parameter param) { Literals.PARAMETER__INIT); } else { // The parameter is a singleton time. - Value init = param.getInit().get(0); - if (init.getTime() == null) { - if (init != null && !isZero(init)) { - if (isInteger(init)) { + Expression expr = param.getInit().get(0); + if (expr instanceof Time) { + if (!ASTUtils.isZero(expr)) { + if (ASTUtils.isInteger(expr)) { error("Missing time unit.", Literals.PARAMETER__INIT); } else { error("Invalid time literal.", @@ -984,28 +985,25 @@ public void checkState(StateVar stateVar) { // If the state is declared to be a time, // make sure that it is initialized correctly. if (stateVar.getInit() != null) { - for (Value init : stateVar.getInit()) { - if (stateVar.getType() != null && stateVar.getType().isTime() && - !isValidTime(init)) { + for (Expression expr : stateVar.getInit()) { + if (stateVar.getType() != null && stateVar.getType().isTime() && !isValidTime(expr)) { if (isParameterized(stateVar)) { error( "Referenced parameter does not denote a time.", Literals.STATE_VAR__INIT); - } else { - if (init != null && !isZero(init)) { - if (isInteger(init)) { - error( - "Missing time unit.", Literals.STATE_VAR__INIT); - } else { - error("Invalid time literal.", - Literals.STATE_VAR__INIT); - } + } else if (expr != null && !ASTUtils.isZero(expr)) { + if (ASTUtils.isInteger(expr)) { + error( + "Missing time unit.", Literals.STATE_VAR__INIT); + } else { + error("Invalid time literal.", + Literals.STATE_VAR__INIT); } } } } } - } else if (this.target.requiresTypes && (ASTUtils.getInferredType(stateVar)).isUndefined()) { + } else if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { // Report if a type is missing error("State must have a type.", Literals.STATE_VAR__TYPE); } @@ -1013,8 +1011,8 @@ public void checkState(StateVar stateVar) { if (isCBasedTarget() && stateVar.getInit().size() > 1) { // In C, if initialization is done with a list, elements cannot // refer to parameters. - for (Value it : stateVar.getInit()) { - if (it.getParameter() != null) { + for (Expression expr : stateVar.getInit()) { + if (expr instanceof ParameterReference) { error("List items cannot refer to a parameter.", Literals.STATE_VAR__INIT); break; @@ -1180,30 +1178,34 @@ else if (this.target == Target.Python) { } @Check(CheckType.FAST) - public void checkValueAsTime(Value value) { - EObject container = value.eContainer(); + public void checkValueAsTime(Expression expr) { + EObject container = expr.eContainer(); if (container instanceof Timer || container instanceof Action || container instanceof Connection || container instanceof Deadline) { // If parameter is referenced, check that it is of the correct type. - if (value.getParameter() != null) { - if (!isOfTimeType(value.getParameter()) && target.requiresTypes) { + if (expr instanceof ParameterReference) { + final var param = ((ParameterReference) expr).getParameter(); + if (!isOfTimeType(param) && target.requiresTypes) { error("Parameter is not of time type", - Literals.VALUE__PARAMETER); + Literals.PARAMETER_REFERENCE__PARAMETER); } - } else if (value.getTime() == null) { - if (value.getLiteral() != null && !isZero(value.getLiteral())) { - if (isInteger(value.getLiteral())) { - error("Missing time unit.", Literals.VALUE__LITERAL); - } else { - error("Invalid time literal.", - Literals.VALUE__LITERAL); - } - } else if (value.getCode() != null) { - error("Invalid time literal.", Literals.VALUE__CODE); + } else if (!(expr instanceof Time)) { + if (expr instanceof Literal && !isZero((Literal) expr)) { + if (ASTUtils.isInteger(expr)) { + error("Missing time unit.", Literals.LITERAL__LITERAL); + } else { + error("Invalid time literal.", Literals.LITERAL__LITERAL); + } + } else if (expr instanceof Code) { + error("Invalid time literal.", Literals.CODE__BODY); } } } + // FIXME: It will be hard to keep this list of expression types complete if we add more expressions + // in the future. Better to put the code in a mehtod and call it in the check methods for + // Timer, Action, Connection, Deadline, and have a default case where an error is reported + // on any umknown expression type. } @Check(CheckType.FAST) From 1c7fde02d75f77b4c99a196b2a8d398d878f61b6 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 15:02:21 +0100 Subject: [PATCH 07/58] rename ValueGenerator -> ExpressionGenerator --- .../{ValueGenerator.java => ExpressionGenerator.java} | 6 +++--- .../src/org/lflang/generator/cpp/CppParameterGenerator.kt | 2 +- .../src/org/lflang/generator/cpp/CppStateGenerator.kt | 2 +- org.lflang/src/org/lflang/generator/ts/TSGenerator.kt | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) rename org.lflang/src/org/lflang/generator/{ValueGenerator.java => ExpressionGenerator.java} (97%) diff --git a/org.lflang/src/org/lflang/generator/ValueGenerator.java b/org.lflang/src/org/lflang/generator/ExpressionGenerator.java similarity index 97% rename from org.lflang/src/org/lflang/generator/ValueGenerator.java rename to org.lflang/src/org/lflang/generator/ExpressionGenerator.java index 3c14fe82ab..05b900fb8a 100644 --- a/org.lflang/src/org/lflang/generator/ValueGenerator.java +++ b/org.lflang/src/org/lflang/generator/ExpressionGenerator.java @@ -20,7 +20,7 @@ * Encapsulates logic for representing {@code Value}s in a * target language. */ -public final class ValueGenerator { +public final class ExpressionGenerator { /** * A {@code TimeInTargetLanguage} is a @@ -46,10 +46,10 @@ public interface GetTargetReference { /** * Instantiates a target-language-specific - * ValueGenerator parameterized by {@code f}. + * ExpressionGenerator parameterized by {@code f}. * @param f a time representation strategy */ - public ValueGenerator(TimeInTargetLanguage f, GetTargetReference g) { + public ExpressionGenerator(TimeInTargetLanguage f, GetTargetReference g) { this.timeInTargetLanguage = f; this.getTargetReference = g; } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt index c330a83fcc..09a6135337 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppParameterGenerator.kt @@ -37,7 +37,7 @@ class CppParameterGenerator(private val reactor: Reactor) { /** * Create a list of initializers for the given parameter * - * TODO This is redundant to ValueGenerator.getInitializerList + * TODO This is redundant to ExpressionGenerator.getInitializerList */ private fun Parameter.getInitializerList() = init.map { if (isOfTimeType) it.toTime() diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt index da6ccfbf89..ad510d3964 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStateGenerator.kt @@ -37,7 +37,7 @@ class CppStateGenerator(private val reactor: Reactor) { /** * Create a list of state initializers in target code. * - * TODO This is redundant to ValueGenerator.getInitializerList + * TODO This is redundant to ExpressionGenerator.getInitializerList */ private fun getInitializerList(state: StateVar) = state.init.map { when { diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index dfe0449b5e..fdd34a2900 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -44,7 +44,7 @@ import org.lflang.generator.LFGeneratorContext import org.lflang.generator.PrependOperator import org.lflang.generator.SubContext import org.lflang.generator.TargetTypes -import org.lflang.generator.ValueGenerator +import org.lflang.generator.ExpressionGenerator import org.lflang.generator.GeneratorUtils.canGenerate import org.lflang.inferredType import org.lflang.lf.Action @@ -100,7 +100,8 @@ class TSGenerator( "reactor.ts", "microtime.d.ts", "nanotimer.d.ts", "time.ts", "ulog.d.ts", "util.ts") - private val VG = ValueGenerator(::timeInTargetLanguage) { param -> "this.${param.name}.get()" } + private val VG = + ExpressionGenerator(::timeInTargetLanguage) { param -> "this.${param.name}.get()" } private fun timeInTargetLanguage(value: TimeValue): String { return if (value.unit != null) { From 686303e969bb12af3bb51ddf7b0aacab658d3a32 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 10 Mar 2022 15:06:37 +0100 Subject: [PATCH 08/58] fix the CGenerator --- .../src/org/lflang/generator/c/CGenerator.xtend | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 38dda27d6a..3659c5bcf1 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -82,6 +82,7 @@ import org.lflang.lf.LfFactory import org.lflang.lf.Mode import org.lflang.lf.Model import org.lflang.lf.Output +import org.lflang.lf.ParameterReference import org.lflang.lf.Port import org.lflang.lf.Reaction import org.lflang.lf.Reactor @@ -4824,7 +4825,7 @@ class CGenerator extends GeneratorBase { } override getNetworkBufferType() '''uint8_t*''' - + /** * Return a C expression that can be used to initialize the specified * state variable within the specified parent. If the state variable @@ -4834,13 +4835,13 @@ class CGenerator extends GeneratorBase { protected def String getInitializer(StateVar state, ReactorInstance parent) { var list = new LinkedList(); - for (i : state?.init) { - if (i.parameter !== null) { - list.add(CUtil.reactorRef(parent) + "->" + i.parameter.name) + for (expr : state?.init) { + if (expr instanceof ParameterReference) { + list.add(CUtil.reactorRef(parent) + "->" + expr.parameter.name) } else if (state.isOfTimeType) { - list.add(i.targetTime) + list.add(expr.targetTime) } else { - list.add(i.targetTime) + list.add(expr.targetTime) } } From 23d79ae8ac02bbf0705421533cb07a21835fb810 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 11 Mar 2022 16:54:33 +0100 Subject: [PATCH 09/58] fix compile errors after merge --- .../src/org/lflang/generator/c/CStateGenerator.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java index 5cb8f602b2..402f9f7ed7 100644 --- a/org.lflang/src/org/lflang/generator/c/CStateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CStateGenerator.java @@ -7,10 +7,10 @@ import org.lflang.generator.GeneratorBase; import org.lflang.generator.ModeInstance; import org.lflang.generator.ReactorInstance; -import org.lflang.lf.Mode; +import org.lflang.lf.Expression; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; import org.lflang.lf.StateVar; -import org.lflang.lf.Value; public class CStateGenerator { /** @@ -153,11 +153,12 @@ private static String generateModalPropertyInitializer( */ private static String getInitializerExpr(StateVar state, ReactorInstance parent) { var list = new LinkedList(); - for (Value i : state.getInit()) { - if (i.getParameter() != null) { - list.add(CUtil.reactorRef(parent) + "->" + i.getParameter().getName()); + for (Expression expr : state.getInit()) { + if (expr instanceof ParameterReference) { + final var param = ((ParameterReference)expr).getParameter(); + list.add(CUtil.reactorRef(parent) + "->" + param.getName()); } else { - list.add(GeneratorBase.getTargetTime(i)); + list.add(GeneratorBase.getTargetTime(expr)); } } return list.size() == 1 ? From ae883823c4ea593e96122bcf4b342e4cae4c8275 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 11 Mar 2022 17:13:20 +0100 Subject: [PATCH 10/58] fix compile errors in tests --- .../compiler/LinguaFrancaASTUtilsTest.java | 66 +++++++++---------- .../compiler/LinguaFrancaValidationTest.java | 8 +-- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java index b7ccf6f592..09a0091972 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaASTUtilsTest.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import javax.inject.Inject; import org.eclipse.xtext.testing.InjectWith; @@ -42,8 +41,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; + import org.lflang.ASTUtils; import org.lflang.lf.Instantiation; +import org.lflang.lf.Literal; import org.lflang.lf.Model; import org.lflang.lf.Parameter; import org.lflang.lf.StateVar; @@ -222,50 +223,47 @@ public void initialValue() throws Exception { Parameter parameter = (Parameter)obj; if (parameter.getName() == "x") { var values = ASTUtils.initialValue(parameter, null); - Assertions.assertEquals(values.get(0).getLiteral(), "1"); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "1"); - values = ASTUtils.initialValue(parameter, - List.of(map.get("a1"))); - Assertions.assertEquals(values.get(0).getLiteral(), "2"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "2"); - values = ASTUtils.initialValue(parameter, - List.of(map.get("a2"))); - Assertions.assertEquals(values.get(0).getLiteral(), "-1"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-1"); - values = ASTUtils.initialValue(parameter, - List.of(map.get("a1"), map.get("b1"))); - Assertions.assertEquals(values.get(0).getLiteral(), "3"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "3"); - values = ASTUtils.initialValue(parameter, - List.of(map.get("a2"), map.get("b1"))); - Assertions.assertEquals(values.get(0).getLiteral(), "-1"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-1"); - values = ASTUtils.initialValue(parameter, - List.of(map.get("a1"), map.get("b2"))); - Assertions.assertEquals(values.get(0).getLiteral(), "-2"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-2"); - values = ASTUtils.initialValue(parameter, - List.of(map.get("a2"), map.get("b2"))); - Assertions.assertEquals(values.get(0).getLiteral(), "-1"); + values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-1"); } else if (parameter.getName() == "y") { var values = ASTUtils.initialValue(parameter, null); - Assertions.assertEquals(values.get(0).getLiteral(), "2"); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "2"); - try { - values = ASTUtils.initialValue(parameter, - List.of(map.get("a1"))); - } catch (IllegalArgumentException ex) { - Assertions.assertTrue(ex.getMessage() - .startsWith("Parameter y is not")); - } + Assertions.assertThrows(IllegalArgumentException.class, + () -> ASTUtils.initialValue(parameter, List.of(map.get("a1")))); - values = ASTUtils.initialValue(parameter, - List.of(map.get("b1"))); - Assertions.assertEquals(values.get(0).getLiteral(), "3"); + values = ASTUtils.initialValue(parameter, List.of(map.get("b1"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "3"); - values = ASTUtils.initialValue(parameter, - List.of(map.get("b2"))); - Assertions.assertEquals(values.get(0).getLiteral(), "-2"); + values = ASTUtils.initialValue(parameter, List.of(map.get("b2"))); + Assertions.assertInstanceOf(Literal.class, values.get(0)); + Assertions.assertEquals(((Literal)values.get(0)).getLiteral(), "-2"); } } }); 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 d3a64e19d8..63ec4437dd 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -936,7 +936,7 @@ public void nonZeroTimeValueWithoutUnits() throws Exception { " printf(\"Hello World.\\n\");", " =}", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getValue(), null, "Missing time unit."); + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getLiteral(), null, "Missing time unit."); } /** @@ -963,7 +963,7 @@ public void parameterTypeMismatch() throws Exception { " printf(\"Hello World.\\n\");", " =}", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getValue(), + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getParameterReference(), null, "Parameter is not of time type"); } @@ -991,7 +991,7 @@ public void targetCodeInTimeArgument() throws Exception { " printf(\"Hello World.\\n\");", " =}", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getValue(), + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getLiteral(), null, "Invalid time literal"); } @@ -1255,7 +1255,7 @@ public void stateAndParameterDeclarationsInC() throws Exception { "Invalid time literal."); validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Uninitialized parameter."); - validator.assertError(model, LfPackage.eINSTANCE.getValue(), null, + validator.assertError(model, LfPackage.eINSTANCE.getLiteral(), null, "Missing time unit."); } From 2b72c410bdcffe87383463c9e3fc17a78a205c3c Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 11 Mar 2022 17:16:12 +0100 Subject: [PATCH 11/58] bugfixes --- .../org/lflang/tests/compiler/LinguaFrancaValidationTest.java | 2 +- org.lflang/src/org/lflang/validation/LFValidator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 63ec4437dd..81a8ddf5c8 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -991,7 +991,7 @@ public void targetCodeInTimeArgument() throws Exception { " printf(\"Hello World.\\n\");", " =}", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getLiteral(), + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getCode(), null, "Invalid time literal"); } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index ef1d531773..9e7febda28 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -611,7 +611,7 @@ public void checkParameter(Parameter param) { } else { // The parameter is a singleton time. Expression expr = param.getInit().get(0); - if (expr instanceof Time) { + if (!(expr instanceof Time)) { if (!ASTUtils.isZero(expr)) { if (ASTUtils.isInteger(expr)) { error("Missing time unit.", Literals.PARAMETER__INIT); From 745eedfcfbf45134bad0448773deb2770c48dc17 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 11 Mar 2022 17:28:49 +0100 Subject: [PATCH 12/58] fix compile errors in diagram synthesis --- .../synthesis/util/UtilityExtensions.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java b/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java index b27b027123..eeca34dbf1 100644 --- a/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java +++ b/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java @@ -46,9 +46,12 @@ import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; import org.lflang.generator.ReactorInstance; import org.lflang.lf.Code; +import org.lflang.lf.Expression; import org.lflang.lf.Host; +import org.lflang.lf.Literal; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; -import org.lflang.lf.Value; +import org.lflang.lf.Time; /** @@ -65,17 +68,17 @@ public class UtilityExtensions extends AbstractSynthesisExtensions { /** * Converts a timing value into readable text */ - public String toText(Value value) { - if (value != null) { - if (value.getParameter() != null) { - return value.getParameter().getName(); - } else if (value.getTime() != null) { - return value.getTime().getInterval() + - value.getTime().getUnit().toString(); - } else if (value.getLiteral() != null) { - return value.getLiteral(); - } else if (value.getCode() != null) { - ASTUtils.toText(value.getCode()); + public String toText(Expression expr) { + if (expr != null) { + if (expr instanceof ParameterReference) { + return ((ParameterReference)expr).getParameter().getName(); + } else if (expr instanceof Time) { + final var time = (Time)expr; + return time.getInterval() + time.getUnit().toString(); + } else if (expr instanceof Literal) { + return ((Literal)expr).getLiteral(); + } else if (expr instanceof Code) { + ASTUtils.toText((Code)expr); } } return ""; From b563a558c975b6a2c585c23e2bb0809b9a383a96 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 11 Mar 2022 18:00:43 +0100 Subject: [PATCH 13/58] fix validation of deadlines --- .../org/lflang/validation/LFValidator.java | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 9e7febda28..b864ca07c9 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -155,6 +155,8 @@ public void checkAction(Action action) { String.join(", ", SPACING_VIOLATION_POLICIES) + ".", Literals.ACTION__POLICY); } + checkExpressionAsTime(action.getMinDelay()); + checkExpressionAsTime(action.getMinSpacing()); } @Check(CheckType.FAST) @@ -367,6 +369,7 @@ public void checkDeadline(Deadline deadline) { TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", Literals.DEADLINE__DELAY); } + checkExpressionAsTime(deadline.getDelay()); } @Check(CheckType.FAST) @@ -1150,6 +1153,8 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { @Check(CheckType.FAST) public void checkTimer(Timer timer) { checkName(timer.getName(), Literals.VARIABLE__NAME); + checkExpressionAsTime(timer.getOffset()); + checkExpressionAsTime(timer.getPeriod()); } @Check(CheckType.FAST) @@ -1176,37 +1181,6 @@ else if (this.target == Target.Python) { } } } - - @Check(CheckType.FAST) - public void checkValueAsTime(Expression expr) { - EObject container = expr.eContainer(); - - if (container instanceof Timer || container instanceof Action || - container instanceof Connection || container instanceof Deadline) { - // If parameter is referenced, check that it is of the correct type. - if (expr instanceof ParameterReference) { - final var param = ((ParameterReference) expr).getParameter(); - if (!isOfTimeType(param) && target.requiresTypes) { - error("Parameter is not of time type", - Literals.PARAMETER_REFERENCE__PARAMETER); - } - } else if (!(expr instanceof Time)) { - if (expr instanceof Literal && !isZero((Literal) expr)) { - if (ASTUtils.isInteger(expr)) { - error("Missing time unit.", Literals.LITERAL__LITERAL); - } else { - error("Invalid time literal.", Literals.LITERAL__LITERAL); - } - } else if (expr instanceof Code) { - error("Invalid time literal.", Literals.CODE__BODY); - } - } - } - // FIXME: It will be hard to keep this list of expression types complete if we add more expressions - // in the future. Better to put the code in a mehtod and call it in the check methods for - // Timer, Action, Connection, Deadline, and have a default case where an error is reported - // on any umknown expression type. - } @Check(CheckType.FAST) public void checkVarRef(VarRef varRef) { @@ -1435,6 +1409,38 @@ private void checkName(String name, EStructuralFeature feature) { } } + /** + * Check if an expressions denotes a valid time. + * @param expr the expression to check + */ + private void checkExpressionAsTime(Expression expr) { + if (expr == null) { + return; + } + // If parameter is referenced, check that it is of the correct type. + if (expr instanceof ParameterReference) { + final var param = ((ParameterReference) expr).getParameter(); + if (!isOfTimeType(param) && target.requiresTypes) { + error("Parameter is not of time type", + Literals.PARAMETER_REFERENCE__PARAMETER); + } + } else if (!(expr instanceof Time)) { + if (expr instanceof Literal && !isZero(expr)) { + if (ASTUtils.isInteger(expr)) { + error("Missing time unit.", Literals.LITERAL__LITERAL); + } else { + error("Invalid time literal.", Literals.LITERAL__LITERAL); + } + } else if (expr instanceof Code) { + error("Invalid time literal.", Literals.CODE__BODY); + } + } + // FIXME: It will be hard to keep this list of expression types complete if we add more expressions + // in the future. Better to put the code in a mehtod and call it in the check methods for + // Timer, Action, Connection, Deadline, and have a default case where an error is reported + // on any umknown expression type. + } + /** * Return the number of main or federated reactors declared. * @param iter An iterator over all objects in the resource. From 18e798c2e0e515c5d39df02853a847672ee7add1 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 13:04:18 +0100 Subject: [PATCH 14/58] fix use of eReferences in checkExpressionAsTime --- .../org/lflang/validation/LFValidator.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index b864ca07c9..a4ee0b428c 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -50,6 +50,7 @@ import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.xtext.validation.Check; import org.eclipse.xtext.validation.CheckType; @@ -155,8 +156,8 @@ public void checkAction(Action action) { String.join(", ", SPACING_VIOLATION_POLICIES) + ".", Literals.ACTION__POLICY); } - checkExpressionAsTime(action.getMinDelay()); - checkExpressionAsTime(action.getMinSpacing()); + checkExpressionAsTime(action.getMinDelay(), Literals.ACTION__MIN_DELAY); + checkExpressionAsTime(action.getMinSpacing(), Literals.ACTION__MIN_SPACING); } @Check(CheckType.FAST) @@ -369,7 +370,7 @@ public void checkDeadline(Deadline deadline) { TimeValue.MAX_LONG_DEADLINE + " nanoseconds.", Literals.DEADLINE__DELAY); } - checkExpressionAsTime(deadline.getDelay()); + checkExpressionAsTime(deadline.getDelay(), Literals.DEADLINE__DELAY); } @Check(CheckType.FAST) @@ -1153,8 +1154,8 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { @Check(CheckType.FAST) public void checkTimer(Timer timer) { checkName(timer.getName(), Literals.VARIABLE__NAME); - checkExpressionAsTime(timer.getOffset()); - checkExpressionAsTime(timer.getPeriod()); + checkExpressionAsTime(timer.getOffset(), Literals.TIMER__OFFSET); + checkExpressionAsTime(timer.getPeriod(), Literals.TIMER__PERIOD); } @Check(CheckType.FAST) @@ -1412,8 +1413,9 @@ private void checkName(String name, EStructuralFeature feature) { /** * Check if an expressions denotes a valid time. * @param expr the expression to check + * @param eReference the eReference to report errors on */ - private void checkExpressionAsTime(Expression expr) { + private void checkExpressionAsTime(Expression expr, EReference eReference) { if (expr == null) { return; } @@ -1421,18 +1423,17 @@ private void checkExpressionAsTime(Expression expr) { if (expr instanceof ParameterReference) { final var param = ((ParameterReference) expr).getParameter(); if (!isOfTimeType(param) && target.requiresTypes) { - error("Parameter is not of time type", - Literals.PARAMETER_REFERENCE__PARAMETER); + error("Parameter is not of time type", eReference); } } else if (!(expr instanceof Time)) { if (expr instanceof Literal && !isZero(expr)) { if (ASTUtils.isInteger(expr)) { - error("Missing time unit.", Literals.LITERAL__LITERAL); + error("Missing time unit.", eReference); } else { - error("Invalid time literal.", Literals.LITERAL__LITERAL); + error("Invalid time literal.", eReference); } } else if (expr instanceof Code) { - error("Invalid time literal.", Literals.CODE__BODY); + error("Invalid time literal.", eReference); } } // FIXME: It will be hard to keep this list of expression types complete if we add more expressions From d213f438c2695902a0a0f54025d041e600cefafa Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 13:16:01 +0100 Subject: [PATCH 15/58] bugfix --- org.lflang/src/org/lflang/ModelInfo.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ModelInfo.java b/org.lflang/src/org/lflang/ModelInfo.java index 79fc222cfb..84de93d598 100644 --- a/org.lflang/src/org/lflang/ModelInfo.java +++ b/org.lflang/src/org/lflang/ModelInfo.java @@ -164,7 +164,9 @@ private void collectOverflowingNodes() { } // If any of the upstream parameters overflow, report this deadline. - if (detectOverflow(new HashSet<>(), ((ParameterReference)deadline.getDelay()).getParameter())) { + final var delay = deadline.getDelay(); + if (delay instanceof ParameterReference + && detectOverflow(new HashSet<>(), ((ParameterReference) deadline.getDelay()).getParameter())) { this.overflowingDeadlines.add(deadline); } } From 872191defd5803945be206e36d38f008412b641d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 13:20:24 +0100 Subject: [PATCH 16/58] fix unit tests --- .../tests/compiler/LinguaFrancaValidationTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 81a8ddf5c8..12e8a7b227 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -936,7 +936,7 @@ public void nonZeroTimeValueWithoutUnits() throws Exception { " printf(\"Hello World.\\n\");", " =}", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getLiteral(), null, "Missing time unit."); + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); } /** @@ -963,7 +963,7 @@ public void parameterTypeMismatch() throws Exception { " printf(\"Hello World.\\n\");", " =}", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getParameterReference(), + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), null, "Parameter is not of time type"); } @@ -991,8 +991,8 @@ public void targetCodeInTimeArgument() throws Exception { " printf(\"Hello World.\\n\");", " =}", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getCode(), - null, "Invalid time literal"); + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), + null, "Invalid time literal."); } @@ -1255,7 +1255,7 @@ public void stateAndParameterDeclarationsInC() throws Exception { "Invalid time literal."); validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Uninitialized parameter."); - validator.assertError(model, LfPackage.eINSTANCE.getLiteral(), null, + validator.assertError(model, LfPackage.eINSTANCE.getTimer(), null, "Missing time unit."); } From 2605217c4a394f21668e1cb922bcb9ecb0995b8d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 13:37:44 +0100 Subject: [PATCH 17/58] fix bug in C++ generator --- org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt index 330d0a579b..03cd752049 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt @@ -10,7 +10,7 @@ import org.lflang.isGeneric import org.lflang.isMultiport import org.lflang.lf.Expression import org.lflang.lf.LfPackage -import org.lflang.lf.Parameter +import org.lflang.lf.ParameterReference import org.lflang.lf.Port import org.lflang.lf.Preamble import org.lflang.lf.Reaction @@ -75,7 +75,7 @@ fun TimeValue.toCppCode() = CppTypes.getTargetTimeExpr(this) * This should be set to false if called from code generators for the inner class. */ fun Expression.toTime(outerContext: Boolean = false): String = - if (outerContext && this is Parameter) "__lf_inner.${this.name}" + if (outerContext && this is ParameterReference) "__lf_inner.${this.parameter.name}" else CppTypes.getTargetExpr(this, InferredType.time()) /** From 647782ce72f4176ac0359aa55cd00cc6ecec9b2d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 16:52:19 +0100 Subject: [PATCH 18/58] use Expressions for after delays, add a validator rule --- org.lflang/src/org/lflang/LinguaFranca.xtext | 10 +--------- org.lflang/src/org/lflang/validation/LFValidator.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 659a82ded0..4e84d7291c 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -231,17 +231,9 @@ Connection: | ( '(' leftPorts += VarRef (',' leftPorts += VarRef)* ')' iterated ?= '+'?)) ('->' | physical?='~>') rightPorts += VarRef (',' rightPorts += VarRef)* - (delay=Delay)? + ('after' delay=Expression)? (serializer=Serializer)? ';'? - ; - -// After clause with a delay that can either be specified as a parameter or as -// a literal value. If no units are given (which implies that the time interval -// must be zero), the clause must be ended with a semicolon. If units are given, -// the semicolon is optional. -Delay: - 'after' (parameter=[Parameter] | time=TypedTime) ; // Chooses the serializer to use for the connection diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index a4ee0b428c..cb96759e4a 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -359,6 +359,17 @@ public void checkConnection(Connection connection) { } } } + + // Check the after delay + if (connection.getDelay() != null) { + final var delay = connection.getDelay(); + if (delay instanceof ParameterReference || delay instanceof Time) { + checkExpressionAsTime(delay, Literals.CONNECTION__DELAY); + } else { + error("After delays can only be given by time literals or paramters.", + Literals.CONNECTION__DELAY); + } + } } @Check(CheckType.FAST) From a5a073b30a44e4cf0052a62f3988463ab806e435 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 17:26:50 +0100 Subject: [PATCH 19/58] remove all uses of Delay from the code base --- org.lflang/src/org/lflang/ASTUtils.java | 19 ++++++---------- org.lflang/src/org/lflang/AstExtensions.kt | 3 --- .../lflang/federated/CGeneratorExtension.java | 12 +++++----- .../src/org/lflang/federated/FedASTUtils.java | 5 ++--- .../lflang/federated/FederateInstance.java | 8 +++---- .../federated/PythonGeneratorExtension.java | 4 ++-- .../lflang/generator/ExpressionGenerator.java | 11 ---------- .../org/lflang/generator/GeneratorBase.java | 22 +++++-------------- .../org/lflang/generator/ReactorInstance.java | 17 +------------- .../generator/c/CFederateGenerator.java | 16 +++++--------- .../org/lflang/generator/c/CGenerator.java | 6 ++--- .../lflang/generator/c/CNetworkGenerator.java | 6 ++--- .../generator/python/PythonGenerator.java | 4 ++-- .../python/PythonNetworkGenerator.java | 4 ++-- .../org/lflang/generator/ts/TSGenerator.kt | 5 ++--- 15 files changed, 46 insertions(+), 96 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 680753d30a..4fc1fe0ae7 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -66,7 +66,6 @@ import org.lflang.lf.Assignment; import org.lflang.lf.Code; import org.lflang.lf.Connection; -import org.lflang.lf.Delay; import org.lflang.lf.Element; import org.lflang.lf.Expression; import org.lflang.lf.ImportedReactor; @@ -414,7 +413,7 @@ private static List rerouteViaDelay(Connection connection, */ private static Instantiation getDelayInstance(Reactor delayClass, Connection connection, String generic, Boolean defineWidthFromConnection) { - Delay delay = connection.getDelay(); + Expression delay = connection.getDelay(); Instantiation delayInstance = factory.createInstantiation(); delayInstance.setReactorClass(delayClass); if (!StringExtensions.isNullOrEmpty(generic)) { @@ -441,12 +440,15 @@ private static Instantiation getDelayInstance(Reactor delayClass, } Assignment assignment = factory.createAssignment(); assignment.setLhs(delayClass.getParameters().get(0)); - if (delay.getParameter() != null) { + if (delay instanceof ParameterReference) { var expr = factory.createParameterReference(); - expr.setParameter(delay.getParameter()); + expr.setParameter(((ParameterReference)delay).getParameter()); assignment.getRhs().add(expr); + } else if (delay instanceof Time){ + assignment.getRhs().add(delay); } else { - assignment.getRhs().add(delay.getTime()); + // the validator ensures that a delay is only a Time or a ParameterReference + throw new RuntimeException("Unexpected expression type"); } delayInstance.getParameters().add(assignment); delayInstance.setName("delay"); // This has to be overridden. @@ -916,13 +918,6 @@ public static String toText(Expression expr) { } } - public static String toText(Delay d) { - if (d.getParameter() != null) { - return d.getParameter().getName(); - } - return toText(d.getTime()); - } - /** * Return a string of the form either "name" or "container.name" depending * on in which form the variable reference was given. diff --git a/org.lflang/src/org/lflang/AstExtensions.kt b/org.lflang/src/org/lflang/AstExtensions.kt index dd445fcc87..fe1a6dd805 100644 --- a/org.lflang/src/org/lflang/AstExtensions.kt +++ b/org.lflang/src/org/lflang/AstExtensions.kt @@ -161,9 +161,6 @@ fun TypeParm.toText(): String = fun Element.toText(): String = literal?.withoutQuotes()?.trim() ?: id ?: "" - -fun Delay.toText(): String = ASTUtils.toText(this) - fun Time.toTimeValue(): TimeValue = TimeValue(interval.toLong(), TimeUnit.fromName(this.unit)) diff --git a/org.lflang/src/org/lflang/federated/CGeneratorExtension.java b/org.lflang/src/org/lflang/federated/CGeneratorExtension.java index 42518375b7..f02533d1a4 100644 --- a/org.lflang/src/org/lflang/federated/CGeneratorExtension.java +++ b/org.lflang/src/org/lflang/federated/CGeneratorExtension.java @@ -34,9 +34,10 @@ import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; -import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Parameter; +import org.lflang.lf.ParameterReference; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; import org.lflang.lf.VarRef; @@ -230,17 +231,16 @@ public static String createPortStatusFieldForInput(Input input) { * @param generator * @return */ - public static String getNetworkDelayLiteral(Delay delay) { + public static String getNetworkDelayLiteral(Expression delay) { String additionalDelayString = "NEVER"; if (delay != null) { - Parameter p = delay.getParameter(); TimeValue tv; - if (delay.getParameter() != null) { + if (delay instanceof ParameterReference) { // The parameter has to be parameter of the main reactor. // And that value has to be a Time. - tv = ASTUtils.getDefaultAsTimeValue(p); + tv = ASTUtils.getDefaultAsTimeValue(((ParameterReference)delay).getParameter()); } else { - tv = ASTUtils.toTimeValue(delay.getTime()); + tv = ASTUtils.getLiteralTimeValue(delay); } additionalDelayString = Long.toString(tv.toNanoSeconds()); } diff --git a/org.lflang/src/org/lflang/federated/FedASTUtils.java b/org.lflang/src/org/lflang/federated/FedASTUtils.java index a51a16e071..e16e5f70b8 100644 --- a/org.lflang/src/org/lflang/federated/FedASTUtils.java +++ b/org.lflang/src/org/lflang/federated/FedASTUtils.java @@ -46,7 +46,6 @@ import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Connection; -import org.lflang.lf.Delay; import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; @@ -125,7 +124,7 @@ private static Action createNetworkAction( // provided using after is enforced by setting // the minDelay. if (connection.getDelay() != null) { - action.setMinDelay(connection.getDelay().getTime()); + action.setMinDelay(connection.getDelay()); } } else { action.setOrigin(ActionOrigin.LOGICAL); @@ -580,7 +579,7 @@ private static void addNetworkOutputControlReaction( int channelIndex, int receivingFedID, GeneratorBase generator, - Delay delay + Expression delay ) { LfFactory factory = LfFactory.eINSTANCE; Reaction reaction = factory.createReaction(); diff --git a/org.lflang/src/org/lflang/federated/FederateInstance.java b/org.lflang/src/org/lflang/federated/FederateInstance.java index 1da57efe66..fa1ada37bf 100644 --- a/org.lflang/src/org/lflang/federated/FederateInstance.java +++ b/org.lflang/src/org/lflang/federated/FederateInstance.java @@ -47,7 +47,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.TriggerInstance; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; -import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Output; @@ -119,7 +119,7 @@ public FederateInstance( /** * A list of outputs that can be triggered directly or indirectly by physical actions. */ - public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); + public Set outputsConnectedToPhysicalActions = new LinkedHashSet<>(); /** * The host, if specified using the 'at' keyword. @@ -137,7 +137,7 @@ public FederateInstance( * may may include null, meaning that there is a connection * from the federate instance that has no delay. */ - public Map> dependsOn = new LinkedHashMap<>(); + public Map> dependsOn = new LinkedHashMap<>(); /** * The directory, if specified using the 'at' keyword. @@ -155,7 +155,7 @@ public FederateInstance( * may may include null, meaning that there is a connection * from the federate instance that has no delay. */ - public Map> sendsTo = new LinkedHashMap<>(); + public Map> sendsTo = new LinkedHashMap<>(); /** * The user, if specified using the 'at' keyword. diff --git a/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java b/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java index 81b6a456d6..488a8d021f 100644 --- a/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java +++ b/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java @@ -34,7 +34,7 @@ import org.lflang.federated.serialization.SupportedSerializers; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; -import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.VarRef; /** @@ -71,7 +71,7 @@ public static String generateNetworkSenderBody( FederateInstance receivingFed, InferredType type, boolean isPhysical, - Delay delay, + Expression delay, SupportedSerializers serializer, CoordinationType coordinationType ) { diff --git a/org.lflang/src/org/lflang/generator/ExpressionGenerator.java b/org.lflang/src/org/lflang/generator/ExpressionGenerator.java index 05b900fb8a..df89b1b2cf 100644 --- a/org.lflang/src/org/lflang/generator/ExpressionGenerator.java +++ b/org.lflang/src/org/lflang/generator/ExpressionGenerator.java @@ -7,7 +7,6 @@ import org.lflang.ASTUtils; import org.lflang.TimeValue; import org.lflang.lf.Assignment; -import org.lflang.lf.Delay; import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.Parameter; @@ -130,16 +129,6 @@ public String getTargetTime(Time t) { return timeInTargetLanguage.apply(new TimeValue(t.getInterval(), TimeUnit.fromName(t.getUnit()))); } - /** - * Return the time specified by {@code d}, expressed as - * code that is valid for some target languages. - */ - public String getTargetTime(Delay d) { - return d.getParameter() != null ? ASTUtils.toText(d) : timeInTargetLanguage.apply( - ASTUtils.toTimeValue(d.getTime()) // The time is given as a parameter reference. - ); - } - /** * Return the time specified by {@code v}, expressed as * code that is valid for some target languages. diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.java b/org.lflang/src/org/lflang/generator/GeneratorBase.java index a824ea9fb4..9912f79362 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.java +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.java @@ -64,7 +64,6 @@ import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Action; import org.lflang.lf.Connection; -import org.lflang.lf.Delay; import org.lflang.lf.Expression; import org.lflang.lf.Instantiation; import org.lflang.lf.LfFactory; @@ -715,7 +714,7 @@ public String generateNetworkSenderBody( FederateInstance receivingFed, InferredType type, boolean isPhysical, - Delay delay, + Expression delay, SupportedSerializers serializer ) { throw new UnsupportedOperationException("This target does not support network connections between federates."); @@ -753,7 +752,7 @@ public String generateNetworkOutputControlReactionBody( int receivingFederateID, int sendingBankIndex, int sendingChannelIndex, - Delay delay + Expression delay ) { throw new UnsupportedOperationException("This target does not support network connections between federates."); } @@ -1226,10 +1225,10 @@ private void replaceConnectionFromFederate( && targetConfig.coordination != CoordinationType.DECENTRALIZED) { // Map the delays on connections between federates. // First see if the cache has been created. - Set dependsOnDelays = dstFederate.dependsOn.get(srcFederate); + Set dependsOnDelays = dstFederate.dependsOn.get(srcFederate); if (dependsOnDelays == null) { // If not, create it. - dependsOnDelays = new LinkedHashSet(); + dependsOnDelays = new LinkedHashSet(); dstFederate.dependsOn.put(srcFederate, dependsOnDelays); } // Put the delay on the cache. @@ -1240,9 +1239,9 @@ private void replaceConnectionFromFederate( dependsOnDelays.add(null); } // Map the connections between federates. - Set sendsToDelays = srcFederate.sendsTo.get(dstFederate); + Set sendsToDelays = srcFederate.sendsTo.get(dstFederate); if (sendsToDelays == null) { - sendsToDelays = new LinkedHashSet(); + sendsToDelays = new LinkedHashSet(); srcFederate.sendsTo.put(dstFederate, sendsToDelays); } if (connection.getDelay() != null) { @@ -1357,13 +1356,4 @@ public static String getTargetTime(Expression expr) { } return ASTUtils.toText(expr); } - - // FIXME: this should be placed in ExpressionGenerator - public static String getTargetTime(Delay d) { - if (d.getParameter() != null) { - return ASTUtils.toText(d); - } else { - return getTargetTime(d.getTime()); - } - } } diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 3673069478..869806b303 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -39,7 +39,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.TriggerInstance.BuiltinTriggerVariable; import org.lflang.lf.Action; import org.lflang.lf.Connection; -import org.lflang.lf.Delay; import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; @@ -51,6 +50,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.lf.Reaction; import org.lflang.lf.Reactor; import org.lflang.lf.ReactorDecl; +import org.lflang.lf.Time; import org.lflang.lf.Timer; import org.lflang.lf.TriggerRef; import org.lflang.lf.VarRef; @@ -654,21 +654,6 @@ public TimeValue getTimeValue(Expression expr) { return ASTUtils.getLiteralTimeValue(expr); } } - - /** - * Assuming that the given delay denotes a valid time, return a time value. - * - * If the delay is given as a parameter reference, this will look up the - * precise time value assigned to this reactor instance. - */ - public TimeValue getTimeValue(Delay d) { - Parameter p = d.getParameter(); - if (p != null) { - return ASTUtils.getLiteralTimeValue(lookupParameterInstance(p).getInitialValue().get(0)); - } else { - return ASTUtils.toTimeValue(d.getTime()); - } - } ////////////////////////////////////////////////////// //// Protected fields. diff --git a/org.lflang/src/org/lflang/generator/c/CFederateGenerator.java b/org.lflang/src/org/lflang/generator/c/CFederateGenerator.java index 460256dc65..075ff51607 100644 --- a/org.lflang/src/org/lflang/generator/c/CFederateGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CFederateGenerator.java @@ -1,16 +1,11 @@ package org.lflang.generator.c; -import java.util.Map; - import org.lflang.ASTUtils; -import org.lflang.TargetConfig; -import org.lflang.TargetProperty.CoordinationType; import org.lflang.federated.FederateInstance; import org.lflang.generator.CodeBuilder; import org.lflang.generator.GeneratorBase; -import org.lflang.generator.ParameterInstance; -import org.lflang.generator.ReactorInstance; -import org.lflang.lf.Delay; +import org.lflang.lf.Expression; +import org.lflang.lf.ParameterReference; /** * Generate code for federate related functionality @@ -76,15 +71,16 @@ public static String generateFederateNeighborStructure(FederateInstance federate // There is at least one delay, so find the minimum. // If there is no delay at all, this is encoded as NEVER. code.pr("candidate_tmp = FOREVER;"); - for (Delay delay : delays) { + for (Expression delay : delays) { if (delay == null) { // Use NEVER to encode no delay at all. code.pr("candidate_tmp = NEVER;"); } else { var delayTime = GeneratorBase.getTargetTime(delay); - if (delay.getParameter() != null) { + if (delay instanceof ParameterReference) { // The delay is given as a parameter reference. Find its value. - delayTime = GeneratorBase.timeInTargetLanguage(ASTUtils.getDefaultAsTimeValue(delay.getParameter())); + final var param = ((ParameterReference)delay).getParameter(); + delayTime = GeneratorBase.timeInTargetLanguage(ASTUtils.getDefaultAsTimeValue(param)); } code.pr(String.join("\n", "if ("+delayTime+" < candidate_tmp) {", diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 86a0024e6d..5d6a3b248c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -92,7 +92,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.c.InteractingContainedReactors; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; -import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Instantiation; import org.lflang.lf.Mode; @@ -2476,7 +2476,7 @@ public String generateNetworkSenderBody( FederateInstance receivingFed, InferredType type, boolean isPhysical, - Delay delay, + Expression delay, SupportedSerializers serializer ) { return CNetworkGenerator.generateNetworkSenderBody( @@ -2537,7 +2537,7 @@ public String generateNetworkOutputControlReactionBody( int receivingFederateID, int sendingBankIndex, int sendingChannelIndex, - Delay delay + Expression delay ) { return CNetworkGenerator.generateNetworkOutputControlReactionBody( port, diff --git a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java index 382108415a..e6599863a1 100644 --- a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java @@ -2,9 +2,9 @@ import org.lflang.federated.CGeneratorExtension; import org.lflang.federated.FederateInstance; +import org.lflang.lf.Expression; import org.lflang.lf.VarRef; import org.lflang.lf.Action; -import org.lflang.lf.Delay; import org.lflang.lf.Port; import java.util.regex.Pattern; @@ -162,7 +162,7 @@ public static String generateNetworkSenderBody( FederateInstance receivingFed, InferredType type, boolean isPhysical, - Delay delay, + Expression delay, SupportedSerializers serializer, CTypes types, CoordinationType coordinationType @@ -321,7 +321,7 @@ public static String generateNetworkOutputControlReactionBody( int receivingFederateID, int sendingBankIndex, int sendingChannelIndex, - Delay delay + Expression delay ) { // Store the code var result = new CodeBuilder(); diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java index 0f6604b52f..93a2f41e1d 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.java @@ -67,7 +67,7 @@ import org.lflang.generator.c.CGenerator; import org.lflang.generator.c.CUtil; import org.lflang.lf.Action; -import org.lflang.lf.Delay; +import org.lflang.lf.Expression; import org.lflang.lf.Input; import org.lflang.lf.Model; import org.lflang.lf.Output; @@ -504,7 +504,7 @@ public String generateNetworkSenderBody( FederateInstance receivingFed, InferredType type, boolean isPhysical, - Delay delay, + Expression delay, SupportedSerializers serializer ) { return PythonNetworkGenerator.generateNetworkSenderBody( diff --git a/org.lflang/src/org/lflang/generator/python/PythonNetworkGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonNetworkGenerator.java index 205d353772..324b41961a 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonNetworkGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonNetworkGenerator.java @@ -2,9 +2,9 @@ import org.lflang.federated.FederateInstance; import org.lflang.federated.PythonGeneratorExtension; +import org.lflang.lf.Expression; import org.lflang.lf.VarRef; import org.lflang.lf.Action; -import org.lflang.lf.Delay; import org.lflang.InferredType; import org.lflang.TargetProperty.CoordinationType; import org.lflang.federated.serialization.SupportedSerializers; @@ -90,7 +90,7 @@ public static String generateNetworkSenderBody( FederateInstance receivingFed, InferredType type, boolean isPhysical, - Delay delay, + Expression delay, SupportedSerializers serializer, CoordinationType coordinationType ) { diff --git a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt index 758ac6650a..c772b3cb7b 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSGenerator.kt @@ -48,7 +48,6 @@ import org.lflang.generator.ExpressionGenerator import org.lflang.generator.GeneratorUtils.canGenerate import org.lflang.inferredType import org.lflang.lf.Action -import org.lflang.lf.Delay import org.lflang.lf.Expression import org.lflang.lf.Instantiation import org.lflang.lf.Parameter @@ -570,7 +569,7 @@ class TSGenerator( receivingFed: FederateInstance, type: InferredType, isPhysical: Boolean, - delay: Delay?, + delay: Expression?, serializer: SupportedSerializers ): String { return with(PrependOperator) {""" @@ -601,7 +600,7 @@ class TSGenerator( receivingFederateID: Int, sendingBankIndex: Int, sendingChannelIndex: Int, - delay: Delay? + delay: Expression? ): String? { return with(PrependOperator) {""" |// TODO(hokeun): Figure out what to do for generateNetworkOutputControlReactionBody From f9dd4ecc827ea6a6d29d03ed72f15da74e53a34d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 17:46:49 +0100 Subject: [PATCH 20/58] fix unit tests --- .../org/lflang/tests/compiler/LinguaFrancaValidationTest.java | 4 ++-- org.lflang/src/org/lflang/validation/LFValidator.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 12e8a7b227..a13d38df49 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -906,8 +906,8 @@ public void nonzeroAfterMustHaveUnits() throws Exception { " b = new X()", " a.y -> b.x after 1", "}"); - validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTime(), - null, "Missing or invalid time unit."); + validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getConnection(), + null, "Missing time unit."); } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index cb96759e4a..5d487af35a 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -363,10 +363,10 @@ public void checkConnection(Connection connection) { // Check the after delay if (connection.getDelay() != null) { final var delay = connection.getDelay(); - if (delay instanceof ParameterReference || delay instanceof Time) { + if (delay instanceof ParameterReference || delay instanceof Time || delay instanceof Literal) { checkExpressionAsTime(delay, Literals.CONNECTION__DELAY); } else { - error("After delays can only be given by time literals or paramters.", + error("After delays can only be given by time literals or parameters.", Literals.CONNECTION__DELAY); } } From 5ce567ea8f50a00fbb4575ed1087625d7ca5a31a Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 23 Mar 2022 17:58:40 +0100 Subject: [PATCH 21/58] delete unused grammar rule --- org.lflang/src/org/lflang/LinguaFranca.xtext | 6 ------ 1 file changed, 6 deletions(-) diff --git a/org.lflang/src/org/lflang/LinguaFranca.xtext b/org.lflang/src/org/lflang/LinguaFranca.xtext index 4e84d7291c..78252b9a8c 100644 --- a/org.lflang/src/org/lflang/LinguaFranca.xtext +++ b/org.lflang/src/org/lflang/LinguaFranca.xtext @@ -308,12 +308,6 @@ Time: (interval=INT unit=TimeUnit) ; -// This production is used when we know integer literals are -// to be interpreted as time. -TypedTime returns Time: - (interval=INT unit=TimeUnit?) -; - Port: Input | Output; From beee9e583eeb9356c899c4f637d5e8a80effeff8 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 24 Mar 2022 12:09:48 +0100 Subject: [PATCH 22/58] simplify time check --- .../src/org/lflang/validation/LFValidator.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 5d487af35a..ab324d69b2 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1436,21 +1436,13 @@ private void checkExpressionAsTime(Expression expr, EReference eReference) { if (!isOfTimeType(param) && target.requiresTypes) { error("Parameter is not of time type", eReference); } - } else if (!(expr instanceof Time)) { - if (expr instanceof Literal && !isZero(expr)) { - if (ASTUtils.isInteger(expr)) { - error("Missing time unit.", eReference); - } else { - error("Invalid time literal.", eReference); - } - } else if (expr instanceof Code) { - error("Invalid time literal.", eReference); + } else if(expr instanceof Literal) { + if (!isZero(expr)) { + error("Missing time unit.", eReference); } + } else if (!(expr instanceof Time)) { + error("Invalid time literal.", eReference); } - // FIXME: It will be hard to keep this list of expression types complete if we add more expressions - // in the future. Better to put the code in a mehtod and call it in the check methods for - // Timer, Action, Connection, Deadline, and have a default case where an error is reported - // on any umknown expression type. } /** From 7c530cd9a56618aa95a6085062899cf697c8cb2f Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 24 Mar 2022 12:23:52 +0100 Subject: [PATCH 23/58] avoid code duplication and always use checkExpressionAsTime --- .../org/lflang/generator/TimerInstance.java | 2 +- .../lflang/validation/BaseLFValidator.java | 2 +- .../org/lflang/validation/LFValidator.java | 33 ++----------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/TimerInstance.java b/org.lflang/src/org/lflang/generator/TimerInstance.java index f1250ea05f..6683b37bdb 100644 --- a/org.lflang/src/org/lflang/generator/TimerInstance.java +++ b/org.lflang/src/org/lflang/generator/TimerInstance.java @@ -70,7 +70,7 @@ public TimerInstance(Timer definition, ReactorInstance parent) { try { this.period = parent.getTimeValue(definition.getPeriod()); } catch (IllegalArgumentException ex) { - parent.reporter.reportError(definition.getOffset(), "Invalid time."); + parent.reporter.reportError(definition.getPeriod(), "Invalid time."); } } } diff --git a/org.lflang/src/org/lflang/validation/BaseLFValidator.java b/org.lflang/src/org/lflang/validation/BaseLFValidator.java index 1ce506efb3..6b6e7e91ab 100644 --- a/org.lflang/src/org/lflang/validation/BaseLFValidator.java +++ b/org.lflang/src/org/lflang/validation/BaseLFValidator.java @@ -44,7 +44,7 @@ public class BaseLFValidator extends AbstractLFValidator { @Check(CheckType.FAST) public void checkTime(Time time) { if (!ASTUtils.isValidTime(time)) { - error("Missing or invalid time unit. " + + error("Invalid time unit. " + "Should be one of " + TimeUnit.list() + ".", Literals.TIME__UNIT); } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index ab324d69b2..7d661d6201 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -29,8 +29,6 @@ import static org.lflang.ASTUtils.inferPortWidth; import static org.lflang.ASTUtils.isGeneric; import static org.lflang.ASTUtils.isOfTimeType; -import static org.lflang.ASTUtils.isParameterized; -import static org.lflang.ASTUtils.isValidTime; import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; import static org.lflang.ASTUtils.toText; @@ -67,7 +65,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.Deadline; import org.lflang.lf.Expression; @@ -168,19 +165,7 @@ public void checkAssignment(Assignment assignment) { error("Incompatible type.", Literals.ASSIGNMENT__RHS); } else if (assignment.getRhs().size() > 0) { Expression expr = assignment.getRhs().get(0); - if (!isValidTime(expr)) { - if (expr instanceof Literal) { - error("Missing time unit.", Literals.ASSIGNMENT__RHS); - } else if (expr instanceof ParameterReference) { - final var param = ((ParameterReference) expr).getParameter(); - error("Cannot assign parameter: " + param.getName() + " to " + - assignment.getLhs().getName() + - ". The latter is a time parameter, but the former is not.", - Literals.ASSIGNMENT__RHS); - } else { - error("This is not a valid time expression.", Literals.ASSIGNMENT__RHS); - } - } + checkExpressionAsTime(expr, Literals.ASSIGNMENT__RHS); } // If this assignment overrides a parameter that is used in a deadline, // report possible overflow. @@ -1001,21 +986,7 @@ public void checkState(StateVar stateVar) { // make sure that it is initialized correctly. if (stateVar.getInit() != null) { for (Expression expr : stateVar.getInit()) { - if (stateVar.getType() != null && stateVar.getType().isTime() && !isValidTime(expr)) { - if (isParameterized(stateVar)) { - error( - "Referenced parameter does not denote a time.", - Literals.STATE_VAR__INIT); - } else if (expr != null && !ASTUtils.isZero(expr)) { - if (ASTUtils.isInteger(expr)) { - error( - "Missing time unit.", Literals.STATE_VAR__INIT); - } else { - error("Invalid time literal.", - Literals.STATE_VAR__INIT); - } - } - } + checkExpressionAsTime(expr, Literals.STATE_VAR__INIT); } } } else if (this.target.requiresTypes && ASTUtils.getInferredType(stateVar).isUndefined()) { From f87774e385b62e7718ba3735e65f714b34a6d374 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 21 Apr 2022 16:24:06 +0200 Subject: [PATCH 24/58] refactor: toText(Code) -> toTaggedText(Code) --- org.lflang/src/org/lflang/ASTUtils.java | 8 ++++---- org.lflang/src/org/lflang/AstExtensions.kt | 12 ++++++------ .../org/lflang/generator/ReactionInstance.java | 2 +- .../src/org/lflang/generator/TargetTypes.java | 2 +- .../src/org/lflang/generator/c/CGenerator.java | 16 ++-------------- .../lflang/generator/c/CReactionGenerator.java | 7 ++----- .../org/lflang/generator/cpp/CppExtensions.kt | 3 ++- .../lflang/generator/cpp/CppMethodGenerator.kt | 4 ++-- .../lflang/generator/cpp/CppPreambleGenerator.kt | 6 +++--- .../lflang/generator/cpp/CppReactionGenerator.kt | 6 +++--- .../lflang/generator/cpp/CppReactorGenerator.kt | 6 +++--- .../python/PythonPreambleGenerator.java | 2 +- .../python/PythonReactionGenerator.java | 4 ++-- .../src/org/lflang/generator/rust/RustModel.kt | 8 ++++---- .../src/org/lflang/generator/rust/RustTypes.kt | 4 ++-- .../lflang/generator/ts/TSConnectionGenerator.kt | 5 ----- .../src/org/lflang/generator/ts/TSExtensions.kt | 4 ++-- .../lflang/generator/ts/TSReactionGenerator.kt | 10 +++++----- .../lflang/generator/ts/TSReactorGenerator.kt | 2 +- 19 files changed, 46 insertions(+), 65 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 4fc1fe0ae7..c199d17ec4 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -776,7 +776,7 @@ public static List collectElements(Reactor definition, EStructuralFeature * @param code AST node to render as string. * @return Textual representation of the given argument. */ - public static String toText(Code code) { + public static String toTaggedText(Code code) { return CodeMap.Correspondence.tag(code, toUntaggedText(code), true); } @@ -824,7 +824,7 @@ private static String toUntaggedText(Code code) { } public static String toText(TypeParm t) { - return !StringExtensions.isNullOrEmpty(t.getLiteral()) ? t.getLiteral() : toText(t.getCode()); + return !StringExtensions.isNullOrEmpty(t.getLiteral()) ? t.getLiteral() : toTaggedText(t.getCode()); } /** @@ -912,7 +912,7 @@ public static String toText(Expression expr) { } else if (expr instanceof Literal) { return ((Literal) expr).getLiteral(); } else if (expr instanceof Code) { - return toText((Code) expr); + return toTaggedText((Code) expr); } else { throw new RuntimeException("Unknown expression type!"); } @@ -993,7 +993,7 @@ public static List toListOfStrings(Element value) { public static String baseType(Type type) { if (type != null) { if (type.getCode() != null) { - return toText(type.getCode()); + return toTaggedText(type.getCode()); } else { if (type.isTime()) { return "time"; diff --git a/org.lflang/src/org/lflang/AstExtensions.kt b/org.lflang/src/org/lflang/AstExtensions.kt index fe1a6dd805..d1ddfc570c 100644 --- a/org.lflang/src/org/lflang/AstExtensions.kt +++ b/org.lflang/src/org/lflang/AstExtensions.kt @@ -138,17 +138,17 @@ val StateVar.isOfTimeType: Boolean get() = ASTUtils.isOfTimeType(this) /** * Translate this code element into its textual representation. - * @see ASTUtils.toText + * @see ASTUtils.toTaggedText */ -fun Code.toText(): String = ASTUtils.toText(this) +fun Code.toTaggedText(): String = ASTUtils.toTaggedText(this) /** * Translate this code element into its textual representation. - * @see ASTUtils.toText + * @see ASTUtils.toTaggedText */ fun TypeParm.toText(): String = if (!literal.isNullOrEmpty()) literal - else code.toText() + else code.toTaggedText() /** @@ -224,7 +224,7 @@ fun Type.toText(): String = baseType + arraySpec?.toText().orEmpty() */ val Type.baseType: String get() = when { - code != null -> code.toText() + code != null -> code.toTaggedText() isTime -> "time" else -> id + stars.orEmpty().joinToString() } @@ -237,7 +237,7 @@ val Type.baseType: String */ val String.isZero: Boolean get() = this.toIntOrNull() == 0 -val Code.isZero: Boolean get() = this.toText().isZero +val Code.isZero: Boolean get() = this.toTaggedText().isZero /** diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index a0f9d53432..c4b223fa86 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -81,7 +81,7 @@ public ReactionInstance( // If the reaction body starts with the magic string // UNORDERED_REACTION_MARKER, then mark it unordered, // overriding the argument. - String body = ASTUtils.toText(definition.getCode()); + String body = ASTUtils.toTaggedText(definition.getCode()); if (body != null && body.contains(UNORDERED_REACTION_MARKER)) { this.isUnordered = true; } diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/src/org/lflang/generator/TargetTypes.java index 19a9ebfea8..3628fb2ebe 100644 --- a/org.lflang/src/org/lflang/generator/TargetTypes.java +++ b/org.lflang/src/org/lflang/generator/TargetTypes.java @@ -238,7 +238,7 @@ default String getTargetExpr(Expression expr, InferredType type) { } else if (expr instanceof Literal) { return ASTUtils.addZeroToLeadingDot(((Literal) expr).getLiteral()); // here we don't escape } else if (expr instanceof Code) { - return ASTUtils.toText((Code) expr); + return ASTUtils.toTaggedText((Code) expr); } else { throw new IllegalStateException("Invalid value " + expr); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 9e683ed7d9..51eb01dc4f 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -78,18 +78,6 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY import org.lflang.generator.TargetTypes; import org.lflang.generator.TimerInstance; import org.lflang.generator.TriggerInstance; -import org.lflang.generator.c.CActionGenerator; -import org.lflang.generator.c.CTimerGenerator; -import org.lflang.generator.c.CStateGenerator; -import org.lflang.generator.c.CTracingGenerator; -import org.lflang.generator.c.CPortGenerator; -import org.lflang.generator.c.CModesGenerator; -import org.lflang.generator.c.CMainGenerator; -import org.lflang.generator.c.CFederateGenerator; -import org.lflang.generator.c.CNetworkGenerator; -import org.lflang.generator.c.CTriggerObjectsGenerator; -import org.lflang.generator.c.CConstructorGenerator; -import org.lflang.generator.c.InteractingContainedReactors; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; import org.lflang.lf.Expression; @@ -1331,7 +1319,7 @@ public void generateUserPreamblesForReactor(Reactor reactor) { for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { code.pr("// *********** From the preamble, verbatim:"); code.prSourceLineNumber(p.getCode()); - code.pr(toText(p.getCode())); + code.pr(toTaggedText(p.getCode())); code.pr("\n// *********** End of preamble."); } } @@ -2633,7 +2621,7 @@ protected void generateTopLevelPreambles() { if (this.mainDef != null) { var mainModel = (Model) toDefinition(mainDef.getReactorClass()).eContainer(); for (Preamble p : mainModel.getPreambles()) { - code.pr(toText(p.getCode())); + code.pr(toTaggedText(p.getCode())); } } } diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index b36a767a49..88443ecb48 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -11,12 +11,9 @@ import org.lflang.ASTUtils; import org.lflang.ErrorReporter; import org.lflang.InferredType; -import org.lflang.Target; import org.lflang.federated.CGeneratorExtension; import org.lflang.federated.FederateInstance; import org.lflang.generator.CodeBuilder; -import org.lflang.generator.ReactionInstance; -import org.lflang.generator.TriggerInstance; import org.lflang.generator.ModeInstance.ModeTransitionType; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -1181,7 +1178,7 @@ public static String generateReaction( boolean requiresType ) { var code = new CodeBuilder(); - var body = ASTUtils.toText(reaction.getCode()); + var body = ASTUtils.toTaggedText(reaction.getCode()); String init = generateInitializationForReaction( body, reaction, decl, reactionIndex, types, errorReporter, mainDef, @@ -1216,7 +1213,7 @@ public static String generateFunction(String header, String init, Code code) { function.indent(); function.pr(init); function.prSourceLineNumber(code); - function.pr(ASTUtils.toText(code)); + function.pr(ASTUtils.toTaggedText(code)); function.unindent(); function.pr("}"); return function.toString(); diff --git a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt index 03cd752049..ab7b274268 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt @@ -20,6 +20,7 @@ import org.lflang.lf.VarRef import org.lflang.lf.Visibility import org.lflang.lf.WidthSpec import org.lflang.toText +import org.lflang.toTaggedText import org.lflang.unreachable /************* @@ -98,7 +99,7 @@ fun WidthSpec.toCppCode(): String = terms.joinToString(" + ") { else "1" } } - it.code != null -> it.code.toText() + it.code != null -> it.code.toTaggedText() else -> it.width.toString() } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt index 17aa30032c..3497a964c5 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt @@ -29,7 +29,7 @@ import org.lflang.generator.PrependOperator import org.lflang.lf.Method import org.lflang.lf.MethodArgument import org.lflang.lf.Reactor -import org.lflang.toText +import org.lflang.toTaggedText /** A C++ code generator for state variables */ class CppMethodGenerator(private val reactor: Reactor) { @@ -45,7 +45,7 @@ class CppMethodGenerator(private val reactor: Reactor) { """ |${reactor.templateLine} |$targetType ${reactor.templateName}::Inner::$name(${cppArgs.joinToString(", ")})$constQualifier { - ${" | "..code.toText()} + ${" | "..code.toTaggedText()} |} """.trimMargin() } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt index 9ec9b31b3e..17e130edb7 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt @@ -30,7 +30,7 @@ import org.lflang.generator.PrependOperator import org.lflang.lf.Preamble import org.lflang.model import org.lflang.scoping.LFGlobalScopeProvider -import org.lflang.toText +import org.lflang.toTaggedText import org.lflang.toUnixString @@ -60,7 +60,7 @@ class CppPreambleGenerator( |#include "reactor-cpp/reactor-cpp.hh" ${" |"..includes.joinToString(separator = "\n", prefix = "// include the preambles from imported files \n")} | - ${" |"..publicPreambles.joinToString(separator = "\n") { it.code.toText() }} + ${" |"..publicPreambles.joinToString(separator = "\n") { it.code.toTaggedText() }} """.trimMargin() } } @@ -79,7 +79,7 @@ class CppPreambleGenerator( |using namespace std::chrono_literals; |using namespace reactor::operators; | - ${" |"..privatePreambles.joinToString(separator = "\n") { it.code.toText() }} + ${" |"..privatePreambles.joinToString(separator = "\n") { it.code.toTaggedText() }} """.trimMargin() } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt index f418255c35..1aacc3659a 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt @@ -29,7 +29,7 @@ import org.lflang.isBank import org.lflang.label import org.lflang.lf.* import org.lflang.priority -import org.lflang.toText +import org.lflang.toTaggedText /** A C++ code generator for reactions and their function bodies */ class CppReactionGenerator( @@ -144,7 +144,7 @@ class CppReactionGenerator( |// reaction ${reaction.label} |${reactor.templateLine} ${" |"..getFunctionDefinitionSignature(reaction, "body")} { - ${" | "..reaction.code.toText()} + ${" | "..reaction.code.toTaggedText()} |} | """.trimMargin() @@ -155,7 +155,7 @@ class CppReactionGenerator( return """ |${reactor.templateLine} ${" |"..getFunctionDefinitionSignature(reaction, "deadline_handler")} { - ${" | "..reaction.deadline.code.toText()} + ${" | "..reaction.deadline.code.toTaggedText()} |} | """.trimMargin() diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt index 85556a83a9..eca65cb197 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt @@ -28,7 +28,7 @@ import org.lflang.ErrorReporter import org.lflang.generator.PrependOperator import org.lflang.isGeneric import org.lflang.lf.Reactor -import org.lflang.toText +import org.lflang.toTaggedText import org.lflang.toUnixString /** @@ -61,11 +61,11 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi private fun publicPreamble() = reactor.preambles.filter { it.isPublic } - .joinToString(separator = "\n", prefix = "// public preamble\n") { it.code.toText() } + .joinToString(separator = "\n", prefix = "// public preamble\n") { it.code.toTaggedText() } private fun privatePreamble() = reactor.preambles.filter { it.isPrivate } - .joinToString(separator = "\n", prefix = "// private preamble\n") { it.code.toText() } + .joinToString(separator = "\n", prefix = "// private preamble\n") { it.code.toTaggedText() } /** Generate a C++ header file declaring the given reactor. */ fun generateHeader() = with(PrependOperator) { diff --git a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java index cdceba56fe..331d03bc5a 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java @@ -26,7 +26,7 @@ public class PythonPreambleGenerator { */ public static String generatePythonPreambles(List preambles) { List preamblesCode = new ArrayList<>(); - preambles.forEach(p -> preamblesCode.add(ASTUtils.toText(p.getCode()))); + preambles.forEach(p -> preamblesCode.add(ASTUtils.toTaggedText(p.getCode()))); return preamblesCode.size() > 0 ? String.join("\n", "# From the preamble, verbatim:", String.join("\n", preamblesCode), diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 80367512a3..f34c18a7d7 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -502,7 +502,7 @@ public static String generatePythonReaction(Reactor reactor, Reaction reaction, code.pr(generatePythonFunction( generatePythonReactionFunctionName(reactionIndex), inits.toString(), - ASTUtils.toText(reaction.getCode()), + ASTUtils.toTaggedText(reaction.getCode()), reactionParameters )); // Now generate code for the deadline violation function, if there is one. @@ -510,7 +510,7 @@ public static String generatePythonReaction(Reactor reactor, Reaction reaction, code.pr(generatePythonFunction( generatePythonDeadlineFunctionName(reactionIndex), "", - ASTUtils.toText(reaction.getDeadline().getCode()), + ASTUtils.toTaggedText(reaction.getDeadline().getCode()), reactionParameters )); } diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 2d47becd69..1a0ead4902 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -333,7 +333,7 @@ sealed class ReactorComponent { ?.let { TimeValue(it.toLong(), DEFAULT_TIME_UNIT_IN_TIMER).toRustTimeExpr() } ?: throw InvalidLfSourceException("Not an integer literal", this) this is Time -> toRustTimeExpr() - this is Code -> toText().inBlock() + this is Code -> toTaggedText().inBlock() else -> RustTypes.getTargetExpr(this, InferredType.time()) } } @@ -389,7 +389,7 @@ fun WidthSpec.toRustExpr(): String = terms.joinToString(" + ") { when { it.parameter != null -> it.parameter.name it.port != null -> throw UnsupportedGeneratorFeatureException("Width specs that use a port") - it.code != null -> it.code.toText().inBlock() + it.code != null -> it.code.toTaggedText().inBlock() else -> it.width.toString() } } @@ -531,7 +531,7 @@ object RustModelBuilder { this[DepKind.Uses] = makeDeps { sources } this[DepKind.Effects] = makeDeps { effects } }, - body = n.code.toText(), + body = n.code.toTaggedText(), isStartup = n.triggers.any { it.isStartup }, isShutdown = n.triggers.any { it.isShutdown }, debugLabel = ASTUtils.label(n), @@ -559,7 +559,7 @@ object RustModelBuilder { typeParamList = reactor.typeParms.map { TypeParamInfo(targetCode = it.toText(), it.identifier, it.locationInfo()) }, - preambles = reactor.preambles.map { it.code.toText() }, + preambles = reactor.preambles.map { it.code.toTaggedText() }, stateVars = reactor.stateVars.map { StateVarInfo( lfName = it.name, diff --git a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt index f555aff7fb..535e12f38f 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt @@ -24,7 +24,7 @@ package org.lflang.generator.rust -import org.lflang.ASTUtils.toText +import org.lflang.ASTUtils.toTaggedText import org.lflang.InferredType import org.lflang.TimeValue import org.lflang.generator.TargetCode @@ -54,7 +54,7 @@ object RustTypes : TargetTypes { else ident override fun getTargetExpr(expr: Expression, type: InferredType?): String = when (expr) { - is Code -> toText(expr).inBlock() + is Code -> toTaggedText(expr).inBlock() else -> super.getTargetExpr(expr, type) } diff --git a/org.lflang/src/org/lflang/generator/ts/TSConnectionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSConnectionGenerator.kt index 166774537f..9083fc049e 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSConnectionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSConnectionGenerator.kt @@ -3,13 +3,8 @@ package org.lflang.generator.ts import org.lflang.ErrorReporter import org.lflang.hasMultipleConnections import org.lflang.isBank -import org.lflang.isInput -import org.lflang.isMultiport import org.lflang.lf.Connection -import org.lflang.lf.Port -import org.lflang.lf.Reactor import org.lflang.lf.VarRef -import org.lflang.toText import java.util.* /** diff --git a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt index f8ed80ae68..7d8e9565e5 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt @@ -8,7 +8,7 @@ import org.lflang.lf.Parameter import org.lflang.lf.Port import org.lflang.lf.Type import org.lflang.lf.WidthSpec -import org.lflang.toText +import org.lflang.toTaggedText /** * The following definition provide extension that are useful for TypeScript target. @@ -27,7 +27,7 @@ fun WidthSpec.toTSCode(): String = terms.joinToString(" + ") { else "1" } } - it.code != null -> it.code.toText() + it.code != null -> it.code.toTaggedText() else -> it.width.toString() } } diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt index d5433fb295..5bec4cf60d 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt @@ -8,7 +8,7 @@ import org.lflang.isBank import org.lflang.isMultiport import org.lflang.lf.* import org.lflang.lf.Timer -import org.lflang.toText +import org.lflang.toTaggedText import java.util.* import kotlin.collections.HashSet @@ -87,7 +87,7 @@ class TSReactionGenerator( ${" | "..reactPrologue} | // =============== END deadline prologue | try { - ${" | "..reaction.deadline.code.toText()} + ${" | "..reaction.deadline.code.toTaggedText()} | } finally { | // =============== START deadline epilogue ${" | "..reactEpilogue} @@ -128,7 +128,7 @@ class TSReactionGenerator( ${" | "..reactPrologue} | // =============== END react prologue | try { - ${" | "..reaction.code.toText()} + ${" | "..reaction.code.toTaggedText()} | } finally { | // =============== START react epilogue ${" | "..reactEpilogue} @@ -459,8 +459,8 @@ class TSReactionGenerator( // TODO(hokeun): Find a better way to gracefully handle this skipping. // Do not add reactions created by generateNetworkOutputControlReactionBody // or generateNetworkInputControlReactionBody. - if (reaction.code.toText().contains("generateNetworkOutputControlReactionBody") - || reaction.code.toText().contains("generateNetworkInputControlReactionBody")) { + if (reaction.code.toTaggedText().contains("generateNetworkOutputControlReactionBody") + || reaction.code.toTaggedText().contains("generateNetworkInputControlReactionBody")) { continue; } if (federate.contains(reaction)) { diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt index 0b00f8c351..55b3334552 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt @@ -89,7 +89,7 @@ class TSReactorGenerator( preambleCodes.add(with(PrependOperator) { """ |// *********** From the preamble, verbatim: - |${preamble.code.toText()} + |${preamble.code.toTaggedText()} | |// *********** End of preamble."""}.trimMargin()) } From d3cd947159abd7e65de0519f1b6436a1c73acd70 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 21 Apr 2022 17:59:00 +0200 Subject: [PATCH 25/58] implement toText in dedicated switch class --- org.lflang/src/org/lflang/ASTUtils.java | 170 ++---------------- org.lflang/src/org/lflang/AstExtensions.kt | 77 +------- org.lflang/src/org/lflang/TargetProperty.java | 5 +- org.lflang/src/org/lflang/ast/ToText.java | 116 ++++++++++++ .../generator/cpp/CppReactionGenerator.kt | 1 + 5 files changed, 140 insertions(+), 229 deletions(-) create mode 100644 org.lflang/src/org/lflang/ast/ToText.java diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index c199d17ec4..476c230c47 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -45,7 +45,6 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.TerminalRule; import org.eclipse.xtext.nodemodel.ICompositeNode; -import org.eclipse.xtext.nodemodel.ILeafNode; import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.impl.CompositeNode; import org.eclipse.xtext.nodemodel.impl.HiddenLeafNode; @@ -57,12 +56,12 @@ import org.eclipse.xtext.xbase.lib.IteratorExtensions; import org.eclipse.xtext.xbase.lib.StringExtensions; +import org.lflang.ast.ToText; import org.lflang.generator.CodeMap; import org.lflang.generator.GeneratorBase; import org.lflang.generator.InvalidSourceException; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; -import org.lflang.lf.ArraySpec; import org.lflang.lf.Assignment; import org.lflang.lf.Code; import org.lflang.lf.Connection; @@ -93,7 +92,6 @@ import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; -import org.lflang.util.StringUtil; import com.google.common.collect.HashMultimap; import com.google.common.collect.Iterators; @@ -771,78 +769,26 @@ public static List collectElements(Reactor definition, EStructuralFeature //////////////////////////////// //// Utility functions for translating AST nodes into text + /** Instance of a switch class for creating textual representations of AST nodes */ + private static final ToText toText = new ToText(); + /** * Translate the given code into its textual representation. - * @param code AST node to render as string. + * @param node AST node to render as string. * @return Textual representation of the given argument. */ - public static String toTaggedText(Code code) { - return CodeMap.Correspondence.tag(code, toUntaggedText(code), true); + public static String toText(EObject node) { + return toText.doSwitch(node); } /** * Translate the given code into its textual representation - * without any {@code CodeMap.Correspondence} tags inserted. - * @param code AST node to render as string. + * with additional {@code CodeMap.Correspondence} tags inserted. + * @param node AST node to render as string. * @return Textual representation of the given argument. */ - private static String toUntaggedText(Code code) { - // FIXME: This function should not be necessary, but it is because we currently inspect the - // content of code blocks in the validator and generator (using regexes, etc.). See #810, #657. - String text = ""; - if (code != null) { - ICompositeNode node = NodeModelUtils.getNode(code); - if (node != null) { - StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1)); - for (ILeafNode leaf : node.getLeafNodes()) { - builder.append(leaf.getText()); - } - String str = builder.toString().trim(); - // Remove the code delimiters (and any surrounding comments). - // This assumes any comment before {= does not include {=. - int start = str.indexOf("{="); - int end = str.indexOf("=}", start); - if (start == -1 || end == -1) { - // Silent failure is needed here because toText is needed to create the intermediate representation, - // which the validator uses. - return str; - } - str = str.substring(start + 2, end); - if (str.split("\n").length > 1) { - // multi line code - text = StringUtil.trimCodeBlock(str); - } else { - // single line code - text = str.trim(); - } - } else if (code.getBody() != null) { - // Code must have been added as a simple string. - text = code.getBody(); - } - } - return text; - } - - public static String toText(TypeParm t) { - return !StringExtensions.isNullOrEmpty(t.getLiteral()) ? t.getLiteral() : toTaggedText(t.getCode()); - } - - /** - * Return a textual representation of the given element, - * without quotes if there are any. Leading or trailing - * whitespace is removed. - * - * @param e The element to be rendered as a string. - */ - public static String toText(Element e) { - String str = ""; - if (e.getLiteral() != null) { - str = withoutQuotes(e.getLiteral()).trim(); - } - if (e.getId() != null) { - str = e.getId(); - } - return str; + public static String toTaggedText(EObject node) { + return CodeMap.Correspondence.tag(node, toText(node), true); } /** @@ -886,80 +832,6 @@ public static boolean toBoolean(Element e) { return toText(e).equalsIgnoreCase("true"); } - /** - * Convert a time to its textual representation as it would - * appear in LF code. - * - * @param t The time to be converted - * @return A textual representation - */ - public static String toText(Time t) { - return toTimeValue(t).toString(); - } - - /** - * Convert an expression to its textual representation as it would - * appear in LF code. - * - * @param expr The expression to be converted - * @return A textual representation - */ - public static String toText(Expression expr) { - if (expr instanceof ParameterReference) { - return ((ParameterReference) expr).getParameter().getName(); - } else if (expr instanceof Time ) { - return toText((Time) expr); - } else if (expr instanceof Literal) { - return ((Literal) expr).getLiteral(); - } else if (expr instanceof Code) { - return toTaggedText((Code) expr); - } else { - throw new RuntimeException("Unknown expression type!"); - } - } - - /** - * Return a string of the form either "name" or "container.name" depending - * on in which form the variable reference was given. - * @param v The variable reference. - */ - public static String toText(VarRef v) { - if (v.getContainer() != null) { - return String.format("%s.%s", v.getClass().getName(), v.getVariable().getName()); - } else { - return v.getVariable().getName(); - } - } - - /** - * Convert an array specification to its textual representation as it would - * appear in LF code. - * - * @param spec The array spec to be converted - * @return A textual representation - */ - public static String toText(ArraySpec spec) { - if (spec != null) { - return (spec.isOfVariableLength()) ? "[]" : "[" + spec.getLength() + "]"; - } - return ""; - } - - /** - * Translate the given type into its textual representation, including - * any array specifications. - * @param type AST node to render as string. - * @return Textual representation of the given argument. - */ - public static String toText(Type type) { - if (type != null) { - String base = baseType(type); - String arr = (type.getArraySpec() != null) ? toText(type.getArraySpec()) : ""; - return base + arr; - } - return ""; - } - /** * Given the right-hand side of a target property, return a list with all * the strings that the property lists. @@ -1035,7 +907,7 @@ public static boolean isZero(String literal) { } public static boolean isZero(Code code) { - return code != null && isZero(toUntaggedText(code)); + return code != null && isZero(toText(code)); } /** @@ -1074,7 +946,7 @@ public static boolean isInteger(String literal) { * @return True if the given code is an integer, false otherwise. */ public static boolean isInteger(Code code) { - return isInteger(toUntaggedText(code)); + return isInteger(toText(code)); } /** @@ -1851,21 +1723,7 @@ public static String findAnnotationInComments(EObject object, String key) { } return null; } - - /** - * Remove quotation marks surrounding the specified string. - */ - public static String withoutQuotes(String s) { - String result = s; - if (s.startsWith("\"") || s.startsWith("'")) { - result = s.substring(1); - } - if (result.endsWith("\"") || result.endsWith("'")) { - result = result.substring(0, result.length() - 1); - } - return result; - } - + /** * Search for an `@label` annotation for a given reaction. * diff --git a/org.lflang/src/org/lflang/AstExtensions.kt b/org.lflang/src/org/lflang/AstExtensions.kt index d1ddfc570c..19b773a21c 100644 --- a/org.lflang/src/org/lflang/AstExtensions.kt +++ b/org.lflang/src/org/lflang/AstExtensions.kt @@ -137,84 +137,19 @@ val Parameter.isOfTimeType: Boolean get() = ASTUtils.isOfTimeType(this) val StateVar.isOfTimeType: Boolean get() = ASTUtils.isOfTimeType(this) /** - * Translate this code element into its textual representation. + * Translate this code element into its textual representation + * with additional {@code CodeMap.Correspondence} tags inserted. * @see ASTUtils.toTaggedText */ -fun Code.toTaggedText(): String = ASTUtils.toTaggedText(this) +fun EObject.toTaggedText(): String = ASTUtils.toTaggedText(this) /** * Translate this code element into its textual representation. - * @see ASTUtils.toTaggedText - */ -fun TypeParm.toText(): String = - if (!literal.isNullOrEmpty()) literal - else code.toTaggedText() - - -/** - * Return a textual representation of this element, - * without quotes if there are any. Leading or trailing - * whitespace is removed. - * - * @receiver The element to be rendered as a string. - */ -fun Element.toText(): String = - literal?.withoutQuotes()?.trim() ?: id ?: "" - -fun Time.toTimeValue(): TimeValue = TimeValue(interval.toLong(), TimeUnit.fromName(this.unit)) - - -/** - * Return a string of the form either "name" or "container.name" depending - * on in which form the variable reference was given. - * @receiver The variable reference. + * @see ASTUtils.toText */ -fun TriggerRef.toText(): String = - when { - this is VarRef && container != null -> "${container.name}.${variable.name}" - this is VarRef -> variable.name - isStartup -> "startup" - isShutdown -> "shutdown" - else -> throw UnsupportedOperationException("What's this ref: $this") - } - +fun EObject.toText(): String = ASTUtils.toText(this) -/** - * Convert an expression to its textual representation as it would - * appear in LF code. - * - * @receiver The value to be converted - * @return A textual representation - */ -fun Expression.toText(): String = ASTUtils.toText(this) - -/** - * Convert a time to its textual representation as it would - * appear in LF code. - * @receiver The time to be converted - */ -fun Time.toText(): String = "$interval $unit" - - -/** - * Convert an array specification to its textual representation as it would - * appear in LF code. - * - * @receiver The array spec to be converted - * @return A textual representation - */ -fun ArraySpec.toText(): String = - if (isOfVariableLength) "[]" - else "[$length]" - - -/** - * Translate the given type into its textual representation, including - * any array specifications. - * @receiver AST node to render as string. - * @return Textual representation of the given argument. - */ -fun Type.toText(): String = baseType + arraySpec?.toText().orEmpty() +fun Time.toTimeValue(): TimeValue = ASTUtils.toTimeValue(this) /** * Translate the given type into its textual representation, but diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 8a0e49a0ca..fd122db845 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -44,6 +44,7 @@ import org.lflang.lf.KeyValuePair; import org.lflang.lf.KeyValuePairs; import org.lflang.util.FileUtil; +import org.lflang.util.StringUtil; import org.lflang.validation.LFValidator; /** @@ -440,12 +441,12 @@ public enum TargetProperty { // are as expected. if (value.getLiteral() != null) { - Path resolved = referencePath.resolveSibling(ASTUtils.withoutQuotes(value.getLiteral())); + Path resolved = referencePath.resolveSibling(StringUtil.removeQuotes(value.getLiteral())); config.rust.addAndCheckTopLevelModule(resolved, value, err); } else if (value.getArray() != null) { for (Element element : value.getArray().getElements()) { - String literal = ASTUtils.withoutQuotes(element.getLiteral()); + String literal = StringUtil.removeQuotes(element.getLiteral()); Path resolved = referencePath.resolveSibling(literal); config.rust.addAndCheckTopLevelModule(resolved, element, err); } diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java new file mode 100644 index 0000000000..b6cea1677f --- /dev/null +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -0,0 +1,116 @@ +package org.lflang.ast; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.ILeafNode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; +import org.eclipse.xtext.xbase.lib.StringExtensions; + +import org.lflang.ASTUtils; +import org.lflang.lf.ArraySpec; +import org.lflang.lf.Code; +import org.lflang.lf.Element; +import org.lflang.lf.Literal; +import org.lflang.lf.ParameterReference; +import org.lflang.lf.Time; +import org.lflang.lf.Type; +import org.lflang.lf.TypeParm; +import org.lflang.lf.VarRef; +import org.lflang.lf.util.LfSwitch; +import org.lflang.util.StringUtil; + +public class ToText extends LfSwitch { + + @Override + public String caseArraySpec(ArraySpec spec) { + return (spec.isOfVariableLength()) ? "[]" : "[" + spec.getLength() + "]"; + } + + @Override + public String caseCode(Code code) { + String text = ""; + if (code != null) { + ICompositeNode node = NodeModelUtils.getNode(code); + if (node != null) { + StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1)); + for (ILeafNode leaf : node.getLeafNodes()) { + builder.append(leaf.getText()); + } + String str = builder.toString().trim(); + // Remove the code delimiters (and any surrounding comments). + // This assumes any comment before {= does not include {=. + int start = str.indexOf("{="); + int end = str.indexOf("=}", start); + if (start == -1 || end == -1) { + // Silent failure is needed here because toText is needed to create the intermediate representation, + // which the validator uses. + return str; + } + str = str.substring(start + 2, end); + if (str.split("\n").length > 1) { + // multi line code + text = StringUtil.trimCodeBlock(str); + } else { + // single line code + text = str.trim(); + } + } else if (code.getBody() != null) { + // Code must have been added as a simple string. + text = code.getBody(); + } + } + return text; + } + + @Override + public String caseElement(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + // FIXME: There are more cases; these should be added + return null; + } + + @Override + public String caseLiteral(Literal l) { + return l.toString(); + } + + @Override + public String caseParameterReference(ParameterReference p) { + return p.getParameter().getName(); + } + + @Override + public String caseTime(Time t) { + return ASTUtils.toTimeValue(t).toString(); + } + + @Override + public String caseType(Type type) { + String base = ASTUtils.baseType(type); + String arr = (type.getArraySpec() != null) ? doSwitch(type.getArraySpec()) : ""; + return base + arr; + } + + @Override + public String caseTypeParm(TypeParm t) { + return !StringExtensions.isNullOrEmpty(t.getLiteral()) ? t.getLiteral() : doSwitch(t.getCode()); + } + + @Override + public String caseVarRef(VarRef v) { + if (v.getContainer() != null) { + return String.format("%s.%s", v.getContainer().getName(), v.getVariable().getName()); + } else { + return v.getVariable().getName(); + } + } + + @Override + public String defaultCase(EObject object) { + throw new UnsupportedOperationException("ToText has no case for " + object.getClass().getName()); + } +} diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt index 1aacc3659a..2a03008378 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt @@ -29,6 +29,7 @@ import org.lflang.isBank import org.lflang.label import org.lflang.lf.* import org.lflang.priority +import org.lflang.toText import org.lflang.toTaggedText /** A C++ code generator for reactions and their function bodies */ From f32212f102666452db4e5c1f1dcd291fbe4eae90 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 10:15:48 +0200 Subject: [PATCH 26/58] fix compilation error in tests --- .../lflang/tests/compiler/LinguaFrancaValidationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 583edf1512..736ae223f0 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -26,8 +26,6 @@ ***************/ package org.lflang.tests.compiler; -import static org.lflang.ASTUtils.withoutQuotes; - import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -40,6 +38,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; + import org.lflang.Target; import org.lflang.TargetProperty; import org.lflang.TargetProperty.ArrayType; @@ -53,6 +52,7 @@ import org.lflang.lf.Model; import org.lflang.lf.Visibility; import org.lflang.tests.LFInjectorProvider; +import org.lflang.util.StringUtil; import com.google.inject.Inject; @@ -1696,7 +1696,7 @@ public void checkTargetProperties() throws Exception { // 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'.", withoutQuotes(it))); + null, String.format("Could not find file: '%s'.", StringUtil.removeQuotes(it))); } } From 20f0ef83fb72bb5161af72bc34f958e786bbc135 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 10:26:12 +0200 Subject: [PATCH 27/58] bugfix --- org.lflang/src/org/lflang/ast/ToText.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index b6cea1677f..953cf1cb49 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -75,7 +75,7 @@ public String caseElement(Element e) { @Override public String caseLiteral(Literal l) { - return l.toString(); + return l.getLiteral(); } @Override From 750f8aeacd03e1e8b34625e046cb7ab5ccf1412a Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 11:40:57 +0200 Subject: [PATCH 28/58] bugfix --- org.lflang/src/org/lflang/ast/ToText.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 953cf1cb49..02be4c66f7 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -70,7 +70,7 @@ public String caseElement(Element e) { return e.getId(); } // FIXME: There are more cases; these should be added - return null; + return ""; } @Override From 1fb9003f8840d2ecb9f089adbb3520ec125114e8 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 11:41:19 +0200 Subject: [PATCH 29/58] fix a weird exception that suddenly occurred --- .../org/lflang/validation/LFValidator.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 7d661d6201..8cd9f2836f 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1110,25 +1110,30 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { KeyValuePair schedulerTargetProperty = schedulerTargetProperties .size() > 0 ? schedulerTargetProperties.get(0) : null; if (schedulerTargetProperty != null) { - String schedulerName = schedulerTargetProperty.getValue().getId(); - if (!TargetProperty.SchedulerOption.valueOf(schedulerName) - .prioritizesDeadline()) { - // Check if a deadline is assigned to any reaction - if (info.model.getReactors().stream().filter(reactor -> { - // Filter reactors that contain at least one reaction that - // has a deadline handler. - return ASTUtils.allReactions(reactor).stream() - .filter(reaction -> { - return reaction.getDeadline() != null; - }).count() > 0; - }).count() > 0) { - warning("This program contains deadlines, but the chosen " - + schedulerName - + " scheduler does not prioritize reaction execution " - + "based on deadlines. This might result in a sub-optimal " - + "scheduling.", schedulerTargetProperty, - Literals.KEY_VALUE_PAIR__VALUE); + String schedulerName = ASTUtils.toText(schedulerTargetProperty.getValue()); + try { + if (!TargetProperty.SchedulerOption.valueOf(schedulerName) + .prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + if (info.model.getReactors().stream().filter(reactor -> { + // Filter reactors that contain at least one reaction that + // has a deadline handler. + return ASTUtils.allReactions(reactor).stream() + .filter(reaction -> { + return reaction.getDeadline() != null; + }).count() > 0; + }).count() > 0) { + warning("This program contains deadlines, but the chosen " + + schedulerName + + " scheduler does not prioritize reaction execution " + + "based on deadlines. This might result in a sub-optimal " + + "scheduling.", schedulerTargetProperty, + Literals.KEY_VALUE_PAIR__VALUE); + } } + } catch (IllegalArgumentException e) { + // the given scheduler is invalid, but this is already checked by + // checkTargetProperties } } } From b98ea0631d53b70db8d276acb0ebd97eaf44c14a Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 12:48:06 +0200 Subject: [PATCH 30/58] correctly deal with null --- org.lflang/src/org/lflang/ASTUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 476c230c47..6622e43394 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -778,6 +778,8 @@ public static List collectElements(Reactor definition, EStructuralFeature * @return Textual representation of the given argument. */ public static String toText(EObject node) { + if (node == null) + return null; return toText.doSwitch(node); } @@ -788,6 +790,8 @@ public static String toText(EObject node) { * @return Textual representation of the given argument. */ public static String toTaggedText(EObject node) { + if (node == null) + return null; return CodeMap.Correspondence.tag(node, toText(node), true); } From a086884014b064708f9139f9d201c52f89da0242 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 13:30:53 +0200 Subject: [PATCH 31/58] fix logic error in validator --- org.lflang/src/org/lflang/validation/LFValidator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 8cd9f2836f..ab579c7864 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -28,6 +28,7 @@ import static org.lflang.ASTUtils.inferPortWidth; import static org.lflang.ASTUtils.isGeneric; +import static org.lflang.ASTUtils.isInteger; import static org.lflang.ASTUtils.isOfTimeType; import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; @@ -1410,9 +1411,9 @@ private void checkExpressionAsTime(Expression expr, EReference eReference) { if (expr instanceof ParameterReference) { final var param = ((ParameterReference) expr).getParameter(); if (!isOfTimeType(param) && target.requiresTypes) { - error("Parameter is not of time type", eReference); + error("Parameter is not of time type.", eReference); } - } else if(expr instanceof Literal) { + } else if(expr instanceof Literal && isInteger(expr)) { if (!isZero(expr)) { error("Missing time unit.", eReference); } From 70a2e4d6e99d3b7e96420a5805e37da65820fab6 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 13:32:20 +0200 Subject: [PATCH 32/58] adjust unit tests --- .../lflang/tests/compiler/LinguaFrancaValidationTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 736ae223f0..86f872f406 100644 --- a/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java +++ b/org.lflang.tests/src/org/lflang/tests/compiler/LinguaFrancaValidationTest.java @@ -964,7 +964,7 @@ public void parameterTypeMismatch() throws Exception { " =}", "}"); validator.assertError(parseWithoutError(testCase), LfPackage.eINSTANCE.getTimer(), - null, "Parameter is not of time type"); + null, "Parameter is not of time type."); } /** @@ -1250,9 +1250,11 @@ public void stateAndParameterDeclarationsInC() throws Exception { validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Parameter cannot be initialized using parameter."); validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, - "Referenced parameter does not denote a time."); + "Missing time unit."); validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, - "Invalid time literal."); + "Parameter is not of time type."); + validator.assertError(model, LfPackage.eINSTANCE.getStateVar(), null, + "Invalid time literal."); validator.assertError(model, LfPackage.eINSTANCE.getParameter(), null, "Uninitialized parameter."); validator.assertError(model, LfPackage.eINSTANCE.getTimer(), null, From a62b6c5fa075eeaf8268610cbcdae6f2e36dde17 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 13:42:17 +0200 Subject: [PATCH 33/58] fix zero delays; no need to replicate expressions anymore --- org.lflang/src/org/lflang/ASTUtils.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 6622e43394..994b61c811 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -438,16 +438,7 @@ private static Instantiation getDelayInstance(Reactor delayClass, } Assignment assignment = factory.createAssignment(); assignment.setLhs(delayClass.getParameters().get(0)); - if (delay instanceof ParameterReference) { - var expr = factory.createParameterReference(); - expr.setParameter(((ParameterReference)delay).getParameter()); - assignment.getRhs().add(expr); - } else if (delay instanceof Time){ - assignment.getRhs().add(delay); - } else { - // the validator ensures that a delay is only a Time or a ParameterReference - throw new RuntimeException("Unexpected expression type"); - } + assignment.getRhs().add(delay); delayInstance.getParameters().add(assignment); delayInstance.setName("delay"); // This has to be overridden. return delayInstance; From a05bc20aead3afeabe28eb20f0701ad431b3c52c Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 22 Apr 2022 13:55:12 +0200 Subject: [PATCH 34/58] add tests for zero delays --- test/C/src/AfterZero.lf | 55 +++++++++++++++++++++++++++++++++++++++ test/Cpp/src/AfterZero.lf | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 test/C/src/AfterZero.lf create mode 100644 test/Cpp/src/AfterZero.lf diff --git a/test/C/src/AfterZero.lf b/test/C/src/AfterZero.lf new file mode 100644 index 0000000000..cb19d2dc19 --- /dev/null +++ b/test/C/src/AfterZero.lf @@ -0,0 +1,55 @@ +// This checks that the after keyword adjusts logical time, not +// using physical time. +target C { + fast: false, + timeout: 3 sec +}; +reactor foo { + input x:int; + output y:int; + reaction(x) -> y {= + SET(y, 2*x->value); + =} +} +reactor print { + state expected_time:time(0); + state received:int(0); + input x:int; + reaction(x) {= + self->received++; + interval_t elapsed_time = get_elapsed_logical_time(); + printf("Result is %d\n", x->value); + if (x->value != 84) { + printf("ERROR: Expected result to be 84.\n"); + exit(1); + } + printf("Current logical time is: %lld\n", elapsed_time); + printf("Current microstep is: %lld\n", get_microstep()); + printf("Current physical time is: %lld\n", get_elapsed_physical_time()); + if (elapsed_time != self->expected_time) { + printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); + exit(2); + } + if (get_microstep() == 1) { + printf("ERROR: Expected microstep to be 1\n"); + exit(3); + } + self->expected_time += SEC(1); + =} + reaction(shutdown) {= + if (self->received == 0) { + printf("ERROR: Final reactor received no data.\n"); + exit(3); + } + =} +} + +main reactor { + f = new foo(); + p = new print(); + timer t(0, 1 sec); + reaction(t) -> f.x {= + SET(f.x, 42); + =} + f.y -> p.x after 0; +} diff --git a/test/Cpp/src/AfterZero.lf b/test/Cpp/src/AfterZero.lf new file mode 100644 index 0000000000..82450c71e4 --- /dev/null +++ b/test/Cpp/src/AfterZero.lf @@ -0,0 +1,55 @@ +// This checks that the after keyword adjusts logical time, not +// using physical time. +target Cpp { + fast: false, + timeout: 3 sec +}; +reactor foo { + input x:int; + output y:int; + reaction(x) -> y {= + y.set(2*(*x.get())); + =} +} +reactor print { + state expected_time:time(0); + state i:int(0); + input x:int; + reaction(x) {= + i++; + auto elapsed_time = get_elapsed_logical_time(); + std::cout << "Result is " << *x.get() << '\n'; + if (*x.get() != 84) { + std::cerr << "ERROR: Expected result to be 84.\n"; + exit(1); + } + std::cout << "Current logical time is: " << elapsed_time << '\n'; + std::cout << "Current microstep is: " << get_microstep() << '\n'; + std::cout << "Current physical time is: " << get_elapsed_physical_time() << '\n'; + if (elapsed_time != expected_time) { + std::cerr << "ERROR: Expected logical time to be " << expected_time << '\n'; + exit(2); + } + if (get_microstep() != 1) { + std::cerr << "Expected microstrp to be 1\n"; + exit(3); + } + expected_time += 1s; + =} + reaction(shutdown) {= + if (i == 0) { + std::cerr << "ERROR: Final reactor received no data.\n"; + exit(3); + } + =} +} +main reactor { + f = new foo(); + p = new print(); + timer t(0, 1 sec); + reaction(t) -> f.x {= + f.x.set(42); + std::cout << "Timer!\n"; + =} + f.y -> p.x after 0; +} From 038781c4d0dd5a773c29af8086ba2f25e84bfff9 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 29 Apr 2022 12:55:18 +0200 Subject: [PATCH 35/58] bugfix in test --- test/C/src/AfterZero.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/AfterZero.lf b/test/C/src/AfterZero.lf index cb19d2dc19..b40ea77079 100644 --- a/test/C/src/AfterZero.lf +++ b/test/C/src/AfterZero.lf @@ -30,7 +30,7 @@ reactor print { printf("ERROR: Expected logical time to be %lld.\n", self->expected_time); exit(2); } - if (get_microstep() == 1) { + if (get_microstep() != 1) { printf("ERROR: Expected microstep to be 1\n"); exit(3); } From 73e449510677a2a8cb8314ca5e293f790f03e24e Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 29 Apr 2022 16:33:44 +0200 Subject: [PATCH 36/58] remove Element case from toText as its specification differs from the other cases --- org.lflang/src/org/lflang/ASTUtils.java | 27 +++++++++++++--- org.lflang/src/org/lflang/TargetProperty.java | 32 +++++++++---------- org.lflang/src/org/lflang/ast/ToText.java | 17 +++------- .../generator/rust/CargoDependencySpec.java | 2 +- .../org/lflang/validation/LFValidator.java | 2 +- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 994b61c811..04a6780aa7 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -92,6 +92,7 @@ import org.lflang.lf.Variable; import org.lflang.lf.WidthSpec; import org.lflang.lf.WidthTerm; +import org.lflang.util.StringUtil; import com.google.common.collect.HashMultimap; import com.google.common.collect.Iterators; @@ -824,9 +825,27 @@ public static TimeValue toTimeValue(Time e) { * @param e The element to be rendered as a boolean. */ public static boolean toBoolean(Element e) { - return toText(e).equalsIgnoreCase("true"); + return toSingleString(e).equalsIgnoreCase("true"); } - + + /** + * Given the right-hand side of a target property, return a string that + * represents the given value/ + * + * If the given value is not a literal or and id (but for instance and array or dict), + * an empty string is returned. If the element is a string, any quotes are removed. + * + * @param e The right-hand side of a target property. + */ + public static String toSingleString(Element e) { + if (e.getLiteral() != null) { + return StringUtil.removeQuotes(e.getLiteral()).trim(); + } else if (e.getId() != null) { + return e.getId(); + } + return ""; + } + /** * Given the right-hand side of a target property, return a list with all * the strings that the property lists. @@ -843,9 +862,9 @@ public static List toListOfStrings(Element value) { } return elements; } else { - String v = toText(value); + String v = toSingleString(value); if (!v.isEmpty()) { - elements.add(toText(value)); + elements.add(v); } } return elements; diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index fd122db845..86955ff0bb 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -70,7 +70,7 @@ public enum TargetProperty { BUILD_TYPE("build-type", UnionType.BUILD_TYPE_UNION, Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Rust), (config, value, err) -> { config.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION - .forName(ASTUtils.toText(value)); + .forName(ASTUtils.toSingleString(value)); // set it there too, because the default is different. config.rust.setBuildType(config.cmakeBuildType); }), @@ -81,7 +81,7 @@ public enum TargetProperty { CLOCK_SYNC("clock-sync", UnionType.CLOCK_SYNC_UNION, Arrays.asList(Target.C, Target.CCPP), (config, value, err) -> { config.clockSync = (ClockSyncMode) UnionType.CLOCK_SYNC_UNION - .forName(ASTUtils.toText(value)); + .forName(ASTUtils.toSingleString(value)); }), /** @@ -158,7 +158,7 @@ public enum TargetProperty { */ COMPILER("compiler", PrimitiveType.STRING, Target.ALL, (config, value, err) -> { - config.compiler = ASTUtils.toText(value); + config.compiler = ASTUtils.toSingleString(value); }), /** @@ -180,7 +180,7 @@ public enum TargetProperty { .forName(entry.getName()); switch (option) { case FROM: - config.dockerOptions.from = ASTUtils.toText(entry.getValue()); + config.dockerOptions.from = ASTUtils.toSingleString(entry.getValue()); break; default: break; @@ -195,7 +195,7 @@ public enum TargetProperty { */ EXTERNAL_RUNTIME_PATH("external-runtime-path", PrimitiveType.STRING, Arrays.asList(Target.CPP), (config, value, err) -> { - config.externalRuntimePath = ASTUtils.toText(value); + config.externalRuntimePath = ASTUtils.toSingleString(value); }), /** @@ -238,7 +238,7 @@ public enum TargetProperty { Arrays.asList(Target.C, Target.CCPP, Target.Python), (config, value, err) -> { config.coordination = (CoordinationType) UnionType.COORDINATION_UNION - .forName(ASTUtils.toText(value)); + .forName(ASTUtils.toSingleString(value)); }), /** @@ -276,7 +276,7 @@ public enum TargetProperty { LOGGING("logging", UnionType.LOGGING_UNION, Target.ALL, (config, value, err) -> { config.logLevel = (LogLevel) UnionType.LOGGING_UNION - .forName(ASTUtils.toText(value)); + .forName(ASTUtils.toSingleString(value)); }), /** @@ -320,7 +320,7 @@ public enum TargetProperty { */ RUNTIME_VERSION("runtime-version", PrimitiveType.STRING, Arrays.asList(Target.CPP), (config, value, err) -> { - config.runtimeVersion = ASTUtils.toText(value); + config.runtimeVersion = ASTUtils.toSingleString(value); }), @@ -330,7 +330,7 @@ public enum TargetProperty { SCHEDULER("scheduler", UnionType.SCHEDULER_UNION, Arrays.asList(Target.C, Target.CCPP, Target.Python), (config, value, err) -> { config.schedulerType = (SchedulerOption) UnionType.SCHEDULER_UNION - .forName(ASTUtils.toText(value)); + .forName(ASTUtils.toSingleString(value)); }), /** @@ -386,7 +386,7 @@ public enum TargetProperty { .forName(entry.getName()); switch (option) { case TRACE_FILE_NAME: - config.tracing.traceFileName = ASTUtils.toText(entry.getValue()); + config.tracing.traceFileName = ASTUtils.toSingleString(entry.getValue()); break; default: break; @@ -866,7 +866,7 @@ private Optional> match(Element e) { if (option instanceof TargetPropertyType) { return ((TargetPropertyType) option).validate(e); } else { - return ASTUtils.toText(e) + return ASTUtils.toSingleString(e) .equalsIgnoreCase(option.toString()); } }).findAny(); @@ -1084,11 +1084,11 @@ public static void produceError(String name, String description, */ public enum PrimitiveType implements TargetPropertyType { BOOLEAN("'true' or 'false'", - v -> ASTUtils.toText(v).equalsIgnoreCase("true") - || ASTUtils.toText(v).equalsIgnoreCase("false")), + v -> ASTUtils.toSingleString(v).equalsIgnoreCase("true") + || ASTUtils.toSingleString(v).equalsIgnoreCase("false")), INTEGER("an integer", v -> { try { - Integer.parseInt(ASTUtils.toText(v)); + Integer.parseInt(ASTUtils.toSingleString(v)); } catch (NumberFormatException e) { return false; } @@ -1096,7 +1096,7 @@ public enum PrimitiveType implements TargetPropertyType { }), NON_NEGATIVE_INTEGER("a non-negative integer", v -> { try { - int result = Integer.parseInt(ASTUtils.toText(v)); + int result = Integer.parseInt(ASTUtils.toSingleString(v)); if (result < 0) return false; } catch (NumberFormatException e) { @@ -1160,7 +1160,7 @@ public void check(Element e, String name, LFValidator v) { // Looking in the same directory is too restrictive. Disabling this check for now. /* if (this == FILE) { - String file = ASTUtils.toText(e); + String file = ASTUtils.toSingleString(e); if (!FileConfig.fileExists(file, FileConfig.toPath(e.eResource().getURI()).toFile().getParent())) { v.targetPropertyWarnings diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 02be4c66f7..4a41cc3c2e 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -9,7 +9,6 @@ import org.lflang.ASTUtils; import org.lflang.lf.ArraySpec; import org.lflang.lf.Code; -import org.lflang.lf.Element; import org.lflang.lf.Literal; import org.lflang.lf.ParameterReference; import org.lflang.lf.Time; @@ -19,6 +18,11 @@ import org.lflang.lf.util.LfSwitch; import org.lflang.util.StringUtil; + +/** + * Switch class for converting AST nodes to their textual representation as + * it would appear in LF code. + */ public class ToText extends LfSwitch { @Override @@ -62,17 +66,6 @@ public String caseCode(Code code) { return text; } - @Override - public String caseElement(Element e) { - if (e.getLiteral() != null) { - return StringUtil.removeQuotes(e.getLiteral()).trim(); - } else if (e.getId() != null) { - return e.getId(); - } - // FIXME: There are more cases; these should be added - return ""; - } - @Override public String caseLiteral(Literal l) { return l.getLiteral(); diff --git a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java index 0b48f1a2e2..3dbc3b24c9 100644 --- a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java +++ b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java @@ -166,7 +166,7 @@ private static CargoDependencySpec parseValue(Element element, boolean isRuntime "Expected an array of strings for key '" + name + "'"); } features = array.getElements().stream() - .map(ASTUtils::toText) + .map(ASTUtils::toSingleString) .map(StringUtil::removeQuotes) .collect(Collectors.toList()); continue; diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index ab579c7864..638aa1e754 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1111,7 +1111,7 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { KeyValuePair schedulerTargetProperty = schedulerTargetProperties .size() > 0 ? schedulerTargetProperties.get(0) : null; if (schedulerTargetProperty != null) { - String schedulerName = ASTUtils.toText(schedulerTargetProperty.getValue()); + String schedulerName = ASTUtils.toSingleString(schedulerTargetProperty.getValue()); try { if (!TargetProperty.SchedulerOption.valueOf(schedulerName) .prioritizesDeadline()) { From f35ce29e754969ae2d8ad1b338af416690655732 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 29 Apr 2022 16:40:48 +0200 Subject: [PATCH 37/58] refactoring --- org.lflang/src/org/lflang/ASTUtils.java | 10 ++-- org.lflang/src/org/lflang/TargetProperty.java | 46 +++++++++---------- .../generator/rust/CargoDependencySpec.java | 2 +- .../org/lflang/validation/LFValidator.java | 2 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 04a6780aa7..368dc74fa2 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -825,7 +825,7 @@ public static TimeValue toTimeValue(Time e) { * @param e The element to be rendered as a boolean. */ public static boolean toBoolean(Element e) { - return toSingleString(e).equalsIgnoreCase("true"); + return elementToSingleString(e).equalsIgnoreCase("true"); } /** @@ -837,7 +837,7 @@ public static boolean toBoolean(Element e) { * * @param e The right-hand side of a target property. */ - public static String toSingleString(Element e) { + public static String elementToSingleString(Element e) { if (e.getLiteral() != null) { return StringUtil.removeQuotes(e.getLiteral()).trim(); } else if (e.getId() != null) { @@ -854,15 +854,15 @@ public static String toSingleString(Element e) { * are ignored; they are not added to the list. * @param value The right-hand side of a target property. */ - public static List toListOfStrings(Element value) { + public static List elementToListOfStrings(Element value) { List elements = new ArrayList<>(); if (value.getArray() != null) { for (Element element : value.getArray().getElements()) { - elements.addAll(toListOfStrings(element)); + elements.addAll(elementToListOfStrings(element)); } return elements; } else { - String v = toSingleString(value); + String v = elementToSingleString(value); if (!v.isEmpty()) { elements.add(v); } diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 86955ff0bb..9395ea9d8e 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -60,7 +60,7 @@ public enum TargetProperty { */ BUILD("build", UnionType.STRING_OR_STRING_ARRAY, Arrays.asList(Target.C, Target.CCPP), (config, value, err) -> { - config.buildCommands = ASTUtils.toListOfStrings(value); + config.buildCommands = ASTUtils.elementToListOfStrings(value); }), /** @@ -70,7 +70,7 @@ public enum TargetProperty { BUILD_TYPE("build-type", UnionType.BUILD_TYPE_UNION, Arrays.asList(Target.C, Target.CCPP, Target.CPP, Target.Rust), (config, value, err) -> { config.cmakeBuildType = (BuildType) UnionType.BUILD_TYPE_UNION - .forName(ASTUtils.toSingleString(value)); + .forName(ASTUtils.elementToSingleString(value)); // set it there too, because the default is different. config.rust.setBuildType(config.cmakeBuildType); }), @@ -81,7 +81,7 @@ public enum TargetProperty { CLOCK_SYNC("clock-sync", UnionType.CLOCK_SYNC_UNION, Arrays.asList(Target.C, Target.CCPP), (config, value, err) -> { config.clockSync = (ClockSyncMode) UnionType.CLOCK_SYNC_UNION - .forName(ASTUtils.toSingleString(value)); + .forName(ASTUtils.elementToSingleString(value)); }), /** @@ -133,14 +133,14 @@ public enum TargetProperty { */ CMAKE_INCLUDE("cmake-include", UnionType.FILE_OR_FILE_ARRAY, Arrays.asList(Target.CPP, Target.C, Target.CCPP), (config, value, err) -> { - config.cmakeIncludes = ASTUtils.toListOfStrings(value); + config.cmakeIncludes = ASTUtils.elementToListOfStrings(value); }, // FIXME: This merging of lists is potentially dangerous since // the incoming list of cmake-includes can belong to a .lf file that is // located in a different location, and keeping just filename // strings like this without absolute paths is incorrect. (config, value, err) -> { - config.cmakeIncludes.addAll(ASTUtils.toListOfStrings(value)); + config.cmakeIncludes.addAll(ASTUtils.elementToListOfStrings(value)); }), /** @@ -158,7 +158,7 @@ public enum TargetProperty { */ COMPILER("compiler", PrimitiveType.STRING, Target.ALL, (config, value, err) -> { - config.compiler = ASTUtils.toSingleString(value); + config.compiler = ASTUtils.elementToSingleString(value); }), /** @@ -180,7 +180,7 @@ public enum TargetProperty { .forName(entry.getName()); switch (option) { case FROM: - config.dockerOptions.from = ASTUtils.toSingleString(entry.getValue()); + config.dockerOptions.from = ASTUtils.elementToSingleString(entry.getValue()); break; default: break; @@ -195,7 +195,7 @@ public enum TargetProperty { */ EXTERNAL_RUNTIME_PATH("external-runtime-path", PrimitiveType.STRING, Arrays.asList(Target.CPP), (config, value, err) -> { - config.externalRuntimePath = ASTUtils.toSingleString(value); + config.externalRuntimePath = ASTUtils.elementToSingleString(value); }), /** @@ -213,14 +213,14 @@ public enum TargetProperty { */ FILES("files", UnionType.FILE_OR_FILE_ARRAY, List.of(Target.C, Target.CCPP, Target.Python), (config, value, err) -> { - config.fileNames = ASTUtils.toListOfStrings(value); + config.fileNames = ASTUtils.elementToListOfStrings(value); }, // FIXME: This merging of lists is potentially dangerous since // the incoming list of files can belong to a .lf file that is // located in a different location, and keeping just filename // strings like this without absolute paths is incorrect. (config, value, err) -> { - config.fileNames.addAll(ASTUtils.toListOfStrings(value)); + config.fileNames.addAll(ASTUtils.elementToListOfStrings(value)); }), /** @@ -228,7 +228,7 @@ public enum TargetProperty { */ FLAGS("flags", UnionType.STRING_OR_STRING_ARRAY, Arrays.asList(Target.C, Target.CCPP), (config, value, err) -> { - config.compilerFlags = ASTUtils.toListOfStrings(value); + config.compilerFlags = ASTUtils.elementToListOfStrings(value); }), /** @@ -238,7 +238,7 @@ public enum TargetProperty { Arrays.asList(Target.C, Target.CCPP, Target.Python), (config, value, err) -> { config.coordination = (CoordinationType) UnionType.COORDINATION_UNION - .forName(ASTUtils.toSingleString(value)); + .forName(ASTUtils.elementToSingleString(value)); }), /** @@ -276,7 +276,7 @@ public enum TargetProperty { LOGGING("logging", UnionType.LOGGING_UNION, Target.ALL, (config, value, err) -> { config.logLevel = (LogLevel) UnionType.LOGGING_UNION - .forName(ASTUtils.toSingleString(value)); + .forName(ASTUtils.elementToSingleString(value)); }), /** @@ -303,7 +303,7 @@ public enum TargetProperty { PROTOBUFS("protobufs", UnionType.FILE_OR_FILE_ARRAY, Arrays.asList(Target.C, Target.CCPP, Target.TS, Target.Python), (config, value, err) -> { - config.protoFiles = ASTUtils.toListOfStrings(value); + config.protoFiles = ASTUtils.elementToListOfStrings(value); }), @@ -320,7 +320,7 @@ public enum TargetProperty { */ RUNTIME_VERSION("runtime-version", PrimitiveType.STRING, Arrays.asList(Target.CPP), (config, value, err) -> { - config.runtimeVersion = ASTUtils.toSingleString(value); + config.runtimeVersion = ASTUtils.elementToSingleString(value); }), @@ -330,7 +330,7 @@ public enum TargetProperty { SCHEDULER("scheduler", UnionType.SCHEDULER_UNION, Arrays.asList(Target.C, Target.CCPP, Target.Python), (config, value, err) -> { config.schedulerType = (SchedulerOption) UnionType.SCHEDULER_UNION - .forName(ASTUtils.toSingleString(value)); + .forName(ASTUtils.elementToSingleString(value)); }), /** @@ -386,7 +386,7 @@ public enum TargetProperty { .forName(entry.getName()); switch (option) { case TRACE_FILE_NAME: - config.tracing.traceFileName = ASTUtils.toSingleString(entry.getValue()); + config.tracing.traceFileName = ASTUtils.elementToSingleString(entry.getValue()); break; default: break; @@ -459,7 +459,7 @@ public enum TargetProperty { */ CARGO_FEATURES("cargo-features", ArrayType.STRING_ARRAY, List.of(Target.Rust), (config, value, err) -> { - config.rust.setCargoFeatures(ASTUtils.toListOfStrings(value)); + config.rust.setCargoFeatures(ASTUtils.elementToListOfStrings(value)); }), /** @@ -866,7 +866,7 @@ private Optional> match(Element e) { if (option instanceof TargetPropertyType) { return ((TargetPropertyType) option).validate(e); } else { - return ASTUtils.toSingleString(e) + return ASTUtils.elementToSingleString(e) .equalsIgnoreCase(option.toString()); } }).findAny(); @@ -1084,11 +1084,11 @@ public static void produceError(String name, String description, */ public enum PrimitiveType implements TargetPropertyType { BOOLEAN("'true' or 'false'", - v -> ASTUtils.toSingleString(v).equalsIgnoreCase("true") - || ASTUtils.toSingleString(v).equalsIgnoreCase("false")), + v -> ASTUtils.elementToSingleString(v).equalsIgnoreCase("true") + || ASTUtils.elementToSingleString(v).equalsIgnoreCase("false")), INTEGER("an integer", v -> { try { - Integer.parseInt(ASTUtils.toSingleString(v)); + Integer.parseInt(ASTUtils.elementToSingleString(v)); } catch (NumberFormatException e) { return false; } @@ -1096,7 +1096,7 @@ public enum PrimitiveType implements TargetPropertyType { }), NON_NEGATIVE_INTEGER("a non-negative integer", v -> { try { - int result = Integer.parseInt(ASTUtils.toSingleString(v)); + int result = Integer.parseInt(ASTUtils.elementToSingleString(v)); if (result < 0) return false; } catch (NumberFormatException e) { diff --git a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java index 3dbc3b24c9..11783a41b3 100644 --- a/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java +++ b/org.lflang/src/org/lflang/generator/rust/CargoDependencySpec.java @@ -166,7 +166,7 @@ private static CargoDependencySpec parseValue(Element element, boolean isRuntime "Expected an array of strings for key '" + name + "'"); } features = array.getElements().stream() - .map(ASTUtils::toSingleString) + .map(ASTUtils::elementToSingleString) .map(StringUtil::removeQuotes) .collect(Collectors.toList()); continue; diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 638aa1e754..6e3275fe68 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1111,7 +1111,7 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { KeyValuePair schedulerTargetProperty = schedulerTargetProperties .size() > 0 ? schedulerTargetProperties.get(0) : null; if (schedulerTargetProperty != null) { - String schedulerName = ASTUtils.toSingleString(schedulerTargetProperty.getValue()); + String schedulerName = ASTUtils.elementToSingleString(schedulerTargetProperty.getValue()); try { if (!TargetProperty.SchedulerOption.valueOf(schedulerName) .prioritizesDeadline()) { From c2f7949313df8bb51a5652e5ef5e184ad195473c Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 29 Apr 2022 16:44:25 +0200 Subject: [PATCH 38/58] code should not be null when toText is called --- org.lflang/src/org/lflang/ast/ToText.java | 57 +++++++++++------------ 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 4a41cc3c2e..57000d4237 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -32,38 +32,35 @@ public String caseArraySpec(ArraySpec spec) { @Override public String caseCode(Code code) { - String text = ""; - if (code != null) { - ICompositeNode node = NodeModelUtils.getNode(code); - if (node != null) { - StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1)); - for (ILeafNode leaf : node.getLeafNodes()) { - builder.append(leaf.getText()); - } - String str = builder.toString().trim(); - // Remove the code delimiters (and any surrounding comments). - // This assumes any comment before {= does not include {=. - int start = str.indexOf("{="); - int end = str.indexOf("=}", start); - if (start == -1 || end == -1) { - // Silent failure is needed here because toText is needed to create the intermediate representation, - // which the validator uses. - return str; - } - str = str.substring(start + 2, end); - if (str.split("\n").length > 1) { - // multi line code - text = StringUtil.trimCodeBlock(str); - } else { - // single line code - text = str.trim(); - } - } else if (code.getBody() != null) { - // Code must have been added as a simple string. - text = code.getBody(); + ICompositeNode node = NodeModelUtils.getNode(code); + if (node != null) { + StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1)); + for (ILeafNode leaf : node.getLeafNodes()) { + builder.append(leaf.getText()); } + String str = builder.toString().trim(); + // Remove the code delimiters (and any surrounding comments). + // This assumes any comment before {= does not include {=. + int start = str.indexOf("{="); + int end = str.indexOf("=}", start); + if (start == -1 || end == -1) { + // Silent failure is needed here because toText is needed to create the intermediate representation, + // which the validator uses. + return str; + } + str = str.substring(start + 2, end); + if (str.split("\n").length > 1) { + // multi line code + return StringUtil.trimCodeBlock(str); + } else { + // single line code + return str.trim(); + } + } else if (code.getBody() != null) { + // Code must have been added as a simple string. + return code.getBody(); } - return text; + return ""; } @Override From 4e921dd762f657c3df05af24a96c32d357d3d03d Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 29 Apr 2022 16:56:22 +0200 Subject: [PATCH 39/58] make ToText a singleton --- org.lflang/src/org/lflang/ASTUtils.java | 5 +---- org.lflang/src/org/lflang/ast/ToText.java | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 368dc74fa2..0218451c20 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -761,9 +761,6 @@ public static List collectElements(Reactor definition, EStructuralFeature //////////////////////////////// //// Utility functions for translating AST nodes into text - /** Instance of a switch class for creating textual representations of AST nodes */ - private static final ToText toText = new ToText(); - /** * Translate the given code into its textual representation. * @param node AST node to render as string. @@ -772,7 +769,7 @@ public static List collectElements(Reactor definition, EStructuralFeature public static String toText(EObject node) { if (node == null) return null; - return toText.doSwitch(node); + return ToText.instance.doSwitch(node); } /** diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 57000d4237..7d6bb2a505 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -25,6 +25,12 @@ */ public class ToText extends LfSwitch { + /// public instance initialized when loading the class + public static final ToText instance = new ToText(); + + // private constructor + private ToText() { super(); } + @Override public String caseArraySpec(ArraySpec spec) { return (spec.isOfVariableLength()) ? "[]" : "[" + spec.getLength() + "]"; From 87842d8522b9d7fdf2099128d20e25065172db17 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 29 Apr 2022 17:19:34 +0200 Subject: [PATCH 40/58] use ToText also in diagrams --- .../synthesis/LinguaFrancaSynthesis.java | 4 +- .../styles/LinguaFrancaShapeExtensions.java | 5 ++- .../synthesis/util/UtilityExtensions.java | 40 +------------------ org.lflang/src/org/lflang/ast/ToText.java | 16 ++++++++ 4 files changed, 22 insertions(+), 43 deletions(-) diff --git a/org.lflang.diagram/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java b/org.lflang.diagram/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java index f59b78799e..7131da51cd 100644 --- a/org.lflang.diagram/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java +++ b/org.lflang.diagram/src/org/lflang/diagram/synthesis/LinguaFrancaSynthesis.java @@ -1127,7 +1127,7 @@ private String createParameterLabel(ParameterInstance param, boolean bullet) { } if (!IterableExtensions.isNullOrEmpty(param.getInitialValue())) { b.append("("); - b.append(IterableExtensions.join(param.getInitialValue(), ", ", _utilityExtensions::toText)); + b.append(IterableExtensions.join(param.getInitialValue(), ", ", ASTUtils::toText)); b.append(")"); } return b.toString(); @@ -1163,7 +1163,7 @@ private String createStateVariableLabel(StateVar variable, boolean bullet) { } if (!IterableExtensions.isNullOrEmpty(variable.getInit())) { b.append("("); - b.append(IterableExtensions.join(variable.getInit(), ", ", _utilityExtensions::toText)); + b.append(IterableExtensions.join(variable.getInit(), ", ", ASTUtils::toText)); b.append(")"); } return b.toString(); diff --git a/org.lflang.diagram/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java b/org.lflang.diagram/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java index dfc0d1ab60..a7f13df7f6 100644 --- a/org.lflang.diagram/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java +++ b/org.lflang.diagram/src/org/lflang/diagram/synthesis/styles/LinguaFrancaShapeExtensions.java @@ -68,6 +68,7 @@ import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.lib.StringExtensions; +import org.lflang.ASTUtils; import org.lflang.diagram.synthesis.AbstractSynthesisExtensions; import org.lflang.diagram.synthesis.LinguaFrancaSynthesis; import org.lflang.diagram.synthesis.postprocessor.ReactionPortAdjustment; @@ -175,7 +176,7 @@ public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reacto if (reactorInstance.reactorDefinition.getHost() != null && getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { KText hostNameText = _kContainerRenderingExtensions.addText(childContainer, - _utilityExtensions.toText(reactorInstance.reactorDefinition.getHost())); + ASTUtils.toText(reactorInstance.reactorDefinition.getHost())); DiagramSyntheses.suppressSelectability(hostNameText); _linguaFrancaStyleExtensions.underlineSelectionStyle(hostNameText); setGridPlacementDataFromPointToPoint(hostNameText, @@ -245,7 +246,7 @@ public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reac if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) { KText reactorHostText = _kContainerRenderingExtensions.addText(childContainer, - _utilityExtensions.toText(reactorInstance.getDefinition().getHost())); + ASTUtils.toText(reactorInstance.getDefinition().getHost())); DiagramSyntheses.suppressSelectability(reactorHostText); _linguaFrancaStyleExtensions.underlineSelectionStyle(reactorHostText); setGridPlacementDataFromPointToPoint(reactorHostText, diff --git a/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java b/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java index b5879f34f4..772071756d 100644 --- a/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java +++ b/org.lflang.diagram/src/org/lflang/diagram/synthesis/util/UtilityExtensions.java @@ -64,45 +64,7 @@ public class UtilityExtensions extends AbstractSynthesisExtensions { @Extension private KGraphFactory _kGraphFactory = KGraphFactory.eINSTANCE; - - /** - * Converts a timing value into readable text - */ - public String toText(Expression expr) { - if (expr != null) { - if (expr instanceof ParameterReference) { - return ((ParameterReference)expr).getParameter().getName(); - } else if (expr instanceof Time) { - final var time = (Time)expr; - return time.getInterval() + time.getUnit().toString(); - } else if (expr instanceof Literal) { - return ((Literal)expr).getLiteral(); - } else if (expr instanceof Code) { - final var body = ((Code)expr).getBody(); - return StringUtil.trimCodeBlock(body); - } - } - return ""; - } - - /** - * Converts a host value into readable text - */ - public String toText(Host host) { - StringBuilder sb = new StringBuilder(); - if (host != null) { - if (!StringExtensions.isNullOrEmpty(host.getUser())) { - sb.append(host.getUser()).append("@"); - } - if (!StringExtensions.isNullOrEmpty(host.getAddr())) { - sb.append(host.getAddr()); - } - if (host.getPort() != 0) { - sb.append(":").append(host.getPort()); - } - } - return sb.toString(); - } + /** * Returns true if the reactor is the primary reactor diff --git a/org.lflang/src/org/lflang/ast/ToText.java b/org.lflang/src/org/lflang/ast/ToText.java index 7d6bb2a505..3f862a240e 100644 --- a/org.lflang/src/org/lflang/ast/ToText.java +++ b/org.lflang/src/org/lflang/ast/ToText.java @@ -9,6 +9,7 @@ import org.lflang.ASTUtils; import org.lflang.lf.ArraySpec; import org.lflang.lf.Code; +import org.lflang.lf.Host; import org.lflang.lf.Literal; import org.lflang.lf.ParameterReference; import org.lflang.lf.Time; @@ -69,6 +70,21 @@ public String caseCode(Code code) { return ""; } + @Override + public String caseHost(Host host) { + StringBuilder sb = new StringBuilder(); + if (!StringExtensions.isNullOrEmpty(host.getUser())) { + sb.append(host.getUser()).append("@"); + } + if (!StringExtensions.isNullOrEmpty(host.getAddr())) { + sb.append(host.getAddr()); + } + if (host.getPort() != 0) { + sb.append(":").append(host.getPort()); + } + return sb.toString(); + } + @Override public String caseLiteral(Literal l) { return l.getLiteral(); From 1ee3e3b334982be114ac37e16d92d206999d7bc1 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 18 May 2022 11:12:56 -0700 Subject: [PATCH 41/58] Simplify pr method. The work ostensibly done by this method is, I think, taken care of elsewhere. A bug resulted from its complexity. --- .../src/org/lflang/generator/CodeBuilder.java | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/CodeBuilder.java b/org.lflang/src/org/lflang/generator/CodeBuilder.java index e23d2a73f1..52d2cc9f83 100644 --- a/org.lflang/src/org/lflang/generator/CodeBuilder.java +++ b/org.lflang/src/org/lflang/generator/CodeBuilder.java @@ -98,31 +98,11 @@ public void pr(String format, Object... args) { } /** - * Append the specified text plus a final newline to the specified - * code buffer. This also replaces tabs with four spaces. - * @param text The the object whose toString() method provides the text. + * Append the given text to the code buffer at the current indentation level. */ - public void pr(Object text) { - String string = text.toString(); - string = string.replaceAll("\t", " "); - String[] split = string.split("\n"); - int offset = Stream.of(split).skip(1) - .mapToInt(line -> line.indexOf(line.trim())) - .min() - .orElse(0); - // Now make a pass for each line, replacing the offset leading - // spaces with the current indentation. - boolean firstLine = true; - for (String line : split) { - code.append(indentation); - // Do not trim the first line - if (firstLine) { - code.append(line); - firstLine = false; - } else { - code.append(line.substring(offset)); - } - code.append("\n"); + public void pr(CharSequence text) { + for (String line : (Iterable) () -> text.toString().lines().iterator()) { + code.append(indentation).append(line).append(System.lineSeparator()); } } From 82b4d4ba8ab71487c2be952e69f8482bbd2e9fe3 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 18 May 2022 18:53:23 -0700 Subject: [PATCH 42/58] [tests] Ad hoc patch for LSP tests. --- org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java index d8f669dbf9..01f3d5a651 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java @@ -28,6 +28,7 @@ class ErrorInserter { /** A basic error inserter builder on which more specific error inserters can be built. */ private static final Builder BASE_ERROR_INSERTER = new Builder() .insertCondition(s -> Stream.of(";", "}", "{").anyMatch(s::endsWith)) + .insertCondition(s -> !s.trim().startsWith("else")) .insertable(" 0 = 1;").insertable("some_undeclared_var1524263 = 9;").insertable(" ++;"); public static final Builder C = BASE_ERROR_INSERTER .replacer("lf_set(", "UNDEFINED_NAME2828376(") From 1b5dbd28d8507ecccd148c3b615f27f1cd116234 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 18 May 2022 20:40:57 -0700 Subject: [PATCH 43/58] [tests] Further revise LSP tests. --- .../org/lflang/tests/lsp/ErrorInserter.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java index 01f3d5a651..c90d510ddc 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java @@ -12,6 +12,7 @@ import java.util.ListIterator; import java.util.Random; import java.util.function.BiFunction; +import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; @@ -27,8 +28,8 @@ class ErrorInserter { /** A basic error inserter builder on which more specific error inserters can be built. */ private static final Builder BASE_ERROR_INSERTER = new Builder() - .insertCondition(s -> Stream.of(";", "}", "{").anyMatch(s::endsWith)) - .insertCondition(s -> !s.trim().startsWith("else")) + .insertCondition((s0, s1) -> Stream.of(";", "}", "{").anyMatch(s0::endsWith)) + .insertCondition((s0, s1) -> !s1.trim().startsWith("else")) .insertable(" 0 = 1;").insertable("some_undeclared_var1524263 = 9;").insertable(" ++;"); public static final Builder C = BASE_ERROR_INSERTER .replacer("lf_set(", "UNDEFINED_NAME2828376(") @@ -79,7 +80,7 @@ private boolean get() { * @param insertCondition Whether the error inserter is permitted to insert a line after a given line. * @throws IOException if the content of {@code originalTest} cannot be read. */ - private AlteredTest(Path originalTest, Predicate insertCondition) throws IOException { + private AlteredTest(Path originalTest, BiPredicate insertCondition) throws IOException { this.badLines = new ArrayList<>(); this.path = originalTest; this.lines = new LinkedList<>(); // Constant-time insertion during iteration is desired. @@ -88,10 +89,9 @@ private AlteredTest(Path originalTest, Predicate insertCondition) throws boolean ret = true; it.previous(); if (it.hasPrevious()) { - ret = insertCondition.test(it.previous()); + ret = insertCondition.test(it.previous(), it.next()); } it.next(); - it.next(); return ret; }; } @@ -231,18 +231,18 @@ public T next() { } private final Node> replacers; private final Node insertables; - private final Predicate insertCondition; + private final BiPredicate insertCondition; /** Initializes a builder for error inserters. */ public Builder() { - this(null, null, s -> true); + this(null, null, (s0, s1) -> true); } /** Construct a builder with the given replacers and insertables. */ private Builder( Node> replacers, Node insertables, - Predicate insertCondition + BiPredicate insertCondition ) { this.replacers = replacers; this.insertables = insertables; @@ -280,9 +280,10 @@ public Builder insertable(String line) { } /** - * Record that for any line X, insertCondition(X) is a necessary condition that a line may be inserted after X. + * Record that for any lines X, Y, insertCondition(X, Y) is a necessary condition that a line may be inserted + * between X and Y. */ - public Builder insertCondition(Predicate insertCondition) { + public Builder insertCondition(BiPredicate insertCondition) { return new Builder(replacers, insertables, insertCondition.and(insertCondition)); } @@ -302,13 +303,13 @@ public ErrorInserter get(Random random) { private final Random random; private final ImmutableList> replacers; private final ImmutableList insertables; - private final Predicate insertCondition; + private final BiPredicate insertCondition; private ErrorInserter( Random random, ImmutableList> replacers, ImmutableList insertables, - Predicate insertCondition + BiPredicate insertCondition ) { this.random = random; this.replacers = replacers; From 8d4d047534ed1917fcb30d4f18411f3483407d6f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 19 May 2022 09:28:31 -0700 Subject: [PATCH 44/58] [tests] Whitespace only. --- test/C/src/ActionDelay.lf | 8 +- test/C/src/Composition.lf | 54 ++++++------ test/C/src/CompositionAfter.lf | 44 +++++----- test/C/src/CompositionInheritance.lf | 66 +++++++-------- test/C/src/DelayStructWithAfter.lf | 2 +- test/C/src/DelayedReaction.lf | 8 +- test/C/src/DoubleReaction.lf | 60 +++++++------- test/C/src/DoubleTrigger.lf | 10 +-- test/C/src/Hello.lf | 66 +++++++-------- test/C/src/IdentifierLength.lf | 40 ++++----- test/C/src/Import.lf | 8 +- test/C/src/ImportRenamed.lf | 16 ++-- test/C/src/InheritanceAction.lf | 50 +++++------ test/C/src/ManualDelayedReaction.lf | 41 +++++----- test/C/src/NativeListsAndTimes.lf | 38 ++++----- test/C/src/ParameterizedState.lf | 12 +-- test/C/src/PeriodicDesugared.lf | 2 +- test/C/src/SendingInside.lf | 34 ++++---- test/C/src/Stop.lf | 8 +- test/C/src/StopZero.lf | 4 +- test/C/src/StructAsType.lf | 2 +- test/C/src/StructAsTypeDirect.lf | 2 +- test/C/src/TimeLimit.lf | 50 +++++------ test/C/src/TimeState.lf | 12 +-- test/C/src/Timeout.lf | 8 +- test/C/src/TimeoutZero.lf | 8 +- test/C/src/Wcet.lf | 14 ++-- test/C/src/concurrent/AsyncCallback.lf | 74 ++++++++--------- test/C/src/concurrent/AsyncCallbackDrop.lf | 80 +++++++++--------- test/C/src/concurrent/AsyncCallbackReplace.lf | 82 +++++++++---------- test/C/src/concurrent/CompositionThreaded.lf | 44 +++++----- .../src/concurrent/DoubleReactionThreaded.lf | 60 +++++++------- test/C/src/concurrent/HelloThreaded.lf | 58 ++++++------- test/C/src/concurrent/ImportThreaded.lf | 10 +-- test/C/src/concurrent/MinimalThreaded.lf | 10 +-- test/C/src/concurrent/ScheduleAt.lf | 4 +- .../C/src/concurrent/SendingInsideThreaded.lf | 34 ++++---- test/C/src/concurrent/StopThreaded.lf | 2 +- test/C/src/concurrent/StopZeroThreaded.lf | 4 +- test/C/src/concurrent/Threaded.lf | 70 ++++++++-------- test/C/src/concurrent/ThreadedMultiport.lf | 56 ++++++------- test/C/src/concurrent/ThreadedThreaded.lf | 70 ++++++++-------- test/C/src/concurrent/TimeoutThreaded.lf | 8 +- test/C/src/concurrent/TimeoutZeroThreaded.lf | 8 +- test/C/src/concurrent/Tracing.lf | 82 +++++++++---------- .../federated/DistributedBankToMultiport.lf | 10 +-- .../DistributedCountDecentralizedLate.lf | 4 +- ...tributedCountDecentralizedLateHierarchy.lf | 4 +- .../DistributedLoopedActionDecentralized.lf | 6 +- .../DistributedLoopedPhysicalAction.lf | 4 +- test/C/src/federated/DistributedStop.lf | 18 ++-- test/C/src/federated/DistributedStopZero.lf | 4 +- test/C/src/federated/LoopDistributedDouble.lf | 4 +- test/C/src/federated/PhysicalSTP.lf | 6 +- .../failing/DistributedDoublePortLooped2.lf | 2 +- test/C/src/lib/Imported.lf | 4 +- test/C/src/lib/ImportedAgain.lf | 14 ++-- test/C/src/lib/LoopedActionSender.lf | 4 +- test/C/src/lib/TestCountMultiport.lf | 12 +-- .../src/modal_models/ModalNestedReactions.lf | 30 +++---- .../MultipleOutputFeeder_2Connections.lf | 38 ++++----- test/C/src/multiport/BankSelfBroadcast.lf | 12 +-- test/C/src/multiport/BankToBank.lf | 40 ++++----- test/C/src/multiport/BankToBankMultiport.lf | 6 +- .../src/multiport/BankToBankMultiportAfter.lf | 6 +- test/C/src/multiport/BankToReaction.lf | 10 +-- test/C/src/multiport/FullyConnected.lf | 16 ++-- .../multiport/FullyConnectedAddressable.lf | 10 +-- .../C/src/multiport/MultiportFromHierarchy.lf | 44 +++++----- test/C/src/multiport/MultiportIn.lf | 74 ++++++++--------- test/C/src/multiport/MultiportOut.lf | 70 ++++++++-------- test/C/src/multiport/MultiportToHierarchy.lf | 42 +++++----- .../src/multiport/ReactionToContainedBank.lf | 6 +- .../src/multiport/ReactionToContainedBank2.lf | 2 +- .../ReactionToContainedBankMultiport.lf | 4 +- test/C/src/multiport/ReactionsToNested.lf | 12 +-- .../serialization/PersonProtocolBuffers.lf | 2 +- test/C/src/serialization/ProtoNoPacking.lf | 6 +- test/Cpp/src/ActionDelay.lf | 6 +- test/Cpp/src/DelayedReaction.lf | 12 +-- test/Cpp/src/DoubleTrigger.lf | 10 +-- test/Cpp/src/Hello.lf | 16 ++-- test/Cpp/src/ManualDelayedReaction.lf | 16 ++-- test/Cpp/src/NativeListsAndTimes.lf | 40 ++++----- test/Cpp/src/SendingInside.lf | 4 +- test/Cpp/src/Stride.lf | 2 +- test/Cpp/src/TimeLimit.lf | 52 ++++++------ test/Cpp/src/TimeState.lf | 12 +-- test/Cpp/src/concurrent/HelloThreaded.lf | 16 ++-- .../src/concurrent/SendingInsideThreaded.lf | 4 +- test/Cpp/src/concurrent/TimeLimitThreaded.lf | 52 ++++++------ test/Cpp/src/multiport/BankSelfBroadcast.lf | 8 +- test/Cpp/src/multiport/BankToBank.lf | 40 ++++----- test/Cpp/src/multiport/BankToBankMultiport.lf | 6 +- .../src/multiport/BankToBankMultiportAfter.lf | 8 +- test/Cpp/src/multiport/FullyConnected.lf | 10 +-- .../multiport/FullyConnectedAddressable.lf | 8 +- .../src/multiport/MultiportFromHierarchy.lf | 42 +++++----- test/Cpp/src/multiport/MultiportIn.lf | 70 ++++++++-------- test/Cpp/src/multiport/MultiportOut.lf | 68 +++++++-------- .../Cpp/src/multiport/MultiportToHierarchy.lf | 42 +++++----- .../ReadMultiportOutputOfContainedBank.lf | 50 +++++------ .../multiport/ReadOutputOfContainedBank.lf | 30 +++---- test/Cpp/src/multiport/WidthGivenByCode.lf | 12 +-- .../multiport/WriteInputOfContainedBank.lf | 2 +- .../WriteMultiportInputOfContainedBank.lf | 18 ++-- test/Cpp/src/target/Methods.lf | 20 ++--- test/Python/src/ActionDelay.lf | 6 +- test/Python/src/Composition.lf | 30 +++---- test/Python/src/CompositionAfter.lf | 42 +++++----- test/Python/src/CompositionInheritance.lf | 62 +++++++------- test/Python/src/DelayedReaction.lf | 2 +- test/Python/src/DoubleReaction.lf | 6 +- test/Python/src/Hello.lf | 8 +- test/Python/src/ImportRenamed.lf | 16 ++-- test/Python/src/PeriodicDesugared.lf | 2 +- test/Python/src/Pipeline.lf | 8 +- test/Python/src/concurrent/AsyncCallback.lf | 33 ++++---- .../DistributedLoopedPhysicalAction.lf | 16 ++-- test/Python/src/federated/DistributedStop.lf | 30 +++---- .../DistributedCountDecentralizedLate.lf | 24 +++--- ...tributedCountDecentralizedLateHierarchy.lf | 4 +- .../DistributedLoopedActionDecentralized.lf | 6 +- .../failing/LoopDistributedDouble.lf | 4 +- .../src/federated/failing/PhysicalSTP.lf | 8 +- test/Python/src/lib/LoopedActionSender.lf | 8 +- .../src/modal_models/ModalNestedReactions.lf | 34 ++++---- .../MultipleOutputFeeder_2Connections.lf | 30 +++---- test/Python/src/multiport/BankToBank.lf | 26 +++--- .../src/multiport/BankToBankMultiport.lf | 6 +- .../src/multiport/BankToBankMultiportAfter.lf | 6 +- .../Python/src/multiport/ReactionsToNested.lf | 14 ++-- .../serialization/PersonProtocolBuffers.lf | 6 +- .../src/serialization/ProtoNoPacking.lf | 6 +- test/Rust/src/NativeListsAndTimes.lf | 2 +- test/Rust/src/TimeState.lf | 10 +-- .../multiport/FullyConnectedAddressable.lf | 6 +- test/Rust/src/multiport/MultiportOut.lf | 56 ++++++------- test/Rust/src/target/CliFeature.lf | 2 +- test/TypeScript/src/DelayedReaction.lf | 6 +- test/TypeScript/src/DoubleTrigger.lf | 8 +- test/TypeScript/src/NativeListsAndTimes.lf | 39 ++++----- .../src/serialization/ProtoNoPacking.lf | 8 +- 143 files changed, 1600 insertions(+), 1605 deletions(-) diff --git a/test/C/src/ActionDelay.lf b/test/C/src/ActionDelay.lf index 9c06fcb90e..8bb665dd59 100644 --- a/test/C/src/ActionDelay.lf +++ b/test/C/src/ActionDelay.lf @@ -22,19 +22,19 @@ reactor Source { =} } reactor Sink { - input in:int; - reaction(in) {= + input in:int; + reaction(in) {= interval_t elapsed_logical = lf_time_logical_elapsed(); interval_t logical = lf_time_logical(); interval_t physical = lf_time_physical(); printf("Logical, physical, and elapsed logical: %lld %lld %lld.\n", logical, physical, elapsed_logical); if (elapsed_logical != MSEC(100)) { - printf("FAILURE: Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); + printf("FAILURE: Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); exit(1); } else { printf("SUCCESS. Elapsed logical time is 100 msec.\n"); } - =} + =} } main reactor ActionDelay { diff --git a/test/C/src/Composition.lf b/test/C/src/Composition.lf index 2dbf42fd47..1560298bbf 100644 --- a/test/C/src/Composition.lf +++ b/test/C/src/Composition.lf @@ -5,36 +5,36 @@ target C { timeout: 10 sec }; reactor Source(period:time(2 sec)) { - output y:int; - timer t(1 sec, period); - state count:int(0); - reaction(t) -> y {= - (self->count)++; - printf("Source sending %d.\n", self->count); - lf_set(y, self->count); - =} + output y:int; + timer t(1 sec, period); + state count:int(0); + reaction(t) -> y {= + (self->count)++; + printf("Source sending %d.\n", self->count); + lf_set(y, self->count); + =} } reactor Test { - input x:int; - state count:int(0); - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - fprintf(stderr, "FAILURE: Expected %d\n", self->count); - exit(1); - } - =} - reaction(shutdown) {= - if (self->count == 0) { - fprintf(stderr, "FAILURE: No data received.\n"); - } - =} + input x:int; + state count:int(0); + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + fprintf(stderr, "FAILURE: Expected %d\n", self->count); + exit(1); + } + =} + reaction(shutdown) {= + if (self->count == 0) { + fprintf(stderr, "FAILURE: No data received.\n"); + } + =} } main reactor Composition { - s = new Source(); - - d = new Test(); - s.y -> d.x; + s = new Source(); + + d = new Test(); + s.y -> d.x; } \ No newline at end of file diff --git a/test/C/src/CompositionAfter.lf b/test/C/src/CompositionAfter.lf index 850d4ca405..9d699c5cdc 100644 --- a/test/C/src/CompositionAfter.lf +++ b/test/C/src/CompositionAfter.lf @@ -1,35 +1,35 @@ // This test connects a simple counting source to tester // that checks against its own count. target C { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec }; reactor Source(period:time(2 sec)) { - output y:int; - timer t(1 sec, period); - state count:int(0); - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + output y:int; + timer t(1 sec, period); + state count:int(0); + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Test { - input x:int; - state count:int(0); - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d\n", self->count); - exit(1); - } - =} + input x:int; + state count:int(0); + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d\n", self->count); + exit(1); + } + =} } main reactor CompositionAfter(delay:time(5 sec)) { - s = new Source(); - d = new Test(); - s.y -> d.x after delay; + s = new Source(); + d = new Test(); + s.y -> d.x after delay; } \ No newline at end of file diff --git a/test/C/src/CompositionInheritance.lf b/test/C/src/CompositionInheritance.lf index ec3302563c..5dde90a29a 100644 --- a/test/C/src/CompositionInheritance.lf +++ b/test/C/src/CompositionInheritance.lf @@ -6,45 +6,45 @@ target C { }; reactor Source(period:time(2 sec)) { input foo:int; - output y:int; - timer t(1 sec, period); - state count:int(0); - reaction(t) -> y {= - printf("Hello World. At time %lld, my count is: %d.\n", lf_time_logical_elapsed(), self->count); - lf_set(y, self->count); - =} + output y:int; + timer t(1 sec, period); + state count:int(0); + reaction(t) -> y {= + printf("Hello World. At time %lld, my count is: %d.\n", lf_time_logical_elapsed(), self->count); + lf_set(y, self->count); + =} } reactor SourceExtended extends Source { - output y2: int; - timer t2(1 sec, 3 sec); - reaction(t2) -> y2 {= - (self->count)++; - printf("At time %lld, source sending %d.\n", lf_time_logical_elapsed(), self->count); - lf_set(y2, self->count); - =} + output y2: int; + timer t2(1 sec, 3 sec); + reaction(t2) -> y2 {= + (self->count)++; + printf("At time %lld, source sending %d.\n", lf_time_logical_elapsed(), self->count); + lf_set(y2, self->count); + =} } reactor Test { - input x:int; - state count:int(0); - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - fprintf(stderr, "FAILURE: Expected %d\n", self->count); - exit(1); - } - =} - reaction(shutdown) {= - if (self->count == 0) { - fprintf(stderr, "FAILURE: No data received.\n"); - } - =} + input x:int; + state count:int(0); + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + fprintf(stderr, "FAILURE: Expected %d\n", self->count); + exit(1); + } + =} + reaction(shutdown) {= + if (self->count == 0) { + fprintf(stderr, "FAILURE: No data received.\n"); + } + =} } main reactor CompositionInheritance { - s = new SourceExtended(period = 2 sec); - - d = new Test(); - s.y2 -> d.x; + s = new SourceExtended(period = 2 sec); + + d = new Test(); + s.y2 -> d.x; } \ No newline at end of file diff --git a/test/C/src/DelayStructWithAfter.lf b/test/C/src/DelayStructWithAfter.lf index b213f9e677..940f93841b 100644 --- a/test/C/src/DelayStructWithAfter.lf +++ b/test/C/src/DelayStructWithAfter.lf @@ -2,7 +2,7 @@ target C {files: include/hello.h}; preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { diff --git a/test/C/src/DelayedReaction.lf b/test/C/src/DelayedReaction.lf index c582a5f190..577f073c03 100644 --- a/test/C/src/DelayedReaction.lf +++ b/test/C/src/DelayedReaction.lf @@ -9,15 +9,15 @@ reactor Source { =} } reactor Sink { - input in:int; - reaction(in) {= + input in:int; + reaction(in) {= interval_t elapsed = lf_time_logical_elapsed(); printf("Nanoseconds since start: %lld.\n", elapsed); if (elapsed != 100000000LL) { printf("ERROR: Expected 100000000 but.\n"); exit(1); - } - =} + } + =} } main reactor DelayedReaction { diff --git a/test/C/src/DoubleReaction.lf b/test/C/src/DoubleReaction.lf index 7cbbde3902..2d8e33187f 100644 --- a/test/C/src/DoubleReaction.lf +++ b/test/C/src/DoubleReaction.lf @@ -6,39 +6,39 @@ target C { fast: true }; reactor Clock(offset:time(0), period:time(1 sec)) { - output y:int; - timer t(offset, period); - state count:int(0); - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + output y:int; + timer t(offset, period); + state count:int(0); + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Destination { - input x:int; - input w:int; - state s:int(2); - reaction(x, w) {= - int sum = 0; - if (x->is_present) { - sum += x->value; - } - if (w->is_present) { - sum += w->value; - } - printf("Sum of inputs is: %d\n", sum); - if (sum != self->s) { - printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); - exit(1); - } - self->s += 2; - =} + input x:int; + input w:int; + state s:int(2); + reaction(x, w) {= + int sum = 0; + if (x->is_present) { + sum += x->value; + } + if (w->is_present) { + sum += w->value; + } + printf("Sum of inputs is: %d\n", sum); + if (sum != self->s) { + printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); + exit(1); + } + self->s += 2; + =} } main reactor DoubleReaction { - c1 = new Clock(); - c2 = new Clock(); - d = new Destination(); - c1.y -> d.x; - c2.y -> d.w; + c1 = new Clock(); + c2 = new Clock(); + d = new Destination(); + c1.y -> d.x; + c2.y -> d.w; } \ No newline at end of file diff --git a/test/C/src/DoubleTrigger.lf b/test/C/src/DoubleTrigger.lf index c3fb19f931..fecd8b96e5 100644 --- a/test/C/src/DoubleTrigger.lf +++ b/test/C/src/DoubleTrigger.lf @@ -5,10 +5,10 @@ target C { fast: true }; main reactor DoubleTrigger { - timer t1; - timer t2; - state s:int(0); - reaction(t1, t2) {= + timer t1; + timer t2; + state s:int(0); + reaction(t1, t2) {= self->s++; if (self->s > 1) { printf("FAILURE: Reaction got triggered twice.\n"); @@ -17,7 +17,7 @@ main reactor DoubleTrigger { =} reaction(shutdown) {= if (self->s == 1) { - printf("SUCCESS.\n"); + printf("SUCCESS.\n"); } else { printf("FAILURE: Reaction was never triggered.\n"); exit(1); diff --git a/test/C/src/Hello.lf b/test/C/src/Hello.lf index 9cb651a730..0c0ace8aa0 100644 --- a/test/C/src/Hello.lf +++ b/test/C/src/Hello.lf @@ -8,41 +8,41 @@ target C { fast: true }; reactor Reschedule(period:time(2 secs), message:string("Hello C")) { - state count:int(0); - state previous_time:time(0); - timer t(1 secs, period); - logical action a; - reaction(t) -> a {= - printf("%s\n", self->message); - lf_schedule(a, MSEC(200)); - // Print the current time. - self->previous_time = lf_time_logical(); - time_t secs = self->previous_time/BILLION; - printf("Current time is %lld\n", self->previous_time); - printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); - =} - reaction(a) {= - (self->count)++; - printf("***** action %d at time %lld\n", self->count, lf_time_logical()); - // Check the a_has_value variable. - if (a->has_value) { - printf("FAILURE: Expected a_has_value to be false, but it was true.\n"); - exit(2); - } - long long time = lf_time_logical(); - if (time - self->previous_time != 200000000ll) { - printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", - time - self->previous_time - ); - exit(1); - } - =} + state count:int(0); + state previous_time:time(0); + timer t(1 secs, period); + logical action a; + reaction(t) -> a {= + printf("%s\n", self->message); + lf_schedule(a, MSEC(200)); + // Print the current time. + self->previous_time = lf_time_logical(); + time_t secs = self->previous_time/BILLION; + printf("Current time is %lld\n", self->previous_time); + printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); + =} + reaction(a) {= + (self->count)++; + printf("***** action %d at time %lld\n", self->count, lf_time_logical()); + // Check the a_has_value variable. + if (a->has_value) { + printf("FAILURE: Expected a_has_value to be false, but it was true.\n"); + exit(2); + } + long long time = lf_time_logical(); + if (time - self->previous_time != 200000000ll) { + printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", + time - self->previous_time + ); + exit(1); + } + =} } reactor Inside(period:time(1 sec), message:string("Composite default message.")) { - third_instance = new Reschedule(period = period, message = message); + third_instance = new Reschedule(period = period, message = message); } main reactor Hello { - first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); - second_instance = new Reschedule(message = "Hello from second_instance."); - composite_instance = new Inside(message = "Hello from composite_instance."); + first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); + second_instance = new Reschedule(message = "Hello from second_instance."); + composite_instance = new Inside(message = "Hello from composite_instance."); } \ No newline at end of file diff --git a/test/C/src/IdentifierLength.lf b/test/C/src/IdentifierLength.lf index 3725ea79d3..c33a5316b4 100644 --- a/test/C/src/IdentifierLength.lf +++ b/test/C/src/IdentifierLength.lf @@ -5,28 +5,28 @@ target C { fast: true }; reactor A_Really_Long_Name_For_A_Source(period:time(2 sec)) { - output y:int; - timer t(1 sec, period); - state count:int(0); - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + output y:int; + timer t(1 sec, period); + state count:int(0); + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Another_Really_Long_Name_For_A_Test_Class { - input x:int; - state count:int(0); - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d\n", self->count); - exit(1); - } - =} + input x:int; + state count:int(0); + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d\n", self->count); + exit(1); + } + =} } main reactor IdentifierLength { - a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source(); - another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class(); - a_really_long_name_for_a_source_instance.y -> another_really_long_name_for_a_test_instance.x; + a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source(); + another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class(); + a_really_long_name_for_a_source_instance.y -> another_really_long_name_for_a_test_instance.x; } \ No newline at end of file diff --git a/test/C/src/Import.lf b/test/C/src/Import.lf index 71f2bacc14..b8a739b291 100644 --- a/test/C/src/Import.lf +++ b/test/C/src/Import.lf @@ -4,8 +4,8 @@ target C; import Imported from "lib/Imported.lf" main reactor Import { timer t; - a = new Imported(); - reaction(t) -> a.x {= - lf_set(a.x, 42); - =} + a = new Imported(); + reaction(t) -> a.x {= + lf_set(a.x, 42); + =} } diff --git a/test/C/src/ImportRenamed.lf b/test/C/src/ImportRenamed.lf index 44134ee613..6990ccf4da 100644 --- a/test/C/src/ImportRenamed.lf +++ b/test/C/src/ImportRenamed.lf @@ -5,12 +5,12 @@ import Imported as X from "lib/Imported.lf" import Imported as Y from "lib/Imported.lf" import ImportedAgain as Z from "lib/ImportedAgain.lf" main reactor { - timer t; - a = new X(); - b = new Y(); - c = new Z(); - - reaction(t) -> a.x {= - lf_set(a.x, 42); - =} + timer t; + a = new X(); + b = new Y(); + c = new Z(); + + reaction(t) -> a.x {= + lf_set(a.x, 42); + =} } diff --git a/test/C/src/InheritanceAction.lf b/test/C/src/InheritanceAction.lf index 767f115eb9..0e6b01c4ad 100644 --- a/test/C/src/InheritanceAction.lf +++ b/test/C/src/InheritanceAction.lf @@ -5,37 +5,37 @@ target C { }; reactor Source { logical action foo:int; - output y:int; - reaction(foo) -> y {= - lf_set(y, foo->value); - =} + output y:int; + reaction(foo) -> y {= + lf_set(y, foo->value); + =} } reactor SourceExtended extends Source { - reaction(startup) -> foo {= - lf_schedule_int(foo, 0, 42); - =} + reaction(startup) -> foo {= + lf_schedule_int(foo, 0, 42); + =} } reactor Test { - input x:int; - state count:int(0); - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != 42) { - fprintf(stderr, "FAILURE: Expected 42\n"); - exit(1); - } - =} - reaction(shutdown) {= - if (self->count == 0) { - fprintf(stderr, "FAILURE: No data received.\n"); - } - =} + input x:int; + state count:int(0); + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != 42) { + fprintf(stderr, "FAILURE: Expected 42\n"); + exit(1); + } + =} + reaction(shutdown) {= + if (self->count == 0) { + fprintf(stderr, "FAILURE: No data received.\n"); + } + =} } main reactor { - s = new SourceExtended(); - d = new Test(); - s.y -> d.x; + s = new SourceExtended(); + d = new Test(); + s.y -> d.x; } \ No newline at end of file diff --git a/test/C/src/ManualDelayedReaction.lf b/test/C/src/ManualDelayedReaction.lf index 5ed0da8241..c93824ef13 100644 --- a/test/C/src/ManualDelayedReaction.lf +++ b/test/C/src/ManualDelayedReaction.lf @@ -10,22 +10,21 @@ target C { // That's the stuff that shall be generated for the after reactor GeneratedDelay { - - input y_in:int; - output y_out:int; - state y_state:int(0); - - // TODO: delay in act or the schedule call? - physical action act(0 msec); + input y_in:int; + output y_out:int; + state y_state:int(0); - reaction(y_in) -> act {= - self->y_state = y_in->value; - lf_schedule(act, MSEC(100)); -=} + // TODO: delay in act or the schedule call? + physical action act(0 msec); - reaction(act) -> y_out {= - lf_set(y_out, self->y_state); - =} + reaction(y_in) -> act {= + self->y_state = y_in->value; + lf_schedule(act, MSEC(100)); + =} + + reaction(act) -> y_out {= + lf_set(y_out, self->y_state); + =} } reactor Source { output out:int; @@ -37,27 +36,25 @@ reactor Source { } reactor Sink { - input in:int; - reaction(in) {= + input in:int; + reaction(in) {= interval_t elapsed_logical = lf_time_logical_elapsed(); interval_t logical = lf_time_logical(); interval_t physical = lf_time_physical(); printf("Nanoseconds since start: %lld %lld %lld.\n", logical, physical, elapsed_logical); if (elapsed_logical < MSEC(100)) { - printf("Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); + printf("Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); exit(1); - } - =} deadline(200 msec) {= =} + } + =} deadline(200 msec) {= =} } main reactor ManualDelayedReaction { - source = new Source(); sink = new Sink(); g = new GeneratedDelay(); - + // source.out -> sink.in; // rewritten above source.out -> g.y_in; g.y_out -> sink.in; - } diff --git a/test/C/src/NativeListsAndTimes.lf b/test/C/src/NativeListsAndTimes.lf index d75b511779..f77a2820d2 100644 --- a/test/C/src/NativeListsAndTimes.lf +++ b/test/C/src/NativeListsAndTimes.lf @@ -3,23 +3,23 @@ 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 - r:time({=0=}), // Zero-valued target code also is a valid time - 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 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 - reaction(tick) {= - // Target code - =} + 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 + r:time({=0=}), // Zero-valued target code also is a valid time + 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 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 + reaction(tick) {= + // Target code + =} } \ No newline at end of file diff --git a/test/C/src/ParameterizedState.lf b/test/C/src/ParameterizedState.lf index 4fe6045a79..07033c98b3 100644 --- a/test/C/src/ParameterizedState.lf +++ b/test/C/src/ParameterizedState.lf @@ -1,12 +1,12 @@ target C; reactor Foo(bar:int(42)) { - state baz(bar); - - reaction (startup) {= - printf("Baz: %d\n", self->baz); - =} + state baz(bar); + + reaction (startup) {= + printf("Baz: %d\n", self->baz); + =} } main reactor { - a = new Foo(); + a = new Foo(); } \ No newline at end of file diff --git a/test/C/src/PeriodicDesugared.lf b/test/C/src/PeriodicDesugared.lf index f82f653bc8..24c105499e 100644 --- a/test/C/src/PeriodicDesugared.lf +++ b/test/C/src/PeriodicDesugared.lf @@ -12,7 +12,7 @@ main reactor ( reaction(startup) -> init, recur {= if (self->offset == 0) { printf("Hello World!\n"); - lf_schedule(recur, 0); + lf_schedule(recur, 0); } else { lf_schedule(init, 0); } diff --git a/test/C/src/SendingInside.lf b/test/C/src/SendingInside.lf index 66ef27bf7b..198c09bd11 100644 --- a/test/C/src/SendingInside.lf +++ b/test/C/src/SendingInside.lf @@ -5,23 +5,23 @@ target C { fast: true }; reactor Printer { - input x:int; - state count:int(1); - reaction(x) {= - printf("Inside reactor received: %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d.\n", self->count); - exit(1); - } - self->count++; - =} + input x:int; + state count:int(1); + reaction(x) {= + printf("Inside reactor received: %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d.\n", self->count); + exit(1); + } + self->count++; + =} } main reactor SendingInside { - state count:int(0); - timer t(0, 1 sec); - p = new Printer(); - reaction(t) -> p.x {= - (self->count)++; - lf_set(p.x, self->count); - =} + state count:int(0); + timer t(0, 1 sec); + p = new Printer(); + reaction(t) -> p.x {= + (self->count)++; + lf_set(p.x, self->count); + =} } \ No newline at end of file diff --git a/test/C/src/Stop.lf b/test/C/src/Stop.lf index 03370fd8ee..d741e89ac5 100644 --- a/test/C/src/Stop.lf +++ b/test/C/src/Stop.lf @@ -41,14 +41,14 @@ reactor Consumer { printf("SUCCESS: successfully enforced stop.\n"); } else if(lf_tag_compare(current_tag, (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); + exit(1); } else if (self->reaction_invoked_correctly == false) { // Check to see if reactions were called correctly - fprintf(stderr,"ERROR: Failed to invoke reaction(in) at tag (%llu, %d).\n", + fprintf(stderr,"ERROR: Failed to invoke reaction(in) at tag (%llu, %d).\n", current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); + exit(1); } =} } diff --git a/test/C/src/StopZero.lf b/test/C/src/StopZero.lf index 692e939e04..e1556797bd 100644 --- a/test/C/src/StopZero.lf +++ b/test/C/src/StopZero.lf @@ -25,7 +25,7 @@ reactor Sender { printf("Requesting stop at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_request_stop(); + lf_request_stop(); } else if (lf_tag_compare(lf_tag(), one) > 0) { fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", lf_time_logical_elapsed(), @@ -74,7 +74,7 @@ reactor Receiver { printf("Requesting stop at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_request_stop(); + lf_request_stop(); } =} diff --git a/test/C/src/StructAsType.lf b/test/C/src/StructAsType.lf index c4d6326b93..a475f569de 100644 --- a/test/C/src/StructAsType.lf +++ b/test/C/src/StructAsType.lf @@ -3,7 +3,7 @@ target C {files: include/hello.h}; preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { diff --git a/test/C/src/StructAsTypeDirect.lf b/test/C/src/StructAsTypeDirect.lf index 73e45bb83e..c0ca2c96ff 100644 --- a/test/C/src/StructAsTypeDirect.lf +++ b/test/C/src/StructAsTypeDirect.lf @@ -3,7 +3,7 @@ target C {files: include/hello.h}; preamble {= - #include "hello.h" + #include "hello.h" =} reactor Source { diff --git a/test/C/src/TimeLimit.lf b/test/C/src/TimeLimit.lf index 7ff27990cf..107cbf8126 100644 --- a/test/C/src/TimeLimit.lf +++ b/test/C/src/TimeLimit.lf @@ -13,26 +13,26 @@ target C { fast: true }; reactor Clock(offset:time(0), period:time(1 sec)) { - output y:int; - timer t(offset, period); - state count:int(0); - reaction(t) -> y {= - (self->count)++; - //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); - lf_set(y, self->count); - =} + output y:int; + timer t(offset, period); + state count:int(0); + reaction(t) -> y {= + (self->count)++; + //printf("Reacting at time %ld.\n", lf_time_logical_elapsed()); + lf_set(y, self->count); + =} } reactor Destination { - input x:int; - state s:int(1); - reaction(x) {= - // printf("%d\n", x->value); - if (x->value != self->s) { - printf("Error: Expected %d and got %d.\n", self->s, x->value); - exit(1); - } - self->s++; - =} + input x:int; + state s:int(1); + reaction(x) {= + // printf("%d\n", x->value); + if (x->value != self->s) { + printf("Error: Expected %d and got %d.\n", self->s, x->value); + exit(1); + } + self->s++; + =} reaction(shutdown) {= printf("**** shutdown reaction invoked.\n"); if (self->s != 10000002) { @@ -43,11 +43,11 @@ reactor Destination { =} } main reactor TimeLimit(period:time(1 usec)) { - timer stop(10 secs); - reaction(stop) {= - lf_request_stop(); - =} - c = new Clock(period = period); - d = new Destination(); - c.y -> d.x; + timer stop(10 secs); + reaction(stop) {= + lf_request_stop(); + =} + c = new Clock(period = period); + d = new Destination(); + c.y -> d.x; } diff --git a/test/C/src/TimeState.lf b/test/C/src/TimeState.lf index 64c78410c4..6ea766f6ab 100644 --- a/test/C/src/TimeState.lf +++ b/test/C/src/TimeState.lf @@ -1,13 +1,13 @@ target C; reactor Foo(bar:int(42)) { - state baz:time(500 msec); - - reaction (startup) {= - printf("Baz: %lld\n", self->baz); - =} + state baz:time(500 msec); + + reaction (startup) {= + printf("Baz: %lld\n", self->baz); + =} } main reactor { - a = new Foo(); + a = new Foo(); } \ No newline at end of file diff --git a/test/C/src/Timeout.lf b/test/C/src/Timeout.lf index e8aa6d8045..b46f661169 100644 --- a/test/C/src/Timeout.lf +++ b/test/C/src/Timeout.lf @@ -16,9 +16,9 @@ reactor Consumer { tag_t current_tag = lf_tag(); if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", current_tag.time, current_tag.microstep); - exit(1); + exit(1); } else if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { self->success = true; // Successfully invoked the reaction at (timeout, 0) @@ -32,9 +32,9 @@ reactor Consumer { self->success == true) { printf("SUCCESS: successfully enforced timeout.\n"); } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", current_tag.time, current_tag.microstep); - exit(1); + exit(1); } =} } diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index 02fe880829..461792fe76 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -17,9 +17,9 @@ reactor Consumer { tag_t current_tag = lf_tag(); if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", current_tag.time, current_tag.microstep); - exit(1); + exit(1); } else if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { self->success = true; // Successfully invoked the reaction at (timeout, 0) @@ -33,9 +33,9 @@ reactor Consumer { self->success == true) { printf("SUCCESS: successfully enforced timeout.\n"); } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", current_tag.time, current_tag.microstep); - exit(1); + exit(1); } =} } diff --git a/test/C/src/Wcet.lf b/test/C/src/Wcet.lf index 10b2c1d54e..ca12ab41af 100644 --- a/test/C/src/Wcet.lf +++ b/test/C/src/Wcet.lf @@ -14,12 +14,12 @@ reactor Work { input in2: int; output out:int; reaction(in1, in2) -> out {= - int ret; - if (in1->value > 10) { - ret = in2->value * in1->value; - } else { - ret = in2->value + in1->value; - } + int ret; + if (in1->value > 10) { + ret = in2->value * in1->value; + } else { + ret = in2->value + in1->value; + } lf_set(out, ret); =} } @@ -38,4 +38,4 @@ main reactor Wcet { source.out1 -> work.in1; source.out2 -> work.in2; work.out -> print.in; -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index 146b3d2636..d7ee1b0afa 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -10,56 +10,56 @@ target C { tracing: true, - timeout: 2 sec + timeout: 2 sec }; main reactor AsyncCallback { - - preamble {= - void callback(void* a) { - // Schedule twice. If the action is not physical, these should - // get consolidated into a single action triggering. If it is, - // then they cause two separate triggerings with close but not - // equal time stamps. The minimum time between these is determined - // by the argument in the physical action definition. - lf_schedule(a, 0LL); + + preamble {= + void callback(void* a) { + // Schedule twice. If the action is not physical, these should + // get consolidated into a single action triggering. If it is, + // then they cause two separate triggerings with close but not + // equal time stamps. The minimum time between these is determined + // by the argument in the physical action definition. lf_schedule(a, 0LL); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - instant_t sleep_time = 100000000; - lf_nanosleep(sleep_time); - callback(a); - return NULL; - } - 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); - + lf_schedule(a, 0LL); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + instant_t sleep_time = 100000000; + lf_nanosleep(sleep_time); + callback(a); + return NULL; + } + 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); + physical action a(100 msec):int; state i:int(0); - reaction(t) -> a {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, a); - =} - - reaction(a) {= - instant_t elapsed_time = lf_time_logical_elapsed(); + reaction(t) -> a {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, a); + =} + + reaction(a) {= + instant_t elapsed_time = lf_time_logical_elapsed(); printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); - if (elapsed_time <= self->expected_time) { - printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); - exit(1); - } + if (elapsed_time <= self->expected_time) { + printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); + exit(1); + } if (self->toggle) { self->toggle = false; self->expected_time += 200000000LL; } else { self->toggle = true; } - =} + =} } \ No newline at end of file diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index 180ef6f528..296356e04a 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -3,59 +3,59 @@ // This test will not work with the unthreaded C target because that target // does not implement any mutex protecting the event queue. target C { - timeout: 2 sec + timeout: 2 sec }; main reactor { - - preamble {= - void callback(void* a) { - // Schedule twice in rapid succession. - // The second value should be dropped because the - // timestamps will not be sufficiently separated. - // The minimum time between these is determined - // by the argument in the physical action definition. - lf_schedule_int(a, 0, 0); + + preamble {= + void callback(void* a) { + // Schedule twice in rapid succession. + // The second value should be dropped because the + // timestamps will not be sufficiently separated. + // The minimum time between these is determined + // by the argument in the physical action definition. + lf_schedule_int(a, 0, 0); lf_schedule_int(a, 0, 1); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - instant_t sleep_time = 100000000; - lf_nanosleep(sleep_time); - callback(a); - return NULL; - } - 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); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + instant_t sleep_time = 100000000; + lf_nanosleep(sleep_time); + callback(a); + return NULL; + } + 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); physical action a(100 msec, 100 msec, "drop"):int; state i:int(0); - reaction(t) -> a {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, a); - =} - - reaction(a) {= - instant_t elapsed_time = lf_time_logical_elapsed(); + reaction(t) -> a {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, a); + =} + + reaction(a) {= + instant_t elapsed_time = lf_time_logical_elapsed(); printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); - if (elapsed_time <= self->expected_time) { - printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); - exit(1); - } - if (a->value != 0) { - printf("ERROR: Received: %d, expected 0 because the second event should have been dropped.\n", a->value); - exit(2); - } + if (elapsed_time <= self->expected_time) { + printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); + exit(1); + } + if (a->value != 0) { + printf("ERROR: Received: %d, expected 0 because the second event should have been dropped.\n", a->value); + exit(2); + } if (self->toggle) { self->toggle = false; self->expected_time += 200000000LL; } else { self->toggle = true; } - =} + =} } diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index 15977f1a4c..58fb53ba5a 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -3,59 +3,59 @@ // This test will not work with the unthreaded C target because that target // does not implement any mutex protecting the event queue. target C { - timeout: 2 sec + timeout: 2 sec }; main reactor { - - preamble {= - void callback(void* a) { - // Schedule twice in rapid succession. - // The second value should be dropped because the - // timestamps will not be sufficiently separated. - // The minimum time between these is determined - // by the argument in the physical action definition. - lf_schedule_int(a, 0, 0); + + preamble {= + void callback(void* a) { + // Schedule twice in rapid succession. + // The second value should be dropped because the + // timestamps will not be sufficiently separated. + // The minimum time between these is determined + // by the argument in the physical action definition. + lf_schedule_int(a, 0, 0); lf_schedule_int(a, 0, 1); - } - // Simulate time passing before a callback occurs. - void* take_time(void* a) { - instant_t sleep_time = 100000000; - lf_nanosleep(sleep_time); - callback(a); - return NULL; - } - 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); + } + // Simulate time passing before a callback occurs. + void* take_time(void* a) { + instant_t sleep_time = 100000000; + lf_nanosleep(sleep_time); + callback(a); + return NULL; + } + 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); physical action a(100 msec, 100 msec, "replace"):int; state i:int(0); - - reaction(t) -> a {= - // start new thread, provide callback - lf_thread_create(&self->thread_id, &take_time, a); - =} - - reaction(a) {= - instant_t elapsed_time = lf_time_logical_elapsed(); + + reaction(t) -> a {= + // start new thread, provide callback + lf_thread_create(&self->thread_id, &take_time, a); + =} + + reaction(a) {= + instant_t elapsed_time = lf_time_logical_elapsed(); printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); - if (elapsed_time <= self->expected_time) { - printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); - exit(1); - } - if (a->value != 1) { - printf("ERROR: Received: %d, expected 1 because the second event should have replaced the first.\n", a->value); - exit(2); - } + if (elapsed_time <= self->expected_time) { + printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); + exit(1); + } + if (a->value != 1) { + printf("ERROR: Received: %d, expected 1 because the second event should have replaced the first.\n", a->value); + exit(2); + } if (self->toggle) { self->toggle = false; self->expected_time += 200000000LL; } else { self->toggle = true; } - =} + =} } diff --git a/test/C/src/concurrent/CompositionThreaded.lf b/test/C/src/concurrent/CompositionThreaded.lf index 44bc395c8a..d4bd90c133 100644 --- a/test/C/src/concurrent/CompositionThreaded.lf +++ b/test/C/src/concurrent/CompositionThreaded.lf @@ -1,34 +1,34 @@ // This test connects a simple counting source to tester // that checks against its own count. target C { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec }; reactor Source(period:time(2 sec)) { - output y:int; - timer t(1 sec, period); - state count:int(0); - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + output y:int; + timer t(1 sec, period); + state count:int(0); + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Test { - input x:int; - state count:int(0); - reaction(x) {= - (self->count)++; - printf("Received %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d\n", self->count); - exit(1); - } - =} + input x:int; + state count:int(0); + reaction(x) {= + (self->count)++; + printf("Received %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d\n", self->count); + exit(1); + } + =} } main reactor CompositionThreaded { - s = new Source(); - d = new Test(); - s.y -> d.x; + s = new Source(); + d = new Test(); + s.y -> d.x; } \ No newline at end of file diff --git a/test/C/src/concurrent/DoubleReactionThreaded.lf b/test/C/src/concurrent/DoubleReactionThreaded.lf index 8c690f046d..c790a18307 100644 --- a/test/C/src/concurrent/DoubleReactionThreaded.lf +++ b/test/C/src/concurrent/DoubleReactionThreaded.lf @@ -6,38 +6,38 @@ target C { fast: true, }; reactor Clock(offset:time(0), period:time(1 sec)) { - output y:int; - timer t(offset, period); - state count:int(0); - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} + output y:int; + timer t(offset, period); + state count:int(0); + reaction(t) -> y {= + (self->count)++; + lf_set(y, self->count); + =} } reactor Destination { - input x:int; - input w:int; - state s:int(2); - reaction(x, w) {= - int sum = 0; - if (x->is_present) { - sum += x->value; - } - if (w->is_present) { - sum += w->value; - } - printf("Sum of inputs is: %d\n", sum); - if (sum != self->s) { - printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); - exit(1); - } - self->s += 2; - =} + input x:int; + input w:int; + state s:int(2); + reaction(x, w) {= + int sum = 0; + if (x->is_present) { + sum += x->value; + } + if (w->is_present) { + sum += w->value; + } + printf("Sum of inputs is: %d\n", sum); + if (sum != self->s) { + printf("FAILURE: Expected sum to be %d, but it was %d.\n", self->s, sum); + exit(1); + } + self->s += 2; + =} } main reactor DoubleReactionThreaded { - c1 = new Clock(); - c2 = new Clock(); - d = new Destination(); - c1.y -> d.x; - c2.y -> d.w; + c1 = new Clock(); + c2 = new Clock(); + d = new Destination(); + c1.y -> d.x; + c2.y -> d.w; } \ No newline at end of file diff --git a/test/C/src/concurrent/HelloThreaded.lf b/test/C/src/concurrent/HelloThreaded.lf index 33e1c011a7..4a4044d823 100644 --- a/test/C/src/concurrent/HelloThreaded.lf +++ b/test/C/src/concurrent/HelloThreaded.lf @@ -8,43 +8,43 @@ target C { fast: true, }; reactor Reschedule(period:time(2 secs), message:string("Hello C")) { - state count:int(0); - state previous_time:time(0); - timer t(1 secs, period); - logical action a; - reaction(t) -> a {= - printf("%s\n", self->message); - lf_schedule(a, MSEC(200)); - // Print the current time. - self->previous_time = lf_time_logical(); - time_t secs = self->previous_time/BILLION; - printf("Current time is %lld\n", self->previous_time); - printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); - =} - - reaction(a) {= - (self->count)++; - printf("***** action %d at time %lld\n", self->count, lf_time_logical()); + state count:int(0); + state previous_time:time(0); + timer t(1 secs, period); + logical action a; + reaction(t) -> a {= + printf("%s\n", self->message); + lf_schedule(a, MSEC(200)); + // Print the current time. + self->previous_time = lf_time_logical(); + time_t secs = self->previous_time/BILLION; + printf("Current time is %lld\n", self->previous_time); + printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); + =} + + reaction(a) {= + (self->count)++; + printf("***** action %d at time %lld\n", self->count, lf_time_logical()); // Check the a_has_value variable. if (a->has_value) { printf("FAILURE: Expected a->has_value to be false, but it was true.\n"); exit(2); } - long long time = lf_time_logical(); - if (time - self->previous_time != 200000000ll) { - printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", - time - self->previous_time - ); - exit(1); - } - =} + long long time = lf_time_logical(); + if (time - self->previous_time != 200000000ll) { + printf("FAILURE: Expected 200ms of logical time to elapse but got %lld nanoseconds.\n", + time - self->previous_time + ); + exit(1); + } + =} } reactor Inside(period:time(1 sec), message:string("Composite default message.")) { - third_instance = new Reschedule(period = period, message = message); + third_instance = new Reschedule(period = period, message = message); } main reactor HelloThreaded { - first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); - second_instance = new Reschedule(message = "Hello from second_instance."); - composite_instance = new Inside(message = "Hello from composite_instance."); + first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); + second_instance = new Reschedule(message = "Hello from second_instance."); + composite_instance = new Inside(message = "Hello from composite_instance."); } \ No newline at end of file diff --git a/test/C/src/concurrent/ImportThreaded.lf b/test/C/src/concurrent/ImportThreaded.lf index 16544ed969..c54b1fbdb3 100644 --- a/test/C/src/concurrent/ImportThreaded.lf +++ b/test/C/src/concurrent/ImportThreaded.lf @@ -6,9 +6,9 @@ target C { import Imported from "../lib/Imported.lf"; main reactor ImportThreaded { - timer t; - a = new Imported(); - reaction(t) -> a.x {= - lf_set(a.x, 42); - =} + timer t; + a = new Imported(); + reaction(t) -> a.x {= + lf_set(a.x, 42); + =} } diff --git a/test/C/src/concurrent/MinimalThreaded.lf b/test/C/src/concurrent/MinimalThreaded.lf index fab2c19992..3e8d0e8804 100644 --- a/test/C/src/concurrent/MinimalThreaded.lf +++ b/test/C/src/concurrent/MinimalThreaded.lf @@ -2,8 +2,8 @@ target C { }; main reactor MinimalThreaded { - timer t; - reaction(t) {= - printf("Hello World.\n"); - =} -} \ No newline at end of file + timer t; + reaction(t) {= + printf("Hello World.\n"); + =} +} diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index cf411fabcd..c8d21552a6 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -18,7 +18,7 @@ reactor Scheduler { 900 msec, 900 msec); state action_hit_list_microstep:int[](1, 2, 0, 1, 0, 2, 3, 4, 5); // Size = 9 state action_hit_list_times:int[](0, 0, 400 msec, 400msec, 800 msec, 800 msec, - 800 msec, 900msec, 900msec); // Size = 9 + 800 msec, 900msec, 900msec); // Size = 9 state action_hit_list_index:int(0); reaction(startup) -> act {= for (int i=0; i < 16; i++) { @@ -33,7 +33,7 @@ reactor Scheduler { instant_t elapsed_time = lf_time_logical_elapsed(); if (elapsed_time == self->action_hit_list_times[self->action_hit_list_index] && microstep == self->action_hit_list_microstep[self->action_hit_list_index]) { - self->action_hit_list_index++; + self->action_hit_list_index++; } printf("Triggered at tag (%lld, %u).\n", elapsed_time, microstep); =} diff --git a/test/C/src/concurrent/SendingInsideThreaded.lf b/test/C/src/concurrent/SendingInsideThreaded.lf index dd5afd1fab..5e415e997b 100644 --- a/test/C/src/concurrent/SendingInsideThreaded.lf +++ b/test/C/src/concurrent/SendingInsideThreaded.lf @@ -5,23 +5,23 @@ target C { fast: true }; reactor Printer { - input x:int; - state count:int(1); - reaction(x) {= - printf("Inside reactor received: %d\n", x->value); - if (x->value != self->count) { - printf("FAILURE: Expected %d.\n", self->count); - exit(1); - } - self->count++; - =} + input x:int; + state count:int(1); + reaction(x) {= + printf("Inside reactor received: %d\n", x->value); + if (x->value != self->count) { + printf("FAILURE: Expected %d.\n", self->count); + exit(1); + } + self->count++; + =} } main reactor SendingInsideThreaded { - state count:int(0); - timer t(0, 1 sec); - p = new Printer(); - reaction(t) -> p.x {= - (self->count)++; - lf_set(p.x, self->count); - =} + state count:int(0); + timer t(0, 1 sec); + p = new Printer(); + reaction(t) -> p.x {= + (self->count)++; + lf_set(p.x, self->count); + =} } \ No newline at end of file diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index c155afe107..ca70ad1d53 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -51,7 +51,7 @@ reactor Consumer { current_tag.time - lf_time_start(), current_tag.microstep); } else if (self->reaction_invoked_correctly == false) { // Check to see if reactions were called correctly - lf_print_error_and_exit("Failed to invoke reaction(in) at tag (%llu, %d).", + lf_print_error_and_exit("Failed to invoke reaction(in) at tag (%llu, %d).", current_tag.time - lf_time_start(), current_tag.microstep); } =} diff --git a/test/C/src/concurrent/StopZeroThreaded.lf b/test/C/src/concurrent/StopZeroThreaded.lf index b90797e664..0928ce1020 100644 --- a/test/C/src/concurrent/StopZeroThreaded.lf +++ b/test/C/src/concurrent/StopZeroThreaded.lf @@ -25,7 +25,7 @@ reactor Sender { printf("Requesting stop at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_request_stop(); + lf_request_stop(); } else if (lf_tag_compare(lf_tag(), one) > 0) { fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", lf_time_logical_elapsed(), @@ -74,7 +74,7 @@ reactor Receiver { printf("Requesting stop at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_request_stop(); + lf_request_stop(); } =} diff --git a/test/C/src/concurrent/Threaded.lf b/test/C/src/concurrent/Threaded.lf index 72d026ac3a..bad1b37f2c 100644 --- a/test/C/src/concurrent/Threaded.lf +++ b/test/C/src/concurrent/Threaded.lf @@ -13,48 +13,48 @@ target C { flags: "" // Disable compiler optimization so that TakeTime actually takes time. }; reactor Source { - timer t(0, 200 msec); - output out:int; - state s:int(0); - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + timer t(0, 200 msec); + output out:int; + state s:int(0); + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor TakeTime { - input in:int; - output out:int; - reaction(in) -> out {= - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - int offset = 0; - for (int i = 0; i < 100000000; i++) { - offset++; - } - lf_set(out, in->value + offset); - =} + input in:int; + output out:int; + reaction(in) -> out {= + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + int offset = 0; + for (int i = 0; i < 100000000; i++) { + offset++; + } + lf_set(out, in->value + offset); + =} } reactor Destination(width:int(4)) { - state s:int(400000000); - input[width] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { + state s:int(400000000); + input[width] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += in_width; - =} + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += in_width; + =} } main reactor (width:int(4)) { - a = new Source(); - t = new[width] TakeTime(); - (a.out)+ -> t.in; + a = new Source(); + t = new[width] TakeTime(); + (a.out)+ -> t.in; b = new Destination(width = width); - t.out -> b.in; + t.out -> b.in; } diff --git a/test/C/src/concurrent/ThreadedMultiport.lf b/test/C/src/concurrent/ThreadedMultiport.lf index 396deccada..f4500910b9 100644 --- a/test/C/src/concurrent/ThreadedMultiport.lf +++ b/test/C/src/concurrent/ThreadedMultiport.lf @@ -4,20 +4,20 @@ target C { flags: "", // Disable compiler optimization so that TakeTime actually takes time. }; reactor Source(width:int(4)) { - timer t(0, 200 msec); - output[width] out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[width] out:int; + state s:int(0); + reaction(t) -> out {= for(int i = 0; i < out_width; i++) { lf_set(out[i], self->s); } - self->s++; - =} + self->s++; + =} } reactor Computation(iterations:int(100000000)) { - input in:int; - output out:int; - reaction(in) -> out {= + input in:int; + output out:int; + reaction(in) -> out {= // struct timespec sleep_time = {(time_t) 0, (long)200000000}; // struct timespec remaining_time; // nanosleep(&sleep_time, &remaining_time); @@ -26,25 +26,25 @@ reactor Computation(iterations:int(100000000)) { offset++; } lf_set(out, in->value + offset); - =} + =} } reactor Destination(width:int(4), iterations:int(100000000)) { - state s:int(0); - input[width] in:int; - reaction(in) {= + state s:int(0); + input[width] in:int; + reaction(in) {= int expected = self->iterations * self->width + self->s; - int sum = 0; - for (int i = 0; i < in_width; i++) { + int sum = 0; + for (int i = 0; i < in_width; i++) { if (in[i]->is_present) sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != expected) { - printf("ERROR: Expected %d.\n", expected); - exit(1); - } - self->s += self->width; - =} - reaction(shutdown) {= + printf("Sum of received: %d.\n", sum); + if (sum != expected) { + printf("ERROR: Expected %d.\n", expected); + exit(1); + } + self->s += self->width; + =} + reaction(shutdown) {= if (self->s == 0) { fprintf(stderr, "ERROR: Destination received no input!\n"); exit(1); @@ -54,9 +54,9 @@ reactor Destination(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); - a.out -> t.in; - t.out -> b.in; + a = new Source(width = width); + t = new[width] Computation(iterations = iterations); + b = new Destination(width = width, iterations = iterations); + a.out -> t.in; + t.out -> b.in; } \ No newline at end of file diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 5b11e2a758..dbff8b780b 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -12,48 +12,48 @@ target C { flags: "", // Disable compiler optimization so that TakeTime actually takes time. }; reactor Source { - timer t(0, 200 msec); - output out:int; - state s:int(0); - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + timer t(0, 200 msec); + output out:int; + state s:int(0); + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor TakeTime { - input in:int; - output out:int; - reaction(in) -> out {= - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - int offset = 0; - for (int i = 0; i < 100000000; i++) { - offset++; - } - lf_set(out, in->value + offset); - =} + input in:int; + output out:int; + reaction(in) -> out {= + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + int offset = 0; + for (int i = 0; i < 100000000; i++) { + offset++; + } + lf_set(out, in->value + offset); + =} } reactor Destination(width:int(4)) { - state s:int(400000000); - input[width] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { + state s:int(400000000); + input[width] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += in_width; - =} + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += in_width; + =} } main reactor ThreadedThreaded(width:int(4)) { - a = new Source(); - t = new[width] TakeTime(); - (a.out)+ -> t.in; + a = new Source(); + t = new[width] TakeTime(); + (a.out)+ -> t.in; b = new Destination(width = width); - t.out -> b.in; + t.out -> b.in; } diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index c5a1940a75..769abb9d42 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -17,9 +17,9 @@ reactor Consumer { tag_t current_tag = lf_tag(); if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", current_tag.time, current_tag.microstep); - exit(1); + exit(1); } else if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { self->success = true; // Successfully invoked the reaction at (timeout, 0) @@ -33,9 +33,9 @@ reactor Consumer { self->success == true) { printf("SUCCESS: successfully enforced timeout.\n"); } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", current_tag.time - start_time, current_tag.microstep); - exit(1); + exit(1); } =} } diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index 35f1629e38..cb2c14f898 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -18,9 +18,9 @@ reactor Consumer { tag_t current_tag = lf_tag(); if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", current_tag.time - start_time, current_tag.microstep); - exit(1); + exit(1); } else if (lf_tag_compare(current_tag, (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { self->success = true; // Successfully invoked the reaction at (timeout, 0) @@ -34,9 +34,9 @@ reactor Consumer { self->success == true) { printf("SUCCESS: successfully enforced timeout.\n"); } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", current_tag.time - start_time, current_tag.microstep); - exit(1); + exit(1); } =} } diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index 4be0f217e0..e3e6a62fb8 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -6,21 +6,21 @@ target C { logging: DEBUG }; reactor Source { - timer t(0, 200 msec); - output out:int; - state s:int(0); - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + timer t(0, 200 msec); + output out:int; + state s:int(0); + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor TakeTime( bank_index:int(0) ) { - input in:int; - output out:int; - state event:string("No ID"); - reaction(startup) {= + input in:int; + output out:int; + state event:string("No ID"); + reaction(startup) {= // Construct an id string for a user trace event. const char* format = "Count completed by reactor %d."; size_t length = strlen(format) + 2; @@ -33,18 +33,18 @@ reactor TakeTime( exit(1); } =} - reaction(in) -> out {= - // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - int offset = 0; - for (int i = 0; i < 100000000; i++) { - offset++; - } - tracepoint_user_event(self->event); - lf_set(out, in->value + offset); - =} - reaction(shutdown) {= + reaction(in) -> out {= + // struct timespec sleep_time = {(time_t) 0, (long)200000000}; + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + int offset = 0; + for (int i = 0; i < 100000000; i++) { + offset++; + } + tracepoint_user_event(self->event); + lf_set(out, in->value + offset); + =} + reaction(shutdown) {= // NOTE: Can't actually free this because the tracepoint // code runs after shutdown events are processed and the // string id of the event may get corrupted. @@ -52,35 +52,35 @@ reactor TakeTime( =} } reactor Destination(width:int(4)) { - state s:int(400000000); - state count:int(0); - input[width] in:int; - reaction(startup) {= + state s:int(400000000); + state count:int(0); + input[width] in:int; + reaction(startup) {= // Register the user value event. if (!register_user_trace_event("Number of Destination invocations")) { fprintf(stderr, "ERROR: Failed to register trace event.\n"); exit(1); } =} - reaction(in) {= + reaction(in) {= self->count++; tracepoint_user_value("Number of Destination invocations", self->count); - int sum = 0; - for (int i = 0; i < in_width; i++) { + int sum = 0; + for (int i = 0; i < in_width; i++) { sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += in_width; - =} + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += in_width; + =} } main reactor (width:int(4)) { - a = new Source(); - t = new[width] TakeTime(); - (a.out)+ -> t.in; + a = new Source(); + t = new[width] TakeTime(); + (a.out)+ -> t.in; b = new Destination(width = width); - t.out -> b.in; + t.out -> b.in; } diff --git a/test/C/src/federated/DistributedBankToMultiport.lf b/test/C/src/federated/DistributedBankToMultiport.lf index 2b103e26c1..3003378e6d 100644 --- a/test/C/src/federated/DistributedBankToMultiport.lf +++ b/test/C/src/federated/DistributedBankToMultiport.lf @@ -10,11 +10,11 @@ reactor Destination { state count:int(1); reaction(in) {= for (int i = 0; i < in_width; i++) { - lf_print("Received %d.", in[i]->value); - if (self->count != in[i]->value) { - lf_print_error_and_exit("Expected %d.", self->count); - } - } + lf_print("Received %d.", in[i]->value); + if (self->count != in[i]->value) { + lf_print_error_and_exit("Expected %d.", self->count); + } + } self->count++; =} reaction(shutdown) {= diff --git a/test/C/src/federated/DistributedCountDecentralizedLate.lf b/test/C/src/federated/DistributedCountDecentralizedLate.lf index f290de0a28..45e5d01b77 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLate.lf @@ -38,8 +38,8 @@ reactor Print { tag_t current_tag = lf_tag(); printf("At tag (%lld, %u), message has violated the STP offset by (%lld, %u).\n", current_tag.time - start_time, current_tag.microstep, - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep); + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep); self->success_stp_violation++; self->c++; =} diff --git a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf index a8293dbef6..ffdf0ac476 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -39,8 +39,8 @@ reactor ImportantActuator { =} STP (0) {= tag_t current_tag = lf_tag(); printf("Message violated STP offset by (%lld, %u).\n", - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep); + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep); self->success_stp_violation++; self->c++; =} diff --git a/test/C/src/federated/DistributedLoopedActionDecentralized.lf b/test/C/src/federated/DistributedLoopedActionDecentralized.lf index 68a4d84b45..96b4a10a0f 100644 --- a/test/C/src/federated/DistributedLoopedActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedActionDecentralized.lf @@ -102,9 +102,9 @@ reactor STPReceiver(take_a_break_after:int(10), break_interval:time(400 msec), s // time step. if (current_tag.time != self->last_time_updated_stp) { lf_print("Raising the STP offset by %lld.", MSEC(10)); - self->stp_offset += MSEC(10); - lf_set_stp_offset(MSEC(10)); - self->last_time_updated_stp = current_tag.time; + self->stp_offset += MSEC(10); + lf_set_stp_offset(MSEC(10)); + self->last_time_updated_stp = current_tag.time; } =} diff --git a/test/C/src/federated/DistributedLoopedPhysicalAction.lf b/test/C/src/federated/DistributedLoopedPhysicalAction.lf index ad69ff200e..433d726cbb 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalAction.lf @@ -25,10 +25,10 @@ reactor Sender(take_a_break_after:int(10), break_interval:time(550 msec)) { lf_set(out, self->sent_messages); self->sent_messages++; if (self->sent_messages < self->take_a_break_after) { - lf_schedule(act, 0); + lf_schedule(act, 0); } else { // Take a break - self->sent_messages = 0; + self->sent_messages = 0; lf_schedule(act, self->break_interval); } =} diff --git a/test/C/src/federated/DistributedStop.lf b/test/C/src/federated/DistributedStop.lf index 943e04920f..70a0bfb1ef 100644 --- a/test/C/src/federated/DistributedStop.lf +++ b/test/C/src/federated/DistributedStop.lf @@ -20,7 +20,7 @@ reactor Sender { // for 'act' like Stop.lf, we trigger the // same reaction to test lf_request_stop() being // called multiple times - lf_schedule(act, 0); + lf_schedule(act, 0); } if (lf_time_logical_elapsed() == USEC(1)) { // Call lf_request_stop() both at (1 usec, 0) and @@ -34,7 +34,7 @@ reactor Sender { tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; if (lf_tag_compare(lf_tag(), _1usec1) == 0) { // The reaction was invoked at (1 usec, 1) as expected - self->reaction_invoked_correctly = true; + self->reaction_invoked_correctly = true; } else if (lf_tag_compare(lf_tag(), _1usec1) > 0) { // The reaction should not have been invoked at tags larger than (1 usec, 1) lf_print_error_and_exit("ERROR: Invoked reaction(t, act) at tag bigger than shutdown."); @@ -74,18 +74,18 @@ reactor Receiver ( lf_print("Requesting stop at (%lld, %u).", lf_time_logical_elapsed(), lf_tag().microstep); - lf_request_stop(); - // The receiver should receive a message at tag - // (1 usec, 1) and trigger this reaction - self->reaction_invoked_correctly = true; + lf_request_stop(); + // The receiver should receive a message at tag + // (1 usec, 1) and trigger this reaction + self->reaction_invoked_correctly = true; } - + tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; if (lf_tag_compare(lf_tag(), _1usec1) > 0) { - self->reaction_invoked_correctly = false; + self->reaction_invoked_correctly = false; } =} - + reaction(shutdown) {= // Sender should have requested stop earlier than the receiver. // Therefore, the shutdown events must occur at (1000, 0) on the diff --git a/test/C/src/federated/DistributedStopZero.lf b/test/C/src/federated/DistributedStopZero.lf index d4bc66d88a..9cdcb8bcf3 100644 --- a/test/C/src/federated/DistributedStopZero.lf +++ b/test/C/src/federated/DistributedStopZero.lf @@ -21,7 +21,7 @@ reactor Sender { printf("Requesting stop at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_request_stop(); + lf_request_stop(); } =} @@ -53,7 +53,7 @@ reactor Receiver { printf("Requesting stop at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); - lf_request_stop(); + lf_request_stop(); } =} diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 5f0e919673..2586be677c 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -40,8 +40,8 @@ reactor Looper(incr:int(1), delay:time(0 msec)) { =} reaction(a) -> out, out2 {= if (self->count%2 == 0) { - lf_set(out, self->count); - } else { + lf_set(out, self->count); + } else { lf_set(out2, self->count); } self->count += self->incr; diff --git a/test/C/src/federated/PhysicalSTP.lf b/test/C/src/federated/PhysicalSTP.lf index 85e9658e16..f43b5304a0 100644 --- a/test/C/src/federated/PhysicalSTP.lf +++ b/test/C/src/federated/PhysicalSTP.lf @@ -22,7 +22,7 @@ reactor Print (STP_offset_param:time(0)) { instant_t STP_discrepency = lf_time_logical() + self->STP_offset_param - in->physical_time_of_arrival; if (STP_discrepency < 0) { lf_print("The message has violated the STP offset by %lld in physical time.", -1 * STP_discrepency); - self->c++; + self->c++; } else { lf_print_error_and_exit("Message arrived %lld early.", STP_discrepency); } @@ -33,8 +33,8 @@ reactor Print (STP_offset_param:time(0)) { =} reaction(shutdown) {= if (self->c != 3) { - lf_print_error_and_exit("Expected to receive 2 items but got %d.", self->c); - } + lf_print_error_and_exit("Expected to receive 2 items but got %d.", self->c); + } =} } diff --git a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf index 2fcffa3f41..874d96d472 100644 --- a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf +++ b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf @@ -50,7 +50,7 @@ reactor Print { reaction(in, in2) -> out {= interval_t elapsed_time = lf_time_logical_elapsed(); if (in->is_present) { - lf_print("At tag (%lld, %u), received in = %d.", elapsed_time, lf_tag().microstep, in->value); + lf_print("At tag (%lld, %u), received in = %d.", elapsed_time, lf_tag().microstep, in->value); } if (in2->is_present) { lf_print("At tag (%lld, %u), received in2 = %d.", elapsed_time, lf_tag().microstep, in2->value); diff --git a/test/C/src/lib/Imported.lf b/test/C/src/lib/Imported.lf index 6f5db9371a..8b2a8d143d 100644 --- a/test/C/src/lib/Imported.lf +++ b/test/C/src/lib/Imported.lf @@ -6,6 +6,6 @@ reactor Imported { input x:int; a = new ImportedAgain(); reaction(x) -> a.x {= - lf_set(a.x, x->value); - =} + lf_set(a.x, x->value); + =} } \ No newline at end of file diff --git a/test/C/src/lib/ImportedAgain.lf b/test/C/src/lib/ImportedAgain.lf index a71c434f50..7f0be2bf4c 100644 --- a/test/C/src/lib/ImportedAgain.lf +++ b/test/C/src/lib/ImportedAgain.lf @@ -3,12 +3,12 @@ target C; reactor ImportedAgain { - input x:int; - reaction(x) {= + input x:int; + reaction(x) {= printf("Received: %d.\n", x->value); - if (x->value != 42) { - printf("ERROR: Expected input to be 42. Got: %d.\n", x->value); - exit(1); - } - =} + if (x->value != 42) { + printf("ERROR: Expected input to be 42. Got: %d.\n", x->value); + exit(1); + } + =} } diff --git a/test/C/src/lib/LoopedActionSender.lf b/test/C/src/lib/LoopedActionSender.lf index 3ad91cc113..0dc8dd77d1 100644 --- a/test/C/src/lib/LoopedActionSender.lf +++ b/test/C/src/lib/LoopedActionSender.lf @@ -26,10 +26,10 @@ reactor Sender(take_a_break_after:int(10), break_interval:time(400 msec)) { lf_set(out, self->sent_messages); self->sent_messages++; if (self->sent_messages < self->take_a_break_after) { - lf_schedule(act, 0); + lf_schedule(act, 0); } else { // Take a break - self->sent_messages=0; + self->sent_messages=0; lf_schedule(act, self->break_interval); } =} diff --git a/test/C/src/lib/TestCountMultiport.lf b/test/C/src/lib/TestCountMultiport.lf index 7abae6bdf3..4e6dda48a5 100644 --- a/test/C/src/lib/TestCountMultiport.lf +++ b/test/C/src/lib/TestCountMultiport.lf @@ -17,13 +17,13 @@ reactor TestCountMultiport(start:int(1), stride:int(1), num_inputs:int(1), width reaction(in) {= for (int i = 0; i < in_width; i++) { if (!in[i]->is_present) { - lf_print_error_and_exit("No input on channel %d.", i); + lf_print_error_and_exit("No input on channel %d.", i); } - lf_print("Received %d on channel %d.", in[i]->value, i); - if (in[i]->value != self->count) { - lf_print_error_and_exit("Expected %d.", self->count); - } - self->count += self->stride; + lf_print("Received %d on channel %d.", in[i]->value, i); + if (in[i]->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count += self->stride; } self->inputs_received++; =} diff --git a/test/C/src/modal_models/ModalNestedReactions.lf b/test/C/src/modal_models/ModalNestedReactions.lf index 695ff4c8ac..27c7121bda 100644 --- a/test/C/src/modal_models/ModalNestedReactions.lf +++ b/test/C/src/modal_models/ModalNestedReactions.lf @@ -8,32 +8,32 @@ target C { }; reactor CounterCycle { - input next:bool; - + input next:bool; + output count:int; output only_in_two:bool; - output never:int; - + output never:int; + initial mode One { - reaction(next) -> count, Two {= + reaction(next) -> count, Two {= lf_set(count, 1); lf_set_mode(Two); - =} + =} } mode Two { - fwd = new Forward() - next -> fwd.in - fwd.out -> only_in_two - - reaction(next) -> count, One {= + fwd = new Forward() + next -> fwd.in + fwd.out -> only_in_two + + reaction(next) -> count, One {= lf_set(count, 2); lf_set_mode(One); - =} + =} } mode Three { - reaction(next) -> never {= + reaction(next) -> never {= lf_set(never, true); - =} + =} } } @@ -58,7 +58,7 @@ main reactor { // Check reaction(stepper) counter.count, counter.only_in_two {= printf("%d\n", counter.count->value); - + if (!counter.count->is_present) { printf("ERROR: Missing mode change.\n"); exit(1); diff --git a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf index 2fea77b1cc..9c0771083b 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -11,33 +11,33 @@ target C { import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next:bool; - output count:int; - + input next:bool; + output count:int; + initial mode One { - counter1 = new Counter(period=250msec); - counter1.value -> count; - - reaction(next) -> Two {= + counter1 = new Counter(period=250msec); + counter1.value -> count; + + reaction(next) -> Two {= lf_set_mode(Two); - =} + =} } mode Two { - counter2 = new Counter(period=100msec); - counter2.value -> count; - - reaction(next) -> continue(One) {= + counter2 = new Counter(period=100msec); + counter2.value -> count; + + reaction(next) -> continue(One) {= lf_set_mode(One); - =} + =} } } reactor Counter(period:time(1sec)) { output value:int - + timer t(0, period) state curval:int(0) - + reaction(t) -> value {= lf_set(value, self->curval++); =} @@ -45,7 +45,7 @@ reactor Counter(period:time(1sec)) { main reactor { timer stepper(500msec, 500msec) - + modal = new Modal() test = new TraceTesting( events_size = 1, @@ -74,12 +74,12 @@ main reactor { reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} - + // Print reaction(modal.count) {= printf("%d\n", modal.count->value); =} - + modal.count -> test.events -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankSelfBroadcast.lf b/test/C/src/multiport/BankSelfBroadcast.lf index f052dfa450..f1c6596642 100644 --- a/test/C/src/multiport/BankSelfBroadcast.lf +++ b/test/C/src/multiport/BankSelfBroadcast.lf @@ -19,22 +19,22 @@ reactor A ( reaction(in) {= for (int i = 0; i < in_width; i++) { if (in[i]->is_present) { - lf_print( - "Reactor %d received %d on channel %d.", + lf_print( + "Reactor %d received %d on channel %d.", self->bank_index, in[i]->value, i ); if (in[i]->value != i) { lf_print_error_and_exit("Expected %d.", i); } self->received = true; - } else { - lf_print( - "Reactor %d channel %d is absent.", + } else { + lf_print( + "Reactor %d channel %d is absent.", self->bank_index, i ); lf_print_error_and_exit("Expected %d.", i); } - } + } =} reaction(shutdown) {= if (!self->received) { diff --git a/test/C/src/multiport/BankToBank.lf b/test/C/src/multiport/BankToBank.lf index 10742d4253..7e029fc7aa 100644 --- a/test/C/src/multiport/BankToBank.lf +++ b/test/C/src/multiport/BankToBank.lf @@ -6,28 +6,28 @@ target C { reactor Source( bank_index:int(0) ) { - timer t(0, 200 msec); - output out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output out:int; + state s:int(0); + reaction(t) -> out {= lf_set(out, self->s); - self->s += self->bank_index; - =} + self->s += self->bank_index; + =} } reactor Destination( bank_index:int(0) ) { - state s:int(0); - input in:int; - reaction(in) {= - printf("Destination %d received: %d.\n", self->bank_index, in->value); - if (in->value != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += self->bank_index; - =} - reaction(shutdown) {= + state s:int(0); + input in:int; + reaction(in) {= + printf("Destination %d received: %d.\n", self->bank_index, in->value); + if (in->value != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += self->bank_index; + =} + reaction(shutdown) {= if (self->s == 0 && self->bank_index != 0) { fprintf(stderr, "ERROR: Destination %d received no input!\n", self->bank_index); exit(1); @@ -37,7 +37,7 @@ reactor Destination( } main reactor BankToBank(width:int(4)) { - a = new[width] Source(); - b = new[width] Destination(); - a.out -> b.in; + 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 684b1d469f..8253f63027 100644 --- a/test/C/src/multiport/BankToBankMultiport.lf +++ b/test/C/src/multiport/BankToBankMultiport.lf @@ -37,7 +37,7 @@ reactor Destination(width:int(1)) { =} } 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; + a = new[bank_width] Source(width = 4); + b = new[bank_width] Destination(width = 4); + a.out -> b.in; } \ No newline at end of file diff --git a/test/C/src/multiport/BankToBankMultiportAfter.lf b/test/C/src/multiport/BankToBankMultiportAfter.lf index 65a81c25b9..17185982a6 100644 --- a/test/C/src/multiport/BankToBankMultiportAfter.lf +++ b/test/C/src/multiport/BankToBankMultiportAfter.lf @@ -37,7 +37,7 @@ reactor Destination(width:int(1)) { =} } 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; + a = new[bank_width] Source(width = 4); + b = new[bank_width] Destination(width = 4); + a.out -> b.in after 200 msec; } \ No newline at end of file diff --git a/test/C/src/multiport/BankToReaction.lf b/test/C/src/multiport/BankToReaction.lf index f59365dbcb..66b64bdda4 100644 --- a/test/C/src/multiport/BankToReaction.lf +++ b/test/C/src/multiport/BankToReaction.lf @@ -11,11 +11,11 @@ main reactor { reaction(s.out) {= for (int i = 0; i < s_width; i++) { - lf_print("Received %d.", s[i].out->value); - if (self->count != s[i].out->value) { - lf_print_error_and_exit("Expected %d.", self->count); - } - } + lf_print("Received %d.", s[i].out->value); + if (self->count != s[i].out->value) { + lf_print_error_and_exit("Expected %d.", self->count); + } + } self->count++; =} } diff --git a/test/C/src/multiport/FullyConnected.lf b/test/C/src/multiport/FullyConnected.lf index 85059007e4..feeb53949d 100644 --- a/test/C/src/multiport/FullyConnected.lf +++ b/test/C/src/multiport/FullyConnected.lf @@ -6,21 +6,21 @@ reactor Node( ) { input[num_nodes] in: int; output out: int; - + state received: bool(false); - + reaction (startup) -> out{= - lf_print("Hello from node %d!", self->bank_index); - // broadcast my ID to everyone - lf_set(out, self->bank_index); + lf_print("Hello from node %d!", self->bank_index); + // broadcast my ID to everyone + lf_set(out, self->bank_index); =} - + reaction (in) {= printf("Node %d received messages from ", self->bank_index); size_t count = 0; - for (int i = 0; i < in_width; i++) { + for (int i = 0; i < in_width; i++) { if (in[i]->is_present) { - self->received = true; + self->received = true; count++; printf("%d, ", in[i]->value); } diff --git a/test/C/src/multiport/FullyConnectedAddressable.lf b/test/C/src/multiport/FullyConnectedAddressable.lf index 2943b2eacc..d5e76e65ae 100644 --- a/test/C/src/multiport/FullyConnectedAddressable.lf +++ b/test/C/src/multiport/FullyConnectedAddressable.lf @@ -14,22 +14,22 @@ reactor Node( reaction (startup) -> out {= int outChannel = (self->bank_index + 1) % self->num_nodes; - lf_print("Node %d sending %d out on channel %d.", + lf_print("Node %d sending %d out on channel %d.", self->bank_index, self->bank_index, outChannel ); - // broadcast my ID to everyone - lf_set(out[outChannel], self->bank_index); + // broadcast my ID to everyone + lf_set(out[outChannel], self->bank_index); =} reaction (in) {= self->triggered = true; printf("Node %d received messages from ", self->bank_index); size_t count = 0; - for (int i = 0; i < in_width; i++) { + for (int i = 0; i < in_width; i++) { if (in[i]->is_present) { count++; printf("%d, ", in[i]->value); - self->received = in[i]->value; + self->received = in[i]->value; } } printf("\n"); diff --git a/test/C/src/multiport/MultiportFromHierarchy.lf b/test/C/src/multiport/MultiportFromHierarchy.lf index ed4aa7d909..a6e3a1fc41 100644 --- a/test/C/src/multiport/MultiportFromHierarchy.lf +++ b/test/C/src/multiport/MultiportFromHierarchy.lf @@ -4,31 +4,31 @@ target C { fast: true }; reactor Source(width:int(3)) { - timer t(0, 200 msec); - output[width] out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[width] out:int; + state s:int(0); + reaction(t) -> out {= for(int i = 0; i < out_width; i++) { lf_set(out[i], self->s++); } - =} + =} } reactor Destination(width:int(3)) { - state s:int(6); - input[width] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { + state s:int(6); + input[width] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { if (in[i]->is_present) sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} - reaction(shutdown) {= + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} + reaction(shutdown) {= if (self->s <= 6) { fprintf(stderr, "ERROR: Destination received no input!\n"); exit(1); @@ -49,7 +49,7 @@ reactor InsideContainer(width:int(3)) { } main reactor MultiportFromHierarchy(width:int(4)) { - a = new Container(width = width); - b = new Destination(width = width); - a.out -> b.in; -} \ No newline at end of file + a = new Container(width = width); + b = new Destination(width = width); + a.out -> b.in; +} diff --git a/test/C/src/multiport/MultiportIn.lf b/test/C/src/multiport/MultiportIn.lf index 3a03830dc8..140db6caf3 100644 --- a/test/C/src/multiport/MultiportIn.lf +++ b/test/C/src/multiport/MultiportIn.lf @@ -6,36 +6,36 @@ target C { }; reactor Source { - timer t(0, 200 msec); - output out:int; - state s:int(0); - reaction(t) -> out {= - lf_set(out, self->s); - self->s++; - =} + timer t(0, 200 msec); + output out:int; + state s:int(0); + reaction(t) -> out {= + lf_set(out, self->s); + self->s++; + =} } reactor Computation { - input in:int; - output out:int; - reaction(in) -> out {= - lf_set(out, in->value); - =} + input in:int; + output out:int; + reaction(in) -> out {= + lf_set(out, in->value); + =} } reactor Destination { - state s:int(0); - input[4] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { - sum += in[i]->value; + state s:int(0); + input[4] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { + sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 4; - =} + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 4; + =} reaction(shutdown) {= if (self->s == 0) { fprintf(stderr, "ERROR: Destination received no input!\n"); @@ -46,15 +46,15 @@ reactor Destination { } main reactor MultiportIn { - a = new Source(); - t1 = new Computation(); - t2 = new Computation(); - t3 = new Computation(); - t4 = new Computation(); - b = new Destination(); - a.out -> t1.in; - a.out -> t2.in; - a.out -> t3.in; - a.out -> t4.in; - t1.out, t2.out, t3.out, t4.out -> b.in; -} \ No newline at end of file + a = new Source(); + t1 = new Computation(); + t2 = new Computation(); + t3 = new Computation(); + t4 = new Computation(); + b = new Destination(); + a.out -> t1.in; + a.out -> t2.in; + a.out -> t3.in; + a.out -> t4.in; + t1.out, t2.out, t3.out, t4.out -> b.in; +} diff --git a/test/C/src/multiport/MultiportOut.lf b/test/C/src/multiport/MultiportOut.lf index 28b9b6dadf..284afd6c68 100644 --- a/test/C/src/multiport/MultiportOut.lf +++ b/test/C/src/multiport/MultiportOut.lf @@ -4,43 +4,43 @@ target C { fast: true }; reactor Source { - timer t(0, 200 msec); - output[4] out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[4] out:int; + state s:int(0); + reaction(t) -> out {= for(int i = 0; i < 4; i++) { lf_set(out[i], self->s); } - self->s++; - =} + self->s++; + =} } reactor Computation { - input in:int; - output out:int; - reaction(in) -> out {= + input in:int; + output out:int; + reaction(in) -> out {= // No need to sleep for this test. // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - lf_set(out, in->value); - =} + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + lf_set(out, in->value); + =} } reactor Destination { - state s:int(0); - input[4] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { + state s:int(0); + input[4] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { if (in[i]->is_present) sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 4; - =} - reaction(shutdown) {= + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 4; + =} + reaction(shutdown) {= if (self->s == 0) { fprintf(stderr, "ERROR: Destination received no input!\n"); exit(1); @@ -50,12 +50,12 @@ reactor Destination { } main reactor { - a = new Source(); - t1 = new Computation(); - t2 = new Computation(); - t3 = new Computation(); - t4 = new Computation(); - b = new Destination(); - a.out -> t1.in, t2.in, t3.in, t4.in; - t1.out, t2.out, t3.out, t4.out -> b.in; -} \ No newline at end of file + a = new Source(); + t1 = new Computation(); + t2 = new Computation(); + t3 = new Computation(); + t4 = new Computation(); + b = new Destination(); + a.out -> t1.in, t2.in, t3.in, t4.in; + t1.out, t2.out, t3.out, t4.out -> b.in; +} diff --git a/test/C/src/multiport/MultiportToHierarchy.lf b/test/C/src/multiport/MultiportToHierarchy.lf index 44c6d203ed..f855a6df03 100644 --- a/test/C/src/multiport/MultiportToHierarchy.lf +++ b/test/C/src/multiport/MultiportToHierarchy.lf @@ -5,31 +5,31 @@ target C { fast: true }; reactor Source(width:int(2)) { - timer t(0, 200 msec); - output[width] out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[width] out:int; + state s:int(0); + reaction(t) -> out {= for(int i = 0; i < 4; i++) { lf_set(out[i], self->s++); } - =} + =} } reactor Destination(width:int(4)) { - state s:int(6); - input[width] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in_width; i++) { + state s:int(6); + input[width] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in_width; i++) { if (in[i]->is_present) sum += in[i]->value; } - printf("Sum of received: %d.\n", sum); - if (sum != self->s) { - printf("ERROR: Expected %d.\n", self->s); - exit(1); - } - self->s += 16; - =} - reaction(shutdown) {= + printf("Sum of received: %d.\n", sum); + if (sum != self->s) { + printf("ERROR: Expected %d.\n", self->s); + exit(1); + } + self->s += 16; + =} + reaction(shutdown) {= if (self->s <= 6) { fprintf(stderr, "ERROR: Destination received no input!\n"); exit(1); @@ -44,7 +44,7 @@ reactor Container(width:int(4)) { } main reactor MultiportToHierarchy(width:int(4)) { - a = new Source(width = width); - b = new Container(width = width); - a.out -> b.in; + a = new Source(width = width); + b = new Container(width = width); + a.out -> b.in; } \ No newline at end of file diff --git a/test/C/src/multiport/ReactionToContainedBank.lf b/test/C/src/multiport/ReactionToContainedBank.lf index 7e05882186..feda1a0626 100644 --- a/test/C/src/multiport/ReactionToContainedBank.lf +++ b/test/C/src/multiport/ReactionToContainedBank.lf @@ -1,5 +1,5 @@ - // Test reaction sending messages to a contained bank of reactors. - target C { +// Test reaction sending messages to a contained bank of reactors. +target C { timeout: 1 sec, fast: true }; @@ -13,7 +13,7 @@ main reactor ReactionToContainedBank(width:int(2)) { reaction(t) -> test.in {= for (int i = 0; i < self->width; i++) { - lf_set(test[i].in, self->count); + lf_set(test[i].in, self->count); } self->count++; =} diff --git a/test/C/src/multiport/ReactionToContainedBank2.lf b/test/C/src/multiport/ReactionToContainedBank2.lf index c7acfd16d7..173c2964ed 100644 --- a/test/C/src/multiport/ReactionToContainedBank2.lf +++ b/test/C/src/multiport/ReactionToContainedBank2.lf @@ -13,7 +13,7 @@ reactor ReactionToContainedBank(width:int(2)) { reaction(t) -> test.in {= for (int i = 0; i < self->width; i++) { - lf_set(test[i].in, self->count); + lf_set(test[i].in, self->count); } self->count++; =} diff --git a/test/C/src/multiport/ReactionToContainedBankMultiport.lf b/test/C/src/multiport/ReactionToContainedBankMultiport.lf index 25f0f26f62..4fe7002f13 100644 --- a/test/C/src/multiport/ReactionToContainedBankMultiport.lf +++ b/test/C/src/multiport/ReactionToContainedBankMultiport.lf @@ -15,9 +15,9 @@ main reactor(width:int(2)) { reaction(t) -> test.in {= for (int i = 0; i < self->width; i++) { for (int j = 0; j < self->width; j++) { - lf_set(test[j].in[i], self->count); + lf_set(test[j].in[i], self->count); } self->count++; } =} -} \ No newline at end of file +} diff --git a/test/C/src/multiport/ReactionsToNested.lf b/test/C/src/multiport/ReactionsToNested.lf index b9ff2b11ec..990e5431a8 100644 --- a/test/C/src/multiport/ReactionsToNested.lf +++ b/test/C/src/multiport/ReactionsToNested.lf @@ -6,14 +6,14 @@ target C { reactor T(expected:int(0)) { input z:int; state received:bool(false); - reaction(z) {= - lf_print("T received %d", z->value); - self->received = true; - if (z->value != self->expected) { + reaction(z) {= + lf_print("T received %d", z->value); + self->received = true; + if (z->value != self->expected) { lf_print_error_and_exit("Expected %d", self->expected); } - =} - reaction(shutdown) {= + =} + reaction(shutdown) {= if (!self->received) { lf_print_error_and_exit("No input received"); } diff --git a/test/C/src/serialization/PersonProtocolBuffers.lf b/test/C/src/serialization/PersonProtocolBuffers.lf index 699e4085d0..c928ccb058 100644 --- a/test/C/src/serialization/PersonProtocolBuffers.lf +++ b/test/C/src/serialization/PersonProtocolBuffers.lf @@ -42,6 +42,6 @@ main reactor { // Extract and print the unpacked message. printf("Name: %s\n", unpacked->name); - free(buffer); // Free the allocated serialized buffer + free(buffer); // Free the allocated serialized buffer =} } \ No newline at end of file diff --git a/test/C/src/serialization/ProtoNoPacking.lf b/test/C/src/serialization/ProtoNoPacking.lf index 4115cbbd4f..1ea28df808 100644 --- a/test/C/src/serialization/ProtoNoPacking.lf +++ b/test/C/src/serialization/ProtoNoPacking.lf @@ -36,7 +36,7 @@ reactor SinkProto { =} } main reactor ProtoNoPacking { - s = new SourceProto(); - d = new SinkProto(); - s.out -> d.in; + s = new SourceProto(); + d = new SinkProto(); + s.out -> d.in; } diff --git a/test/Cpp/src/ActionDelay.lf b/test/Cpp/src/ActionDelay.lf index 3a1fd2040f..432121da9a 100644 --- a/test/Cpp/src/ActionDelay.lf +++ b/test/Cpp/src/ActionDelay.lf @@ -24,8 +24,8 @@ reactor Source { } reactor Sink { - input in:int; - reaction(in) {= + input in:int; + reaction(in) {= auto elapsed_logical = get_elapsed_logical_time(); auto logical = get_logical_time(); auto physical = get_physical_time(); @@ -38,7 +38,7 @@ reactor Sink { } else { std::cout << "SUCCESS. Elapsed logical time is 100 msec.\n"; } - =} + =} } main reactor ActionDelay { diff --git a/test/Cpp/src/DelayedReaction.lf b/test/Cpp/src/DelayedReaction.lf index fe301f08eb..190889aaa6 100644 --- a/test/Cpp/src/DelayedReaction.lf +++ b/test/Cpp/src/DelayedReaction.lf @@ -5,19 +5,19 @@ reactor Source { output out:void; reaction(startup) -> out {= out.set(); - =} -} + =} +} reactor Sink { - input in:void; - reaction(in) {= + input in:void; + reaction(in) {= auto elapsed = get_elapsed_logical_time(); std::cout << "Nanoseconds since start: " << elapsed << '\n'; if (elapsed != 100ms) { std::cerr << "ERROR: Expected 100000000 nsecs.\n"; exit(1); - } - =} + } + =} } main reactor DelayedReaction { diff --git a/test/Cpp/src/DoubleTrigger.lf b/test/Cpp/src/DoubleTrigger.lf index 36b5747e43..cfcaef8781 100644 --- a/test/Cpp/src/DoubleTrigger.lf +++ b/test/Cpp/src/DoubleTrigger.lf @@ -3,10 +3,10 @@ target Cpp; main reactor DoubleTrigger { - timer t1; - timer t2; - state s:int(0); - reaction(t1, t2) {= + timer t1; + timer t2; + state s:int(0); + reaction(t1, t2) {= s++; if (s > 1) { std::cout << "FAILURE: Reaction got triggered twice." << std::endl; @@ -15,7 +15,7 @@ main reactor DoubleTrigger { =} reaction(shutdown) {= if (s == 1) { - std::cout << "SUCCESS" << std::endl; + std::cout << "SUCCESS" << std::endl; } else { std::cerr << "FAILURE: Reaction was never triggered." << std::endl; exit(1); diff --git a/test/Cpp/src/Hello.lf b/test/Cpp/src/Hello.lf index d9e25bc89b..3e82bd1a14 100644 --- a/test/Cpp/src/Hello.lf +++ b/test/Cpp/src/Hello.lf @@ -20,15 +20,15 @@ reactor HelloCpp(period:time(2 secs), message:{=std::string=}("Hello C++")) { std::cout << "Current time is " << previous_time << std::endl; =} reaction(a) {= - count++; - auto time = get_logical_time(); - std::cout << "***** action " << count << " at time " + count++; + auto time = get_logical_time(); + std::cout << "***** action " << count << " at time " << time << std::endl; - auto diff = time - previous_time; - if (diff != 200ms) { - std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " - << "but got " << diff << std::endl; - exit(1); + auto diff = time - previous_time; + if (diff != 200ms) { + std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " + << "but got " << diff << std::endl; + exit(1); } =} } diff --git a/test/Cpp/src/ManualDelayedReaction.lf b/test/Cpp/src/ManualDelayedReaction.lf index 254aed6dbd..4fc2c08142 100644 --- a/test/Cpp/src/ManualDelayedReaction.lf +++ b/test/Cpp/src/ManualDelayedReaction.lf @@ -23,29 +23,29 @@ reactor Source { // reaction(t) -> out after 100 msec {= reaction(t) -> out {= out.set(1); - =} + =} } reactor Sink { - input in:int; - reaction(in) {= + input in:int; + reaction(in) {= auto elapsed_logical = get_elapsed_logical_time(); std::cout << "Elapsed logical time: " << elapsed_logical << '\n'; if (elapsed_logical != 100ms) { std::cerr << "ERROR: Expected 100 ms\n"; exit(1); - } - =} + } + =} } main reactor ManualDelayedReaction { source = new Source(); sink = new Sink(); g = new GeneratedDelay(); - + // source.out -> sink.in; // rewritten above source.out -> g.y_in; g.y_out -> sink.in; - -} \ No newline at end of file + +} diff --git a/test/Cpp/src/NativeListsAndTimes.lf b/test/Cpp/src/NativeListsAndTimes.lf index 205b8d6c34..91ced749bf 100644 --- a/test/Cpp/src/NativeListsAndTimes.lf +++ b/test/Cpp/src/NativeListsAndTimes.lf @@ -3,26 +3,26 @@ 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 - q:{=std::vector=}{1 msec, 2 msec, 3 msec}, // list of time values - r:time({=0=}), // Zero-valued target code also is a valid time - 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 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 times: std::vector>{q, g}; // a list of lists - reaction(tick) {= - // Target code - =} + 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:{=std::vector=}{1 msec, 2 msec, 3 msec}, // list of time values + r:time({=0=}), // Zero-valued target code also is a valid time + 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 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 times: std::vector>{q, g}; // a list of lists + reaction(tick) {= + // Target code + =} } main reactor NativeListsAndTimes { diff --git a/test/Cpp/src/SendingInside.lf b/test/Cpp/src/SendingInside.lf index 83bddff60b..9b1baad990 100644 --- a/test/Cpp/src/SendingInside.lf +++ b/test/Cpp/src/SendingInside.lf @@ -11,7 +11,7 @@ reactor Printer { std::cout << "Inside reactor received: " << *x.get() << std::endl; if (*x.get() != count) { std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); + exit(1); } count++; =} @@ -22,6 +22,6 @@ main reactor SendingInside { p = new Printer(); reaction(t) -> p.x {= count++; - p.x.set(count); + p.x.set(count); =} } diff --git a/test/Cpp/src/Stride.lf b/test/Cpp/src/Stride.lf index 652e6c42bf..a1c84d2e56 100644 --- a/test/Cpp/src/Stride.lf +++ b/test/Cpp/src/Stride.lf @@ -16,7 +16,7 @@ reactor Count(stride:int(1)) { reactor Display { input x:int; reaction(x) {= - std::cout << "Received " << *x.get() << std::endl; + std::cout << "Received " << *x.get() << std::endl; =} } main reactor Stride { diff --git a/test/Cpp/src/TimeLimit.lf b/test/Cpp/src/TimeLimit.lf index ccf388a1bf..9d0181e73c 100644 --- a/test/Cpp/src/TimeLimit.lf +++ b/test/Cpp/src/TimeLimit.lf @@ -4,40 +4,40 @@ // Correct output for this 1, 2, 3, 4. // Failure for this test is failing to halt or getting the wrong data. target Cpp { - fast: true, + fast: true, }; reactor Clock(offset:time(0), period:time(1 sec)) { - output y:int; - timer t(offset, period); - state count:int(0); - reaction(t) -> y {= - count++; - //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; - y.set(count); - =} + output y:int; + timer t(offset, period); + state count:int(0); + reaction(t) -> y {= + count++; + //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; + y.set(count); + =} } reactor Destination { - input x:int; - state s:int(1); - reaction(x) {= - //std::cout << "Received " << *x.get() << '\n'; - if (*x.get() != s) { - std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; - exit(1); - } - s++; - =} + input x:int; + state s:int(1); + reaction(x) {= + //std::cout << "Received " << *x.get() << '\n'; + if (*x.get() != s) { + std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; + exit(1); + } + s++; + =} } main reactor TimeLimit(period:time(100 usec)) { - timer stop(10 secs); - reaction(stop) {= - environment()->sync_shutdown(); - =} + timer stop(10 secs); + reaction(stop) {= + environment()->sync_shutdown(); + =} reaction(shutdown) {= std::cout << "**** shutdown reaction invoked.\n"; =} - c = new Clock(period = period); - d = new Destination(); - c.y -> d.x; + c = new Clock(period = period); + d = new Destination(); + c.y -> d.x; } diff --git a/test/Cpp/src/TimeState.lf b/test/Cpp/src/TimeState.lf index e5d7b1944a..4cd2061a55 100644 --- a/test/Cpp/src/TimeState.lf +++ b/test/Cpp/src/TimeState.lf @@ -1,13 +1,13 @@ target Cpp; reactor Foo(bar:time(42 msec)) { - state baz(bar); - - reaction (startup) {= - std::cout << "Baz: " << baz << std::endl; - =} + state baz(bar); + + reaction (startup) {= + std::cout << "Baz: " << baz << std::endl; + =} } main reactor { - a = new Foo(); + a = new Foo(); } diff --git a/test/Cpp/src/concurrent/HelloThreaded.lf b/test/Cpp/src/concurrent/HelloThreaded.lf index 02978bf896..a1aa6cc4e6 100644 --- a/test/Cpp/src/concurrent/HelloThreaded.lf +++ b/test/Cpp/src/concurrent/HelloThreaded.lf @@ -20,15 +20,15 @@ reactor HelloCpp(period:time(2 secs), message:{=std::string=}("Hello C++")) { std::cout << "Current time is " << previous_time << std::endl; =} reaction(a) {= - count++; - auto time = get_logical_time(); - std::cout << "***** action " << count << " at time " + count++; + auto time = get_logical_time(); + std::cout << "***** action " << count << " at time " << time << std::endl; - auto diff = time - previous_time; - if (diff != 200ms) { - std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " - << "but got " << diff << std::endl; - exit(1); + auto diff = time - previous_time; + if (diff != 200ms) { + std::cerr << "FAILURE: Expected 200 msecs of logical time to elapse " + << "but got " << diff << std::endl; + exit(1); } =} } diff --git a/test/Cpp/src/concurrent/SendingInsideThreaded.lf b/test/Cpp/src/concurrent/SendingInsideThreaded.lf index 78190a7ac2..1ba5ce6878 100644 --- a/test/Cpp/src/concurrent/SendingInsideThreaded.lf +++ b/test/Cpp/src/concurrent/SendingInsideThreaded.lf @@ -11,7 +11,7 @@ reactor Printer { std::cout << "Inside reactor received: " << *x.get() << std::endl; if (*x.get() != count) { std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); + exit(1); } count++; =} @@ -22,6 +22,6 @@ main reactor { p = new Printer(); reaction(t) -> p.x {= count++; - p.x.set(count); + p.x.set(count); =} } diff --git a/test/Cpp/src/concurrent/TimeLimitThreaded.lf b/test/Cpp/src/concurrent/TimeLimitThreaded.lf index 2697b40a95..bd97ac66db 100644 --- a/test/Cpp/src/concurrent/TimeLimitThreaded.lf +++ b/test/Cpp/src/concurrent/TimeLimitThreaded.lf @@ -4,40 +4,40 @@ // Correct output for this 1, 2, 3, 4. // Failure for this test is failing to halt or getting the wrong data. target Cpp { - fast: true + fast: true }; reactor Clock(offset:time(0), period:time(1 sec)) { - output y:int; - timer t(offset, period); - state count:int(0); - reaction(t) -> y {= - count++; - //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; - y.set(count); - =} + output y:int; + timer t(offset, period); + state count:int(0); + reaction(t) -> y {= + count++; + //std::cout << "Reacting at time " << get_elapsed_logical_time() << '\n'; + y.set(count); + =} } reactor Destination { - input x:int; - state s:int(1); - reaction(x) {= - //std::cout << "Received " << *x.get() << '\n'; - if (*x.get() != s) { - std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; - exit(1); - } - s++; - =} + input x:int; + state s:int(1); + reaction(x) {= + //std::cout << "Received " << *x.get() << '\n'; + if (*x.get() != s) { + std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; + exit(1); + } + s++; + =} } main reactor (period:time(100 usec)) { - timer stop(10 secs); - reaction(stop) {= - environment()->sync_shutdown(); - =} + timer stop(10 secs); + reaction(stop) {= + environment()->sync_shutdown(); + =} reaction(shutdown) {= std::cout << "**** shutdown reaction invoked.\n"; =} - c = new Clock(period = period); - d = new Destination(); - c.y -> d.x; + c = new Clock(period = period); + d = new Destination(); + c.y -> d.x; } diff --git a/test/Cpp/src/multiport/BankSelfBroadcast.lf b/test/Cpp/src/multiport/BankSelfBroadcast.lf index 5fa219dcc3..d2a2fad70b 100644 --- a/test/Cpp/src/multiport/BankSelfBroadcast.lf +++ b/test/Cpp/src/multiport/BankSelfBroadcast.lf @@ -18,19 +18,19 @@ reactor A(bank_index:size_t(0)) { reaction(in) {= for (size_t i = 0; i < in.size(); i++) { if (in[i].is_present()) { - std::cout << "Reactor " << bank_index << " received " - << *in[i].get() << " on channel " << i << '\n'; + std::cout << "Reactor " << bank_index << " received " + << *in[i].get() << " on channel " << i << '\n'; if (*in[i].get() != i) { std::cerr << "ERROR: Expected " << i << '\n'; exit(1); } received = true; - } else { + } else { std::cout << "Reactor " << bank_index << " channel " << i << " is absent.\n"; std::cerr << "ERROR: Expected " << i << '\n'; exit(1); } - } + } =} reaction(shutdown) {= if (!received) { diff --git a/test/Cpp/src/multiport/BankToBank.lf b/test/Cpp/src/multiport/BankToBank.lf index b1b05ae93b..1c82464b1e 100644 --- a/test/Cpp/src/multiport/BankToBank.lf +++ b/test/Cpp/src/multiport/BankToBank.lf @@ -4,26 +4,26 @@ target Cpp { fast: true }; reactor Source(bank_index:size_t(0)) { - timer t(0, 200 msec); - output out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output out:int; + state s:int(0); + reaction(t) -> out {= out.set(s); - s += bank_index; - =} + s += bank_index; + =} } reactor Destination(bank_index:size_t(0)) { - state s:int(0); - input in:int; - reaction(in) {= - std::cout << "Destination " << bank_index << " received: " << *in.get() << "\n"; - if (*in.get() != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += bank_index; - =} - reaction(shutdown) {= + state s:int(0); + input in:int; + reaction(in) {= + std::cout << "Destination " << bank_index << " received: " << *in.get() << "\n"; + if (*in.get() != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += bank_index; + =} + reaction(shutdown) {= if (s == 0 && bank_index != 0) { std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; exit(1); @@ -34,7 +34,7 @@ reactor Destination(bank_index:size_t(0)) { main reactor BankToBank(width:int(4)) { // FIXME: Should set the width to "width" rather than "4". - a = new[4] Source(); - b = new[4] Destination(); - a.out -> b.in; + a = new[4] Source(); + b = new[4] Destination(); + a.out -> b.in; } \ No newline at end of file diff --git a/test/Cpp/src/multiport/BankToBankMultiport.lf b/test/Cpp/src/multiport/BankToBankMultiport.lf index 68d19fb77d..f9965031c7 100644 --- a/test/Cpp/src/multiport/BankToBankMultiport.lf +++ b/test/Cpp/src/multiport/BankToBankMultiport.lf @@ -37,7 +37,7 @@ reactor Destination(width:size_t(1)) { =} } 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; + a = new[bank_width] Source(width = 4); + b = new[bank_width] Destination(width = 4); + a.out -> b.in; } \ No newline at end of file diff --git a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf index cb3ff849df..7ecc45100f 100644 --- a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf @@ -46,7 +46,7 @@ reactor Destination(width:size_t(1)) { =} } 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; -} \ No newline at end of file + 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/FullyConnected.lf b/test/Cpp/src/multiport/FullyConnected.lf index a235d6a29f..9c1809a705 100644 --- a/test/Cpp/src/multiport/FullyConnected.lf +++ b/test/Cpp/src/multiport/FullyConnected.lf @@ -8,16 +8,16 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { state received: bool{false}; reaction (startup) -> out{= - std::cout << "Hello from node " << bank_index << "!\n"; - // broadcast my ID to everyone - out.set(bank_index); + std::cout << "Hello from node " << bank_index << "!\n"; + // broadcast my ID to everyone + out.set(bank_index); =} reaction (in) {= std::cout << "Node " << bank_index << " received messages from "; received = true; size_t count{0}; - for (auto& port : in) { + for (auto& port : in) { if (port.is_present()) { count++; std::cout << *port.get() << ", "; @@ -40,4 +40,4 @@ reactor Node(bank_index: size_t(0), 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; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/FullyConnectedAddressable.lf b/test/Cpp/src/multiport/FullyConnectedAddressable.lf index 43ed3e2a3b..3ea46ae739 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressable.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressable.lf @@ -10,9 +10,9 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { state received: bool{false}; reaction (startup) -> out{= - std::cout << "Hello from node " << bank_index << "!\n"; - // send my ID only to my right neighbour - out[(bank_index + 1) % num_nodes].set(bank_index); + std::cout << "Hello from node " << bank_index << "!\n"; + // send my ID only to my right neighbour + out[(bank_index + 1) % num_nodes].set(bank_index); =} reaction (in) {= @@ -20,7 +20,7 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { received = true; size_t count{0}; size_t result{0}; - for (auto& port : in) { + for (auto& port : in) { if (port.is_present()) { count++; result = *port.get(); diff --git a/test/Cpp/src/multiport/MultiportFromHierarchy.lf b/test/Cpp/src/multiport/MultiportFromHierarchy.lf index 495799e2b3..1d2c392142 100644 --- a/test/Cpp/src/multiport/MultiportFromHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromHierarchy.lf @@ -4,31 +4,31 @@ target Cpp { fast: true }; reactor Source { - timer t(0, 200 msec); - output[4] out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[4] out:int; + state s:int(0); + reaction(t) -> out {= for(int i = 0; i < 4; i++) { out[i].set(s++); } - =} + =} } reactor Destination { - state s:int(6); - input[4] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in.size(); i++) { + state s:int(6); + input[4] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in.size(); i++) { if (in[i].is_present()) sum += *in[i].get(); } - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 16; - =} - reaction(shutdown) {= + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 16; + =} + reaction(shutdown) {= if (s <= 6) { std::cerr << "ERROR: Destination received no input!\n"; exit(1); @@ -49,7 +49,7 @@ reactor InsideContainer { } main reactor MultiportFromHierarchy { - a = new Container(); - b = new Destination(); - a.out -> b.in; + a = new Container(); + b = new Destination(); + a.out -> b.in; } \ No newline at end of file diff --git a/test/Cpp/src/multiport/MultiportIn.lf b/test/Cpp/src/multiport/MultiportIn.lf index 48975105e4..b08ab0c9c3 100644 --- a/test/Cpp/src/multiport/MultiportIn.lf +++ b/test/Cpp/src/multiport/MultiportIn.lf @@ -6,35 +6,35 @@ target Cpp { }; reactor Source { - timer t(0, 200 msec); - output out:int; - state s:int(0); - reaction(t) -> out {= - out.set(s++); - =} + timer t(0, 200 msec); + output out:int; + state s:int(0); + reaction(t) -> out {= + out.set(s++); + =} } reactor Computation { - input in:int; - output out:int; - reaction(in) -> out {= - out.set(*in.get()); - =} + input in:int; + output out:int; + reaction(in) -> out {= + out.set(*in.get()); + =} } reactor Destination { - state s:int(0); - input[4] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in.size(); i++) { - sum += *in[i].get(); + state s:int(0); + input[4] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in.size(); i++) { + sum += *in[i].get(); } - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 4; - =} + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 4; + =} reaction(shutdown) {= if (s == 0) { std::cerr << "ERROR: Destination received no input!\n"; @@ -45,15 +45,15 @@ reactor Destination { } main reactor MultiportIn { - a = new Source(); - t1 = new Computation(); - t2 = new Computation(); - t3 = new Computation(); - t4 = new Computation(); - b = new Destination(); - a.out -> t1.in; - a.out -> t2.in; - a.out -> t3.in; - a.out -> t4.in; - t1.out, t2.out, t3.out, t4.out -> b.in; + a = new Source(); + t1 = new Computation(); + t2 = new Computation(); + t3 = new Computation(); + t4 = new Computation(); + b = new Destination(); + a.out -> t1.in; + a.out -> t2.in; + a.out -> t3.in; + a.out -> t4.in; + t1.out, t2.out, t3.out, t4.out -> b.in; } \ No newline at end of file diff --git a/test/Cpp/src/multiport/MultiportOut.lf b/test/Cpp/src/multiport/MultiportOut.lf index 9db502973d..a7fbab7710 100644 --- a/test/Cpp/src/multiport/MultiportOut.lf +++ b/test/Cpp/src/multiport/MultiportOut.lf @@ -4,43 +4,43 @@ target Cpp { fast: true }; reactor Source { - timer t(0, 200 msec); - output[4] out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[4] out:int; + state s:int(0); + reaction(t) -> out {= for(int i = 0; i < 4; i++) { out[i].set(s); } - s++; - =} + s++; + =} } reactor Computation { - input in:int; - output out:int; - reaction(in) -> out {= + input in:int; + output out:int; + reaction(in) -> out {= // No need to sleep for this test. // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - out.set(*in.get()); - =} + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + out.set(*in.get()); + =} } reactor Destination { - state s:int(0); - input[4] in:int; - reaction(in) {= - int sum = 0; - for (int i = 0; i < in.size(); i++) { + state s:int(0); + input[4] in:int; + reaction(in) {= + int sum = 0; + for (int i = 0; i < in.size(); i++) { if (in[i].is_present()) sum += *in[i].get(); } - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 4; - =} - reaction(shutdown) {= + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 4; + =} + reaction(shutdown) {= if (s == 0) { std::cerr << "ERROR: Destination received no input!\n"; exit(1); @@ -50,12 +50,12 @@ reactor Destination { } main reactor { - a = new Source(); - t1 = new Computation(); - t2 = new Computation(); - t3 = new Computation(); - t4 = new Computation(); - b = new Destination(); - a.out -> t1.in, t2.in, t3.in, t4.in; - t1.out, t2.out, t3.out, t4.out -> b.in; + a = new Source(); + t1 = new Computation(); + t2 = new Computation(); + t3 = new Computation(); + t4 = new Computation(); + b = new Destination(); + a.out -> t1.in, t2.in, t3.in, t4.in; + t1.out, t2.out, t3.out, t4.out -> b.in; } diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index 17dca6304f..13f1f34804 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -5,31 +5,31 @@ target Cpp { fast: true }; reactor Source(width:size_t(4)) { - timer t(0, 200 msec); - output[width] out:int; - state s:int(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[width] out:int; + state s:int(0); + reaction(t) -> out {= for(size_t i = 0; i < 4; i++) { out[i].set(s++); } - =} + =} } reactor Destination(width:size_t(4)) { - state s:int(6); - input[width] in:int; - reaction(in) {= - int sum = 0; - for (size_t i = 0; i < in.size(); i++) { + state s:int(6); + input[width] in:int; + reaction(in) {= + int sum = 0; + for (size_t i = 0; i < in.size(); i++) { if (in[i].is_present()) sum += *in[i].get(); } - std::cout << "Sum of received: " << sum << ".\n"; - if (sum != s) { - std::cerr << "ERROR: Expected " << s << ".\n"; - exit(1); - } - s += 16; - =} - reaction(shutdown) {= + std::cout << "Sum of received: " << sum << ".\n"; + if (sum != s) { + std::cerr << "ERROR: Expected " << s << ".\n"; + exit(1); + } + s += 16; + =} + reaction(shutdown) {= if (s <= 6) { std::cerr << "ERROR: Destination received no input!\n"; exit(1); @@ -44,7 +44,7 @@ reactor Container(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; + a = new Source(width=width); + b = new Container(width=width); + a.out -> b.in; } \ No newline at end of file diff --git a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf index 098494a241..52aa04df9e 100644 --- a/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadMultiportOutputOfContainedBank.lf @@ -5,8 +5,8 @@ reactor Contained(bank_index:size_t(0)) { output[3] out:unsigned; reaction(startup) -> out {= for (size_t i = 0; i < 3; i++) { - out[i].set(bank_index * i); - } + out[i].set(bank_index * i); + } =} } @@ -16,41 +16,41 @@ main reactor { reaction(startup) c.out {= for (size_t i = 0; i < c.size(); i++) { for (size_t j = 0; j < c[i].out.size(); j++) { - unsigned result = *c[i].out[j].get(); - std::cout << "Startup reaction reading output of contained " - << "reactor: " << result << std::endl; - if (result != i * j) { - std::cout << "FAILURE: expected " << i * j << std::endl; - exit(2); - } - } + unsigned result = *c[i].out[j].get(); + std::cout << "Startup reaction reading output of contained " + << "reactor: " << result << std::endl; + if (result != i * j) { + std::cout << "FAILURE: expected " << i * j << std::endl; + exit(2); + } + } } count++; =} reaction(c.out) {= for (size_t i = 0; i < c.size(); i++) { for (size_t j = 0; j < c[i].out.size(); j++) { - unsigned result = *c[i].out[j].get(); - std::cout << "Reading output of contained reactor: " << result << std::endl; - if (result != i * j) { - std::cout << "FAILURE: expected " << i * j << std::endl; - exit(2); - } - } + unsigned result = *c[i].out[j].get(); + std::cout << "Reading output of contained reactor: " << result << std::endl; + if (result != i * j) { + std::cout << "FAILURE: expected " << i * j << std::endl; + exit(2); + } + } } count++; =} reaction(startup, c.out) {= for (size_t i = 0; i < c.size(); i++) { for (size_t j = 0; j < c[i].out.size(); j++) { - unsigned result = *c[i].out[j].get(); - std::cout << "Alternate triggering reading output of contained " - << "reactor: " << result << std::endl; - if (result != i * j) { - std::cout << "FAILURE: expected " << i * j << std::endl; - exit(2); - } - } + unsigned result = *c[i].out[j].get(); + std::cout << "Alternate triggering reading output of contained " + << "reactor: " << result << std::endl; + if (result != i * j) { + std::cout << "FAILURE: expected " << i * j << std::endl; + exit(2); + } + } } count++; =} diff --git a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf index 300d2b238c..8b08b4ca06 100644 --- a/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf +++ b/test/Cpp/src/multiport/ReadOutputOfContainedBank.lf @@ -14,23 +14,23 @@ main reactor { reaction(startup) c.out {= for (size_t i = 0; i < c.size(); i++) { unsigned result = *c[i].out.get(); - std::cout << "Startup reaction reading output of contained " - << "reactor: " << result << std::endl; - if (result != 42 * i) { - std::cout << "FAILURE: expected " << 42 * i << std::endl; - exit(2); - } + std::cout << "Startup reaction reading output of contained " + << "reactor: " << result << std::endl; + if (result != 42 * i) { + std::cout << "FAILURE: expected " << 42 * i << std::endl; + exit(2); + } } count++; =} reaction(c.out) {= for (size_t i = 0; i < c.size(); i++) { unsigned result = *c[i].out.get(); - std::cout << "Reading output of contained reactor: " << result + std::cout << "Reading output of contained reactor: " << result << std::endl; - if (result != 42 * i) { - std::cout << "FAILURE: expected " << 42 * i << std::endl; - exit(2); + if (result != 42 * i) { + std::cout << "FAILURE: expected " << 42 * i << std::endl; + exit(2); } } count++; @@ -38,11 +38,11 @@ main reactor { reaction(startup, c.out) {= for (size_t i = 0; i < c.size(); i++) { unsigned result = *c[i].out.get(); - std::cout << "Alternate triggering reading output of contained " - << "reactor: " << result << std::endl; - if (result != 42 * i) { - std::cout << "FAILURE: expected " << 42 * i << std::endl; - exit(2); + std::cout << "Alternate triggering reading output of contained " + << "reactor: " << result << std::endl; + if (result != 42 * i) { + std::cout << "FAILURE: expected " << 42 * i << std::endl; + exit(2); } } count++; diff --git a/test/Cpp/src/multiport/WidthGivenByCode.lf b/test/Cpp/src/multiport/WidthGivenByCode.lf index 40a24d043e..34cd5d5bb7 100644 --- a/test/Cpp/src/multiport/WidthGivenByCode.lf +++ b/test/Cpp/src/multiport/WidthGivenByCode.lf @@ -3,13 +3,13 @@ target Cpp reactor Foo(a: size_t{8}, b: size_t{2}) { input[{=a*b=}] in: size_t; output[{=a/b=}] out: size_t; - + reaction (startup) in -> out {= - if (in.size() != a*b){ + if (in.size() != a*b) { std::cerr << "ERROR: expected in to have a width of " << a*b << '\n'; exit(1); } - if (out.size() != a/b){ + if (out.size() != a/b) { std::cerr << "ERROR: expected out to have a width of " << a/b << '\n'; exit(2); } @@ -21,7 +21,7 @@ main reactor { foo2 = new Foo(a=10, b=3); foo3 = new Foo(a=9, b=9); foo_bank = new[{=42=}] Foo(); - + reaction (startup) foo_bank.out {= if (foo_bank.size() != 42) { std::cerr << "ERROR: expected foo_bank to have a width of " << 42 << '\n'; @@ -30,8 +30,8 @@ main reactor { for (auto& foo : foo_bank) { if (foo.out.size() != 4) { std::cerr << "ERROR: expected foo_bank.out to have a width of " << 4 << '\n'; - exit(4); + exit(4); } } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf index 985631cabb..4d2c95b093 100644 --- a/test/Cpp/src/multiport/WriteInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteInputOfContainedBank.lf @@ -26,5 +26,5 @@ main reactor { for (size_t i = 0; i < c.size(); i++) { c[i].in.set(i*42); } - =} + =} } diff --git a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf index 9b45cb62e1..6ea717db95 100644 --- a/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf +++ b/test/Cpp/src/multiport/WriteMultiportInputOfContainedBank.lf @@ -5,12 +5,12 @@ reactor Contained(bank_index:size_t(0)) { state count:int(0); reaction(in) {= for (size_t i = 0; i < 3; i++) { - unsigned result = *in[i].get(); - std::cout << "Instance " << bank_index << " received " << result << '\n'; - if (result != bank_index * i) { - std::cout << "FAILURE: expected " << i * bank_index << '\n'; - exit(2); - } + unsigned result = *in[i].get(); + std::cout << "Instance " << bank_index << " received " << result << '\n'; + if (result != bank_index * i) { + std::cout << "FAILURE: expected " << i * bank_index << '\n'; + exit(2); + } } count++; =} @@ -27,8 +27,8 @@ main reactor { reaction(startup) -> c.in {= for (size_t i = 0; i < c.size(); i++) { for (size_t j = 0; j < c[i].in.size(); j++) { - c[i].in[j].set(i*j); - } + c[i].in[j].set(i*j); + } } - =} + =} } diff --git a/test/Cpp/src/target/Methods.lf b/test/Cpp/src/target/Methods.lf index f9c063def3..8d375fd7ad 100644 --- a/test/Cpp/src/target/Methods.lf +++ b/test/Cpp/src/target/Methods.lf @@ -1,24 +1,24 @@ target Cpp; main reactor { - - state foo:int(2); - - const method getFoo(): int {= - return foo; - =} - - method add(x:int) {= + + state foo:int(2); + + const method getFoo(): int {= + return foo; + =} + + method add(x:int) {= foo += x; =} - + reaction(startup){= std::cout << "Foo is initialized to " << getFoo() << '\n'; if (getFoo() != 2) { std::cerr << "Error: expected 2!\n"; exit(1); } - + add(40); std::cout << "2 + 40 = " << getFoo() << '\n'; if (getFoo() != 42) { diff --git a/test/Python/src/ActionDelay.lf b/test/Python/src/ActionDelay.lf index 800c126e79..861fa3ed0c 100644 --- a/test/Python/src/ActionDelay.lf +++ b/test/Python/src/ActionDelay.lf @@ -23,8 +23,8 @@ reactor Source { =} } reactor Sink { - input _in; - reaction(_in) {= + input _in; + reaction(_in) {= elapsed_logical = lf.time.logical_elapsed() logical = lf.time.logical() physical = lf.time.physical() @@ -34,7 +34,7 @@ reactor Sink { exit(1) else: print("SUCCESS. Elapsed logical time is 100 msec.\n") - =} + =} } main reactor ActionDelay { source = new Source(); diff --git a/test/Python/src/Composition.lf b/test/Python/src/Composition.lf index 95ebb7db5b..02e8384ca7 100644 --- a/test/Python/src/Composition.lf +++ b/test/Python/src/Composition.lf @@ -6,35 +6,35 @@ target Python { }; reactor Source(period(2 sec)) { - output y; - timer t(1 sec, period); - state count(0); - reaction(t) -> y {= + output y; + timer t(1 sec, period); + state count(0); + reaction(t) -> y {= self.count += 1 print("Source sending " + str(self.count)) #print("y value is " + str(y.value)) y.set(self.count) - =} + =} } reactor Test { - input x; - state count(0); - reaction(x) {= + input x; + state count(0); + reaction(x) {= self.count += 1 print("Recieved " + str(x.value)) if (x.value != self.count): sys.stderr.write("FAILURE: Expected " + str(self.count) + "\n") exit(1) - =} - reaction(shutdown) {= + =} + reaction(shutdown) {= if(self.count == 0): sys.stderr.write("FAILURE: No data received.\n") - =} + =} } main reactor Composition { - s = new Source(); - - d = new Test(); - s.y -> d.x; + s = new Source(); + + d = new Test(); + s.y -> d.x; } diff --git a/test/Python/src/CompositionAfter.lf b/test/Python/src/CompositionAfter.lf index fe015379b3..e3b671349f 100644 --- a/test/Python/src/CompositionAfter.lf +++ b/test/Python/src/CompositionAfter.lf @@ -1,33 +1,33 @@ // This test connects a simple counting source to tester // that checks against its own count. target Python { - fast: true, - timeout: 10 sec + fast: true, + timeout: 10 sec }; reactor Source(period(2 sec)) { - output y; - timer t(1 sec, period); - state count(0); - reaction(t) -> y {= - self.count += 1 - y.set(self.count) - =} + output y; + timer t(1 sec, period); + state count(0); + reaction(t) -> y {= + self.count += 1 + y.set(self.count) + =} } reactor Test { - input x; - state count(0); - reaction(x) {= - self.count += 1 - print("Received ", x.value) - if x.value != self.count: - sys.stderr.write("FAILURE: Expected %d\n", self.count) - exit(1) - =} + input x; + state count(0); + reaction(x) {= + self.count += 1 + print("Received ", x.value) + if x.value != self.count: + sys.stderr.write("FAILURE: Expected %d\n", self.count) + exit(1) + =} } main reactor(delay(5 sec)) { - s = new Source(); - d = new Test(); - s.y -> d.x after delay; + s = new Source(); + d = new Test(); + s.y -> d.x after delay; } \ No newline at end of file diff --git a/test/Python/src/CompositionInheritance.lf b/test/Python/src/CompositionInheritance.lf index 530041a661..79376d8460 100644 --- a/test/Python/src/CompositionInheritance.lf +++ b/test/Python/src/CompositionInheritance.lf @@ -6,43 +6,43 @@ target Python { }; reactor Source(period(2 sec)) { input foo; - output y; - timer t(1 sec, period); - state count(0); - reaction(t) -> y {= - print("Hello World. My count is: ", self.count) - y.set(self.count) - =} + output y; + timer t(1 sec, period); + state count(0); + reaction(t) -> y {= + print("Hello World. My count is: ", self.count) + y.set(self.count) + =} } reactor SourceExtended extends Source { - output y2; - timer t2(1 sec, 3 sec); - reaction(t2) -> y2 {= - self.count += 1 - print("Source sending ", self.count) - y2.set(self.count) - =} + output y2; + timer t2(1 sec, 3 sec); + reaction(t2) -> y2 {= + self.count += 1 + print("Source sending ", self.count) + y2.set(self.count) + =} } reactor Test { - input x; - state count(0); - reaction(x) {= - self.count += 1 - print("Received ", x.value) - if x.value != self.count: - sys.stderr.write("FAILURE: Expected %d\n", self.count) - exit(1) - =} - reaction(shutdown) {= - if self.count == 0: - sys.stderr.write("FAILURE: No data received.\n") - =} + input x; + state count(0); + reaction(x) {= + self.count += 1 + print("Received ", x.value) + if x.value != self.count: + sys.stderr.write("FAILURE: Expected %d\n", self.count) + exit(1) + =} + reaction(shutdown) {= + if self.count == 0: + sys.stderr.write("FAILURE: No data received.\n") + =} } main reactor { - s = new SourceExtended(); - - d = new Test(); - s.y2 -> d.x; + s = new SourceExtended(); + + d = new Test(); + s.y2 -> d.x; } \ No newline at end of file diff --git a/test/Python/src/DelayedReaction.lf b/test/Python/src/DelayedReaction.lf index 733bec5ff4..7fd329abd6 100644 --- a/test/Python/src/DelayedReaction.lf +++ b/test/Python/src/DelayedReaction.lf @@ -15,7 +15,7 @@ reactor Sink { print("Nanoseconds since start: ", elapsed) if elapsed != 100000000: sys.stderr.write("ERROR: Expected 100000000 but.\n") - exit(1) + exit(1) =} } main reactor DelayedReaction { diff --git a/test/Python/src/DoubleReaction.lf b/test/Python/src/DoubleReaction.lf index c801d49780..5f16ff6329 100644 --- a/test/Python/src/DoubleReaction.lf +++ b/test/Python/src/DoubleReaction.lf @@ -2,8 +2,8 @@ // trigger it only once. // Correct output for this 2, 4, 6, 8, etc. target Python { - timeout: 10 sec, - fast: true + timeout: 10 sec, + fast: true }; reactor Clock(offset(0), period(1 sec)) { output y; @@ -38,4 +38,4 @@ main reactor DoubleReaction { d = new Destination(); c1.y -> d.x; c2.y -> d.w; -} \ No newline at end of file +} diff --git a/test/Python/src/Hello.lf b/test/Python/src/Hello.lf index f2ed3645e3..8a267db465 100644 --- a/test/Python/src/Hello.lf +++ b/test/Python/src/Hello.lf @@ -35,10 +35,10 @@ reactor Reschedule(period(2 secs), message("Hello Python")) { =} } reactor Inside(period(1 sec), message("Composite default message.")) { - third_instance = new Reschedule(period = period, message = message); + third_instance = new Reschedule(period = period, message = message); } main reactor Hello { - first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); - second_instance = new Reschedule(message = "Hello from second_instance."); - composite_instance = new Inside(message = "Hello from composite_instance."); + first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); + second_instance = new Reschedule(message = "Hello from second_instance."); + composite_instance = new Inside(message = "Hello from composite_instance."); } \ No newline at end of file diff --git a/test/Python/src/ImportRenamed.lf b/test/Python/src/ImportRenamed.lf index c178d18bf9..f22d290f75 100644 --- a/test/Python/src/ImportRenamed.lf +++ b/test/Python/src/ImportRenamed.lf @@ -5,12 +5,12 @@ import Imported as X from "lib/Imported.lf" import Imported as Y from "lib/Imported.lf" import ImportedAgain as Z from "lib/ImportedAgain.lf" main reactor { - timer t; - a = new X(); - b = new Y(); - c = new Z(); - - reaction(t) -> a.x {= - a.x.set(42) - =} + timer t; + a = new X(); + b = new Y(); + c = new Z(); + + reaction(t) -> a.x {= + a.x.set(42) + =} } diff --git a/test/Python/src/PeriodicDesugared.lf b/test/Python/src/PeriodicDesugared.lf index 0bf7c65cf2..6fabc32710 100644 --- a/test/Python/src/PeriodicDesugared.lf +++ b/test/Python/src/PeriodicDesugared.lf @@ -12,7 +12,7 @@ main reactor( reaction(startup) -> init, recur {= if self.offset == 0: print("Hello World!") - recur.schedule(0) + recur.schedule(0) else: init.schedule(0) =} diff --git a/test/Python/src/Pipeline.lf b/test/Python/src/Pipeline.lf index d5351841d8..f0bb80c33d 100644 --- a/test/Python/src/Pipeline.lf +++ b/test/Python/src/Pipeline.lf @@ -3,16 +3,16 @@ target Python { }; reactor TakeTime { - input _in; - output out; - reaction(_in) -> out {= + input _in; + output out; + reaction(_in) -> out {= offset = 0 for i in range(10000): offset+=1 out.set(_in.value + offset) - =} + =} } reactor Print { diff --git a/test/Python/src/concurrent/AsyncCallback.lf b/test/Python/src/concurrent/AsyncCallback.lf index 559c4e89c8..f346e1c35e 100644 --- a/test/Python/src/concurrent/AsyncCallback.lf +++ b/test/Python/src/concurrent/AsyncCallback.lf @@ -4,12 +4,12 @@ * schedule a physical action twice. */ target Python { - timeout: 2 sec + timeout: 2 sec }; main reactor AsyncCallback { - - preamble {= + + preamble {= # Note that preamble code is generated inside the reactor class in Python import time import threading @@ -29,24 +29,23 @@ main reactor AsyncCallback { self.time.sleep(0.1) self.callback(a) return None - - =} - timer t(0, 200 msec); - state threads({=list()=}); - state expected_time(100 msec); - state toggle(false); - + =} + timer t(0, 200 msec); + state threads({=list()=}); + state expected_time(100 msec); + state toggle(false); + physical action a(100 msec); state i(0); - - reaction(t) -> a {= + + reaction(t) -> a {= # start new thread, provide callback x = self.threading.Thread(target=self.take_time, args=(a,)) self.threads.append(x) x.start() - =} - - reaction(a) {= + =} + + reaction(a) {= elapsed_time = lf.time.logical_elapsed() print("Asynchronous callback {:d}: Assigned logical time greater than start time by {:d} nsec.".format(self.i, elapsed_time)); self.i += 1 @@ -58,5 +57,5 @@ main reactor AsyncCallback { self.expected_time += 200000000 else: self.toggle = True - =} -} \ No newline at end of file + =} +} diff --git a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf index 30c1ccb60b..272047184d 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf @@ -25,11 +25,11 @@ reactor Sender(take_a_break_after(10), break_interval(550 msec)) { out.set(self.sent_messages) self.sent_messages += 1 if self.sent_messages < self.take_a_break_after: - act.schedule(0) + act.schedule(0) else: # Take a break - self.sent_messages = 0 - act.schedule(self.break_interval) + self.sent_messages = 0 + act.schedule(self.break_interval) =} } @@ -49,8 +49,7 @@ reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { reaction(startup) {= self.base_logical_time = lf.time.logical() =} - - + reaction(in_) {= current_tag = get_current_tag() print("At tag ({}, {}) received {}".format( @@ -69,11 +68,11 @@ reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { self.breaks += 1 self.received_messages = 0 =} - + reaction(t) {= # Do nothing =} - + reaction(shutdown) {= if self.breaks != 2 or (self.total_received_messages != ((SEC(1)//self.break_interval)+1) * self.take_a_break_after): self.sys.stderr.write("Test failed. Breaks: {}, Messages: {}.".format(self.breaks, self.total_received_messages)) @@ -82,10 +81,9 @@ reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { =} } - federated reactor DistributedLoopedPhysicalAction { sender = new Sender(); receiver = new Receiver(); sender.out -> receiver.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index 85dece070d..beaa07b7fc 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -1,9 +1,9 @@ - /** - * Test for request_stop() in federated execution with centralized coordination. - * - * @author Soroush Bateni - */ - +/** +* Test for request_stop() in federated execution with centralized coordination. +* +* @author Soroush Bateni +*/ + target Python; preamble {= @@ -25,7 +25,7 @@ reactor Sender { # for 'act' like Stop.lf, we trigger the # same reaction to test request_stop() being # called multiple times - act.schedule(0) + act.schedule(0) if lf.time.logical_elapsed() == USEC(1): # Call request_stop() both at (1 usec, 0) and # (1 usec, 1) @@ -33,17 +33,17 @@ reactor Sender { lf.time.logical_elapsed(), get_microstep())) request_stop() - + _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) if lf.tag_compare(get_current_tag(), _1usec1) == 0: # The reaction was invoked at (1 usec, 1) as expected - self.reaction_invoked_correctly = True + self.reaction_invoked_correctly = True elif lf.tag_compare(get_current_tag(), _1usec1) > 0: # The reaction should not have been invoked at tags larger than (1 usec, 1) sys.stderr.write("ERROR: Invoked reaction(t, act) at tag bigger than shutdown.\n") sys.exit(1) =} - + reaction(shutdown) {= if lf.time.logical_elapsed() != USEC(1) or get_microstep() != 1: sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( @@ -76,13 +76,13 @@ reactor Receiver ( lf.time.logical_elapsed(), get_microstep())) request_stop() - # The receiver should receive a message at tag - # (1 usec, 1) and trigger this reaction + # The receiver should receive a message at tag + # (1 usec, 1) and trigger this reaction self.reaction_invoked_correctly = True _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) if lf.tag_compare(get_current_tag(), _1usec1) > 0: - self.reaction_invoked_correctly = False + self.reaction_invoked_correctly = False =} reaction(shutdown) {= @@ -108,6 +108,6 @@ reactor Receiver ( federated reactor DistributedStop { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf b/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf index 456b55cff1..b09d0a00a0 100644 --- a/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf +++ b/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf @@ -1,10 +1,10 @@ - /** - * Test a form of a distributed deterministic system - * where a federate that receives timestamped messages has a timer in addition to the messages - * as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. - * @author Edward A. Lee - * @author Soroush Bateni - */ +/** +* Test a form of a distributed deterministic system +* where a federate that receives timestamped messages has a timer in addition to the messages +* as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. +* @author Edward A. Lee +* @author Soroush Bateni +*/ target Python { timeout: 4900 msec, coordination: decentralized @@ -44,17 +44,17 @@ reactor Print { current_tag = get_current_tag() print("At tag ({}, {}), message has violated the STP offset by ({}, {}).".format( current_tag.time - start_time, current_tag.microstep, - current_tag.time - in_.intended_tag.time, - current_tag.microstep - in_.intended_tag.microstep - ) - ) + current_tag.time - in_.intended_tag.time, + current_tag.microstep - in_.intended_tag.microstep + ) + ) self.success_stp_violation += 1 self.c += 1 =} reaction(t) {= // Do nothing. =} - + reaction(shutdown) {= if self.success + self.success_stp_violation != 5: self.sys.stderr.write("Failed to detect STP violations in messages.\n") diff --git a/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf index 82605c16f8..fa15f32276 100644 --- a/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf @@ -42,8 +42,8 @@ reactor ImportantActuator { =} STP (0) {= tag_t current_tag = get_current_tag(); printf("Message violated STP offset by (%lld, %u).\n", - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep); + current_tag.time - in->intended_tag.time, + current_tag.microstep - in->intended_tag.microstep); self->success_stp_violation++; self->c++; =} diff --git a/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf b/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf index bb99a0d8dc..e675cac98e 100644 --- a/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf +++ b/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf @@ -105,9 +105,9 @@ reactor STPReceiver(take_a_break_after:int(10), break_interval:time(400 msec), s // time step. if (current_tag.time != self->last_time_updated_stp) { info_print("Raising the STP offset by %lld.", MSEC(10)); - self->stp_offset += MSEC(10); - set_stp_offset(MSEC(10)); - self->last_time_updated_stp = current_tag.time; + self->stp_offset += MSEC(10); + set_stp_offset(MSEC(10)); + self->last_time_updated_stp = current_tag.time; } =} diff --git a/test/Python/src/federated/failing/LoopDistributedDouble.lf b/test/Python/src/federated/failing/LoopDistributedDouble.lf index 4e28fbe530..040781ef90 100644 --- a/test/Python/src/federated/failing/LoopDistributedDouble.lf +++ b/test/Python/src/federated/failing/LoopDistributedDouble.lf @@ -41,8 +41,8 @@ reactor Looper(incr(1), delay(0 msec)) { =} reaction(a) -> out, out2 {= if (self->count%2 == 0) { - SET(out, self->count); - } else { + SET(out, self->count); + } else { SET(out2, self->count); } self->count += self->incr; diff --git a/test/Python/src/federated/failing/PhysicalSTP.lf b/test/Python/src/federated/failing/PhysicalSTP.lf index 6e3903f416..ddea2eef7a 100644 --- a/test/Python/src/federated/failing/PhysicalSTP.lf +++ b/test/Python/src/federated/failing/PhysicalSTP.lf @@ -9,7 +9,7 @@ target Python { timeout: 1900 msec, coordination: decentralized }; - + import Count from "../lib/Count.lf"; reactor Print (STP_offset_param(0)) { @@ -27,7 +27,7 @@ reactor Print (STP_offset_param(0)) { STP_discrepency = lf.time.logical() + self.STP_offset_param - in_.physical_time_of_arrival if STP_discrepency < 0: print("The message has violated the STP offset by {} in physical time.".format(-1 * STP_discrepency)) - self.c += 1 + self.c += 1 else: self.sys.stderr.write("Message arrived {} early.\n".format(STP_discrepency)) self.sys.exit(1) @@ -47,6 +47,6 @@ reactor Print (STP_offset_param(0)) { federated reactor { c = new Count(offset = 1 msec, period = 1 sec); p = new Print(STP_offset_param = 1 usec); - + c.out -> p.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/lib/LoopedActionSender.lf b/test/Python/src/lib/LoopedActionSender.lf index 5a2da44e66..f04ddf896c 100644 --- a/test/Python/src/lib/LoopedActionSender.lf +++ b/test/Python/src/lib/LoopedActionSender.lf @@ -1,4 +1,4 @@ -/** +/** * A sender reactor that outputs integers * in superdense time. * @@ -21,11 +21,11 @@ reactor Sender(take_a_break_after(10), break_interval(400 msec)) { out.set(self.sent_messages) self.sent_messages += 1 if self.sent_messages < self.take_a_break_after: - act.schedule(0) + act.schedule(0) else: # Take a break - self.sent_messages=0; - act.schedule(self.break_interval) + self.sent_messages=0; + act.schedule(self.break_interval) =} } \ No newline at end of file diff --git a/test/Python/src/modal_models/ModalNestedReactions.lf b/test/Python/src/modal_models/ModalNestedReactions.lf index 5f134ea33f..eb74985354 100644 --- a/test/Python/src/modal_models/ModalNestedReactions.lf +++ b/test/Python/src/modal_models/ModalNestedReactions.lf @@ -8,39 +8,39 @@ target Python { } reactor CounterCycle { - input next - + input next + output count output only_in_two - output never - + output never + initial mode One { - reaction(next) -> count, Two {= + reaction(next) -> count, Two {= count.set(1) Two.set() - =} + =} } mode Two { - fwd = new Forward() - next -> fwd.inp - fwd.out -> only_in_two - - reaction(next) -> count, One {= + fwd = new Forward() + next -> fwd.inp + fwd.out -> only_in_two + + reaction(next) -> count, One {= count.set(2) One.set() - =} + =} } mode Three { - reaction(next) -> never {= + reaction(next) -> never {= never.set(True) - =} + =} } } reactor Forward { input inp output out - + reaction(inp) -> out {= out.set(inp.value) =} @@ -49,7 +49,7 @@ reactor Forward { main reactor { timer stepper(0, 250msec) counter = new CounterCycle() - + // Trigger reaction(stepper) -> counter.next {= counter.next.set(True) @@ -69,7 +69,7 @@ main reactor { sys.stderr.write("ERROR: Missing output from indirectly nested reaction.\n") exit(3) =} - + reaction(counter.never) {= sys.stderr.write("ERROR: Detected output from unreachable mode.\n") exit(4) diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf index ab4d032b91..335b3abd23 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -11,24 +11,24 @@ target Python { import TraceTesting from "util/TraceTesting.lf" reactor Modal { - input next - output count - + input next + output count + initial mode One { - counter1 = new Counter(period=250msec) - counter1.value -> count - - reaction(next) -> Two {= + counter1 = new Counter(period=250msec) + counter1.value -> count + + reaction(next) -> Two {= Two.set() - =} + =} } mode Two { - counter2 = new Counter(period=100msec) - counter2.value -> count - - reaction(next) -> continue(One) {= + counter2 = new Counter(period=100msec) + counter2.value -> count + + reaction(next) -> continue(One) {= One.set() - =} + =} } } @@ -74,12 +74,12 @@ main reactor { reaction(stepper) -> modal.next {= modal.next.set(True) =} - + // Print reaction(modal.count) {= print(modal.count.value) =} - + modal.count -> test.events } diff --git a/test/Python/src/multiport/BankToBank.lf b/test/Python/src/multiport/BankToBank.lf index 0f05000440..ed451b26b6 100644 --- a/test/Python/src/multiport/BankToBank.lf +++ b/test/Python/src/multiport/BankToBank.lf @@ -6,27 +6,27 @@ target Python { reactor Source( bank_index(0) ) { - timer t(0, 200 msec); - output out; - state s(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output out; + state s(0); + reaction(t) -> out {= out.set(self.s) self.s += self.bank_index - =} + =} } reactor Destination( bank_index(0) ) { - state s(0); - input _in; - reaction(_in) {= + state s(0); + input _in; + reaction(_in) {= print("Destination " + str(self.bank_index) + " received: " + str(_in.value)) if (_in.value != self.s): sys.stderr.write("ERROR: Expected " + str(self.s)) exit(1) self.s += self.bank_index - =} - reaction(shutdown) {= + =} + reaction(shutdown) {= if self.s == 0 and self.bank_index != 0: sys.stderr.write("ERROR: Destination " + self.bank_index + " received no input!") exit(1) @@ -35,7 +35,7 @@ reactor Destination( } main reactor BankToBank(width(4)) { - a = new[width] Source(); - b = new[width] Destination(); - a.out -> b._in; + 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 0459862424..e86994369d 100644 --- a/test/Python/src/multiport/BankToBankMultiport.lf +++ b/test/Python/src/multiport/BankToBankMultiport.lf @@ -38,7 +38,7 @@ reactor Destination(width(1)) { =} } main reactor BankToBankMultiport(bank_width(4)) { - a = new[bank_width] Source(width = 4); - b = new[bank_width] Destination(width = 4); - a.out -> b._in; + 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 279a65c517..d9ddcd280d 100644 --- a/test/Python/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Python/src/multiport/BankToBankMultiportAfter.lf @@ -5,7 +5,7 @@ target Python { }; import Source, Destination from "BankToBankMultiport.lf" 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; + 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/ReactionsToNested.lf b/test/Python/src/multiport/ReactionsToNested.lf index f2ee46b355..8a5d4e6c45 100644 --- a/test/Python/src/multiport/ReactionsToNested.lf +++ b/test/Python/src/multiport/ReactionsToNested.lf @@ -6,14 +6,14 @@ target Python { reactor T(expected(0)) { input z; state received(false); - reaction(z) {= - print(f"T received {z.value}.") - self.received = True - if z.value != self.expected: + reaction(z) {= + print(f"T received {z.value}.") + self.received = True + if z.value != self.expected: sys.stderr.write(f"ERROR: Expected {self.response}") exit(1) - =} - reaction(shutdown) {= + =} + reaction(shutdown) {= if self.received is not True: sys.stderr.write(f"ERROR: No input received.") exit(1) @@ -35,4 +35,4 @@ main reactor { reaction(startup) -> d.y {= d.y[1].set(43) =} -} \ No newline at end of file +} diff --git a/test/Python/src/serialization/PersonProtocolBuffers.lf b/test/Python/src/serialization/PersonProtocolBuffers.lf index 18f1932f98..5bed7c3adf 100644 --- a/test/Python/src/serialization/PersonProtocolBuffers.lf +++ b/test/Python/src/serialization/PersonProtocolBuffers.lf @@ -23,7 +23,7 @@ target Python {protobufs: Person.proto}; main reactor { - reaction(startup) {= + reaction(startup) {= person = Person.Person() person.name = "Lingua Franca" @@ -39,5 +39,5 @@ main reactor { # Extract and print the unpacked message. print("Name: ", unpacked.name) - =} -} \ No newline at end of file + =} +} diff --git a/test/Python/src/serialization/ProtoNoPacking.lf b/test/Python/src/serialization/ProtoNoPacking.lf index eebd5cdb9d..f294cbdf87 100644 --- a/test/Python/src/serialization/ProtoNoPacking.lf +++ b/test/Python/src/serialization/ProtoNoPacking.lf @@ -38,7 +38,7 @@ reactor SinkProto { } main reactor ProtoNoPacking { - s = new SourceProto(); - d = new SinkProto(); - s.out -> d._in; + s = new SourceProto(); + d = new SinkProto(); + s.out -> d._in; } diff --git a/test/Rust/src/NativeListsAndTimes.lf b/test/Rust/src/NativeListsAndTimes.lf index 9991f41d37..a702d8f265 100644 --- a/test/Rust/src/NativeListsAndTimes.lf +++ b/test/Rust/src/NativeListsAndTimes.lf @@ -11,7 +11,7 @@ reactor Foo(x: i32(0), // todo // p2: i32[](1), // List of integers with single element // p3: i32[](), // Empty list of integers q: Vec (1 msec, 2 msec, 3 msec), // List of time values - g: time[](1 msec, 2 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 diff --git a/test/Rust/src/TimeState.lf b/test/Rust/src/TimeState.lf index 751e426064..a6e80d095e 100644 --- a/test/Rust/src/TimeState.lf +++ b/test/Rust/src/TimeState.lf @@ -1,13 +1,13 @@ target Rust; reactor Foo { - state baz: time(500 msec); - - reaction (startup) {= + state baz: time(500 msec); + + reaction (startup) {= assert_eq!(500, self.baz.as_millis()); - =} + =} } main reactor TimeState { - a = new Foo(); + a = new Foo(); } diff --git a/test/Rust/src/multiport/FullyConnectedAddressable.lf b/test/Rust/src/multiport/FullyConnectedAddressable.lf index 49d84a6658..1da11f65cb 100644 --- a/test/Rust/src/multiport/FullyConnectedAddressable.lf +++ b/test/Rust/src/multiport/FullyConnectedAddressable.lf @@ -13,7 +13,7 @@ reactor Node(bank_index: usize(0), num_nodes: usize(4)) { reaction (startup) -> out{= println!("Hello from node {}!", self.bank_index); - // send my ID only to my right neighbour + // send my ID only to my right neighbour ctx.set(out.get((self.bank_index + 1) % self.num_nodes), self.bank_index); =} @@ -22,7 +22,7 @@ reactor Node(bank_index: usize(0), num_nodes: usize(4)) { self.received = true; let mut count = 0; let mut result = 0; - for port in inpt { + for port in inpt { if let Some(v) = ctx.get(&port) { count += 1; result = v; @@ -50,4 +50,4 @@ main reactor(num_nodes: usize(4)) { nodes2 = new[num_nodes] Node(num_nodes=num_nodes); interleaved(nodes2.out) -> nodes2.inpt; -} \ No newline at end of file +} diff --git a/test/Rust/src/multiport/MultiportOut.lf b/test/Rust/src/multiport/MultiportOut.lf index bfb290cfb0..234481b82c 100644 --- a/test/Rust/src/multiport/MultiportOut.lf +++ b/test/Rust/src/multiport/MultiportOut.lf @@ -1,34 +1,34 @@ // Check multiport capabilities on Outputs. target Rust { timeout: 2 sec, -}; +}; reactor Source { - timer t(0, 200 msec); - output[4] out: u32; - state s: u32(0); - reaction(t) -> out {= + timer t(0, 200 msec); + output[4] out: u32; + state s: u32(0); + reaction(t) -> out {= for i in 0..out.len() { ctx.set(out.get(i), self.s); } - self.s += 1; - =} + self.s += 1; + =} } reactor Computation { - input in: u32; - output out: u32; - reaction(in) -> out {= + input in: u32; + output out: u32; + reaction(in) -> out {= // No need to sleep for this test. // struct timespec sleep_time = {(time_t) 0, (long)200000000}; - // struct timespec remaining_time; - // nanosleep(&sleep_time, &remaining_time); - ctx.set(out, ctx.get(r#in).unwrap()); - =} + // struct timespec remaining_time; + // nanosleep(&sleep_time, &remaining_time); + ctx.set(out, ctx.get(r#in).unwrap()); + =} } reactor Destination { - state s: u32(0); - input[4] in: u32; - reaction(in) {= - let mut sum = 0; + state s: u32(0); + input[4] in: u32; + reaction(in) {= + let mut sum = 0; for channel in r#in { if let Some(ci) = ctx.get(&channel) { sum += ci; @@ -37,20 +37,20 @@ reactor Destination { println!("Sum of received: {}", sum); assert_eq!(sum, self.s); self.s += 4; - =} - reaction(shutdown) {= + =} + reaction(shutdown) {= assert_ne!(0, self.s); println!("Success"); =} } main reactor { - a = new Source(); - t1 = new Computation(); - t2 = new Computation(); - t3 = new Computation(); - t4 = new Computation(); - b = new Destination(); - a.out -> t1.in, t2.in, t3.in, t4.in; - t1.out, t2.out, t3.out, t4.out -> b.in; + a = new Source(); + t1 = new Computation(); + t2 = new Computation(); + t3 = new Computation(); + t4 = new Computation(); + b = new Destination(); + a.out -> t1.in, t2.in, t3.in, t4.in; + t1.out, t2.out, t3.out, t4.out -> b.in; } diff --git a/test/Rust/src/target/CliFeature.lf b/test/Rust/src/target/CliFeature.lf index c53b9e62d1..96228bf9b4 100644 --- a/test/Rust/src/target/CliFeature.lf +++ b/test/Rust/src/target/CliFeature.lf @@ -1,5 +1,5 @@ target Rust { - build-type: Release, + build-type: Release, cargo-features: ["cli"] }; diff --git a/test/TypeScript/src/DelayedReaction.lf b/test/TypeScript/src/DelayedReaction.lf index 0d467ba471..6502ff5182 100644 --- a/test/TypeScript/src/DelayedReaction.lf +++ b/test/TypeScript/src/DelayedReaction.lf @@ -10,14 +10,14 @@ reactor Source { } reactor Sink { - input x:number; - reaction(x) {= + input x:number; + reaction(x) {= let elapsed = util.getElapsedLogicalTime(); console.log("Nanoseconds since start: " + elapsed); if (! elapsed.isEqualTo(TimeValue.msec(100))) { util.requestErrorStop("ERROR: Expected 100 msecs but got" + elapsed) } - =} + =} } main reactor DelayedReaction { source = new Source(); diff --git a/test/TypeScript/src/DoubleTrigger.lf b/test/TypeScript/src/DoubleTrigger.lf index 58496ff6d1..cf8f76572d 100644 --- a/test/TypeScript/src/DoubleTrigger.lf +++ b/test/TypeScript/src/DoubleTrigger.lf @@ -5,10 +5,10 @@ target TypeScript { timeout: 1 sec }; main reactor DoubleTrigger { - timer t1; - timer t2; - state s:number(0); - reaction(t1, t2) {= + timer t1; + timer t2; + state s:number(0); + reaction(t1, t2) {= s++; if (s > 1) { util.requestErrorStop("FAILURE: Reaction got triggered twice.") diff --git a/test/TypeScript/src/NativeListsAndTimes.lf b/test/TypeScript/src/NativeListsAndTimes.lf index 025bc648b7..7af003c3ed 100644 --- a/test/TypeScript/src/NativeListsAndTimes.lf +++ b/test/TypeScript/src/NativeListsAndTimes.lf @@ -1,24 +1,25 @@ target TypeScript; // This test passes if it is successfully compiled into valid target code. main reactor (x:number(0), - y:time(0), // Units are missing but not required - z(1 msec), // Type is missing but not required - p:number[](1, 2, 3, 4), // List of integers - q:TimeValue[](1 msec, 2 msec, 3 msec), // list of time values - r:time({=0=}), // Zero-valued target code also is a valid time - 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 v:boolean; // 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 - reaction(tick) {= - // Target code - =} + y:time(0), // Units are missing but not required + z(1 msec), // Type is missing but not required + p:number[](1, 2, 3, 4), // List of integers + q:TimeValue[](1 msec, 2 msec, 3 msec), // list of time values + r:time({=0=}), // Zero-valued target code also is a valid time + 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 v:boolean; // 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 + reaction(tick) {= + var x = 0; + // Target code + =} } \ No newline at end of file diff --git a/test/TypeScript/src/serialization/ProtoNoPacking.lf b/test/TypeScript/src/serialization/ProtoNoPacking.lf index b8de2efa04..e658a3341d 100644 --- a/test/TypeScript/src/serialization/ProtoNoPacking.lf +++ b/test/TypeScript/src/serialization/ProtoNoPacking.lf @@ -41,7 +41,7 @@ reactor SinkProto { } main reactor ProtoNoPacking { - s = new SourceProto(); - d = new SinkProto(); - s.out -> d.x; -} \ No newline at end of file + s = new SourceProto(); + d = new SinkProto(); + s.out -> d.x; +} From 3ef8ae5508e9c40351a19543662ed79272b1752a Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 19 May 2022 10:22:41 -0700 Subject: [PATCH 45/58] [tests] Whitespace only. This pass was automated instead of manual. It replaces carriage return/line feed line terminators with just line feed terminators, and it removes trailing whitespace. --- test/C/src/ActionDelay.lf | 6 +- test/C/src/ActionIsPresent.lf | 2 +- test/C/src/ActionWithNoReaction.lf | 2 +- test/C/src/After.lf | 2 +- test/C/src/AfterCycles.lf | 14 +- test/C/src/Alignment.lf | 6 +- test/C/src/ArrayAsParameter.lf | 2 +- test/C/src/ArrayAsType.lf | 2 +- test/C/src/ArrayParallel.lf | 2 +- test/C/src/ArrayPrint.lf | 2 +- test/C/src/Composition.lf | 8 +- test/C/src/CompositionAfter.lf | 8 +- test/C/src/CompositionGain.lf | 4 +- test/C/src/CompositionInheritance.lf | 8 +- test/C/src/CountSelf.lf | 5 +- test/C/src/CountTest.lf | 2 - test/C/src/DanglingOutput.lf | 2 +- test/C/src/Deadline.lf | 2 +- test/C/src/DeadlineAnytime.lf | 1 - test/C/src/DelayArray.lf | 2 +- test/C/src/DelayArrayWithAfter.lf | 4 +- test/C/src/DelayInt.lf | 12 +- test/C/src/DelayPointer.lf | 12 +- test/C/src/DelayString.lf | 8 +- test/C/src/DelayStruct.lf | 2 +- test/C/src/DelayStructWithAfter.lf | 2 +- test/C/src/DelayStructWithAfterOverlapped.lf | 2 +- test/C/src/DelayedAction.lf | 4 +- test/C/src/DelayedReaction.lf | 10 +- test/C/src/Determinism.lf | 4 +- test/C/src/DoubleInvocation.lf | 4 +- test/C/src/DoublePort.lf | 11 +- test/C/src/DoubleReaction.lf | 2 +- test/C/src/DoubleTrigger.lf | 4 +- test/C/src/Gain.lf | 2 +- test/C/src/GetMicroStep.lf | 4 +- test/C/src/GetTime.lf | 6 +- test/C/src/Hello.lf | 6 +- test/C/src/HelloWorld.lf | 2 +- test/C/src/Hierarchy.lf | 4 +- test/C/src/Hierarchy2.lf | 2 +- test/C/src/IdentifierLength.lf | 8 +- test/C/src/Import.lf | 2 +- test/C/src/ImportComposition.lf | 2 +- test/C/src/ImportRenamed.lf | 4 +- test/C/src/InheritanceAction.lf | 6 +- test/C/src/ManualDelayedReaction.lf | 2 +- test/C/src/Microsteps.lf | 2 +- test/C/src/Minimal.lf | 2 +- test/C/src/MovingAverage.lf | 4 +- test/C/src/NativeListsAndTimes.lf | 6 +- test/C/src/ParameterHierarchy.lf | 2 +- test/C/src/ParameterizedState.lf | 4 +- test/C/src/PeriodicDesugared.lf | 6 +- test/C/src/PhysicalConnection.lf | 4 +- test/C/src/PingPong.lf | 20 +- test/C/src/Preamble.lf | 2 +- test/C/src/ReadOutputOfContainedReactor.lf | 2 +- test/C/src/Schedule.lf | 2 +- test/C/src/ScheduleLogicalAction.lf | 2 +- test/C/src/ScheduleValue.lf | 2 +- test/C/src/SendingInside.lf | 2 +- test/C/src/SendsPointerTest.lf | 2 +- test/C/src/SetArray.lf | 2 +- test/C/src/SetToken.lf | 2 +- test/C/src/SimpleDeadline.lf | 2 +- test/C/src/SimpleImport.lf | 2 +- test/C/src/SlowingClock.lf | 6 +- test/C/src/SlowingClockPhysical.lf | 8 +- test/C/src/Starvation.lf | 132 +++++----- test/C/src/Stop.lf | 122 ++++----- test/C/src/StopZero.lf | 206 ++++++++-------- test/C/src/Stride.lf | 2 +- test/C/src/StructAsState.lf | 2 +- test/C/src/StructAsType.lf | 4 +- test/C/src/StructAsTypeDirect.lf | 2 +- test/C/src/StructParallel.lf | 4 +- test/C/src/StructPrint.lf | 2 +- test/C/src/StructScale.lf | 6 +- test/C/src/SubclassesAndStartup.lf | 2 +- test/C/src/TestForPreviousOutput.lf | 2 +- test/C/src/TimeState.lf | 4 +- test/C/src/Timeout.lf | 94 +++---- test/C/src/TimeoutZero.lf | 96 ++++---- test/C/src/ToReactionNested.lf | 6 +- test/C/src/TriggerDownstreamOnlyIfPresent2.lf | 2 +- test/C/src/UnconnectedInput.lf | 2 +- test/C/src/Wcet.lf | 2 +- test/C/src/concurrent/AsyncCallback.lf | 14 +- test/C/src/concurrent/AsyncCallbackDrop.lf | 8 +- test/C/src/concurrent/AsyncCallbackReplace.lf | 6 +- test/C/src/concurrent/CompositionThreaded.lf | 2 +- .../DeadlineHandledAboveThreaded.lf | 2 +- test/C/src/concurrent/DeadlineThreaded.lf | 2 +- test/C/src/concurrent/DelayIntThreaded.lf | 12 +- test/C/src/concurrent/DeterminismThreaded.lf | 2 +- .../src/concurrent/DoubleReactionThreaded.lf | 2 +- test/C/src/concurrent/GainThreaded.lf | 70 +++--- test/C/src/concurrent/HelloThreaded.lf | 4 +- test/C/src/concurrent/ImportThreaded.lf | 2 +- test/C/src/concurrent/PingPongThreaded.lf | 20 +- test/C/src/concurrent/ScheduleAt.lf | 10 +- .../C/src/concurrent/SendingInsideThreaded.lf | 2 +- test/C/src/concurrent/StarvationThreaded.lf | 134 +++++----- test/C/src/concurrent/StopThreaded.lf | 130 +++++----- test/C/src/concurrent/StopZeroThreaded.lf | 206 ++++++++-------- test/C/src/concurrent/ThreadedMultiport.lf | 6 +- test/C/src/concurrent/TimeoutThreaded.lf | 96 ++++---- test/C/src/concurrent/TimeoutZeroThreaded.lf | 98 ++++---- test/C/src/concurrent/Tracing.lf | 4 +- test/C/src/concurrent/Workers.lf | 2 +- test/C/src/docker/HelloWorldContainerized.lf | 2 +- test/C/src/docker/PingPongContainerized.lf | 16 +- .../DistributedCountContainerized.lf | 4 +- .../DistributedDoublePortContainerized.lf | 6 +- .../DistributedMultiportContainerized.lf | 2 +- ...stributedStopDecentralizedContainerized.lf | 34 +-- test/C/src/federated/BroadcastFeedback.lf | 2 +- .../BroadcastFeedbackWithHierarchy.lf | 6 +- test/C/src/federated/ChainWithDelay.lf | 2 +- test/C/src/federated/ClockSync.lf | 11 +- test/C/src/federated/CycleDetection.lf | 12 +- test/C/src/federated/DecentralizedP2PComm.lf | 2 +- .../DecentralizedP2PUnbalancedTimeout.lf | 8 +- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 6 +- test/C/src/federated/DistributedBank.lf | 2 +- .../federated/DistributedBankToMultiport.lf | 12 +- test/C/src/federated/DistributedCount.lf | 4 +- .../DistributedCountDecentralizedLate.lf | 6 +- ...ributedCountDecentralizedLateDownstream.lf | 18 +- ...tributedCountDecentralizedLateHierarchy.lf | 12 +- .../src/federated/DistributedCountPhysical.lf | 4 +- .../DistributedCountPhysicalAfterDelay.lf | 12 +- .../DistributedCountPhysicalDecentralized.lf | 4 +- test/C/src/federated/DistributedDoublePort.lf | 10 +- .../src/federated/DistributedLoopedAction.lf | 12 +- .../DistributedLoopedActionDecentralized.lf | 34 +-- .../DistributedLoopedPhysicalAction.lf | 12 +- ...ibutedLoopedPhysicalActionDecentralized.lf | 4 +- test/C/src/federated/DistributedMultiport.lf | 4 +- .../federated/DistributedMultiportToBank.lf | 8 +- .../federated/DistributedMultiportToken.lf | 4 +- .../src/federated/DistributedNetworkOrder.lf | 16 +- test/C/src/federated/DistributedStop.lf | 232 +++++++++--------- .../federated/DistributedStopDecentralized.lf | 34 +-- test/C/src/federated/DistributedStopZero.lf | 166 ++++++------- .../DistributedStopZeroDecentralized.lf | 32 +-- test/C/src/federated/DistributedToken.lf | 10 +- .../federated/LoopDistributedCentralized.lf | 8 +- .../LoopDistributedCentralizedPrecedence.lf | 6 +- ...stributedCentralizedPrecedenceHierarchy.lf | 14 +- .../federated/LoopDistributedDecentralized.lf | 6 +- test/C/src/federated/LoopDistributedDouble.lf | 8 +- test/C/src/federated/ParallelDestinations.lf | 6 +- test/C/src/federated/ParallelSources.lf | 6 +- .../src/federated/ParallelSourcesMultiport.lf | 8 +- test/C/src/federated/PhysicalSTP.lf | 8 +- test/C/src/federated/PingPongDistributed.lf | 16 +- .../federated/PingPongDistributedPhysical.lf | 24 +- test/C/src/federated/StopAtShutdown.lf | 12 +- test/C/src/federated/TopLevelArtifacts.lf | 16 +- .../failing/DistributedDoublePortLooped.lf | 12 +- .../failing/DistributedDoublePortLooped2.lf | 10 +- .../DistributedNetworkOrderDecentralized.lf | 14 +- .../LoopDistributedDecentralizedPrecedence.lf | 8 +- ...ributedDecentralizedPrecedenceHierarchy.lf | 8 +- test/C/src/lib/Imported.lf | 4 +- test/C/src/lib/ImportedComposition.lf | 2 +- test/C/src/lib/InternalDelay.lf | 2 +- test/C/src/lib/LoopedActionSender.lf | 73 +++--- test/C/src/lib/Test.lf | 2 +- test/C/src/lib/TestCount.lf | 4 +- test/C/src/lib/TestCountMultiport.lf | 4 +- test/C/src/modal_models/ConvertCaseTest.lf | 34 +-- test/C/src/modal_models/Count3Modes.lf | 12 +- test/C/src/modal_models/ModalActions.lf | 20 +- test/C/src/modal_models/ModalAfter.lf | 22 +- test/C/src/modal_models/ModalCycleBreaker.lf | 22 +- .../src/modal_models/ModalNestedReactions.lf | 8 +- test/C/src/modal_models/ModalStartup.lf | 22 +- test/C/src/modal_models/ModalStateReset.lf | 24 +- test/C/src/modal_models/ModalTimers.lf | 20 +- .../MultipleOutputFeeder_2Connections.lf | 8 +- ...ultipleOutputFeeder_ReactionConnections.lf | 24 +- test/C/src/modal_models/util/TraceTesting.lf | 30 +-- test/C/src/multiport/BankIndexInitializer.lf | 4 +- test/C/src/multiport/BankMulticast.lf | 10 +- .../src/multiport/BankMultiportToReaction.lf | 10 +- .../src/multiport/BankReactionsInContainer.lf | 6 +- test/C/src/multiport/BankSelfBroadcast.lf | 6 +- test/C/src/multiport/BankToBank.lf | 4 +- test/C/src/multiport/BankToBankMultiport.lf | 6 +- .../src/multiport/BankToBankMultiportAfter.lf | 6 +- test/C/src/multiport/BankToMultiport.lf | 12 +- test/C/src/multiport/BankToReaction.lf | 10 +- test/C/src/multiport/Broadcast.lf | 8 +- test/C/src/multiport/BroadcastAfter.lf | 8 +- .../C/src/multiport/BroadcastMultipleAfter.lf | 4 +- test/C/src/multiport/FullyConnected.lf | 8 +- .../multiport/FullyConnectedAddressable.lf | 18 +- .../FullyConnectedAddressableAfter.lf | 2 +- test/C/src/multiport/MultiportFromBank.lf | 6 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 6 +- .../C/src/multiport/MultiportFromHierarchy.lf | 6 +- test/C/src/multiport/MultiportFromReaction.lf | 3 +- test/C/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 4 +- .../multiport/MultiportMutableInputArray.lf | 4 +- test/C/src/multiport/MultiportOut.lf | 4 +- test/C/src/multiport/MultiportToBank.lf | 10 +- test/C/src/multiport/MultiportToBankAfter.lf | 6 +- test/C/src/multiport/MultiportToBankDouble.lf | 10 +- .../src/multiport/MultiportToBankHierarchy.lf | 8 +- test/C/src/multiport/MultiportToHierarchy.lf | 8 +- test/C/src/multiport/MultiportToMultiport.lf | 6 +- test/C/src/multiport/MultiportToMultiport2.lf | 2 +- .../multiport/MultiportToMultiport2After.lf | 4 +- .../multiport/MultiportToMultiportArray.lf | 6 +- .../MultiportToMultiportParameter.lf | 6 +- test/C/src/multiport/MultiportToPort.lf | 6 +- test/C/src/multiport/MultiportToReaction.lf | 2 +- test/C/src/multiport/NestedBanks.lf | 4 +- .../C/src/multiport/NestedInterleavedBanks.lf | 4 +- test/C/src/multiport/PipelineAfter.lf | 10 +- .../src/multiport/ReactionToContainedBank.lf | 4 +- .../src/multiport/ReactionToContainedBank2.lf | 4 +- .../ReactionToContainedBankMultiport.lf | 4 +- .../TriggerDownstreamOnlyIfPresent.lf | 2 +- .../serialization/PersonProtocolBuffers.lf | 22 +- test/C/src/serialization/ProtoNoPacking.lf | 12 +- .../serialization/ROSBuiltInSerialization.lf | 36 +-- .../ROSBuiltInSerializationSharedPtr.lf | 36 +-- test/C/src/target/CMakeInclude.lf | 4 +- test/C/src/target/DistributedCMakeInclude.lf | 2 +- test/C/src/target/HelloWorldCCPP.lf | 6 +- test/C/src/target/HelloWorldCCPPNoCMake.lf | 6 +- test/C/src/target/HelloWorldFederatedCCPP.lf | 6 +- .../target/HelloWorldFederatedCCPPNoCMake.lf | 4 +- .../src/target/HelloWorldFederatedNoCMake.lf | 4 +- test/C/src/target/HelloWorldNoCMake.lf | 2 +- test/C/src/target/HelloWorldThreadedCPP.lf | 4 +- test/C/src/target/lib/ImportedCMakeInclude.lf | 4 +- test/Cpp/src/ActionDelay.lf | 6 +- test/Cpp/src/ActionIsPresent.lf | 2 +- test/Cpp/src/ActionWithNoReaction.lf | 2 +- test/Cpp/src/After.lf | 2 +- test/Cpp/src/Alignment.lf | 2 +- test/Cpp/src/ArrayAsParameter.lf | 2 +- test/Cpp/src/ArrayAsType.lf | 6 +- test/Cpp/src/ArrayParallel.lf | 2 +- test/Cpp/src/ArrayPrint.lf | 10 +- test/Cpp/src/ArrayScale.lf | 2 +- test/Cpp/src/Composition.lf | 4 +- test/Cpp/src/CompositionAfter.lf | 4 +- test/Cpp/src/CompositionGain.lf | 2 +- test/Cpp/src/DeadlineHandledAbove.lf | 2 +- test/Cpp/src/DelayInt.lf | 8 +- test/Cpp/src/DelayedReaction.lf | 4 +- test/Cpp/src/Determinism.lf | 2 +- test/Cpp/src/DoubleInvocation.lf | 4 +- test/Cpp/src/DoublePort.lf | 12 +- test/Cpp/src/DoubleTrigger.lf | 4 +- test/Cpp/src/GetMicroStep.lf | 2 +- test/Cpp/src/GetTime.lf | 2 +- test/Cpp/src/Hello.lf | 10 +- test/Cpp/src/ImportComposition.lf | 4 +- test/Cpp/src/ImportRenamed.lf | 2 +- test/Cpp/src/ManualDelayedReaction.lf | 2 +- test/Cpp/src/MovingAverage.lf | 2 +- test/Cpp/src/MultipleContained.lf | 2 +- test/Cpp/src/NativeListsAndTimes.lf | 4 +- test/Cpp/src/ParameterHierarchy.lf | 2 +- test/Cpp/src/PeriodicDesugared.lf | 8 +- test/Cpp/src/Pipeline.lf | 8 +- test/Cpp/src/PreambleTest.lf | 6 +- test/Cpp/src/ScheduleLogicalAction.lf | 2 +- test/Cpp/src/SelfLoop.lf | 2 +- test/Cpp/src/SimpleDeadline.lf | 6 +- test/Cpp/src/SimpleImport.lf | 2 +- test/Cpp/src/SlowingClock.lf | 2 +- test/Cpp/src/SlowingClockPhysical.lf | 6 +- test/Cpp/src/StartupOutFromInside.lf | 2 +- test/Cpp/src/StructParallel.lf | 2 +- test/Cpp/src/StructScale.lf | 2 +- test/Cpp/src/TimeLimit.lf | 2 +- test/Cpp/src/TimeState.lf | 2 +- test/Cpp/src/Timeout_Test.lf | 6 +- test/Cpp/src/ToReactionNested.lf | 2 +- .../src/TriggerDownstreamOnlyIfPresent2.lf | 2 +- test/Cpp/src/concurrent/AsyncCallback.lf | 8 +- test/Cpp/src/concurrent/AsyncCallback2.lf | 8 +- .../Cpp/src/concurrent/CompositionThreaded.lf | 4 +- .../DeadlineHandledAboveThreaded.lf | 2 +- test/Cpp/src/concurrent/DelayIntThreaded.lf | 8 +- .../Cpp/src/concurrent/DeterminismThreaded.lf | 2 +- test/Cpp/src/concurrent/HelloThreaded.lf | 10 +- test/Cpp/src/concurrent/Threaded.lf | 2 +- test/Cpp/src/concurrent/ThreadedThreaded.lf | 2 +- test/Cpp/src/concurrent/TimeLimitThreaded.lf | 2 +- test/Cpp/src/concurrent/Workers.lf | 2 +- test/Cpp/src/lib/Imported.lf | 2 +- test/Cpp/src/lib/ImportedComposition.lf | 2 +- test/Cpp/src/lib/LoopedActionSender.lf | 6 +- test/Cpp/src/multiport/BankSelfBroadcast.lf | 8 +- test/Cpp/src/multiport/BankToBank.lf | 4 +- test/Cpp/src/multiport/BankToBankMultiport.lf | 4 +- .../src/multiport/BankToBankMultiportAfter.lf | 8 +- test/Cpp/src/multiport/BankToMultiport.lf | 10 +- test/Cpp/src/multiport/Broadcast.lf | 6 +- test/Cpp/src/multiport/BroadcastAfter.lf | 10 +- .../src/multiport/BroadcastMultipleAfter.lf | 8 +- test/Cpp/src/multiport/FullyConnected.lf | 12 +- .../multiport/FullyConnectedAddressable.lf | 16 +- .../FullyConnectedAddressableAfter.lf | 4 +- test/Cpp/src/multiport/MultiportFromBank.lf | 6 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 6 +- .../src/multiport/MultiportFromHierarchy.lf | 8 +- test/Cpp/src/multiport/MultiportIn.lf | 6 +- test/Cpp/src/multiport/MultiportOut.lf | 4 +- test/Cpp/src/multiport/MultiportToBank.lf | 6 +- .../Cpp/src/multiport/MultiportToBankAfter.lf | 6 +- .../src/multiport/MultiportToBankHierarchy.lf | 8 +- .../Cpp/src/multiport/MultiportToHierarchy.lf | 8 +- .../Cpp/src/multiport/MultiportToMultiport.lf | 10 +- .../src/multiport/MultiportToMultiport2.lf | 2 +- .../multiport/MultiportToMultiportArray.lf | 10 +- test/Cpp/src/multiport/MultiportToPort.lf | 6 +- test/Cpp/src/multiport/PipelineAfter.lf | 10 +- test/Cpp/src/target/AfterVoid.lf | 4 +- test/Cpp/src/target/GenericDelay.lf | 6 +- test/Cpp/src/target/PreambleFile.lf | 6 +- test/Python/src/ActionDelay.lf | 6 +- test/Python/src/ActionWithNoReaction.lf | 2 +- test/Python/src/After.lf | 2 +- test/Python/src/AfterCycles.lf | 14 +- test/Python/src/AfterOverlapped.lf | 2 +- test/Python/src/ArrayAsParameter.lf | 2 +- test/Python/src/ArrayParallel.lf | 2 +- test/Python/src/CompareTags.lf | 4 +- test/Python/src/Composition.lf | 2 +- test/Python/src/CompositionAfter.lf | 6 +- test/Python/src/CompositionGain.lf | 2 +- test/Python/src/CompositionInheritance.lf | 2 +- test/Python/src/CountSelf.lf | 6 +- test/Python/src/CountTest.lf | 1 - test/Python/src/DanglingOutput.lf | 2 +- test/Python/src/Deadline.lf | 4 +- test/Python/src/DeadlineHandledAbove.lf | 2 +- test/Python/src/DelayArrayWithAfter.lf | 6 +- test/Python/src/DelayInt.lf | 8 +- test/Python/src/DelayString.lf | 4 +- test/Python/src/DelayedAction.lf | 4 +- test/Python/src/DelayedReaction.lf | 8 +- test/Python/src/Determinism.lf | 4 +- test/Python/src/DoubleInvocation.lf | 4 +- test/Python/src/Gain.lf | 4 +- test/Python/src/GetMicroStep.lf | 4 +- test/Python/src/GetTime.lf | 6 +- test/Python/src/Hello.lf | 6 +- test/Python/src/Hierarchy.lf | 4 +- test/Python/src/Hierarchy2.lf | 2 +- test/Python/src/IdentifierLength.lf | 4 +- test/Python/src/Import.lf | 2 +- test/Python/src/ImportComposition.lf | 4 +- test/Python/src/ImportRenamed.lf | 2 +- test/Python/src/ManualDelayedReaction.lf | 10 +- test/Python/src/Microsteps.lf | 2 +- test/Python/src/Minimal.lf | 4 +- test/Python/src/MovingAverage.lf | 6 +- test/Python/src/MultipleContained.lf | 2 +- test/Python/src/NativeListsAndTimes.lf | 8 +- test/Python/src/ParameterizedState.lf | 2 +- test/Python/src/PeriodicDesugared.lf | 6 +- test/Python/src/PingPong.lf | 20 +- test/Python/src/Pipeline.lf | 10 +- test/Python/src/Preamble.lf | 2 +- .../src/ReadOutputOfContainedReactor.lf | 2 +- test/Python/src/ScheduleLogicalAction.lf | 2 +- test/Python/src/SendingInside.lf | 2 +- test/Python/src/SimpleDeadline.lf | 2 +- test/Python/src/SimpleImport.lf | 2 +- test/Python/src/SlowingClock.lf | 2 +- test/Python/src/Stride.lf | 2 +- test/Python/src/StructAsState.lf | 2 +- test/Python/src/StructAsType.lf | 4 +- test/Python/src/StructAsTypeDirect.lf | 2 +- test/Python/src/StructParallel.lf | 4 +- test/Python/src/StructPrint.lf | 2 +- test/Python/src/StructScale.lf | 10 +- test/Python/src/SubclassesAndStartup.lf | 2 +- test/Python/src/TestForPreviousOutput.lf | 2 +- test/Python/src/TimeState.lf | 2 +- test/Python/src/Timers.lf | 2 +- .../src/TriggerDownstreamOnlyIfPresent.lf | 4 +- .../src/TriggerDownstreamOnlyIfPresent2.lf | 2 +- test/Python/src/UnconnectedInput.lf | 2 +- test/Python/src/Wcet.lf | 4 +- test/Python/src/concurrent/AsyncCallback.lf | 4 +- .../src/concurrent/AsyncCallbackNoTimer.lf | 30 +-- .../src/docker/FilesPropertyContainerized.lf | 4 +- .../src/docker/HelloWorldContainerized.lf | 2 +- .../src/docker/PingPongContainerized.lf | 16 +- .../DistributedCountContainerized.lf | 4 +- .../DistributedDoublePortContainerized.lf | 6 +- .../DistributedMultiportContainerized.lf | 2 +- ...stributedStopDecentralizedContainerized.lf | 34 +-- .../Python/src/federated/BroadcastFeedback.lf | 2 +- .../BroadcastFeedbackWithHierarchy.lf | 6 +- test/Python/src/federated/ChainWithDelay.lf | 2 +- test/Python/src/federated/CycleDetection.lf | 14 +- .../DecentralizedP2PUnbalancedTimeout.lf | 14 +- ...centralizedP2PUnbalancedTimeoutPhysical.lf | 6 +- test/Python/src/federated/DistributedBank.lf | 4 +- .../federated/DistributedBankToMultiport.lf | 10 +- test/Python/src/federated/DistributedCount.lf | 4 +- .../src/federated/DistributedCountPhysical.lf | 6 +- .../DistributedCountPhysicalAfterDelay.lf | 6 +- .../DistributedCountPhysicalDecentralized.lf | 4 +- .../src/federated/DistributedDoublePort.lf | 12 +- .../src/federated/DistributedLoopedAction.lf | 8 +- .../DistributedLoopedPhysicalAction.lf | 8 +- ...ibutedLoopedPhysicalActionDecentralized.lf | 4 +- .../src/federated/DistributedMultiport.lf | 2 +- .../federated/DistributedMultiportToBank.lf | 6 +- .../federated/DistributedMultiportToken.lf | 4 +- test/Python/src/federated/DistributedStop.lf | 226 ++++++++--------- .../federated/DistributedStopDecentralized.lf | 40 +-- .../src/federated/DistributedStopZero.lf | 182 +++++++------- .../src/federated/ParallelDestinations.lf | 6 +- test/Python/src/federated/ParallelSources.lf | 6 +- .../src/federated/ParallelSourcesMultiport.lf | 8 +- .../src/federated/PingPongDistributed.lf | 20 +- test/Python/src/federated/StopAtShutdown.lf | 12 +- .../Python/src/federated/failing/ClockSync.lf | 17 +- .../failing/DistributedCountDecentralized.lf | 2 +- .../DistributedCountDecentralizedLate.lf | 2 +- ...ributedCountDecentralizedLateDownstream.lf | 22 +- ...tributedCountDecentralizedLateHierarchy.lf | 16 +- .../DistributedLoopedActionDecentralized.lf | 36 +-- .../failing/DistributedNetworkOrder.lf | 16 +- .../failing/LoopDistributedCentralized.lf | 8 +- .../LoopDistributedCentralizedPrecedence.lf | 6 +- ...stributedCentralizedPrecedenceHierarchy.lf | 14 +- .../failing/LoopDistributedDecentralized.lf | 6 +- .../failing/LoopDistributedDouble.lf | 6 +- .../src/federated/failing/PhysicalSTP.lf | 4 +- .../federated/failing/TopLevelArtifacts.lf | 18 +- test/Python/src/lib/Count.lf | 2 +- test/Python/src/lib/Imported.lf | 6 +- test/Python/src/lib/ImportedAgain.lf | 2 +- test/Python/src/lib/ImportedComposition.lf | 2 +- test/Python/src/lib/InternalDelay.lf | 2 +- test/Python/src/lib/LoopedActionSender.lf | 61 +++-- test/Python/src/lib/Test.lf | 2 +- test/Python/src/lib/TestCount.lf | 4 +- test/Python/src/lib/TestCountMultiport.lf | 4 +- .../src/modal_models/ConvertCaseTest.lf | 30 +-- test/Python/src/modal_models/Count3Modes.lf | 12 +- test/Python/src/modal_models/ModalActions.lf | 18 +- test/Python/src/modal_models/ModalAfter.lf | 20 +- .../src/modal_models/ModalCycleBreaker.lf | 20 +- .../src/modal_models/ModalNestedReactions.lf | 6 +- test/Python/src/modal_models/ModalStartup.lf | 18 +- .../src/modal_models/ModalStateReset.lf | 22 +- test/Python/src/modal_models/ModalTimers.lf | 18 +- .../MultipleOutputFeeder_2Connections.lf | 12 +- ...ultipleOutputFeeder_ReactionConnections.lf | 22 +- .../src/modal_models/util/TraceTesting.lf | 24 +- .../src/multiport/BankIndexInitializer.lf | 4 +- .../src/multiport/BankReactionsInContainer.lf | 4 +- test/Python/src/multiport/BankToBank.lf | 6 +- .../src/multiport/BankToBankMultiport.lf | 6 +- .../src/multiport/BankToBankMultiportAfter.lf | 4 +- test/Python/src/multiport/BankToMultiport.lf | 4 +- test/Python/src/multiport/Broadcast.lf | 10 +- test/Python/src/multiport/BroadcastAfter.lf | 6 +- .../src/multiport/BroadcastMultipleAfter.lf | 6 +- .../Python/src/multiport/MultiportFromBank.lf | 6 +- .../multiport/MultiportFromBankHierarchy.lf | 4 +- .../MultiportFromBankHierarchyAfter.lf | 6 +- .../src/multiport/MultiportFromHierarchy.lf | 8 +- .../src/multiport/MultiportFromReaction.lf | 2 +- test/Python/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 2 +- test/Python/src/multiport/MultiportOut.lf | 10 +- test/Python/src/multiport/MultiportToBank.lf | 8 +- .../src/multiport/MultiportToBankAfter.lf | 6 +- .../src/multiport/MultiportToBankHierarchy.lf | 8 +- .../src/multiport/MultiportToHierarchy.lf | 6 +- .../src/multiport/MultiportToMultiport.lf | 4 +- .../src/multiport/MultiportToMultiport2.lf | 2 +- .../multiport/MultiportToMultiport2After.lf | 2 +- .../multiport/MultiportToMultiportArray.lf | 4 +- .../MultiportToMultiportParameter.lf | 6 +- test/Python/src/multiport/MultiportToPort.lf | 6 +- .../src/multiport/MultiportToReaction.lf | 2 +- test/Python/src/multiport/NestedBanks.lf | 6 +- .../src/multiport/NestedInterleavedBanks.lf | 4 +- test/Python/src/multiport/PipelineAfter.lf | 10 +- .../serialization/PersonProtocolBuffers.lf | 14 +- .../src/serialization/ProtoNoPacking.lf | 10 +- test/Rust/src/CompositionWithPorts.lf | 1 - test/Rust/src/MainReactorParam.lf | 2 +- test/Rust/src/NativeListsAndTimes.lf | 2 +- test/Rust/src/Stop.lf | 10 +- test/Rust/src/StopCleanup.lf | 6 +- test/Rust/src/TimeState.lf | 2 +- test/Rust/src/concurrent/Workers.lf | 2 +- .../src/multiport/ConnectionToSelfBank.lf | 2 +- .../multiport/ConnectionToSelfMultiport.lf | 2 +- test/Rust/src/multiport/MultiportFromBank.lf | 2 +- .../src/multiport/MultiportFromHierarchy.lf | 6 +- test/Rust/src/multiport/MultiportIn.lf | 2 +- test/Rust/src/multiport/MultiportOut.lf | 4 +- test/Rust/src/multiport/MultiportToBank.lf | 4 +- .../src/multiport/MultiportToBankHierarchy.lf | 6 +- .../src/multiport/MultiportToMultiport.lf | 2 +- test/TypeScript/src/ActionDelay.lf | 6 +- test/TypeScript/src/ActionWithNoReaction.lf | 2 +- test/TypeScript/src/ArrayAsParameter.lf | 2 +- test/TypeScript/src/ArrayAsType.lf | 2 +- test/TypeScript/src/ArrayPrint.lf | 2 +- test/TypeScript/src/Composition.lf | 8 +- test/TypeScript/src/DanglingOutput.lf | 2 +- test/TypeScript/src/DeadlineHandledAbove.lf | 2 +- test/TypeScript/src/DelayInt.lf | 10 +- test/TypeScript/src/DelayedAction.lf | 4 +- test/TypeScript/src/DelayedReaction.lf | 4 +- test/TypeScript/src/Determinism.lf | 4 +- test/TypeScript/src/DoubleInvocation.lf | 4 +- test/TypeScript/src/DoubleTrigger.lf | 2 +- test/TypeScript/src/Gain.lf | 2 +- test/TypeScript/src/GetTime.lf | 6 +- test/TypeScript/src/Hello.lf | 6 +- test/TypeScript/src/HelloWorld.lf | 2 +- test/TypeScript/src/Hierarchy.lf | 4 +- test/TypeScript/src/Hierarchy2.lf | 2 +- test/TypeScript/src/Import.lf | 2 +- test/TypeScript/src/Microsteps.lf | 2 +- test/TypeScript/src/Minimal.lf | 2 +- test/TypeScript/src/MovingAverage.lf | 2 +- test/TypeScript/src/MultipleContained.lf | 2 +- test/TypeScript/src/NativeListsAndTimes.lf | 6 +- test/TypeScript/src/ParameterizedState.lf | 2 +- test/TypeScript/src/PeriodicDesugared.lf | 6 +- test/TypeScript/src/Preamble.lf | 2 +- .../src/ReadOutputOfContainedReactor.lf | 2 +- test/TypeScript/src/Schedule.lf | 2 +- test/TypeScript/src/ScheduleLogicalAction.lf | 2 +- test/TypeScript/src/SendingInside.lf | 2 +- test/TypeScript/src/SendingInside2.lf | 2 +- test/TypeScript/src/SendsPointerTest.lf | 2 +- test/TypeScript/src/SimpleDeadline.lf | 2 +- test/TypeScript/src/SlowingClock.lf | 2 +- test/TypeScript/src/Stride.lf | 2 +- test/TypeScript/src/StructAsState.lf | 2 +- test/TypeScript/src/StructAsType.lf | 2 +- test/TypeScript/src/StructAsTypeDirect.lf | 2 +- test/TypeScript/src/StructPrint.lf | 2 +- test/TypeScript/src/StructScale.lf | 2 +- test/TypeScript/src/TestForPreviousOutput.lf | 2 +- test/TypeScript/src/TimeLimit.lf | 2 +- test/TypeScript/src/TimeState.lf | 4 +- test/TypeScript/src/Wcet.lf | 4 +- .../src/concurrent/AsyncCallback.lf | 2 +- .../src/docker/HelloWorldContainerized.lf | 2 +- .../src/federated/DistributedCount.lf | 2 +- .../src/federated/PingPongDistributed.lf | 2 +- test/TypeScript/src/lib/Imported.lf | 2 +- test/TypeScript/src/lib/ImportedAgain.lf | 2 +- test/TypeScript/src/lib/TestCount.lf | 2 +- .../TypeScript/src/multiport/BankMulticast.lf | 10 +- .../src/multiport/BankMultiportToReaction.lf | 8 +- .../src/multiport/BankReactionsInContainer.lf | 4 +- .../src/multiport/BankSelfBroadcast.lf | 2 +- test/TypeScript/src/multiport/BankToBank.lf | 2 +- .../src/multiport/BankToBankMultiport.lf | 2 +- .../src/multiport/BankToBankMultiportAfter.lf | 2 +- .../src/multiport/BankToMultiport.lf | 4 +- .../src/multiport/BankToReaction.lf | 6 +- test/TypeScript/src/multiport/Broadcast.lf | 4 +- .../src/multiport/BroadcastAfter.lf | 6 +- .../src/multiport/BroadcastMultipleAfter.lf | 4 +- .../src/multiport/FullyConnected.lf | 4 +- .../src/multiport/MultiportFromBank.lf | 2 +- .../MultiportFromBankHierarchyAfter.lf | 4 +- .../src/multiport/MultiportFromHierarchy.lf | 2 +- .../src/multiport/MultiportFromReaction.lf | 3 +- test/TypeScript/src/multiport/MultiportIn.lf | 4 +- .../src/multiport/MultiportInParameterized.lf | 2 +- .../multiport/MultiportMutableInputArray.lf | 4 +- .../src/multiport/MultiportToBank.lf | 4 +- .../src/multiport/MultiportToBankAfter.lf | 4 +- .../src/multiport/MultiportToBankDouble.lf | 8 +- .../src/multiport/MultiportToBankHierarchy.lf | 4 +- .../src/multiport/MultiportToHierarchy.lf | 4 +- .../src/multiport/MultiportToMultiport.lf | 4 +- .../multiport/MultiportToMultiportArray.lf | 4 +- .../MultiportToMultiportParameter.lf | 2 +- .../src/multiport/MultiportToPort.lf | 4 +- .../src/multiport/MultiportToReaction.lf | 2 +- .../TypeScript/src/multiport/PipelineAfter.lf | 8 +- .../src/multiport/ReactionToContainedBank.lf | 6 +- .../src/serialization/ProtoNoPacking.lf | 8 +- 606 files changed, 2988 insertions(+), 3001 deletions(-) diff --git a/test/C/src/ActionDelay.lf b/test/C/src/ActionDelay.lf index 8bb665dd59..2c062cb774 100644 --- a/test/C/src/ActionDelay.lf +++ b/test/C/src/ActionDelay.lf @@ -19,7 +19,7 @@ reactor Source { output out:int; reaction(startup) -> out {= lf_set(out, 1); - =} + =} } reactor Sink { input in:int; @@ -41,7 +41,7 @@ main reactor ActionDelay { source = new Source(); sink = new Sink(); g = new GeneratedDelay(); - + source.out -> g.y_in; g.y_out -> sink.in; -} \ No newline at end of file +} diff --git a/test/C/src/ActionIsPresent.lf b/test/C/src/ActionIsPresent.lf index 3e57b676f7..2431d9ed24 100644 --- a/test/C/src/ActionIsPresent.lf +++ b/test/C/src/ActionIsPresent.lf @@ -22,4 +22,4 @@ main reactor ActionIsPresent(offset:time(1 nsec), period:time(500 msec)) { exit(1); } =} -} \ No newline at end of file +} diff --git a/test/C/src/ActionWithNoReaction.lf b/test/C/src/ActionWithNoReaction.lf index 79c200d924..9eb8f7fd5a 100644 --- a/test/C/src/ActionWithNoReaction.lf +++ b/test/C/src/ActionWithNoReaction.lf @@ -33,4 +33,4 @@ main reactor ActionWithNoReaction { lf_set(f.x, 42); =} f.y -> p.x after 10 msec; -} \ No newline at end of file +} diff --git a/test/C/src/After.lf b/test/C/src/After.lf index 4a714ce3a1..d05084c443 100644 --- a/test/C/src/After.lf +++ b/test/C/src/After.lf @@ -47,4 +47,4 @@ main reactor After { lf_set(f.x, 42); =} f.y -> p.x after 10 msec; -} \ No newline at end of file +} diff --git a/test/C/src/AfterCycles.lf b/test/C/src/AfterCycles.lf index 25038b579a..193ad05741 100644 --- a/test/C/src/AfterCycles.lf +++ b/test/C/src/AfterCycles.lf @@ -4,7 +4,7 @@ target C; reactor Source { output out:unsigned; - + reaction(startup) -> out {= lf_set(out, 1); =} @@ -12,9 +12,9 @@ reactor Source { reactor Work { input in:unsigned; output out:unsigned; - + reaction(in) -> out {= - lf_set(out, in->value); + lf_set(out, in->value); =} } @@ -23,10 +23,10 @@ main reactor AfterCycles { s = new Source(); w0 = new Work(); w1 = new Work(); - + s.out -> w0.in after 10 msec; s.out -> w1.in after 20 msec; - + reaction(w0.out) {= self->count++; interval_t elapsed_time = lf_time_logical_elapsed(); @@ -40,7 +40,7 @@ main reactor AfterCycles { exit(4); } =} - + reaction(w1.out) {= self->count++; interval_t elapsed_time = lf_time_logical_elapsed(); @@ -58,7 +58,7 @@ main reactor AfterCycles { reaction(shutdown) {= if (self->count != 2) { fprintf(stderr, "Top-level reactions should have been triggered but were not.\n"); - exit(5); + exit(5); } =} } diff --git a/test/C/src/Alignment.lf b/test/C/src/Alignment.lf index c18c5b9c15..b1b8239d73 100644 --- a/test/C/src/Alignment.lf +++ b/test/C/src/Alignment.lf @@ -74,7 +74,7 @@ reactor Destination { state last_invoked:tag_t({= NEVER_TAG_INITIALIZER =}); reaction(ok, in) {= if (ok->is_present && in->is_present) { - lf_print("Destination: Input %d is prime at tag (%lld, %d).", + lf_print("Destination: Input %d is prime at tag (%lld, %d).", in->value, current_tag.time - start_time, current_tag.microstep ); @@ -86,9 +86,9 @@ reactor Destination { self->last_invoked.time - start_time, self->last_invoked.microstep ); } - self->last_invoked = current_tag; + self->last_invoked = current_tag; =} -} +} main reactor { source = new Source(); sieve = new Sieve(); diff --git a/test/C/src/ArrayAsParameter.lf b/test/C/src/ArrayAsParameter.lf index 5b88a534bd..c1a2304fb9 100644 --- a/test/C/src/ArrayAsParameter.lf +++ b/test/C/src/ArrayAsParameter.lf @@ -38,4 +38,4 @@ main reactor ArrayAsParameter { s = new Source(sequence = (1, 2, 3, 4), n_sequence=4); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/ArrayAsType.lf b/test/C/src/ArrayAsType.lf index 4a8372e45a..3d056c075b 100644 --- a/test/C/src/ArrayAsType.lf +++ b/test/C/src/ArrayAsType.lf @@ -37,4 +37,4 @@ main reactor ArrayAsType { s = new Source(); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/ArrayParallel.lf b/test/C/src/ArrayParallel.lf index 2b3cd79b83..7dfe222420 100644 --- a/test/C/src/ArrayParallel.lf +++ b/test/C/src/ArrayParallel.lf @@ -16,4 +16,4 @@ main reactor ArrayParallel { s.out -> c2.in; c1.out -> p1.in; c2.out -> p2.in; -} \ No newline at end of file +} diff --git a/test/C/src/ArrayPrint.lf b/test/C/src/ArrayPrint.lf index 19a3a0572a..0a1b8549ac 100644 --- a/test/C/src/ArrayPrint.lf +++ b/test/C/src/ArrayPrint.lf @@ -6,7 +6,7 @@ reactor Source { reaction(startup) -> out {= // Dynamically allocate an output array of length 3. SET_NEW_ARRAY(out, 3); - + // Above allocates the array, which then must be populated. out->value[0] = 0; out->value[1] = 1; diff --git a/test/C/src/Composition.lf b/test/C/src/Composition.lf index 1560298bbf..468f1c5c5f 100644 --- a/test/C/src/Composition.lf +++ b/test/C/src/Composition.lf @@ -21,9 +21,9 @@ reactor Test { reaction(x) {= (self->count)++; printf("Received %d\n", x->value); - if (x->value != self->count) { + if (x->value != self->count) { fprintf(stderr, "FAILURE: Expected %d\n", self->count); - exit(1); + exit(1); } =} reaction(shutdown) {= @@ -34,7 +34,7 @@ reactor Test { } main reactor Composition { s = new Source(); - + d = new Test(); s.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/CompositionAfter.lf b/test/C/src/CompositionAfter.lf index 9d699c5cdc..10b93329b7 100644 --- a/test/C/src/CompositionAfter.lf +++ b/test/C/src/CompositionAfter.lf @@ -21,15 +21,15 @@ reactor Test { reaction(x) {= (self->count)++; printf("Received %d\n", x->value); - if (x->value != self->count) { + if (x->value != self->count) { printf("FAILURE: Expected %d\n", self->count); - exit(1); + exit(1); } - =} + =} } main reactor CompositionAfter(delay:time(5 sec)) { s = new Source(); d = new Test(); s.y -> d.x after delay; -} \ No newline at end of file +} diff --git a/test/C/src/CompositionGain.lf b/test/C/src/CompositionGain.lf index 3b79f65557..39be56cf43 100644 --- a/test/C/src/CompositionGain.lf +++ b/test/C/src/CompositionGain.lf @@ -18,7 +18,7 @@ reactor Wrapper { main reactor CompositionGain { wrapper = new Wrapper(); reaction(startup) -> wrapper.x {= - lf_set(wrapper.x, 42); + lf_set(wrapper.x, 42); =} reaction(wrapper.y) {= printf("Received %d\n", wrapper.y->value); @@ -27,4 +27,4 @@ main reactor CompositionGain { exit(2); } =} -} \ No newline at end of file +} diff --git a/test/C/src/CompositionInheritance.lf b/test/C/src/CompositionInheritance.lf index 5dde90a29a..568a7aa3d5 100644 --- a/test/C/src/CompositionInheritance.lf +++ b/test/C/src/CompositionInheritance.lf @@ -31,9 +31,9 @@ reactor Test { reaction(x) {= (self->count)++; printf("Received %d\n", x->value); - if (x->value != self->count) { + if (x->value != self->count) { fprintf(stderr, "FAILURE: Expected %d\n", self->count); - exit(1); + exit(1); } =} reaction(shutdown) {= @@ -44,7 +44,7 @@ reactor Test { } main reactor CompositionInheritance { s = new SourceExtended(period = 2 sec); - + d = new Test(); s.y2 -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/CountSelf.lf b/test/C/src/CountSelf.lf index 71efb079c0..c0e7429352 100644 --- a/test/C/src/CountSelf.lf +++ b/test/C/src/CountSelf.lf @@ -17,9 +17,8 @@ reactor CountSelf2(delay:time(100 msec)) { lf_schedule_int(a, self->delay, a->value + 1); =} } -main reactor { +main reactor { d = new CountSelf2(); t = new TestCount(num_inputs = 11, start = 0); - d.out -> t.in; + d.out -> t.in; } - diff --git a/test/C/src/CountTest.lf b/test/C/src/CountTest.lf index c5ec6436a1..5aa1e6eed0 100644 --- a/test/C/src/CountTest.lf +++ b/test/C/src/CountTest.lf @@ -12,5 +12,3 @@ main reactor CountTest { test = new TestCount(num_inputs = 4); count.out -> test.in; } - - diff --git a/test/C/src/DanglingOutput.lf b/test/C/src/DanglingOutput.lf index 5919ea3efd..d7625c697e 100644 --- a/test/C/src/DanglingOutput.lf +++ b/test/C/src/DanglingOutput.lf @@ -22,4 +22,4 @@ main reactor DanglingOutput { source = new Source(); container = new Gain(); source.out -> container.in; -} \ No newline at end of file +} diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index 49588827b3..890944971a 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -49,4 +49,4 @@ main reactor Deadline { s = new Source(); d = new Destination(timeout = 1 sec); s.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/DeadlineAnytime.lf b/test/C/src/DeadlineAnytime.lf index 9f7f3c4c5d..e6760e4546 100644 --- a/test/C/src/DeadlineAnytime.lf +++ b/test/C/src/DeadlineAnytime.lf @@ -27,4 +27,3 @@ reactor A { main reactor { a = new A(); } - diff --git a/test/C/src/DelayArray.lf b/test/C/src/DelayArray.lf index 38cfa1da65..e39c4764d8 100644 --- a/test/C/src/DelayArray.lf +++ b/test/C/src/DelayArray.lf @@ -17,7 +17,7 @@ reactor Source { reaction(startup) -> out {= // Dynamically allocate an output array of length 3. SET_NEW_ARRAY(out, 3); - + // Above allocates the array, which then must be populated. out->value[0] = 0; out->value[1] = 1; diff --git a/test/C/src/DelayArrayWithAfter.lf b/test/C/src/DelayArrayWithAfter.lf index 40c94c887e..cf0aaec393 100644 --- a/test/C/src/DelayArrayWithAfter.lf +++ b/test/C/src/DelayArrayWithAfter.lf @@ -11,8 +11,8 @@ reactor Source { reaction(t) -> out {= // Dynamically allocate an output array of length 3. SET_NEW_ARRAY(out, 3); - printf("At time %lld, sending array at address %p\n", lf_time_logical_elapsed(), out->value); - + printf("At time %lld, sending array at address %p\n", lf_time_logical_elapsed(), out->value); + // Above allocates the array, which then must be populated. out->value[0] = 1 * self->iteration; out->value[1] = 2 * self->iteration; diff --git a/test/C/src/DelayInt.lf b/test/C/src/DelayInt.lf index 219f8239bd..c6d047890c 100644 --- a/test/C/src/DelayInt.lf +++ b/test/C/src/DelayInt.lf @@ -19,7 +19,7 @@ reactor Test { reaction(startup) {= // Record the logical time at the start. self->start_time = lf_time_logical(); - =} + =} reaction(in) {= printf("Received: %d.\n", in->value); self->received_value = true; @@ -33,23 +33,23 @@ reactor Test { } if (in->value != 42) { printf("ERROR: Expected input value to be 42. It was %d.\n", in->value); - exit(2); + exit(2); } =} reaction(shutdown) {= printf("Checking that communication occurred.\n"); if (!self->received_value) { printf("ERROR: No communication occurred!\n"); - exit(3); + exit(3); } =} } -main reactor DelayInt { +main reactor DelayInt { d = new Delay(); t = new Test(); - d.out -> t.in; + d.out -> t.in; reaction(startup) -> d.in {= lf_set(d.in, 42); =} -} \ No newline at end of file +} diff --git a/test/C/src/DelayPointer.lf b/test/C/src/DelayPointer.lf index 6d7a70b6b5..55ac36c51c 100644 --- a/test/C/src/DelayPointer.lf +++ b/test/C/src/DelayPointer.lf @@ -29,7 +29,7 @@ reactor Test { reaction(startup) {= // Record the logical time at the start. self->start_time = lf_time_logical(); - =} + =} reaction(in) {= printf("Received: %d.\n", *(in->value)); self->received_value = true; @@ -43,22 +43,22 @@ reactor Test { } if (*(in->value) != 42) { printf("ERROR: Expected input value to be 42. It was %d.\n", *(in->value)); - exit(2); + exit(2); } =} reaction(shutdown) {= printf("Checking that communication occurred.\n"); if (!self->received_value) { printf("ERROR: No communication occurred!\n"); - exit(3); + exit(3); } =} } -main reactor { +main reactor { s = new Source(); d = new DelayPointer2(); t = new Test(); s.out -> d.in; - d.out -> t.in; -} \ No newline at end of file + d.out -> t.in; +} diff --git a/test/C/src/DelayString.lf b/test/C/src/DelayString.lf index 239535adf8..8830aa7730 100644 --- a/test/C/src/DelayString.lf +++ b/test/C/src/DelayString.lf @@ -27,16 +27,16 @@ reactor Test { } if (strcmp(in->value, "Hello") != 0) { printf("ERROR: Expected input value to be \"Hello\". It was \"%s\".\n", in->value); - exit(2); + exit(2); } =} } -main reactor { +main reactor { d = new DelayString2(); t = new Test(); - d.out -> t.in; + d.out -> t.in; reaction(startup) -> d.in {= lf_set(d.in, "Hello"); =} -} \ No newline at end of file +} diff --git a/test/C/src/DelayStruct.lf b/test/C/src/DelayStruct.lf index ad7286ab98..977bdf3bb0 100644 --- a/test/C/src/DelayStruct.lf +++ b/test/C/src/DelayStruct.lf @@ -25,7 +25,7 @@ reactor Source { reaction(startup) -> out {= // Dynamically allocate an output struct. SET_NEW(out); - + // Above allocates a struct, which then must be populated. out->value->name = "Earth"; out->value->value = 42; diff --git a/test/C/src/DelayStructWithAfter.lf b/test/C/src/DelayStructWithAfter.lf index 940f93841b..edb5a6baf9 100644 --- a/test/C/src/DelayStructWithAfter.lf +++ b/test/C/src/DelayStructWithAfter.lf @@ -10,7 +10,7 @@ reactor Source { reaction(startup) -> out {= // Dynamically allocate an output struct. SET_NEW(out); - + // Above allocates a struct, which then must be populated. out->value->name = "Earth"; out->value->value = 42; diff --git a/test/C/src/DelayStructWithAfterOverlapped.lf b/test/C/src/DelayStructWithAfterOverlapped.lf index 78f6970a4a..a93c819588 100644 --- a/test/C/src/DelayStructWithAfterOverlapped.lf +++ b/test/C/src/DelayStructWithAfterOverlapped.lf @@ -17,7 +17,7 @@ reactor Source { self->s++; // Dynamically allocate an output struct. SET_NEW(out); - + // Above allocates a struct, which then must be populated. out->value->name = "Earth"; out->value->value = 42 * self->s; diff --git a/test/C/src/DelayedAction.lf b/test/C/src/DelayedAction.lf index 04bcc7fa42..455cf4373c 100644 --- a/test/C/src/DelayedAction.lf +++ b/test/C/src/DelayedAction.lf @@ -9,7 +9,7 @@ main reactor DelayedAction { reaction(t) -> a {= lf_schedule(a, MSEC(100)); =} - + reaction(a) {= interval_t elapsed = lf_time_logical_elapsed(); interval_t elapsed_physical = lf_time_physical_elapsed(); @@ -22,4 +22,4 @@ main reactor DelayedAction { exit(1); } =} -} \ No newline at end of file +} diff --git a/test/C/src/DelayedReaction.lf b/test/C/src/DelayedReaction.lf index 577f073c03..c58a9bd3db 100644 --- a/test/C/src/DelayedReaction.lf +++ b/test/C/src/DelayedReaction.lf @@ -6,8 +6,8 @@ reactor Source { timer t; reaction(t) -> out {= lf_set(out, 1); - =} -} + =} +} reactor Sink { input in:int; reaction(in) {= @@ -16,12 +16,12 @@ reactor Sink { if (elapsed != 100000000LL) { printf("ERROR: Expected 100000000 but.\n"); exit(1); - } + } =} } main reactor DelayedReaction { - + source = new Source(); sink = new Sink(); source.out -> sink.in after 100 msec; -} \ No newline at end of file +} diff --git a/test/C/src/Determinism.lf b/test/C/src/Determinism.lf index 653acee409..cfd35308d7 100644 --- a/test/C/src/Determinism.lf +++ b/test/C/src/Determinism.lf @@ -5,7 +5,7 @@ reactor Source { reaction(t) -> y {= lf_set(y, 1); =} -} +} reactor Destination { input x:int; input y:int; @@ -41,4 +41,4 @@ main reactor Determinism { s.y -> p1.x; p1.y -> p2.x; p2.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/DoubleInvocation.lf b/test/C/src/DoubleInvocation.lf index 87cdcd7ddd..4b66006156 100644 --- a/test/C/src/DoubleInvocation.lf +++ b/test/C/src/DoubleInvocation.lf @@ -20,7 +20,7 @@ reactor Ball { timer trigger(0, 1 sec); reaction(trigger) -> position, velocity {= lf_set(position, self->p); - lf_set(velocity, -1); + lf_set(velocity, -1); self->p -= 1; =} } @@ -49,4 +49,4 @@ main reactor DoubleInvocation { b1.velocity -> p.velocity; b1.position -> plot.position; b1.velocity -> plot.velocity; -} \ No newline at end of file +} diff --git a/test/C/src/DoublePort.lf b/test/C/src/DoublePort.lf index c1ba1b8e12..b0d6afbb80 100644 --- a/test/C/src/DoublePort.lf +++ b/test/C/src/DoublePort.lf @@ -1,10 +1,10 @@ -/** +/** * Test the case where two upstream reactors * pass messages to a downstream reactor on two * different ports. One message carries * a microstep delay relative to the other. - * - * @author Soroush Bateni + * + * @author Soroush Bateni */ target C { timeout: 900 msec, @@ -21,7 +21,7 @@ reactor CountMicrostep { reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} - + reaction(act) -> out {= lf_set(out, act->value); =} @@ -38,7 +38,7 @@ reactor Print { exit(1); } =} - + reaction(shutdown) {= printf("SUCCESS: messages were at least one microstep apart.\n"); =} @@ -51,4 +51,3 @@ main reactor DoublePort { c.out -> p.in; cm.out -> p.in2; } - diff --git a/test/C/src/DoubleReaction.lf b/test/C/src/DoubleReaction.lf index 2d8e33187f..dfa6a913d3 100644 --- a/test/C/src/DoubleReaction.lf +++ b/test/C/src/DoubleReaction.lf @@ -41,4 +41,4 @@ main reactor DoubleReaction { d = new Destination(); c1.y -> d.x; c2.y -> d.w; -} \ No newline at end of file +} diff --git a/test/C/src/DoubleTrigger.lf b/test/C/src/DoubleTrigger.lf index fecd8b96e5..e8cf8e5a88 100644 --- a/test/C/src/DoubleTrigger.lf +++ b/test/C/src/DoubleTrigger.lf @@ -1,4 +1,4 @@ -// Test that two simultaneous triggers don't cause +// Test that two simultaneous triggers don't cause // a reaction to execute twice at the same tag. target C { timeout: 1 sec, @@ -16,7 +16,7 @@ main reactor DoubleTrigger { } =} reaction(shutdown) {= - if (self->s == 1) { + if (self->s == 1) { printf("SUCCESS.\n"); } else { printf("FAILURE: Reaction was never triggered.\n"); diff --git a/test/C/src/Gain.lf b/test/C/src/Gain.lf index 93c270a5f0..05e6210974 100644 --- a/test/C/src/Gain.lf +++ b/test/C/src/Gain.lf @@ -33,4 +33,4 @@ reaction(startup) -> g.x {= lf_set(g.x, 1); =} - } \ No newline at end of file + } diff --git a/test/C/src/GetMicroStep.lf b/test/C/src/GetMicroStep.lf index d50251628d..0eca6c6843 100644 --- a/test/C/src/GetMicroStep.lf +++ b/test/C/src/GetMicroStep.lf @@ -1,4 +1,4 @@ -// Tests the lf_tag().microstep function in the C target. +// Tests the lf_tag().microstep function in the C target. target C; main reactor GetMicroStep { state s:int(1); @@ -18,4 +18,4 @@ main reactor GetMicroStep { lf_schedule(l, 0); } =} -} \ No newline at end of file +} diff --git a/test/C/src/GetTime.lf b/test/C/src/GetTime.lf index 7d29bcc414..6988aec45b 100644 --- a/test/C/src/GetTime.lf +++ b/test/C/src/GetTime.lf @@ -12,13 +12,13 @@ main reactor GetTime { interval_t elapsed = lf_time_logical_elapsed(); printf("Elapsed logical time is %lld.\n", elapsed); - + instant_t physical = lf_time_physical(); printf("Physical time is %lld.\n", physical); instant_t elapsed_physical = lf_time_physical_elapsed(); printf("Elapsed physical time is %lld.\n", elapsed_physical); - + printf("Time lag is %lld.\n", physical - logical); =} -} \ No newline at end of file +} diff --git a/test/C/src/Hello.lf b/test/C/src/Hello.lf index 0c0ace8aa0..63b51f4b6f 100644 --- a/test/C/src/Hello.lf +++ b/test/C/src/Hello.lf @@ -37,12 +37,12 @@ reactor Reschedule(period:time(2 secs), message:string("Hello C")) { exit(1); } =} -} +} reactor Inside(period:time(1 sec), message:string("Composite default message.")) { third_instance = new Reschedule(period = period, message = message); } -main reactor Hello { +main reactor Hello { first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); second_instance = new Reschedule(message = "Hello from second_instance."); composite_instance = new Inside(message = "Hello from composite_instance."); -} \ No newline at end of file +} diff --git a/test/C/src/HelloWorld.lf b/test/C/src/HelloWorld.lf index b87509fd95..e85fd19c23 100644 --- a/test/C/src/HelloWorld.lf +++ b/test/C/src/HelloWorld.lf @@ -20,4 +20,4 @@ reactor HelloWorld2 { main reactor HelloWorld { a = new HelloWorld2(); -} \ No newline at end of file +} diff --git a/test/C/src/Hierarchy.lf b/test/C/src/Hierarchy.lf index 97f401794e..bb41461ef3 100644 --- a/test/C/src/Hierarchy.lf +++ b/test/C/src/Hierarchy.lf @@ -38,8 +38,8 @@ main reactor Hierarchy { source = new Source(); container = new GainContainer(); print = new Print(); - print2 = new Print(); + print2 = new Print(); source.out -> container.in; container.out -> print.in; container.out -> print2.in; -} \ No newline at end of file +} diff --git a/test/C/src/Hierarchy2.lf b/test/C/src/Hierarchy2.lf index 4d7f311022..d6146c70d6 100644 --- a/test/C/src/Hierarchy2.lf +++ b/test/C/src/Hierarchy2.lf @@ -57,4 +57,4 @@ main reactor Hierarchy2 { print = new Print(); source.out -> addCount.in; addCount.out -> print.in; -} \ No newline at end of file +} diff --git a/test/C/src/IdentifierLength.lf b/test/C/src/IdentifierLength.lf index c33a5316b4..42558cced8 100644 --- a/test/C/src/IdentifierLength.lf +++ b/test/C/src/IdentifierLength.lf @@ -19,14 +19,14 @@ reactor Another_Really_Long_Name_For_A_Test_Class { reaction(x) {= (self->count)++; printf("Received %d\n", x->value); - if (x->value != self->count) { + if (x->value != self->count) { printf("FAILURE: Expected %d\n", self->count); - exit(1); + exit(1); } - =} + =} } main reactor IdentifierLength { a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source(); another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class(); a_really_long_name_for_a_source_instance.y -> another_really_long_name_for_a_test_instance.x; -} \ No newline at end of file +} diff --git a/test/C/src/Import.lf b/test/C/src/Import.lf index b8a739b291..33fabaeb45 100644 --- a/test/C/src/Import.lf +++ b/test/C/src/Import.lf @@ -6,6 +6,6 @@ main reactor Import { timer t; a = new Imported(); reaction(t) -> a.x {= - lf_set(a.x, 42); + lf_set(a.x, 42); =} } diff --git a/test/C/src/ImportComposition.lf b/test/C/src/ImportComposition.lf index 25721d435a..2fe2650eaa 100644 --- a/test/C/src/ImportComposition.lf +++ b/test/C/src/ImportComposition.lf @@ -7,7 +7,7 @@ main reactor ImportComposition { a = new ImportedComposition(); state received:bool(false); reaction(startup) -> a.x {= - lf_set(a.x, 42); + lf_set(a.x, 42); =} reaction(a.y) {= interval_t receive_time = lf_time_logical_elapsed(); diff --git a/test/C/src/ImportRenamed.lf b/test/C/src/ImportRenamed.lf index 6990ccf4da..d1a1042629 100644 --- a/test/C/src/ImportRenamed.lf +++ b/test/C/src/ImportRenamed.lf @@ -9,8 +9,8 @@ main reactor { a = new X(); b = new Y(); c = new Z(); - + reaction(t) -> a.x {= - lf_set(a.x, 42); + lf_set(a.x, 42); =} } diff --git a/test/C/src/InheritanceAction.lf b/test/C/src/InheritanceAction.lf index 0e6b01c4ad..85295c6632 100644 --- a/test/C/src/InheritanceAction.lf +++ b/test/C/src/InheritanceAction.lf @@ -23,9 +23,9 @@ reactor Test { reaction(x) {= (self->count)++; printf("Received %d\n", x->value); - if (x->value != 42) { + if (x->value != 42) { fprintf(stderr, "FAILURE: Expected 42\n"); - exit(1); + exit(1); } =} reaction(shutdown) {= @@ -38,4 +38,4 @@ main reactor { s = new SourceExtended(); d = new Test(); s.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/ManualDelayedReaction.lf b/test/C/src/ManualDelayedReaction.lf index c93824ef13..d8b9e301c7 100644 --- a/test/C/src/ManualDelayedReaction.lf +++ b/test/C/src/ManualDelayedReaction.lf @@ -32,7 +32,7 @@ reactor Source { // reaction(t) -> out after 100 msec {= reaction(t) -> out {= lf_set(out, 1); - =} + =} } reactor Sink { diff --git a/test/C/src/Microsteps.lf b/test/C/src/Microsteps.lf index a95d9414fe..0a7616d07c 100644 --- a/test/C/src/Microsteps.lf +++ b/test/C/src/Microsteps.lf @@ -35,4 +35,4 @@ main reactor Microsteps { reaction(repeat) -> d.y {= lf_set(d.y, 1); =} -} \ No newline at end of file +} diff --git a/test/C/src/Minimal.lf b/test/C/src/Minimal.lf index 3fbd9cc948..4b0a72aa82 100644 --- a/test/C/src/Minimal.lf +++ b/test/C/src/Minimal.lf @@ -4,5 +4,5 @@ main reactor Minimal { reaction(startup) {= printf("Hello World.\n"); =} - + } diff --git a/test/C/src/MovingAverage.lf b/test/C/src/MovingAverage.lf index 14fed26e5f..e7bc27d089 100644 --- a/test/C/src/MovingAverage.lf +++ b/test/C/src/MovingAverage.lf @@ -22,7 +22,7 @@ reactor MovingAverageImpl { state index:int(0); input in:double; output out:double; - + reaction(in) -> out {= // Calculate the output. double sum = in->value; @@ -48,4 +48,4 @@ main reactor MovingAverage { p = new TestDouble(expected=(0.0, 0.25, 0.75, 1.5, 2.5, 3.5)); s.out -> m.in; m.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/NativeListsAndTimes.lf b/test/C/src/NativeListsAndTimes.lf index f77a2820d2..4218f5d088 100644 --- a/test/C/src/NativeListsAndTimes.lf +++ b/test/C/src/NativeListsAndTimes.lf @@ -2,10 +2,10 @@ target C; // This test passes if it is successfully compiled into valid target code. -main reactor(x:int(0), +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 + p:int[](1, 2, 3, 4), // List of integers q:interval_t[](1 msec, 2 msec, 3 msec), // list of time values r:time({=0=}), // Zero-valued target code also is a valid time g:time[](1 msec, 2 msec) // List of time values @@ -22,4 +22,4 @@ main reactor(x:int(0), reaction(tick) {= // Target code =} -} \ No newline at end of file +} diff --git a/test/C/src/ParameterHierarchy.lf b/test/C/src/ParameterHierarchy.lf index 72262f7ada..77faeb495c 100644 --- a/test/C/src/ParameterHierarchy.lf +++ b/test/C/src/ParameterHierarchy.lf @@ -17,4 +17,4 @@ reactor Another(p:int(20)) { } main reactor ParameterHierarchy { a = new Intermediate(p = 42); -} \ No newline at end of file +} diff --git a/test/C/src/ParameterizedState.lf b/test/C/src/ParameterizedState.lf index 07033c98b3..028ce86262 100644 --- a/test/C/src/ParameterizedState.lf +++ b/test/C/src/ParameterizedState.lf @@ -2,11 +2,11 @@ target C; reactor Foo(bar:int(42)) { state baz(bar); - + reaction (startup) {= printf("Baz: %d\n", self->baz); =} } main reactor { a = new Foo(); -} \ No newline at end of file +} diff --git a/test/C/src/PeriodicDesugared.lf b/test/C/src/PeriodicDesugared.lf index 24c105499e..3dc7b23ec7 100644 --- a/test/C/src/PeriodicDesugared.lf +++ b/test/C/src/PeriodicDesugared.lf @@ -4,11 +4,11 @@ target C { }; main reactor ( - offset:time(0), + offset:time(0), period:time(500 msec)) { logical action init(offset); logical action recur(period); - + reaction(startup) -> init, recur {= if (self->offset == 0) { printf("Hello World!\n"); @@ -17,7 +17,7 @@ main reactor ( lf_schedule(init, 0); } =} - + reaction(init, recur) -> recur {= printf("Hello World!\n"); lf_schedule(recur, 0); diff --git a/test/C/src/PhysicalConnection.lf b/test/C/src/PhysicalConnection.lf index 715d17d1dd..20d213d37d 100644 --- a/test/C/src/PhysicalConnection.lf +++ b/test/C/src/PhysicalConnection.lf @@ -20,5 +20,5 @@ reactor Destination { main reactor PhysicalConnection { source = new Source(); destination = new Destination(); - source.out ~> destination.in; -} \ No newline at end of file + source.out ~> destination.in; +} diff --git a/test/C/src/PingPong.lf b/test/C/src/PingPong.lf index 3d62082713..d01783627e 100644 --- a/test/C/src/PingPong.lf +++ b/test/C/src/PingPong.lf @@ -3,22 +3,22 @@ * intended to measure message-passing overhead. * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * Ping introduces a microstep delay using a logical action * to break the causality loop. - * + * * To get a sense, some (informal) results for 1,000,000 ping-pongs * on my Mac: - * + * * Unthreaded: 97 msec * Threaded: 265 msec - * + * * There is no parallelism in this application, so it does not benefit from being * being threaded, just some additional overhead. - * + * * These measurements are total execution time, including startup and shutdown. * These are about an order of magnitude faster than anything reported in the paper. - * + * * @author Edward A. Lee */ target C { @@ -29,7 +29,7 @@ reactor Ping(count:int(10)) { output send:int; state pingsLeft:int(count); logical action serve; - reaction (startup, serve) -> send {= + reaction (startup, serve) -> send {= lf_set(send, self->pingsLeft--); =} reaction (receive) -> serve {= @@ -46,7 +46,7 @@ reactor Pong(expected:int(10)) { state count:int(0); reaction(receive) -> send {= self->count++; - lf_set(send, receive->value); + lf_set(send, receive->value); =} reaction(shutdown) {= if (self->count != self->expected) { @@ -63,5 +63,5 @@ main reactor PingPong { ping = new Ping(); pong = new Pong(); ping.send -> pong.receive; - pong.send -> ping.receive; -} \ No newline at end of file + pong.send -> ping.receive; +} diff --git a/test/C/src/Preamble.lf b/test/C/src/Preamble.lf index fc33e20711..875757e2f4 100644 --- a/test/C/src/Preamble.lf +++ b/test/C/src/Preamble.lf @@ -16,4 +16,4 @@ main reactor Preamble { printf("Converted string %s to int %d.\n", s, i); printf("42 plus 42 is %d.\n", add_42(42)); =} -} \ No newline at end of file +} diff --git a/test/C/src/ReadOutputOfContainedReactor.lf b/test/C/src/ReadOutputOfContainedReactor.lf index ded5223b8a..a18c29d4ca 100644 --- a/test/C/src/ReadOutputOfContainedReactor.lf +++ b/test/C/src/ReadOutputOfContainedReactor.lf @@ -43,4 +43,4 @@ main reactor ReadOutputOfContainedReactor { printf("Test passes.\n"); } =} -} \ No newline at end of file +} diff --git a/test/C/src/Schedule.lf b/test/C/src/Schedule.lf index 03c965b1cb..5ad4b3d718 100644 --- a/test/C/src/Schedule.lf +++ b/test/C/src/Schedule.lf @@ -21,4 +21,4 @@ main reactor { reaction(t) -> a.x {= lf_set(a.x, 1); =} -} \ No newline at end of file +} diff --git a/test/C/src/ScheduleLogicalAction.lf b/test/C/src/ScheduleLogicalAction.lf index 94f41dd237..37e9e08bc0 100644 --- a/test/C/src/ScheduleLogicalAction.lf +++ b/test/C/src/ScheduleLogicalAction.lf @@ -40,4 +40,4 @@ main reactor { lf_set(f.x, 42); =} f.y -> p.x; -} \ No newline at end of file +} diff --git a/test/C/src/ScheduleValue.lf b/test/C/src/ScheduleValue.lf index 2ee31895d9..2227235dae 100644 --- a/test/C/src/ScheduleValue.lf +++ b/test/C/src/ScheduleValue.lf @@ -16,4 +16,4 @@ main reactor ScheduleValue { exit(1); } =} -} \ No newline at end of file +} diff --git a/test/C/src/SendingInside.lf b/test/C/src/SendingInside.lf index 198c09bd11..155a8e83fe 100644 --- a/test/C/src/SendingInside.lf +++ b/test/C/src/SendingInside.lf @@ -24,4 +24,4 @@ main reactor SendingInside { (self->count)++; lf_set(p.x, self->count); =} -} \ No newline at end of file +} diff --git a/test/C/src/SendsPointerTest.lf b/test/C/src/SendsPointerTest.lf index cd640ef920..00466a3fff 100644 --- a/test/C/src/SendsPointerTest.lf +++ b/test/C/src/SendsPointerTest.lf @@ -26,4 +26,4 @@ main reactor SendsPointerTest { s = new SendsPointer(); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/SetArray.lf b/test/C/src/SetArray.lf index a58b2c90fe..fcc0312894 100644 --- a/test/C/src/SetArray.lf +++ b/test/C/src/SetArray.lf @@ -8,7 +8,7 @@ reactor Source { // Dynamically allocate an output array of length 3. int* array = (int*)malloc(3 * sizeof(int)); SET_ARRAY(out, array, sizeof(int), 3); - + // Above allocates the array, which then must be populated. out->value[0] = 0; out->value[1] = 1; diff --git a/test/C/src/SetToken.lf b/test/C/src/SetToken.lf index a9752732cf..9fa13875cd 100644 --- a/test/C/src/SetToken.lf +++ b/test/C/src/SetToken.lf @@ -25,4 +25,4 @@ main reactor SetToken { s = new Source(); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/SimpleDeadline.lf b/test/C/src/SimpleDeadline.lf index 63fe4f1c8a..3de7cc3ec5 100644 --- a/test/C/src/SimpleDeadline.lf +++ b/test/C/src/SimpleDeadline.lf @@ -31,4 +31,4 @@ main reactor SimpleDeadline { lf_nanosleep(sleep_time_ns); lf_set(d.x, 42); =} -} \ No newline at end of file +} diff --git a/test/C/src/SimpleImport.lf b/test/C/src/SimpleImport.lf index c5e11547c7..37e5715a86 100644 --- a/test/C/src/SimpleImport.lf +++ b/test/C/src/SimpleImport.lf @@ -4,4 +4,4 @@ import HelloWorld2 from "HelloWorld.lf"; main reactor SimpleImport { a = new HelloWorld2(); b = new HelloWorld2(); -} \ No newline at end of file +} diff --git a/test/C/src/SlowingClock.lf b/test/C/src/SlowingClock.lf index 31bd9facbf..16b32f9951 100644 --- a/test/C/src/SlowingClock.lf +++ b/test/C/src/SlowingClock.lf @@ -1,6 +1,6 @@ -/** +/** * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a logical action with a minimum delay of 100 msec. + * msec on a logical action with a minimum delay of 100 msec. * The use of the logical action ensures the elapsed time jumps exactly from * 0 to 100, 300, 600, and 1000 msec. */ @@ -34,7 +34,7 @@ main reactor SlowingClock { if (self->expected_time != MSEC(1500)) { printf("ERROR: Expected the next expected time to be: 1500000000 nsec.\n"); printf("It was: \%lld nsec.\n", self->expected_time); - exit(2); + exit(2); } else { printf("Test passes.\n"); } diff --git a/test/C/src/SlowingClockPhysical.lf b/test/C/src/SlowingClockPhysical.lf index a1f7b81c56..1bf257f54d 100644 --- a/test/C/src/SlowingClockPhysical.lf +++ b/test/C/src/SlowingClockPhysical.lf @@ -1,8 +1,8 @@ -/** +/** /* * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a physical action with a minimum delay of 100 msec. - * The use of the physical action makes the elapsed time jumps from 0 to + * msec on a physical action with a minimum delay of 100 msec. + * The use of the physical action makes the elapsed time jumps from 0 to * approximately 100 msec, to approximatly 300 msec thereafter, drifting away * further with each new event. */ @@ -37,7 +37,7 @@ main reactor SlowingClockPhysical { if (self->expected_time < MSEC(500)) { printf("ERROR: Expected the next expected time to be at least: 500000000 nsec.\n"); printf("It was: \%lld nsec.\n", self->expected_time); - exit(2); + exit(2); } =} } diff --git a/test/C/src/Starvation.lf b/test/C/src/Starvation.lf index bc03600eb8..ea04967a04 100644 --- a/test/C/src/Starvation.lf +++ b/test/C/src/Starvation.lf @@ -1,66 +1,66 @@ -/** - * Test that the starvation functionality in absence of - * the "keepalive: true" target property indeed works as - * expected. - * - * @author Soroush Bateni - */ - target C; - reactor SuperDenseSender(number_of_iterations:int(10)){ - logical action loop; - output out:int; - state iterator:int(0); - reaction(startup, loop) -> out {= - if (self->iterator < self->number_of_iterations) { - lf_schedule(loop, 0); - } - self->iterator++; - lf_set(out, 42); - =} - - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == start_time - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Sender successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - start_time, - current_tag.microstep); - exit(1); - } - =} - } - - reactor SuperDenseReceiver(number_of_iterations:int(10)) { - input in:int; - reaction(in) {= - tag_t current_tag = lf_tag(); - printf("Received %d at tag (%lld, %u).\n", - in->value, - current_tag.time - start_time, - current_tag.microstep); - =} - - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == start_time - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Receiver successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - start_time, - current_tag.microstep); - exit(1); - } - =} -} - -main reactor Starvation { - sender = new SuperDenseSender(); - receiver = new SuperDenseReceiver(); - - sender.out -> receiver.in; -} \ No newline at end of file +/** + * Test that the starvation functionality in absence of + * the "keepalive: true" target property indeed works as + * expected. + * + * @author Soroush Bateni + */ + target C; + reactor SuperDenseSender(number_of_iterations:int(10)){ + logical action loop; + output out:int; + state iterator:int(0); + reaction(startup, loop) -> out {= + if (self->iterator < self->number_of_iterations) { + lf_schedule(loop, 0); + } + self->iterator++; + lf_set(out, 42); + =} + + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == start_time + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Sender successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - start_time, + current_tag.microstep); + exit(1); + } + =} + } + + reactor SuperDenseReceiver(number_of_iterations:int(10)) { + input in:int; + reaction(in) {= + tag_t current_tag = lf_tag(); + printf("Received %d at tag (%lld, %u).\n", + in->value, + current_tag.time - start_time, + current_tag.microstep); + =} + + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == start_time + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Receiver successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - start_time, + current_tag.microstep); + exit(1); + } + =} +} + +main reactor Starvation { + sender = new SuperDenseSender(); + receiver = new SuperDenseReceiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/Stop.lf b/test/C/src/Stop.lf index d741e89ac5..cba17dffd9 100644 --- a/test/C/src/Stop.lf +++ b/test/C/src/Stop.lf @@ -1,61 +1,61 @@ -/* - * A test for the lf_request_stop() functionality in Lingua Franca. - * - * @author Soroush Bateni - */ - target C { - timeout: 11 msec -}; - -import Sender from "lib/LoopedActionSender.lf" - -reactor Consumer { - input in:int; - state reaction_invoked_correctly:bool(false); - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - // The reaction should not have been called at tags larger than (10 msec, 9) - fprintf(stderr, "ERROR: Invoked reaction(in) at tag bigger than shutdown.\n"); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { - // Call lf_request_stop() at relative tag (10 msec, 8) - printf("Requesting stop.\n"); - lf_request_stop(); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { - // Check that this reaction is indeed also triggered at (10 msec, 9) - self->reaction_invoked_correctly = true; - } - =} - - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - // Check to see if shutdown is called at relative tag (10 msec, 9) - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && - self->reaction_invoked_correctly == true) { - printf("SUCCESS: successfully enforced stop.\n"); - } else if(lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); - } else if (self->reaction_invoked_correctly == false) { - // Check to see if reactions were called correctly - fprintf(stderr,"ERROR: Failed to invoke reaction(in) at tag (%llu, %d).\n", - current_tag.time - lf_time_start(), current_tag.microstep); - exit(1); - } - =} -} - -main reactor { - consumer = new Consumer(); - producer = new Sender(break_interval = 1 msec); - - producer.out -> consumer.in; -} \ No newline at end of file +/* + * A test for the lf_request_stop() functionality in Lingua Franca. + * + * @author Soroush Bateni + */ + target C { + timeout: 11 msec +}; + +import Sender from "lib/LoopedActionSender.lf" + +reactor Consumer { + input in:int; + state reaction_invoked_correctly:bool(false); + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + // The reaction should not have been called at tags larger than (10 msec, 9) + fprintf(stderr, "ERROR: Invoked reaction(in) at tag bigger than shutdown.\n"); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { + // Call lf_request_stop() at relative tag (10 msec, 8) + printf("Requesting stop.\n"); + lf_request_stop(); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { + // Check that this reaction is indeed also triggered at (10 msec, 9) + self->reaction_invoked_correctly = true; + } + =} + + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + // Check to see if shutdown is called at relative tag (10 msec, 9) + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && + self->reaction_invoked_correctly == true) { + printf("SUCCESS: successfully enforced stop.\n"); + } else if(lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time - lf_time_start(), current_tag.microstep); + exit(1); + } else if (self->reaction_invoked_correctly == false) { + // Check to see if reactions were called correctly + fprintf(stderr,"ERROR: Failed to invoke reaction(in) at tag (%llu, %d).\n", + current_tag.time - lf_time_start(), current_tag.microstep); + exit(1); + } + =} +} + +main reactor { + consumer = new Consumer(); + producer = new Sender(break_interval = 1 msec); + + producer.out -> consumer.in; +} diff --git a/test/C/src/StopZero.lf b/test/C/src/StopZero.lf index e1556797bd..a5d9da364f 100644 --- a/test/C/src/StopZero.lf +++ b/test/C/src/StopZero.lf @@ -1,103 +1,103 @@ -/** - * Test for lf_request_stop() at tag (0,0). - * This also tests for logically simultaneous calls - * to lf_request_stop(). - * - * @author Soroush Bateni - */ -target C; - -reactor Sender { - output out:int; - state reaction_invoked_correctly:bool(false); - timer t(0, 1 usec); - logical action act; - reaction(t) -> out, act {= - printf("Sending 42 at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); - lf_schedule(act, 0); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } else if (lf_tag_compare(lf_tag(), one) > 0) { - fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - =} - reaction(act) {= - // Reaction should be invoked at (0,1) - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), one) == 0) { - self->reaction_invoked_correctly = true; - } - =} - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Sender failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } else if (self->reaction_invoked_correctly == false) { - fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -reactor Receiver { - input in:int; - reaction(in) {= - printf("Received %d at (%lld, %u).\n", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} - - reaction(shutdown) {= - // Shutdown events must occur at (0, 1) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -main reactor StopZero { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in; -} \ No newline at end of file +/** + * Test for lf_request_stop() at tag (0,0). + * This also tests for logically simultaneous calls + * to lf_request_stop(). + * + * @author Soroush Bateni + */ +target C; + +reactor Sender { + output out:int; + state reaction_invoked_correctly:bool(false); + timer t(0, 1 usec); + logical action act; + reaction(t) -> out, act {= + printf("Sending 42 at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); + lf_schedule(act, 0); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } else if (lf_tag_compare(lf_tag(), one) > 0) { + fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + =} + reaction(act) {= + // Reaction should be invoked at (0,1) + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), one) == 0) { + self->reaction_invoked_correctly = true; + } + =} + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Sender failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } else if (self->reaction_invoked_correctly == false) { + fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +reactor Receiver { + input in:int; + reaction(in) {= + printf("Received %d at (%lld, %u).\n", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} + + reaction(shutdown) {= + // Shutdown events must occur at (0, 1) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +main reactor StopZero { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/Stride.lf b/test/C/src/Stride.lf index a146073176..de73fbd78b 100644 --- a/test/C/src/Stride.lf +++ b/test/C/src/Stride.lf @@ -28,4 +28,4 @@ main reactor Stride { c = new Count(stride = 2); d = new Display(); c.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/StructAsState.lf b/test/C/src/StructAsState.lf index 42a55c5c64..2dc942285f 100644 --- a/test/C/src/StructAsState.lf +++ b/test/C/src/StructAsState.lf @@ -15,4 +15,4 @@ main reactor StructAsState { exit(1); } =} -} \ No newline at end of file +} diff --git a/test/C/src/StructAsType.lf b/test/C/src/StructAsType.lf index a475f569de..c8ba4e5f43 100644 --- a/test/C/src/StructAsType.lf +++ b/test/C/src/StructAsType.lf @@ -8,7 +8,7 @@ preamble {= reactor Source { output out:hello_t; - + reaction(startup) -> out {= // Create the struct on the stack and then copy // it to the output as follows: @@ -36,4 +36,4 @@ main reactor StructAsType { s = new Source(); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/StructAsTypeDirect.lf b/test/C/src/StructAsTypeDirect.lf index c0ca2c96ff..651b10d3f2 100644 --- a/test/C/src/StructAsTypeDirect.lf +++ b/test/C/src/StructAsTypeDirect.lf @@ -29,4 +29,4 @@ main reactor { s = new Source(); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/StructParallel.lf b/test/C/src/StructParallel.lf index 3f6adcb399..16bfbacb4a 100644 --- a/test/C/src/StructParallel.lf +++ b/test/C/src/StructParallel.lf @@ -31,7 +31,7 @@ reactor Check(expected:int(42)) { reactor Print(scale:int(2)) { // Mutable keyword indicates that this reactor wants a writable copy of the input. mutable input in:hello_t*; - + output out:hello_t*; reaction(in) -> out {= in->value->value *= self->scale; @@ -50,4 +50,4 @@ main reactor StructParallel { s.out -> c2.in; c1.out -> p1.in; c2.out -> p2.in; -} \ No newline at end of file +} diff --git a/test/C/src/StructPrint.lf b/test/C/src/StructPrint.lf index 7c8299dd69..a34dee51a3 100644 --- a/test/C/src/StructPrint.lf +++ b/test/C/src/StructPrint.lf @@ -33,4 +33,4 @@ main reactor { s = new Print(); p = new Check(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/StructScale.lf b/test/C/src/StructScale.lf index 96acd20426..3068dbde5b 100644 --- a/test/C/src/StructScale.lf +++ b/test/C/src/StructScale.lf @@ -22,10 +22,10 @@ reactor Source { // expected parameter is for testing. reactor TestInput(expected:int(42)) { - + input in:hello_t*; state invoked:bool(false); - + reaction(in) {= printf("Received: name = %s, value = %d\n", in->value->name, in->value->value); if (in->value->value != self->expected) { @@ -45,7 +45,7 @@ reactor TestInput(expected:int(42)) { reactor Print(scale:int(2)) { // Mutable keyword indicates that this reactor wants a writable copy of the input. mutable input in:hello_t*; - + output out:hello_t*; reaction(in) -> out {= in->value->value *= self->scale; diff --git a/test/C/src/SubclassesAndStartup.lf b/test/C/src/SubclassesAndStartup.lf index 2c32635653..d08a335fb7 100644 --- a/test/C/src/SubclassesAndStartup.lf +++ b/test/C/src/SubclassesAndStartup.lf @@ -37,4 +37,4 @@ reactor SubB(name:string("SubB")) extends Super { main reactor SubclassesAndStartup { a = new SubA(); b = new SubB(); -} \ No newline at end of file +} diff --git a/test/C/src/TestForPreviousOutput.lf b/test/C/src/TestForPreviousOutput.lf index 9dbeffd12b..deb29ca943 100644 --- a/test/C/src/TestForPreviousOutput.lf +++ b/test/C/src/TestForPreviousOutput.lf @@ -33,4 +33,4 @@ main reactor TestForPreviousOutput { s = new Source(); d = new Sink(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/TimeState.lf b/test/C/src/TimeState.lf index 6ea766f6ab..4f680df27b 100644 --- a/test/C/src/TimeState.lf +++ b/test/C/src/TimeState.lf @@ -2,7 +2,7 @@ target C; reactor Foo(bar:int(42)) { state baz:time(500 msec); - + reaction (startup) {= printf("Baz: %lld\n", self->baz); =} @@ -10,4 +10,4 @@ reactor Foo(bar:int(42)) { main reactor { a = new Foo(); -} \ No newline at end of file +} diff --git a/test/C/src/Timeout.lf b/test/C/src/Timeout.lf index b46f661169..c28aec018c 100644 --- a/test/C/src/Timeout.lf +++ b/test/C/src/Timeout.lf @@ -1,47 +1,47 @@ -/* - * A test for the timeout functionality in Lingua Franca. - * - * @author Soroush Bateni - */ - target C { - timeout: 11 msec -}; - -import Sender from "lib/LoopedActionSender.lf" - -reactor Consumer { - input in:int; - state success:bool(false); - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} - - reaction(shutdown) {= - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } - =} -} - -main reactor Timeout { - consumer = new Consumer(); - producer = new Sender(break_interval = 1 msec); - - producer.out -> consumer.in; -} \ No newline at end of file +/* + * A test for the timeout functionality in Lingua Franca. + * + * @author Soroush Bateni + */ + target C { + timeout: 11 msec +}; + +import Sender from "lib/LoopedActionSender.lf" + +reactor Consumer { + input in:int; + state success:bool(false); + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} + + reaction(shutdown) {= + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } + =} +} + +main reactor Timeout { + consumer = new Consumer(); + producer = new Sender(break_interval = 1 msec); + + producer.out -> consumer.in; +} diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index 461792fe76..e93ffa1ae5 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -1,48 +1,48 @@ -/* - * A test for the timeout functionality in Lingua Franca. - * This variant tests timeout at (0,0). - * - * @author Soroush Bateni - */ - target C { - timeout: 0 sec -}; - -import Sender from "lib/LoopedActionSender.lf" - -reactor Consumer { - input in:int; - state success:bool(false); - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} - - reaction(shutdown) {= - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } - =} -} - -main reactor { - consumer = new Consumer(); - producer = new Sender(break_interval = 1 msec); - - producer.out -> consumer.in; -} \ No newline at end of file +/* + * A test for the timeout functionality in Lingua Franca. + * This variant tests timeout at (0,0). + * + * @author Soroush Bateni + */ + target C { + timeout: 0 sec +}; + +import Sender from "lib/LoopedActionSender.lf" + +reactor Consumer { + input in:int; + state success:bool(false); + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} + + reaction(shutdown) {= + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } + =} +} + +main reactor { + consumer = new Consumer(); + producer = new Sender(break_interval = 1 msec); + + producer.out -> consumer.in; +} diff --git a/test/C/src/ToReactionNested.lf b/test/C/src/ToReactionNested.lf index e3efb27a09..847c983e2f 100644 --- a/test/C/src/ToReactionNested.lf +++ b/test/C/src/ToReactionNested.lf @@ -15,7 +15,7 @@ main reactor { state received:bool(false); s = new CountContainer(); - + reaction(s.out) {= if (s.out->is_present) { lf_print("Received %d.", s.out->value); @@ -23,8 +23,8 @@ main reactor { lf_print_error_and_exit("Expected %d.", self->count); } self->received = true; - } - self->count++; + } + self->count++; =} reaction(shutdown) {= if (!self->received) { diff --git a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf index 51c116f1ff..ca7deb1bae 100644 --- a/test/C/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/C/src/TriggerDownstreamOnlyIfPresent2.lf @@ -31,4 +31,4 @@ main reactor TriggerDownstreamOnlyIfPresent2 { s = new Source(); d = new[2] Destination(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/UnconnectedInput.lf b/test/C/src/UnconnectedInput.lf index ecec9fe0ba..1335e6c155 100644 --- a/test/C/src/UnconnectedInput.lf +++ b/test/C/src/UnconnectedInput.lf @@ -40,4 +40,4 @@ main reactor UnconnectedInput { print = new Print(); source.out -> add.in2; add.out -> print.in; -} \ No newline at end of file +} diff --git a/test/C/src/Wcet.lf b/test/C/src/Wcet.lf index ca12ab41af..3bd6ea6a4e 100644 --- a/test/C/src/Wcet.lf +++ b/test/C/src/Wcet.lf @@ -34,7 +34,7 @@ main reactor Wcet { source = new Source(); work = new Work(); print = new Print(); - + source.out1 -> work.in1; source.out2 -> work.in2; work.out -> print.in; diff --git a/test/C/src/concurrent/AsyncCallback.lf b/test/C/src/concurrent/AsyncCallback.lf index d7ee1b0afa..1f947525ff 100644 --- a/test/C/src/concurrent/AsyncCallback.lf +++ b/test/C/src/concurrent/AsyncCallback.lf @@ -3,7 +3,7 @@ * This test case assumes that target is multithreaded. * This test will not work with the unthreaded C target because that target * does not implement any mutex protecting the event queue. - * + * * Note: This test uses the LF platform support to enable it to run on multiple * platforms. */ @@ -14,7 +14,7 @@ target C { }; main reactor AsyncCallback { - + preamble {= void callback(void* a) { // Schedule twice. If the action is not physical, these should @@ -38,19 +38,19 @@ main reactor AsyncCallback { 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); - + reaction(t) -> a {= // start new thread, provide callback lf_thread_create(&self->thread_id, &take_time, a); =} - + reaction(a) {= instant_t elapsed_time = lf_time_logical_elapsed(); printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", - self->i++, elapsed_time); + self->i++, elapsed_time); if (elapsed_time <= self->expected_time) { printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); exit(1); @@ -62,4 +62,4 @@ main reactor AsyncCallback { self->toggle = true; } =} -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/AsyncCallbackDrop.lf b/test/C/src/concurrent/AsyncCallbackDrop.lf index 296356e04a..6ceee20954 100644 --- a/test/C/src/concurrent/AsyncCallbackDrop.lf +++ b/test/C/src/concurrent/AsyncCallbackDrop.lf @@ -7,7 +7,7 @@ target C { }; main reactor { - + preamble {= void callback(void* a) { // Schedule twice in rapid succession. @@ -34,15 +34,15 @@ main reactor { physical action a(100 msec, 100 msec, "drop"):int; state i:int(0); - + reaction(t) -> a {= // start new thread, provide callback lf_thread_create(&self->thread_id, &take_time, a); =} - + reaction(a) {= instant_t elapsed_time = lf_time_logical_elapsed(); - printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); + printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); if (elapsed_time <= self->expected_time) { printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); exit(1); diff --git a/test/C/src/concurrent/AsyncCallbackReplace.lf b/test/C/src/concurrent/AsyncCallbackReplace.lf index 58fb53ba5a..3492fb3211 100644 --- a/test/C/src/concurrent/AsyncCallbackReplace.lf +++ b/test/C/src/concurrent/AsyncCallbackReplace.lf @@ -7,7 +7,7 @@ target C { }; main reactor { - + preamble {= void callback(void* a) { // Schedule twice in rapid succession. @@ -39,10 +39,10 @@ main reactor { // start new thread, provide callback lf_thread_create(&self->thread_id, &take_time, a); =} - + reaction(a) {= instant_t elapsed_time = lf_time_logical_elapsed(); - printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); + printf("Asynchronous callback %d: Assigned logical time greater than start time by %lld nsec.\n", self->i++, elapsed_time); if (elapsed_time <= self->expected_time) { printf("ERROR: Expected logical time to be larger than %lld.\n", self->expected_time); exit(1); diff --git a/test/C/src/concurrent/CompositionThreaded.lf b/test/C/src/concurrent/CompositionThreaded.lf index d4bd90c133..ea7b62dc8e 100644 --- a/test/C/src/concurrent/CompositionThreaded.lf +++ b/test/C/src/concurrent/CompositionThreaded.lf @@ -31,4 +31,4 @@ main reactor CompositionThreaded { s = new Source(); d = new Test(); s.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf index 97186be99e..2bd268ce02 100644 --- a/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/C/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -37,4 +37,4 @@ main reactor { exit(2); } =} -} +} diff --git a/test/C/src/concurrent/DeadlineThreaded.lf b/test/C/src/concurrent/DeadlineThreaded.lf index bfbee6a275..e39b971667 100644 --- a/test/C/src/concurrent/DeadlineThreaded.lf +++ b/test/C/src/concurrent/DeadlineThreaded.lf @@ -51,4 +51,4 @@ main reactor { s = new Source(); d = new Destination(timeout = 200 msec); s.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/DelayIntThreaded.lf b/test/C/src/concurrent/DelayIntThreaded.lf index ddb5acd8a4..bdd29b35ff 100644 --- a/test/C/src/concurrent/DelayIntThreaded.lf +++ b/test/C/src/concurrent/DelayIntThreaded.lf @@ -20,7 +20,7 @@ reactor Test { reaction(startup) {= // Record the logical time at the start. self->start_time = lf_time_logical(); - =} + =} reaction(in) {= printf("Received: %d.\n", in->value); self->received_value = true; @@ -34,23 +34,23 @@ reactor Test { } if (in->value != 42) { printf("ERROR: Expected input value to be 42. It was %d.\n", in->value); - exit(2); + exit(2); } =} reaction(shutdown) {= printf("Checking that communication occurred.\n"); if (!self->received_value) { printf("ERROR: No communication occurred!\n"); - exit(3); + exit(3); } =} } -main reactor { +main reactor { d = new Delay(); t = new Test(); - d.out -> t.in; + d.out -> t.in; reaction(startup) -> d.in {= lf_set(d.in, 42); =} -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/DeterminismThreaded.lf b/test/C/src/concurrent/DeterminismThreaded.lf index b078d83bfd..e6edddbf43 100644 --- a/test/C/src/concurrent/DeterminismThreaded.lf +++ b/test/C/src/concurrent/DeterminismThreaded.lf @@ -6,7 +6,7 @@ reactor Source { reaction(t) -> y {= lf_set(y, 1); =} -} +} reactor Destination { input x:int; input y:int; diff --git a/test/C/src/concurrent/DoubleReactionThreaded.lf b/test/C/src/concurrent/DoubleReactionThreaded.lf index c790a18307..56bb2e2f13 100644 --- a/test/C/src/concurrent/DoubleReactionThreaded.lf +++ b/test/C/src/concurrent/DoubleReactionThreaded.lf @@ -40,4 +40,4 @@ main reactor DoubleReactionThreaded { d = new Destination(); c1.y -> d.x; c2.y -> d.w; -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/GainThreaded.lf b/test/C/src/concurrent/GainThreaded.lf index b10bd4eaaf..3ba998b549 100644 --- a/test/C/src/concurrent/GainThreaded.lf +++ b/test/C/src/concurrent/GainThreaded.lf @@ -1,36 +1,36 @@ // Example in the Wiki. - target C; - reactor Scale(scale:int(2)) { - input x:int; - output y:int; - reaction(x) -> y {= - lf_set(y, x->value * self->scale); - =} - } - reactor Test { - input x:int; - state received_value:bool(false); - reaction(x) {= - printf("Received %d.\n", x->value); - self->received_value = true; - if (x->value != 2) { - printf("ERROR: Expected 2!\n"); - exit(1); - } - =} - reaction(shutdown) {= - if (!self->received_value) { - printf("ERROR: No value received by Test reactor!\n"); - } else { - printf("Test passes.\n"); - } - =} - } - main reactor { - g = new Scale(); - d = new Test(); - g.y -> d.x; - reaction(startup) -> g.x {= - lf_set(g.x, 1); - =} - } +target C; +reactor Scale(scale:int(2)) { + input x:int; + output y:int; + reaction(x) -> y {= + lf_set(y, x->value * self->scale); + =} +} +reactor Test { + input x:int; + state received_value:bool(false); + reaction(x) {= + printf("Received %d.\n", x->value); + self->received_value = true; + if (x->value != 2) { + printf("ERROR: Expected 2!\n"); + exit(1); + } + =} + reaction(shutdown) {= + if (!self->received_value) { + printf("ERROR: No value received by Test reactor!\n"); + } else { + printf("Test passes.\n"); + } + =} +} +main reactor { + g = new Scale(); + d = new Test(); + g.y -> d.x; + reaction(startup) -> g.x {= + lf_set(g.x, 1); + =} +} diff --git a/test/C/src/concurrent/HelloThreaded.lf b/test/C/src/concurrent/HelloThreaded.lf index 4a4044d823..0febdbbb74 100644 --- a/test/C/src/concurrent/HelloThreaded.lf +++ b/test/C/src/concurrent/HelloThreaded.lf @@ -21,7 +21,7 @@ reactor Reschedule(period:time(2 secs), message:string("Hello C")) { printf("Current time is %lld\n", self->previous_time); printf("Which is %sPlus %lld nanoseconds.\n", ctime(&secs), self->previous_time % BILLION); =} - + reaction(a) {= (self->count)++; printf("***** action %d at time %lld\n", self->count, lf_time_logical()); @@ -47,4 +47,4 @@ main reactor HelloThreaded { first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); second_instance = new Reschedule(message = "Hello from second_instance."); composite_instance = new Inside(message = "Hello from composite_instance."); -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/ImportThreaded.lf b/test/C/src/concurrent/ImportThreaded.lf index c54b1fbdb3..ac0e0cbf38 100644 --- a/test/C/src/concurrent/ImportThreaded.lf +++ b/test/C/src/concurrent/ImportThreaded.lf @@ -9,6 +9,6 @@ main reactor ImportThreaded { timer t; a = new Imported(); reaction(t) -> a.x {= - lf_set(a.x, 42); + lf_set(a.x, 42); =} } diff --git a/test/C/src/concurrent/PingPongThreaded.lf b/test/C/src/concurrent/PingPongThreaded.lf index 5d74429f72..88c27ecd5d 100644 --- a/test/C/src/concurrent/PingPongThreaded.lf +++ b/test/C/src/concurrent/PingPongThreaded.lf @@ -1,24 +1,24 @@ - /** +/** * Basic benchmark from the Savina benchmark suite that is * intended to measure message-passing overhead. * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * Ping introduces a microstep delay using a logical action * to break the causality loop. - * + * * To get a sense, some (informal) results for 1,000,000 ping-pongs * on my Mac: - * + * * Unthreaded: 97 msec * Threaded: 265 msec (168 msec with optimization of executing immediately) - * + * * There is no parallelism in this application, so it does not benefit from being * being threaded, just some additional overhead. - * + * * These measurements are total execution time, including startup and shutdown. * These are about an order of magnitude faster than anything reported in the paper. - * + * * @author Edward A. Lee */ target C { @@ -46,7 +46,7 @@ reactor Pong(expected:int(10)) { state count:int(0); reaction(receive) -> send {= self->count++; - lf_set(send, receive->value); + lf_set(send, receive->value); =} reaction(shutdown) {= if (self->count != self->expected) { @@ -63,5 +63,5 @@ main reactor PingPongThreaded { ping = new Ping(); pong = new Pong(); ping.send -> pong.receive; - pong.send -> ping.receive; -} \ No newline at end of file + pong.send -> ping.receive; +} diff --git a/test/C/src/concurrent/ScheduleAt.lf b/test/C/src/concurrent/ScheduleAt.lf index c8d21552a6..9a6d430398 100644 --- a/test/C/src/concurrent/ScheduleAt.lf +++ b/test/C/src/concurrent/ScheduleAt.lf @@ -1,7 +1,7 @@ /** * Test _lf_schedule_at_tag which is an internal API function * not meant to be used in user code. - * + * * @author Soroush Bateni */ @@ -15,7 +15,7 @@ reactor Scheduler { state microstep_delay_list:uint32_t[](0,1,1,2,2,0,0,1,1,0,2,3,3,4,4,5); // List of microsteps. Size = 16 state times:int[](0,0,0,0,0, 400 msec, 400 msec, 400 msec, 400 msec, // List of the corresponding times. Size = 16 800 msec, 800 msec, 800 msec, 800 msec, 900 msec, - 900 msec, 900 msec); + 900 msec, 900 msec); state action_hit_list_microstep:int[](1, 2, 0, 1, 0, 2, 3, 4, 5); // Size = 9 state action_hit_list_times:int[](0, 0, 400 msec, 400msec, 800 msec, 800 msec, 800 msec, 900msec, 900msec); // Size = 9 @@ -27,7 +27,7 @@ reactor Scheduler { NULL); } =} - + reaction(act) {= microstep_t microstep = lf_tag().microstep; instant_t elapsed_time = lf_time_logical_elapsed(); @@ -37,7 +37,7 @@ reactor Scheduler { } printf("Triggered at tag (%lld, %u).\n", elapsed_time, microstep); =} - + reaction(shutdown) {= if (self->action_hit_list_index != 9) { fprintf(stderr, "ERROR: incorrect number of actions were correctly scheduled: %d.", self->action_hit_list_index); @@ -49,4 +49,4 @@ reactor Scheduler { main reactor ScheduleAt { sender = new Scheduler(); -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/SendingInsideThreaded.lf b/test/C/src/concurrent/SendingInsideThreaded.lf index 5e415e997b..1b4cb04d25 100644 --- a/test/C/src/concurrent/SendingInsideThreaded.lf +++ b/test/C/src/concurrent/SendingInsideThreaded.lf @@ -24,4 +24,4 @@ main reactor SendingInsideThreaded { (self->count)++; lf_set(p.x, self->count); =} -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/StarvationThreaded.lf b/test/C/src/concurrent/StarvationThreaded.lf index b58680664b..d9906a1297 100644 --- a/test/C/src/concurrent/StarvationThreaded.lf +++ b/test/C/src/concurrent/StarvationThreaded.lf @@ -1,67 +1,67 @@ -/** - * Test that the starvation functionality in absence of - * the "keepalive: true" target property indeed works as - * expected. This version uses the threaded runtime. - * - * @author Soroush Bateni - */ - target C { -}; - reactor SuperDenseSender(number_of_iterations:int(10)){ - logical action loop; - output out:int; - state iterator:int(0); - reaction(startup, loop) -> out {= - if (self->iterator < self->number_of_iterations) { - lf_schedule(loop, 0); - } - self->iterator++; - lf_set(out, 42); - =} - - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == start_time - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Sender successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - start_time, - current_tag.microstep); - exit(1); - } - =} - } - - reactor SuperDenseReceiver(number_of_iterations:int(10)) { - input in:int; - reaction(in) {= - tag_t current_tag = lf_tag(); - printf("Received %d at tag (%lld, %u).\n", - in->value, - current_tag.time - start_time, - current_tag.microstep); - =} - - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - if (current_tag.time == start_time - && current_tag.microstep == self->number_of_iterations + 1) { - printf("SUCCESS: Receiver successfully detected starvation.\n"); - } else { - fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " - "Shutting down at tag (%lld, %u).\n", - current_tag.time - start_time, - current_tag.microstep); - exit(1); - } - =} -} - -main reactor StarvationThreaded { - sender = new[8] SuperDenseSender(); - receiver = new[8] SuperDenseReceiver(); - - sender.out -> receiver.in; -} \ No newline at end of file +/** + * Test that the starvation functionality in absence of + * the "keepalive: true" target property indeed works as + * expected. This version uses the threaded runtime. + * + * @author Soroush Bateni + */ +target C { +}; + reactor SuperDenseSender(number_of_iterations:int(10)){ + logical action loop; + output out:int; + state iterator:int(0); + reaction(startup, loop) -> out {= + if (self->iterator < self->number_of_iterations) { + lf_schedule(loop, 0); + } + self->iterator++; + lf_set(out, 42); + =} + + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == start_time + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Sender successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at sender. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - start_time, + current_tag.microstep); + exit(1); + } + =} + } + + reactor SuperDenseReceiver(number_of_iterations:int(10)) { + input in:int; + reaction(in) {= + tag_t current_tag = lf_tag(); + printf("Received %d at tag (%lld, %u).\n", + in->value, + current_tag.time - start_time, + current_tag.microstep); + =} + + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + if (current_tag.time == start_time + && current_tag.microstep == self->number_of_iterations + 1) { + printf("SUCCESS: Receiver successfully detected starvation.\n"); + } else { + fprintf(stderr, "ERROR: Failed to properly enforce starvation at receiver. " + "Shutting down at tag (%lld, %u).\n", + current_tag.time - start_time, + current_tag.microstep); + exit(1); + } + =} +} + +main reactor StarvationThreaded { + sender = new[8] SuperDenseSender(); + receiver = new[8] SuperDenseReceiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index ca70ad1d53..17311774af 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -1,65 +1,65 @@ -/* - * A test for the lf_request_stop() functionality in Lingua Franca. - * This version of the test is threaded. - * - * @author Soroush Bateni - */ - target C { - timeout: 11 msec, - build-type: RelWithDebInfo, - // logging: DEBUG -}; - -import Sender from "../lib/LoopedActionSender.lf" - -reactor Consumer { - input in:int; - state reaction_invoked_correctly:bool(false); - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - // The reaction should not have been called at tags larger than (10 - // msec, 9) - char time[255]; - lf_print_error_and_exit("Invoked reaction(in) at tag (%llu, %d) which is bigger than shutdown.", - current_tag.time - lf_time_start(), current_tag.microstep); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { - // Call lf_request_stop() at relative tag (10 msec, 8) - lf_print("Requesting stop."); - lf_request_stop(); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { - // Check that this reaction is indeed also triggered at (10 msec, 9) - // printf("Reaction invoked.\n"); - self->reaction_invoked_correctly = true; - } - =} - - reaction(shutdown) {= - tag_t current_tag = lf_tag(); - lf_print("Shutdown invoked at tag (%lld, %u).", current_tag.time - lf_time_start(), current_tag.microstep); - // Check to see if shutdown is called at relative tag (10 msec, 9) - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && - self->reaction_invoked_correctly == true) { - lf_print("SUCCESS: successfully enforced stop."); - } else if(lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { - lf_print_error_and_exit("Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.", - current_tag.time - lf_time_start(), current_tag.microstep); - } else if (self->reaction_invoked_correctly == false) { - // Check to see if reactions were called correctly - lf_print_error_and_exit("Failed to invoke reaction(in) at tag (%llu, %d).", - current_tag.time - lf_time_start(), current_tag.microstep); - } - =} -} - -main reactor { - consumer = new[4] Consumer(); - producer = new[4] Sender(break_interval = 1 msec); - - producer.out -> consumer.in; -} +/* + * A test for the lf_request_stop() functionality in Lingua Franca. + * This version of the test is threaded. + * + * @author Soroush Bateni + */ + target C { + timeout: 11 msec, + build-type: RelWithDebInfo, + // logging: DEBUG +}; + +import Sender from "../lib/LoopedActionSender.lf" + +reactor Consumer { + input in:int; + state reaction_invoked_correctly:bool(false); + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + // The reaction should not have been called at tags larger than (10 + // msec, 9) + char time[255]; + lf_print_error_and_exit("Invoked reaction(in) at tag (%llu, %d) which is bigger than shutdown.", + current_tag.time - lf_time_start(), current_tag.microstep); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 8}) == 0) { + // Call lf_request_stop() at relative tag (10 msec, 8) + lf_print("Requesting stop."); + lf_request_stop(); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0) { + // Check that this reaction is indeed also triggered at (10 msec, 9) + // printf("Reaction invoked.\n"); + self->reaction_invoked_correctly = true; + } + =} + + reaction(shutdown) {= + tag_t current_tag = lf_tag(); + lf_print("Shutdown invoked at tag (%lld, %u).", current_tag.time - lf_time_start(), current_tag.microstep); + // Check to see if shutdown is called at relative tag (10 msec, 9) + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) == 0 && + self->reaction_invoked_correctly == true) { + lf_print("SUCCESS: successfully enforced stop."); + } else if(lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(10) + lf_time_start(), .microstep = 9}) > 0) { + lf_print_error_and_exit("Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.", + current_tag.time - lf_time_start(), current_tag.microstep); + } else if (self->reaction_invoked_correctly == false) { + // Check to see if reactions were called correctly + lf_print_error_and_exit("Failed to invoke reaction(in) at tag (%llu, %d).", + current_tag.time - lf_time_start(), current_tag.microstep); + } + =} +} + +main reactor { + consumer = new[4] Consumer(); + producer = new[4] Sender(break_interval = 1 msec); + + producer.out -> consumer.in; +} diff --git a/test/C/src/concurrent/StopZeroThreaded.lf b/test/C/src/concurrent/StopZeroThreaded.lf index 0928ce1020..0364eaea2a 100644 --- a/test/C/src/concurrent/StopZeroThreaded.lf +++ b/test/C/src/concurrent/StopZeroThreaded.lf @@ -1,103 +1,103 @@ -/** - * Test for lf_request_stop() at tag (0,0). - * This version uses the threaded runtime. - * - * @author Soroush Bateni - */ -target C { -}; - -reactor Sender { - output out:int; - state reaction_invoked_correctly:bool(false); - timer t(0, 1 usec); - logical action act; - reaction(t) -> out, act {= - printf("Sending 42 at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); - lf_schedule(act, 0); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } else if (lf_tag_compare(lf_tag(), one) > 0) { - fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - =} - reaction(act) {= - // Reaction should be invoked at (0,1) - tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), one) == 0) { - self->reaction_invoked_correctly = true; - } - =} - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Sender failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } else if (self->reaction_invoked_correctly == false) { - fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -reactor Receiver { - input in:int; - reaction(in) {= - printf("Received %d at (%lld, %u).\n", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} - - reaction(shutdown) {= - // Shutdown events must occur at (0, 1) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -main reactor StopZeroThreaded { - sender = new[4] Sender(); - receiver = new[4] Receiver(); - - sender.out -> receiver.in; -} \ No newline at end of file +/** + * Test for lf_request_stop() at tag (0,0). + * This version uses the threaded runtime. + * + * @author Soroush Bateni + */ +target C { +}; + +reactor Sender { + output out:int; + state reaction_invoked_correctly:bool(false); + timer t(0, 1 usec); + logical action act; + reaction(t) -> out, act {= + printf("Sending 42 at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); + lf_schedule(act, 0); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } else if (lf_tag_compare(lf_tag(), one) > 0) { + fprintf(stderr, "ERROR: Reaction called after shutdown at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + =} + reaction(act) {= + // Reaction should be invoked at (0,1) + tag_t one = (tag_t) { .time = lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), one) == 0) { + self->reaction_invoked_correctly = true; + } + =} + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Sender failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } else if (self->reaction_invoked_correctly == false) { + fprintf(stderr, "ERROR: Sender reaction(act) was not invoked. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +reactor Receiver { + input in:int; + reaction(in) {= + printf("Received %d at (%lld, %u).\n", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} + + reaction(shutdown) {= + // Shutdown events must occur at (0, 1) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Receiver failed to stop the program in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the program at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +main reactor StopZeroThreaded { + sender = new[4] Sender(); + receiver = new[4] Receiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/concurrent/ThreadedMultiport.lf b/test/C/src/concurrent/ThreadedMultiport.lf index f4500910b9..fefbdf9233 100644 --- a/test/C/src/concurrent/ThreadedMultiport.lf +++ b/test/C/src/concurrent/ThreadedMultiport.lf @@ -2,7 +2,7 @@ target C { timeout: 2 sec, flags: "", // Disable compiler optimization so that TakeTime actually takes time. -}; +}; reactor Source(width:int(4)) { timer t(0, 200 msec); output[width] out:int; @@ -53,10 +53,10 @@ 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); a.out -> t.in; t.out -> b.in; -} \ No newline at end of file +} diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index 769abb9d42..82508843b6 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -1,48 +1,48 @@ -/* - * A test for the timeout functionality in Lingua Franca. - * This version of the test is threaded. - * - * @author Soroush Bateni - */ - target C { - timeout: 11 msec, -}; - -import Sender from "../lib/LoopedActionSender.lf" - -reactor Consumer { - input in:int; - state success:bool(false); - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time, current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} - - reaction(shutdown) {= - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time - start_time, current_tag.microstep); - exit(1); - } - =} -} - -main reactor { - consumer = new[4] Consumer(); - producer = new[4] Sender(break_interval = 1 msec); - - producer.out -> consumer.in; -} +/* + * A test for the timeout functionality in Lingua Franca. + * This version of the test is threaded. + * + * @author Soroush Bateni + */ +target C { + timeout: 11 msec, +}; + +import Sender from "../lib/LoopedActionSender.lf" + +reactor Consumer { + input in:int; + state success:bool(false); + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time, current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} + + reaction(shutdown) {= + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(11) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time - start_time, current_tag.microstep); + exit(1); + } + =} +} + +main reactor { + consumer = new[4] Consumer(); + producer = new[4] Sender(break_interval = 1 msec); + + producer.out -> consumer.in; +} diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index cb2c14f898..e8982e6f51 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -1,49 +1,49 @@ -/* - * A test for the timeout functionality in Lingua Franca. - * This variant tests timeout at (0,0) and uses the threaded - * runtime. - * - * @author Soroush Bateni - */ - target C { - timeout: 0 sec, -}; - -import Sender from "../lib/LoopedActionSender.lf" - -reactor Consumer { - input in:int; - state success:bool(false); - reaction(in) {= - tag_t current_tag = lf_tag(); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { - fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", - current_tag.time - start_time, current_tag.microstep); - exit(1); - } else if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { - self->success = true; // Successfully invoked the reaction at (timeout, 0) - } - =} - - reaction(shutdown) {= - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); - if (lf_tag_compare(current_tag, - (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && - self->success == true) { - printf("SUCCESS: successfully enforced timeout.\n"); - } else { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", - current_tag.time - start_time, current_tag.microstep); - exit(1); - } - =} -} - -main reactor { - consumer = new[4] Consumer(); - producer = new[4] Sender(break_interval = 1 msec); - - producer.out -> consumer.in; -} +/* + * A test for the timeout functionality in Lingua Franca. + * This variant tests timeout at (0,0) and uses the threaded + * runtime. + * + * @author Soroush Bateni + */ + target C { + timeout: 0 sec, +}; + +import Sender from "../lib/LoopedActionSender.lf" + +reactor Consumer { + input in:int; + state success:bool(false); + reaction(in) {= + tag_t current_tag = lf_tag(); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) > 0) { + fprintf(stderr,"ERROR: Tag (%lld, %d) received. Failed to enforce timeout.\n", + current_tag.time - start_time, current_tag.microstep); + exit(1); + } else if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0) { + self->success = true; // Successfully invoked the reaction at (timeout, 0) + } + =} + + reaction(shutdown) {= + printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep); + if (lf_tag_compare(current_tag, + (tag_t) { .time = MSEC(0) + lf_time_start(), .microstep = 0}) == 0 && + self->success == true) { + printf("SUCCESS: successfully enforced timeout.\n"); + } else { + fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + current_tag.time - start_time, current_tag.microstep); + exit(1); + } + =} +} + +main reactor { + consumer = new[4] Consumer(); + producer = new[4] Sender(break_interval = 1 msec); + + producer.out -> consumer.in; +} diff --git a/test/C/src/concurrent/Tracing.lf b/test/C/src/concurrent/Tracing.lf index e3e6a62fb8..ce29149294 100644 --- a/test/C/src/concurrent/Tracing.lf +++ b/test/C/src/concurrent/Tracing.lf @@ -1,7 +1,7 @@ // Version of ThreadedThreaded used to test tracing functions. target C { timeout: 2 sec, - tracing: true, + tracing: true, flags: "", // Disable compiler optimization so that TakeTime actually takes time. logging: DEBUG }; @@ -26,7 +26,7 @@ reactor TakeTime( size_t length = strlen(format) + 2; self->event = (string)malloc(sizeof(char) * (length + 1)); snprintf(self->event, length, format, self->bank_index); - + // Register the user trace event. if (!register_user_trace_event(self->event)) { fprintf(stderr, "ERROR: Failed to register trace event.\n"); diff --git a/test/C/src/concurrent/Workers.lf b/test/C/src/concurrent/Workers.lf index 2b1a563b1f..879ce62809 100644 --- a/test/C/src/concurrent/Workers.lf +++ b/test/C/src/concurrent/Workers.lf @@ -7,4 +7,4 @@ main reactor { lf_print("Using 16 workers."); } =} -} \ No newline at end of file +} diff --git a/test/C/src/docker/HelloWorldContainerized.lf b/test/C/src/docker/HelloWorldContainerized.lf index 3d677e3345..5188ffc9d9 100644 --- a/test/C/src/docker/HelloWorldContainerized.lf +++ b/test/C/src/docker/HelloWorldContainerized.lf @@ -9,4 +9,4 @@ import HelloWorld2 from "../HelloWorld.lf" main reactor { a = new HelloWorld2(); -} \ No newline at end of file +} diff --git a/test/C/src/docker/PingPongContainerized.lf b/test/C/src/docker/PingPongContainerized.lf index 3e6510918a..d451077f70 100644 --- a/test/C/src/docker/PingPongContainerized.lf +++ b/test/C/src/docker/PingPongContainerized.lf @@ -3,22 +3,22 @@ * intended to measure message-passing overhead. * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * Ping introduces a microstep delay using a logical action * to break the causality loop. - * + * * To get a sense, some (informal) results for 1,000,000 ping-pongs * on my Mac: - * + * * Unthreaded: 97 msec * Threaded: 265 msec - * + * * There is no parallelism in this application, so it does not benefit from being * being threaded, just some additional overhead. - * + * * These measurements are total execution time, including startup and shutdown. * These are about an order of magnitude faster than anything reported in the paper. - * + * * @author Edward A. Lee */ target C { @@ -34,5 +34,5 @@ main reactor PingPongContainerized { ping = new Ping(); pong = new Pong(); ping.send -> pong.receive; - pong.send -> ping.receive; -} \ No newline at end of file + pong.send -> ping.receive; +} diff --git a/test/C/src/docker/federated/DistributedCountContainerized.lf b/test/C/src/docker/federated/DistributedCountContainerized.lf index c270011d1c..058719b139 100644 --- a/test/C/src/docker/federated/DistributedCountContainerized.lf +++ b/test/C/src/docker/federated/DistributedCountContainerized.lf @@ -2,7 +2,7 @@ * where a federation that receives timestamped messages has only those * messages as triggers. Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * @author Edward A. Lee + * @author Edward A. Lee */ target C { timeout: 5 sec, @@ -14,7 +14,7 @@ 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/docker/federated/DistributedDoublePortContainerized.lf b/test/C/src/docker/federated/DistributedDoublePortContainerized.lf index 5840713960..e8e8a98d8d 100644 --- a/test/C/src/docker/federated/DistributedDoublePortContainerized.lf +++ b/test/C/src/docker/federated/DistributedDoublePortContainerized.lf @@ -1,10 +1,10 @@ -/** +/** * Test the case for when two upstream federates * send messages to a downstream federte on two - * different ports. One message should carry a + * different ports. One message should carry a * microstep delay relative to the other * message. - * + * * @author Soroush Bateni */ target C { diff --git a/test/C/src/docker/federated/DistributedMultiportContainerized.lf b/test/C/src/docker/federated/DistributedMultiportContainerized.lf index ac36c0e1bf..d5cc44f860 100644 --- a/test/C/src/docker/federated/DistributedMultiportContainerized.lf +++ b/test/C/src/docker/federated/DistributedMultiportContainerized.lf @@ -11,4 +11,4 @@ federated reactor DistributedMultiportContainerized at rti { s = new Source(); d = new Destination(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf b/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf index 334c0fe7e4..e4f0ad0754 100644 --- a/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf +++ b/test/C/src/docker/federated/DistributedStopDecentralizedContainerized.lf @@ -1,17 +1,17 @@ - /** - * Test for lf_request_stop() in federated execution with decentralized coordination. - * - * @author Soroush Bateni - */ -target C { - coordination: decentralized, - docker: true -}; - -import Sender, Receiver from "../../federated/DistributedStop.lf" - -federated reactor DistributedStopDecentralizedContainerized at rti { - sender = new Sender(); - receiver = new Receiver(); - sender.out -> receiver.in; -} \ No newline at end of file +/** + * Test for lf_request_stop() in federated execution with decentralized coordination. + * + * @author Soroush Bateni + */ +target C { + coordination: decentralized, + docker: true +}; + +import Sender, Receiver from "../../federated/DistributedStop.lf" + +federated reactor DistributedStopDecentralizedContainerized at rti { + sender = new Sender(); + receiver = new Receiver(); + sender.out -> receiver.in; +} diff --git a/test/C/src/federated/BroadcastFeedback.lf b/test/C/src/federated/BroadcastFeedback.lf index c223889ffd..c0618bfd17 100644 --- a/test/C/src/federated/BroadcastFeedback.lf +++ b/test/C/src/federated/BroadcastFeedback.lf @@ -9,7 +9,7 @@ reactor SenderAndReceiver { output out:int; input[2] in:int; 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 32bb1195f6..66757dc5c8 100644 --- a/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/C/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -8,18 +8,18 @@ reactor SenderAndReceiver { output out:int; input[2] in:int; state received:bool(false); - + reaction(startup) -> out {= lf_set(out, 42); =} - + r = new Receiver(); in -> r.in; } reactor Receiver { input[2] in:int; state received:bool(false); - + reaction(in) {= if (in[0]->is_present && in[1]->is_present && in[0]->value == 42 && in[1]->value == 42) { lf_print("SUCCESS"); diff --git a/test/C/src/federated/ChainWithDelay.lf b/test/C/src/federated/ChainWithDelay.lf index 1116093cde..b9490b7569 100644 --- a/test/C/src/federated/ChainWithDelay.lf +++ b/test/C/src/federated/ChainWithDelay.lf @@ -1,6 +1,6 @@ /** * Demonstration that monotonic NET hypothesis is invalid. - * + * * @author Edward A. Lee */ target C { diff --git a/test/C/src/federated/ClockSync.lf b/test/C/src/federated/ClockSync.lf index 1855c6980e..b154572726 100644 --- a/test/C/src/federated/ClockSync.lf +++ b/test/C/src/federated/ClockSync.lf @@ -28,11 +28,11 @@ 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); - + reaction(tick) -> out {= lf_set(out, 42); =} @@ -48,11 +48,11 @@ reactor Printer { interval_t offset = _lf_time_physical_clock_offset + _lf_time_test_physical_clock_offset; lf_print("Clock sync error at startup is %lld ns.", offset); =} - + reaction(in) {= lf_print("Received %d.", in->value); =} - + reaction(shutdown) {= interval_t offset = _lf_time_physical_clock_offset + _lf_time_test_physical_clock_offset; lf_print("Clock sync error at shutdown is %lld ns.", offset); @@ -74,4 +74,3 @@ federated reactor ClockSync { fed1 = new Federate(); fed2 = new Federate(); } - diff --git a/test/C/src/federated/CycleDetection.lf b/test/C/src/federated/CycleDetection.lf index d9df75b330..ac55476ad2 100644 --- a/test/C/src/federated/CycleDetection.lf +++ b/test/C/src/federated/CycleDetection.lf @@ -9,11 +9,11 @@ reactor CAReplica { input local_update:int; input remote_update:int; input query:int; - + state balance:int(0); output response:int; - + reaction(local_update, remote_update) {= if (local_update->is_present) { self->balance += local_update->value; @@ -22,7 +22,7 @@ reactor CAReplica { self->balance += remote_update->value; } =} - + reaction(query) -> response {= lf_set(response, self->balance); =} @@ -30,7 +30,7 @@ reactor CAReplica { reactor UserInput { input balance:int; output deposit:int; - + reaction(startup) -> deposit {= lf_set(deposit, 100); =} @@ -41,7 +41,7 @@ reactor UserInput { lf_print("Balance: %d", balance->value); lf_request_stop(); =} - + reaction(shutdown) {= lf_print("Test passed!"); =} @@ -59,4 +59,4 @@ federated reactor { (u2.deposit)+ -> r2.query, r2.local_update; r2.response -> u2.balance; u2.deposit -> r1.remote_update; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DecentralizedP2PComm.lf b/test/C/src/federated/DecentralizedP2PComm.lf index 6e203ef2ef..99301ffda9 100644 --- a/test/C/src/federated/DecentralizedP2PComm.lf +++ b/test/C/src/federated/DecentralizedP2PComm.lf @@ -17,7 +17,7 @@ reactor Platform(start:int(0), expected_start:int(0), stp_offset_param:time(0)) reaction(in) {= lf_print("Received %d.", in->value); if (in->value != self->expected_start++) { - lf_print_error_and_exit("Expected %d but got %d.", + lf_print_error_and_exit("Expected %d but got %d.", self->expected_start - 1, in->value ); diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf index c17f0e0581..723962f648 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -2,8 +2,8 @@ * Test a source-destination scenario where the source falls behind real-time, and reaches the * timeout much later than the destination. In this test, the destination closes the connection * early, causing the transmission to fail. Warnings will be printed about lost messages. - * - * The test fails if the federation does not exit. + * + * The test fails if the federation does not exit. */ target C { timeout: 1 msec, @@ -30,7 +30,7 @@ reactor Destination { lf_print("Received %d", x->value); tag_t current_tag = lf_tag(); if (x->value != self->s) { - lf_print_error_and_exit("At tag (%lld, %u) expected %d and got %d.", + lf_print_error_and_exit("At tag (%lld, %u) expected %d and got %d.", current_tag.time - start_time, current_tag.microstep, self->s, x->value ); } @@ -45,4 +45,4 @@ federated reactor (period:time(10 usec)) { c = new Clock(period = period); d = new Destination(); c.y -> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index 0e3b79469c..3c8da87246 100644 --- a/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/C/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -2,9 +2,9 @@ * Test a source-destination scenario where the source falls behind real-time, and reaches the * timeout much later than the destination. In this test, the destination closes the connection * early, causing the transmission to fail. Warnings will be printed. - * + * * The test fails if the federation does not exit amenably. - * This variant has a physical connection between source and destination. + * This variant has a physical connection between source and destination. */ target C { timeout: 1 msec, @@ -43,4 +43,4 @@ federated reactor (period:time(10 usec)) { c = new Clock(period = period); d = new Destination(); c.y ~> d.x; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DistributedBank.lf b/test/C/src/federated/DistributedBank.lf index 98c886b9b8..e6ddeb4a30 100644 --- a/test/C/src/federated/DistributedBank.lf +++ b/test/C/src/federated/DistributedBank.lf @@ -19,4 +19,4 @@ reactor Node { federated reactor DistributedBank { n = new[2] Node(); -} \ No newline at end of file +} diff --git a/test/C/src/federated/DistributedBankToMultiport.lf b/test/C/src/federated/DistributedBankToMultiport.lf index 3003378e6d..83cd2954bb 100644 --- a/test/C/src/federated/DistributedBankToMultiport.lf +++ b/test/C/src/federated/DistributedBankToMultiport.lf @@ -4,18 +4,18 @@ target C { }; import Count from "../lib/Count.lf"; - + reactor Destination { input[2] in:int; state count:int(1); reaction(in) {= for (int i = 0; i < in_width; i++) { - lf_print("Received %d.", in[i]->value); + lf_print("Received %d.", in[i]->value); if (self->count != in[i]->value) { lf_print_error_and_exit("Expected %d.", self->count); - } - } - self->count++; + } + } + self->count++; =} reaction(shutdown) {= if (self->count == 0) { @@ -28,4 +28,4 @@ federated reactor { s = new[2] Count(); d = new Destination(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DistributedCount.lf b/test/C/src/federated/DistributedCount.lf index 4fc6159f9a..302d163b92 100644 --- a/test/C/src/federated/DistributedCount.lf +++ b/test/C/src/federated/DistributedCount.lf @@ -2,7 +2,7 @@ * where a federation that receives timestamped messages has only those * messages as triggers. Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * @author Edward A. Lee + * @author Edward A. Lee */ target C { timeout: 5 sec, @@ -33,7 +33,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/DistributedCountDecentralizedLate.lf b/test/C/src/federated/DistributedCountDecentralizedLate.lf index 45e5d01b77..aa14480ffd 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLate.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLate.lf @@ -1,4 +1,4 @@ - /** +/** * Test a form of a distributed deterministic system * where a federate that receives timestamped messages has a timer in addition to the messages * as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. @@ -29,7 +29,7 @@ reactor Print { in->value, in->intended_tag.time - lf_time_start(), in->intended_tag.microstep); - if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, + if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { self->success++; // Message was on-time } @@ -46,7 +46,7 @@ reactor Print { reaction(t) {= // Do nothing. =} - + reaction(shutdown) {= if ((self->success + self->success_stp_violation) != 5) { fprintf(stderr, "Failed to detect STP violations in messages.\n"); diff --git a/test/C/src/federated/DistributedCountDecentralizedLateDownstream.lf b/test/C/src/federated/DistributedCountDecentralizedLateDownstream.lf index d6b0b3993f..c987e0d4ff 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLateDownstream.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLateDownstream.lf @@ -1,10 +1,10 @@ -/** +/** * Test a form of a distributed deterministic system * where a federate that receives timestamped messages has a timer in addition to the messages * as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. * In addition, this test shows that the STP violation is passed down the hierarchy until it is handled. - * - * An STP violation occurs if when a message with intended tag g1 arrives + * + * An STP violation occurs if when a message with intended tag g1 arrives * on a port p after the receiving federate has progressed far enough that * it cannot process an event with tag g1 on the port p. * This test has a fast timer (10 usec period) in the receiving federate @@ -13,7 +13,7 @@ * Furthermore, this test sets the STP threshold to 0, which makes the * violation extremely likely to occur. It could still not occur, however, * if the message arrives between ticks of the 10 usec timer. - * + * * @author Edward A. Lee * @author Soroush Bateni */ @@ -40,7 +40,7 @@ reactor ImportantActuator { in->value, in->intended_tag.time - lf_time_start(), in->intended_tag.microstep); - if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, + if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { self->success++; // Message was on-time } else { @@ -59,7 +59,7 @@ reactor ImportantActuator { reaction(t) {= // Do nothing. =} - + reaction(shutdown) {= if ((self->success + self->success_stp_violation) != 2) { lf_print_error_and_exit("Failed to detect STP violation in messages."); @@ -72,7 +72,7 @@ reactor ImportantActuator { reactor Print { input in:int; reaction(in) {= - tag_t current_tag = lf_tag(); + tag_t current_tag = lf_tag(); lf_print("Print reactor: at tag (%lld, %u) received %d. Intended tag is (%lld, %u).", current_tag.time - lf_time_start(), current_tag.microstep, @@ -95,12 +95,12 @@ reactor Receiver { lf_set(p.in, in->value + 1); lf_set(a.in, in->value + 1); =} - + reaction(t) {= // Do nothing. =} } - + federated reactor { c = new Count(period = 1 sec); r = new Receiver(); diff --git a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf index ffdf0ac476..4323dcf600 100644 --- a/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/C/src/federated/DistributedCountDecentralizedLateHierarchy.lf @@ -1,10 +1,10 @@ -/** +/** * Test a form of a distributed deterministic system * where a federate that receives timestamped messages has a timer in addition to the messages * as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. * In addition, this test shows that the STP violation of the reaction * is passed down the hierarchy until it is handled. - * + * * @author Edward A. Lee * @author Soroush Bateni */ @@ -31,7 +31,7 @@ reactor ImportantActuator { in->value, in->intended_tag.time - lf_time_start(), in->intended_tag.microstep); - if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, + if (lf_tag_compare((tag_t){.time=current_tag.time - lf_time_start(), .microstep=current_tag.microstep}, (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { self->success++; // Message was on-time } @@ -47,7 +47,7 @@ reactor ImportantActuator { reaction(t) {= // Do nothing. =} - + reaction(shutdown) {= if ((self->success + self->success_stp_violation) != 5) { fprintf(stderr, "Failed to detect STP violations in messages.\n"); @@ -61,7 +61,7 @@ reactor ImportantActuator { reactor Print { input in:int; reaction(in) {= - tag_t current_tag = lf_tag(); + tag_t current_tag = lf_tag(); printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", current_tag.time - lf_time_start(), current_tag.microstep, @@ -82,7 +82,7 @@ reactor Receiver { a = new ImportantActuator(); in -> p.in; in -> a.in; - + reaction(t) {= // Do nothing. =} diff --git a/test/C/src/federated/DistributedCountPhysical.lf b/test/C/src/federated/DistributedCountPhysical.lf index ed2e2ab87d..7519a1b18d 100644 --- a/test/C/src/federated/DistributedCountPhysical.lf +++ b/test/C/src/federated/DistributedCountPhysical.lf @@ -1,10 +1,10 @@ -/** +/** * Test a particularly simple form of a distributed deterministic system * where a federation that receives timestamped messages only over connections * that are marked 'physical' (using the ~> arrow). * Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * + * * @author Edward A. Lee * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf index 9643da43a6..4c0f2edab6 100644 --- a/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/C/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,11 +1,11 @@ -/** - * Test a distributed system where a federation +/** + * Test a distributed system where a federation * receives messages only over connections - * that are marked 'physical' (using the - * ~> arrow) with an after delay. The receiver - * verifies that the after delay is correctly + * that are marked 'physical' (using the + * ~> arrow) with an after delay. The receiver + * verifies that the after delay is correctly * imposed. - * + * * @author Edward A. Lee * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf index f8fb218ebc..af7f835f5a 100644 --- a/test/C/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/C/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,10 +1,10 @@ -/** +/** * Test a particularly simple form of a distributed deterministic system * where a federation that receives timestamped messages only over connections * that are marked 'physical' (using the ~> arrow). * Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * + * * @author Edward A. Lee * @author Soroush Bateni */ diff --git a/test/C/src/federated/DistributedDoublePort.lf b/test/C/src/federated/DistributedDoublePort.lf index 277a954e43..39765a3a35 100644 --- a/test/C/src/federated/DistributedDoublePort.lf +++ b/test/C/src/federated/DistributedDoublePort.lf @@ -1,10 +1,10 @@ -/** +/** * Test the case for when two upstream federates * send messages to a downstream federte on two - * different ports. One message should carry a + * different ports. One message should carry a * microstep delay relative to the other * message. - * + * * @author Soroush Bateni */ target C { @@ -23,7 +23,7 @@ reactor CountMicrostep { reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} - + reaction(act) -> out {= lf_set(out, act->value); =} @@ -39,7 +39,7 @@ reactor Print { lf_print_error_and_exit("ERROR: invalid logical simultaneity."); } =} - + reaction(shutdown) {= lf_print("SUCCESS: messages were at least one microstep apart."); =} diff --git a/test/C/src/federated/DistributedLoopedAction.lf b/test/C/src/federated/DistributedLoopedAction.lf index ae8fe60a73..aef554f701 100644 --- a/test/C/src/federated/DistributedLoopedAction.lf +++ b/test/C/src/federated/DistributedLoopedAction.lf @@ -1,7 +1,7 @@ /** * Test a sender-receiver network system that * relies on microsteps being taken into account. - * + * * @author Soroush Bateni */ @@ -29,11 +29,11 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(400 msec)) { if (in->value != self->received_messages++) { fprintf(stderr,"ERROR: received messages out of order.\n"); // exit(1); - } + } if (lf_time_logical_elapsed() != self->breaks * self->break_interval) { fprintf(stderr,"ERROR: received messages at an incorrect time: %lld.\n", lf_time_logical_elapsed()); // exit(2); - } + } if (self->received_messages == self->take_a_break_after) { // Sender is taking a break; @@ -41,11 +41,11 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(400 msec)) { self->received_messages = 0; } =} - + reaction(t) {= // Do nothing =} - + reaction(shutdown) {= if (self->breaks != 3 || (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) @@ -61,6 +61,6 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(400 msec)) { federated reactor DistributedLoopedAction { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in; } diff --git a/test/C/src/federated/DistributedLoopedActionDecentralized.lf b/test/C/src/federated/DistributedLoopedActionDecentralized.lf index 96b4a10a0f..72a624dbb0 100644 --- a/test/C/src/federated/DistributedLoopedActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedActionDecentralized.lf @@ -4,19 +4,19 @@ * The purpose of this test is to check whether the functionalities * pertinent to dynamic STP offset adjustments are present and * functioning to a degree. - * + * * This version of the test does not use a centralized * coordinator to advance tag. Therefore, * the receiver will rely on an STP offset (initially - * zero) to wait long enough for messages to arrive + * zero) to wait long enough for messages to arrive * before advancing its tag. In this test, - * the STP offset is initially zero and gradually - * raised every time an STP violation is perceived until - * no STP violation is observed. Therefore, the exact + * the STP offset is initially zero and gradually + * raised every time an STP violation is perceived until + * no STP violation is observed. Therefore, the exact * outcome of the test will depend on actual runtime * timing. * - * + * * @author Soroush Bateni */ @@ -48,18 +48,18 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(400 msec)) { // in this test because messages on the network can // arrive late. Note that with an accurate STP offset, // this type of error should be extremely rare. - + } if (in->value != self->received_messages) { lf_print_warning("Skipped expected value %d. Received value %d.", self->received_messages, in->value); self->received_messages = in->value; // exit(1); // The receiver should tolerate this type of error - // in this test because multiple messages arriving + // in this test because multiple messages arriving // at a given tag (t, m) can overwrite each other. - // Because messages arrive in order, only the last + // Because messages arrive in order, only the last // value that is received on the port at a given tag - // can be observed. Note that with an accurate STP - // offset, this type of error should be extremely + // can be observed. Note that with an accurate STP + // offset, this type of error should be extremely // rare. // FIXME: Messages should not be dropped or // overwritten. @@ -71,7 +71,7 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(400 msec)) { self->received_messages = 0; } =} - + reaction(shutdown) {= if (self->breaks != 3 || (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) @@ -87,14 +87,14 @@ reactor STPReceiver(take_a_break_after:int(10), break_interval:time(400 msec), s 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 - + reaction (in) -> receiver.in {= lf_print("Received %d.", in->value); lf_set(receiver.in, in->value); =} STP (stp_offset) {= lf_print("Received %d late.", in->value); tag_t current_tag = lf_tag(); - lf_print("STP violation of (%lld, %u) perceived on the input.", + lf_print("STP violation of (%lld, %u) perceived on the input.", current_tag.time - in->intended_tag.time, current_tag.microstep - in->intended_tag.microstep); lf_set(receiver.in, in->value); @@ -107,16 +107,16 @@ reactor STPReceiver(take_a_break_after:int(10), break_interval:time(400 msec), s self->last_time_updated_stp = current_tag.time; } =} - + reaction (t) {= // Do nothing =} } -federated reactor DistributedLoopedActionDecentralized { +federated reactor DistributedLoopedActionDecentralized { sender = new Sender(take_a_break_after = 10, break_interval = 400 msec); stpReceiver = new STPReceiver(take_a_break_after = 10, break_interval = 400 msec); - + sender.out -> stpReceiver.in; } diff --git a/test/C/src/federated/DistributedLoopedPhysicalAction.lf b/test/C/src/federated/DistributedLoopedPhysicalAction.lf index 433d726cbb..be1c2f37f6 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalAction.lf @@ -7,7 +7,7 @@ * sent to the RTI (a form of null message that must be sent because of the * physical action). The presence of this option also silences a warning * about having a physical action that triggers an output. - * + * * @author Soroush Bateni */ @@ -44,7 +44,7 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(550 msec)) { // Comment this line for a more sensible // log output. reaction(in) {= - tag_t current_tag = lf_tag(); + tag_t current_tag = lf_tag(); lf_print("At tag (%lld, %u) received %d.", current_tag.time - lf_time_start(), current_tag.microstep, @@ -60,11 +60,11 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(550 msec)) { self->received_messages = 0; } =} - + reaction(t) {= // Do nothing =} - + reaction(shutdown) {= if (self->breaks != 2 || (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) @@ -79,6 +79,6 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(550 msec)) { federated reactor DistributedLoopedPhysicalAction { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf b/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf index 31b2d2067b..37ab178c84 100644 --- a/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf +++ b/test/C/src/federated/DistributedLoopedPhysicalActionDecentralized.lf @@ -1,7 +1,7 @@ /** * Test a sender-receiver network system that * relies on microsteps being taken into account. - * + * * @author Soroush Bateni */ @@ -15,6 +15,6 @@ import Sender, Receiver from "DistributedLoopedPhysicalAction.lf" federated reactor { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in; } diff --git a/test/C/src/federated/DistributedMultiport.lf b/test/C/src/federated/DistributedMultiport.lf index 94e264e44d..80042e340a 100644 --- a/test/C/src/federated/DistributedMultiport.lf +++ b/test/C/src/federated/DistributedMultiport.lf @@ -24,7 +24,7 @@ reactor Destination { lf_print("Received %d.", in[i]->value); if (in[i]->value != self->count++) { lf_print_error_and_exit("Expected %d.", self->count - 1); - } + } } } =} @@ -39,4 +39,4 @@ federated reactor DistributedMultiport { s = new Source(); d = new Destination(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DistributedMultiportToBank.lf b/test/C/src/federated/DistributedMultiportToBank.lf index 20106db95e..e69477943f 100644 --- a/test/C/src/federated/DistributedMultiportToBank.lf +++ b/test/C/src/federated/DistributedMultiportToBank.lf @@ -14,15 +14,15 @@ reactor Source { self->count++; =} } - + reactor Destination { input in:int; state count:int(0); reaction(in) {= - lf_print("Received %d.", in->value); + lf_print("Received %d.", in->value); if (self->count++ != in->value) { lf_print_error_and_exit("Expected %d.", self->count - 1); - } + } =} reaction(shutdown) {= if (self->count == 0) { @@ -35,4 +35,4 @@ federated reactor DistributedMultiportToBank { s = new Source(); d = new[2] Destination(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DistributedMultiportToken.lf b/test/C/src/federated/DistributedMultiportToken.lf index b814b44272..929f384083 100644 --- a/test/C/src/federated/DistributedMultiportToken.lf +++ b/test/C/src/federated/DistributedMultiportToken.lf @@ -31,7 +31,7 @@ reactor Destination { reaction(in) {= for (int i = 0; i < in_width; i++) { if (in[i]->is_present) { - lf_print("Received %s.", in[i]->value); + lf_print("Received %s.", in[i]->value); } } =} @@ -41,4 +41,4 @@ federated reactor DistributedMultiportToken { s = new Source(); d = new Destination(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/DistributedNetworkOrder.lf b/test/C/src/federated/DistributedNetworkOrder.lf index c7f47d3b5e..b155373ff5 100644 --- a/test/C/src/federated/DistributedNetworkOrder.lf +++ b/test/C/src/federated/DistributedNetworkOrder.lf @@ -1,11 +1,11 @@ /* * This is a test for send_timed_message, * which is an internal API. - * - * This test sends a second message at time 5 msec that has the same intended tag as + * + * This test sends a second message at time 5 msec that has the same intended tag as * a message that it had previously sent at time 0 msec. This results in a warning, * but the message microstep is incremented and correctly received one microstep later. - * + * * @author Soroush Bateni */ @@ -20,11 +20,11 @@ reactor Sender { reaction(t) -> out {= int payload = 1; if (lf_time_logical_elapsed() == 0LL) { - send_timed_message(MSEC(10), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + send_timed_message(MSEC(10), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), (unsigned char*)&payload); } else if (lf_time_logical_elapsed() == MSEC(5)) { payload = 2; - send_timed_message(MSEC(5), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + send_timed_message(MSEC(5), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), (unsigned char*)&payload); } =} @@ -33,7 +33,7 @@ reactor Sender { reactor Receiver { input in:int; state success:int(0); - + reaction(in) {= tag_t current_tag = lf_tag(); if (current_tag.time == (start_time + MSEC(10))) { @@ -48,7 +48,7 @@ reactor Receiver { lf_time_logical_elapsed(), lf_tag().microstep); =} - + reaction(shutdown) {= if (self->success != 2) { fprintf(stderr, "ERROR: Failed to receive messages.\n"); @@ -61,6 +61,6 @@ reactor Receiver { federated reactor DistributedNetworkOrder { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in; } diff --git a/test/C/src/federated/DistributedStop.lf b/test/C/src/federated/DistributedStop.lf index 70a0bfb1ef..7b274b1720 100644 --- a/test/C/src/federated/DistributedStop.lf +++ b/test/C/src/federated/DistributedStop.lf @@ -1,116 +1,116 @@ - /** - * Test for lf_request_stop() in federated execution with centralized coordination. - * - * @author Soroush Bateni - */ -target C; - -reactor Sender { - output out:int; - timer t(0, 1 usec); - logical action act; - state reaction_invoked_correctly:bool(false); - reaction(t, act) -> out, act {= - lf_print("Sending 42 at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); - if (lf_tag().microstep == 0) { - // Instead of having a separate reaction - // for 'act' like Stop.lf, we trigger the - // same reaction to test lf_request_stop() being - // called multiple times - lf_schedule(act, 0); - } - if (lf_time_logical_elapsed() == USEC(1)) { - // Call lf_request_stop() both at (1 usec, 0) and - // (1 usec, 1) - lf_print("Requesting stop at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - - tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), _1usec1) == 0) { - // The reaction was invoked at (1 usec, 1) as expected - self->reaction_invoked_correctly = true; - } else if (lf_tag_compare(lf_tag(), _1usec1) > 0) { - // The reaction should not have been invoked at tags larger than (1 usec, 1) - lf_print_error_and_exit("ERROR: Invoked reaction(t, act) at tag bigger than shutdown."); - } - =} - - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(1) || - lf_tag().microstep != 1) { - lf_print_error_and_exit("ERROR: Sender failed to stop the federation in time. " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } else if (self->reaction_invoked_correctly == false) { - lf_print_error_and_exit("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } - lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -reactor Receiver ( - stp_offset:time(10 msec) // Used in the decentralized variant of the test -) { - input in:int; - state reaction_invoked_correctly:bool(false); - reaction(in) {= - lf_print("Received %d at (%lld, %u).", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - if (lf_time_logical_elapsed() == USEC(1)) { - lf_print("Requesting stop at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - // The receiver should receive a message at tag - // (1 usec, 1) and trigger this reaction - self->reaction_invoked_correctly = true; - } - - tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; - if (lf_tag_compare(lf_tag(), _1usec1) > 0) { - self->reaction_invoked_correctly = false; - } - =} - - reaction(shutdown) {= - // Sender should have requested stop earlier than the receiver. - // Therefore, the shutdown events must occur at (1000, 0) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(1) || - lf_tag().microstep != 1) { - lf_print_error_and_exit("Receiver failed to stop the federation at the right time. " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } else if (self->reaction_invoked_correctly == false) { - lf_print_error_and_exit("Receiver reaction(in) was not invoked the correct number of times. " - "Stopping at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - } - lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -federated reactor DistributedStop { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in; -} \ No newline at end of file +/** + * Test for lf_request_stop() in federated execution with centralized coordination. + * + * @author Soroush Bateni + */ +target C; + +reactor Sender { + output out:int; + timer t(0, 1 usec); + logical action act; + state reaction_invoked_correctly:bool(false); + reaction(t, act) -> out, act {= + lf_print("Sending 42 at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); + if (lf_tag().microstep == 0) { + // Instead of having a separate reaction + // for 'act' like Stop.lf, we trigger the + // same reaction to test lf_request_stop() being + // called multiple times + lf_schedule(act, 0); + } + if (lf_time_logical_elapsed() == USEC(1)) { + // Call lf_request_stop() both at (1 usec, 0) and + // (1 usec, 1) + lf_print("Requesting stop at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + + tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), _1usec1) == 0) { + // The reaction was invoked at (1 usec, 1) as expected + self->reaction_invoked_correctly = true; + } else if (lf_tag_compare(lf_tag(), _1usec1) > 0) { + // The reaction should not have been invoked at tags larger than (1 usec, 1) + lf_print_error_and_exit("ERROR: Invoked reaction(t, act) at tag bigger than shutdown."); + } + =} + + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(1) || + lf_tag().microstep != 1) { + lf_print_error_and_exit("ERROR: Sender failed to stop the federation in time. " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } else if (self->reaction_invoked_correctly == false) { + lf_print_error_and_exit("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } + lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +reactor Receiver ( + stp_offset:time(10 msec) // Used in the decentralized variant of the test +) { + input in:int; + state reaction_invoked_correctly:bool(false); + reaction(in) {= + lf_print("Received %d at (%lld, %u).", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + if (lf_time_logical_elapsed() == USEC(1)) { + lf_print("Requesting stop at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + // The receiver should receive a message at tag + // (1 usec, 1) and trigger this reaction + self->reaction_invoked_correctly = true; + } + + tag_t _1usec1 = (tag_t) { .time = USEC(1) + lf_time_start(), .microstep = 1u }; + if (lf_tag_compare(lf_tag(), _1usec1) > 0) { + self->reaction_invoked_correctly = false; + } + =} + + reaction(shutdown) {= + // Sender should have requested stop earlier than the receiver. + // Therefore, the shutdown events must occur at (1000, 0) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(1) || + lf_tag().microstep != 1) { + lf_print_error_and_exit("Receiver failed to stop the federation at the right time. " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } else if (self->reaction_invoked_correctly == false) { + lf_print_error_and_exit("Receiver reaction(in) was not invoked the correct number of times. " + "Stopping at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + } + lf_print("SUCCESS: Successfully stopped the federation at (%lld, %u).", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +federated reactor DistributedStop { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/federated/DistributedStopDecentralized.lf b/test/C/src/federated/DistributedStopDecentralized.lf index 53ab5809bd..81c9ca5706 100644 --- a/test/C/src/federated/DistributedStopDecentralized.lf +++ b/test/C/src/federated/DistributedStopDecentralized.lf @@ -1,17 +1,17 @@ - /** - * Test for lf_request_stop() in federated execution with decentralized coordination. - * - * @author Soroush Bateni - */ -target C { - coordination: decentralized -}; - -import Sender, Receiver from "DistributedStop.lf" - -federated reactor DistributedStopDecentralized { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in; -} +/** + * Test for lf_request_stop() in federated execution with decentralized coordination. + * + * @author Soroush Bateni + */ +target C { + coordination: decentralized +}; + +import Sender, Receiver from "DistributedStop.lf" + +federated reactor DistributedStopDecentralized { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/federated/DistributedStopZero.lf b/test/C/src/federated/DistributedStopZero.lf index 9cdcb8bcf3..21570abe20 100644 --- a/test/C/src/federated/DistributedStopZero.lf +++ b/test/C/src/federated/DistributedStopZero.lf @@ -1,83 +1,83 @@ -/** - * Test for lf_request_stop() in federated execution with centralized coordination - * at tag (0,0). - * - * @author Soroush Bateni - */ -target C; - -reactor Sender { - output out:int; - timer t(0, 1 usec); - reaction(t) -> out{= - printf("Sending 42 at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_set(out, 42); - - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} - - reaction(shutdown) {= - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Sender failed to stop the federation in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -reactor Receiver { - input in:int; - reaction(in) {= - printf("Received %d at (%lld, %u).\n", - in->value, - lf_time_logical_elapsed(), - lf_tag().microstep); - tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; - if (lf_tag_compare(lf_tag(), zero) == 0) { - // Request stop at (0,0) - printf("Requesting stop at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - lf_request_stop(); - } - =} - - reaction(shutdown) {= - // Sender should have requested stop earlier than the receiver. - // Therefore, the shutdown events must occur at (1000, 0) on the - // receiver. - if (lf_time_logical_elapsed() != USEC(0) || - lf_tag().microstep != 1) { - fprintf(stderr, "ERROR: Receiver failed to stop the federation in time. " - "Stopping at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - exit(1); - } - printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", - lf_time_logical_elapsed(), - lf_tag().microstep); - =} -} - -federated reactor { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in; -} \ No newline at end of file +/** + * Test for lf_request_stop() in federated execution with centralized coordination + * at tag (0,0). + * + * @author Soroush Bateni + */ +target C; + +reactor Sender { + output out:int; + timer t(0, 1 usec); + reaction(t) -> out{= + printf("Sending 42 at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_set(out, 42); + + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} + + reaction(shutdown) {= + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Sender failed to stop the federation in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +reactor Receiver { + input in:int; + reaction(in) {= + printf("Received %d at (%lld, %u).\n", + in->value, + lf_time_logical_elapsed(), + lf_tag().microstep); + tag_t zero = (tag_t) { .time = lf_time_start(), .microstep = 0u }; + if (lf_tag_compare(lf_tag(), zero) == 0) { + // Request stop at (0,0) + printf("Requesting stop at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + lf_request_stop(); + } + =} + + reaction(shutdown) {= + // Sender should have requested stop earlier than the receiver. + // Therefore, the shutdown events must occur at (1000, 0) on the + // receiver. + if (lf_time_logical_elapsed() != USEC(0) || + lf_tag().microstep != 1) { + fprintf(stderr, "ERROR: Receiver failed to stop the federation in time. " + "Stopping at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + exit(1); + } + printf("SUCCESS: Successfully stopped the federation at (%lld, %u).\n", + lf_time_logical_elapsed(), + lf_tag().microstep); + =} +} + +federated reactor { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/federated/DistributedStopZeroDecentralized.lf b/test/C/src/federated/DistributedStopZeroDecentralized.lf index 9cc4f39645..801c39ec67 100644 --- a/test/C/src/federated/DistributedStopZeroDecentralized.lf +++ b/test/C/src/federated/DistributedStopZeroDecentralized.lf @@ -1,16 +1,16 @@ -/** - * Test for lf_request_stop() in federated execution with decentralized coordination - * at tag (0,0). - * - * @author Soroush Bateni - */ -target C; - -import Sender, Receiver from "DistributedStopZero.lf" - -federated reactor { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in; -} +/** + * Test for lf_request_stop() in federated execution with decentralized coordination + * at tag (0,0). + * + * @author Soroush Bateni + */ +target C; + +import Sender, Receiver from "DistributedStopZero.lf" + +federated reactor { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in; +} diff --git a/test/C/src/federated/DistributedToken.lf b/test/C/src/federated/DistributedToken.lf index 668b134425..89f9cecfba 100644 --- a/test/C/src/federated/DistributedToken.lf +++ b/test/C/src/federated/DistributedToken.lf @@ -7,13 +7,13 @@ * Distributed_Sender, and Distributed_Receiver. * The RTI is realized in the first of these and is identified * as a "launcher," so it launches the other two programs. - * + * * This program uses a 'logical' connection -> with a STP violation handler, * decentralized coordination, and an 'after' that is sufficiently - * large to get deterministic timestamps. Hence, it realizes a - * 'poor man's Ptides' that does not require clock synchronization + * large to get deterministic timestamps. Hence, it realizes a + * 'poor man's Ptides' that does not require clock synchronization * nor HLA-style centralized control over the advancement of time. - * + * * @author Edward A. Lee */ target C { @@ -99,4 +99,4 @@ federated reactor DistributedToken { msg = new MessageGenerator(root = "Hello World"); dsp = new PrintMessage(); msg.message -> dsp.message after 40 msec; -} \ No newline at end of file +} diff --git a/test/C/src/federated/LoopDistributedCentralized.lf b/test/C/src/federated/LoopDistributedCentralized.lf index b561be6062..e8d241c7b0 100644 --- a/test/C/src/federated/LoopDistributedCentralized.lf +++ b/test/C/src/federated/LoopDistributedCentralized.lf @@ -1,13 +1,13 @@ /** * This tests a feedback loop with physical actions and * centralized coordination. - * + * * @author Edward A. Lee */ target C { flags: "-Wall", coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, + coordination-options: {advance-message-interval: 100 msec}, timeout: 5 sec } preamble {= @@ -33,7 +33,7 @@ reactor Looper(incr:int(1), delay:time(0 msec)) { // Start the thread that listens for Enter or Return. lf_thread_t thread_id; lf_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); + lf_thread_create(&thread_id, &ping, a); =} reaction(a) -> out {= lf_set(out, self->count); @@ -59,4 +59,4 @@ federated reactor LoopDistributedCentralized(delay:time(0)) { right = new Looper(incr = -1); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf index 167dae414b..3ce7dde49a 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedence.lf @@ -1,14 +1,14 @@ /** * This tests that the precedence order of reaction invocation is kept * when a feedback loop is present in centralized coordination. - * + * * @author Edward A. Lee * @author Soroush Bateni */ target C { flags: "-Wall", coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, + coordination-options: {advance-message-interval: 100 msec}, timeout: 5 sec } @@ -46,4 +46,4 @@ federated reactor (delay:time(0)) { right = new Looper(incr = -1); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf index 1d2848f5e4..92fb61de9c 100644 --- a/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,14 +1,14 @@ /** * This tests that the precedence order of reaction invocation is kept * in the hierarchy of reactors when a feedback loop is present in centralized coordination. - * + * * @author Edward A. Lee * @author Soroush Bateni */ target C { flags: "-Wall", coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, + coordination-options: {advance-message-interval: 100 msec}, timeout: 5 sec } @@ -18,7 +18,7 @@ reactor Contained (incr:int(1)) { state count:int(0); state received_count:int(0); reaction(t) {= - self->count += self->incr; + self->count += self->incr; =} reaction(in) {= self->received_count = self->count; @@ -35,11 +35,11 @@ reactor Looper(incr:int(1), delay:time(0 msec)) { output out:int; state count:int(0); timer t(0, 1 sec); - + c = new Contained(incr = incr); - + reaction(t) -> out {= - lf_print("Sending network output %d", self->count); + lf_print("Sending network output %d", self->count); lf_set(out, self->count); self->count += self->incr; =} @@ -62,4 +62,4 @@ federated reactor (delay:time(0)) { right = new Looper(incr = -1); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/LoopDistributedDecentralized.lf b/test/C/src/federated/LoopDistributedDecentralized.lf index 184ae961f5..7983f514e7 100644 --- a/test/C/src/federated/LoopDistributedDecentralized.lf +++ b/test/C/src/federated/LoopDistributedDecentralized.lf @@ -1,7 +1,7 @@ /** * This tests a feedback loop with physical actions and * decentralized coordination. - * + * * @author Edward A. Lee */ target C { @@ -31,7 +31,7 @@ reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { // Start the thread that listens for Enter or Return. lf_thread_t thread_id; lf_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); + lf_thread_create(&thread_id, &ping, a); =} reaction(a) -> out {= lf_print("Setting out."); @@ -47,7 +47,7 @@ reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { 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_comma_separated_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); + lf_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); =} 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 diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 2586be677c..14b8451fe1 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -1,13 +1,13 @@ /** * This tests a feedback loop with physical actions and * centralized coordination. - * + * * @author Edward A. Lee */ target C { flags: "-Wall", coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, + coordination-options: {advance-message-interval: 100 msec}, timeout: 5 sec } preamble {= @@ -36,7 +36,7 @@ reactor Looper(incr:int(1), delay:time(0 msec)) { // Start the thread that listens for Enter or Return. lf_thread_t thread_id; lf_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); + lf_thread_create(&thread_id, &ping, a); =} reaction(a) -> out, out2 {= if (self->count%2 == 0) { @@ -79,4 +79,4 @@ federated reactor (delay:time(0)) { right.out -> left.in; right.out2 -> left.in2; left.out2 -> right.in2; -} \ No newline at end of file +} diff --git a/test/C/src/federated/ParallelDestinations.lf b/test/C/src/federated/ParallelDestinations.lf index 13e52c3a93..072980eb50 100644 --- a/test/C/src/federated/ParallelDestinations.lf +++ b/test/C/src/federated/ParallelDestinations.lf @@ -12,7 +12,7 @@ reactor Source { output[2] out:int; c1 = new Count(); c2 = new Count(); - + c1.out, c2.out -> out; } @@ -20,6 +20,6 @@ federated reactor { s = new Source(); t1 = new TestCount(num_inputs = 3); t2 = new TestCount(num_inputs = 3); - + s.out -> t1.in, t2.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/ParallelSources.lf b/test/C/src/federated/ParallelSources.lf index 62cb2efc45..6b22cc422d 100644 --- a/test/C/src/federated/ParallelSources.lf +++ b/test/C/src/federated/ParallelSources.lf @@ -13,7 +13,7 @@ reactor Destination { t1 = new TestCount(num_inputs = 3); t2 = new TestCount(num_inputs = 3); - + in -> t1.in, t2.in; } @@ -21,6 +21,6 @@ federated reactor { c1 = new Count(); c2 = new Count(); d = new Destination(); - + c1.out, c2.out -> d.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/ParallelSourcesMultiport.lf b/test/C/src/federated/ParallelSourcesMultiport.lf index 25baac4bdb..d3f3a8ae1c 100644 --- a/test/C/src/federated/ParallelSourcesMultiport.lf +++ b/test/C/src/federated/ParallelSourcesMultiport.lf @@ -12,7 +12,7 @@ reactor Source { output[2] out:int; c1 = new Count(); c2 = new Count(); - + c1.out, c2.out -> out; } @@ -22,7 +22,7 @@ reactor Destination1 { t1 = new TestCount(num_inputs = 3); t2 = new TestCount(num_inputs = 3); t3 = new TestCount(num_inputs = 3); - + in -> t1.in, t2.in, t3.in; } @@ -31,6 +31,6 @@ federated reactor { s2 = new Source(); d1 = new Destination1(); t4 = new TestCount(num_inputs = 3); - + s1.out, s2.out -> d1.in, t4.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/PhysicalSTP.lf b/test/C/src/federated/PhysicalSTP.lf index f43b5304a0..571f1b4aa3 100644 --- a/test/C/src/federated/PhysicalSTP.lf +++ b/test/C/src/federated/PhysicalSTP.lf @@ -6,7 +6,7 @@ target C { timeout: 1900 msec, coordination: decentralized }; - + import Count from "../lib/Count.lf"; reactor Print (STP_offset_param:time(0)) { @@ -38,9 +38,9 @@ reactor Print (STP_offset_param:time(0)) { =} } -federated reactor { +federated reactor { c = new Count(offset = 1 msec, period = 1 sec); p = new Print(STP_offset_param = 1 usec); - + c.out -> p.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/PingPongDistributed.lf b/test/C/src/federated/PingPongDistributed.lf index 9933d2709e..4ad2e4fca5 100644 --- a/test/C/src/federated/PingPongDistributed.lf +++ b/test/C/src/federated/PingPongDistributed.lf @@ -1,21 +1,21 @@ /** * Basic benchmark from the Savina benchmark suite that is * intended to measure message-passing overhead. - * - * This version is distributed, communicating using logical + * + * This version is distributed, communicating using logical * connections over sockets. - * + * * See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * This is a distributed version, where Ping and Pong run in * separate programs and can be run on different machines. - * + * * There is no parallelism in this application, so it does not benefit from being * being distributed. - * + * * @author Edward A. Lee */ target C; @@ -24,5 +24,5 @@ federated reactor(count:int(10)) { ping = new Ping(count = count); pong = new Pong(expected = count); ping.send -> pong.receive; - pong.send -> ping.receive; -} \ No newline at end of file + pong.send -> ping.receive; +} diff --git a/test/C/src/federated/PingPongDistributedPhysical.lf b/test/C/src/federated/PingPongDistributedPhysical.lf index 24b590d5cb..73a0931480 100644 --- a/test/C/src/federated/PingPongDistributedPhysical.lf +++ b/test/C/src/federated/PingPongDistributedPhysical.lf @@ -1,29 +1,29 @@ - /** +/** * Basic benchmark from the Savina benchmark suite that is * intended to measure message-passing overhead. - * + * * This version is distributed, communicating using physical * connections over sockets. - * + * * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * This is a distributed version, where Ping and Pong run in * separate programs and can be run on different machines. - * + * * To get a sense, some (informal) results for 1,000,000 ping-pongs * on my Mac: - * + * * Unthreaded: 97 msec * Threaded: 265 msec * Distributed: 53 seconds - * + * * There is no parallelism in this application, so it does not benefit from being * being distributed. - * + * * These measurements are total execution time, including startup and shutdown, of * all three programs. - * + * * @author Edward A. Lee */ target C; @@ -33,7 +33,7 @@ reactor Ping(count:int(10)) { output send:int; state pingsLeft:int(count); logical action serve; - reaction (startup, serve) -> send {= + reaction (startup, serve) -> send {= printf("At logical time %lld, Ping sending %d.\n", lf_time_logical_elapsed(), self->pingsLeft); lf_set(send, self->pingsLeft--); =} @@ -44,7 +44,7 @@ reactor Ping(count:int(10)) { lf_request_stop(); } =} -} +} reactor Pong(expected:int(10)) { input receive:int; output send:int; @@ -71,5 +71,5 @@ federated reactor (count:int(10)) { ping = new Ping(count = count); pong = new Pong(expected = count); ping.send ~> pong.receive; - pong.send ~> ping.receive; + pong.send ~> ping.receive; } diff --git a/test/C/src/federated/StopAtShutdown.lf b/test/C/src/federated/StopAtShutdown.lf index 558d713ee0..f17ed81a03 100644 --- a/test/C/src/federated/StopAtShutdown.lf +++ b/test/C/src/federated/StopAtShutdown.lf @@ -1,9 +1,9 @@ /** - * Check that lf_request_stop() doesn't cause + * Check that lf_request_stop() doesn't cause * any issues at the shutdown tag. - * + * * Original bug discovered by Steven Wong - * + * * @author Steven Wong */ target C { @@ -15,11 +15,11 @@ reactor A { reaction(startup) {= lf_print("Hello World!"); =} - + reaction(in) {= lf_print("Got it"); =} - + reaction(shutdown) {= lf_request_stop(); =} @@ -40,4 +40,4 @@ federated reactor { a = new A(); b = new B(); b.out -> a.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/TopLevelArtifacts.lf b/test/C/src/federated/TopLevelArtifacts.lf index 7a8ab4409c..2ce9dbdb69 100644 --- a/test/C/src/federated/TopLevelArtifacts.lf +++ b/test/C/src/federated/TopLevelArtifacts.lf @@ -1,19 +1,19 @@ /** * Test whether top-level reactions, actions, and ports are handled appropriately. - * + * * Currently, these artifacts are replicated on all federates. - * + * * @note This just tests for the correctness of the code generation. These top-level * artifacts might be disallowed in the future. */ - + target C { timeout: 1 msec }; - + import Count from "../lib/Count.lf"; import TestCount from "../lib/TestCount.lf"; - + federated reactor { state successes:int(0); reaction (startup) {= @@ -28,15 +28,15 @@ reaction (act) {= self->successes++; =} - + c = new Count(); tc = new TestCount(); c.out -> tc.in; - + reaction (shutdown) {= if (self->successes != 3) { lf_print_error_and_exit("Failed to properly execute top-level reactions"); } lf_print("SUCCESS!"); =} -} \ No newline at end of file +} diff --git a/test/C/src/federated/failing/DistributedDoublePortLooped.lf b/test/C/src/federated/failing/DistributedDoublePortLooped.lf index dc662cc49e..10ee73fb43 100644 --- a/test/C/src/federated/failing/DistributedDoublePortLooped.lf +++ b/test/C/src/federated/failing/DistributedDoublePortLooped.lf @@ -1,10 +1,10 @@ -/** +/** * Test the case for when two upstream federates * send messages to a downstream federate on two - * different ports. One message should carry a + * different ports. One message should carry a * microstep delay relative to the other * message. - * + * * @author Soroush Bateni */ target C { @@ -30,7 +30,7 @@ reactor Count { output out2:int; timer t(0, 1 msec); reaction(in1) -> out1 {= - + =} // in2 is not connected to anything. // Consequently, the control reaction @@ -39,7 +39,7 @@ reactor Count { lf_set(out2, self->count++); =} reaction(in3) {= - + =} } @@ -51,7 +51,7 @@ reactor CountMicrostep { reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} - + reaction(act) -> out {= lf_set(out, act->value); =} diff --git a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf index 874d96d472..9e9ce50d11 100644 --- a/test/C/src/federated/failing/DistributedDoublePortLooped2.lf +++ b/test/C/src/federated/failing/DistributedDoublePortLooped2.lf @@ -1,10 +1,10 @@ -/** +/** * Test the case for when two upstream federates * send messages to a downstream federte on two - * different ports. One message should carry a + * different ports. One message should carry a * microstep delay relative to the other * message. - * + * * @author Soroush Bateni */ target C { @@ -22,7 +22,7 @@ reactor Count { lf_print("Count sends %d.", self->count); lf_set(out, self->count++); =} - + reaction(in) {= lf_print("Count received %d.", in->value); =} @@ -36,7 +36,7 @@ reactor CountMicrostep { reaction(t) -> act {= lf_schedule_int(act, 0, self->count++); =} - + reaction(act) -> out {= lf_set(out, act->value); =} diff --git a/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf b/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf index 521fe916cd..f8fe99fca6 100644 --- a/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf +++ b/test/C/src/federated/failing/DistributedNetworkOrderDecentralized.lf @@ -3,10 +3,10 @@ * which is an internal API. * This version of the test uses the * decentralized coordination. - * + * * FIXME: Because this test sends messages with intended tag * out of order, it will fail. - * + * * @author Soroush Bateni */ @@ -21,11 +21,11 @@ reactor Sender { reaction(t) {= int payload = 1; if (lf_time_logical_elapsed() == 0LL) { - send_timed_message(MSEC(10), MSG_TYPE_P2P_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + send_timed_message(MSEC(10), MSG_TYPE_P2P_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), (unsigned char*)&payload); } else if (lf_time_logical_elapsed() == MSEC(5)) { payload = 2; - send_timed_message(MSEC(5), MSG_TYPE_P2P_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + send_timed_message(MSEC(5), MSG_TYPE_P2P_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), (unsigned char*)&payload); } =} @@ -34,7 +34,7 @@ reactor Sender { reactor Receiver { input in:int; state success:int(0); - + reaction(in) {= tag_t current_tag = lf_tag(); if (current_tag.time == (start_time + MSEC(10))) { @@ -51,7 +51,7 @@ reactor Receiver { in->intended_tag.time - lf_time_start(), in->intended_tag.microstep); =} - + reaction(shutdown) {= if (self->success != 2) { fprintf(stderr, "ERROR: Failed to receive messages.\n"); @@ -64,6 +64,6 @@ reactor Receiver { federated reactor { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in; } diff --git a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf index 03b1d4a82b..5d79fd3927 100644 --- a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf +++ b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedence.lf @@ -1,7 +1,7 @@ /** * This tests that the precedence order of reaction invocation is kept * when a feedback loop is present in decentralized coordination. - * + * * @author Edward A. Lee * @author Soroush Bateni */ @@ -31,8 +31,8 @@ reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { 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); - self->received_count = self->count; + lf_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + self->received_count = self->count; =} 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 @@ -57,4 +57,4 @@ federated reactor (delay:time(0)) { right = new Looper(incr = -1, stp_offset = 5 msec); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf index be86201e88..6cf9236901 100644 --- a/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf +++ b/test/C/src/federated/failing/LoopDistributedDecentralizedPrecedenceHierarchy.lf @@ -1,7 +1,7 @@ /** * 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 */ @@ -18,9 +18,9 @@ reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { output out:int; state count:int(0); timer t(0, 1 sec); - + c = new Contained(incr = incr); - + reaction(t) -> out {= lf_set(out, self->count); self->count += self->incr; @@ -54,4 +54,4 @@ federated reactor (delay:time(0)) { right = new Looper(incr = -1, stp_offset = 5 msec); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/C/src/lib/Imported.lf b/test/C/src/lib/Imported.lf index 8b2a8d143d..02a0534cc3 100644 --- a/test/C/src/lib/Imported.lf +++ b/test/C/src/lib/Imported.lf @@ -6,6 +6,6 @@ reactor Imported { input x:int; a = new ImportedAgain(); reaction(x) -> a.x {= - lf_set(a.x, x->value); + lf_set(a.x, x->value); =} -} \ No newline at end of file +} diff --git a/test/C/src/lib/ImportedComposition.lf b/test/C/src/lib/ImportedComposition.lf index 8f1cf5073d..1caef740d6 100644 --- a/test/C/src/lib/ImportedComposition.lf +++ b/test/C/src/lib/ImportedComposition.lf @@ -17,4 +17,4 @@ reactor ImportedComposition { x -> g1.x after 10 msec; g1.y -> g2.x after 30 msec; g2.y -> y after 15 msec; -} \ No newline at end of file +} diff --git a/test/C/src/lib/InternalDelay.lf b/test/C/src/lib/InternalDelay.lf index 4116d08c2c..8571bddc16 100644 --- a/test/C/src/lib/InternalDelay.lf +++ b/test/C/src/lib/InternalDelay.lf @@ -11,4 +11,4 @@ reactor InternalDelay ( reaction(d) -> out {= lf_set(out, d->value); =} -} \ No newline at end of file +} diff --git a/test/C/src/lib/LoopedActionSender.lf b/test/C/src/lib/LoopedActionSender.lf index 0dc8dd77d1..abdd2fcfd6 100644 --- a/test/C/src/lib/LoopedActionSender.lf +++ b/test/C/src/lib/LoopedActionSender.lf @@ -1,37 +1,36 @@ -/** - * A sender reactor that outputs integers - * in superdense time. - * - * @author Soroush Bateni - */ -target C; - -/** - * @param take_a_break_after: Indicates how many messages are sent - * in consecutive superdense time - * @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)) { - output out:int; - logical action act; - state sent_messages:int(0); - reaction(startup, act) -> act, out {= - // Send a message on out - /* printf("At tag (%lld, %u) sending value %d.\n", - lf_time_logical_elapsed(), - lf_tag().microstep, - self->sent_messages - ); */ - lf_set(out, self->sent_messages); - self->sent_messages++; - if (self->sent_messages < self->take_a_break_after) { - lf_schedule(act, 0); - } else { - // Take a break - self->sent_messages=0; - lf_schedule(act, self->break_interval); - } - =} -} - \ No newline at end of file +/** + * A sender reactor that outputs integers + * in superdense time. + * + * @author Soroush Bateni + */ +target C; + +/** + * @param take_a_break_after: Indicates how many messages are sent + * in consecutive superdense time + * @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)) { + output out:int; + logical action act; + state sent_messages:int(0); + reaction(startup, act) -> act, out {= + // Send a message on out + /* printf("At tag (%lld, %u) sending value %d.\n", + lf_time_logical_elapsed(), + lf_tag().microstep, + self->sent_messages + ); */ + lf_set(out, self->sent_messages); + self->sent_messages++; + if (self->sent_messages < self->take_a_break_after) { + lf_schedule(act, 0); + } else { + // Take a break + self->sent_messages=0; + lf_schedule(act, self->break_interval); + } + =} +} diff --git a/test/C/src/lib/Test.lf b/test/C/src/lib/Test.lf index 96beb934c5..f4c573f009 100644 --- a/test/C/src/lib/Test.lf +++ b/test/C/src/lib/Test.lf @@ -10,4 +10,4 @@ reactor TestDouble(expected:double[](1.0, 1.0, 1.0, 1.0)) { } self->count++; =} -} \ No newline at end of file +} diff --git a/test/C/src/lib/TestCount.lf b/test/C/src/lib/TestCount.lf index 7a1f081f4a..7580494f05 100644 --- a/test/C/src/lib/TestCount.lf +++ b/test/C/src/lib/TestCount.lf @@ -2,7 +2,7 @@ * Test that a counting sequence of inputs starts with the specified start * parameter value, increments by the specified stride, and receives the * specified number of inputs. - * + * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. * @param num_inputs The number of inputs expected. Default is 1. @@ -29,4 +29,4 @@ reactor TestCount(start:int(1), stride:int(1), num_inputs:int(1)) { ); } =} -} \ No newline at end of file +} diff --git a/test/C/src/lib/TestCountMultiport.lf b/test/C/src/lib/TestCountMultiport.lf index 4e6dda48a5..60d1fee312 100644 --- a/test/C/src/lib/TestCountMultiport.lf +++ b/test/C/src/lib/TestCountMultiport.lf @@ -4,7 +4,7 @@ * specified number of inputs. This version has a multiport input, and * each input is expected to be present and incremented over the previous * input. - * + * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. * @param num_inputs The number of inputs expected on each channel. Default is 1. @@ -36,4 +36,4 @@ reactor TestCountMultiport(start:int(1), stride:int(1), num_inputs:int(1), width ); } =} -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/ConvertCaseTest.lf b/test/C/src/modal_models/ConvertCaseTest.lf index 7f710ad347..8f4f7603ce 100644 --- a/test/C/src/modal_models/ConvertCaseTest.lf +++ b/test/C/src/modal_models/ConvertCaseTest.lf @@ -14,17 +14,17 @@ reactor ResetProcessor { input discard:bool; input character:char; output converted:int; - + initial mode Converting { converter = new Converter(); character -> converter.raw; converter.converted -> converted; - + reaction(discard) -> Discarding {= lf_set_mode(Discarding); =} } - + mode Discarding { reaction(character) -> converted {= lf_set(converted, '_'); @@ -40,17 +40,17 @@ reactor HistoryProcessor { input discard:bool; input character:char; output converted:int; - + initial mode Converting { converter = new Converter(); character -> converter.raw; converter.converted -> converted; - + reaction(discard) -> Discarding {= lf_set_mode(Discarding); =} } - + mode Discarding { reaction(character) -> converted {= lf_set(converted, '_'); @@ -101,13 +101,13 @@ reactor Converter { reactor InputFeeder(message:string("")) { output character:char; state idx:int(0); - + timer t(0, 250msec); - + preamble {= #include =} - + reaction(t) -> character {= if (self->idx < strlen(self->message)) { lf_set(character, *(self->message + self->idx)); @@ -118,17 +118,17 @@ reactor InputFeeder(message:string("")) { main reactor { timer stepper(500msec, 1sec) - + feeder = new InputFeeder(message="Hello World!") reset_processor = new ResetProcessor() history_processor = new HistoryProcessor() - + feeder.character -> reset_processor.character feeder.character -> history_processor.character - + test = new TraceTesting( events_size = 2, - trace_size = 60, + trace_size = 60, trace = ( 0,1,72,1,72, 250000000,1,69,1,69, @@ -149,16 +149,16 @@ main reactor { lf_set(reset_processor.discard, true); lf_set(history_processor.discard, true); =} - + reaction(reset_processor.converted) {= printf("Reset: %c\n", reset_processor.converted->value); =} - + reaction(history_processor.converted) {= printf("History: %c\n", history_processor.converted->value); =} - + reset_processor.converted, history_processor.converted -> test.events -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/Count3Modes.lf b/test/C/src/modal_models/Count3Modes.lf index ecc7ed568c..ce7a232944 100644 --- a/test/C/src/modal_models/Count3Modes.lf +++ b/test/C/src/modal_models/Count3Modes.lf @@ -10,7 +10,7 @@ target C { reactor CounterCycle { input next:bool; output count:int; - + initial mode One { reaction(next) -> count, Two {= lf_set(count, 1); @@ -34,9 +34,9 @@ reactor CounterCycle { main reactor { timer stepper(0, 250msec); counter = new CounterCycle(); - + state expected_value:int(1); - + // Trigger reaction(stepper) -> counter.next {= lf_set(counter.next, true); @@ -45,7 +45,7 @@ main reactor { // Check reaction(stepper) counter.count {= printf("%d\n", counter.count->value); - + if (!counter.count->is_present) { printf("ERROR: Missing mode change.\n"); exit(1); @@ -53,11 +53,11 @@ main reactor { printf("ERROR: Wrong mode.\n"); exit(2); } - + if (self->expected_value == 3) { self->expected_value = 1; } else { self->expected_value++; } =} -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/ModalActions.lf b/test/C/src/modal_models/ModalActions.lf index 685c2ceeb9..3b2e2b0d6f 100644 --- a/test/C/src/modal_models/ModalActions.lf +++ b/test/C/src/modal_models/ModalActions.lf @@ -11,17 +11,17 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next:bool - + output mode_switch:int output action1_sched:int output action1_exec:int output action2_sched:int output action2_exec:int - + initial mode One { timer T1(0, 750msec) logical action delay1(500msec) - + reaction(T1) -> delay1, action1_sched {= printf("Scheduled Action\n"); lf_schedule(delay1, 0); @@ -31,7 +31,7 @@ reactor Modal { printf("Executed Action\n"); lf_set(action1_exec, 1); =} - + reaction(next) -> reset(Two), mode_switch {= printf("Transitioning to mode Two (reset)\n"); lf_set(mode_switch, 1); @@ -41,7 +41,7 @@ reactor Modal { mode Two { timer T2(0, 750msec) logical action delay2(500msec) - + reaction(T2) -> delay2, action2_sched {= printf("Scheduled Action2\n"); lf_schedule(delay2, 0); @@ -51,7 +51,7 @@ reactor Modal { printf("Executed Action2\n"); lf_set(action2_exec, 1); =} - + reaction(next) -> continue(One), mode_switch {= printf("Transitioning to mode One (continue)\n"); lf_set(mode_switch, 1); @@ -62,11 +62,11 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 5, - trace_size = 165, + trace_size = 165, trace = ( 0,0,0,1,1,0,0,0,0,0,0, 500000000,0,0,0,1,1,1,0,0,0,0, @@ -89,11 +89,11 @@ main reactor { reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} - + modal.mode_switch, modal.action1_sched, modal.action1_exec, modal.action2_sched, modal.action2_exec -> test.events -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/ModalAfter.lf b/test/C/src/modal_models/ModalAfter.lf index 0a64743fd3..427c3c74b1 100644 --- a/test/C/src/modal_models/ModalAfter.lf +++ b/test/C/src/modal_models/ModalAfter.lf @@ -11,20 +11,20 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next:bool - + output mode_switch:int output produced1:int output consumed1:int output produced2:int output consumed2:int - + initial mode One { producer1 = new Producer(mode_id=1) consumer1 = new Consumer(mode_id=1) producer1.product -> produced1 producer1.product -> consumer1.product after 500msec; consumer1.report -> consumed1; - + reaction(next) -> reset(Two), mode_switch {= printf("Transitioning to mode Two (reset)\n"); lf_set(mode_switch, 1); @@ -37,7 +37,7 @@ reactor Modal { producer2.product -> produced2 producer2.product -> consumer2.product after 500msec; consumer2.report -> consumed2; - + reaction(next) -> continue(One), mode_switch {= printf("Transitioning to mode One (continue)\n"); lf_set(mode_switch, 1); @@ -48,9 +48,9 @@ reactor Modal { reactor Producer(mode_id:int(0)) { output product:int - + timer t(0, 750msec) - + reaction(t) -> product {= printf("Produced in %d\n", self->mode_id); lf_set(product, 1); @@ -60,7 +60,7 @@ reactor Producer(mode_id:int(0)) { reactor Consumer(mode_id:int(0)) { input product:int output report:int - + reaction(product) -> report {= printf("Consumed in %d\n", self->mode_id); lf_set(report, 1); @@ -69,11 +69,11 @@ reactor Consumer(mode_id:int(0)) { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 5, - trace_size = 165, + trace_size = 165, trace = ( 0,0,0,1,1,0,0,0,0,0,0, 500000000,0,0,0,1,1,1,0,0,0,0, @@ -96,11 +96,11 @@ main reactor { reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} - + modal.mode_switch, modal.produced1, modal.consumed1, modal.produced2, modal.consumed2 -> test.events -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/ModalCycleBreaker.lf b/test/C/src/modal_models/ModalCycleBreaker.lf index 8446ec5fbe..f5b39e69d6 100644 --- a/test/C/src/modal_models/ModalCycleBreaker.lf +++ b/test/C/src/modal_models/ModalCycleBreaker.lf @@ -1,6 +1,6 @@ /* * Modal Reactor Test. - * + * * Tests if connections in the same reactor that have the same destination work if they are located in separate modes. */ target C { @@ -14,14 +14,14 @@ reactor Modal { input in1:int; input in2:int; output out:int; - + mode Two { // Defining reaction to in2 before in1 would cause cycle if no mode were present timer wait(150msec, 1sec) - + reaction(in2) {= // lf_set(out, in2->value); =} - + reaction(wait) -> One {= lf_set_mode(One); printf("Switching to mode One\n"); @@ -43,21 +43,21 @@ reactor Modal { reactor Counter(period:time(1sec)) { output value:int - + timer t(0, period) state curval:int(0) - + reaction(t) -> value {= lf_set(value, self->curval++); =} } main reactor { - counter = new Counter(period=100msec) + counter = new Counter(period=100msec) modal = new Modal() test = new TraceTesting( events_size = 1, - trace_size = 27, + trace_size = 27, trace = ( 0,1,0, 100000000,1,1, @@ -70,10 +70,10 @@ main reactor { 100000000,1,9 ), training = false) - + counter.value -> modal.in1 modal.out -> modal.in2 - + modal.out -> test.events @@ -81,4 +81,4 @@ main reactor { reaction(modal.out) {= printf("%d\n", modal.out->value); =} -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/ModalNestedReactions.lf b/test/C/src/modal_models/ModalNestedReactions.lf index 27c7121bda..9de2c054e2 100644 --- a/test/C/src/modal_models/ModalNestedReactions.lf +++ b/test/C/src/modal_models/ModalNestedReactions.lf @@ -24,7 +24,7 @@ reactor CounterCycle { fwd = new Forward() next -> fwd.in fwd.out -> only_in_two - + reaction(next) -> count, One {= lf_set(count, 2); lf_set_mode(One); @@ -40,7 +40,7 @@ reactor CounterCycle { reactor Forward { input in:bool; output out:bool; - + reaction(in) -> out {= lf_set(out, in->value); =} @@ -49,7 +49,7 @@ reactor Forward { main reactor { timer stepper(0, 250msec) counter = new CounterCycle() - + // Trigger reaction(stepper) -> counter.next {= lf_set(counter.next, true); @@ -70,7 +70,7 @@ main reactor { exit(3); } =} - + reaction(counter.never) {= printf("ERROR: Detected output from unreachable mode.\n"); exit(4); diff --git a/test/C/src/modal_models/ModalStartup.lf b/test/C/src/modal_models/ModalStartup.lf index 5ea7f31567..4145fef9ec 100644 --- a/test/C/src/modal_models/ModalStartup.lf +++ b/test/C/src/modal_models/ModalStartup.lf @@ -11,30 +11,30 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next:bool - + output mode_switch:int output startup1:int output startup2:int output startup3:int - + initial mode One { reaction(startup) -> startup1 {= printf("Startup 1 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); lf_set(startup1, 1); =} - + reaction(next) -> reset(Two), mode_switch {= printf("Transitioning to mode Two (reset)\n"); lf_set(mode_switch, 1); lf_set_mode(Two); =} } - mode Two { + mode Two { reaction(startup) -> startup2 {= printf("Startup 2 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); lf_set(startup2, 1); =} - + reaction(next) -> continue(Three), mode_switch {= printf("Transitioning to mode Three (continue)\n"); lf_set(mode_switch, 1); @@ -42,12 +42,12 @@ reactor Modal { =} } - mode Three { + mode Three { reaction(startup) -> startup3 {= printf("Startup 3 at (%lld, %u).\n", lf_time_logical_elapsed(), lf_tag().microstep); lf_set(startup3, 1); =} - + reaction(next) -> continue(One), mode_switch {= printf("Transitioning to mode One (continue)\n"); lf_set(mode_switch, 1); @@ -58,11 +58,11 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 4, - trace_size = 72, + trace_size = 72, trace = ( 0,0,0,1,1,0,0,0,0, 1000000000,1,1,0,1, @@ -73,7 +73,7 @@ main reactor { 1,1,0,1,0,1,0,1, 1000000000,1,1,0,1,0, 1,0,1,0,0,1,0,1,1,1,0,1 - ), + ), training = false ) @@ -81,7 +81,7 @@ main reactor { reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} - + modal.mode_switch, modal.startup1, modal.startup2, diff --git a/test/C/src/modal_models/ModalStateReset.lf b/test/C/src/modal_models/ModalStateReset.lf index ecc7847229..11849a8e19 100644 --- a/test/C/src/modal_models/ModalStateReset.lf +++ b/test/C/src/modal_models/ModalStateReset.lf @@ -11,28 +11,28 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next:bool; - + output mode_switch:int output count0:int; output count1:int; output count2:int; - + state counter0:int(0); - + reaction(next) -> count0 {= printf("Counter0: %d\n", self->counter0); lf_set(count0, self->counter0++); =} - + initial mode One { state counter1:int(0); timer T1(0msec, 250msec); - + reaction(T1) -> count1 {= printf("Counter1: %d\n", self->counter1); lf_set(count1, self->counter1++); =} - + reaction(next) -> reset(Two), mode_switch {= printf("Transitioning to mode Two (reset)\n"); lf_set(mode_switch, 1); @@ -42,12 +42,12 @@ reactor Modal { mode Two { state counter2:int(-2); timer T2(0msec, 250msec); - + reaction(T2) -> count2 {= printf("Counter2: %d\n", self->counter2); lf_set(count2, self->counter2++); =} - + reaction(next) -> continue(One), mode_switch {= printf("Transitioning to mode One (continue)\n"); lf_set(mode_switch, 1); @@ -58,11 +58,11 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 4, - trace_size = 171, + trace_size = 171, trace = ( 0,0,0,0,0,1,0,0,0, 250000000,0,0,0,0,1,1,0,0, @@ -89,10 +89,10 @@ main reactor { reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} - + modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/ModalTimers.lf b/test/C/src/modal_models/ModalTimers.lf index 3367ba9afe..1548df116f 100644 --- a/test/C/src/modal_models/ModalTimers.lf +++ b/test/C/src/modal_models/ModalTimers.lf @@ -11,19 +11,19 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next:bool - + output mode_switch:int output timer1:int output timer2:int - + initial mode One { timer T1(0, 750msec) - + reaction(T1) -> timer1 {= printf("T1\n"); lf_set(timer1, 1); =} - + reaction(next) -> reset(Two), mode_switch {= printf("Transitioning to mode Two (reset)\n"); lf_set(mode_switch, 1); @@ -32,12 +32,12 @@ reactor Modal { } mode Two { timer T2(0, 750msec) - + reaction(T2) -> timer2 {= printf("T2\n"); lf_set(timer2, 1); =} - + reaction(next) -> continue(One), mode_switch {= printf("Transitioning to mode One (continue)\n"); lf_set(mode_switch, 1); @@ -48,11 +48,11 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 3, - trace_size = 77, + trace_size = 77, trace = ( 0,0,0,1,1,0,0, 750000000,0,0,1,1,0,0, @@ -71,9 +71,9 @@ main reactor { reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} - + modal.mode_switch, modal.timer1, modal.timer2 -> test.events -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf index 9c0771083b..039ad2a859 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -1,6 +1,6 @@ /* * Modal Reactor Test. - * + * * Tests if connections in the same reactor that have the same destination work if they are located in separate modes. */ target C { @@ -13,11 +13,11 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next:bool; output count:int; - + initial mode One { counter1 = new Counter(period=250msec); counter1.value -> count; - + reaction(next) -> Two {= lf_set_mode(Two); =} @@ -49,7 +49,7 @@ main reactor { modal = new Modal() test = new TraceTesting( events_size = 1, - trace_size = 51, + trace_size = 51, trace = ( 0,1,0, 250000000,1,1, diff --git a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index 1c182c49cb..a03957e35a 100644 --- a/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/C/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -1,6 +1,6 @@ /* * Modal Reactor Test. - * + * * Tests if a connection and a reaction in the same reactor can have the same destination if they are located in separate modes. */ target C { @@ -13,22 +13,22 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next:bool; output count:int; - + initial mode One { counter1 = new Counter(period=250msec); counter1.value -> count; - + reaction(next) -> Two {= lf_set_mode(Two); =} } mode Two { counter2 = new Counter(period=100msec); - + reaction(counter2.value) -> count {= lf_set(count, counter2.value->value * 10); =} - + reaction(next) -> continue(One) {= lf_set_mode(One); =} @@ -37,10 +37,10 @@ reactor Modal { reactor Counter(period:time(1sec)) { output value:int - + timer t(0, period) state curval:int(0) - + reaction(t) -> value {= lf_set(value, self->curval++); =} @@ -48,11 +48,11 @@ reactor Counter(period:time(1sec)) { main reactor { timer stepper(500msec, 500msec) - + modal = new Modal() test = new TraceTesting( events_size = 1, - trace_size = 51, + trace_size = 51, trace = ( 0,1,0, 250000000,1,1, @@ -77,12 +77,12 @@ main reactor { reaction(stepper) -> modal.next {= lf_set(modal.next, true); =} - + // Print reaction(modal.count) {= printf("%d\n", modal.count->value); =} - + modal.count -> test.events -} \ No newline at end of file +} diff --git a/test/C/src/modal_models/util/TraceTesting.lf b/test/C/src/modal_models/util/TraceTesting.lf index c8d91b7898..b0d9917058 100644 --- a/test/C/src/modal_models/util/TraceTesting.lf +++ b/test/C/src/modal_models/util/TraceTesting.lf @@ -6,45 +6,45 @@ target C; preamble {= #include =} - + reactor TraceTesting(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) - + reaction(startup) {= self->last_reaction_time = lf_time_logical(); =} - + reaction(events) {= // Time passed since last reaction int curr_reaction_delay = lf_time_logical() - self->last_reaction_time; - + if (self->training) { // Save time self->recorded_events = (int*) realloc(self->recorded_events, sizeof(int) * (self->recorded_events_next + 1 + 2 * self->events_size)); - self->recorded_events[self->recorded_events_next++] = curr_reaction_delay; + self->recorded_events[self->recorded_events_next++] = curr_reaction_delay; } else { if (self->trace_idx >= self->trace_size) { printf("ERROR: Trace Error: Current execution exceeds given trace.\n"); exit(1); } - + int trace_reaction_delay = self->trace[self->trace_idx++]; - + if (curr_reaction_delay != trace_reaction_delay) { printf("ERROR: Trace Mismatch: Unexpected reaction timing. (delay: %d, expected: %d)\n", curr_reaction_delay, trace_reaction_delay); exit(2); } } - + for (int i = 0; i < self->events_size; i++) { int curr_present = events[i]->is_present; int curr_value = events[i]->value; - + if (self->training) { // Save event self->recorded_events[self->recorded_events_next++] = curr_present; @@ -52,7 +52,7 @@ reactor TraceTesting(events_size:int(0), trace_size:int(0), trace:int[](0), trai } else { int trace_present = self->trace[self->trace_idx++]; int trace_value = self->trace[self->trace_idx++]; - + if (trace_present != curr_present) { printf("ERROR: Trace Mismatch: Unexpected event presence. (event: %d, presence: %d, expected: %d)\n", i, curr_present, trace_present); exit(3); @@ -62,10 +62,10 @@ reactor TraceTesting(events_size:int(0), trace_size:int(0), trace:int[](0), trai } } } - + self->last_reaction_time = lf_time_logical(); =} - + reaction(shutdown) {= if (self->training) { printf("Recorded event trace (%d): (", self->recorded_events_next); @@ -76,8 +76,8 @@ reactor TraceTesting(events_size:int(0), trace_size:int(0), trace:int[](0), trai } } printf(")\n"); - + free(self->recorded_events); } =} -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankIndexInitializer.lf b/test/C/src/multiport/BankIndexInitializer.lf index 4a638f9bf2..84d25b5dda 100644 --- a/test/C/src/multiport/BankIndexInitializer.lf +++ b/test/C/src/multiport/BankIndexInitializer.lf @@ -18,7 +18,7 @@ reactor Source( reactor Sink(width:int(4)) { input[width] in:int; state received:bool(false); - + reaction (in) {= for (int idx = 0; idx < in_width; idx++) { if (in[idx]->is_present) { @@ -40,4 +40,4 @@ main reactor(width:int(4)) { source = new[width] Source(value = {= table[bank_index] =}); sink = new Sink(width = width); source.out -> sink.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankMulticast.lf b/test/C/src/multiport/BankMulticast.lf index ab938c3de0..7112a88804 100644 --- a/test/C/src/multiport/BankMulticast.lf +++ b/test/C/src/multiport/BankMulticast.lf @@ -13,26 +13,26 @@ import TestCount from "../lib/TestCount.lf" reactor Foo { input in:int; output out:int; - + c = new Count(); c.out -> out; - + d = new TestCount(num_inputs = 4); in -> d.in; } reactor Bar { output[4] out:int; - + foo = new[4] Foo(); - + foo.out -> foo.in; foo.out -> out; } main reactor { bar = new Bar(); - + d = new[4] TestCount(num_inputs = 4); bar.out -> d.in; } diff --git a/test/C/src/multiport/BankMultiportToReaction.lf b/test/C/src/multiport/BankMultiportToReaction.lf index d6b2724860..dd8435925d 100644 --- a/test/C/src/multiport/BankMultiportToReaction.lf +++ b/test/C/src/multiport/BankMultiportToReaction.lf @@ -16,7 +16,7 @@ main reactor { state received:bool(false); s = new[2] DoubleCount(); - + reaction(s.out) {= for (int i = 0; i < s_width; i++) { for (int j = 0; j < s[0].out_width; j++) { @@ -26,14 +26,14 @@ main reactor { lf_print_error_and_exit("Expected %d.", self->count); } self->received = true; - } + } } - } - self->count++; + } + self->count++; =} reaction(shutdown) {= if (!self->received) { lf_print_error_and_exit("No inputs present."); } =} -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankReactionsInContainer.lf b/test/C/src/multiport/BankReactionsInContainer.lf index 8ce8cd1bcc..95103754a5 100644 --- a/test/C/src/multiport/BankReactionsInContainer.lf +++ b/test/C/src/multiport/BankReactionsInContainer.lf @@ -8,12 +8,12 @@ reactor R (bank_index:int(0)) { output[2] out:int; input[2] in:int; state received:bool(false); - + reaction(startup) -> out {= for (int i = 0; i < out_width; i++) { int value = self->bank_index * 2 + i; lf_set(out[i], value); - lf_print("Inner sending %d to bank %d channel %d.", + lf_print("Inner sending %d to bank %d channel %d.", value, self->bank_index, i ); } @@ -40,7 +40,7 @@ reactor R (bank_index:int(0)) { main reactor { s = new[2] R(); state received:bool(false); - + reaction(startup) -> s.in {= int count = 0; for (int i = 0; i < s_width; i++) { diff --git a/test/C/src/multiport/BankSelfBroadcast.lf b/test/C/src/multiport/BankSelfBroadcast.lf index f1c6596642..48296c3500 100644 --- a/test/C/src/multiport/BankSelfBroadcast.lf +++ b/test/C/src/multiport/BankSelfBroadcast.lf @@ -3,8 +3,8 @@ * back to a multiport input of the same reactors in the bank * so that each reactor in the bank receives the output * produced by itself and each other reactor. - * - * @author Edward A. Lee + * + * @author Edward A. Lee */ target C; reactor A ( @@ -45,4 +45,4 @@ reactor A ( main reactor { a = new[4] A(); (a.out)+ -> a.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankToBank.lf b/test/C/src/multiport/BankToBank.lf index 7e029fc7aa..a869ce1116 100644 --- a/test/C/src/multiport/BankToBank.lf +++ b/test/C/src/multiport/BankToBank.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors. +// Check bank of reactors sending to bank of reactors. target C { timeout: 2 sec, fast: true, @@ -36,7 +36,7 @@ reactor Destination( =} } -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 8253f63027..343600718a 100644 --- a/test/C/src/multiport/BankToBankMultiport.lf +++ b/test/C/src/multiport/BankToBankMultiport.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target C { timeout: 2 sec, fast: true, @@ -36,8 +36,8 @@ reactor Destination(width:int(1)) { printf("Success.\n"); =} } -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; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankToBankMultiportAfter.lf b/test/C/src/multiport/BankToBankMultiportAfter.lf index 17185982a6..22aa5c590d 100644 --- a/test/C/src/multiport/BankToBankMultiportAfter.lf +++ b/test/C/src/multiport/BankToBankMultiportAfter.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target C { timeout: 2 sec, fast: true, @@ -36,8 +36,8 @@ reactor Destination(width:int(1)) { printf("Success.\n"); =} } -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; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankToMultiport.lf b/test/C/src/multiport/BankToMultiport.lf index 6c32e36e5c..859eb56426 100644 --- a/test/C/src/multiport/BankToMultiport.lf +++ b/test/C/src/multiport/BankToMultiport.lf @@ -5,7 +5,7 @@ reactor Source( bank_index:int(0) ) { output out:int; - + reaction (startup) -> out {= lf_set(out, self->bank_index); =} @@ -14,7 +14,7 @@ reactor Source( reactor Sink(width:int(4)) { input[width] in:int; state received:bool(false); - + reaction (in) {= for (int i = 0; i < in_width; i++) { if (in[i]->is_present) { @@ -22,15 +22,15 @@ reactor Sink(width:int(4)) { self->received = true; if (in[i]->value != i) { fprintf(stderr, "ERROR: expected %d\n", i); - exit(1); - } + exit(1); + } } } =} reaction(shutdown) {= if (!self->received) { fprintf(stderr, "ERROR: Sink received no data\n"); - exit(1); + exit(1); } =} } @@ -39,4 +39,4 @@ main reactor BankToMultiport(width:int(5)) { source = new[width] Source(); sink = new Sink(width = width); source.out -> sink.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BankToReaction.lf b/test/C/src/multiport/BankToReaction.lf index 66b64bdda4..7a832aeee1 100644 --- a/test/C/src/multiport/BankToReaction.lf +++ b/test/C/src/multiport/BankToReaction.lf @@ -8,14 +8,14 @@ main reactor { state count:int(1); s = new[2] Count(); - + reaction(s.out) {= for (int i = 0; i < s_width; i++) { - lf_print("Received %d.", s[i].out->value); + lf_print("Received %d.", s[i].out->value); if (self->count != s[i].out->value) { lf_print_error_and_exit("Expected %d.", self->count); - } - } - self->count++; + } + } + self->count++; =} } diff --git a/test/C/src/multiport/Broadcast.lf b/test/C/src/multiport/Broadcast.lf index 9129f9c54b..a02cbf00eb 100644 --- a/test/C/src/multiport/Broadcast.lf +++ b/test/C/src/multiport/Broadcast.lf @@ -1,11 +1,11 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source { output out:int; - + reaction(startup) -> out {= lf_set(out, 42); =} @@ -31,8 +31,8 @@ reactor Destination(bank_index:int(0)) { =} } -main reactor { +main reactor { a = new Source(); b = new[4] Destination(); (a.out)+ -> b.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BroadcastAfter.lf b/test/C/src/multiport/BroadcastAfter.lf index 99ed7a6413..cc4f82b164 100644 --- a/test/C/src/multiport/BroadcastAfter.lf +++ b/test/C/src/multiport/BroadcastAfter.lf @@ -1,11 +1,11 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source { output out:int; - + reaction(startup) -> out {= lf_set(out, 42); =} @@ -35,8 +35,8 @@ reactor Destination(bank_index:int(0)) { =} } -main reactor { +main reactor { a = new Source(); b = new[4] Destination(); (a.out)+ -> b.in after 1 sec; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/BroadcastMultipleAfter.lf b/test/C/src/multiport/BroadcastMultipleAfter.lf index 585ad2258a..b410368071 100644 --- a/test/C/src/multiport/BroadcastMultipleAfter.lf +++ b/test/C/src/multiport/BroadcastMultipleAfter.lf @@ -1,11 +1,11 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source(value:int(42)) { output out:int; - + reaction(startup) -> out {= lf_set(out, self->value); =} diff --git a/test/C/src/multiport/FullyConnected.lf b/test/C/src/multiport/FullyConnected.lf index feeb53949d..2b4ccb83c8 100644 --- a/test/C/src/multiport/FullyConnected.lf +++ b/test/C/src/multiport/FullyConnected.lf @@ -12,7 +12,7 @@ reactor Node( reaction (startup) -> out{= lf_print("Hello from node %d!", self->bank_index); // broadcast my ID to everyone - lf_set(out, self->bank_index); + lf_set(out, self->bank_index); =} reaction (in) {= @@ -24,15 +24,15 @@ reactor Node( count++; printf("%d, ", in[i]->value); } - } + } printf("\n"); if (count != self->num_nodes) { - lf_print_error_and_exit("Received fewer messages than expected!"); + lf_print_error_and_exit("Received fewer messages than expected!"); } =} reaction (shutdown) {= if (!self->received) { - lf_print_error_and_exit("Received no input!"); + lf_print_error_and_exit("Received no input!"); } =} } diff --git a/test/C/src/multiport/FullyConnectedAddressable.lf b/test/C/src/multiport/FullyConnectedAddressable.lf index d5e76e65ae..6562373cb9 100644 --- a/test/C/src/multiport/FullyConnectedAddressable.lf +++ b/test/C/src/multiport/FullyConnectedAddressable.lf @@ -8,19 +8,19 @@ reactor Node( ) { input[num_nodes] in: int; output[num_nodes] out: int; - + state received:int(0); state triggered:bool(false); - + reaction (startup) -> out {= int outChannel = (self->bank_index + 1) % self->num_nodes; lf_print("Node %d sending %d out on channel %d.", self->bank_index, self->bank_index, outChannel ); // broadcast my ID to everyone - lf_set(out[outChannel], self->bank_index); + lf_set(out[outChannel], self->bank_index); =} - + reaction (in) {= self->triggered = true; printf("Node %d received messages from ", self->bank_index); @@ -31,19 +31,19 @@ reactor Node( printf("%d, ", in[i]->value); self->received = in[i]->value; } - } + } printf("\n"); int expected = self->bank_index == 0 ? self->num_nodes - 1 : self->bank_index - 1; if (count != 1) { - lf_print_error_and_exit("Received %d messages, but expecting only one!"); + lf_print_error_and_exit("Received %d messages, but expecting only one!"); } if (self->received != expected) { - lf_print_error_and_exit("Received %d, but expected %d!", self->received, expected); + lf_print_error_and_exit("Received %d, but expected %d!", self->received, expected); } =} reaction (shutdown) {= if (!self->triggered) { - lf_print_error_and_exit("Received no input!"); + lf_print_error_and_exit("Received no input!"); } =} } @@ -51,7 +51,7 @@ reactor Node( main reactor(num_nodes: size_t(4)) { nodes1 = new[num_nodes] Node(num_nodes=num_nodes); nodes1.out -> interleaved(nodes1.in); - + nodes2 = new[num_nodes] Node(num_nodes=num_nodes); interleaved(nodes2.out) -> nodes2.in; } diff --git a/test/C/src/multiport/FullyConnectedAddressableAfter.lf b/test/C/src/multiport/FullyConnectedAddressableAfter.lf index 8a619a1f1b..2dc2e0dfe5 100644 --- a/test/C/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/C/src/multiport/FullyConnectedAddressableAfter.lf @@ -7,7 +7,7 @@ import Node from "FullyConnectedAddressable.lf" main reactor(num_nodes: size_t(4)) { nodes1 = new[num_nodes] Node(num_nodes=num_nodes); nodes1.out -> interleaved(nodes1.in) after 200msec; - + nodes2 = new[num_nodes] Node(num_nodes=num_nodes); interleaved(nodes2.out) -> nodes2.in after 400msec; } diff --git a/test/C/src/multiport/MultiportFromBank.lf b/test/C/src/multiport/MultiportFromBank.lf index 1b786de284..62f9128eef 100644 --- a/test/C/src/multiport/MultiportFromBank.lf +++ b/test/C/src/multiport/MultiportFromBank.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, fast: true -}; +}; reactor Source( check_override:int(0), bank_index:int(0) @@ -39,4 +39,4 @@ main reactor MultiportFromBank(width:int(4)) { a = new[width] Source(check_override = 1); b = new Destination(port_width = width); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportFromBankHierarchy.lf b/test/C/src/multiport/MultiportFromBankHierarchy.lf index 2945281498..1f2de8805d 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchy.lf @@ -1,4 +1,4 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, @@ -16,4 +16,4 @@ main reactor(width:int(4)) { a = new Container(port_width = width); b = new Destination(port_width = width); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf index 8521b7d158..d7fbf7a775 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, fast: true -}; +}; import Destination from "MultiportFromBank.lf" import Container from "MultiportFromBankHierarchy.lf" @@ -11,4 +11,4 @@ main reactor MultiportFromBankHierarchyAfter { a = new Container(port_width = 4); b = new Destination(port_width = 4); a.out -> b.in after 1 sec; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportFromHierarchy.lf b/test/C/src/multiport/MultiportFromHierarchy.lf index a6e3a1fc41..d21c47aa3f 100644 --- a/test/C/src/multiport/MultiportFromHierarchy.lf +++ b/test/C/src/multiport/MultiportFromHierarchy.lf @@ -1,8 +1,8 @@ - // Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(3)) { timer t(0, 200 msec); output[width] out:int; @@ -48,7 +48,7 @@ reactor InsideContainer(width:int(3)) { 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 cdfa161cbc..0e38e2d3e2 100644 --- a/test/C/src/multiport/MultiportFromReaction.lf +++ b/test/C/src/multiport/MultiportFromReaction.lf @@ -2,7 +2,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Destination(width:int(1)) { state s:int(6); input[width] in:int; @@ -39,4 +39,3 @@ main reactor MultiportFromReaction(width:int(4)) { =} b = new Destination(width = width); } - diff --git a/test/C/src/multiport/MultiportIn.lf b/test/C/src/multiport/MultiportIn.lf index 140db6caf3..7d2b6cc874 100644 --- a/test/C/src/multiport/MultiportIn.lf +++ b/test/C/src/multiport/MultiportIn.lf @@ -28,7 +28,7 @@ reactor Destination { int sum = 0; for (int i = 0; i < in_width; i++) { sum += in[i]->value; - } + } printf("Sum of received: %d.\n", sum); if (sum != self->s) { printf("ERROR: Expected %d.\n", self->s); @@ -45,7 +45,7 @@ reactor Destination { =} } -main reactor MultiportIn { +main reactor MultiportIn { a = new Source(); t1 = new Computation(); t2 = new Computation(); diff --git a/test/C/src/multiport/MultiportInParameterized.lf b/test/C/src/multiport/MultiportInParameterized.lf index 631b06d2e8..dbfdcd937b 100644 --- a/test/C/src/multiport/MultiportInParameterized.lf +++ b/test/C/src/multiport/MultiportInParameterized.lf @@ -28,7 +28,7 @@ reactor Destination(width:int(1)) { int sum = 0; for (int i = 0; i < in_width; i++) { sum += in[i]->value; - } + } printf("Sum of received: %d.\n", sum); if (sum != self->s) { printf("ERROR: Expected %d.\n", self->s); @@ -62,4 +62,4 @@ main reactor { // t2.out -> b.in[1]; // t3.out -> b.in[2]; // dt4.out -> b.in[3]; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportMutableInputArray.lf b/test/C/src/multiport/MultiportMutableInputArray.lf index 4082e4465c..c30e82c245 100644 --- a/test/C/src/multiport/MultiportMutableInputArray.lf +++ b/test/C/src/multiport/MultiportMutableInputArray.lf @@ -9,7 +9,7 @@ reactor Source { reaction(startup) -> out {= // Dynamically allocate an output array of length 3. SET_NEW_ARRAY(out[0], 3); - + // Above allocates the array, which then must be populated. out[0]->value[0] = 0; out[0]->value[1] = 1; @@ -17,7 +17,7 @@ reactor Source { // Dynamically allocate an output array of length 3. SET_NEW_ARRAY(out[1], 3); - + // Above allocates the array, which then must be populated. out[1]->value[0] = 3; out[1]->value[1] = 4; diff --git a/test/C/src/multiport/MultiportOut.lf b/test/C/src/multiport/MultiportOut.lf index 284afd6c68..008ccfd8c6 100644 --- a/test/C/src/multiport/MultiportOut.lf +++ b/test/C/src/multiport/MultiportOut.lf @@ -2,7 +2,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[4] out:int; @@ -49,7 +49,7 @@ reactor Destination { =} } -main reactor { +main reactor { a = new Source(); t1 = new Computation(); t2 = new Computation(); diff --git a/test/C/src/multiport/MultiportToBank.lf b/test/C/src/multiport/MultiportToBank.lf index bc2493a0ae..2081059987 100644 --- a/test/C/src/multiport/MultiportToBank.lf +++ b/test/C/src/multiport/MultiportToBank.lf @@ -1,8 +1,8 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(2)) { output[width] out:int; // Connected to a bank of Destination reactors input dummy:int; // Not connected to anything @@ -13,7 +13,7 @@ reactor Source(width:int(2)) { =} // Test also that multiple appearances of the same effect port // do not result in multiple allocations of memory for the port. - reaction(dummy) -> out {= // Contents of the reactions does not matter (either could be empty) + reaction(dummy) -> out {= // Contents of the reactions does not matter (either could be empty) for(int i = 0; i < out_width; i++) { lf_set(out[i], i); } @@ -41,8 +41,8 @@ reactor Destination( =} } -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; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToBankAfter.lf b/test/C/src/multiport/MultiportToBankAfter.lf index 3285e4fbe1..743ef31664 100644 --- a/test/C/src/multiport/MultiportToBankAfter.lf +++ b/test/C/src/multiport/MultiportToBankAfter.lf @@ -2,7 +2,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(2)) { output[width] out:int; reaction(startup) -> out {= @@ -37,8 +37,8 @@ reactor Destination( =} } -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. -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToBankDouble.lf b/test/C/src/multiport/MultiportToBankDouble.lf index 4df066eb9e..9417106b6c 100644 --- a/test/C/src/multiport/MultiportToBankDouble.lf +++ b/test/C/src/multiport/MultiportToBankDouble.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients where the source +// Check multiport output to bank of recipients where the source // has two reactions that write to the output. target C { timeout: 2 sec, fast: true -}; +}; reactor Source { output[3] out:int; // Connected to a bank of Destination reactors reaction(startup) -> out {= @@ -13,7 +13,7 @@ reactor Source { =} // Test also that multiple appearances of the same effect port // do not result in multiple allocations of memory for the port. - reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) + reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) for(int i = 0; i < out_width; i++) { lf_set(out[i], i * 2); } @@ -41,8 +41,8 @@ reactor Destination( =} } -main reactor { +main reactor { a = new Source(); b = new[3] Destination(); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToBankHierarchy.lf b/test/C/src/multiport/MultiportToBankHierarchy.lf index c3ef3b09c3..55589af019 100644 --- a/test/C/src/multiport/MultiportToBankHierarchy.lf +++ b/test/C/src/multiport/MultiportToBankHierarchy.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(2)) { output[width] out:int; reaction(startup) -> out {= @@ -39,8 +39,8 @@ reactor Container(width:int(2)) { 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; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToHierarchy.lf b/test/C/src/multiport/MultiportToHierarchy.lf index f855a6df03..c8740986c6 100644 --- a/test/C/src/multiport/MultiportToHierarchy.lf +++ b/test/C/src/multiport/MultiportToHierarchy.lf @@ -1,9 +1,9 @@ - // Check multiport output to multiport input, where the latter is a hierarchical reactor. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. // Note that the destination reactor has width wider than the sender, so one input is dangling. target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(2)) { timer t(0, 200 msec); output[width] out:int; @@ -43,8 +43,8 @@ reactor Container(width:int(4)) { 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; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToMultiport.lf b/test/C/src/multiport/MultiportToMultiport.lf index 7063ab4327..3cd560360f 100644 --- a/test/C/src/multiport/MultiportToMultiport.lf +++ b/test/C/src/multiport/MultiportToMultiport.lf @@ -2,7 +2,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(1)) { timer t(0, 200 msec); output[width] out:int; @@ -39,8 +39,8 @@ reactor Destination(width:int(1)) { printf("Success.\n"); =} } -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; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToMultiport2.lf b/test/C/src/multiport/MultiportToMultiport2.lf index 7c2af0a8bd..6212b94373 100644 --- a/test/C/src/multiport/MultiportToMultiport2.lf +++ b/test/C/src/multiport/MultiportToMultiport2.lf @@ -33,4 +33,4 @@ main reactor MultiportToMultiport2(width1:int(3), width2:int(2), width3:int(5)) a2 = new Source(width = width2); b = new Destination(width = width3); a1.out, a2.out -> b.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToMultiport2After.lf b/test/C/src/multiport/MultiportToMultiport2After.lf index 4f30e20496..4928cb5cb4 100644 --- a/test/C/src/multiport/MultiportToMultiport2After.lf +++ b/test/C/src/multiport/MultiportToMultiport2After.lf @@ -10,7 +10,7 @@ reactor Source(width:int(2)) { } =} } - + reactor Destination(width:int(2)) { input[width] in:int; reaction (in) {= @@ -37,4 +37,4 @@ main reactor MultiportToMultiport2After { a2 = new Source(width = 2); b = new Destination(width = 5); a1.out, a2.out -> b.in after 1 sec; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToMultiportArray.lf b/test/C/src/multiport/MultiportToMultiportArray.lf index 7da4746bd0..abccb3e6c7 100644 --- a/test/C/src/multiport/MultiportToMultiportArray.lf +++ b/test/C/src/multiport/MultiportToMultiportArray.lf @@ -3,7 +3,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[2] out:int[]; @@ -12,7 +12,7 @@ reactor Source { for(int i = 0; i < 2; i++) { // Dynamically allocate an output array of length 3. SET_NEW_ARRAY(out[i], 3); - + // Above allocates the array, which then must be populated. out[i]->value[0] = self->s++; out[i]->value[1] = self->s++; @@ -49,7 +49,7 @@ reactor Destination { =} } -main reactor MultiportToMultiportArray { +main reactor MultiportToMultiportArray { a = new Source(); b = new Destination(); a.out -> b.in; diff --git a/test/C/src/multiport/MultiportToMultiportParameter.lf b/test/C/src/multiport/MultiportToMultiportParameter.lf index 9684fd1e38..850b24ab1e 100644 --- a/test/C/src/multiport/MultiportToMultiportParameter.lf +++ b/test/C/src/multiport/MultiportToMultiportParameter.lf @@ -2,7 +2,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(1)) { timer t(0, 200 msec); output[width] out:int; @@ -39,8 +39,8 @@ reactor Destination(width:int(1)) { printf("Success.\n"); =} } -main reactor (width:int(4)) { +main reactor (width:int(4)) { a = new Source(width = width); b = new Destination(width = width); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToPort.lf b/test/C/src/multiport/MultiportToPort.lf index 5bcba30e3a..12bd6eb435 100644 --- a/test/C/src/multiport/MultiportToPort.lf +++ b/test/C/src/multiport/MultiportToPort.lf @@ -3,7 +3,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source { output[2] out:int; reaction(startup) -> out {= @@ -33,9 +33,9 @@ reactor Destination(expected:int(0)) { =} } -main reactor MultiportToPort { +main reactor MultiportToPort { a = new Source(); b1 = new Destination(); b2 = new Destination(expected = 1); a.out -> b1.in, b2.in; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/MultiportToReaction.lf b/test/C/src/multiport/MultiportToReaction.lf index fb68777b39..cabe03fe0c 100644 --- a/test/C/src/multiport/MultiportToReaction.lf +++ b/test/C/src/multiport/MultiportToReaction.lf @@ -2,7 +2,7 @@ target C { timeout: 2 sec, fast: true -}; +}; reactor Source(width:int(1)) { timer t(0, 200 msec); state s:int(0); diff --git a/test/C/src/multiport/NestedBanks.lf b/test/C/src/multiport/NestedBanks.lf index f842d9aca5..841ee9e1f5 100644 --- a/test/C/src/multiport/NestedBanks.lf +++ b/test/C/src/multiport/NestedBanks.lf @@ -8,7 +8,7 @@ main reactor { c = new[3] C(); d = new D(); e = new E(); - + (a.x)+ -> c.z, d.u, e.t; } reactor A(bank_index:int(0)) { @@ -66,4 +66,4 @@ reactor G(c_bank_index:int(0)) { lf_print_error_and_exit("Expected %d but received %d.", self->c_bank_index * 2 + 1, s->value); } =} -} \ No newline at end of file +} diff --git a/test/C/src/multiport/NestedInterleavedBanks.lf b/test/C/src/multiport/NestedInterleavedBanks.lf index 54741e974a..a4729b99dd 100644 --- a/test/C/src/multiport/NestedInterleavedBanks.lf +++ b/test/C/src/multiport/NestedInterleavedBanks.lf @@ -29,8 +29,8 @@ reactor C { } =} } -main reactor { +main reactor { b = new[2] B(); c = new C(); b.q -> c.i; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/PipelineAfter.lf b/test/C/src/multiport/PipelineAfter.lf index eb46734acd..ba4b2fc88a 100644 --- a/test/C/src/multiport/PipelineAfter.lf +++ b/test/C/src/multiport/PipelineAfter.lf @@ -2,7 +2,7 @@ target C; reactor Source { output out:unsigned; - + reaction (startup) -> out {= lf_set(out, 40); =} @@ -11,7 +11,7 @@ reactor Source { reactor Compute { input in:unsigned; output out:unsigned; - + reaction (in) -> out {= lf_set(out, in->value + 2); =} @@ -19,7 +19,7 @@ reactor Compute { reactor Sink { input in:unsigned; - + reaction (in) {= printf("Received %d\n", in->value); if (in->value != 42) { @@ -31,7 +31,7 @@ reactor Sink { exit(2); } =} - + } main reactor { @@ -40,4 +40,4 @@ main reactor { sink = new Sink(); source.out, compute.out -> compute.in, sink.in after 500 msec; -} \ No newline at end of file +} diff --git a/test/C/src/multiport/ReactionToContainedBank.lf b/test/C/src/multiport/ReactionToContainedBank.lf index feda1a0626..5beb13d52b 100644 --- a/test/C/src/multiport/ReactionToContainedBank.lf +++ b/test/C/src/multiport/ReactionToContainedBank.lf @@ -8,9 +8,9 @@ import TestCount from "../lib/TestCount.lf"; main reactor ReactionToContainedBank(width:int(2)) { timer t(0, 100 msec); state count:int(1); - + test = new[width] TestCount(num_inputs = 11); - + reaction(t) -> test.in {= for (int i = 0; i < self->width; i++) { lf_set(test[i].in, self->count); diff --git a/test/C/src/multiport/ReactionToContainedBank2.lf b/test/C/src/multiport/ReactionToContainedBank2.lf index 173c2964ed..0cea7cbb22 100644 --- a/test/C/src/multiport/ReactionToContainedBank2.lf +++ b/test/C/src/multiport/ReactionToContainedBank2.lf @@ -8,9 +8,9 @@ import TestCount from "../lib/TestCount.lf"; reactor ReactionToContainedBank(width:int(2)) { timer t(0, 100 msec); state count:int(1); - + test = new[width] TestCount(num_inputs = 11); - + reaction(t) -> test.in {= for (int i = 0; i < self->width; i++) { lf_set(test[i].in, self->count); diff --git a/test/C/src/multiport/ReactionToContainedBankMultiport.lf b/test/C/src/multiport/ReactionToContainedBankMultiport.lf index 4fe7002f13..e9bb65da6d 100644 --- a/test/C/src/multiport/ReactionToContainedBankMultiport.lf +++ b/test/C/src/multiport/ReactionToContainedBankMultiport.lf @@ -9,9 +9,9 @@ import TestCountMultiport from "../lib/TestCountMultiport.lf"; main reactor(width:int(2)) { timer t(0, 100 msec); state count:int(1); - + test = new[width] TestCountMultiport(num_inputs = 11, width = width); - + reaction(t) -> test.in {= for (int i = 0; i < self->width; i++) { for (int j = 0; j < self->width; j++) { diff --git a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf index d5c4eee3ad..3fc68f7439 100644 --- a/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf +++ b/test/C/src/multiport/TriggerDownstreamOnlyIfPresent.lf @@ -40,4 +40,4 @@ main reactor TriggerDownstreamOnlyIfPresent { d = new[2] Destination(); s.a -> d.a; s.b -> d.b; -} \ No newline at end of file +} diff --git a/test/C/src/serialization/PersonProtocolBuffers.lf b/test/C/src/serialization/PersonProtocolBuffers.lf index c928ccb058..480482e6eb 100644 --- a/test/C/src/serialization/PersonProtocolBuffers.lf +++ b/test/C/src/serialization/PersonProtocolBuffers.lf @@ -6,15 +6,15 @@ * * To run this example first install the protocol buffers compiler * from https://github.com/protocolbuffers/protobuf. It is also - * available from homebrew on a Mac via - * + * available from homebrew on a Mac via + * * $ brew install protobuf - * + * * Building protobuf from source is slow, so avoid doing that - * if possible. Next install the C plugin for protocol buffers from - * + * if possible. Next install the C plugin for protocol buffers from + * * https://github.com/protobuf-c/protobuf-c - * + * * The code generator assumes * that executables are installed within the PATH. On a Mac, this is * typically at /usr/local/bin. @@ -27,21 +27,21 @@ main reactor { Person person = PERSON__INIT; // Macro to create the protocol buffer uint8_t* buffer; // Buffer to store the serialized data unsigned len; // Length of the packed message - + person.name = "Lingua Franca"; person.id = 1; person.email = "eal@berkeley.edu"; - + // Pack the message into buffer. len = person__get_packed_size(&person); buffer = (uint8_t*)malloc(len); person__pack(&person, buffer); - + // Now unpack the message from buffer. Person *unpacked = person__unpack(NULL, len, buffer); - + // Extract and print the unpacked message. printf("Name: %s\n", unpacked->name); free(buffer); // Free the allocated serialized buffer =} - } \ No newline at end of file + } diff --git a/test/C/src/serialization/ProtoNoPacking.lf b/test/C/src/serialization/ProtoNoPacking.lf index 1ea28df808..c593f3e839 100644 --- a/test/C/src/serialization/ProtoNoPacking.lf +++ b/test/C/src/serialization/ProtoNoPacking.lf @@ -5,15 +5,15 @@ * * To run this example first install the protocol buffers compiler * from https://github.com/protocolbuffers/protobuf. It is also - * available from homebrew on a Mac via - * + * available from homebrew on a Mac via + * * $ brew install protobuf - * + * * Building protobuf from source is slow, so avoid doing that - * if possible. Next install the C plugin for protocol buffers from - * + * if possible. Next install the C plugin for protocol buffers from + * * https://github.com/protobuf-c/protobuf-c - * + * * The code generator assumes * that executables are installed within the PATH. On a Mac, this is * typically at /usr/local/bin. diff --git a/test/C/src/serialization/ROSBuiltInSerialization.lf b/test/C/src/serialization/ROSBuiltInSerialization.lf index 9a1daed80b..f3ecbc5f8b 100644 --- a/test/C/src/serialization/ROSBuiltInSerialization.lf +++ b/test/C/src/serialization/ROSBuiltInSerialization.lf @@ -2,23 +2,23 @@ * This test showcases the infrastructure that is built into the * CCpp target that can automatically serialize and deserialize ROS2 * messages in federated programs. - * - * This test contains a sender-receiver federated program in which + * + * This test contains a sender-receiver federated program in which * the 'sender' federate sends a std_msgs::msg::Int32 message to the * 'receiver' federate. - * + * * To run this test, make sure that your terminal is properly sourced - * for ROS2. See + * for ROS2. See * https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. - * + * * Then you can use lfc to compile this program: - * + * * lfc ROSBuiltInSerialization.lf - * + * * And launch the federated program in the `bin` folder: - * + * * bin/ROSBuiltInSerialization - * + * * @author Soroush Bateni */ target CCpp { @@ -28,33 +28,33 @@ preamble {= #include "std_msgs/msg/int32.hpp" - + =} reactor Sender { output out:std_msgs::msg::Int32; - + // state serialized_msg_pcl:rclcpp::SerializedMessage({=0u=}); state count:int(0); - + timer t (0, 1 sec); - + reaction (t) -> out {= std_msgs::msg::Int32 ros_message; ros_message.data = self->count++; lf_set(out, ros_message); - + =} } reactor Receiver { input in:std_msgs::msg::Int32; state count:int(0); - - reaction (in) {= + + reaction (in) {= // Print the ROS2 message data lf_print( - "Serialized integer after deserialization: %d", + "Serialized integer after deserialization: %d", in->value.data ); if (in->value.data != self->count) { @@ -67,6 +67,6 @@ reactor Receiver { federated reactor { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in serializer "ros2"; } diff --git a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf index fa4964d842..c26287f664 100644 --- a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf +++ b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf @@ -2,23 +2,23 @@ * This test showcases the infrastructure that is built into the * CCpp target that can automatically serialize and deserialize ROS2 * messages (with a shared_ptr type) in federated programs. - * - * This test contains a sender-receiver federated program in which + * + * This test contains a sender-receiver federated program in which * the 'sender' federate sends a std_msgs::msg::Int32 message to the * 'receiver' federate. - * + * * To run this test, make sure that your terminal is properly sourced - * for ROS2. See + * for ROS2. See * https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. - * + * * Then you can use lfc to compile this program: - * + * * lfc ROSBuiltInSerialization.lf - * + * * And launch the federated program in the `bin` folder: - * + * * bin/ROSBuiltInSerialization - * + * * @author Soroush Bateni */ target CCpp { @@ -28,21 +28,21 @@ preamble {= #include "std_msgs/msg/int32.hpp" - + =} reactor Sender { output out:std::shared_ptr; - + state count:int(0); - + timer t (0, 1 sec); - + reaction (t) -> out {= auto ros_message = std::make_shared(); ros_message->data = self->count++; lf_set(out, ros_message); - + =} } @@ -50,11 +50,11 @@ reactor Sender { reactor Receiver { input in:std::shared_ptr; state count:int(0); - - reaction (in) {= + + reaction (in) {= // Print the ROS2 message data lf_print( - "Serialized integer after deserialization: %d", + "Serialized integer after deserialization: %d", in->value->data ); if (in->value->data != self->count) { @@ -67,6 +67,6 @@ reactor Receiver { federated reactor { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in serializer "ros2"; } diff --git a/test/C/src/target/CMakeInclude.lf b/test/C/src/target/CMakeInclude.lf index 4a465e3442..f0c8681476 100644 --- a/test/C/src/target/CMakeInclude.lf +++ b/test/C/src/target/CMakeInclude.lf @@ -4,7 +4,7 @@ */ target C { cmake-include: [ - "../include/mlib-cmake-extension.cmake", + "../include/mlib-cmake-extension.cmake", "../include/foo-cmake-compile-definition.txt" ], timeout: 0 sec @@ -16,7 +16,7 @@ reactor Foo { =} reaction (startup) {= lf_print("Maximum of 4.20 and %.2f is %.2f", FOO, fmax(4.20, FOO)); - + // Check if BAR is defined, which is an error condition (@see federated/DistributedCMakeIncludeSeparateCompile.lf). #ifdef BAR #error "I found definition for BAR in Foo. Failed to compile federates separately." diff --git a/test/C/src/target/DistributedCMakeInclude.lf b/test/C/src/target/DistributedCMakeInclude.lf index 78e6fbb6ac..5fcd141948 100644 --- a/test/C/src/target/DistributedCMakeInclude.lf +++ b/test/C/src/target/DistributedCMakeInclude.lf @@ -15,7 +15,7 @@ reactor Bar { =} reaction (startup) {= lf_print("Maximum of 4.20 and %.2f is %.2f", BAR, fmax(4.20, BAR)); - + // Check if FOO is defined, which is an error condition (@see DistributedCMakeIncludeSeparateCompile.lf). #ifdef FOO #error "I found definition for FOO in Bar. Failed to compile federates separately." diff --git a/test/C/src/target/HelloWorldCCPP.lf b/test/C/src/target/HelloWorldCCPP.lf index f7d3b81bdb..801a0f6982 100644 --- a/test/C/src/target/HelloWorldCCPP.lf +++ b/test/C/src/target/HelloWorldCCPP.lf @@ -1,6 +1,6 @@ /** - * A variant of HelloWorld.lf that tests the - * CCpp target in conjunction with the CMake build system. + * A variant of HelloWorld.lf that tests the + * CCpp target in conjunction with the CMake build system. * This test should not pass if it does not compile. */ target CCpp { @@ -26,4 +26,4 @@ reactor HelloWorld { } main reactor { a = new HelloWorld(); -} \ No newline at end of file +} diff --git a/test/C/src/target/HelloWorldCCPPNoCMake.lf b/test/C/src/target/HelloWorldCCPPNoCMake.lf index 491f445dde..cdedac4a11 100644 --- a/test/C/src/target/HelloWorldCCPPNoCMake.lf +++ b/test/C/src/target/HelloWorldCCPPNoCMake.lf @@ -1,7 +1,7 @@ /** - * A variant of HelloWorld.lf that tests the + * A variant of HelloWorld.lf that tests the * CCpp target in conjunction with the legacy build system ( - * CMake disabled). This test should not pass if it does not + * CMake disabled). This test should not pass if it does not * compile. */ target CCpp { @@ -12,4 +12,4 @@ target CCpp { import HelloWorld from "HelloWorldCCPP.lf"; main reactor { a = new HelloWorld(); -} \ No newline at end of file +} diff --git a/test/C/src/target/HelloWorldFederatedCCPP.lf b/test/C/src/target/HelloWorldFederatedCCPP.lf index 9d8fa21c27..68e6f2fc85 100644 --- a/test/C/src/target/HelloWorldFederatedCCPP.lf +++ b/test/C/src/target/HelloWorldFederatedCCPP.lf @@ -1,6 +1,6 @@ /** - * A variant of HelloWorld.lf that tests the federated - * runtime with the CCpp target. This test should not pass if it + * A variant of HelloWorld.lf that tests the federated + * runtime with the CCpp target. This test should not pass if it * does not compile. */ target CCpp { @@ -12,4 +12,4 @@ import HelloWorld from "HelloWorldCCPP.lf"; federated reactor { a = new HelloWorld(); b = new HelloWorld(); // Create a non-singleton federation -} \ No newline at end of file +} diff --git a/test/C/src/target/HelloWorldFederatedCCPPNoCMake.lf b/test/C/src/target/HelloWorldFederatedCCPPNoCMake.lf index d91f76b092..8536db8b05 100644 --- a/test/C/src/target/HelloWorldFederatedCCPPNoCMake.lf +++ b/test/C/src/target/HelloWorldFederatedCCPPNoCMake.lf @@ -1,5 +1,5 @@ /** - * A variant of HelloWorld.lf that tests the federated + * A variant of HelloWorld.lf that tests the federated * runtime with the CCpp target with the CMake build system * disabled. This test should not pass if it does not compile. */ @@ -13,4 +13,4 @@ import HelloWorld from "HelloWorldCCPP.lf"; federated reactor { a = new HelloWorld(); b = new HelloWorld(); // Create a non-singleton federation -} \ No newline at end of file +} diff --git a/test/C/src/target/HelloWorldFederatedNoCMake.lf b/test/C/src/target/HelloWorldFederatedNoCMake.lf index c1da80bb61..85b42728a4 100644 --- a/test/C/src/target/HelloWorldFederatedNoCMake.lf +++ b/test/C/src/target/HelloWorldFederatedNoCMake.lf @@ -1,6 +1,6 @@ /** * A variant of HelloWorld.lf that checks the compatibility - * of the federated C runtime with no CMake. This test + * of the federated C runtime with no CMake. This test * should not pass if it does not compile. */ target C { @@ -14,4 +14,4 @@ import HelloWorld from "HelloWorldNoCMake.lf"; federated reactor { a = new HelloWorld(); b = new HelloWorld(); // Create a non-singleton federation -} \ No newline at end of file +} diff --git a/test/C/src/target/HelloWorldNoCMake.lf b/test/C/src/target/HelloWorldNoCMake.lf index 04b002fbef..3c1c411d7a 100644 --- a/test/C/src/target/HelloWorldNoCMake.lf +++ b/test/C/src/target/HelloWorldNoCMake.lf @@ -25,4 +25,4 @@ reactor HelloWorld { main reactor HelloWorldNoCMake { a = new HelloWorld(); -} \ No newline at end of file +} diff --git a/test/C/src/target/HelloWorldThreadedCPP.lf b/test/C/src/target/HelloWorldThreadedCPP.lf index 4545f32b3c..baa97fb771 100644 --- a/test/C/src/target/HelloWorldThreadedCPP.lf +++ b/test/C/src/target/HelloWorldThreadedCPP.lf @@ -1,6 +1,6 @@ /** * A variant of HelloWorld.lf that tests - * the threaded CCpp target. This test should not pass + * the threaded CCpp target. This test should not pass * if it does not compile. */ target CCpp { @@ -10,4 +10,4 @@ target CCpp { import HelloWorld from "HelloWorldCCPP.lf"; main reactor { a = new HelloWorld(); -} \ No newline at end of file +} diff --git a/test/C/src/target/lib/ImportedCMakeInclude.lf b/test/C/src/target/lib/ImportedCMakeInclude.lf index 2fbea3ac18..6feb1669ad 100644 --- a/test/C/src/target/lib/ImportedCMakeInclude.lf +++ b/test/C/src/target/lib/ImportedCMakeInclude.lf @@ -8,10 +8,10 @@ reactor Baz { =} reaction (startup) {= lf_print("Maximum of 4.20 and %.2f is %.2f", BAZ, fmax(4.20, BAZ)); - + // Check if FOO is defined, which is an error condition (@see DistributedCMakeIncludeSeparateCompile.lf). #ifdef FOO #error "I found definition for FOO in Baz. Failed to compile federates separately." #endif // FOO =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/ActionDelay.lf b/test/Cpp/src/ActionDelay.lf index 432121da9a..fb930ad1c3 100644 --- a/test/Cpp/src/ActionDelay.lf +++ b/test/Cpp/src/ActionDelay.lf @@ -20,7 +20,7 @@ reactor Source { output out:int; reaction(startup) -> out {= out.set(1); - =} + =} } reactor Sink { @@ -45,7 +45,7 @@ main reactor ActionDelay { source = new Source(); sink = new Sink(); g = new GeneratedDelay(); - + source.out -> g.y_in; g.y_out -> sink.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/ActionIsPresent.lf b/test/Cpp/src/ActionIsPresent.lf index 17409bd8a3..f2b2bfd01e 100644 --- a/test/Cpp/src/ActionIsPresent.lf +++ b/test/Cpp/src/ActionIsPresent.lf @@ -24,4 +24,4 @@ main reactor ActionIsPresent(offset:time(1 nsec), period:time(500 msec)) { exit(1); } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/ActionWithNoReaction.lf b/test/Cpp/src/ActionWithNoReaction.lf index 7838408116..74c96ad75a 100644 --- a/test/Cpp/src/ActionWithNoReaction.lf +++ b/test/Cpp/src/ActionWithNoReaction.lf @@ -33,4 +33,4 @@ main reactor { f.x.set(42); =} f.y -> p.x; -} \ No newline at end of file +} diff --git a/test/Cpp/src/After.lf b/test/Cpp/src/After.lf index 23fe4d573c..0434ce55eb 100644 --- a/test/Cpp/src/After.lf +++ b/test/Cpp/src/After.lf @@ -47,4 +47,4 @@ main reactor { std::cout << "Timer!\n"; =} f.y -> p.x after 10 msec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/Alignment.lf b/test/Cpp/src/Alignment.lf index df75c56331..2cd58de2c1 100644 --- a/test/Cpp/src/Alignment.lf +++ b/test/Cpp/src/Alignment.lf @@ -97,4 +97,4 @@ main reactor { source.out -> sieve.in; sieve.out -> destination.ok; source.out -> destination.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/ArrayAsParameter.lf b/test/Cpp/src/ArrayAsParameter.lf index 6eabef2959..0bd5e36344 100644 --- a/test/Cpp/src/ArrayAsParameter.lf +++ b/test/Cpp/src/ArrayAsParameter.lf @@ -36,4 +36,4 @@ main reactor ArrayAsParameter { s = new Source(sequence{1, 2, 3, 4}); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/ArrayAsType.lf b/test/Cpp/src/ArrayAsType.lf index 147d322a08..fd0b36e570 100644 --- a/test/Cpp/src/ArrayAsType.lf +++ b/test/Cpp/src/ArrayAsType.lf @@ -19,7 +19,7 @@ reactor Print { reaction(in) {= int expected = 3; bool failed = false; - + // get a reference to the result to avoid a copy auto& result = *in.get(); @@ -27,7 +27,7 @@ reactor Print { for (int i = 0; i < 3; i++) { std::cout << result[i]; if (i < 2) { - std::cout << ", "; + std::cout << ", "; } // check whether values match expectation. @@ -48,4 +48,4 @@ main reactor { s = new Source(); p = new Print(); s.out -> p.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/ArrayParallel.lf b/test/Cpp/src/ArrayParallel.lf index 39a3fdcd38..ba09d11e58 100644 --- a/test/Cpp/src/ArrayParallel.lf +++ b/test/Cpp/src/ArrayParallel.lf @@ -19,4 +19,4 @@ main reactor ArrayParallel { s.out -> c2.in; c1.out -> p1.in; c2.out -> p2.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/ArrayPrint.lf b/test/Cpp/src/ArrayPrint.lf index b6937a9d28..d9cf43a722 100644 --- a/test/Cpp/src/ArrayPrint.lf +++ b/test/Cpp/src/ArrayPrint.lf @@ -1,5 +1,5 @@ // Source produces a dynamically allocated array, which it passes -// to Print. The ownership semantics of values ensure that the array +// to Print. The ownership semantics of values ensure that the array // is automatically deleted if it does have no owner. target Cpp; @@ -13,8 +13,8 @@ reactor Source { (*result)[1] = 1; (*result)[2] = 2; // Send the array and move ownership. This implicitly converts the mutable - // value to an immutable value. - out.set(std::move(result)); + // value to an immutable value. + out.set(std::move(result)); =} } @@ -24,7 +24,7 @@ reactor Print(scale:int(1)) { reaction(in) {= int expected = 0; bool failed = false; - + // get a reference to the result to avoid a copy auto& result = *in.get(); @@ -32,7 +32,7 @@ reactor Print(scale:int(1)) { for (int i = 0; i < 3; i++) { std::cout << result[i]; if (i < 2) { - std::cout << ", "; + std::cout << ", "; } // check whether values match expectation. diff --git a/test/Cpp/src/ArrayScale.lf b/test/Cpp/src/ArrayScale.lf index 4803f3be0d..c335ac3a13 100644 --- a/test/Cpp/src/ArrayScale.lf +++ b/test/Cpp/src/ArrayScale.lf @@ -29,4 +29,4 @@ main reactor ArrayScale { p = new Print(scale(2)); s.out -> c.in; c.out -> p.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/Composition.lf b/test/Cpp/src/Composition.lf index 4b72250cb3..f7e7f4ada6 100644 --- a/test/Cpp/src/Composition.lf +++ b/test/Cpp/src/Composition.lf @@ -22,14 +22,14 @@ reactor Test { std::cout << "Received " << value << std::endl; if (value != count) { std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); + exit(1); } =} reaction(shutdown) {= if (count != 5) { std::cerr << "ERROR: expected to receive 5 values but got " << count << '\n'; exit(1); - } + } =} } main reactor Composition { diff --git a/test/Cpp/src/CompositionAfter.lf b/test/Cpp/src/CompositionAfter.lf index f4998565cc..30b1dc1808 100644 --- a/test/Cpp/src/CompositionAfter.lf +++ b/test/Cpp/src/CompositionAfter.lf @@ -22,14 +22,14 @@ reactor Test { std::cout << "Received " << value << std::endl; if (value != count) { std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); + exit(1); } =} reaction(shutdown) {= if (count != 3) { std::cerr << "ERROR: expected to receive 3 values but got " << count << '\n'; exit(1); - } + } =} } main reactor (delay:time(5 sec)) { diff --git a/test/Cpp/src/CompositionGain.lf b/test/Cpp/src/CompositionGain.lf index b37208ae42..8a8a19d132 100644 --- a/test/Cpp/src/CompositionGain.lf +++ b/test/Cpp/src/CompositionGain.lf @@ -27,4 +27,4 @@ main reactor CompositionGain { exit(2); } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/DeadlineHandledAbove.lf b/test/Cpp/src/DeadlineHandledAbove.lf index 9b5000c5b1..5d9bc3b73c 100644 --- a/test/Cpp/src/DeadlineHandledAbove.lf +++ b/test/Cpp/src/DeadlineHandledAbove.lf @@ -34,4 +34,4 @@ main reactor DeadlineHandledAbove { exit(2); } =} -} +} diff --git a/test/Cpp/src/DelayInt.lf b/test/Cpp/src/DelayInt.lf index ae0c3eac57..b92319c4ef 100644 --- a/test/Cpp/src/DelayInt.lf +++ b/test/Cpp/src/DelayInt.lf @@ -21,7 +21,7 @@ reactor Test { reaction(start) {= // Record the logical time at the start. start_time = get_logical_time(); - =} + =} reaction(in) {= std::cout << "Received: " << *in.get() << std::endl; // Check the time of the input. @@ -36,16 +36,16 @@ reactor Test { if (*in.get() != 42) { std::cerr << "ERROR: Expected input value to be 42. " << "It was " << *in.get() << std::endl; - exit(2); + exit(2); } =} } -main reactor DelayInt { +main reactor DelayInt { timer t; d = new Delay(); test = new Test(); - d.out -> test.in; + d.out -> test.in; reaction(t) -> d.in {= d.in.set(42); =} diff --git a/test/Cpp/src/DelayedReaction.lf b/test/Cpp/src/DelayedReaction.lf index 190889aaa6..36b9572da5 100644 --- a/test/Cpp/src/DelayedReaction.lf +++ b/test/Cpp/src/DelayedReaction.lf @@ -20,8 +20,8 @@ reactor Sink { =} } -main reactor DelayedReaction { +main reactor DelayedReaction { source = new Source(); sink = new Sink(); source.out -> sink.in after 100 msec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/Determinism.lf b/test/Cpp/src/Determinism.lf index a37c102e92..37045e145f 100644 --- a/test/Cpp/src/Determinism.lf +++ b/test/Cpp/src/Determinism.lf @@ -6,7 +6,7 @@ reactor Source { reaction(t) -> y {= y.set(1); =} -} +} reactor Destination { input x:int; input y:int; diff --git a/test/Cpp/src/DoubleInvocation.lf b/test/Cpp/src/DoubleInvocation.lf index 25d8e2e0b7..73a6ea832b 100644 --- a/test/Cpp/src/DoubleInvocation.lf +++ b/test/Cpp/src/DoubleInvocation.lf @@ -7,7 +7,7 @@ // This behavior was oddly eliminated by either of the following // actions, neither of which should affect this behavior: // * Removing the startup reaction in Print. -// * Sending only position, not velocity from Ball. +// * Sending only position, not velocity from Ball. // (copied from the c version of the test) target Cpp{ @@ -51,4 +51,4 @@ main reactor DoubleInvocation { b1.velocity -> p.velocity; b1.position -> plot.position; b1.velocity -> plot.velocity; -} \ No newline at end of file +} diff --git a/test/Cpp/src/DoublePort.lf b/test/Cpp/src/DoublePort.lf index 9751cbabcf..c14133ec1f 100644 --- a/test/Cpp/src/DoublePort.lf +++ b/test/Cpp/src/DoublePort.lf @@ -1,10 +1,10 @@ -/** +/** * Test the case where two upstream reactors * pass messages to a downstream reactor on two * different ports. One message carries * a microstep delay relative to the other. - * - * @author Maiko Brants + * + * @author Maiko Brants */ target Cpp { timeout: 900 msec, @@ -33,10 +33,10 @@ reactor Print { input in2:int; reaction(in, in2) {= if(in.is_present()){ - reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() + reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() << "), received in = " << *in.get(); } else if (in2.is_present()){ - reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() + reactor::log::Info() << "At tag (" << get_elapsed_logical_time() << ", " << environment()->logical_time().micro_step() << "), received in2 = " << *in2.get(); } @@ -58,4 +58,4 @@ main reactor DoublePort { p = new Print(); c.c -> p.in; cm.out -> p.in2; -} \ No newline at end of file +} diff --git a/test/Cpp/src/DoubleTrigger.lf b/test/Cpp/src/DoubleTrigger.lf index cfcaef8781..e1493c81b3 100644 --- a/test/Cpp/src/DoubleTrigger.lf +++ b/test/Cpp/src/DoubleTrigger.lf @@ -1,4 +1,4 @@ -// Test that two simultaneous triggers don't cause +// Test that two simultaneous triggers don't cause // a reaction to execute twice at the same tag. target Cpp; @@ -14,7 +14,7 @@ main reactor DoubleTrigger { } =} reaction(shutdown) {= - if (s == 1) { + if (s == 1) { std::cout << "SUCCESS" << std::endl; } else { std::cerr << "FAILURE: Reaction was never triggered." << std::endl; diff --git a/test/Cpp/src/GetMicroStep.lf b/test/Cpp/src/GetMicroStep.lf index ab98ce3a65..237ec6f812 100644 --- a/test/Cpp/src/GetMicroStep.lf +++ b/test/Cpp/src/GetMicroStep.lf @@ -1,4 +1,4 @@ -// Tests the get_microstep() function in the C target. +// Tests the get_microstep() function in the C target. target Cpp; main reactor GetMicroStep { state s: {=reactor::mstep_t=} (1); diff --git a/test/Cpp/src/GetTime.lf b/test/Cpp/src/GetTime.lf index 5b3fca9947..509826b1f7 100644 --- a/test/Cpp/src/GetTime.lf +++ b/test/Cpp/src/GetTime.lf @@ -13,7 +13,7 @@ main reactor GetTime { auto elapsed = get_elapsed_logical_time(); auto elapsed_secs = std::chrono::duration_cast(elapsed); std::cout << "Elapsed logical time is " << elapsed_secs << std::endl; - + auto physical = get_physical_time(); std::cout << "Physical time is " << physical << std::endl; diff --git a/test/Cpp/src/Hello.lf b/test/Cpp/src/Hello.lf index 3e82bd1a14..9802df5643 100644 --- a/test/Cpp/src/Hello.lf +++ b/test/Cpp/src/Hello.lf @@ -31,14 +31,14 @@ reactor HelloCpp(period:time(2 secs), message:{=std::string=}("Hello C++")) { exit(1); } =} -} -reactor Inside(period:time(1 sec), +} +reactor Inside(period:time(1 sec), message:{=std::string=}("Composite default message.")) { third_instance = new HelloCpp(period = period, message = message); } -main reactor Hello { - first_instance = new HelloCpp(period = 4 sec, +main reactor Hello { + first_instance = new HelloCpp(period = 4 sec, message = "Hello from first_instance."); second_instance = new HelloCpp(message = "Hello from second_instance."); composite_instance = new Inside(message = "Hello from composite_instance."); -} +} diff --git a/test/Cpp/src/ImportComposition.lf b/test/Cpp/src/ImportComposition.lf index a62e221dce..bf5f94da8a 100644 --- a/test/Cpp/src/ImportComposition.lf +++ b/test/Cpp/src/ImportComposition.lf @@ -29,7 +29,7 @@ main reactor ImportComposition { exit(1); } if(*imp_comp.y.get() != 42*2*2) { - reactor::log::Error() << "ERROR: Received value should have been: " << 42*2*2 << "."; + reactor::log::Error() << "ERROR: Received value should have been: " << 42*2*2 << "."; exit(2); } =} @@ -39,4 +39,4 @@ main reactor ImportComposition { exit(3); } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/ImportRenamed.lf b/test/Cpp/src/ImportRenamed.lf index f66864b1ed..c400f51406 100644 --- a/test/Cpp/src/ImportRenamed.lf +++ b/test/Cpp/src/ImportRenamed.lf @@ -20,4 +20,4 @@ main reactor { reaction(t) -> a.x {= a.x.set(42); =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/ManualDelayedReaction.lf b/test/Cpp/src/ManualDelayedReaction.lf index 4fc2c08142..c935889239 100644 --- a/test/Cpp/src/ManualDelayedReaction.lf +++ b/test/Cpp/src/ManualDelayedReaction.lf @@ -38,7 +38,7 @@ reactor Sink { =} } -main reactor ManualDelayedReaction { +main reactor ManualDelayedReaction { source = new Source(); sink = new Sink(); g = new GeneratedDelay(); diff --git a/test/Cpp/src/MovingAverage.lf b/test/Cpp/src/MovingAverage.lf index 916751a823..606fd9e8ba 100644 --- a/test/Cpp/src/MovingAverage.lf +++ b/test/Cpp/src/MovingAverage.lf @@ -65,4 +65,4 @@ main reactor MovingAverage { p = new Print(); s.out -> m.in; m.out -> p.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/MultipleContained.lf b/test/Cpp/src/MultipleContained.lf index 2805700754..1c5c05d7c4 100644 --- a/test/Cpp/src/MultipleContained.lf +++ b/test/Cpp/src/MultipleContained.lf @@ -29,4 +29,4 @@ main reactor MultipleContained { c.in1.set(c.trigger.get()); c.in2.set(c.trigger.get()); =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/NativeListsAndTimes.lf b/test/Cpp/src/NativeListsAndTimes.lf index 91ced749bf..132f8a69e8 100644 --- a/test/Cpp/src/NativeListsAndTimes.lf +++ b/test/Cpp/src/NativeListsAndTimes.lf @@ -2,10 +2,10 @@ target Cpp; // This test passes if it is successfully compiled into valid target code. -reactor Foo(x:int(0), +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 + p:int[]{1, 2, 3, 4}, // List of integers q:{=std::vector=}{1 msec, 2 msec, 3 msec}, // list of time values r:time({=0=}), // Zero-valued target code also is a valid time g:time[]{1 msec, 2 msec} // List of time values diff --git a/test/Cpp/src/ParameterHierarchy.lf b/test/Cpp/src/ParameterHierarchy.lf index 9d094ca699..b06cdc3305 100644 --- a/test/Cpp/src/ParameterHierarchy.lf +++ b/test/Cpp/src/ParameterHierarchy.lf @@ -25,4 +25,4 @@ reactor Another(p:int(20)) { } main reactor ParameterHierarchy { a = new Intermediate(p = 42); -} \ No newline at end of file +} diff --git a/test/Cpp/src/PeriodicDesugared.lf b/test/Cpp/src/PeriodicDesugared.lf index 6cff7bfff1..45578a7938 100644 --- a/test/Cpp/src/PeriodicDesugared.lf +++ b/test/Cpp/src/PeriodicDesugared.lf @@ -4,21 +4,21 @@ target Cpp { }; main reactor ( - offset:time(50 msec), + offset:time(50 msec), period:time(500 msec)) { logical action init(offset):void; logical action recur(period):void; state expected(offset); - + reaction(startup) -> init {= std::cout << "Hello from Periodic!\n"; init.schedule(); =} - + reaction(init) -> recur {= recur.schedule(); =} - + reaction(init, recur) -> recur {= std::cout << "Periodic trigger!\n"; auto logical_time = get_elapsed_logical_time(); diff --git a/test/Cpp/src/Pipeline.lf b/test/Cpp/src/Pipeline.lf index 5ab5894fdb..db9d02627e 100644 --- a/test/Cpp/src/Pipeline.lf +++ b/test/Cpp/src/Pipeline.lf @@ -25,17 +25,17 @@ reactor Print { main reactor Pipeline { timer t(0, 200 msec); state count:int(0); - + c1 = new Computation(); c2 = new Computation(); c3 = new Computation(); c4 = new Computation(); p = new Print(); - + reaction(t) -> c1.in {= - c1.in.set(count++); + c1.in.set(count++); =} - + c1.out -> c2.in after 200 msec; c2.out -> c3.in after 200 msec; c3.out -> c4.in after 200 msec; diff --git a/test/Cpp/src/PreambleTest.lf b/test/Cpp/src/PreambleTest.lf index 8303f99ea7..84e3ff97f3 100644 --- a/test/Cpp/src/PreambleTest.lf +++ b/test/Cpp/src/PreambleTest.lf @@ -11,7 +11,7 @@ main reactor { }; =} // this is only used inside reactions and therefore goes to the generated source file - // This function is only used inside a reaction and therefore is part of the private + // This function is only used inside a reaction and therefore is part of the private // interface. Moreover, we need to make sure that the function is only defined once // within a source file. This goes to Preamble/Preamble.cc private preamble {= @@ -20,13 +20,13 @@ main reactor { } =} logical action a:MyStruct; - + reaction(startup) -> a {= a.schedule({add_42(42), "baz"}); =} reaction(a) {= auto& value = *a.get(); - std::cout << "Received " << value.foo << " and '" << value.bar << "'\n"; + std::cout << "Received " << value.foo << " and '" << value.bar << "'\n"; =} } diff --git a/test/Cpp/src/ScheduleLogicalAction.lf b/test/Cpp/src/ScheduleLogicalAction.lf index 2b38e2620a..1218c74ad4 100644 --- a/test/Cpp/src/ScheduleLogicalAction.lf +++ b/test/Cpp/src/ScheduleLogicalAction.lf @@ -48,4 +48,4 @@ main reactor { f.x.set(42); =} f.y -> p.x; -} \ No newline at end of file +} diff --git a/test/Cpp/src/SelfLoop.lf b/test/Cpp/src/SelfLoop.lf index 9a7ee29dbd..e16a92cbab 100644 --- a/test/Cpp/src/SelfLoop.lf +++ b/test/Cpp/src/SelfLoop.lf @@ -39,4 +39,4 @@ reactor Self { main reactor SelfLoop { u = new Self(); u.y -> u.x; -} \ No newline at end of file +} diff --git a/test/Cpp/src/SimpleDeadline.lf b/test/Cpp/src/SimpleDeadline.lf index 6b1397784c..d7933499ba 100644 --- a/test/Cpp/src/SimpleDeadline.lf +++ b/test/Cpp/src/SimpleDeadline.lf @@ -3,7 +3,7 @@ // deadline violation. target Cpp; reactor Deadline(threshold:time(100 msec)) { - private preamble {= + private preamble {= #include =} input x:int; @@ -20,7 +20,7 @@ reactor Print { input in:bool; reaction(in) {= if (*in.get()) { - std::cout << "Output successfully produced by deadline handler." + std::cout << "Output successfully produced by deadline handler." << std::endl; } =} @@ -33,4 +33,4 @@ main reactor SimpleDeadline { std::this_thread::sleep_for(std::chrono::milliseconds(20)); d.x.set(42); =} -} +} diff --git a/test/Cpp/src/SimpleImport.lf b/test/Cpp/src/SimpleImport.lf index c1782143a4..1951128a96 100644 --- a/test/Cpp/src/SimpleImport.lf +++ b/test/Cpp/src/SimpleImport.lf @@ -4,4 +4,4 @@ import HelloWorld2 from "HelloWorld.lf"; main reactor SimpleImport { a = new HelloWorld2(); b = new HelloWorld2(); -} \ No newline at end of file +} diff --git a/test/Cpp/src/SlowingClock.lf b/test/Cpp/src/SlowingClock.lf index ca271ada9d..3863d348f9 100644 --- a/test/Cpp/src/SlowingClock.lf +++ b/test/Cpp/src/SlowingClock.lf @@ -3,7 +3,7 @@ * @author Maiko Brants TU Dresden * * Events are scheduled with increasing additional delays of 0, 100, 300, 600 -* msec on a logical action with a minimum delay of 100 msec. +* msec on a logical action with a minimum delay of 100 msec. * The use of the logical action ensures the elapsed time jumps exactly from * 0 to 100, 300, 600, and 1000 msec. * diff --git a/test/Cpp/src/SlowingClockPhysical.lf b/test/Cpp/src/SlowingClockPhysical.lf index c9c9ec15f7..9f55dd5ade 100644 --- a/test/Cpp/src/SlowingClockPhysical.lf +++ b/test/Cpp/src/SlowingClockPhysical.lf @@ -3,8 +3,8 @@ * @author Maiko Brants TU Dresden * * Events are scheduled with increasing additional delays of 0, 100, 300, 600 - * msec on a physical action with a minimum delay of 100 msec. - * The use of the physical action makes the elapsed time jumps from 0 to + * msec on a physical action with a minimum delay of 100 msec. + * The use of the physical action makes the elapsed time jumps from 0 to * approximately 100 msec, to approximatly 300 msec thereafter, drifting away * further with each new event. * @@ -40,4 +40,4 @@ main reactor SlowingClockPhysical { exit(2); } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/StartupOutFromInside.lf b/test/Cpp/src/StartupOutFromInside.lf index 219c9cc703..a18db51966 100644 --- a/test/Cpp/src/StartupOutFromInside.lf +++ b/test/Cpp/src/StartupOutFromInside.lf @@ -22,4 +22,4 @@ main reactor StartupOutFromInside { exit(1); } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/StructParallel.lf b/test/Cpp/src/StructParallel.lf index 5c8c0df9fe..81039ae851 100644 --- a/test/Cpp/src/StructParallel.lf +++ b/test/Cpp/src/StructParallel.lf @@ -4,7 +4,7 @@ // is currently not supported by the C++ runtime. target Cpp { }; -import Scale from "StructScale.lf"; +import Scale from "StructScale.lf"; import Source, Print from "StructPrint.lf" public preamble {= diff --git a/test/Cpp/src/StructScale.lf b/test/Cpp/src/StructScale.lf index 1e895f6737..6bb0606db7 100644 --- a/test/Cpp/src/StructScale.lf +++ b/test/Cpp/src/StructScale.lf @@ -13,7 +13,7 @@ public preamble {= reactor Scale(scale:int(2)) { input in:Hello; - + output out:Hello; reaction(in) -> out {= auto hello = in.get().get_mutable_copy(); diff --git a/test/Cpp/src/TimeLimit.lf b/test/Cpp/src/TimeLimit.lf index 9d0181e73c..67db942676 100644 --- a/test/Cpp/src/TimeLimit.lf +++ b/test/Cpp/src/TimeLimit.lf @@ -20,7 +20,7 @@ reactor Destination { input x:int; state s:int(1); reaction(x) {= - //std::cout << "Received " << *x.get() << '\n'; + //std::cout << "Received " << *x.get() << '\n'; if (*x.get() != s) { std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; exit(1); diff --git a/test/Cpp/src/TimeState.lf b/test/Cpp/src/TimeState.lf index 4cd2061a55..626120a4c7 100644 --- a/test/Cpp/src/TimeState.lf +++ b/test/Cpp/src/TimeState.lf @@ -2,7 +2,7 @@ target Cpp; 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 ea4e200441..06a676360b 100644 --- a/test/Cpp/src/Timeout_Test.lf +++ b/test/Cpp/src/Timeout_Test.lf @@ -20,7 +20,7 @@ reactor Consumer { reactor::log::Error() << "Received at: " << current.count() << ". Failed to enforce timeout."; exit(1); } else if(current == 11ms) { - success=true; + success=true; } =} @@ -38,7 +38,7 @@ reactor Consumer { main reactor Timeout_Test { consumer = new Consumer(); - producer = new Sender(break_interval = 1 msec); - + producer = new Sender(break_interval = 1 msec); + producer.out -> consumer.in; } diff --git a/test/Cpp/src/ToReactionNested.lf b/test/Cpp/src/ToReactionNested.lf index dbacf94b67..19799eddc3 100644 --- a/test/Cpp/src/ToReactionNested.lf +++ b/test/Cpp/src/ToReactionNested.lf @@ -33,4 +33,4 @@ main reactor { exit(1); } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf index 5a443d28c3..caa59f2591 100644 --- a/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Cpp/src/TriggerDownstreamOnlyIfPresent2.lf @@ -35,4 +35,4 @@ main reactor TriggerDownstreamOnlyIfPresent2 { s = new Source(); d = new[2] Destination(); s.out -> d.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/concurrent/AsyncCallback.lf b/test/Cpp/src/concurrent/AsyncCallback.lf index 1740e0bf62..f5740ea0be 100644 --- a/test/Cpp/src/concurrent/AsyncCallback.lf +++ b/test/Cpp/src/concurrent/AsyncCallback.lf @@ -5,11 +5,11 @@ target Cpp { cmake-include: "AsyncCallback.cmake" }; -main reactor AsyncCallback { - public preamble {= +main reactor AsyncCallback { + public preamble {= #include =} - + timer t(0, 200 msec); state thread:{=std::thread=}; state expected_time:time(100 msec); @@ -36,7 +36,7 @@ main reactor AsyncCallback { a.schedule(0); }); =} - + reaction(a) {= auto elapsed_time = get_elapsed_logical_time(); std::cout << "Asynchronous callback " << i++ << ": Assigned logical " diff --git a/test/Cpp/src/concurrent/AsyncCallback2.lf b/test/Cpp/src/concurrent/AsyncCallback2.lf index 1dde4dfc26..2d74156c44 100644 --- a/test/Cpp/src/concurrent/AsyncCallback2.lf +++ b/test/Cpp/src/concurrent/AsyncCallback2.lf @@ -5,11 +5,11 @@ target Cpp { cmake-include: "AsyncCallback.cmake" }; -main reactor AsyncCallback2 { - private preamble {= +main reactor AsyncCallback2 { + private preamble {= #include =} - + timer t(0, 200 msec); state expected_time:time(0); @@ -30,7 +30,7 @@ main reactor AsyncCallback2 { }); thread.join(); =} - + reaction(a) {= auto elapsed_time = get_elapsed_logical_time(); std::cout << "Asynchronous callback " << i++ << ": Assigned logical " diff --git a/test/Cpp/src/concurrent/CompositionThreaded.lf b/test/Cpp/src/concurrent/CompositionThreaded.lf index 89f6afbf9d..9fe0e65750 100644 --- a/test/Cpp/src/concurrent/CompositionThreaded.lf +++ b/test/Cpp/src/concurrent/CompositionThreaded.lf @@ -22,14 +22,14 @@ reactor Test { std::cout << "Received " << value << std::endl; if (value != count) { std::cerr << "FAILURE: Expected " << count << std::endl; - exit(1); + exit(1); } =} reaction(shutdown) {= if (count != 5) { std::cerr << "ERROR: expected to receive 5 values but got " << count << '\n'; exit(1); - } + } =} } main reactor { diff --git a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf index e9fd02caf3..e0ae0e334b 100644 --- a/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf +++ b/test/Cpp/src/concurrent/DeadlineHandledAboveThreaded.lf @@ -33,4 +33,4 @@ main reactor { exit(2); } =} -} +} diff --git a/test/Cpp/src/concurrent/DelayIntThreaded.lf b/test/Cpp/src/concurrent/DelayIntThreaded.lf index 893ba71275..8f2e2e3cd4 100644 --- a/test/Cpp/src/concurrent/DelayIntThreaded.lf +++ b/test/Cpp/src/concurrent/DelayIntThreaded.lf @@ -20,7 +20,7 @@ reactor Test { reaction(start) {= // Record the logical time at the start. start_time = get_logical_time(); - =} + =} reaction(in) {= std::cout << "Received: " << *in.get() << std::endl; // Check the time of the input. @@ -35,16 +35,16 @@ reactor Test { if (*in.get() != 42) { std::cerr << "ERROR: Expected input value to be 42. " << "It was " << *in.get() << std::endl; - exit(2); + exit(2); } =} } -main reactor { +main reactor { timer t; d = new Delay(); test = new Test(); - d.out -> test.in; + d.out -> test.in; reaction(t) -> d.in {= d.in.set(42); =} diff --git a/test/Cpp/src/concurrent/DeterminismThreaded.lf b/test/Cpp/src/concurrent/DeterminismThreaded.lf index 5f27ab49b6..00f84d6da0 100644 --- a/test/Cpp/src/concurrent/DeterminismThreaded.lf +++ b/test/Cpp/src/concurrent/DeterminismThreaded.lf @@ -5,7 +5,7 @@ reactor Source { reaction(t) -> y {= y.set(1); =} -} +} reactor Destination { input x:int; input y:int; diff --git a/test/Cpp/src/concurrent/HelloThreaded.lf b/test/Cpp/src/concurrent/HelloThreaded.lf index a1aa6cc4e6..8aa73406e6 100644 --- a/test/Cpp/src/concurrent/HelloThreaded.lf +++ b/test/Cpp/src/concurrent/HelloThreaded.lf @@ -31,14 +31,14 @@ reactor HelloCpp(period:time(2 secs), message:{=std::string=}("Hello C++")) { exit(1); } =} -} -reactor Inside(period:time(1 sec), +} +reactor Inside(period:time(1 sec), message:{=std::string=}("Composite default message.")) { third_instance = new HelloCpp(period = period, message = message); } -main reactor { - first_instance = new HelloCpp(period = 4 sec, +main reactor { + first_instance = new HelloCpp(period = 4 sec, message = "Hello from first_instance."); second_instance = new HelloCpp(message = "Hello from second_instance."); composite_instance = new Inside(message = "Hello from composite_instance."); -} +} diff --git a/test/Cpp/src/concurrent/Threaded.lf b/test/Cpp/src/concurrent/Threaded.lf index 4d1cb80183..5a11bfb02a 100644 --- a/test/Cpp/src/concurrent/Threaded.lf +++ b/test/Cpp/src/concurrent/Threaded.lf @@ -21,7 +21,7 @@ reactor Source { =} } reactor Computation { - private preamble {= + private preamble {= #include =} input in:int; diff --git a/test/Cpp/src/concurrent/ThreadedThreaded.lf b/test/Cpp/src/concurrent/ThreadedThreaded.lf index ebfefaf9b5..cc5a5ffd99 100644 --- a/test/Cpp/src/concurrent/ThreadedThreaded.lf +++ b/test/Cpp/src/concurrent/ThreadedThreaded.lf @@ -21,7 +21,7 @@ reactor Source { =} } reactor Computation { - private preamble {= + private preamble {= #include =} input in:int; diff --git a/test/Cpp/src/concurrent/TimeLimitThreaded.lf b/test/Cpp/src/concurrent/TimeLimitThreaded.lf index bd97ac66db..4ad60a9fff 100644 --- a/test/Cpp/src/concurrent/TimeLimitThreaded.lf +++ b/test/Cpp/src/concurrent/TimeLimitThreaded.lf @@ -20,7 +20,7 @@ reactor Destination { input x:int; state s:int(1); reaction(x) {= - //std::cout << "Received " << *x.get() << '\n'; + //std::cout << "Received " << *x.get() << '\n'; if (*x.get() != s) { std::cerr << "Error: Expected " << s << " and got " << *x.get() << '\n'; exit(1); diff --git a/test/Cpp/src/concurrent/Workers.lf b/test/Cpp/src/concurrent/Workers.lf index 814763fdf0..a20eeea57d 100644 --- a/test/Cpp/src/concurrent/Workers.lf +++ b/test/Cpp/src/concurrent/Workers.lf @@ -8,4 +8,4 @@ main reactor { std::cout << "Using 16 workers.\n"; } =} -} \ No newline at end of file +} diff --git a/test/Cpp/src/lib/Imported.lf b/test/Cpp/src/lib/Imported.lf index dbad42eaa4..ab21168b30 100644 --- a/test/Cpp/src/lib/Imported.lf +++ b/test/Cpp/src/lib/Imported.lf @@ -8,5 +8,5 @@ reactor Imported { a = new ImportedAgain(); reaction(x) -> a.x {= a.x.set(x.get()); - =} + =} } diff --git a/test/Cpp/src/lib/ImportedComposition.lf b/test/Cpp/src/lib/ImportedComposition.lf index 67902fc9c9..9f4871e3b6 100644 --- a/test/Cpp/src/lib/ImportedComposition.lf +++ b/test/Cpp/src/lib/ImportedComposition.lf @@ -24,4 +24,4 @@ reactor ImportedComposition { x -> g1.x after 10 msec; g1.y -> g2.x after 30 msec; g2.y -> y after 15 msec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/lib/LoopedActionSender.lf b/test/Cpp/src/lib/LoopedActionSender.lf index 0611f429d3..06ba66c154 100644 --- a/test/Cpp/src/lib/LoopedActionSender.lf +++ b/test/Cpp/src/lib/LoopedActionSender.lf @@ -1,7 +1,7 @@ -/** +/** * A sender reactor that outputs integers * in superdense time. - * + * * Modeled after the C version of this file. * * @author Maiko Brants @@ -29,4 +29,4 @@ act.schedule(break_interval); } =} - } \ No newline at end of file + } diff --git a/test/Cpp/src/multiport/BankSelfBroadcast.lf b/test/Cpp/src/multiport/BankSelfBroadcast.lf index d2a2fad70b..6373484a8d 100644 --- a/test/Cpp/src/multiport/BankSelfBroadcast.lf +++ b/test/Cpp/src/multiport/BankSelfBroadcast.lf @@ -3,9 +3,9 @@ * back to a multiport input of the same reactors in the bank * so that each reactor in the bank receives the output * produced by itself and each other reactor. - * + * * @author Edward A. Lee - * @author Christian Menard + * @author Christian Menard */ target Cpp; reactor A(bank_index:size_t(0)) { @@ -18,7 +18,7 @@ reactor A(bank_index:size_t(0)) { reaction(in) {= for (size_t i = 0; i < in.size(); i++) { if (in[i].is_present()) { - std::cout << "Reactor " << bank_index << " received " + std::cout << "Reactor " << bank_index << " received " << *in[i].get() << " on channel " << i << '\n'; if (*in[i].get() != i) { std::cerr << "ERROR: Expected " << i << '\n'; @@ -42,4 +42,4 @@ reactor A(bank_index:size_t(0)) { main reactor { a = new[4] A(); (a.out)+ -> a.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/BankToBank.lf b/test/Cpp/src/multiport/BankToBank.lf index 1c82464b1e..96a7a7c7a5 100644 --- a/test/Cpp/src/multiport/BankToBank.lf +++ b/test/Cpp/src/multiport/BankToBank.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors. +// Check bank of reactors sending to bank of reactors. target Cpp { timeout: 2 sec, fast: true @@ -37,4 +37,4 @@ main reactor BankToBank(width:int(4)) { a = new[4] Source(); b = new[4] Destination(); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/BankToBankMultiport.lf b/test/Cpp/src/multiport/BankToBankMultiport.lf index f9965031c7..7a31b339a0 100644 --- a/test/Cpp/src/multiport/BankToBankMultiport.lf +++ b/test/Cpp/src/multiport/BankToBankMultiport.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target Cpp { timeout: 2 sec, fast: true @@ -40,4 +40,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; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf index 7ecc45100f..1710f6ee5f 100644 --- a/test/Cpp/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Cpp/src/multiport/BankToBankMultiportAfter.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target Cpp { timeout: 2 sec, fast: true, @@ -20,12 +20,12 @@ reactor Destination(width:size_t(1)) { reaction(in) {= iterations++; auto lt = get_elapsed_logical_time(); - auto expected = iterations * 200ms; + auto expected = iterations * 200ms; if (expected != lt) { std::cerr << "ERROR: Expected logical time to be " << expected << " but got " << lt << '\n'; exit(1); } - + int sum = 0; for (size_t i = 0; i < in.size(); i++) { if (in[i].is_present()) sum += *in[i].get(); @@ -45,7 +45,7 @@ reactor Destination(width:size_t(1)) { std::cout << "Success.\n"; =} } -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 d588d069f3..6682340c24 100644 --- a/test/Cpp/src/multiport/BankToMultiport.lf +++ b/test/Cpp/src/multiport/BankToMultiport.lf @@ -2,7 +2,7 @@ target Cpp; reactor Source(bank_index:size_t(0)) { output out:unsigned; - + reaction (startup) -> out {= out.set(bank_index); =} @@ -11,21 +11,21 @@ reactor Source(bank_index:size_t(0)) { reactor Sink { input[4] in:unsigned; state received:bool(false); - + reaction (in) {= for (unsigned i = 0; i < in.size(); i++) { received = true; std::cout << "Received " << *in[i].get() << '\n'; if (*in[i].get() != i) { std::cerr << "Error: expected " << i << "!\n"; - exit(1); + exit(1); } } =} reaction (shutdown) {= if (!received) { std::cerr << "Error: received no input!\n"; - exit(2); + exit(2); } =} } @@ -34,4 +34,4 @@ main reactor BankToMultiport { source = new[4] Source(); sink = new Sink(); source.out -> sink.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/Broadcast.lf b/test/Cpp/src/multiport/Broadcast.lf index a1e7a8da0e..dd9f71663a 100644 --- a/test/Cpp/src/multiport/Broadcast.lf +++ b/test/Cpp/src/multiport/Broadcast.lf @@ -2,7 +2,7 @@ target Cpp; reactor Source { output out:unsigned; - + reaction (startup) -> out {= out.set(42); =} @@ -10,7 +10,7 @@ reactor Source { reactor Sink(bank_index:size_t(0)) { input in:unsigned; - + reaction (in) {= std::cout << "Received " << *in.get() << '\n'; if (*in.get() != 42) { @@ -24,4 +24,4 @@ main reactor { source = new Source(); sink = new[4] Sink(); (source.out)+ -> sink.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/BroadcastAfter.lf b/test/Cpp/src/multiport/BroadcastAfter.lf index ee8172fbd1..5694383a3e 100644 --- a/test/Cpp/src/multiport/BroadcastAfter.lf +++ b/test/Cpp/src/multiport/BroadcastAfter.lf @@ -1,10 +1,10 @@ target Cpp{ - fast: true + fast: true } reactor Source { output out:unsigned; - + reaction (startup) -> out {= out.set(42); =} @@ -13,7 +13,7 @@ reactor Source { reactor Sink(bank_index: size_t(0)) { input in:unsigned; state received: bool{false}; - + reaction (in) {= std::cout << bank_index << " received " << *in.get() << '\n'; if (*in.get() != 42) { @@ -26,7 +26,7 @@ reactor Sink(bank_index: size_t(0)) { } received = true; =} - + reaction(shutdown) {= if (!received) { std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; @@ -40,4 +40,4 @@ main reactor { source = new Source(); sink = new[4] Sink(); (source.out)+ -> sink.in after 1 sec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf index ad21135834..a0778d9b41 100644 --- a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf @@ -1,10 +1,10 @@ target Cpp{ - fast: true + fast: true } reactor Source(value:unsigned(42)) { output out:unsigned; - + reaction (startup) -> out {= out.set(value); =} @@ -13,7 +13,7 @@ reactor Source(value:unsigned(42)) { reactor Sink(bank_index: size_t(0)) { input in:unsigned; state received: bool{false}; - + reaction (in) {= std::cout << bank_index << " received " << *in.get() << '\n'; auto expected = (bank_index % 3) + 1; @@ -27,7 +27,7 @@ reactor Sink(bank_index: size_t(0)) { } received = true; =} - + reaction(shutdown) {= if (!received) { std::cerr << "ERROR: Destination " << bank_index << " received no input!\n"; diff --git a/test/Cpp/src/multiport/FullyConnected.lf b/test/Cpp/src/multiport/FullyConnected.lf index 9c1809a705..9b0233d43e 100644 --- a/test/Cpp/src/multiport/FullyConnected.lf +++ b/test/Cpp/src/multiport/FullyConnected.lf @@ -4,15 +4,15 @@ target Cpp { 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}; - + reaction (startup) -> out{= std::cout << "Hello from node " << bank_index << "!\n"; // broadcast my ID to everyone out.set(bank_index); =} - + reaction (in) {= std::cout << "Node " << bank_index << " received messages from "; received = true; @@ -22,17 +22,17 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { count++; std::cout << *port.get() << ", "; } - } + } std::cout << '\n'; if (count != num_nodes) { - std::cerr << "ERROR: received less messages than expected!"; + std::cerr << "ERROR: received less messages than expected!"; exit(1); } =} reaction (shutdown) {= if (!received) { std::cerr << "Error: received no input!\n"; - exit(2); + exit(2); } =} } diff --git a/test/Cpp/src/multiport/FullyConnectedAddressable.lf b/test/Cpp/src/multiport/FullyConnectedAddressable.lf index 3ea46ae739..bac6f76fba 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressable.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressable.lf @@ -6,15 +6,15 @@ target Cpp { 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}; - + reaction (startup) -> out{= std::cout << "Hello from node " << bank_index << "!\n"; // send my ID only to my right neighbour - out[(bank_index + 1) % num_nodes].set(bank_index); + out[(bank_index + 1) % num_nodes].set(bank_index); =} - + reaction (in) {= std::cout << "Node " << bank_index << " received messages from "; received = true; @@ -31,7 +31,7 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { size_t expected = bank_index == 0 ? num_nodes - 1 : bank_index - 1; if (count != 1 || result != expected) { - std::cerr << "ERROR: received an unexpected message!\n"; + std::cerr << "ERROR: received an unexpected message!\n"; exit(1); } @@ -39,7 +39,7 @@ reactor Node(bank_index: size_t(0), num_nodes: size_t(4)) { reaction (shutdown) {= if (!received) { std::cerr << "Error: received no input!\n"; - exit(2); + exit(2); } =} } @@ -47,7 +47,7 @@ reactor Node(bank_index: size_t(0), 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); - + nodes2 = new[num_nodes] Node(num_nodes=num_nodes); interleaved(nodes2.out) -> nodes2.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf index 2691cb40a5..d4c8240c95 100644 --- a/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf +++ b/test/Cpp/src/multiport/FullyConnectedAddressableAfter.lf @@ -8,7 +8,7 @@ import Node from "FullyConnectedAddressable.lf" main reactor(num_nodes: size_t(4)) { nodes1 = new[num_nodes] Node(num_nodes=num_nodes); nodes1.out -> interleaved(nodes1.in) after 200msec; - + nodes2 = new[num_nodes] Node(num_nodes=num_nodes); interleaved(nodes2.out) -> nodes2.in after 400msec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportFromBank.lf b/test/Cpp/src/multiport/MultiportFromBank.lf index 6666a110a8..84ac23fdaa 100644 --- a/test/Cpp/src/multiport/MultiportFromBank.lf +++ b/test/Cpp/src/multiport/MultiportFromBank.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source(bank_index:size_t(0)) { output out:unsigned; reaction(startup) -> out {= @@ -36,4 +36,4 @@ main reactor (width:size_t(4)) { a = new[width] Source(); b = new Destination(port_width = width); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf index 112703dc1c..58ef8d77d1 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchy.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source(bank_index:size_t(0)) { output out:unsigned; reaction(startup) -> out {= diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf index 0bf162191d..764e40f2ac 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source(bank_index:int(0)) { output out:int; reaction(startup) -> out {= @@ -46,4 +46,4 @@ main reactor MultiportFromBankHierarchyAfter { a = new Container(); b = new Destination(); a.out -> b.in after 1 sec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportFromHierarchy.lf b/test/Cpp/src/multiport/MultiportFromHierarchy.lf index 1d2c392142..a9454c5730 100644 --- a/test/Cpp/src/multiport/MultiportFromHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportFromHierarchy.lf @@ -1,8 +1,8 @@ - // Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[4] out:int; @@ -48,8 +48,8 @@ reactor InsideContainer { src.out -> out; } -main reactor MultiportFromHierarchy { +main reactor MultiportFromHierarchy { a = new Container(); b = new Destination(); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportIn.lf b/test/Cpp/src/multiport/MultiportIn.lf index b08ab0c9c3..bda94b6204 100644 --- a/test/Cpp/src/multiport/MultiportIn.lf +++ b/test/Cpp/src/multiport/MultiportIn.lf @@ -27,7 +27,7 @@ reactor Destination { int sum = 0; for (int i = 0; i < in.size(); i++) { sum += *in[i].get(); - } + } std::cout << "Sum of received: " << sum << ".\n"; if (sum != s) { std::cerr << "ERROR: Expected " << s << ".\n"; @@ -44,7 +44,7 @@ reactor Destination { =} } -main reactor MultiportIn { +main reactor MultiportIn { a = new Source(); t1 = new Computation(); t2 = new Computation(); @@ -56,4 +56,4 @@ main reactor MultiportIn { a.out -> t3.in; a.out -> t4.in; t1.out, t2.out, t3.out, t4.out -> b.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportOut.lf b/test/Cpp/src/multiport/MultiportOut.lf index a7fbab7710..0d86c22c37 100644 --- a/test/Cpp/src/multiport/MultiportOut.lf +++ b/test/Cpp/src/multiport/MultiportOut.lf @@ -2,7 +2,7 @@ target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[4] out:int; @@ -49,7 +49,7 @@ reactor Destination { =} } -main reactor { +main reactor { a = new Source(); t1 = new Computation(); t2 = new Computation(); diff --git a/test/Cpp/src/multiport/MultiportToBank.lf b/test/Cpp/src/multiport/MultiportToBank.lf index 247f9d244f..4d8605f612 100644 --- a/test/Cpp/src/multiport/MultiportToBank.lf +++ b/test/Cpp/src/multiport/MultiportToBank.lf @@ -2,7 +2,7 @@ target Cpp; reactor Source { output[4] out:unsigned; - + reaction (startup) -> out {= for (unsigned i = 0 ; i < out.size(); i++) { out[i].set(i); @@ -12,7 +12,7 @@ reactor Source { reactor Sink(bank_index:size_t(0)) { input in:unsigned; - + reaction (in) {= std::cout << "Received " << *in.get() << '\n'; if (*in.get() != bank_index) { @@ -26,4 +26,4 @@ main reactor MultiportToBank { source = new Source(); sink = new[4] Sink(); source.out -> sink.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportToBankAfter.lf b/test/Cpp/src/multiport/MultiportToBankAfter.lf index c9500104d4..efd7692057 100644 --- a/test/Cpp/src/multiport/MultiportToBankAfter.lf +++ b/test/Cpp/src/multiport/MultiportToBankAfter.lf @@ -2,7 +2,7 @@ target Cpp; reactor Source { output[4] out:unsigned; - + reaction (startup) -> out {= for (unsigned i = 0 ; i < out.size(); i++) { out[i].set(i); @@ -12,7 +12,7 @@ reactor Source { reactor Sink(bank_index:size_t(0)) { input in:unsigned; - + reaction (in) {= std::cout << "Received " << *in.get() << '\n'; if (*in.get() != bank_index) { @@ -29,5 +29,5 @@ reactor Sink(bank_index:size_t(0)) { main reactor MultiportToBankAfter { source = new Source(); sink = new[4] Sink(); - source.out -> sink.in after 1 sec; + source.out -> sink.in after 1 sec; } diff --git a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf index 30d1a36fee..9d19657aa5 100644 --- a/test/Cpp/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToBankHierarchy.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source { output[3] out:unsigned; reaction(startup) -> out {= @@ -37,8 +37,8 @@ reactor Container { in -> c.in; } -main reactor MultiportToBankHierarchy { +main reactor MultiportToBankHierarchy { a = new Source(); b = new Container(); a.out -> b.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index 13f1f34804..4a0883f134 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -1,9 +1,9 @@ - // Check multiport output to multiport input, where the latter is a hierarchical reactor. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. // Note that the destination reactor has width wider than the sender, so one input is dangling. target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source(width:size_t(4)) { timer t(0, 200 msec); output[width] out:int; @@ -43,8 +43,8 @@ reactor Container(width:size_t(4)) { 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; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportToMultiport.lf b/test/Cpp/src/multiport/MultiportToMultiport.lf index d54fc34c89..43130f5a7e 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport.lf @@ -2,7 +2,7 @@ target Cpp; reactor Source { output[4] out:unsigned; - + reaction (startup) -> out {= for (unsigned i = 0; i < out.size(); i++) { out[i].set(i); @@ -13,21 +13,21 @@ reactor Source { reactor Sink { input[4] in:unsigned; state received:bool(false); - + reaction (in) {= for (unsigned i = 0; i < in.size(); i++) { std::cout << "Received " << *in[i].get() << '\n'; received = true; if (*in[i].get() != i) { std::cerr << "Error: expected " << i << "!\n"; - exit(1); + exit(1); } } =} reaction (shutdown) {= if (!received) { std::cerr << "Error: No data received!\n"; - exit(2); + exit(2); } =} } @@ -36,4 +36,4 @@ main reactor MultiportToMultiport { source = new Source(); sink = new Sink(); source.out -> sink.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportToMultiport2.lf b/test/Cpp/src/multiport/MultiportToMultiport2.lf index 0d8cdf9f5b..0ea63c75fd 100644 --- a/test/Cpp/src/multiport/MultiportToMultiport2.lf +++ b/test/Cpp/src/multiport/MultiportToMultiport2.lf @@ -34,4 +34,4 @@ main reactor MultiportToMultiport2 { a2 = new Source(width = 2); b = new Destination(width = 5); a1.out, a2.out -> b.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/MultiportToMultiportArray.lf b/test/Cpp/src/multiport/MultiportToMultiportArray.lf index 905a44a610..21e95cd2a8 100644 --- a/test/Cpp/src/multiport/MultiportToMultiportArray.lf +++ b/test/Cpp/src/multiport/MultiportToMultiportArray.lf @@ -3,21 +3,21 @@ target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[2] out:int[3]; state s:int(0); reaction(t) -> out {= - for(int i = 0; i < 2; i++) { + for(int i = 0; i < 2; i++) { // Dynamically allocate a new output array auto a = reactor::make_mutable_value>(); // initialize it (*a)[0] = s++; (*a)[1] = s++; - (*a)[2] = s++; + (*a)[2] = s++; // and send it - out[i].set(std::move(a)); + out[i].set(std::move(a)); } =} } @@ -51,7 +51,7 @@ reactor Destination { =} } -main reactor MultiportToMultiportArray { +main reactor MultiportToMultiportArray { a = new Source(); b = new Destination(); a.out -> b.in; diff --git a/test/Cpp/src/multiport/MultiportToPort.lf b/test/Cpp/src/multiport/MultiportToPort.lf index 648637fb37..a3cda51866 100644 --- a/test/Cpp/src/multiport/MultiportToPort.lf +++ b/test/Cpp/src/multiport/MultiportToPort.lf @@ -3,7 +3,7 @@ target Cpp { timeout: 2 sec, fast: true -}; +}; reactor Source { output[2] out:int; reaction(startup) -> out {= @@ -33,9 +33,9 @@ reactor Destination(expected:int(0)) { =} } -main reactor MultiportToPort { +main reactor MultiportToPort { a = new Source(); b1 = new Destination(); b2 = new Destination(expected = 1); a.out -> b1.in, b2.in; -} \ No newline at end of file +} diff --git a/test/Cpp/src/multiport/PipelineAfter.lf b/test/Cpp/src/multiport/PipelineAfter.lf index 976672b7d7..b504a0a6e7 100644 --- a/test/Cpp/src/multiport/PipelineAfter.lf +++ b/test/Cpp/src/multiport/PipelineAfter.lf @@ -2,7 +2,7 @@ target Cpp; reactor Source { output out:unsigned; - + reaction (startup) -> out {= out.set(40); =} @@ -11,7 +11,7 @@ reactor Source { reactor Compute { input in:unsigned; output out:unsigned; - + reaction (in) -> out {= out.set(*in.get() + 2); =} @@ -19,7 +19,7 @@ reactor Compute { reactor Sink { input in:unsigned; - + reaction (in) {= std::cout << "Received " << *in.get() << '\n'; if (*in.get() != 42) { @@ -31,7 +31,7 @@ reactor Sink { exit(2); } =} - + } main reactor { @@ -40,4 +40,4 @@ main reactor { sink = new Sink(); source.out, compute.out -> compute.in, sink.in after 500 msec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/target/AfterVoid.lf b/test/Cpp/src/target/AfterVoid.lf index 1173a33813..53a24080aa 100644 --- a/test/Cpp/src/target/AfterVoid.lf +++ b/test/Cpp/src/target/AfterVoid.lf @@ -37,6 +37,6 @@ reactor print { main reactor { f = new foo(); p = new print(); - + f.y -> p.x after 10 msec; -} \ No newline at end of file +} diff --git a/test/Cpp/src/target/GenericDelay.lf b/test/Cpp/src/target/GenericDelay.lf index 75d67379c3..1b3d3484f1 100644 --- a/test/Cpp/src/target/GenericDelay.lf +++ b/test/Cpp/src/target/GenericDelay.lf @@ -6,11 +6,11 @@ reactor Delay(delay:time(0)) { output out:T; input in:T; logical action a(delay):T; - + reaction (a) -> out {= out.set(a.get()); =} - + reaction (in) -> a {= a.schedule(in.get()); =} @@ -19,7 +19,7 @@ reactor Delay(delay:time(0)) { main reactor { d = new Delay(delay=100 msec); test = new Test(); - d.out -> test.in; + d.out -> test.in; reaction(startup) -> d.in {= d.in.set(42); =} diff --git a/test/Cpp/src/target/PreambleFile.lf b/test/Cpp/src/target/PreambleFile.lf index d55175bfc4..31a87e2900 100644 --- a/test/Cpp/src/target/PreambleFile.lf +++ b/test/Cpp/src/target/PreambleFile.lf @@ -7,7 +7,7 @@ public preamble {= int foo; std::string bar; }; - + int add_42(int i); =} @@ -29,7 +29,7 @@ reactor Source { } reactor Print { - // This helper function is only used within the Print reactor and is + // This helper function is only used within the Print reactor and is // therefore part of its private interface. This goes to PreambleFile/Print.cc private preamble {= void print(const MyStruct& x) { @@ -48,4 +48,4 @@ main reactor PreambleFile { s = new Source(); p = new Print(); s.x -> p.x; -} \ No newline at end of file +} diff --git a/test/Python/src/ActionDelay.lf b/test/Python/src/ActionDelay.lf index 861fa3ed0c..9c3815008e 100644 --- a/test/Python/src/ActionDelay.lf +++ b/test/Python/src/ActionDelay.lf @@ -20,7 +20,7 @@ reactor Source { output out; reaction(startup) -> out {= out.set(1) - =} + =} } reactor Sink { input _in; @@ -40,7 +40,7 @@ main reactor ActionDelay { source = new Source(); sink = new Sink(); g = new GeneratedDelay(); - + source.out -> g.y_in; g.y_out -> sink._in; -} \ No newline at end of file +} diff --git a/test/Python/src/ActionWithNoReaction.lf b/test/Python/src/ActionWithNoReaction.lf index 4d73bea6e1..9e3b657999 100644 --- a/test/Python/src/ActionWithNoReaction.lf +++ b/test/Python/src/ActionWithNoReaction.lf @@ -32,4 +32,4 @@ main reactor { f.x.set(42) =} f.y -> p.x after 10 msec; -} \ No newline at end of file +} diff --git a/test/Python/src/After.lf b/test/Python/src/After.lf index 44655c1609..301c51ddf1 100644 --- a/test/Python/src/After.lf +++ b/test/Python/src/After.lf @@ -44,4 +44,4 @@ main reactor { f.x.set(42) =} f.y -> p.x after 10 msec; -} \ No newline at end of file +} diff --git a/test/Python/src/AfterCycles.lf b/test/Python/src/AfterCycles.lf index 203a62076d..4c03136f28 100644 --- a/test/Python/src/AfterCycles.lf +++ b/test/Python/src/AfterCycles.lf @@ -4,7 +4,7 @@ target Python; reactor Source { output out; - + reaction(startup) -> out {= out.set(1) =} @@ -13,9 +13,9 @@ reactor Source { reactor Work { input _in; output out; - + reaction(_in) -> out {= - out.set(_in.value) + out.set(_in.value) =} } @@ -24,10 +24,10 @@ main reactor AfterCycles { s = new Source(); w0 = new Work(); w1 = new Work(); - + s.out -> w0._in after 10 msec; s.out -> w1._in after 20 msec; - + reaction(w0.out) {= self.count+=1 elapsed_time = lf.time.logical_elapsed() @@ -40,7 +40,7 @@ main reactor AfterCycles { sys.stderr.write("Value should have been 1.\n") exit(4) =} - + reaction(w1.out) {= self.count+=1 elapsed_time = lf.time.logical_elapsed() @@ -59,4 +59,4 @@ main reactor AfterCycles { sys.stderr.write("Top-level reactions should have been triggered but were not.\n") exit(5) =} -} \ No newline at end of file +} diff --git a/test/Python/src/AfterOverlapped.lf b/test/Python/src/AfterOverlapped.lf index 6c961e1ac6..36f716f4e2 100644 --- a/test/Python/src/AfterOverlapped.lf +++ b/test/Python/src/AfterOverlapped.lf @@ -34,4 +34,4 @@ main reactor AfterOverlapped { count = new Count(); test = new Test(); count.out -> test.c after 2 sec; -} \ No newline at end of file +} diff --git a/test/Python/src/ArrayAsParameter.lf b/test/Python/src/ArrayAsParameter.lf index 8c08da4ea1..54b4e7ea2c 100644 --- a/test/Python/src/ArrayAsParameter.lf +++ b/test/Python/src/ArrayAsParameter.lf @@ -34,4 +34,4 @@ main reactor ArrayAsParameter { s = new Source(sequence = (1, 2, 3, 4)); p = new Print(); s.out -> p._in; -} \ No newline at end of file +} diff --git a/test/Python/src/ArrayParallel.lf b/test/Python/src/ArrayParallel.lf index c0c67f9b64..a13df61916 100644 --- a/test/Python/src/ArrayParallel.lf +++ b/test/Python/src/ArrayParallel.lf @@ -16,4 +16,4 @@ main reactor ArrayParallel { s.out -> c2._in; c1.out -> p1._in; c2.out -> p2._in; -} \ No newline at end of file +} diff --git a/test/Python/src/CompareTags.lf b/test/Python/src/CompareTags.lf index b3b2b52669..fbe3c72d43 100644 --- a/test/Python/src/CompareTags.lf +++ b/test/Python/src/CompareTags.lf @@ -1,4 +1,4 @@ -// Tests the lf.tag_compare() function in the python target. +// Tests the lf.tag_compare() function in the python target. target Python { timeout: 10 msec, fast: false @@ -28,4 +28,4 @@ main reactor CompareTags { self.sys.stderr.write("tag3 should be greater than tag1\n") self.sys.exit(1) =} -} \ No newline at end of file +} diff --git a/test/Python/src/Composition.lf b/test/Python/src/Composition.lf index 02e8384ca7..2e5d8f425d 100644 --- a/test/Python/src/Composition.lf +++ b/test/Python/src/Composition.lf @@ -34,7 +34,7 @@ reactor Test { } main reactor Composition { s = new Source(); - + d = new Test(); s.y -> d.x; } diff --git a/test/Python/src/CompositionAfter.lf b/test/Python/src/CompositionAfter.lf index e3b671349f..1c901fb276 100644 --- a/test/Python/src/CompositionAfter.lf +++ b/test/Python/src/CompositionAfter.lf @@ -21,13 +21,13 @@ reactor Test { reaction(x) {= self.count += 1 print("Received ", x.value) - if x.value != self.count: + if x.value != self.count: sys.stderr.write("FAILURE: Expected %d\n", self.count) exit(1) - =} + =} } main reactor(delay(5 sec)) { s = new Source(); d = new Test(); s.y -> d.x after delay; -} \ No newline at end of file +} diff --git a/test/Python/src/CompositionGain.lf b/test/Python/src/CompositionGain.lf index 8d223b1c12..939e386348 100644 --- a/test/Python/src/CompositionGain.lf +++ b/test/Python/src/CompositionGain.lf @@ -26,4 +26,4 @@ main reactor { sys.stderr.write("ERROR: Received value should have been ", str(42 * 2)) exit(2) =} -} \ No newline at end of file +} diff --git a/test/Python/src/CompositionInheritance.lf b/test/Python/src/CompositionInheritance.lf index 79376d8460..83aa4c45da 100644 --- a/test/Python/src/CompositionInheritance.lf +++ b/test/Python/src/CompositionInheritance.lf @@ -45,4 +45,4 @@ main reactor { d = new Test(); s.y2 -> d.x; -} \ No newline at end of file +} diff --git a/test/Python/src/CountSelf.lf b/test/Python/src/CountSelf.lf index b4bc565ace..ebdf249c8a 100644 --- a/test/Python/src/CountSelf.lf +++ b/test/Python/src/CountSelf.lf @@ -28,8 +28,8 @@ reactor Test { =} } -main reactor { +main reactor { d = new CountSelf2(); t = new Test(); - d.out -> t._in; -} \ No newline at end of file + d.out -> t._in; +} diff --git a/test/Python/src/CountTest.lf b/test/Python/src/CountTest.lf index 60f74a8eff..c52b0877e2 100644 --- a/test/Python/src/CountTest.lf +++ b/test/Python/src/CountTest.lf @@ -27,4 +27,3 @@ main reactor CountTest { test = new Test(); count.out -> test.c; } - diff --git a/test/Python/src/DanglingOutput.lf b/test/Python/src/DanglingOutput.lf index 4badec2e7c..ac3b58648d 100644 --- a/test/Python/src/DanglingOutput.lf +++ b/test/Python/src/DanglingOutput.lf @@ -22,4 +22,4 @@ main reactor DanglingOutput { source = new Source(); container = new Gain(); source.out -> container._in; -} \ No newline at end of file +} diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index 87a4f4070c..a421ed73ee 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -16,7 +16,7 @@ reactor Source(period(3 sec)) { start_time = lf.time.physical() while (lf.time.physical() < start_time + sleep_time): pass - + print("Source sends: ", self.count) y.set(self.count) self.count += 1 @@ -32,7 +32,7 @@ reactor Destination(timeout(1 sec)) { # The count variable is odd, so the deadline should have been violated. sys.stderr.write("ERROR: Failed to detect deadline.\n") exit(1) - + self.count += 1 =} deadline(timeout) {= print("Destination deadline handler receives: ", x.value) diff --git a/test/Python/src/DeadlineHandledAbove.lf b/test/Python/src/DeadlineHandledAbove.lf index a5f7e2242d..793c509149 100644 --- a/test/Python/src/DeadlineHandledAbove.lf +++ b/test/Python/src/DeadlineHandledAbove.lf @@ -34,4 +34,4 @@ main reactor DeadlineHandledAbove { sys.stderr.write("FAILURE. Container did not react to deadline violation.\n") exit(2) =} -} \ No newline at end of file +} diff --git a/test/Python/src/DelayArrayWithAfter.lf b/test/Python/src/DelayArrayWithAfter.lf index b6738e2c77..568ed7933f 100644 --- a/test/Python/src/DelayArrayWithAfter.lf +++ b/test/Python/src/DelayArrayWithAfter.lf @@ -10,8 +10,8 @@ reactor Source { timer t(0, 1 sec); reaction(t) -> out {= out.set([(x * self.iteration) for x in [1,2,3]]) - print("At time {:d}, sending list ".format(lf.time.logical_elapsed()), out.value) - + print("At time {:d}, sending list ".format(lf.time.logical_elapsed()), out.value) + self.iteration += 1 =} } @@ -35,7 +35,7 @@ reactor Print(scale(1)) { self.iteration += 1 =} - + reaction(shutdown) {= if self.inputs_received == 0: sys.stderr.write("ERROR: Print reactor received no inputs.\n") diff --git a/test/Python/src/DelayInt.lf b/test/Python/src/DelayInt.lf index d2b8c4d93f..fe41891ba5 100644 --- a/test/Python/src/DelayInt.lf +++ b/test/Python/src/DelayInt.lf @@ -19,7 +19,7 @@ reactor Test { reaction(startup) {= # Record the logical time at the start. self.start_time = lf.time.logical() - =} + =} reaction(_in) {= print("Received: ", _in.value) self.received_value = True @@ -42,11 +42,11 @@ reactor Test { =} } -main reactor DelayInt { +main reactor DelayInt { d = new Delay(); t = new Test(); - d.out -> t._in; + d.out -> t._in; reaction(startup) -> d._in {= d._in.set(42) =} -} \ No newline at end of file +} diff --git a/test/Python/src/DelayString.lf b/test/Python/src/DelayString.lf index 9579a2b9bf..a21d161599 100644 --- a/test/Python/src/DelayString.lf +++ b/test/Python/src/DelayString.lf @@ -29,10 +29,10 @@ reactor Test { =} } -main reactor { +main reactor { d = new DelayString2(); t = new Test(); - d.out -> t._in; + d.out -> t._in; reaction(startup) -> d._in {= d._in.set("Hello") =} diff --git a/test/Python/src/DelayedAction.lf b/test/Python/src/DelayedAction.lf index 60bf1b419f..0895e02cc7 100644 --- a/test/Python/src/DelayedAction.lf +++ b/test/Python/src/DelayedAction.lf @@ -9,7 +9,7 @@ main reactor DelayedAction { reaction(t) -> a {= a.schedule(MSEC(100)) =} - + reaction(a) {= elapsed = lf.time.logical_elapsed() elapsed_physical = lf.time.physical_elapsed() @@ -21,4 +21,4 @@ main reactor DelayedAction { sys.stderr.write("Expected {:d} but got {:d}.\n".format(expected, elapsed)) exit(1) =} -} \ No newline at end of file +} diff --git a/test/Python/src/DelayedReaction.lf b/test/Python/src/DelayedReaction.lf index 7fd329abd6..9c48986480 100644 --- a/test/Python/src/DelayedReaction.lf +++ b/test/Python/src/DelayedReaction.lf @@ -6,8 +6,8 @@ reactor Source { timer t; reaction(t) -> out {= out.set(1) - =} -} + =} +} reactor Sink { input _in; reaction(_in) {= @@ -19,8 +19,8 @@ reactor Sink { =} } main reactor DelayedReaction { - + source = new Source(); sink = new Sink(); source.out -> sink._in after 100 msec; -} \ No newline at end of file +} diff --git a/test/Python/src/Determinism.lf b/test/Python/src/Determinism.lf index 4076de99a5..003b6c7e9e 100644 --- a/test/Python/src/Determinism.lf +++ b/test/Python/src/Determinism.lf @@ -5,7 +5,7 @@ reactor Source { reaction(t) -> y {= y.set(1) =} -} +} reactor Destination { input x; input y; @@ -38,4 +38,4 @@ main reactor Determinism { s.y -> p1.x; p1.y -> p2.x; p2.y -> d.x; -} \ No newline at end of file +} diff --git a/test/Python/src/DoubleInvocation.lf b/test/Python/src/DoubleInvocation.lf index eeee9a6bd0..a24512fb7e 100644 --- a/test/Python/src/DoubleInvocation.lf +++ b/test/Python/src/DoubleInvocation.lf @@ -20,7 +20,7 @@ reactor Ball { timer trigger(0, 1 sec); reaction(trigger) -> position, velocity {= position.set(self.p) - velocity.set(-1) + velocity.set(-1) self.p -= 1 =} } @@ -47,4 +47,4 @@ main reactor DoubleInvocation { b1.velocity -> p.velocity; b1.position -> plot.position; b1.velocity -> plot.velocity; -} \ No newline at end of file +} diff --git a/test/Python/src/Gain.lf b/test/Python/src/Gain.lf index f0327be232..48e7af9d3b 100644 --- a/test/Python/src/Gain.lf +++ b/test/Python/src/Gain.lf @@ -22,7 +22,7 @@ reactor Test { sys.stderr.write("ERROR: No value received by Test reactor!") else: sys.stderr.write("Test passes.") - + =} } main reactor Gain { @@ -32,4 +32,4 @@ main reactor Gain { reaction(startup) -> g.x {= g.x.set(1) =} -} \ No newline at end of file +} diff --git a/test/Python/src/GetMicroStep.lf b/test/Python/src/GetMicroStep.lf index 86194684de..8dd7c0e841 100644 --- a/test/Python/src/GetMicroStep.lf +++ b/test/Python/src/GetMicroStep.lf @@ -1,4 +1,4 @@ -// Tests the get_microstep() function in the python target. +// Tests the get_microstep() function in the python target. target Python { fast: false }; @@ -23,4 +23,4 @@ main reactor GetMicroStep { if self.s < 10: l.schedule(0) =} -} \ No newline at end of file +} diff --git a/test/Python/src/GetTime.lf b/test/Python/src/GetTime.lf index ae9506d5c8..ed03f3afb5 100644 --- a/test/Python/src/GetTime.lf +++ b/test/Python/src/GetTime.lf @@ -12,13 +12,13 @@ main reactor GetTime { elapsed = lf.time.logical_elapsed() print("Elapsed logical time is ", elapsed) - + physical = lf.time.physical() print("Physical time is ", physical) elapsed_physical = lf.time.physical_elapsed() print("Elapsed physical time is ", elapsed_physical) - + print("Time lag is ", physical - logical) =} -} \ No newline at end of file +} diff --git a/test/Python/src/Hello.lf b/test/Python/src/Hello.lf index 8a267db465..7042482877 100644 --- a/test/Python/src/Hello.lf +++ b/test/Python/src/Hello.lf @@ -33,12 +33,12 @@ reactor Reschedule(period(2 secs), message("Hello Python")) { sys.stderr.write("FAILURE: Expected 200ms of logical time to elapse but got {:d} nanoseconds.\n".format(tm - self.previous_time)) exit(1) =} -} +} reactor Inside(period(1 sec), message("Composite default message.")) { third_instance = new Reschedule(period = period, message = message); } -main reactor Hello { +main reactor Hello { first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); second_instance = new Reschedule(message = "Hello from second_instance."); composite_instance = new Inside(message = "Hello from composite_instance."); -} \ No newline at end of file +} diff --git a/test/Python/src/Hierarchy.lf b/test/Python/src/Hierarchy.lf index 4b1d354471..143f06fe01 100644 --- a/test/Python/src/Hierarchy.lf +++ b/test/Python/src/Hierarchy.lf @@ -37,8 +37,8 @@ main reactor Hierarchy { source = new Source(); container = new GainContainer(); print = new Print(); - print2 = new Print(); + print2 = new Print(); source.out -> container._in; container.out -> print._in; container.out -> print2._in; -} \ No newline at end of file +} diff --git a/test/Python/src/Hierarchy2.lf b/test/Python/src/Hierarchy2.lf index 781e2fc8ce..4e8e3717ee 100644 --- a/test/Python/src/Hierarchy2.lf +++ b/test/Python/src/Hierarchy2.lf @@ -58,4 +58,4 @@ main reactor Hierarchy2 { print = new Print(); source.out -> addCount._in; addCount.out -> print._in; -} \ No newline at end of file +} diff --git a/test/Python/src/IdentifierLength.lf b/test/Python/src/IdentifierLength.lf index f5a328a8ec..c38c0951ef 100644 --- a/test/Python/src/IdentifierLength.lf +++ b/test/Python/src/IdentifierLength.lf @@ -22,10 +22,10 @@ reactor Another_Really_Long_Name_For_A_Test_Class { if x.value != self.count: sys.stderr.write("FAILURE: Expected {:d}.\n".format(self.count)) exit(1) - =} + =} } main reactor IdentifierLength { a_really_long_name_for_a_source_instance = new A_Really_Long_Name_For_A_Source_But_Not_Quite_255_Characters_Which_Is_The_Maximum_For_The_Python_Target(); another_really_long_name_for_a_test_instance = new Another_Really_Long_Name_For_A_Test_Class(); a_really_long_name_for_a_source_instance.y -> another_really_long_name_for_a_test_instance.x; -} \ No newline at end of file +} diff --git a/test/Python/src/Import.lf b/test/Python/src/Import.lf index 2aa1737038..723b437f25 100644 --- a/test/Python/src/Import.lf +++ b/test/Python/src/Import.lf @@ -7,6 +7,6 @@ main reactor Import { timer t; a = new Imported(); reaction(t) -> a.x {= - a.x.set(42) + a.x.set(42) =} } diff --git a/test/Python/src/ImportComposition.lf b/test/Python/src/ImportComposition.lf index 2e7c639e7d..ffbd2d2795 100644 --- a/test/Python/src/ImportComposition.lf +++ b/test/Python/src/ImportComposition.lf @@ -7,7 +7,7 @@ main reactor ImportComposition { a = new ImportedComposition(); state received(false); reaction(startup) -> a.x {= - a.x.set(42) + a.x.set(42) =} reaction(a.y) {= receive_time = lf.time.logical_elapsed() @@ -25,4 +25,4 @@ main reactor ImportComposition { sys.stderr.write("ERROR: Nothing received.\n"); exit(3) =} -} +} diff --git a/test/Python/src/ImportRenamed.lf b/test/Python/src/ImportRenamed.lf index f22d290f75..0dcf72e571 100644 --- a/test/Python/src/ImportRenamed.lf +++ b/test/Python/src/ImportRenamed.lf @@ -11,6 +11,6 @@ main reactor { c = new Z(); reaction(t) -> a.x {= - a.x.set(42) + a.x.set(42) =} } diff --git a/test/Python/src/ManualDelayedReaction.lf b/test/Python/src/ManualDelayedReaction.lf index 822ef0def9..42aed21060 100644 --- a/test/Python/src/ManualDelayedReaction.lf +++ b/test/Python/src/ManualDelayedReaction.lf @@ -13,7 +13,7 @@ reactor GeneratedDelay { input y_in; output y_out; state y_state(0); - + // TODO: delay in act or the schedule call? physical action act(0 msec); @@ -32,7 +32,7 @@ reactor Source { // reaction(t) -> out after 100 msec {= reaction(t) -> out {= out.set(1) - =} + =} } reactor Sink { @@ -47,14 +47,14 @@ reactor Sink { exit(1) =} deadline(200 msec) {= =} } -main reactor ManualDelayedReaction { +main reactor ManualDelayedReaction { source = new Source(); sink = new Sink(); g = new GeneratedDelay(); - + // source.out -> sink.s_in; // rewritten above source.out -> g.y_in; g.y_out -> sink.s_in; - + } diff --git a/test/Python/src/Microsteps.lf b/test/Python/src/Microsteps.lf index 6287a88e37..2bcdd6c831 100644 --- a/test/Python/src/Microsteps.lf +++ b/test/Python/src/Microsteps.lf @@ -31,4 +31,4 @@ main reactor Microsteps { reaction(repeat) -> d.y {= d.y.set(1) =} -} \ No newline at end of file +} diff --git a/test/Python/src/Minimal.lf b/test/Python/src/Minimal.lf index 97b60de3d7..62c985ae2b 100644 --- a/test/Python/src/Minimal.lf +++ b/test/Python/src/Minimal.lf @@ -3,5 +3,5 @@ target Python; main reactor Minimal { reaction(startup) {= print("Hello World.") - =} -} \ No newline at end of file + =} +} diff --git a/test/Python/src/MovingAverage.lf b/test/Python/src/MovingAverage.lf index 38d8e3ef44..b507eb846d 100644 --- a/test/Python/src/MovingAverage.lf +++ b/test/Python/src/MovingAverage.lf @@ -22,12 +22,12 @@ reactor MovingAverageImpl { state index(0); input m_in; output out; - + reaction(m_in) -> out {= # Calculate the output. sm = m_in.value sm += sum(self.delay_line) - + out.set(sm/4.0) # Insert the input in the delay line. @@ -46,4 +46,4 @@ main reactor MovingAverage { 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; -} \ No newline at end of file +} diff --git a/test/Python/src/MultipleContained.lf b/test/Python/src/MultipleContained.lf index cc549b5be2..fdf42e54ed 100644 --- a/test/Python/src/MultipleContained.lf +++ b/test/Python/src/MultipleContained.lf @@ -35,4 +35,4 @@ main reactor MultipleContained { c.in1.set(c.trigger.value) c.in2.set(c.trigger.value) =} -} \ No newline at end of file +} diff --git a/test/Python/src/NativeListsAndTimes.lf b/test/Python/src/NativeListsAndTimes.lf index 8f88e07ac7..6fd6a8bfd3 100644 --- a/test/Python/src/NativeListsAndTimes.lf +++ b/test/Python/src/NativeListsAndTimes.lf @@ -1,11 +1,11 @@ - target Python; +target Python; // This test passes if it is successfully compiled into valid target code. -main reactor(x(0), +main reactor(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 + p(1, 2, 3, 4), // List of integers q(1 msec, 2 msec, 3 msec), // list of time values r({=0=}), // Zero-valued target code also is a valid time g(1 msec, 2 msec) // List of time values @@ -24,4 +24,4 @@ main reactor(x(0), reaction(tick) {= # Target code =} -} \ No newline at end of file +} diff --git a/test/Python/src/ParameterizedState.lf b/test/Python/src/ParameterizedState.lf index fcb5a8086e..87b285e5aa 100644 --- a/test/Python/src/ParameterizedState.lf +++ b/test/Python/src/ParameterizedState.lf @@ -9,4 +9,4 @@ reactor Foo(bar(42)) { } main reactor { a = new Foo(); -} \ No newline at end of file +} diff --git a/test/Python/src/PeriodicDesugared.lf b/test/Python/src/PeriodicDesugared.lf index 6fabc32710..4228544db9 100644 --- a/test/Python/src/PeriodicDesugared.lf +++ b/test/Python/src/PeriodicDesugared.lf @@ -4,11 +4,11 @@ target Python { }; main reactor( - offset(0), + offset(0), period(500 msec)) { logical action init(offset); logical action recur(period); - + reaction(startup) -> init, recur {= if self.offset == 0: print("Hello World!") @@ -16,7 +16,7 @@ main reactor( else: init.schedule(0) =} - + reaction(init, recur) -> recur {= print("Hello World!") recur.schedule(0) diff --git a/test/Python/src/PingPong.lf b/test/Python/src/PingPong.lf index d4c8077620..dba29d7f47 100644 --- a/test/Python/src/PingPong.lf +++ b/test/Python/src/PingPong.lf @@ -3,22 +3,22 @@ * intended to measure message-passing overhead. * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * Ping introduces a microstep delay using a logical action * to break the causality loop. - * + * * To get a sense, some (informal) results for 1,000,000 ping-pongs * on my Mac: - * + * * Unthreaded: 97 msec * Threaded: 265 msec - * + * * There is no parallelism in this application, so it does not benefit from being * being threaded, just some additional overhead. - * + * * These measurements are total execution time, including startup and shutdown. * These are about an order of magnitude faster than anything reported in the paper. - * + * * @author Edward A. Lee */ target Python { @@ -29,7 +29,7 @@ reactor Ping(count(10)) { output send; state pingsLeft(count); logical action serve; - reaction (startup, serve) -> send {= + reaction (startup, serve) -> send {= send.set(self.pingsLeft) self.pingsLeft -= 1 =} @@ -52,7 +52,7 @@ reactor Pong(expected(10)) { if self.count != self.expected: sys.stderr.write( "ERROR: Pong expected to receive {} inputs, but it received {}.\n".format( - self.expected, + self.expected, self.count ) ) @@ -65,5 +65,5 @@ main reactor PingPong { ping = new Ping(); pong = new Pong(); ping.send -> pong.receive; - pong.send -> ping.receive; -} \ No newline at end of file + pong.send -> ping.receive; +} diff --git a/test/Python/src/Pipeline.lf b/test/Python/src/Pipeline.lf index f0bb80c33d..760f1eb5d1 100644 --- a/test/Python/src/Pipeline.lf +++ b/test/Python/src/Pipeline.lf @@ -10,7 +10,7 @@ reactor TakeTime { offset = 0 for i in range(10000): offset+=1 - + out.set(_in.value + offset) =} } @@ -37,18 +37,18 @@ reactor Print { main reactor Pipeline { timer t(0, 200 msec); state count(0); - + c1 = new TakeTime(); c2 = new TakeTime(); c3 = new TakeTime(); c4 = new TakeTime(); p = new Print(); - + reaction(t) -> c1._in {= c1._in.set(self.count) - self.count += 1 + self.count += 1 =} - + c1.out -> c2._in after 200 msec; c2.out -> c3._in after 200 msec; c3.out -> c4._in after 200 msec; diff --git a/test/Python/src/Preamble.lf b/test/Python/src/Preamble.lf index 98a68b89ad..7e95efa3ca 100644 --- a/test/Python/src/Preamble.lf +++ b/test/Python/src/Preamble.lf @@ -18,4 +18,4 @@ main reactor Preamble { print("42 plus 42 is ", self.add_42(42)) print("Your platform is ", self.platform.system()) =} -} \ No newline at end of file +} diff --git a/test/Python/src/ReadOutputOfContainedReactor.lf b/test/Python/src/ReadOutputOfContainedReactor.lf index a3a884d034..c2f49112f3 100644 --- a/test/Python/src/ReadOutputOfContainedReactor.lf +++ b/test/Python/src/ReadOutputOfContainedReactor.lf @@ -39,4 +39,4 @@ main reactor ReadOutputOfContainedReactor { else: print("Test passes.") =} -} \ No newline at end of file +} diff --git a/test/Python/src/ScheduleLogicalAction.lf b/test/Python/src/ScheduleLogicalAction.lf index 34b8827c70..8b5b90237f 100644 --- a/test/Python/src/ScheduleLogicalAction.lf +++ b/test/Python/src/ScheduleLogicalAction.lf @@ -39,4 +39,4 @@ main reactor { f.x.set(42) =} f.y -> p.x; -} \ No newline at end of file +} diff --git a/test/Python/src/SendingInside.lf b/test/Python/src/SendingInside.lf index cd5b06c87e..2951b4b6e6 100644 --- a/test/Python/src/SendingInside.lf +++ b/test/Python/src/SendingInside.lf @@ -23,4 +23,4 @@ main reactor SendingInside { self.count += 1 p.x.set(self.count) =} -} \ No newline at end of file +} diff --git a/test/Python/src/SimpleDeadline.lf b/test/Python/src/SimpleDeadline.lf index 33def9391f..e82def7afe 100644 --- a/test/Python/src/SimpleDeadline.lf +++ b/test/Python/src/SimpleDeadline.lf @@ -32,4 +32,4 @@ main reactor SimpleDeadline { self.time.sleep(0.02) d.x.set(42) =} -} \ No newline at end of file +} diff --git a/test/Python/src/SimpleImport.lf b/test/Python/src/SimpleImport.lf index 4cff6c739d..89a141676a 100644 --- a/test/Python/src/SimpleImport.lf +++ b/test/Python/src/SimpleImport.lf @@ -4,4 +4,4 @@ import HelloWorld2 from "HelloWorld.lf"; main reactor SimpleImport { a = new HelloWorld2(); b = new HelloWorld2(); -} \ No newline at end of file +} diff --git a/test/Python/src/SlowingClock.lf b/test/Python/src/SlowingClock.lf index 3a1279c11c..903289ca02 100644 --- a/test/Python/src/SlowingClock.lf +++ b/test/Python/src/SlowingClock.lf @@ -30,7 +30,7 @@ main reactor SlowingClock { if self.expected_time != MSEC(1500): sys.stderr.write("ERROR: Expected the next expected time to be: 1500000000 nsec.\n") sys.stderr.write("It was: {:d} nsec.\n".format(self.expected_time)) - exit(2) + exit(2) else: print("Test passes.") =} diff --git a/test/Python/src/Stride.lf b/test/Python/src/Stride.lf index 4bb8df7414..cac64a4304 100644 --- a/test/Python/src/Stride.lf +++ b/test/Python/src/Stride.lf @@ -27,4 +27,4 @@ main reactor Stride { c = new Count(stride = 2); d = new Display(); c.y -> d.x; -} \ No newline at end of file +} diff --git a/test/Python/src/StructAsState.lf b/test/Python/src/StructAsState.lf index 363a70c70a..06e40465c5 100644 --- a/test/Python/src/StructAsState.lf +++ b/test/Python/src/StructAsState.lf @@ -5,7 +5,7 @@ main reactor StructAsState { class hello: def __init__(self, name, value): self.name = name - self.value = value + self.value = value =} state s ({=self.hello("Earth", 42) =}); reaction(startup) {= diff --git a/test/Python/src/StructAsType.lf b/test/Python/src/StructAsType.lf index 39e2398e05..1f6645e672 100644 --- a/test/Python/src/StructAsType.lf +++ b/test/Python/src/StructAsType.lf @@ -6,7 +6,7 @@ import hello reactor Source { output out; - + reaction(startup) -> out {= temp = hello.hello("Earth", 42) out.set(temp) @@ -26,4 +26,4 @@ main reactor StructAsType { s = new Source(); p = new Print(); s.out -> p._in; -} \ No newline at end of file +} diff --git a/test/Python/src/StructAsTypeDirect.lf b/test/Python/src/StructAsTypeDirect.lf index 62d8dcc33a..490ca61a6b 100644 --- a/test/Python/src/StructAsTypeDirect.lf +++ b/test/Python/src/StructAsTypeDirect.lf @@ -28,4 +28,4 @@ main reactor { s = new Source(); p = new Print(); s.out -> p._in; -} \ No newline at end of file +} diff --git a/test/Python/src/StructParallel.lf b/test/Python/src/StructParallel.lf index bad90e12ba..194f4c8b11 100644 --- a/test/Python/src/StructParallel.lf +++ b/test/Python/src/StructParallel.lf @@ -20,7 +20,7 @@ reactor Check(expected(42)) { reactor Print(scale(2)) { // Mutable keyword indicates that this reactor wants a writable copy of the input. mutable input _in; - + output out; reaction(_in) -> out {= print(_in.value.value) @@ -40,4 +40,4 @@ main reactor StructParallel { s.out -> c2._in; c1.out -> p1._in; c2.out -> p2._in; -} \ No newline at end of file +} diff --git a/test/Python/src/StructPrint.lf b/test/Python/src/StructPrint.lf index b6fb974299..3fdb642abe 100644 --- a/test/Python/src/StructPrint.lf +++ b/test/Python/src/StructPrint.lf @@ -28,4 +28,4 @@ main reactor { s = new Print(); p = new Check(); s.out -> p._in; -} \ No newline at end of file +} diff --git a/test/Python/src/StructScale.lf b/test/Python/src/StructScale.lf index 6f7de4cd25..283a8129f1 100644 --- a/test/Python/src/StructScale.lf +++ b/test/Python/src/StructScale.lf @@ -15,10 +15,10 @@ reactor Source { // expected parameter is for testing. reactor TestInput(expected(42)) { - - + + input _in; - + reaction(_in) {= print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) if _in.value.value != self.expected: @@ -30,7 +30,7 @@ reactor TestInput(expected(42)) { reactor Print(scale(2)) { // Mutable keyword indicates that this reactor wants a writable copy of the input. mutable input _in; - + output out; reaction(_in) -> out {= _in.value.value *= self.scale; @@ -44,4 +44,4 @@ main reactor StructScale { p = new TestInput(expected=84); s.out -> c._in; c.out -> p._in; -} \ No newline at end of file +} diff --git a/test/Python/src/SubclassesAndStartup.lf b/test/Python/src/SubclassesAndStartup.lf index 3178807345..f99923ae3e 100644 --- a/test/Python/src/SubclassesAndStartup.lf +++ b/test/Python/src/SubclassesAndStartup.lf @@ -34,4 +34,4 @@ reactor SubB(name("SubB")) extends Super { main reactor SubclassesAndStartup { a = new SubA(); b = new SubB(); -} +} diff --git a/test/Python/src/TestForPreviousOutput.lf b/test/Python/src/TestForPreviousOutput.lf index 58d211a1e4..149c62b992 100644 --- a/test/Python/src/TestForPreviousOutput.lf +++ b/test/Python/src/TestForPreviousOutput.lf @@ -34,4 +34,4 @@ main reactor TestForPreviousOutput { s = new Source(); d = new Sink(); s.out -> d._in; -} \ No newline at end of file +} diff --git a/test/Python/src/TimeState.lf b/test/Python/src/TimeState.lf index be60d17f18..a00c0e5095 100644 --- a/test/Python/src/TimeState.lf +++ b/test/Python/src/TimeState.lf @@ -10,4 +10,4 @@ reactor Foo(bar(42)) { main reactor { a = new Foo(); -} \ No newline at end of file +} diff --git a/test/Python/src/Timers.lf b/test/Python/src/Timers.lf index 3ff725c27d..3b4b8c0d32 100644 --- a/test/Python/src/Timers.lf +++ b/test/Python/src/Timers.lf @@ -20,4 +20,4 @@ main reactor { exit(1) print("SUCCESS.") =} -} \ No newline at end of file +} diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf index 146147762d..b30a8986ba 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent.lf @@ -14,7 +14,7 @@ reactor Source { if (self.count % 2) == 0: a.set(self.count) else: - b.set(self.count) + b.set(self.count) =} } reactor Destination { @@ -37,4 +37,4 @@ main reactor TriggerDownstreamOnlyIfPresent { d = new[2] Destination(); s.a -> d.a; s.b -> d.b; -} \ No newline at end of file +} diff --git a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf index 55a11236a1..b2c9210e41 100644 --- a/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf +++ b/test/Python/src/TriggerDownstreamOnlyIfPresent2.lf @@ -33,4 +33,4 @@ main reactor TriggerDownstreamOnlyIfPresent2 { s = new Source(); d = new[2] Destination(); s.out -> d._in; -} \ No newline at end of file +} diff --git a/test/Python/src/UnconnectedInput.lf b/test/Python/src/UnconnectedInput.lf index 20a426d249..e08ec57a2a 100644 --- a/test/Python/src/UnconnectedInput.lf +++ b/test/Python/src/UnconnectedInput.lf @@ -43,4 +43,4 @@ main reactor UnconnectedInput { print = new Print(); source.out -> add.in2; add.out -> print._in; -} \ No newline at end of file +} diff --git a/test/Python/src/Wcet.lf b/test/Python/src/Wcet.lf index d8b0e32295..7ee84f1bee 100644 --- a/test/Python/src/Wcet.lf +++ b/test/Python/src/Wcet.lf @@ -33,8 +33,8 @@ main reactor Wcet { source = new Source(); work = new Work(); print = new Print(); - + source.out1 -> work.in1; source.out2 -> work.in2; work.out -> print.p_in; -} \ No newline at end of file +} diff --git a/test/Python/src/concurrent/AsyncCallback.lf b/test/Python/src/concurrent/AsyncCallback.lf index f346e1c35e..dcf9925d7c 100644 --- a/test/Python/src/concurrent/AsyncCallback.lf +++ b/test/Python/src/concurrent/AsyncCallback.lf @@ -34,7 +34,7 @@ main reactor AsyncCallback { state threads({=list()=}); state expected_time(100 msec); state toggle(false); - + physical action a(100 msec); state i(0); @@ -48,7 +48,7 @@ main reactor AsyncCallback { reaction(a) {= elapsed_time = lf.time.logical_elapsed() print("Asynchronous callback {:d}: Assigned logical time greater than start time by {:d} nsec.".format(self.i, elapsed_time)); - self.i += 1 + self.i += 1 if elapsed_time <= self.expected_time: sys.stderr.write("ERROR: Expected logical time to be larger than {:d}.".format(self.expected_time)); exit(1) diff --git a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf index 1bc62c9b01..83b1933d39 100644 --- a/test/Python/src/concurrent/AsyncCallbackNoTimer.lf +++ b/test/Python/src/concurrent/AsyncCallbackNoTimer.lf @@ -1,12 +1,12 @@ /** * Test asynchronous callbacks that trigger a physical action. - * This test creates a concurrent Python thread that schedule a - * physical action twice. - * - * There are no timers in this test to drive the logical time forward. - * This is important in the Python target since the user Python threads - * should be allowed to execute independently of the underlying C core - * runtime, without the C runtime polling the Python context with a + * This test creates a concurrent Python thread that schedule a + * physical action twice. + * + * There are no timers in this test to drive the logical time forward. + * This is important in the Python target since the user Python threads + * should be allowed to execute independently of the underlying C core + * runtime, without the C runtime polling the Python context with a * reaction to a timer. */ target Python { @@ -14,7 +14,7 @@ target Python { }; main reactor { - + preamble {= # Note that preamble code is generated inside the reactor class in Python import time @@ -35,27 +35,27 @@ main reactor { self.time.sleep(0.1) self.callback(a) return None - + =} - + state threads({=list()=}); state expected_time(100 msec); state toggle(false); - + physical action a(100 msec); state i(0); - + reaction(startup) -> a {= # start new thread, provide callback x = self.threading.Thread(target=self.take_time, args=(a,)) self.threads.append(x) x.start() =} - + reaction(a) {= elapsed_time = lf.time.logical_elapsed() print("Asynchronous callback {:d}: Assigned logical time greater than start time by {:d} nsec.".format(self.i, elapsed_time)); - self.i += 1 + self.i += 1 if elapsed_time <= self.expected_time: sys.stderr.write("ERROR: Expected logical time to be larger than {:d}.".format(self.expected_time)); exit(1) @@ -65,4 +65,4 @@ main reactor { else: self.toggle = True =} -} \ No newline at end of file +} diff --git a/test/Python/src/docker/FilesPropertyContainerized.lf b/test/Python/src/docker/FilesPropertyContainerized.lf index 8d166c53ed..7a62a4e4e1 100644 --- a/test/Python/src/docker/FilesPropertyContainerized.lf +++ b/test/Python/src/docker/FilesPropertyContainerized.lf @@ -19,7 +19,7 @@ main reactor { =} state passed(false); timer t(1 msec); - + reaction(t) {= self.passed = True =} @@ -31,4 +31,4 @@ main reactor { else: print("PASSED") =} -} \ No newline at end of file +} diff --git a/test/Python/src/docker/HelloWorldContainerized.lf b/test/Python/src/docker/HelloWorldContainerized.lf index e99e80989b..20de3fe77e 100644 --- a/test/Python/src/docker/HelloWorldContainerized.lf +++ b/test/Python/src/docker/HelloWorldContainerized.lf @@ -6,4 +6,4 @@ import HelloWorld2 from "../HelloWorld.lf" main reactor { a = new HelloWorld2(); -} \ No newline at end of file +} diff --git a/test/Python/src/docker/PingPongContainerized.lf b/test/Python/src/docker/PingPongContainerized.lf index bbc85a3d1a..3f2a6a8c06 100644 --- a/test/Python/src/docker/PingPongContainerized.lf +++ b/test/Python/src/docker/PingPongContainerized.lf @@ -3,22 +3,22 @@ * intended to measure message-passing overhead. * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * Ping introduces a microstep delay using a logical action * to break the causality loop. - * + * * To get a sense, some (informal) results for 1,000,000 ping-pongs * on my Mac: - * + * * Unthreaded: 97 msec * Threaded: 265 msec - * + * * There is no parallelism in this application, so it does not benefit from being * being threaded, just some additional overhead. - * + * * These measurements are total execution time, including startup and shutdown. * These are about an order of magnitude faster than anything reported in the paper. - * + * * @author Edward A. Lee */ target Python { @@ -34,5 +34,5 @@ main reactor PingPongContainerized { ping = new Ping(); pong = new Pong(); ping.send -> pong.receive; - pong.send -> ping.receive; -} \ No newline at end of file + pong.send -> ping.receive; +} diff --git a/test/Python/src/docker/federated/DistributedCountContainerized.lf b/test/Python/src/docker/federated/DistributedCountContainerized.lf index 0104aa0efa..4b4b8d11b9 100644 --- a/test/Python/src/docker/federated/DistributedCountContainerized.lf +++ b/test/Python/src/docker/federated/DistributedCountContainerized.lf @@ -2,7 +2,7 @@ * where a federation that receives timestamped messages has only those * messages as triggers. Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * @author Edward A. Lee + * @author Edward A. Lee */ target Python { timeout: 5 sec, @@ -14,7 +14,7 @@ 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/docker/federated/DistributedDoublePortContainerized.lf b/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf index 451a5286db..f45e86d67f 100644 --- a/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf +++ b/test/Python/src/docker/federated/DistributedDoublePortContainerized.lf @@ -1,10 +1,10 @@ -/** +/** * Test the case for when two upstream federates * send messages to a downstream federte on two - * different ports. One message should carry a + * different ports. One message should carry a * microstep delay relative to the other * message. - * + * * @author Soroush Bateni */ target Python { diff --git a/test/Python/src/docker/federated/DistributedMultiportContainerized.lf b/test/Python/src/docker/federated/DistributedMultiportContainerized.lf index e6297c7744..e70898ed77 100644 --- a/test/Python/src/docker/federated/DistributedMultiportContainerized.lf +++ b/test/Python/src/docker/federated/DistributedMultiportContainerized.lf @@ -11,4 +11,4 @@ federated reactor DistributedMultiportContainerized at rti { s = new Source(); d = new Destination(); s.out -> d.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf index 47eaca20ef..40d550b83d 100644 --- a/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf +++ b/test/Python/src/docker/federated/DistributedStopDecentralizedContainerized.lf @@ -1,17 +1,17 @@ - /** - * Test for request_stop() in federated execution with decentralized coordination. - * - * @author Soroush Bateni - */ -target Python { - coordination: decentralized, - docker: true -}; - -import Sender, Receiver from "../../federated/DistributedStop.lf" - -federated reactor DistributedStopDecentralizedContainerized at rti { - sender = new Sender(); - receiver = new Receiver(); - sender.out -> receiver.in_; -} \ No newline at end of file +/** + * Test for request_stop() in federated execution with decentralized coordination. + * + * @author Soroush Bateni + */ +target Python { + coordination: decentralized, + docker: true +}; + +import Sender, Receiver from "../../federated/DistributedStop.lf" + +federated reactor DistributedStopDecentralizedContainerized at rti { + sender = new Sender(); + receiver = new Receiver(); + sender.out -> receiver.in_; +} diff --git a/test/Python/src/federated/BroadcastFeedback.lf b/test/Python/src/federated/BroadcastFeedback.lf index b5fe4d230d..935a9bf03f 100644 --- a/test/Python/src/federated/BroadcastFeedback.lf +++ b/test/Python/src/federated/BroadcastFeedback.lf @@ -8,7 +8,7 @@ reactor SenderAndReceiver { output out; input[2] inp; 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 b28e42b5a9..999a607830 100644 --- a/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf +++ b/test/Python/src/federated/BroadcastFeedbackWithHierarchy.lf @@ -8,11 +8,11 @@ reactor SenderAndReceiver { output out; input[2] in_; state received(False); - + reaction(startup) -> out {= out.set(42) =} - + r = new Receiver(); in_ -> r.in_; } @@ -22,7 +22,7 @@ reactor Receiver { =} input[2] in_; 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: print("SUCCESS") diff --git a/test/Python/src/federated/ChainWithDelay.lf b/test/Python/src/federated/ChainWithDelay.lf index 187fc7cf32..e8c253bf62 100644 --- a/test/Python/src/federated/ChainWithDelay.lf +++ b/test/Python/src/federated/ChainWithDelay.lf @@ -1,6 +1,6 @@ /** * Demonstration that monotonic NET hypothesis is invalid. - * + * * @author Edward A. Lee */ target Python { diff --git a/test/Python/src/federated/CycleDetection.lf b/test/Python/src/federated/CycleDetection.lf index c5768e960f..4e4fd20998 100644 --- a/test/Python/src/federated/CycleDetection.lf +++ b/test/Python/src/federated/CycleDetection.lf @@ -9,18 +9,18 @@ reactor CAReplica { input local_update; input remote_update; input query; - + state balance(0); output response; - + reaction(local_update, remote_update) {= if local_update.is_present: self.balance += local_update.value if remote_update.is_present: self.balance += remote_update.value =} - + reaction(query) -> response {= response.set(self.balance) =} @@ -31,18 +31,18 @@ reactor UserInput { =} input balance; output deposit; - + reaction(startup) -> deposit {= deposit.set(100) =} reaction(balance) {= if balance.value != 200: - self.sys.stderr.write("Did not receive the expected balance. Expected: 200. Got: {}.\n".format(balance.value)) + self.sys.stderr.write("Did not receive the expected balance. Expected: 200. Got: {}.\n".format(balance.value)) self.sys.exit(1) print("Balance: {}".format(balance.value)) request_stop() =} - + reaction(shutdown) {= print("Test passed!") =} @@ -60,4 +60,4 @@ federated reactor { (u2.deposit)+ -> r2.query, r2.local_update; r2.response -> u2.balance; u2.deposit -> r1.remote_update; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf index 894d84b3f6..1e359bdd97 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeout.lf @@ -2,8 +2,8 @@ * Test a source-destination scenario where the source falls behind real-time, and reaches the * timeout much later than the destination. In this test, the destination closes the connection * early, causing the transmission to fail. Warnings will be printed about lost messages. - * - * The test fails if the federation does not exit. + * + * The test fails if the federation does not exit. */ target Python { timeout: 1 msec, @@ -32,11 +32,11 @@ reactor Destination { input x; state s(1); state startup_logical_time; - + reaction(startup) {= - self.startup_logical_time = lf.time.logical() + self.startup_logical_time = lf.time.logical() =} - + reaction(x) {= print("Received {}".format(x.value)) current_tag = get_current_tag() @@ -46,7 +46,7 @@ reactor Destination { self.sys.exit(1) self.s += 1 =} - + reaction(shutdown) {= print("**** shutdown reaction invoked.") print("Approx. time per reaction: {}ns".format(lf.time.physical_elapsed()//(self.s+1))) @@ -56,4 +56,4 @@ federated reactor (period(10 usec)) { c = new Clock(period = period); d = new Destination(); c.y -> d.x; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf index e08dcdd247..fd5d7e6f42 100644 --- a/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf +++ b/test/Python/src/federated/DecentralizedP2PUnbalancedTimeoutPhysical.lf @@ -2,9 +2,9 @@ * Test a source-destination scenario where the source falls behind real-time, and reaches the * timeout much later than the destination. In this test, the destination closes the connection * early, causing the transmission to fail. Warnings will be printed. - * + * * The test fails if the federation does not exit amenably. - * This variant has a physical connection between source and destination. + * This variant has a physical connection between source and destination. */ target Python { timeout: 1 msec, @@ -44,4 +44,4 @@ federated reactor (period(10 usec)) { c = new Clock(period = period); d = new Destination(); c.y ~> d.x; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DistributedBank.lf b/test/Python/src/federated/DistributedBank.lf index fecc4dea09..8beda9ca85 100644 --- a/test/Python/src/federated/DistributedBank.lf +++ b/test/Python/src/federated/DistributedBank.lf @@ -16,11 +16,11 @@ reactor Node { =} reaction(shutdown) {= if self.count == 0: - self.sys.stderr.write("Timer reactions did not execute.\n") + self.sys.stderr.write("Timer reactions did not execute.\n") self.sys.exit(1) =} } federated reactor DistributedBank { n = new[2] Node(); -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DistributedBankToMultiport.lf b/test/Python/src/federated/DistributedBankToMultiport.lf index b684973fb4..0c6f8a0128 100644 --- a/test/Python/src/federated/DistributedBankToMultiport.lf +++ b/test/Python/src/federated/DistributedBankToMultiport.lf @@ -4,7 +4,7 @@ target Python { }; import Count from "../lib/Count.lf"; - + reactor Destination { preamble {= import sys @@ -13,15 +13,15 @@ reactor Destination { state count(1); reaction(in_) {= for i in range(len(in_)): - print("Received {}.".format(in_[i].value)) + print("Received {}.".format(in_[i].value)) if self.count != in_[i].value: - self.sys.stderr.write("Expected {}.\n".format(self.count)) + self.sys.stderr.write("Expected {}.\n".format(self.count)) self.sys.exit(1) self.count += 1 =} reaction(shutdown) {= if self.count == 0: - self.sys.stderr.write("No data received.\n") + self.sys.stderr.write("No data received.\n") self.sys.exit(1) =} } @@ -30,4 +30,4 @@ federated reactor { s = new[2] Count(); d = new Destination(); s.out -> d.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DistributedCount.lf b/test/Python/src/federated/DistributedCount.lf index 71c43eb8c6..d3551994cf 100644 --- a/test/Python/src/federated/DistributedCount.lf +++ b/test/Python/src/federated/DistributedCount.lf @@ -2,7 +2,7 @@ * where a federation that receives timestamped messages has only those * messages as triggers. Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * @author Edward A. Lee + * @author Edward A. Lee */ target Python { timeout: 5 sec, @@ -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/DistributedCountPhysical.lf b/test/Python/src/federated/DistributedCountPhysical.lf index 1855b48ee8..8c0d384e1d 100644 --- a/test/Python/src/federated/DistributedCountPhysical.lf +++ b/test/Python/src/federated/DistributedCountPhysical.lf @@ -1,10 +1,10 @@ -/** +/** * Test a particularly simple form of a distributed deterministic system * where a federation that receives timestamped messages only over connections * that are marked 'physical' (using the ~> arrow). * Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * + * * @author Edward A. Lee * @author Soroush Bateni */ @@ -30,7 +30,7 @@ reactor Print { elapsed_time = lf.time.logical_elapsed() print("At time {}, received {}.".format(elapsed_time, in_.value)) if in_.value != self.c: - self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) + self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) self.sys.exit(1) if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}. Got {}.\n".format(MSEC(200) * self.c, elapsed_time)) diff --git a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf index e1dad56b42..712515de24 100644 --- a/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/Python/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -1,10 +1,10 @@ -/** +/** * Test a particularly simple form of a distributed deterministic system * where a federation that receives timestamped messages only over connections * that are marked 'physical' (using the ~> arrow). * Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * + * * @author Edward A. Lee * @author Soroush Bateni */ @@ -30,7 +30,7 @@ reactor Print { elapsed_time = lf.time.logical_elapsed() print("At time {}, received {}.".format(elapsed_time, in_.value)) if in_.value != self.c: - self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) + self.sys.stderr.write("ERROR: Expected to receive {}.\n".format(self.c)) self.sys.exit(1) if not (elapsed_time > (SEC(1) * self.c) + MSEC(200)): self.sys.stderr.write("ERROR: Expected received time to be strictly greater than {}. Got {}.\n".format(MSEC(200) * self.c, elapsed_time)) diff --git a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf index 03dcfc8ea4..f78bc68366 100644 --- a/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf +++ b/test/Python/src/federated/DistributedCountPhysicalDecentralized.lf @@ -1,10 +1,10 @@ -/** +/** * Test a particularly simple form of a distributed deterministic system * where a federation that receives timestamped messages only over connections * that are marked 'physical' (using the ~> arrow). * Therefore, no additional coordination of the * advancement of time (HLA or Ptides) is needed. - * + * * @author Edward A. Lee * @author Soroush Bateni */ diff --git a/test/Python/src/federated/DistributedDoublePort.lf b/test/Python/src/federated/DistributedDoublePort.lf index 87e2a15fbc..0834edf343 100644 --- a/test/Python/src/federated/DistributedDoublePort.lf +++ b/test/Python/src/federated/DistributedDoublePort.lf @@ -1,13 +1,13 @@ -/** +/** * Test the case for when two upstream federates * send messages to a downstream federte on two - * different ports. One message should carry a + * different ports. One message should carry a * microstep delay relative to the other * message. - * + * * @author Soroush Bateni */ - + target Python { timeout: 900 msec, @@ -26,7 +26,7 @@ reactor CountMicrostep { act.schedule(0, self.count) self.count += 1 =} - + reaction(act) -> out {= out.set(act.value) =} @@ -45,7 +45,7 @@ reactor Print { self.sys.stderr.write("ERROR: invalid logical simultaneity.") self.sys.exit(1) =} - + reaction(shutdown) {= print("SUCCESS: messages were at least one microstep apart.") =} diff --git a/test/Python/src/federated/DistributedLoopedAction.lf b/test/Python/src/federated/DistributedLoopedAction.lf index cd3330845d..2a3ecc62ea 100644 --- a/test/Python/src/federated/DistributedLoopedAction.lf +++ b/test/Python/src/federated/DistributedLoopedAction.lf @@ -1,7 +1,7 @@ /** * Test a sender-receiver network system that * relies on microsteps being taken into account. - * + * * @author Soroush Bateni */ @@ -44,11 +44,11 @@ reactor Receiver(take_a_break_after(10), break_interval(400 msec)) { self.breaks += 1 self.received_messages = 0 =} - + reaction(t) {= # Do nothing =} - + reaction(shutdown) {= print(((SEC(1)/self.break_interval)+1) * self.take_a_break_after) if self.breaks != 3 or (self.total_received_messages != ((SEC(1)//self.break_interval)+1) * self.take_a_break_after): @@ -62,6 +62,6 @@ reactor Receiver(take_a_break_after(10), break_interval(400 msec)) { federated reactor DistributedLoopedAction { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in_; } diff --git a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf index 272047184d..8268fa29b3 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalAction.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalAction.lf @@ -7,7 +7,7 @@ * sent to the RTI (a form of null message that must be sent because of the * physical action). The presence of this option also silences a warning * about having a physical action that triggers an output. - * + * * @author Soroush Bateni */ @@ -35,7 +35,7 @@ reactor Sender(take_a_break_after(10), break_interval(550 msec)) { reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { preamble {= - import sys + import sys =} input in_; state received_messages(0); @@ -51,7 +51,7 @@ reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { =} reaction(in_) {= - current_tag = get_current_tag() + current_tag = get_current_tag() print("At tag ({}, {}) received {}".format( current_tag.time - self.base_logical_time, current_tag.microstep, @@ -84,6 +84,6 @@ reactor Receiver(take_a_break_after(10), break_interval(550 msec)) { federated reactor DistributedLoopedPhysicalAction { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in_; } diff --git a/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf b/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf index 00aede077d..a3789858fd 100644 --- a/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf +++ b/test/Python/src/federated/DistributedLoopedPhysicalActionDecentralized.lf @@ -1,7 +1,7 @@ /** * Test a sender-receiver network system that * relies on microsteps being taken into account. - * + * * @author Soroush Bateni */ @@ -16,6 +16,6 @@ import Sender, Receiver from "DistributedLoopedPhysicalAction.lf" federated reactor { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in_; } diff --git a/test/Python/src/federated/DistributedMultiport.lf b/test/Python/src/federated/DistributedMultiport.lf index 7b98f291f2..33087190f4 100644 --- a/test/Python/src/federated/DistributedMultiport.lf +++ b/test/Python/src/federated/DistributedMultiport.lf @@ -41,4 +41,4 @@ federated reactor DistributedMultiport { s = new Source(); d = new Destination(); s.out -> d.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DistributedMultiportToBank.lf b/test/Python/src/federated/DistributedMultiportToBank.lf index 5aab4cf758..345e6c351f 100644 --- a/test/Python/src/federated/DistributedMultiportToBank.lf +++ b/test/Python/src/federated/DistributedMultiportToBank.lf @@ -13,7 +13,7 @@ reactor Source { self.count += 1 =} } - + reactor Destination { preamble {= import sys @@ -21,7 +21,7 @@ reactor Destination { input in_; state count(0); reaction(in_) {= - print("Received {}.".format(in_.value)) + print("Received {}.".format(in_.value)) if self.count != in_.value: self.sys.stderr.write("Expected {}.\n".format(self.count)) self.sys.exit(1) @@ -38,4 +38,4 @@ federated reactor DistributedMultiportToBank { s = new Source(); d = new[2] Destination(); s.out -> d.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DistributedMultiportToken.lf b/test/Python/src/federated/DistributedMultiportToken.lf index caeff915ba..fca194f4a3 100644 --- a/test/Python/src/federated/DistributedMultiportToken.lf +++ b/test/Python/src/federated/DistributedMultiportToken.lf @@ -26,7 +26,7 @@ reactor Destination { reaction(in_) {= for i in range(len(in_)): if in_[i].is_present: - print("Received {}.".format(in_[i].value)) + print("Received {}.".format(in_[i].value)) =} } @@ -34,4 +34,4 @@ federated reactor DistributedMultiportToken { s = new Source(); d = new Destination(); s.out -> d.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index beaa07b7fc..516298a336 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -1,113 +1,113 @@ -/** -* Test for request_stop() in federated execution with centralized coordination. -* -* @author Soroush Bateni -*/ - -target Python; - -preamble {= - import sys -=} - -reactor Sender { - output out; - timer t(0, 1 usec); - logical action act; - state reaction_invoked_correctly(False); - reaction(t, act) -> out, act {= - print("Sending 42 at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - out.set(42) - if get_microstep() == 0: - # Instead of having a separate reaction - # for 'act' like Stop.lf, we trigger the - # same reaction to test request_stop() being - # called multiple times - act.schedule(0) - if lf.time.logical_elapsed() == USEC(1): - # Call request_stop() both at (1 usec, 0) and - # (1 usec, 1) - print("Requesting stop at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - request_stop() - - _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) - if lf.tag_compare(get_current_tag(), _1usec1) == 0: - # The reaction was invoked at (1 usec, 1) as expected - self.reaction_invoked_correctly = True - elif lf.tag_compare(get_current_tag(), _1usec1) > 0: - # The reaction should not have been invoked at tags larger than (1 usec, 1) - sys.stderr.write("ERROR: Invoked reaction(t, act) at tag bigger than shutdown.\n") - sys.exit(1) - =} - - reaction(shutdown) {= - if lf.time.logical_elapsed() != USEC(1) or get_microstep() != 1: - sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - get_microstep())) - sys.exit(1) - elif not self.reaction_invoked_correctly: - sys.stderr.write("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - get_microstep())) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - =} -} - -reactor Receiver ( - stp_offset(10 msec) // Used in the decentralized variant of the test -) { - input in_; - state reaction_invoked_correctly(False) - reaction(in_) {= - print("Received {} at ({}, {}).".format( - in_.value, - lf.time.logical_elapsed(), - get_microstep())) - if lf.time.logical_elapsed() == USEC(1): - print("Requesting stop at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - request_stop() - # The receiver should receive a message at tag - # (1 usec, 1) and trigger this reaction - self.reaction_invoked_correctly = True - - _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) - if lf.tag_compare(get_current_tag(), _1usec1) > 0: - self.reaction_invoked_correctly = False - =} - - reaction(shutdown) {= - # Sender should have requested stop earlier than the receiver. - # Therefore, the shutdown events must occur at (1000, 0) on the - # receiver. - if lf.time.logical_elapsed() != USEC(1) or get_microstep() != 1: - sys.stderr.write("Error: Receiver failed to stop the federation at the right time. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - get_microstep())) - sys.exit(1) - elif not self.reaction_invoked_correctly: - sys.stderr.write("Error: Receiver reaction(in) was not invoked the correct number of times. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - get_microstep())) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - =} -} - -federated reactor DistributedStop { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in_; -} +/** +* Test for request_stop() in federated execution with centralized coordination. +* +* @author Soroush Bateni +*/ + +target Python; + +preamble {= + import sys +=} + +reactor Sender { + output out; + timer t(0, 1 usec); + logical action act; + state reaction_invoked_correctly(False); + reaction(t, act) -> out, act {= + print("Sending 42 at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + out.set(42) + if get_microstep() == 0: + # Instead of having a separate reaction + # for 'act' like Stop.lf, we trigger the + # same reaction to test request_stop() being + # called multiple times + act.schedule(0) + if lf.time.logical_elapsed() == USEC(1): + # Call request_stop() both at (1 usec, 0) and + # (1 usec, 1) + print("Requesting stop at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + request_stop() + + _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) + if lf.tag_compare(get_current_tag(), _1usec1) == 0: + # The reaction was invoked at (1 usec, 1) as expected + self.reaction_invoked_correctly = True + elif lf.tag_compare(get_current_tag(), _1usec1) > 0: + # The reaction should not have been invoked at tags larger than (1 usec, 1) + sys.stderr.write("ERROR: Invoked reaction(t, act) at tag bigger than shutdown.\n") + sys.exit(1) + =} + + reaction(shutdown) {= + if lf.time.logical_elapsed() != USEC(1) or get_microstep() != 1: + sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + get_microstep())) + sys.exit(1) + elif not self.reaction_invoked_correctly: + sys.stderr.write("ERROR: Sender reaction(t, act) was not invoked at (1 usec, 1). Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + get_microstep())) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + =} +} + +reactor Receiver ( + stp_offset(10 msec) // Used in the decentralized variant of the test +) { + input in_; + state reaction_invoked_correctly(False) + reaction(in_) {= + print("Received {} at ({}, {}).".format( + in_.value, + lf.time.logical_elapsed(), + get_microstep())) + if lf.time.logical_elapsed() == USEC(1): + print("Requesting stop at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + request_stop() + # The receiver should receive a message at tag + # (1 usec, 1) and trigger this reaction + self.reaction_invoked_correctly = True + + _1usec1 = Tag(time=USEC(1) + get_start_time(), microstep=1) + if lf.tag_compare(get_current_tag(), _1usec1) > 0: + self.reaction_invoked_correctly = False + =} + + reaction(shutdown) {= + # Sender should have requested stop earlier than the receiver. + # Therefore, the shutdown events must occur at (1000, 0) on the + # receiver. + if lf.time.logical_elapsed() != USEC(1) or get_microstep() != 1: + sys.stderr.write("Error: Receiver failed to stop the federation at the right time. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + get_microstep())) + sys.exit(1) + elif not self.reaction_invoked_correctly: + sys.stderr.write("Error: Receiver reaction(in) was not invoked the correct number of times. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + get_microstep())) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + =} +} + +federated reactor DistributedStop { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in_; +} diff --git a/test/Python/src/federated/DistributedStopDecentralized.lf b/test/Python/src/federated/DistributedStopDecentralized.lf index 1294b8fa5d..913948765e 100644 --- a/test/Python/src/federated/DistributedStopDecentralized.lf +++ b/test/Python/src/federated/DistributedStopDecentralized.lf @@ -1,20 +1,20 @@ - /** - * Test for request_stop() in federated execution with decentralized coordination. - * - * @author Soroush Bateni - */ - - // reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target - -target Python { - coordination: decentralized -}; - -import Sender, Receiver from "DistributedStop.lf" - -federated reactor DistributedStopDecentralized { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in_; -} \ No newline at end of file +/** + * Test for request_stop() in federated execution with decentralized coordination. + * + * @author Soroush Bateni + */ + + // reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target + +target Python { + coordination: decentralized +}; + +import Sender, Receiver from "DistributedStop.lf" + +federated reactor DistributedStopDecentralized { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in_; +} diff --git a/test/Python/src/federated/DistributedStopZero.lf b/test/Python/src/federated/DistributedStopZero.lf index d37e1cf5a9..58b4cb4f93 100644 --- a/test/Python/src/federated/DistributedStopZero.lf +++ b/test/Python/src/federated/DistributedStopZero.lf @@ -1,91 +1,91 @@ -/** - * Test for request_stop() in federated execution with centralized coordination - * at tag (0,0). - * - * @author Soroush Bateni - */ - - // reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target - -target Python; - -preamble {= - import sys -=} - -reactor Sender { - output out; - timer t(0, 1 usec); - state startup_logical_time; - - reaction(startup) {= - self.startup_logical_time = lf.time.logical() - =} - reaction(t) -> out{= - print("Sending 42 at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - out.set(42) - zero = Tag(time=self.startup_logical_time, microstep=0) - if lf.tag_compare(get_current_tag(), zero) == 0: - # Request stop at (0,0) - print("Requesting stop at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - request_stop() - =} - - reaction(shutdown) {= - if lf.time.logical_elapsed() != USEC(0) or get_microstep() != 1: - sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - get_microstep())) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - =} -} - -reactor Receiver { - input in_; - state startup_logical_time; - - reaction(startup) {= - self.startup_logical_time = lf.time.logical() - =} - reaction(in_) {= - print("Received {} at ({}, {}).\n".format( - in_.value, - lf.time.logical_elapsed(), - get_microstep())) - zero = Tag(time=self.startup_logical_time, microstep=0) - if lf.tag_compare(get_current_tag(), zero) == 0: - # Request stop at (0,0) - print("Requesting stop at ({}, {}).".format( - lf.time.logical_elapsed(), - get_microstep())) - request_stop() - =} - - reaction(shutdown) {= - # Sender should have requested stop earlier than the receiver. - # Therefore, the shutdown events must occur at (1000, 0) on the - # receiver. - if lf.time.logical_elapsed() != USEC(0) or get_microstep() != 1: - sys.stderr.write("ERROR: Receiver failed to stop the federation in time. Stopping at ({}, {}).\n".format( - lf.time.logical_elapsed(), - get_microstep())) - sys.exit(1) - print("SUCCESS: Successfully stopped the federation at ({}, {}).\n".format( - lf.time.logical_elapsed(), - get_microstep())) - =} -} - -federated reactor { - sender = new Sender(); - receiver = new Receiver(); - - sender.out -> receiver.in_; -} \ No newline at end of file +/** + * Test for request_stop() in federated execution with centralized coordination + * at tag (0,0). + * + * @author Soroush Bateni + */ + + // reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target + +target Python; + +preamble {= + import sys +=} + +reactor Sender { + output out; + timer t(0, 1 usec); + state startup_logical_time; + + reaction(startup) {= + self.startup_logical_time = lf.time.logical() + =} + reaction(t) -> out{= + print("Sending 42 at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + out.set(42) + zero = Tag(time=self.startup_logical_time, microstep=0) + if lf.tag_compare(get_current_tag(), zero) == 0: + # Request stop at (0,0) + print("Requesting stop at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + request_stop() + =} + + reaction(shutdown) {= + if lf.time.logical_elapsed() != USEC(0) or get_microstep() != 1: + sys.stderr.write("ERROR: Sender failed to stop the federation in time. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + get_microstep())) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + =} +} + +reactor Receiver { + input in_; + state startup_logical_time; + + reaction(startup) {= + self.startup_logical_time = lf.time.logical() + =} + reaction(in_) {= + print("Received {} at ({}, {}).\n".format( + in_.value, + lf.time.logical_elapsed(), + get_microstep())) + zero = Tag(time=self.startup_logical_time, microstep=0) + if lf.tag_compare(get_current_tag(), zero) == 0: + # Request stop at (0,0) + print("Requesting stop at ({}, {}).".format( + lf.time.logical_elapsed(), + get_microstep())) + request_stop() + =} + + reaction(shutdown) {= + # Sender should have requested stop earlier than the receiver. + # Therefore, the shutdown events must occur at (1000, 0) on the + # receiver. + if lf.time.logical_elapsed() != USEC(0) or get_microstep() != 1: + sys.stderr.write("ERROR: Receiver failed to stop the federation in time. Stopping at ({}, {}).\n".format( + lf.time.logical_elapsed(), + get_microstep())) + sys.exit(1) + print("SUCCESS: Successfully stopped the federation at ({}, {}).\n".format( + lf.time.logical_elapsed(), + get_microstep())) + =} +} + +federated reactor { + sender = new Sender(); + receiver = new Receiver(); + + sender.out -> receiver.in_; +} diff --git a/test/Python/src/federated/ParallelDestinations.lf b/test/Python/src/federated/ParallelDestinations.lf index 413b281eb0..9dec420180 100644 --- a/test/Python/src/federated/ParallelDestinations.lf +++ b/test/Python/src/federated/ParallelDestinations.lf @@ -12,7 +12,7 @@ reactor Source { output[2] out; c1 = new Count(); c2 = new Count(); - + c1.out, c2.out -> out; } @@ -20,6 +20,6 @@ federated reactor { s = new Source(); t1 = new TestCount(num_inputs = 3); t2 = new TestCount(num_inputs = 3); - + s.out -> t1.in_, t2.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/ParallelSources.lf b/test/Python/src/federated/ParallelSources.lf index 983a04328f..3a81927f87 100644 --- a/test/Python/src/federated/ParallelSources.lf +++ b/test/Python/src/federated/ParallelSources.lf @@ -13,7 +13,7 @@ reactor Destination { t1 = new TestCount(num_inputs = 3); t2 = new TestCount(num_inputs = 3); - + in_ -> t1.in_, t2.in_; } @@ -21,6 +21,6 @@ federated reactor { c1 = new Count(); c2 = new Count(); d = new Destination(); - + c1.out, c2.out -> d.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/ParallelSourcesMultiport.lf b/test/Python/src/federated/ParallelSourcesMultiport.lf index deec689643..ba84a3ef9b 100644 --- a/test/Python/src/federated/ParallelSourcesMultiport.lf +++ b/test/Python/src/federated/ParallelSourcesMultiport.lf @@ -12,7 +12,7 @@ reactor Source { output[2] out; c1 = new Count(); c2 = new Count(); - + c1.out, c2.out -> out; } @@ -22,7 +22,7 @@ reactor Destination1 { t1 = new TestCount(num_inputs = 3); t2 = new TestCount(num_inputs = 3); t3 = new TestCount(num_inputs = 3); - + in_ -> t1.in_, t2.in_, t3.in_; } @@ -31,6 +31,6 @@ federated reactor { s2 = new Source(); d1 = new Destination1(); t4 = new TestCount(num_inputs = 3); - + s1.out, s2.out -> d1.in_, t4.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/PingPongDistributed.lf b/test/Python/src/federated/PingPongDistributed.lf index b647f378ff..e8f9771296 100644 --- a/test/Python/src/federated/PingPongDistributed.lf +++ b/test/Python/src/federated/PingPongDistributed.lf @@ -1,25 +1,25 @@ - /** +/** * Basic benchmark from the Savina benchmark suite that is * intended to measure message-passing overhead. * This is based on https://www.scala-lang.org/old/node/54 * See https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * + * * This is a distributed version, where Ping and Pong run in * separate programs and can be run on different machines. - * + * * To get a sense, some (informal) results for 1,000,000 ping-pongs * on my Mac: - * + * * Unthreaded: 97 msec * Threaded: 265 msec * Distributed: 53 seconds - * + * * There is no parallelism in this application, so it does not benefit from being * being distributed. - * + * * These measurements are total execution time, including startup and shutdown, of * all three programs. - * + * * @author Edward A. Lee */ target Python; @@ -40,12 +40,12 @@ reactor Ping(count(10)) { else: request_stop() =} -} +} reactor Pong(expected(10)) { preamble {= import sys =} - + input receive; output send; state count(0); @@ -67,5 +67,5 @@ federated reactor (count(10)) { ping = new Ping(count = count); pong = new Pong(expected = count); ping.send ~> pong.receive; - pong.send ~> ping.receive; + pong.send ~> ping.receive; } diff --git a/test/Python/src/federated/StopAtShutdown.lf b/test/Python/src/federated/StopAtShutdown.lf index 6da7060e0c..a6464a6f69 100644 --- a/test/Python/src/federated/StopAtShutdown.lf +++ b/test/Python/src/federated/StopAtShutdown.lf @@ -1,9 +1,9 @@ /** - * Check that request_stop() doesn't cause + * Check that request_stop() doesn't cause * any issues at the shutdown tag. - * + * * Original bug discovered by Steven Wong - * + * * @author Steven Wong */ target Python { @@ -15,11 +15,11 @@ reactor A { reaction(startup) {= print("Hello World!") =} - + reaction(in_) {= print("Got it") =} - + reaction(shutdown) {= request_stop() =} @@ -40,4 +40,4 @@ federated reactor { a = new A(); b = new B(); b.out -> a.in_; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/failing/ClockSync.lf b/test/Python/src/federated/failing/ClockSync.lf index a74faa5ed9..e8c91eb468 100644 --- a/test/Python/src/federated/failing/ClockSync.lf +++ b/test/Python/src/federated/failing/ClockSync.lf @@ -7,10 +7,10 @@ * is quite high, so failures should be rare. * @author Edward A. Lee */ - + // reason for failing: clock-sync and clock-sync-options not supported in the python target - - + + target Python { coordination: decentralized, timeout: 10 sec, @@ -32,11 +32,11 @@ target Python { /** * Reactor that outputs periodically. */ -reactor Ticker(period:time(1600 msec)) { +reactor Ticker(period:time(1600 msec)) { output out:int; - + timer tick(0, period); - + reaction(tick) -> out {= SET(out, 42); =} @@ -52,11 +52,11 @@ reactor Printer { interval_t offset = _lf_time_physical_clock_offset + _lf_time_test_physical_clock_offset; info_print("Clock sync error at startup is %lld ns.", offset); =} - + reaction(in) {= info_print("Received %d.", in->value); =} - + reaction(shutdown) {= interval_t offset = _lf_time_physical_clock_offset + _lf_time_test_physical_clock_offset; info_print("Clock sync error at shutdown is %lld ns.", offset); @@ -78,4 +78,3 @@ federated reactor ClockSync { fed1 = new Federate(); fed2 = new Federate(); } - diff --git a/test/Python/src/federated/failing/DistributedCountDecentralized.lf b/test/Python/src/federated/failing/DistributedCountDecentralized.lf index e28f3e4397..8489b1a176 100644 --- a/test/Python/src/federated/failing/DistributedCountDecentralized.lf +++ b/test/Python/src/federated/failing/DistributedCountDecentralized.lf @@ -6,7 +6,7 @@ */ // reason for failing: in_.intended_tag are not supported in python target - + target Python { timeout: 5 sec, coordination: decentralized diff --git a/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf b/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf index b09d0a00a0..f42e7ec736 100644 --- a/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf +++ b/test/Python/src/federated/failing/DistributedCountDecentralizedLate.lf @@ -36,7 +36,7 @@ reactor Print { in_.intended_tag.microstep ) ) - if (lf.tag_compare((tag_t){.time=current_tag.time - get_start_time(), .microstep=current_tag.microstep}, + if (lf.tag_compare((tag_t){.time=current_tag.time - get_start_time(), .microstep=current_tag.microstep}, (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0): self.success += 1 // Message was on-time self.c += 1 diff --git a/test/Python/src/federated/failing/DistributedCountDecentralizedLateDownstream.lf b/test/Python/src/federated/failing/DistributedCountDecentralizedLateDownstream.lf index a48776971d..62239a862f 100644 --- a/test/Python/src/federated/failing/DistributedCountDecentralizedLateDownstream.lf +++ b/test/Python/src/federated/failing/DistributedCountDecentralizedLateDownstream.lf @@ -1,10 +1,10 @@ -/** +/** * Test a form of a distributed deterministic system * where a federate that receives timestamped messages has a timer in addition to the messages * as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. * In addition, this test shows that the STP violation is passed down the hierarchy until it is handled. - * - * An STP violation occurs if when a message with intended tag g1 arrives + * + * An STP violation occurs if when a message with intended tag g1 arrives * on a port p after the receiving federate has progressed far enough that * it cannot process an event with tag g1 on the port p. * This test has a fast timer (10 usec period) in the receiving federate @@ -13,13 +13,13 @@ * Furthermore, this test sets the STP threshold to 0, which makes the * violation extremely likely to occur. It could still not occur, however, * if the message arrives between ticks of the 10 usec timer. - * + * * @author Edward A. Lee * @author Soroush Bateni */ - + // reason for failing: in_.intended_tag are not supported in python target - + target Python { timeout: 1900 msec, // 9 msec headroom for the last (probably tardy) message to arrive. coordination: decentralized @@ -43,7 +43,7 @@ reactor ImportantActuator { in->value, in->intended_tag.time - get_start_time(), in->intended_tag.microstep); - if (lf.tag_compare((tag_t){.time=current_tag.time - get_start_time(), .microstep=current_tag.microstep}, + if (lf.tag_compare((tag_t){.time=current_tag.time - get_start_time(), .microstep=current_tag.microstep}, (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { self->success++; // Message was on-time } else { @@ -62,7 +62,7 @@ reactor ImportantActuator { reaction(t) {= // Do nothing. =} - + reaction(shutdown) {= if ((self->success + self->success_stp_violation) != 2) { lf_print_error_and_exit("Failed to detect STP violation in messages."); @@ -75,7 +75,7 @@ reactor ImportantActuator { reactor Print { input in:int; reaction(in) {= - tag_t current_tag = get_current_tag(); + tag_t current_tag = get_current_tag(); info_print("Print reactor: at tag (%lld, %u) received %d. Intended tag is (%lld, %u).", current_tag.time - get_start_time(), current_tag.microstep, @@ -98,12 +98,12 @@ reactor Receiver { SET(p.in, in->value + 1); SET(a.in, in->value + 1); =} - + reaction(t) {= // Do nothing. =} } - + federated reactor { c = new Count(period = 1 sec); r = new Receiver(); diff --git a/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf index fa15f32276..e8a203bd6c 100644 --- a/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf +++ b/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf @@ -1,16 +1,16 @@ -/** +/** * Test a form of a distributed deterministic system * where a federate that receives timestamped messages has a timer in addition to the messages * as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. * In addition, this test shows that the STP violation of the reaction * is passed down the hierarchy until it is handled. - * + * * @author Edward A. Lee * @author Soroush Bateni */ - + // reason for failing: in_.intended_tag are not supported in python target - + target Python { timeout: 4900 msec, coordination: decentralized @@ -34,7 +34,7 @@ reactor ImportantActuator { in->value, in->intended_tag.time - get_start_time(), in->intended_tag.microstep); - if (lf.tag_compare((tag_t){.time=current_tag.time - get_start_time(), .microstep=current_tag.microstep}, + if (lf.tag_compare((tag_t){.time=current_tag.time - get_start_time(), .microstep=current_tag.microstep}, (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { self->success++; // Message was on-time } @@ -50,7 +50,7 @@ reactor ImportantActuator { reaction(t) {= // Do nothing. =} - + reaction(shutdown) {= if ((self->success + self->success_stp_violation) != 5) { fprintf(stderr, "Failed to detect STP violations in messages.\n"); @@ -64,7 +64,7 @@ reactor ImportantActuator { reactor Print { input in:int; reaction(in) {= - tag_t current_tag = get_current_tag(); + tag_t current_tag = get_current_tag(); printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", current_tag.time - get_start_time(), current_tag.microstep, @@ -85,7 +85,7 @@ reactor Receiver { a = new ImportantActuator(); in -> p.in; in -> a.in; - + reaction(t) {= // Do nothing. =} diff --git a/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf b/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf index e675cac98e..457f515618 100644 --- a/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf +++ b/test/Python/src/federated/failing/DistributedLoopedActionDecentralized.lf @@ -4,19 +4,19 @@ * The purpose of this test is to check whether the functionalities * pertinent to dynamic STP offset adjustments are present and * functioning to a degree. - * + * * This version of the test does not use a centralized * coordinator to advance tag. Therefore, * the receiver will rely on an STP offset (initially - * zero) to wait long enough for messages to arrive + * zero) to wait long enough for messages to arrive * before advancing its tag. In this test, - * the STP offset is initially zero and gradually - * raised every time an STP violation is perceived until - * no STP violation is observed. Therefore, the exact + * the STP offset is initially zero and gradually + * raised every time an STP violation is perceived until + * no STP violation is observed. Therefore, the exact * outcome of the test will depend on actual runtime * timing. * - * + * * @author Soroush Bateni */ @@ -26,7 +26,7 @@ target Python { timeout: 1 sec, coordination: decentralized }; - + import Sender from "../lib/LoopedActionSender.lf" @@ -51,18 +51,18 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(400 msec)) { // in this test because messages on the network can // arrive late. Note that with an accurate STP offset, // this type of error should be extremely rare. - + } if (in->value != self->received_messages) { warning_print("Skipped expected value %d. Received value %d.", self->received_messages, in->value); self->received_messages = in->value; // exit(1); // The receiver should tolerate this type of error - // in this test because multiple messages arriving + // in this test because multiple messages arriving // at a given tag (t, m) can overwrite each other. - // Because messages arrive in order, only the last + // Because messages arrive in order, only the last // value that is received on the port at a given tag - // can be observed. Note that with an accurate STP - // offset, this type of error should be extremely + // can be observed. Note that with an accurate STP + // offset, this type of error should be extremely // rare. // FIXME: Messages should not be dropped or // overwritten. @@ -74,7 +74,7 @@ reactor Receiver(take_a_break_after:int(10), break_interval:time(400 msec)) { self->received_messages = 0; } =} - + reaction(shutdown) {= if (self->breaks != 3 || (self->total_received_messages != ((SEC(1)/self->break_interval)+1) * self->take_a_break_after) @@ -90,14 +90,14 @@ reactor STPReceiver(take_a_break_after:int(10), break_interval:time(400 msec), s 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 - + reaction (in) -> receiver.in {= info_print("Received %d.", in->value); SET(receiver.in, in->value); =} STP (stp_offset) {= info_print("Received %d late.", in->value); tag_t current_tag = get_current_tag(); - info_print("STP violation of (%lld, %u) perceived on the input.", + info_print("STP violation of (%lld, %u) perceived on the input.", current_tag.time - in->intended_tag.time, current_tag.microstep - in->intended_tag.microstep); SET(receiver.in, in->value); @@ -110,16 +110,16 @@ reactor STPReceiver(take_a_break_after:int(10), break_interval:time(400 msec), s self->last_time_updated_stp = current_tag.time; } =} - + reaction (t) {= // Do nothing =} } -federated reactor DistributedLoopedActionDecentralized { +federated reactor DistributedLoopedActionDecentralized { sender = new Sender(take_a_break_after = 10, break_interval = 400 msec); stpReceiver = new STPReceiver(take_a_break_after = 10, break_interval = 400 msec); - + sender.out -> stpReceiver.in; } diff --git a/test/Python/src/federated/failing/DistributedNetworkOrder.lf b/test/Python/src/federated/failing/DistributedNetworkOrder.lf index c71f9bf1ba..85dca881db 100644 --- a/test/Python/src/federated/failing/DistributedNetworkOrder.lf +++ b/test/Python/src/federated/failing/DistributedNetworkOrder.lf @@ -1,11 +1,11 @@ /* * This is a test for send_timed_message, * which is an internal API. - * - * This test sends a second message at time 5 msec that has the same intended tag as + * + * This test sends a second message at time 5 msec that has the same intended tag as * a message that it had previously sent at time 0 msec. This results in a warning, * but the message microstep is incremented and correctly received one microstep later. - * + * * @author Soroush Bateni */ @@ -21,11 +21,11 @@ reactor Sender { reaction(t) {= int payload = 1; if (lf.time.logical_elapsed() == 0LL) { - send_timed_message(MSEC(10), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + send_timed_message(MSEC(10), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), (unsigned char*)&payload); } else if (lf.time.logical_elapsed() == MSEC(5)) { payload = 2; - send_timed_message(MSEC(5), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), + send_timed_message(MSEC(5), MSG_TYPE_TAGGED_MESSAGE, 0, 1, "federate 1", sizeof(int), (unsigned char*)&payload); } =} @@ -34,7 +34,7 @@ reactor Sender { reactor Receiver { input in:int; state success:int(0); - + reaction(in) {= tag_t current_tag = get_current_tag(); if (current_tag.time == (start_time + MSEC(10))) { @@ -49,7 +49,7 @@ reactor Receiver { lf.time.logical_elapsed(), get_microstep()); =} - + reaction(shutdown) {= if (self->success != 2) { fprintf(stderr, "ERROR: Failed to receive messages.\n"); @@ -62,6 +62,6 @@ reactor Receiver { federated reactor DistributedNetworkOrder { sender = new Sender(); receiver = new Receiver(); - + sender.out -> receiver.in; } diff --git a/test/Python/src/federated/failing/LoopDistributedCentralized.lf b/test/Python/src/federated/failing/LoopDistributedCentralized.lf index a0140d4be9..66f11bdedc 100644 --- a/test/Python/src/federated/failing/LoopDistributedCentralized.lf +++ b/test/Python/src/federated/failing/LoopDistributedCentralized.lf @@ -1,7 +1,7 @@ /** * This tests a feedback loop with physical actions and * centralized coordination. - * + * * @author Edward A. Lee */ @@ -10,7 +10,7 @@ target Python { flags: "-Wall", coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, + coordination-options: {advance-message-interval: 100 msec}, timeout: 5 sec } preamble {= @@ -36,7 +36,7 @@ reactor Looper(incr:int(1), delay:time(0 msec)) { // Start the thread that listens for Enter or Return. lf_thread_t thread_id; info_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); + lf_thread_create(&thread_id, &ping, a); =} reaction(a) -> out {= SET(out, self->count); @@ -62,4 +62,4 @@ federated reactor LoopDistributedCentralized(delay:time(0)) { right = new Looper(incr = -1); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf index 894818d666..127808794d 100644 --- a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf +++ b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf @@ -1,7 +1,7 @@ /** * This tests that the precedence order of reaction invocation is kept * when a feedback loop is present in centralized coordination. - * + * * @author Edward A. Lee * @author Soroush Bateni */ @@ -11,7 +11,7 @@ target Python { flags: "-Wall", coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, + coordination-options: {advance-message-interval: 100 msec}, timeout: 5 sec } @@ -49,4 +49,4 @@ federated reactor (delay:time(0)) { right = new Looper(incr = -1); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf index caf578931a..ce0f5d9d20 100644 --- a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -1,7 +1,7 @@ /** * This tests that the precedence order of reaction invocation is kept * in the hierarchy of reactors when a feedback loop is present in centralized coordination. - * + * * @author Edward A. Lee * @author Soroush Bateni */ @@ -12,7 +12,7 @@ target Python { flags: "-Wall", coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, + coordination-options: {advance-message-interval: 100 msec}, timeout: 5 sec } @@ -22,7 +22,7 @@ reactor Contained (incr:int(1)) { state count:int(0); state received_count:int(0); reaction(t) {= - self->count += self->incr; + self->count += self->incr; =} reaction(in) {= self->received_count = self->count; @@ -39,11 +39,11 @@ reactor Looper(incr:int(1), delay:time(0 msec)) { output out:int; state count:int(0); timer t(0, 1 sec); - + c = new Contained(incr = incr); - + reaction(t) -> out {= - info_print("Sending network output %d", self->count); + info_print("Sending network output %d", self->count); SET(out, self->count); self->count += self->incr; =} @@ -66,4 +66,4 @@ federated reactor (delay:time(0)) { right = new Looper(incr = -1); left.out -> right.in; right.out -> left.in; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/failing/LoopDistributedDecentralized.lf b/test/Python/src/federated/failing/LoopDistributedDecentralized.lf index 768d581cc8..3a0dc644cc 100644 --- a/test/Python/src/federated/failing/LoopDistributedDecentralized.lf +++ b/test/Python/src/federated/failing/LoopDistributedDecentralized.lf @@ -1,7 +1,7 @@ /** * This tests a feedback loop with physical actions and * decentralized coordination. - * + * * @author Edward A. Lee */ @@ -34,7 +34,7 @@ reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { // Start the thread that listens for Enter or Return. lf_thread_t thread_id; info_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); + lf_thread_create(&thread_id, &ping, a); =} reaction(a) -> out {= info_print("Setting out."); @@ -50,7 +50,7 @@ reactor Looper(incr:int(1), delay:time(0 msec), stp_offset:time(0)) { 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_comma_separated_time(time_buffer, time_lag); - info_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); + info_print("STP offset was violated. Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); =} 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 diff --git a/test/Python/src/federated/failing/LoopDistributedDouble.lf b/test/Python/src/federated/failing/LoopDistributedDouble.lf index 040781ef90..83bb77d0ea 100644 --- a/test/Python/src/federated/failing/LoopDistributedDouble.lf +++ b/test/Python/src/federated/failing/LoopDistributedDouble.lf @@ -1,7 +1,7 @@ /** * This tests a feedback loop with physical actions and * centralized coordination. - * + * * @author Edward A. Lee */ @@ -37,7 +37,7 @@ reactor Looper(incr(1), delay(0 msec)) { # Start the thread that listens for Enter or Return. lf_thread_t thread_id; info_print("Starting thread."); - lf_thread_create(&thread_id, &ping, a); + lf_thread_create(&thread_id, &ping, a); =} reaction(a) -> out, out2 {= if (self->count%2 == 0) { @@ -80,4 +80,4 @@ federated reactor (delay:time(0)) { right.out -> left.in; right.out2 -> left.in2; left.out2 -> right.in2; -} \ No newline at end of file +} diff --git a/test/Python/src/federated/failing/PhysicalSTP.lf b/test/Python/src/federated/failing/PhysicalSTP.lf index ddea2eef7a..1d3b956b4e 100644 --- a/test/Python/src/federated/failing/PhysicalSTP.lf +++ b/test/Python/src/federated/failing/PhysicalSTP.lf @@ -14,7 +14,7 @@ import Count from "../lib/Count.lf"; reactor Print (STP_offset_param(0)) { preamble {= - import sys + import sys =} input in_; state c(1); @@ -44,7 +44,7 @@ reactor Print (STP_offset_param(0)) { =} } -federated reactor { +federated reactor { c = new Count(offset = 1 msec, period = 1 sec); p = new Print(STP_offset_param = 1 usec); diff --git a/test/Python/src/federated/failing/TopLevelArtifacts.lf b/test/Python/src/federated/failing/TopLevelArtifacts.lf index cfd1dec321..9bb6e9b311 100644 --- a/test/Python/src/federated/failing/TopLevelArtifacts.lf +++ b/test/Python/src/federated/failing/TopLevelArtifacts.lf @@ -1,21 +1,21 @@ /** * Test whether top-level reactions, actions, and ports are handled appropriately. - * + * * Currently, these artifacts are replicated on all federates. - * + * * @note This just tests for the correctness of the code generation. These top-level * artifacts might be disallowed in the future. */ - + // reason for failing: strange error during compile time. lfc seeems to treat this file as C target. - + target Python { timeout: 1 msec }; - + import Count from "../lib/Count.lf"; import TestCount from "../lib/TestCount.lf"; - + federated reactor { preamble {= import sys @@ -42,15 +42,15 @@ self.sys.stderr.write("Ouput has unexpected value {}!\n".format(out.value)); self.sys.exit(1); =} - + c = new Count(); tc = new TestCount(); c.out -> tc.in_; - + reaction (shutdown) {= if self->successes != 3: self.sys.stderr.write("Failed to properly execute top-level reactions\n"); self.sys.exit(1); print("SUCCESS!"); =} -} \ No newline at end of file +} diff --git a/test/Python/src/lib/Count.lf b/test/Python/src/lib/Count.lf index 19f6608ce2..0f7d310fe3 100644 --- a/test/Python/src/lib/Count.lf +++ b/test/Python/src/lib/Count.lf @@ -7,4 +7,4 @@ reactor Count(offset(0), period(1 sec)) { out.set(self.count) self.count += 1 =} -} \ No newline at end of file +} diff --git a/test/Python/src/lib/Imported.lf b/test/Python/src/lib/Imported.lf index 90996aa304..6507a9a395 100644 --- a/test/Python/src/lib/Imported.lf +++ b/test/Python/src/lib/Imported.lf @@ -2,10 +2,10 @@ // that itself imports a reactor definition. target Python; import ImportedAgain from "./ImportedAgain.lf" -reactor Imported { +reactor Imported { input x; a = new ImportedAgain(); reaction(x) -> a.x {= a.x.set(x.value) - =} -} \ No newline at end of file + =} +} diff --git a/test/Python/src/lib/ImportedAgain.lf b/test/Python/src/lib/ImportedAgain.lf index 468c12b668..74abdf4f97 100644 --- a/test/Python/src/lib/ImportedAgain.lf +++ b/test/Python/src/lib/ImportedAgain.lf @@ -11,4 +11,4 @@ reactor ImportedAgain { print("ERROR: Expected input to be 42. Got: " + x.value) exit(1) =} -} \ No newline at end of file +} diff --git a/test/Python/src/lib/ImportedComposition.lf b/test/Python/src/lib/ImportedComposition.lf index 1f18caec9b..3324ce3db8 100644 --- a/test/Python/src/lib/ImportedComposition.lf +++ b/test/Python/src/lib/ImportedComposition.lf @@ -16,4 +16,4 @@ reactor ImportedComposition { x -> g1.x after 10 msec; g1.y -> g2.x after 30 msec; g2.y -> y after 15 msec; -} \ No newline at end of file +} diff --git a/test/Python/src/lib/InternalDelay.lf b/test/Python/src/lib/InternalDelay.lf index 77d12f612b..ab5d47c0e9 100644 --- a/test/Python/src/lib/InternalDelay.lf +++ b/test/Python/src/lib/InternalDelay.lf @@ -11,4 +11,4 @@ reactor InternalDelay ( reaction(d) -> out {= out.set(d.value) =} -} \ No newline at end of file +} diff --git a/test/Python/src/lib/LoopedActionSender.lf b/test/Python/src/lib/LoopedActionSender.lf index f04ddf896c..af60d13743 100644 --- a/test/Python/src/lib/LoopedActionSender.lf +++ b/test/Python/src/lib/LoopedActionSender.lf @@ -1,31 +1,30 @@ -/** - * A sender reactor that outputs integers - * in superdense time. - * - * @author Soroush Bateni - */ -target Python; - -/** - * @param take_a_break_after: Indicates how many messages are sent - * in consecutive superdense time - * @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)) { - output out; - logical action act; - state sent_messages(0); - reaction(startup, act) -> act, out {= - # Send a message on out - out.set(self.sent_messages) - self.sent_messages += 1 - if self.sent_messages < self.take_a_break_after: - act.schedule(0) - else: - # Take a break - self.sent_messages=0; - act.schedule(self.break_interval) - =} -} - \ No newline at end of file +/** + * A sender reactor that outputs integers + * in superdense time. + * + * @author Soroush Bateni + */ +target Python; + +/** + * @param take_a_break_after: Indicates how many messages are sent + * in consecutive superdense time + * @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)) { + output out; + logical action act; + state sent_messages(0); + reaction(startup, act) -> act, out {= + # Send a message on out + out.set(self.sent_messages) + self.sent_messages += 1 + if self.sent_messages < self.take_a_break_after: + act.schedule(0) + else: + # Take a break + self.sent_messages=0; + act.schedule(self.break_interval) + =} +} diff --git a/test/Python/src/lib/Test.lf b/test/Python/src/lib/Test.lf index 03d56c84f8..6f121519a2 100644 --- a/test/Python/src/lib/Test.lf +++ b/test/Python/src/lib/Test.lf @@ -10,4 +10,4 @@ reactor TestDouble(expected(1.0, 1.0, 1.0, 1.0)) { exit(1) self.count += 1 =} -} \ No newline at end of file +} diff --git a/test/Python/src/lib/TestCount.lf b/test/Python/src/lib/TestCount.lf index 314384cca9..824fc45b64 100644 --- a/test/Python/src/lib/TestCount.lf +++ b/test/Python/src/lib/TestCount.lf @@ -2,7 +2,7 @@ * Test that a counting sequence of inputs starts with the specified start * parameter value, increments by the specified stride, and receives the * specified number of inputs. - * + * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. * @param num_inputs The number of inputs expected. Default is 1. @@ -29,4 +29,4 @@ reactor TestCount(start(1), stride(1), num_inputs(1)) { print("Expected to receive {} inputs, but got {}.".format(self.num_inputs, self.inputs_received)) self.sys.exit(1) =} -} \ No newline at end of file +} diff --git a/test/Python/src/lib/TestCountMultiport.lf b/test/Python/src/lib/TestCountMultiport.lf index d1bb8a29ba..f3769b52c6 100644 --- a/test/Python/src/lib/TestCountMultiport.lf +++ b/test/Python/src/lib/TestCountMultiport.lf @@ -4,7 +4,7 @@ * specified number of inputs. This version has a multiport input, and * each input is expected to be present and incremented over the previous * input. - * + * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. * @param num_inputs The number of inputs expected on each channel. Default is 1. @@ -38,4 +38,4 @@ reactor TestCountMultiport(start(1), stride(1), num_inputs(1), width(2)) { )) self.sys.exit(1) =} -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/ConvertCaseTest.lf b/test/Python/src/modal_models/ConvertCaseTest.lf index 2c5150da21..447fb2f870 100644 --- a/test/Python/src/modal_models/ConvertCaseTest.lf +++ b/test/Python/src/modal_models/ConvertCaseTest.lf @@ -13,17 +13,17 @@ reactor ResetProcessor { input discard input character output converted - + initial mode Converting { converter = new Converter() character -> converter.raw converter.converted -> converted - + reaction(discard) -> Discarding {= Discarding.set() =} } - + mode Discarding { reaction(character) -> converted {= converted.set('_') @@ -39,17 +39,17 @@ reactor HistoryProcessor { input discard input character output converted - + initial mode Converting { converter = new Converter() character -> converter.raw converter.converted -> converted - + reaction(discard) -> Discarding {= Discarding.set() =} } - + mode Discarding { reaction(character) -> converted {= converted.set('_') @@ -86,9 +86,9 @@ reactor Converter { reactor InputFeeder(message("")) { output character state idx(0) - + timer t(0, 250 msec) - + reaction(t) -> character {= if self.idx < len(self.message): character.set(self.message[self.idx]) @@ -98,14 +98,14 @@ reactor InputFeeder(message("")) { main reactor { timer stepper(500msec, 1sec) - + feeder = new InputFeeder(message="Hello World!") reset_processor = new ResetProcessor() history_processor = new HistoryProcessor() - + feeder.character -> reset_processor.character feeder.character -> history_processor.character - + test = new TraceTesting( events_size = 2, trace = ( @@ -128,14 +128,14 @@ main reactor { reset_processor.discard.set(True) history_processor.discard.set(True) =} - + reaction(reset_processor.converted) {= print(f"Reset: {reset_processor.converted.value}") =} - + reaction(history_processor.converted) {= print(f"History: {history_processor.converted.value}") =} - + reset_processor.converted, history_processor.converted -> test.events -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/Count3Modes.lf b/test/Python/src/modal_models/Count3Modes.lf index ac3661505e..a4b7470bc3 100644 --- a/test/Python/src/modal_models/Count3Modes.lf +++ b/test/Python/src/modal_models/Count3Modes.lf @@ -10,7 +10,7 @@ target Python { reactor CounterCycle { input next; output count; - + initial mode One { reaction(next) -> count, Two {= count.set(1) @@ -34,9 +34,9 @@ reactor CounterCycle { main reactor { timer stepper(0, 250msec); counter = new CounterCycle(); - + state expected_value(1); - + // Trigger reaction(stepper) -> counter.next {= counter.next.set(True) @@ -45,17 +45,17 @@ main reactor { // Check reaction(stepper) counter.count {= print(f"{counter.count.value}") - + if counter.count.is_present is not True: sys.stderr.write("ERROR: Missing mode change.\n") exit(1) elif counter.count.value != self.expected_value: sys.stderr.write("ERROR: Wrong mode.\n") exit(2) - + if self.expected_value == 3: self.expected_value = 1 else: self.expected_value += 1 =} -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/ModalActions.lf b/test/Python/src/modal_models/ModalActions.lf index da16feea30..cf41e3ce19 100644 --- a/test/Python/src/modal_models/ModalActions.lf +++ b/test/Python/src/modal_models/ModalActions.lf @@ -11,17 +11,17 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next - + output mode_switch output action1_sched output action1_exec output action2_sched output action2_exec - + initial mode One { timer T1(0, 750msec) logical action delay1(500msec) - + reaction(T1) -> delay1, action1_sched {= print("Scheduled Action") delay1.schedule(0) @@ -31,7 +31,7 @@ reactor Modal { print("Executed Action") action1_exec.set(1) =} - + reaction(next) -> reset(Two), mode_switch {= print("Transitioning to mode Two (reset)") mode_switch.set(1) @@ -41,7 +41,7 @@ reactor Modal { mode Two { timer T2(0, 750 msec) logical action delay2(500 msec) - + reaction(T2) -> delay2, action2_sched {= print("Scheduled Action2") delay2.schedule(0) @@ -51,7 +51,7 @@ reactor Modal { print("Executed Action2") action2_exec.set(1) =} - + reaction(next) -> continue(One), mode_switch {= print("Transitioning to mode One (continue)") mode_switch.set(1) @@ -62,7 +62,7 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 5, @@ -88,11 +88,11 @@ main reactor { reaction(stepper) -> modal.next {= modal.next.set(True) =} - + modal.mode_switch, modal.action1_sched, modal.action1_exec, modal.action2_sched, modal.action2_exec -> test.events -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/ModalAfter.lf b/test/Python/src/modal_models/ModalAfter.lf index 4202311b4f..81d1b635da 100644 --- a/test/Python/src/modal_models/ModalAfter.lf +++ b/test/Python/src/modal_models/ModalAfter.lf @@ -11,20 +11,20 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next - + output mode_switch output produced1 output consumed1 output produced2 output consumed2 - + initial mode One { producer1 = new Producer(mode_id=1) consumer1 = new Consumer(mode_id=1) producer1.product -> produced1 producer1.product -> consumer1.product after 500msec consumer1.report -> consumed1 - + reaction(next) -> reset(Two), mode_switch {= print("Transitioning to mode Two (reset)") mode_switch.set(1) @@ -37,7 +37,7 @@ reactor Modal { producer2.product -> produced2 producer2.product -> consumer2.product after 500msec consumer2.report -> consumed2 - + reaction(next) -> continue(One), mode_switch {= print("Transitioning to mode One (continue)") mode_switch.set(1) @@ -48,9 +48,9 @@ reactor Modal { reactor Producer(mode_id(0)) { output product - + timer t(0, 750msec) - + reaction(t) -> product {= print(f"Produced in {self.mode_id}") product.set(1) @@ -60,7 +60,7 @@ reactor Producer(mode_id(0)) { reactor Consumer(mode_id(0)) { input product output report - + reaction(product) -> report {= print("Consumed in {self.mode_id}") report.set(1) @@ -69,7 +69,7 @@ reactor Consumer(mode_id(0)) { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 5, @@ -95,11 +95,11 @@ main reactor { reaction(stepper) -> modal.next {= modal.next.set(True) =} - + modal.mode_switch, modal.produced1, modal.consumed1, modal.produced2, modal.consumed2 -> test.events -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/ModalCycleBreaker.lf b/test/Python/src/modal_models/ModalCycleBreaker.lf index 30a373618e..1950bf848e 100644 --- a/test/Python/src/modal_models/ModalCycleBreaker.lf +++ b/test/Python/src/modal_models/ModalCycleBreaker.lf @@ -1,6 +1,6 @@ /* * Modal Reactor Test. - * + * * Tests if connections in the same reactor that have the same destination work if they are located in separate modes. */ target Python { @@ -14,13 +14,13 @@ reactor Modal { input in1 input in2 output out - + mode Two { # Defining reaction to in2 before in1 would cause cycle if no mode were present timer wait(150msec, 1sec) - + reaction(in2) {= =} - + reaction(wait) -> One {= One.set() print("Switching to mode One") @@ -41,10 +41,10 @@ reactor Modal { reactor Counter(period(1 sec)) { output value - + timer t(0, period) state curval(0) - + reaction(t) -> value {= value.set(self.curval) self.curval += 1 @@ -52,7 +52,7 @@ reactor Counter(period(1 sec)) { } main reactor { - counter = new Counter(period=100msec) + counter = new Counter(period=100msec) modal = new Modal() test = new TraceTesting( events_size = 1, @@ -67,10 +67,10 @@ main reactor { 100000000,1,8, 100000000,1,9 ), training = False) - + counter.value -> modal.in1 modal.out -> modal.in2 - + modal.out -> test.events @@ -78,4 +78,4 @@ main reactor { reaction(modal.out) {= print(modal.out.value) =} -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/ModalNestedReactions.lf b/test/Python/src/modal_models/ModalNestedReactions.lf index eb74985354..e19812700b 100644 --- a/test/Python/src/modal_models/ModalNestedReactions.lf +++ b/test/Python/src/modal_models/ModalNestedReactions.lf @@ -9,7 +9,7 @@ target Python { reactor CounterCycle { input next - + output count output only_in_two output never @@ -24,7 +24,7 @@ reactor CounterCycle { fwd = new Forward() next -> fwd.inp fwd.out -> only_in_two - + reaction(next) -> count, One {= count.set(2) One.set() @@ -58,7 +58,7 @@ main reactor { // Check reaction(stepper) counter.count, counter.only_in_two {= print(counter.count.value) - + if counter.count.is_present is not True: sys.stderr.write("ERROR: Missing mode change.\n") exit(1) diff --git a/test/Python/src/modal_models/ModalStartup.lf b/test/Python/src/modal_models/ModalStartup.lf index 99059da840..c2e2067dc5 100644 --- a/test/Python/src/modal_models/ModalStartup.lf +++ b/test/Python/src/modal_models/ModalStartup.lf @@ -11,30 +11,30 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next - + output mode_switch output startup1 output startup2 output startup3 - + initial mode One { reaction(startup) -> startup1 {= print(f"Startup 1 at ({lf.time.logical_elapsed()}, {get_microstep()}).") startup1.set(1) =} - + reaction(next) -> reset(Two), mode_switch {= print("Transitioning to mode Two (reset)") mode_switch.set(1) Two.set() =} } - mode Two { + mode Two { reaction(startup) -> startup2 {= print(f"Startup 2 at at ({lf.time.logical_elapsed()}, {get_microstep()}).") startup2.set(1) =} - + reaction(next) -> continue(Three), mode_switch {= print("Transitioning to mode Three (continue)") mode_switch.set(1) @@ -42,12 +42,12 @@ reactor Modal { =} } - mode Three { + mode Three { reaction(startup) -> startup3 {= print(f"Startup 3 at at ({lf.time.logical_elapsed()}, {get_microstep()}).") startup3.set(1) =} - + reaction(next) -> continue(One), mode_switch {= print("Transitioning to mode One (continue)") mode_switch.set(1) @@ -58,7 +58,7 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 4, @@ -79,7 +79,7 @@ main reactor { reaction(stepper) -> modal.next {= modal.next.set(True) =} - + modal.mode_switch, modal.startup1, modal.startup2, diff --git a/test/Python/src/modal_models/ModalStateReset.lf b/test/Python/src/modal_models/ModalStateReset.lf index 3ee796508e..81ff0d1bc2 100644 --- a/test/Python/src/modal_models/ModalStateReset.lf +++ b/test/Python/src/modal_models/ModalStateReset.lf @@ -11,30 +11,30 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next - + output mode_switch output count0 output count1 output count2 - + state counter0(0) - + reaction(next) -> count0 {= print(f"Counter0: {self.counter0}") count0.set(self.counter0) self.counter0 += 1 =} - + initial mode One { state counter1(0) timer T1(0msec, 250msec) - + reaction(T1) -> count1 {= print(f"Counter1: {self.counter1}") count1.set(self.counter1) self.counter1 += 1 =} - + reaction(next) -> reset(Two), mode_switch {= print("Transitioning to mode Two (reset)") mode_switch.set(1) @@ -44,13 +44,13 @@ reactor Modal { mode Two { state counter2(-2) timer T2(0msec, 250msec) - + reaction(T2) -> count2 {= print(f"Counter2: {self.counter2}") count2.set(self.counter2) self.counter2 += 1 =} - + reaction(next) -> continue(One), mode_switch {= print("Transitioning to mode One (continue)") mode_switch.set(1) @@ -61,7 +61,7 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 4, @@ -91,10 +91,10 @@ main reactor { reaction(stepper) -> modal.next {= modal.next.set(True) =} - + modal.mode_switch, modal.count0, modal.count1, modal.count2 -> test.events -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/ModalTimers.lf b/test/Python/src/modal_models/ModalTimers.lf index bf09a04749..228d06de66 100644 --- a/test/Python/src/modal_models/ModalTimers.lf +++ b/test/Python/src/modal_models/ModalTimers.lf @@ -11,19 +11,19 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next - + output mode_switch output timer1 output timer2 - + initial mode One { timer T1(0, 750msec) - + reaction(T1) -> timer1 {= print(f"T1: at tag ({lf.time.logical_elapsed()}, {get_microstep()})") timer1.set(1) =} - + reaction(next) -> reset(Two), mode_switch {= print("Transitioning to mode Two (reset)") mode_switch.set(1) @@ -32,12 +32,12 @@ reactor Modal { } mode Two { timer T2(0, 750msec) - + reaction(T2) -> timer2 {= print(f"T2: at tag ({lf.time.logical_elapsed()}, {get_microstep()})") timer2.set(1) =} - + reaction(next) -> continue(One), mode_switch {= print("Transitioning to mode One (continue)") mode_switch.set(1) @@ -48,7 +48,7 @@ reactor Modal { main reactor { timer stepper(1sec, 1sec) - + modal = new Modal() test = new TraceTesting( events_size = 3, @@ -70,9 +70,9 @@ main reactor { reaction(stepper) -> modal.next {= modal.next.set(True) =} - + modal.mode_switch, modal.timer1, modal.timer2 -> test.events -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf index 335b3abd23..5041132a9d 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_2Connections.lf @@ -1,6 +1,6 @@ /* * Modal Reactor Test. - * + * * Tests if connections in the same reactor that have the same destination work if they are located in separate modes. */ target Python { @@ -13,11 +13,11 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next output count - + initial mode One { counter1 = new Counter(period=250msec) counter1.value -> count - + reaction(next) -> Two {= Two.set() =} @@ -34,10 +34,10 @@ reactor Modal { reactor Counter(period(1sec)) { output value - + timer t(0, period) state curval(0) - + reaction(t) -> value {= value.set(self.curval) self.curval += 1 @@ -46,7 +46,7 @@ reactor Counter(period(1sec)) { main reactor { timer stepper(500msec, 500msec) - + modal = new Modal() test = new TraceTesting( events_size = 1, diff --git a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf index 5bb5d18fdc..233c82b158 100644 --- a/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf +++ b/test/Python/src/modal_models/MultipleOutputFeeder_ReactionConnections.lf @@ -1,6 +1,6 @@ /* * Modal Reactor Test. - * + * * Tests if a connection and a reaction in the same reactor can have the same destination if they are located in separate modes. */ target Python { @@ -13,22 +13,22 @@ import TraceTesting from "util/TraceTesting.lf" reactor Modal { input next output count - + initial mode One { counter1 = new Counter(period=250msec) counter1.value -> count - + reaction(next) -> Two {= Two.set() =} } mode Two { counter2 = new Counter(period=100msec) - + reaction(counter2.value) -> count {= count.set(counter2.value.value * 10) =} - + reaction(next) -> continue(One) {= One.set() =} @@ -37,10 +37,10 @@ reactor Modal { reactor Counter(period(1sec)) { output value - + timer t(0, period) state curval(0) - + reaction(t) -> value {= value.set(self.curval) self.curval += 1 @@ -49,7 +49,7 @@ reactor Counter(period(1sec)) { main reactor { timer stepper(500msec, 500msec) - + modal = new Modal() test = new TraceTesting( events_size = 1, @@ -77,12 +77,12 @@ main reactor { reaction(stepper) -> modal.next {= modal.next.set(True) =} - + // Print reaction(modal.count) {= print(modal.count.value) =} - + modal.count -> test.events -} \ No newline at end of file +} diff --git a/test/Python/src/modal_models/util/TraceTesting.lf b/test/Python/src/modal_models/util/TraceTesting.lf index 8f3bf35bb2..f64a282eab 100644 --- a/test/Python/src/modal_models/util/TraceTesting.lf +++ b/test/Python/src/modal_models/util/TraceTesting.lf @@ -5,20 +5,20 @@ target Python 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) - + reaction(startup) {= self.last_reaction_time = lf.time.logical() =} - + reaction(events) {= # Time passed since last reaction curr_reaction_delay = lf.time.logical() - self.last_reaction_time - + if self.training: # Save the time self.recorded_events.append(curr_reaction_delay) @@ -26,18 +26,18 @@ reactor TraceTesting(events_size(0), trace({=[]=}), training(False)) { if self.trace_idx >= len(self.trace): sys.stderr.write("ERROR: Trace Error: Current execution exceeds given trace.\n") exit(1) - + trace_reaction_delay = self.trace[self.trace_idx] self.trace_idx += 1 - + if curr_reaction_delay != trace_reaction_delay: sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected reaction timing. (delay: {curr_reaction_delay}, expected: {trace_reaction_delay})\n") exit(2) - + for i in range(self.events_size): curr_present = events[i].is_present curr_value = events[i].value - + if self.training: # Save the event self.recorded_events.append(curr_present) @@ -47,20 +47,20 @@ reactor TraceTesting(events_size(0), trace({=[]=}), training(False)) { self.trace_idx += 1 trace_value = self.trace[self.trace_idx] self.trace_idx += 1 - + if trace_present != curr_present: sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected event presence. (event: {i}, presence: {curr_present}, expected: {trace_present})\n") exit(3) elif curr_present and trace_value != curr_value: sys.stderr.write(f"ERROR: Trace Mismatch: Unexpected event presence. (event: {i}, value: {curr_value}, expected: {trace_value})\n") exit(4) - + self.last_reaction_time = lf.time.logical() =} - + reaction(shutdown) {= if self.training: print(f"Recorded event trace ({self.recorded_events_next}):") print(self.recorded_events) =} -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/BankIndexInitializer.lf b/test/Python/src/multiport/BankIndexInitializer.lf index 54fb4c16ce..408d364722 100644 --- a/test/Python/src/multiport/BankIndexInitializer.lf +++ b/test/Python/src/multiport/BankIndexInitializer.lf @@ -18,7 +18,7 @@ reactor Source( reactor Sink(width(4)) { input[width] _in; state received(false); - + reaction (_in) {= for (idx, port) in enumerate(_in): if port.is_present is True: @@ -38,4 +38,4 @@ main reactor(width(4)) { source = new[width] Source(value = {= table[bank_index] =}); sink = new Sink(width = width); source.out -> sink._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/BankReactionsInContainer.lf b/test/Python/src/multiport/BankReactionsInContainer.lf index 2ac425094d..2e0454934e 100644 --- a/test/Python/src/multiport/BankReactionsInContainer.lf +++ b/test/Python/src/multiport/BankReactionsInContainer.lf @@ -8,7 +8,7 @@ reactor R (bank_index(0)) { output[2] out; input[2] inp; state received(false); - + reaction(startup) -> out {= for (i, p) in enumerate(out): value = self.bank_index * 2 + i @@ -35,7 +35,7 @@ reactor R (bank_index(0)) { main reactor { s = new[2] R(); state received(false); - + reaction(startup) -> s.inp {= count = 0 for i in range(len(s)): diff --git a/test/Python/src/multiport/BankToBank.lf b/test/Python/src/multiport/BankToBank.lf index ed451b26b6..1b6b453903 100644 --- a/test/Python/src/multiport/BankToBank.lf +++ b/test/Python/src/multiport/BankToBank.lf @@ -1,8 +1,8 @@ - // Check bank of reactors sending to bank of reactors. +// Check bank of reactors sending to bank of reactors. target Python { timeout: 2 sec, fast: true -}; +}; reactor Source( bank_index(0) ) { @@ -34,7 +34,7 @@ reactor Destination( =} } -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 e86994369d..4d7f45cc38 100644 --- a/test/Python/src/multiport/BankToBankMultiport.lf +++ b/test/Python/src/multiport/BankToBankMultiport.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target Python { timeout: 2 sec, fast: true @@ -20,7 +20,7 @@ reactor Destination(width(1)) { sm = 0 for port in _in: if port.is_present: - sm += port.value + sm += port.value print("Sum of received: ", sm) if sm != self.s: @@ -37,7 +37,7 @@ reactor Destination(width(1)) { print("Success.") =} } -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 d9ddcd280d..406b34a03d 100644 --- a/test/Python/src/multiport/BankToBankMultiportAfter.lf +++ b/test/Python/src/multiport/BankToBankMultiportAfter.lf @@ -1,10 +1,10 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target Python { timeout: 2 sec, fast: true }; 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 06caac63c0..0ba57d744d 100644 --- a/test/Python/src/multiport/BankToMultiport.lf +++ b/test/Python/src/multiport/BankToMultiport.lf @@ -13,7 +13,7 @@ reactor Source( reactor Sink(width(4)) { input[width] _in; state received(false); - + reaction (_in) {= for (idx, port) in enumerate(_in): if port.is_present is True: @@ -33,4 +33,4 @@ main reactor BankToMultiport(width(5)) { source = new[width] Source(); sink = new Sink(width = width); source.out -> sink._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/Broadcast.lf b/test/Python/src/multiport/Broadcast.lf index fe489e45ca..a0f90309c1 100644 --- a/test/Python/src/multiport/Broadcast.lf +++ b/test/Python/src/multiport/Broadcast.lf @@ -1,11 +1,11 @@ target Python { timeout: 2 sec, fast: true -}; +}; reactor Source(value(42)) { output out - + reaction(startup) -> out {= out.set(self.value) =} @@ -19,7 +19,7 @@ reactor Destination(bank_index(0), delay(0)) { if (_in.value != 42): sys.stderr.write("ERROR: Expected 42.\n") exit(1) - + if lf.time.logical_elapsed() != self.delay: sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") exit(2) @@ -33,8 +33,8 @@ reactor Destination(bank_index(0), delay(0)) { =} } -main reactor { +main reactor { a = new Source(); b = new[4] Destination(); (a.out)+ -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/BroadcastAfter.lf b/test/Python/src/multiport/BroadcastAfter.lf index 3df0a7a4d3..4f6b86a10d 100644 --- a/test/Python/src/multiport/BroadcastAfter.lf +++ b/test/Python/src/multiport/BroadcastAfter.lf @@ -1,12 +1,12 @@ target Python { timeout: 2 sec, fast: true -}; +}; import Source, Destination from "Broadcast.lf" -main reactor { +main reactor { a = new Source(); b = new[4] Destination(delay = 1 sec); (a.out)+ -> b._in after 1 sec; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/BroadcastMultipleAfter.lf b/test/Python/src/multiport/BroadcastMultipleAfter.lf index 4874201180..bca26a1f45 100644 --- a/test/Python/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Python/src/multiport/BroadcastMultipleAfter.lf @@ -1,7 +1,7 @@ target Python { timeout: 2 sec, fast: true -}; +}; import Source from "Broadcast.lf" @@ -14,7 +14,7 @@ reactor Destination(bank_index(0), delay(0)) { if (_in.value != expected): sys.stderr.write("ERROR: Expected 42.\n") exit(1) - + if lf.time.logical_elapsed() != self.delay: sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") exit(2) @@ -34,4 +34,4 @@ main reactor { a3 = new Source(value=3); b = new[9] Destination(delay = 1 sec); (a1.out, a2.out, a3.out)+ -> b._in after 1 sec; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportFromBank.lf b/test/Python/src/multiport/MultiportFromBank.lf index 1b6a7533cb..7fd2427ebd 100644 --- a/test/Python/src/multiport/MultiportFromBank.lf +++ b/test/Python/src/multiport/MultiportFromBank.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, fast: true -}; +}; reactor Source( check_override(0), bank_index(0) @@ -38,4 +38,4 @@ main reactor MultiportFromBank { a = new[3] Source(check_override = 1); b = new Destination(); a.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportFromBankHierarchy.lf b/test/Python/src/multiport/MultiportFromBankHierarchy.lf index 3e0605f7f9..94d3136dae 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchy.lf @@ -1,4 +1,4 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, @@ -22,4 +22,4 @@ main reactor MultiportFromBankHierarchy { a = new Container(); b = new Destination(); a.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf index 64ba2dcfc4..7074ff5b79 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,13 +1,13 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, fast: true -}; +}; import Container from "MultiportFromBankHierarchy.lf" import Destination from "MultiportFromBank.lf" main reactor MultiportFromBankHierarchyAfter { a = new Container(); b = new Destination(); a.out -> b._in after 1 sec; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportFromHierarchy.lf b/test/Python/src/multiport/MultiportFromHierarchy.lf index 414adc315d..6c839e98bd 100644 --- a/test/Python/src/multiport/MultiportFromHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromHierarchy.lf @@ -1,8 +1,8 @@ - // Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target Python { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[4] out; @@ -46,8 +46,8 @@ reactor InsideContainer { src.out -> out; } -main reactor MultiportFromHierarchy { +main reactor MultiportFromHierarchy { a = new Container(); b = new Destination(); a.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportFromReaction.lf b/test/Python/src/multiport/MultiportFromReaction.lf index ef34e69d76..bda0dce645 100644 --- a/test/Python/src/multiport/MultiportFromReaction.lf +++ b/test/Python/src/multiport/MultiportFromReaction.lf @@ -2,7 +2,7 @@ target Python { timeout: 2 sec, fast: true -}; +}; reactor Destination(width(1)) { state s(6); input[width] _in; diff --git a/test/Python/src/multiport/MultiportIn.lf b/test/Python/src/multiport/MultiportIn.lf index 0d35f718e3..31fd2c71e4 100644 --- a/test/Python/src/multiport/MultiportIn.lf +++ b/test/Python/src/multiport/MultiportIn.lf @@ -45,7 +45,7 @@ reactor Destination { =} } -main reactor MultiportIn { +main reactor MultiportIn { a = new Source(); t1 = new Computation(); t2 = new Computation(); @@ -57,4 +57,4 @@ main reactor MultiportIn { a.out -> t3._in; a.out -> t4._in; t1.out, t2.out, t3.out, t4.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportInParameterized.lf b/test/Python/src/multiport/MultiportInParameterized.lf index 19b0f682ac..253dcbd99e 100644 --- a/test/Python/src/multiport/MultiportInParameterized.lf +++ b/test/Python/src/multiport/MultiportInParameterized.lf @@ -59,4 +59,4 @@ main reactor MultiportInParameterized { // t2.out -> b._in[1]; // t3.out -> b._in[2]; // dt4.out -> b._in[3]; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportOut.lf b/test/Python/src/multiport/MultiportOut.lf index 0c1dbcec31..14ab11a3d8 100644 --- a/test/Python/src/multiport/MultiportOut.lf +++ b/test/Python/src/multiport/MultiportOut.lf @@ -2,7 +2,7 @@ target Python { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[4] out; @@ -10,7 +10,7 @@ reactor Source { reaction(t) -> out {= for port in out: port.set(self.s) - + self.s+=1 =} } @@ -29,7 +29,7 @@ reactor Destination { for port in _in: if port.is_present: sum += port.value - + print("Sum of received: " + str(sum)) if sum != self.s: sys.stderr.write("ERROR: Expected " + str(self.s)) @@ -46,7 +46,7 @@ reactor Destination { =} } -main reactor MultiportOut { +main reactor MultiportOut { a = new Source(); t1 = new Computation(); t2 = new Computation(); @@ -55,4 +55,4 @@ main reactor MultiportOut { b = new Destination(); a.out -> t1._in, t2._in, t3._in, t4._in; t1.out, t2.out, t3.out, t4.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToBank.lf b/test/Python/src/multiport/MultiportToBank.lf index eefc3e864d..8a6327d9d4 100644 --- a/test/Python/src/multiport/MultiportToBank.lf +++ b/test/Python/src/multiport/MultiportToBank.lf @@ -1,8 +1,8 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. target Python { timeout: 2 sec, fast: true -}; +}; reactor Source { output[3] out; reaction(startup) -> out {= @@ -30,8 +30,8 @@ reactor Destination( =} } -main reactor MultiportToBank { +main reactor MultiportToBank { a = new Source(); b = new[3] Destination(); a.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToBankAfter.lf b/test/Python/src/multiport/MultiportToBankAfter.lf index 112453e647..576d5f5743 100644 --- a/test/Python/src/multiport/MultiportToBankAfter.lf +++ b/test/Python/src/multiport/MultiportToBankAfter.lf @@ -2,7 +2,7 @@ target Python { timeout: 2 sec, fast: true -}; +}; import Source from "MultiportToBank.lf" reactor Destination( bank_index(0) @@ -27,8 +27,8 @@ reactor Destination( =} } -main reactor MultiportToBankAfter { +main reactor MultiportToBankAfter { a = new Source(); b = new[3] Destination(); a.out -> b._in after 1 sec; // Width of the bank of delays will be inferred. -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToBankHierarchy.lf b/test/Python/src/multiport/MultiportToBankHierarchy.lf index fe473c39e0..773fbb0130 100644 --- a/test/Python/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportToBankHierarchy.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, fast: true -}; +}; import Source from "MultiportToBank.lf" reactor Destination( bank_index(0) @@ -30,8 +30,8 @@ reactor Container { _in -> c._in; } -main reactor MultiportToBankHierarchy { +main reactor MultiportToBankHierarchy { a = new Source(); b = new Container(); a.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToHierarchy.lf b/test/Python/src/multiport/MultiportToHierarchy.lf index 0e907a3661..f3d29a1d4a 100644 --- a/test/Python/src/multiport/MultiportToHierarchy.lf +++ b/test/Python/src/multiport/MultiportToHierarchy.lf @@ -1,9 +1,9 @@ - // Check multiport output to multiport input, where the latter is a hierarchical reactor. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. // Note that the destination reactor has width wider than the sender, so one input is dangling. target Python { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[4] out; @@ -41,7 +41,7 @@ reactor Container(width(4)) { _in -> dst._in; } -main reactor MultiportToHierarchy { +main reactor MultiportToHierarchy { a = new Source(); b = new Container(); a.out -> b._in; diff --git a/test/Python/src/multiport/MultiportToMultiport.lf b/test/Python/src/multiport/MultiportToMultiport.lf index a313a8771b..7ab864f4e4 100644 --- a/test/Python/src/multiport/MultiportToMultiport.lf +++ b/test/Python/src/multiport/MultiportToMultiport.lf @@ -17,8 +17,8 @@ reactor Source(width(1)) { print("AFTER set, out[{:d}]->value has value ".format(i), out[i].value) =} } -main reactor MultiportToMultiport { +main reactor MultiportToMultiport { a = new Source(width = 4); b = new Destination(width = 4); a.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToMultiport2.lf b/test/Python/src/multiport/MultiportToMultiport2.lf index a248237d18..18008842dd 100644 --- a/test/Python/src/multiport/MultiportToMultiport2.lf +++ b/test/Python/src/multiport/MultiportToMultiport2.lf @@ -29,4 +29,4 @@ main reactor MultiportToMultiport2 { a2 = new Source(width = 2); b = new Destination(width = 5); a1.out, a2.out -> b._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToMultiport2After.lf b/test/Python/src/multiport/MultiportToMultiport2After.lf index e16c3501af..9732d7c284 100644 --- a/test/Python/src/multiport/MultiportToMultiport2After.lf +++ b/test/Python/src/multiport/MultiportToMultiport2After.lf @@ -25,4 +25,4 @@ main reactor MultiportToMultiport2After { a2 = new Source(width = 2); b = new Destination(width = 5); a1.out, a2.out -> b._in after 1 sec; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToMultiportArray.lf b/test/Python/src/multiport/MultiportToMultiportArray.lf index 1dd7c64a61..86ea005f97 100644 --- a/test/Python/src/multiport/MultiportToMultiportArray.lf +++ b/test/Python/src/multiport/MultiportToMultiportArray.lf @@ -3,7 +3,7 @@ target Python { timeout: 2 sec, fast: true -}; +}; reactor Source { timer t(0, 200 msec); output[2] out; @@ -39,7 +39,7 @@ reactor Destination { =} } -main reactor MultiportToMultiportArray { +main reactor MultiportToMultiportArray { a = new Source(); b = new Destination(); a.out -> b._in; diff --git a/test/Python/src/multiport/MultiportToMultiportParameter.lf b/test/Python/src/multiport/MultiportToMultiportParameter.lf index 4cd5fc1c21..b71df08616 100644 --- a/test/Python/src/multiport/MultiportToMultiportParameter.lf +++ b/test/Python/src/multiport/MultiportToMultiportParameter.lf @@ -2,11 +2,11 @@ target Python { timeout: 2 sec, fast: true -}; +}; 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; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToPort.lf b/test/Python/src/multiport/MultiportToPort.lf index 8f814e3b24..50e98e9124 100644 --- a/test/Python/src/multiport/MultiportToPort.lf +++ b/test/Python/src/multiport/MultiportToPort.lf @@ -3,7 +3,7 @@ target Python { timeout: 2 sec, fast: true -}; +}; reactor Source { output[2] out; reaction(startup) -> out {= @@ -30,9 +30,9 @@ reactor Destination(expected(0)) { =} } -main reactor MultiportToPort { +main reactor MultiportToPort { a = new Source(); b1 = new Destination(); b2 = new Destination(expected = 1); a.out -> b1._in, b2._in; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/MultiportToReaction.lf b/test/Python/src/multiport/MultiportToReaction.lf index ab4371882a..51430a4a96 100644 --- a/test/Python/src/multiport/MultiportToReaction.lf +++ b/test/Python/src/multiport/MultiportToReaction.lf @@ -2,7 +2,7 @@ target Python { timeout: 2 sec, fast: true -}; +}; reactor Source(width(1)) { timer t(0, 200 msec); state s(0); diff --git a/test/Python/src/multiport/NestedBanks.lf b/test/Python/src/multiport/NestedBanks.lf index 8d5f118ccb..c6cfa4046f 100644 --- a/test/Python/src/multiport/NestedBanks.lf +++ b/test/Python/src/multiport/NestedBanks.lf @@ -8,7 +8,7 @@ c = new[3] C(); d = new D(); e = new E(); - + (a.x)+ -> c.z, d.u, e.t; } reactor A(bank_index(0)) { @@ -43,7 +43,7 @@ reactor E { input[8] t; reaction(t) {= - for (i, p) in enumerate(t): + for (i, p) in enumerate(t): print(f"e.t[{i}] received {p.value}.") =} } @@ -64,4 +64,4 @@ sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2 + 1} but received {s.value}.\n") exit(1) =} - } \ No newline at end of file + } diff --git a/test/Python/src/multiport/NestedInterleavedBanks.lf b/test/Python/src/multiport/NestedInterleavedBanks.lf index e0be0d5595..f38376cb0e 100644 --- a/test/Python/src/multiport/NestedInterleavedBanks.lf +++ b/test/Python/src/multiport/NestedInterleavedBanks.lf @@ -27,8 +27,8 @@ reactor C { exit(1) =} } -main reactor { +main reactor { b = new[2] B(); c = new C(); b.q -> c.i; -} \ No newline at end of file +} diff --git a/test/Python/src/multiport/PipelineAfter.lf b/test/Python/src/multiport/PipelineAfter.lf index e23990e735..1bf8b65bdd 100644 --- a/test/Python/src/multiport/PipelineAfter.lf +++ b/test/Python/src/multiport/PipelineAfter.lf @@ -2,7 +2,7 @@ target Python; reactor Source { output out; - + reaction (startup) -> out {= out.set(40) =} @@ -11,7 +11,7 @@ reactor Source { reactor Compute { input inp; output out; - + reaction (inp) -> out {= out.set(inp.value + 2) =} @@ -19,7 +19,7 @@ reactor Compute { reactor Sink { input inp; - + reaction (inp) {= print(f"Received {inp.value}") if inp.value != 42: @@ -29,7 +29,7 @@ reactor Sink { sys.stderr.write("ERROR: Expected to receive input after one second.\n") exit(2) =} - + } main reactor { @@ -38,4 +38,4 @@ main reactor { sink = new Sink(); source.out, compute.out -> compute.inp, sink.inp after 500 msec; -} \ No newline at end of file +} diff --git a/test/Python/src/serialization/PersonProtocolBuffers.lf b/test/Python/src/serialization/PersonProtocolBuffers.lf index 5bed7c3adf..76a979c2c8 100644 --- a/test/Python/src/serialization/PersonProtocolBuffers.lf +++ b/test/Python/src/serialization/PersonProtocolBuffers.lf @@ -6,13 +6,13 @@ * * To run this example first install the protocol buffers compiler * from https://github.com/protocolbuffers/protobuf. It is also - * available from homebrew on a Mac via - * + * available from homebrew on a Mac via + * * $ brew install protobuf - * + * * Building protobuf from source is slow, so avoid doing that * if possible. Next, install the Google APIs for Python - * + * * $ pip3 install --upgrade google-api-python-client * * The code generator assumes @@ -25,18 +25,18 @@ target Python {protobufs: Person.proto}; main reactor { reaction(startup) {= person = Person.Person() - + person.name = "Lingua Franca" person.id = 1 person.email = "eal@berkeley.edu" # Pack the message into buffer. serialized_msg = person.SerializeToString() - + # Now unpack the message from buffer. unpacked = Person.Person() unpacked.ParseFromString(serialized_msg) - + # Extract and print the unpacked message. print("Name: ", unpacked.name) =} diff --git a/test/Python/src/serialization/ProtoNoPacking.lf b/test/Python/src/serialization/ProtoNoPacking.lf index f294cbdf87..a7798105c8 100644 --- a/test/Python/src/serialization/ProtoNoPacking.lf +++ b/test/Python/src/serialization/ProtoNoPacking.lf @@ -5,15 +5,15 @@ * * To run this example first install the protocol buffers compiler * from https://github.com/protocolbuffers/protobuf. It is also - * available from homebrew on a Mac via - * + * available from homebrew on a Mac via + * * $ brew install protobuf - * + * * Building protobuf from source is slow, so avoid doing that * if possible. Next, install the Google APIs for Python - * + * * $ pip3 install --upgrade google-api-python-client - * + * * The code generator assumes * that executables are installed within the PATH. On a Mac, this is * typically at /usr/local/bin. diff --git a/test/Rust/src/CompositionWithPorts.lf b/test/Rust/src/CompositionWithPorts.lf index 14cdf53038..f03586cc8d 100644 --- a/test/Rust/src/CompositionWithPorts.lf +++ b/test/Rust/src/CompositionWithPorts.lf @@ -1,4 +1,3 @@ - target Rust; reactor Source { output out: i32; diff --git a/test/Rust/src/MainReactorParam.lf b/test/Rust/src/MainReactorParam.lf index 656340d3a3..81863cd68d 100644 --- a/test/Rust/src/MainReactorParam.lf +++ b/test/Rust/src/MainReactorParam.lf @@ -6,4 +6,4 @@ main reactor (one: u64(1152921504606846976), two: u64({= 1 << 60 =})) { reaction(startup) {= assert_eq!(self.one, self.two); =} -} \ No newline at end of file +} diff --git a/test/Rust/src/NativeListsAndTimes.lf b/test/Rust/src/NativeListsAndTimes.lf index a702d8f265..02435eb095 100644 --- a/test/Rust/src/NativeListsAndTimes.lf +++ b/test/Rust/src/NativeListsAndTimes.lf @@ -2,7 +2,7 @@ target Rust; // This test passes if it is successfully compiled into valid target code. -reactor Foo(x: i32(0), +reactor Foo(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 diff --git a/test/Rust/src/Stop.lf b/test/Rust/src/Stop.lf index 6ad1f4e494..1d8a2917b3 100644 --- a/test/Rust/src/Stop.lf +++ b/test/Rust/src/Stop.lf @@ -1,6 +1,6 @@ /* * A test for the request_stop() functionality in Lingua Franca. - * + * * @author Soroush Bateni */ target Rust { @@ -38,7 +38,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); @@ -60,7 +60,7 @@ reactor Consumer { } println!("Tag is {}.", current_tag); =} - + reaction(shutdown) {= let current_tag = ctx.get_tag(); @@ -76,11 +76,11 @@ reactor Consumer { panic!("ERROR: Failed to invoke reaction(in) at tag {}.", current_tag); } =} -} +} main reactor Stop { consumer = new Consumer(); producer = new Sender(break_interval = 1 msec); - + producer.out -> consumer.in_; } diff --git a/test/Rust/src/StopCleanup.lf b/test/Rust/src/StopCleanup.lf index c6d60842e1..0d5a8bfd5e 100644 --- a/test/Rust/src/StopCleanup.lf +++ b/test/Rust/src/StopCleanup.lf @@ -12,7 +12,7 @@ reactor Sender { ctx.request_stop(Asap); // requested for (T0, 1) =} } - + reactor Consumer { input in_: u32; @@ -21,11 +21,11 @@ reactor Consumer { assert_tag_is!(ctx, (T0, 1)); assert!(ctx.get_elapsed_logical_time().is_zero(), "Should be called on startup step"); =} -} +} main reactor StopCleanup { consumer = new Consumer(); producer = new Sender(); - + producer.out -> consumer.in_; } diff --git a/test/Rust/src/TimeState.lf b/test/Rust/src/TimeState.lf index a6e80d095e..3eef66d06e 100644 --- a/test/Rust/src/TimeState.lf +++ b/test/Rust/src/TimeState.lf @@ -2,7 +2,7 @@ target Rust; reactor Foo { state baz: time(500 msec); - + reaction (startup) {= assert_eq!(500, self.baz.as_millis()); =} diff --git a/test/Rust/src/concurrent/Workers.lf b/test/Rust/src/concurrent/Workers.lf index ed2cb125ff..dfa83be2e5 100644 --- a/test/Rust/src/concurrent/Workers.lf +++ b/test/Rust/src/concurrent/Workers.lf @@ -7,4 +7,4 @@ main reactor { println!("Using 16 workers."); } =} -} \ No newline at end of file +} diff --git a/test/Rust/src/multiport/ConnectionToSelfBank.lf b/test/Rust/src/multiport/ConnectionToSelfBank.lf index 5cba0e84a1..12048756de 100644 --- a/test/Rust/src/multiport/ConnectionToSelfBank.lf +++ b/test/Rust/src/multiport/ConnectionToSelfBank.lf @@ -9,7 +9,7 @@ reactor Node(bank_index: usize(0), num_nodes: usize(4)) { reaction (startup) -> out {= ctx.set(out, self.bank_index); =} - + reaction (in) {= let count = r#in.into_iter().filter(|p| ctx.is_present(p)).count(); assert_eq!(count, self.num_nodes); diff --git a/test/Rust/src/multiport/ConnectionToSelfMultiport.lf b/test/Rust/src/multiport/ConnectionToSelfMultiport.lf index f9a251cbc2..ab4b55d212 100644 --- a/test/Rust/src/multiport/ConnectionToSelfMultiport.lf +++ b/test/Rust/src/multiport/ConnectionToSelfMultiport.lf @@ -11,7 +11,7 @@ reactor Node(num_nodes: usize(4)) { ctx.set(out, i) } =} - + reaction (in) {= let count = r#in.into_iter().filter(|p| ctx.is_present(p)).count(); assert_eq!(count, self.num_nodes); diff --git a/test/Rust/src/multiport/MultiportFromBank.lf b/test/Rust/src/multiport/MultiportFromBank.lf index 58d2001370..25d55a5678 100644 --- a/test/Rust/src/multiport/MultiportFromBank.lf +++ b/test/Rust/src/multiport/MultiportFromBank.lf @@ -1,4 +1,4 @@ - // Check bank output to multiport input. +// Check bank output to multiport input. target Rust { timeout: 2 sec, }; diff --git a/test/Rust/src/multiport/MultiportFromHierarchy.lf b/test/Rust/src/multiport/MultiportFromHierarchy.lf index d0fcc4cc75..b4a48da6fe 100644 --- a/test/Rust/src/multiport/MultiportFromHierarchy.lf +++ b/test/Rust/src/multiport/MultiportFromHierarchy.lf @@ -1,4 +1,4 @@ - // Check multiport output to multiport input, where the former is a hierarchical reactor. +// Check multiport output to multiport input, where the former is a hierarchical reactor. target Rust { timeout: 2 sec, }; @@ -10,7 +10,7 @@ reactor Source { for mut chan in out { ctx.set(&mut chan, self.s); self.s += 1; - } + } =} } reactor Destination { @@ -39,7 +39,7 @@ reactor InsideContainer { src.out -> out; } -main reactor MultiportFromHierarchy { +main reactor MultiportFromHierarchy { a = new Container(); b = new Destination(); a.out -> b.in; diff --git a/test/Rust/src/multiport/MultiportIn.lf b/test/Rust/src/multiport/MultiportIn.lf index 794bee37fa..8b72e81d99 100644 --- a/test/Rust/src/multiport/MultiportIn.lf +++ b/test/Rust/src/multiport/MultiportIn.lf @@ -36,7 +36,7 @@ reactor Destination { =} } -main reactor MultiportIn { +main reactor MultiportIn { a = new Source(); t1 = new Computation(); t2 = new Computation(); diff --git a/test/Rust/src/multiport/MultiportOut.lf b/test/Rust/src/multiport/MultiportOut.lf index 234481b82c..255f1c67e2 100644 --- a/test/Rust/src/multiport/MultiportOut.lf +++ b/test/Rust/src/multiport/MultiportOut.lf @@ -9,7 +9,7 @@ reactor Source { reaction(t) -> out {= for i in 0..out.len() { ctx.set(out.get(i), self.s); - } + } self.s += 1; =} } @@ -44,7 +44,7 @@ reactor Destination { =} } -main reactor { +main reactor { a = new Source(); t1 = new Computation(); t2 = new Computation(); diff --git a/test/Rust/src/multiport/MultiportToBank.lf b/test/Rust/src/multiport/MultiportToBank.lf index 80ce808bad..a148b2a96a 100644 --- a/test/Rust/src/multiport/MultiportToBank.lf +++ b/test/Rust/src/multiport/MultiportToBank.lf @@ -1,9 +1,9 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. target Rust; reactor Source { output[4] out: usize; - + reaction (startup) -> out {= for (i, out) in out.into_iter().enumerate() { ctx.set(out, i) diff --git a/test/Rust/src/multiport/MultiportToBankHierarchy.lf b/test/Rust/src/multiport/MultiportToBankHierarchy.lf index 3c48b986a7..bf705b85b2 100644 --- a/test/Rust/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Rust/src/multiport/MultiportToBankHierarchy.lf @@ -1,7 +1,7 @@ - // Check multiport output to bank of recipients within a hierarchy. +// Check multiport output to bank of recipients within a hierarchy. target Rust { timeout: 2 sec, -}; +}; reactor Source { output[3] out: usize; reaction(startup) -> out {= @@ -33,7 +33,7 @@ reactor Container { in -> c.in; } -main reactor MultiportToBankHierarchy { +main reactor MultiportToBankHierarchy { a = new Source(); b = new Container(); a.out -> b.in; diff --git a/test/Rust/src/multiport/MultiportToMultiport.lf b/test/Rust/src/multiport/MultiportToMultiport.lf index 1d232748e3..23c50f1700 100644 --- a/test/Rust/src/multiport/MultiportToMultiport.lf +++ b/test/Rust/src/multiport/MultiportToMultiport.lf @@ -3,7 +3,7 @@ target Rust; reactor Source { output[4] out: usize; - + reaction (startup) -> out {= for (i, out) in out.into_iter().enumerate() { ctx.set(out, i) diff --git a/test/TypeScript/src/ActionDelay.lf b/test/TypeScript/src/ActionDelay.lf index 44b69587af..29f7d687f6 100644 --- a/test/TypeScript/src/ActionDelay.lf +++ b/test/TypeScript/src/ActionDelay.lf @@ -21,7 +21,7 @@ reactor Source { output out:number; reaction(startup) -> out {= out = 1; - =} + =} } reactor Sink { input x:number; @@ -29,7 +29,7 @@ reactor Sink { const elapsed_logical = util.getElapsedLogicalTime(); const logical = util.getCurrentLogicalTime(); const physical = util.getCurrentPhysicalTime(); - console.log("Logical, physical, and elapsed logical: " + logical + physical + elapsed_logical); + console.log("Logical, physical, and elapsed logical: " + logical + physical + elapsed_logical); const oneHundredMsec = TimeValue.msec(100); if (!elapsed_logical.isEqualTo(oneHundredMsec)) { util.requestErrorStop("Expected " + oneHundredMsec + " but got " + elapsed_logical); @@ -42,7 +42,7 @@ main reactor ActionDelay { source = new Source(); sink = new Sink(); g = new GeneratedDelay(); - + source.out -> g.y_in; g.y_out -> sink.x; } diff --git a/test/TypeScript/src/ActionWithNoReaction.lf b/test/TypeScript/src/ActionWithNoReaction.lf index 68bcb64f8b..8da716146d 100644 --- a/test/TypeScript/src/ActionWithNoReaction.lf +++ b/test/TypeScript/src/ActionWithNoReaction.lf @@ -30,4 +30,4 @@ main reactor { f.x = 42; =} f.y -> p.x after 10 msec; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/ArrayAsParameter.lf b/test/TypeScript/src/ArrayAsParameter.lf index 251c0da738..c4e349addb 100644 --- a/test/TypeScript/src/ArrayAsParameter.lf +++ b/test/TypeScript/src/ArrayAsParameter.lf @@ -28,4 +28,4 @@ main reactor ArrayAsParameter { s = new Source(sequence={= [1, 2, 3, 4] =}); p = new Print(); s.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/ArrayAsType.lf b/test/TypeScript/src/ArrayAsType.lf index ed5cd65955..274c05c6a0 100644 --- a/test/TypeScript/src/ArrayAsType.lf +++ b/test/TypeScript/src/ArrayAsType.lf @@ -44,4 +44,4 @@ main reactor ArrayAsType { s = new Source(); p = new Print(); s.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/ArrayPrint.lf b/test/TypeScript/src/ArrayPrint.lf index 7837b38a9f..306a6de14a 100644 --- a/test/TypeScript/src/ArrayPrint.lf +++ b/test/TypeScript/src/ArrayPrint.lf @@ -42,4 +42,4 @@ main reactor { s = new Source(); p = new Print(); s.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Composition.lf b/test/TypeScript/src/Composition.lf index 56050687c2..e68b978168 100644 --- a/test/TypeScript/src/Composition.lf +++ b/test/TypeScript/src/Composition.lf @@ -19,14 +19,14 @@ reactor Test { reaction(x) {= count++; console.log("Received " + x); - if (x != count) { + if (x != count) { util.requestErrorStop("FAILURE: Expected " + count); } - =} + =} } main reactor Composition { s = new Source(); - + d = new Test(); s.y -> d.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/DanglingOutput.lf b/test/TypeScript/src/DanglingOutput.lf index 5f9042d0f3..f348e7d230 100644 --- a/test/TypeScript/src/DanglingOutput.lf +++ b/test/TypeScript/src/DanglingOutput.lf @@ -22,4 +22,4 @@ main reactor DanglingOutput { source = new Source(); container = new Gain(); source.out -> container.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/DeadlineHandledAbove.lf b/test/TypeScript/src/DeadlineHandledAbove.lf index 9e77c905fb..585b7affe1 100644 --- a/test/TypeScript/src/DeadlineHandledAbove.lf +++ b/test/TypeScript/src/DeadlineHandledAbove.lf @@ -35,4 +35,4 @@ main reactor DeadlineHandledAbove { util.requestErrorStop("FAILURE. Container did not react to deadline violation.") } =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/DelayInt.lf b/test/TypeScript/src/DelayInt.lf index 5b950b3219..682938bbe5 100644 --- a/test/TypeScript/src/DelayInt.lf +++ b/test/TypeScript/src/DelayInt.lf @@ -21,13 +21,13 @@ reactor Test { reaction(startup) {= // Record the logical time at the start. start_time = util.getCurrentLogicalTime(); - =} + =} reaction(x) {= console.log("Received: " + x); received_value = true; // Check the time of the input. let current_time = util.getCurrentLogicalTime(); - let elapsed = current_time.subtract(start_time); + let elapsed = current_time.subtract(start_time); console.log("After " + elapsed + " of logical time."); if (!elapsed.isEqualTo(TimeValue.msec(100))) { util.requestErrorStop("ERROR: Expected elapsed time to be [0, 100000000]. It was " + elapsed) @@ -44,11 +44,11 @@ reactor Test { =} } -main reactor DelayInt { +main reactor DelayInt { d = new Delay(); t = new Test(); - d.out -> t.x; + d.out -> t.x; reaction(startup) -> d.x {= d.x = 42; =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/DelayedAction.lf b/test/TypeScript/src/DelayedAction.lf index 12c507aac3..41278c86b9 100644 --- a/test/TypeScript/src/DelayedAction.lf +++ b/test/TypeScript/src/DelayedAction.lf @@ -8,7 +8,7 @@ main reactor DelayedAction { reaction(t) -> a {= actions.a.schedule(TimeValue.msec(100), null); =} - + reaction(a) {= let elapsedLogical = util.getElapsedLogicalTime(); let elapsedPhysical = util.getElapsedPhysicalTime(); @@ -20,4 +20,4 @@ main reactor DelayedAction { util.requestErrorStop("Failure: expected " + expected + " but got " + elapsedLogical); } =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/DelayedReaction.lf b/test/TypeScript/src/DelayedReaction.lf index 6502ff5182..81302fcf23 100644 --- a/test/TypeScript/src/DelayedReaction.lf +++ b/test/TypeScript/src/DelayedReaction.lf @@ -6,7 +6,7 @@ reactor Source { timer t; reaction(t) -> out {= out = 1; - =} + =} } reactor Sink { @@ -23,4 +23,4 @@ main reactor DelayedReaction { source = new Source(); sink = new Sink(); source.out -> sink.x after 100 msec; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Determinism.lf b/test/TypeScript/src/Determinism.lf index 18f4f68bd0..79d77cc7a1 100644 --- a/test/TypeScript/src/Determinism.lf +++ b/test/TypeScript/src/Determinism.lf @@ -5,7 +5,7 @@ reactor Source { reaction(t) -> y {= y = 1; =} -} +} reactor Destination { input x:number; input y:number; @@ -40,4 +40,4 @@ main reactor Determinism { s.y -> p1.x; p1.y -> p2.x; p2.y -> d.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/DoubleInvocation.lf b/test/TypeScript/src/DoubleInvocation.lf index 8b1bfca834..e9e7ec010c 100644 --- a/test/TypeScript/src/DoubleInvocation.lf +++ b/test/TypeScript/src/DoubleInvocation.lf @@ -20,7 +20,7 @@ reactor Ball { timer trigger(0, 1 sec); reaction(trigger) -> position, velocity {= position = p; - velocity = -1; + velocity = -1; p -= 1; =} } @@ -48,4 +48,4 @@ main reactor DoubleInvocation { b1.velocity -> p.velocity; b1.position -> plot.position; b1.velocity -> plot.velocity; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/DoubleTrigger.lf b/test/TypeScript/src/DoubleTrigger.lf index cf8f76572d..fe1f9c1d45 100644 --- a/test/TypeScript/src/DoubleTrigger.lf +++ b/test/TypeScript/src/DoubleTrigger.lf @@ -1,4 +1,4 @@ -// Test that two simultaneous triggers don't cause +// Test that two simultaneous triggers don't cause // a reaction to execute twice at the same tag. target TypeScript { fast: true, diff --git a/test/TypeScript/src/Gain.lf b/test/TypeScript/src/Gain.lf index 8193ebb862..d646207d51 100644 --- a/test/TypeScript/src/Gain.lf +++ b/test/TypeScript/src/Gain.lf @@ -33,4 +33,4 @@ reaction(startup) -> g.x {= g.x = 1; =} - } \ No newline at end of file + } diff --git a/test/TypeScript/src/GetTime.lf b/test/TypeScript/src/GetTime.lf index c4af03e421..b2d24fec3b 100644 --- a/test/TypeScript/src/GetTime.lf +++ b/test/TypeScript/src/GetTime.lf @@ -13,10 +13,10 @@ main reactor GetTime { let elapsed = util.getElapsedLogicalTime(); console.log("Elapsed logical time is " + elapsed); - + let physical = util.getCurrentPhysicalTime(); console.log("Physical time is " + physical); - + console.log("Time lag is " + physical.subtract(logical)); =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Hello.lf b/test/TypeScript/src/Hello.lf index 2107303cf0..bbd15d36a1 100644 --- a/test/TypeScript/src/Hello.lf +++ b/test/TypeScript/src/Hello.lf @@ -32,12 +32,12 @@ reactor Reschedule(period:time(2 secs), message:string("Hello TypeScript")) { currentTime.subtract(previous_time)); } =} -} +} reactor Inside(period:time(1 sec), message:string("Composite default message.")) { third_instance = new Reschedule(period = period, message = message); } -main reactor Hello { +main reactor Hello { first_instance = new Reschedule(period = 4 sec, message = "Hello from first_instance."); second_instance = new Reschedule(message = "Hello from second_instance."); composite_instance = new Inside(message = "Hello from composite_instance."); -} \ No newline at end of file +} diff --git a/test/TypeScript/src/HelloWorld.lf b/test/TypeScript/src/HelloWorld.lf index de69933c64..2959362396 100644 --- a/test/TypeScript/src/HelloWorld.lf +++ b/test/TypeScript/src/HelloWorld.lf @@ -7,4 +7,4 @@ reactor HelloWorldInside { } main reactor HelloWorld { a = new HelloWorldInside(); -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Hierarchy.lf b/test/TypeScript/src/Hierarchy.lf index 4988fed7bb..7af676436e 100644 --- a/test/TypeScript/src/Hierarchy.lf +++ b/test/TypeScript/src/Hierarchy.lf @@ -39,8 +39,8 @@ main reactor Hierarchy { source = new Source(); container = new GainContainer(); print = new Print(); - print2 = new Print(); + print2 = new Print(); source.out -> container.x; container.out -> print.x; container.out -> print2.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Hierarchy2.lf b/test/TypeScript/src/Hierarchy2.lf index 95b0461789..9abd0016d1 100644 --- a/test/TypeScript/src/Hierarchy2.lf +++ b/test/TypeScript/src/Hierarchy2.lf @@ -56,4 +56,4 @@ main reactor Hierarchy2 { print = new Print(); source.out -> addCount.x; addCount.out -> print.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Import.lf b/test/TypeScript/src/Import.lf index 66422d71f8..858239ba56 100644 --- a/test/TypeScript/src/Import.lf +++ b/test/TypeScript/src/Import.lf @@ -6,7 +6,7 @@ target TypeScript{ import Imported from "lib/Imported.lf"; main reactor Import { timer t; - a = new Imported(); + a = new Imported(); reaction(t) -> a.x {= a.x = 42; =} diff --git a/test/TypeScript/src/Microsteps.lf b/test/TypeScript/src/Microsteps.lf index 3affd5586d..fda8da8424 100644 --- a/test/TypeScript/src/Microsteps.lf +++ b/test/TypeScript/src/Microsteps.lf @@ -33,4 +33,4 @@ main reactor Microsteps { reaction(repeat) -> d.y {= d.y = 1; =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Minimal.lf b/test/TypeScript/src/Minimal.lf index eb898fe1b7..cf11d685c1 100644 --- a/test/TypeScript/src/Minimal.lf +++ b/test/TypeScript/src/Minimal.lf @@ -5,4 +5,4 @@ main reactor Minimal { reaction(t) {= console.log("Hello World."); =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/MovingAverage.lf b/test/TypeScript/src/MovingAverage.lf index 06aa2eb8df..cfab964927 100644 --- a/test/TypeScript/src/MovingAverage.lf +++ b/test/TypeScript/src/MovingAverage.lf @@ -58,4 +58,4 @@ main reactor MovingAverage { p = new Print(); s.out -> m.x; m.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/MultipleContained.lf b/test/TypeScript/src/MultipleContained.lf index a41a8a92f2..4bdf56fe3f 100644 --- a/test/TypeScript/src/MultipleContained.lf +++ b/test/TypeScript/src/MultipleContained.lf @@ -30,4 +30,4 @@ main reactor MultipleContained { c.in1 = c.trigger; c.in2 = c.trigger; =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/NativeListsAndTimes.lf b/test/TypeScript/src/NativeListsAndTimes.lf index 7af003c3ed..bee545bc24 100644 --- a/test/TypeScript/src/NativeListsAndTimes.lf +++ b/test/TypeScript/src/NativeListsAndTimes.lf @@ -1,9 +1,9 @@ target TypeScript; // This test passes if it is successfully compiled into valid target code. -main reactor (x:number(0), +main reactor (x:number(0), y:time(0), // Units are missing but not required z(1 msec), // Type is missing but not required - p:number[](1, 2, 3, 4), // List of integers + p:number[](1, 2, 3, 4), // List of integers q:TimeValue[](1 msec, 2 msec, 3 msec), // list of time values r:time({=0=}), // Zero-valued target code also is a valid time g:time[](1 msec, 2 msec) // List of time values @@ -22,4 +22,4 @@ main reactor (x:number(0), // Target code =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/ParameterizedState.lf b/test/TypeScript/src/ParameterizedState.lf index 1784606a61..d5ef18195e 100644 --- a/test/TypeScript/src/ParameterizedState.lf +++ b/test/TypeScript/src/ParameterizedState.lf @@ -8,4 +8,4 @@ reactor Foo(bar:number(42)) { } main reactor { a = new Foo(); -} \ No newline at end of file +} diff --git a/test/TypeScript/src/PeriodicDesugared.lf b/test/TypeScript/src/PeriodicDesugared.lf index 5236e3551b..97b7e0df58 100644 --- a/test/TypeScript/src/PeriodicDesugared.lf +++ b/test/TypeScript/src/PeriodicDesugared.lf @@ -1,11 +1,11 @@ target TypeScript; main reactor ( - offset:time(0), + offset:time(0), period:time(500 msec)) { logical action init(offset); logical action recur(period); state count:number(0); - + reaction(startup) -> init, recur {= if (offset.isZero()) { console.log("Hello World!"); @@ -14,7 +14,7 @@ main reactor ( actions.init.schedule(0, null); } =} - + reaction(init, recur) -> recur {= console.log("Hello World!"); actions.recur.schedule(0, null); diff --git a/test/TypeScript/src/Preamble.lf b/test/TypeScript/src/Preamble.lf index 101674c0a4..a398ab0e29 100644 --- a/test/TypeScript/src/Preamble.lf +++ b/test/TypeScript/src/Preamble.lf @@ -15,4 +15,4 @@ main reactor Preamble { console.log("Converted string " + s + " to number " + i); console.log("42 plus 42 is " + add42(42)); =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/ReadOutputOfContainedReactor.lf b/test/TypeScript/src/ReadOutputOfContainedReactor.lf index 1f67f10591..80a6b4311e 100644 --- a/test/TypeScript/src/ReadOutputOfContainedReactor.lf +++ b/test/TypeScript/src/ReadOutputOfContainedReactor.lf @@ -39,4 +39,4 @@ main reactor ReadOutputOfContainedReactor { console.log("Test passes."); } =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Schedule.lf b/test/TypeScript/src/Schedule.lf index 6ecdafe743..010a163313 100644 --- a/test/TypeScript/src/Schedule.lf +++ b/test/TypeScript/src/Schedule.lf @@ -22,4 +22,4 @@ main reactor { reaction(t) -> a.x {= a.x = 1; =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/ScheduleLogicalAction.lf b/test/TypeScript/src/ScheduleLogicalAction.lf index afbe58ce23..c6351deeb0 100644 --- a/test/TypeScript/src/ScheduleLogicalAction.lf +++ b/test/TypeScript/src/ScheduleLogicalAction.lf @@ -40,4 +40,4 @@ main reactor { f.x = 42; =} f.y -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/SendingInside.lf b/test/TypeScript/src/SendingInside.lf index b1343f36fc..5ddb809d6c 100644 --- a/test/TypeScript/src/SendingInside.lf +++ b/test/TypeScript/src/SendingInside.lf @@ -24,4 +24,4 @@ main reactor SendingInside { count++; p.x = count; =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/SendingInside2.lf b/test/TypeScript/src/SendingInside2.lf index 69fe9320e4..e8075b6ecc 100644 --- a/test/TypeScript/src/SendingInside2.lf +++ b/test/TypeScript/src/SendingInside2.lf @@ -14,4 +14,4 @@ main reactor SendingInside2 { reaction(t) -> p.x {= p.x = 1; =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/SendsPointerTest.lf b/test/TypeScript/src/SendsPointerTest.lf index 17549ecc20..1582f37919 100644 --- a/test/TypeScript/src/SendsPointerTest.lf +++ b/test/TypeScript/src/SendsPointerTest.lf @@ -23,4 +23,4 @@ main reactor SendsPointerTest { s = new SendsPointer(); p = new Print(); s.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/SimpleDeadline.lf b/test/TypeScript/src/SimpleDeadline.lf index 62b33c8228..53b987fa2a 100644 --- a/test/TypeScript/src/SimpleDeadline.lf +++ b/test/TypeScript/src/SimpleDeadline.lf @@ -33,4 +33,4 @@ main reactor SimpleDeadline { while(util.getCurrentPhysicalTime().isEarlierThan(finishTime)); d.x = 42; =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/SlowingClock.lf b/test/TypeScript/src/SlowingClock.lf index e044db63f1..3d88749bb1 100644 --- a/test/TypeScript/src/SlowingClock.lf +++ b/test/TypeScript/src/SlowingClock.lf @@ -25,4 +25,4 @@ main reactor SlowingClock { util.requestErrorStop("ERROR: Expected the next expected time to be: " + TimeValue.msec(5500) + "It was: " + expected_time) } =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Stride.lf b/test/TypeScript/src/Stride.lf index 9274143d42..2a4840e898 100644 --- a/test/TypeScript/src/Stride.lf +++ b/test/TypeScript/src/Stride.lf @@ -23,4 +23,4 @@ main reactor Stride { c = new Count(stride = 2); d = new Display(); c.y -> d.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/StructAsState.lf b/test/TypeScript/src/StructAsState.lf index b68bacb4dc..da823f5fef 100644 --- a/test/TypeScript/src/StructAsState.lf +++ b/test/TypeScript/src/StructAsState.lf @@ -14,4 +14,4 @@ main reactor StructAsState { util.requestErrorStop("FAILED: Expected 42."); } =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/StructAsType.lf b/test/TypeScript/src/StructAsType.lf index 253ca98bd0..055b92d6ba 100644 --- a/test/TypeScript/src/StructAsType.lf +++ b/test/TypeScript/src/StructAsType.lf @@ -31,4 +31,4 @@ main reactor { s = new Source(); p = new Print(); s.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/StructAsTypeDirect.lf b/test/TypeScript/src/StructAsTypeDirect.lf index f43da4cff8..3ff45ded04 100644 --- a/test/TypeScript/src/StructAsTypeDirect.lf +++ b/test/TypeScript/src/StructAsTypeDirect.lf @@ -31,4 +31,4 @@ main reactor { s = new Source(); p = new Print(); s.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/StructPrint.lf b/test/TypeScript/src/StructPrint.lf index fce08c0338..e22597da88 100644 --- a/test/TypeScript/src/StructPrint.lf +++ b/test/TypeScript/src/StructPrint.lf @@ -29,4 +29,4 @@ main reactor StructPrint { s = new Source(); p = new Print(); s.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/StructScale.lf b/test/TypeScript/src/StructScale.lf index 0c76f005ff..d5614239c8 100644 --- a/test/TypeScript/src/StructScale.lf +++ b/test/TypeScript/src/StructScale.lf @@ -22,4 +22,4 @@ main reactor StructScale { p = new Print(expected=84); s.out -> c.x; c.out -> p.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/TestForPreviousOutput.lf b/test/TypeScript/src/TestForPreviousOutput.lf index 3797800930..33ecdd3675 100644 --- a/test/TypeScript/src/TestForPreviousOutput.lf +++ b/test/TypeScript/src/TestForPreviousOutput.lf @@ -33,4 +33,4 @@ main reactor TestForPreviousOutput { s = new Source(); d = new Sink(); s.out -> d.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/TimeLimit.lf b/test/TypeScript/src/TimeLimit.lf index ef8857fd32..7a0bdac0f2 100644 --- a/test/TypeScript/src/TimeLimit.lf +++ b/test/TypeScript/src/TimeLimit.lf @@ -24,7 +24,7 @@ reactor Destination { if (x != s) { util.requestErrorStop("Error: Expected " + s + " and got " + x + ".") } - s++; + s++; =} } diff --git a/test/TypeScript/src/TimeState.lf b/test/TypeScript/src/TimeState.lf index 1994bb8a0e..d55cbff534 100644 --- a/test/TypeScript/src/TimeState.lf +++ b/test/TypeScript/src/TimeState.lf @@ -2,7 +2,7 @@ target TypeScript; reactor Foo(bar:number(42)) { state baz:time(500 msec); - + reaction (startup) {= console.log("Baz: " + baz); =} @@ -10,4 +10,4 @@ reactor Foo(bar:number(42)) { main reactor { a = new Foo(); -} \ No newline at end of file +} diff --git a/test/TypeScript/src/Wcet.lf b/test/TypeScript/src/Wcet.lf index 2f2d83d26d..3fcb3ef172 100644 --- a/test/TypeScript/src/Wcet.lf +++ b/test/TypeScript/src/Wcet.lf @@ -34,8 +34,8 @@ main reactor Wcet { source = new Source(); work = new Work(); print = new Print(); - + source.out1 -> work.in1; source.out2 -> work.in2; work.out -> print.x; -} \ No newline at end of file +} diff --git a/test/TypeScript/src/concurrent/AsyncCallback.lf b/test/TypeScript/src/concurrent/AsyncCallback.lf index 485c786efe..09a7754551 100644 --- a/test/TypeScript/src/concurrent/AsyncCallback.lf +++ b/test/TypeScript/src/concurrent/AsyncCallback.lf @@ -34,7 +34,7 @@ main reactor AsyncCallback { let elapsed_time = util.getElapsedLogicalTime(); console.log("Asynchronous callback " + i + ": Assigned logical time greater than start time by " + elapsed_time + " nsec." - ); + ); if (elapsed_time.isEarlierThan(expected_time)) { util.requestErrorStop("ERROR: Expected logical time to be larger than " + expected_time + ".") } diff --git a/test/TypeScript/src/docker/HelloWorldContainerized.lf b/test/TypeScript/src/docker/HelloWorldContainerized.lf index 051d783309..831a3afd18 100644 --- a/test/TypeScript/src/docker/HelloWorldContainerized.lf +++ b/test/TypeScript/src/docker/HelloWorldContainerized.lf @@ -6,4 +6,4 @@ import HelloWorldInside from "../HelloWorld.lf" main reactor HelloWorldContainerized { a = new HelloWorldInside(); -} \ No newline at end of file +} diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf index d58c38e0da..1940553c2a 100644 --- a/test/TypeScript/src/federated/DistributedCount.lf +++ b/test/TypeScript/src/federated/DistributedCount.lf @@ -32,7 +32,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.inp after offset; diff --git a/test/TypeScript/src/federated/PingPongDistributed.lf b/test/TypeScript/src/federated/PingPongDistributed.lf index d96434f8d3..e10c0ff8c2 100644 --- a/test/TypeScript/src/federated/PingPongDistributed.lf +++ b/test/TypeScript/src/federated/PingPongDistributed.lf @@ -3,7 +3,7 @@ */ target TypeScript; - + reactor Ping(count:number(10)) { input receive:number; output send:number; diff --git a/test/TypeScript/src/lib/Imported.lf b/test/TypeScript/src/lib/Imported.lf index e33241d158..d06260e695 100644 --- a/test/TypeScript/src/lib/Imported.lf +++ b/test/TypeScript/src/lib/Imported.lf @@ -9,5 +9,5 @@ reactor Imported { a = new ImportedAgain(); reaction(x) -> a.x {= a.x = (x as number); - =} + =} } diff --git a/test/TypeScript/src/lib/ImportedAgain.lf b/test/TypeScript/src/lib/ImportedAgain.lf index 71074b8717..68eec84e7b 100644 --- a/test/TypeScript/src/lib/ImportedAgain.lf +++ b/test/TypeScript/src/lib/ImportedAgain.lf @@ -11,4 +11,4 @@ reactor ImportedAgain { util.requestErrorStop("ERROR: Expected input to be 42. Got: " + x); } =} -} \ No newline at end of file +} diff --git a/test/TypeScript/src/lib/TestCount.lf b/test/TypeScript/src/lib/TestCount.lf index 0acfad7365..b7e8399f8f 100644 --- a/test/TypeScript/src/lib/TestCount.lf +++ b/test/TypeScript/src/lib/TestCount.lf @@ -2,7 +2,7 @@ * Test that a counting sequence of inputs starts with the specified start * parameter value, increments by the specified stride, and receives the * specified number of inputs. - * + * * @param start The starting value for the expected inputs. Default is 1. * @param stride The increment for the inputs. Default is 1. * @param numInputs The number of inputs expected. Default is 1. diff --git a/test/TypeScript/src/multiport/BankMulticast.lf b/test/TypeScript/src/multiport/BankMulticast.lf index 8e00efc69f..155e569c8d 100644 --- a/test/TypeScript/src/multiport/BankMulticast.lf +++ b/test/TypeScript/src/multiport/BankMulticast.lf @@ -12,26 +12,26 @@ import TestCount from "../lib/TestCount.lf" reactor Foo { input inp:number; output out:number; - + c = new Count(); c.out -> out; - + d = new TestCount(numInputs = 4); inp -> d.inp; } reactor Bar { output[4] out:number; - + foo = new[4] Foo(); - + foo.out -> foo.inp; foo.out -> out; } main reactor { bar = new Bar(); - + d = new[4] TestCount(numInputs = 4); bar.out -> d.inp; } diff --git a/test/TypeScript/src/multiport/BankMultiportToReaction.lf b/test/TypeScript/src/multiport/BankMultiportToReaction.lf index f6e4b75e70..b9b4637609 100644 --- a/test/TypeScript/src/multiport/BankMultiportToReaction.lf +++ b/test/TypeScript/src/multiport/BankMultiportToReaction.lf @@ -15,7 +15,7 @@ main reactor { state received:boolean(false); s = new[2] DoubleCount(); - + reaction(s.out) {= for (let i = 0; i < s.length; i++) { for (let j = 0; j < s[0].out.length; j++) { @@ -25,10 +25,10 @@ main reactor { util.requestErrorStop("Expected " + count + "."); } received = true; - } + } } - } - count++; + } + count++; =} reaction(shutdown) {= if (!received) { diff --git a/test/TypeScript/src/multiport/BankReactionsInContainer.lf b/test/TypeScript/src/multiport/BankReactionsInContainer.lf index ffe0e3d588..a973172aa6 100644 --- a/test/TypeScript/src/multiport/BankReactionsInContainer.lf +++ b/test/TypeScript/src/multiport/BankReactionsInContainer.lf @@ -8,7 +8,7 @@ reactor R { output[2] out:number; input[2] inp:number; state received:boolean(false); - + reaction(startup) -> out {= for (let i = 0; i < out.length; i++) { let value = this.getBankIndex() * 2 + i; @@ -39,7 +39,7 @@ reactor R { main reactor { s = new[2] R(); state received:boolean(false); - + reaction(startup) -> s.inp {= let count = 0; for (let i = 0; i < s.length; i++) { diff --git a/test/TypeScript/src/multiport/BankSelfBroadcast.lf b/test/TypeScript/src/multiport/BankSelfBroadcast.lf index 3f0c42f6fc..2b93008501 100644 --- a/test/TypeScript/src/multiport/BankSelfBroadcast.lf +++ b/test/TypeScript/src/multiport/BankSelfBroadcast.lf @@ -3,7 +3,7 @@ * back to a multiport input of the same reactors in the bank * so that each reactor in the bank receives the output * produced by itself and each other reactor. - * + * * @author Edward A. Lee * @author Christian Menard * @author Hokeun Kim diff --git a/test/TypeScript/src/multiport/BankToBank.lf b/test/TypeScript/src/multiport/BankToBank.lf index 52a6d2995a..5661085066 100644 --- a/test/TypeScript/src/multiport/BankToBank.lf +++ b/test/TypeScript/src/multiport/BankToBank.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors. +// Check bank of reactors sending to bank of reactors. target TypeScript { timeout: 2 sec }; diff --git a/test/TypeScript/src/multiport/BankToBankMultiport.lf b/test/TypeScript/src/multiport/BankToBankMultiport.lf index 2ec1c132df..10274e5855 100644 --- a/test/TypeScript/src/multiport/BankToBankMultiport.lf +++ b/test/TypeScript/src/multiport/BankToBankMultiport.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target TypeScript { timeout: 2 sec }; diff --git a/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf b/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf index 5fac9a2dd1..e7321fce11 100644 --- a/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf +++ b/test/TypeScript/src/multiport/BankToBankMultiportAfter.lf @@ -1,4 +1,4 @@ - // Check bank of reactors sending to bank of reactors with multiports. +// Check bank of reactors sending to bank of reactors with multiports. target TypeScript { timeout: 2 sec }; diff --git a/test/TypeScript/src/multiport/BankToMultiport.lf b/test/TypeScript/src/multiport/BankToMultiport.lf index ef8b4abf83..bb12cf2d43 100644 --- a/test/TypeScript/src/multiport/BankToMultiport.lf +++ b/test/TypeScript/src/multiport/BankToMultiport.lf @@ -2,7 +2,7 @@ target TypeScript; reactor Source { output out:number; - + reaction (startup) -> out {= out = this.getBankIndex(); =} @@ -11,7 +11,7 @@ reactor Source { reactor Sink { input[4] inp:number; state received:boolean(false); - + reaction (inp) {= for (let i = 0; i < inp.length; i++) { received = true; diff --git a/test/TypeScript/src/multiport/BankToReaction.lf b/test/TypeScript/src/multiport/BankToReaction.lf index 711ab5328b..087fe4d01b 100644 --- a/test/TypeScript/src/multiport/BankToReaction.lf +++ b/test/TypeScript/src/multiport/BankToReaction.lf @@ -7,14 +7,14 @@ main reactor { state count:number(1); s = new[2] Count(); - + reaction(s.out) {= for (let i = 0; i < s.length; i++) { console.log("Received " + s[i].out + "."); if (count != s[i].out) { util.requestErrorStop("Expected " + count + "."); - } + } } - count++; + count++; =} } diff --git a/test/TypeScript/src/multiport/Broadcast.lf b/test/TypeScript/src/multiport/Broadcast.lf index 46e229e562..a2a3dfe151 100644 --- a/test/TypeScript/src/multiport/Broadcast.lf +++ b/test/TypeScript/src/multiport/Broadcast.lf @@ -2,7 +2,7 @@ target TypeScript; reactor Source { output out:number; - + reaction (startup) -> out {= out = 42; =} @@ -10,7 +10,7 @@ reactor Source { reactor Sink { input inp:number; - + reaction (inp) {= console.log("Received " + inp); if (inp != 42) { diff --git a/test/TypeScript/src/multiport/BroadcastAfter.lf b/test/TypeScript/src/multiport/BroadcastAfter.lf index 5fd9740866..2c2052a327 100644 --- a/test/TypeScript/src/multiport/BroadcastAfter.lf +++ b/test/TypeScript/src/multiport/BroadcastAfter.lf @@ -1,10 +1,10 @@ target TypeScript { timeout: 2 sec -}; +}; reactor Source { output out:number; - + reaction(startup) -> out {= out = 42; =} @@ -32,7 +32,7 @@ reactor Destination { =} } -main reactor { +main reactor { a = new Source(); b = new[4] Destination(); (a.out)+ -> b.inp after 1 sec; diff --git a/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf b/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf index f1e54ad0b3..47157195fa 100644 --- a/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf +++ b/test/TypeScript/src/multiport/BroadcastMultipleAfter.lf @@ -1,10 +1,10 @@ target TypeScript { timeout: 2 sec -}; +}; reactor Source(value:number(42)) { output out:number; - + reaction(startup) -> out {= out = value; =} diff --git a/test/TypeScript/src/multiport/FullyConnected.lf b/test/TypeScript/src/multiport/FullyConnected.lf index 6621d88cd5..80fb68b83b 100644 --- a/test/TypeScript/src/multiport/FullyConnected.lf +++ b/test/TypeScript/src/multiport/FullyConnected.lf @@ -5,7 +5,7 @@ reactor Node( ) { input[numNodes] inp: number; output out: number; - + state received: boolean(false); reaction (startup) -> out{= @@ -13,7 +13,7 @@ reactor Node( // broadcast my ID to everyone out = this.getBankIndex(); =} - + reaction (inp) {= console.log("Node " + this.getBankIndex() + " received messages from "); let count = 0; diff --git a/test/TypeScript/src/multiport/MultiportFromBank.lf b/test/TypeScript/src/multiport/MultiportFromBank.lf index 30c928029c..a360bb41ba 100644 --- a/test/TypeScript/src/multiport/MultiportFromBank.lf +++ b/test/TypeScript/src/multiport/MultiportFromBank.lf @@ -2,7 +2,7 @@ // Here, the bank is smaller than the width of the sending port. target TypeScript { timeout: 2 sec -}; +}; reactor Source { output out:number; reaction(startup) -> out {= diff --git a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf index c18de5366a..2db6644a39 100644 --- a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,8 +1,8 @@ - // Check multiport output to bank of recipients. +// Check multiport output to bank of recipients. // Here, the bank is smaller than the width of the sending port. target TypeScript { timeout: 2 sec -}; +}; import Destination from "MultiportFromBank.lf" import Container from "MultiportFromBankHierarchy.lf" diff --git a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf index abdfa1fee7..c2466edce9 100644 --- a/test/TypeScript/src/multiport/MultiportFromHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportFromHierarchy.lf @@ -1,7 +1,7 @@ // Check multiport output to multiport input, where the former is a hierarchical reactor. target TypeScript { timeout: 2 sec -}; +}; reactor Source(width:number(3)) { timer t(0, 200 msec); output[width] out:number; diff --git a/test/TypeScript/src/multiport/MultiportFromReaction.lf b/test/TypeScript/src/multiport/MultiportFromReaction.lf index 657e15eef3..ec2d74eb3e 100644 --- a/test/TypeScript/src/multiport/MultiportFromReaction.lf +++ b/test/TypeScript/src/multiport/MultiportFromReaction.lf @@ -1,7 +1,7 @@ // Check reaction to multiport input of a contained reactor. target TypeScript { timeout: 2 sec -}; +}; reactor Destination(width:number(1)) { state s:number(6); input[width] inp:number; @@ -37,4 +37,3 @@ main reactor MultiportFromReaction(width:number(4)) { =} b = new Destination(width = width); } - diff --git a/test/TypeScript/src/multiport/MultiportIn.lf b/test/TypeScript/src/multiport/MultiportIn.lf index b774fb5666..50d3dd8153 100644 --- a/test/TypeScript/src/multiport/MultiportIn.lf +++ b/test/TypeScript/src/multiport/MultiportIn.lf @@ -31,7 +31,7 @@ reactor Destination { } else { sum += val; } - } + } console.log("Sum of received: " + sum + "."); if (sum != s) { util.requestErrorStop("ERROR: Expected " + s + "."); @@ -46,7 +46,7 @@ reactor Destination { =} } -main reactor MultiportIn { +main reactor MultiportIn { a = new Source(); t1 = new Computation(); t2 = new Computation(); diff --git a/test/TypeScript/src/multiport/MultiportInParameterized.lf b/test/TypeScript/src/multiport/MultiportInParameterized.lf index ffd11d2561..f0ddfc3c5f 100644 --- a/test/TypeScript/src/multiport/MultiportInParameterized.lf +++ b/test/TypeScript/src/multiport/MultiportInParameterized.lf @@ -30,7 +30,7 @@ reactor Destination(width:number(1)) { if (val !== undefined) { sum += val; } - } + } console.log("Sum of received: " + sum + "."); if (sum != s) { util.requestErrorStop("ERROR: Expected " + s + "."); diff --git a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf index 15a68648e9..c6e74464ed 100644 --- a/test/TypeScript/src/multiport/MultiportMutableInputArray.lf +++ b/test/TypeScript/src/multiport/MultiportMutableInputArray.lf @@ -10,7 +10,7 @@ reactor Source { reaction(startup) -> out {= // Dynamically allocate an output array of length 3. out[0] = new Array(3); - + // Above allocates the array, which then must be populated. out[0][0] = 0; out[0][1] = 1; @@ -18,7 +18,7 @@ reactor Source { // Dynamically allocate an output array of length 3. out[1] = new Array(3); - + // Above allocates the array, which then must be populated. out[1][0] = 3; out[1][1] = 4; diff --git a/test/TypeScript/src/multiport/MultiportToBank.lf b/test/TypeScript/src/multiport/MultiportToBank.lf index 5cf903c36b..381154ed24 100644 --- a/test/TypeScript/src/multiport/MultiportToBank.lf +++ b/test/TypeScript/src/multiport/MultiportToBank.lf @@ -2,7 +2,7 @@ target TypeScript; reactor Source { output[4] out:number; - + reaction (startup) -> out {= for (let i = 0 ; i < out.length; i++) { out[i] = i; @@ -12,7 +12,7 @@ reactor Source { reactor Sink { input inp:number; - + reaction (inp) {= console.log("Received " + inp); if (inp != this.getBankIndex()) { diff --git a/test/TypeScript/src/multiport/MultiportToBankAfter.lf b/test/TypeScript/src/multiport/MultiportToBankAfter.lf index 3bb2af6888..abe2ef1a37 100644 --- a/test/TypeScript/src/multiport/MultiportToBankAfter.lf +++ b/test/TypeScript/src/multiport/MultiportToBankAfter.lf @@ -1,7 +1,7 @@ // Check multiport output to bank of recipients where the width of the bank is inferred. target TypeScript { timeout: 2 sec -}; +}; reactor Source(width:number(2)) { output[width] out:number; reaction(startup) -> out {= @@ -33,7 +33,7 @@ reactor Destination { =} } -main reactor(width:number(3)) { +main reactor(width:number(3)) { a = new Source(width = width); b = new[width] Destination(); a.out -> b.inp after 1 sec; // Width of the bank of delays will be inferred. diff --git a/test/TypeScript/src/multiport/MultiportToBankDouble.lf b/test/TypeScript/src/multiport/MultiportToBankDouble.lf index 7b8964bcb9..3fcaa49ce6 100644 --- a/test/TypeScript/src/multiport/MultiportToBankDouble.lf +++ b/test/TypeScript/src/multiport/MultiportToBankDouble.lf @@ -1,8 +1,8 @@ - // Check multiport output to bank of recipients where the source +// Check multiport output to bank of recipients where the source // has two reactions that write to the output. target TypeScript { timeout: 2 sec -}; +}; reactor Source { output[3] out:number; // Connected to a bank of Destination reactors reaction(startup) -> out {= @@ -12,7 +12,7 @@ reactor Source { =} // Test also that multiple appearances of the same effect port // do not result in multiple allocations of memory for the port. - reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) + reaction(startup) -> out {= // Contents of the reactions does not matter (either could be empty) for (let i = 0; i < out.length; i++) { out[i] = i * 2; } @@ -36,7 +36,7 @@ reactor Destination { =} } -main reactor { +main reactor { a = new Source(); b = new[3] Destination(); a.out -> b.inp; diff --git a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf index dd8d18110d..b97a3ee682 100644 --- a/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToBankHierarchy.lf @@ -2,7 +2,7 @@ // Here, the bank is smaller than the width of the sending port. target TypeScript { timeout: 2 sec -}; +}; reactor Source { output[3] out:number; reaction(startup) -> out {= @@ -34,7 +34,7 @@ reactor Container { inp -> c.inp; } -main reactor MultiportToBankHierarchy { +main reactor MultiportToBankHierarchy { a = new Source(); b = new Container(); a.out -> b.inp; diff --git a/test/TypeScript/src/multiport/MultiportToHierarchy.lf b/test/TypeScript/src/multiport/MultiportToHierarchy.lf index 132ba10120..32f2ea1326 100644 --- a/test/TypeScript/src/multiport/MultiportToHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToHierarchy.lf @@ -1,8 +1,8 @@ - // Check multiport output to multiport input, where the latter is a hierarchical reactor. +// Check multiport output to multiport input, where the latter is a hierarchical reactor. // Note that the destination reactor has width wider than the sender, so one input is dangling. target TypeScript { timeout: 2 sec, -}; +}; reactor Source(width:number(4)) { timer t(0, 200 msec); output[width] out:number; diff --git a/test/TypeScript/src/multiport/MultiportToMultiport.lf b/test/TypeScript/src/multiport/MultiportToMultiport.lf index ac01b63b92..054e0bdb48 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiport.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiport.lf @@ -2,7 +2,7 @@ target TypeScript; reactor Source { output[4] out:number; - + reaction (startup) -> out {= for (let i = 0; i < out.length; i++) { out[i] = i; @@ -13,7 +13,7 @@ reactor Source { reactor Sink { input[4] inp:number; state received:boolean(false); - + reaction (inp) {= for (let i = 0; i < inp.length; i++) { console.log("Received " + inp[i]); diff --git a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf index bb455d3715..72e9467457 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiportArray.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiportArray.lf @@ -2,7 +2,7 @@ // Destination port is wider than sending port. target TypeScript { timeout: 2 sec -}; +}; reactor Source { timer t(0, 200 msec); output[2] out:{=Array=}; @@ -48,7 +48,7 @@ reactor Destination { =} } -main reactor MultiportToMultiportArray { +main reactor MultiportToMultiportArray { a = new Source(); b = new Destination(); a.out -> b.inp; diff --git a/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf b/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf index 71fd5a3474..df67a3f57c 100644 --- a/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf +++ b/test/TypeScript/src/multiport/MultiportToMultiportParameter.lf @@ -1,7 +1,7 @@ // Check multiport output to multiport input. target TypeScript { timeout: 2 sec -}; +}; reactor Source(width:number(1)) { timer t(0, 200 msec); output[width] out:number; diff --git a/test/TypeScript/src/multiport/MultiportToPort.lf b/test/TypeScript/src/multiport/MultiportToPort.lf index 49d0de0af7..987167667c 100644 --- a/test/TypeScript/src/multiport/MultiportToPort.lf +++ b/test/TypeScript/src/multiport/MultiportToPort.lf @@ -2,7 +2,7 @@ // Destination port is wider than sending port. target TypeScript { timeout: 2 sec -}; +}; reactor Source { output[2] out:number; reaction(startup) -> out {= @@ -30,7 +30,7 @@ reactor Destination(expected:number(0)) { =} } -main reactor MultiportToPort { +main reactor MultiportToPort { a = new Source(); b1 = new Destination(); b2 = new Destination(expected = 1); diff --git a/test/TypeScript/src/multiport/MultiportToReaction.lf b/test/TypeScript/src/multiport/MultiportToReaction.lf index 2eebb116b1..bcee23009c 100644 --- a/test/TypeScript/src/multiport/MultiportToReaction.lf +++ b/test/TypeScript/src/multiport/MultiportToReaction.lf @@ -1,7 +1,7 @@ // Check reaction to multiport output of a contained reactor. target TypeScript { timeout: 2 sec -}; +}; reactor Source(width:number(1)) { timer t(0, 200 msec); state s:number(0); diff --git a/test/TypeScript/src/multiport/PipelineAfter.lf b/test/TypeScript/src/multiport/PipelineAfter.lf index 6bc1ed108b..d759895190 100644 --- a/test/TypeScript/src/multiport/PipelineAfter.lf +++ b/test/TypeScript/src/multiport/PipelineAfter.lf @@ -2,7 +2,7 @@ target TypeScript; reactor Source { output out:number; - + reaction (startup) -> out {= out = 40; =} @@ -11,7 +11,7 @@ reactor Source { reactor Compute { input inp:number; output out:number; - + reaction (inp) -> out {= out = (inp as number) + 2; =} @@ -19,7 +19,7 @@ reactor Compute { reactor Sink { input inp:number; - + reaction (inp) {= console.log("Received " + inp); if (inp != 42) { @@ -29,7 +29,7 @@ reactor Sink { util.requestErrorStop("ERROR: Expected to receive input after one second."); } =} - + } main reactor { diff --git a/test/TypeScript/src/multiport/ReactionToContainedBank.lf b/test/TypeScript/src/multiport/ReactionToContainedBank.lf index 9f8b20077a..b664553c20 100644 --- a/test/TypeScript/src/multiport/ReactionToContainedBank.lf +++ b/test/TypeScript/src/multiport/ReactionToContainedBank.lf @@ -1,4 +1,4 @@ - // Test reaction sending messages to a contained bank of reactors. +// Test reaction sending messages to a contained bank of reactors. target TypeScript { timeout: 1 sec }; @@ -7,9 +7,9 @@ import TestCount from "../lib/TestCount.lf"; main reactor ReactionToContainedBank(width:number(2)) { timer t(0, 100 msec); state count:number(1); - + test = new[width] TestCount(numInputs = 11); - + reaction(t) -> test.inp {= for (let i = 0; i < width; i++) { (test[i].inp as number) = count; diff --git a/test/TypeScript/src/serialization/ProtoNoPacking.lf b/test/TypeScript/src/serialization/ProtoNoPacking.lf index e658a3341d..b5ea7bb1a0 100644 --- a/test/TypeScript/src/serialization/ProtoNoPacking.lf +++ b/test/TypeScript/src/serialization/ProtoNoPacking.lf @@ -5,10 +5,10 @@ * * To run this example first install the protocol buffers compiler * from https://github.com/protocolbuffers/protobuf. It is also - * available from homebrew on a Mac via - * + * available from homebrew on a Mac via + * * $ brew install protobuf - * + * * Building protobuf from source is slow, so avoid doing that * if possible. * @@ -22,7 +22,7 @@ reactor SourceProto { reaction(startup) -> out {= // The contents of a compiled proto file are imported in // TypeScript as "import * as <.protoFileName>". So the constructor - // for class ProtoHelloWorld from the file ProtoHelloWorld.proto is + // for class ProtoHelloWorld from the file ProtoHelloWorld.proto is // ProtoHelloWorld.ProtoHelloWorld() let helloObject = new ProtoHelloWorld.ProtoHelloWorld(); helloObject.setName("Hello World"); From ec064c131ed6cebaa4f68abd8926616c5995aa86 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 19 May 2022 11:34:09 -0700 Subject: [PATCH 46/58] [tests] Whitespace only. This is a manual pass for incorrect indentation. --- test/C/src/ManualDelayedReaction.lf | 6 +- test/C/src/Starvation.lf | 6 +- test/C/src/Timeout.lf | 8 +- test/C/src/TimeoutZero.lf | 2 +- test/C/src/concurrent/StarvationThreaded.lf | 2 +- test/C/src/concurrent/StopThreaded.lf | 8 +- test/C/src/concurrent/TimeoutThreaded.lf | 6 +- test/C/src/concurrent/TimeoutZeroThreaded.lf | 8 +- .../DistributedCountContainerized.lf | 2 +- test/C/src/federated/ChainWithDelay.lf | 2 +- test/C/src/federated/DistributedCount.lf | 2 +- .../federated/LoopDistributedCentralized.lf | 2 +- test/C/src/federated/LoopDistributedDouble.lf | 2 +- test/C/src/federated/TopLevelArtifacts.lf | 2 +- test/C/src/multiport/MultiportFromBank.lf | 2 +- .../multiport/MultiportFromBankHierarchy.lf | 2 +- .../MultiportFromBankHierarchyAfter.lf | 2 +- test/C/src/multiport/MultiportToBankDouble.lf | 2 +- .../src/multiport/MultiportToBankHierarchy.lf | 2 +- .../serialization/PersonProtocolBuffers.lf | 4 +- .../serialization/ROSBuiltInSerialization.lf | 10 +- .../ROSBuiltInSerializationSharedPtr.lf | 10 +- test/Cpp/src/ActionValues.lf | 4 +- test/Cpp/src/GetMicroStep.lf | 10 +- test/Cpp/src/Hello.lf | 4 +- test/Cpp/src/Import.lf | 10 +- test/Cpp/src/Timeout_Test.lf | 6 +- test/Cpp/src/concurrent/AsyncCallback.lf | 2 +- test/Cpp/src/concurrent/AsyncCallback2.lf | 2 +- test/Cpp/src/concurrent/HelloThreaded.lf | 4 +- test/Cpp/src/concurrent/ImportThreaded.lf | 10 +- test/Cpp/src/lib/LoopedActionSender.lf | 8 +- .../src/multiport/BroadcastMultipleAfter.lf | 2 +- test/Cpp/src/multiport/MultiportFromBank.lf | 2 +- .../MultiportFromBankHierarchyAfter.lf | 2 +- .../Cpp/src/multiport/MultiportToHierarchy.lf | 2 +- test/Cpp/src/properties/Keepalive.lf | 2 +- test/Python/src/ManualDelayedReaction.lf | 25 ++-- .../DistributedCountContainerized.lf | 2 +- test/Python/src/federated/ChainWithDelay.lf | 2 +- test/Python/src/federated/DistributedCount.lf | 2 +- test/Python/src/federated/DistributedStop.lf | 8 +- .../federated/DistributedStopDecentralized.lf | 2 +- .../src/federated/DistributedStopZero.lf | 2 +- .../Python/src/federated/failing/ClockSync.lf | 2 +- .../LoopDistributedCentralizedPrecedence.lf | 2 +- ...stributedCentralizedPrecedenceHierarchy.lf | 2 +- .../failing/LoopDistributedDecentralized.lf | 2 +- .../failing/LoopDistributedDouble.lf | 2 +- .../federated/failing/TopLevelArtifacts.lf | 10 +- test/Python/src/lib/ImportedAgain.lf | 8 +- test/Python/src/multiport/Broadcast.lf | 4 +- .../src/multiport/BroadcastMultipleAfter.lf | 4 +- .../Python/src/multiport/MultiportFromBank.lf | 2 +- .../multiport/MultiportFromBankHierarchy.lf | 2 +- .../MultiportFromBankHierarchyAfter.lf | 2 +- .../src/multiport/MultiportToBankHierarchy.lf | 2 +- .../src/multiport/MultiportToHierarchy.lf | 2 +- test/Python/src/multiport/NestedBanks.lf | 122 +++++++++--------- test/Rust/src/ActionValues.lf | 4 +- test/Rust/src/CompositionWithPorts.lf | 24 ++-- test/Rust/src/Import.lf | 10 +- test/Rust/src/NativeListsAndTimes.lf | 4 +- test/Rust/src/PortConnectionInSelfOutSelf.lf | 10 +- .../Rust/src/PortConnectionOutChildOutSelf.lf | 4 +- test/Rust/src/SingleFileGeneration.lf | 24 ++-- test/Rust/src/Stop.lf | 9 +- test/Rust/src/StopCleanup.lf | 11 +- test/Rust/src/StopDuringStartup.lf | 2 +- test/Rust/src/StopNoEvent.lf | 2 +- test/Rust/src/StopTopology.lf | 4 +- test/TypeScript/src/ArrayAsType.lf | 6 +- test/TypeScript/src/ArrayPrint.lf | 4 +- test/TypeScript/src/ParameterizedState.lf | 2 +- .../DistributedCountContainerized.lf | 2 +- .../src/federated/DistributedCount.lf | 2 +- .../src/federated/StopAtShutdown.lf | 2 +- test/TypeScript/src/lib/Imported.lf | 2 +- .../src/multiport/BankReactionsInContainer.lf | 2 +- .../MultiportFromBankHierarchyAfter.lf | 2 +- .../src/multiport/MultiportToBankDouble.lf | 2 +- .../src/multiport/MultiportToHierarchy.lf | 2 +- .../src/multiport/ReactionToContainedBank.lf | 2 +- test/TypeScript/src/target/AfterNoTypes.lf | 2 +- 84 files changed, 253 insertions(+), 260 deletions(-) diff --git a/test/C/src/ManualDelayedReaction.lf b/test/C/src/ManualDelayedReaction.lf index d8b9e301c7..bbaa1ad133 100644 --- a/test/C/src/ManualDelayedReaction.lf +++ b/test/C/src/ManualDelayedReaction.lf @@ -36,8 +36,8 @@ reactor Source { } reactor Sink { - input in:int; - reaction(in) {= + input in:int; + reaction(in) {= interval_t elapsed_logical = lf_time_logical_elapsed(); interval_t logical = lf_time_logical(); interval_t physical = lf_time_physical(); @@ -46,7 +46,7 @@ reactor Sink { printf("Expected %lld but got %lld.\n", MSEC(100), elapsed_logical); exit(1); } - =} deadline(200 msec) {= =} + =} deadline(200 msec) {= =} } main reactor ManualDelayedReaction { source = new Source(); diff --git a/test/C/src/Starvation.lf b/test/C/src/Starvation.lf index ea04967a04..dea4b0d718 100644 --- a/test/C/src/Starvation.lf +++ b/test/C/src/Starvation.lf @@ -5,8 +5,8 @@ * * @author Soroush Bateni */ - target C; - reactor SuperDenseSender(number_of_iterations:int(10)){ +target C; +reactor SuperDenseSender(number_of_iterations:int(10)){ logical action loop; output out:int; state iterator:int(0); @@ -31,7 +31,7 @@ exit(1); } =} - } +} reactor SuperDenseReceiver(number_of_iterations:int(10)) { input in:int; diff --git a/test/C/src/Timeout.lf b/test/C/src/Timeout.lf index c28aec018c..49dbe232e6 100644 --- a/test/C/src/Timeout.lf +++ b/test/C/src/Timeout.lf @@ -3,7 +3,7 @@ * * @author Soroush Bateni */ - target C { +target C { timeout: 11 msec }; @@ -40,8 +40,8 @@ reactor Consumer { } main reactor Timeout { - consumer = new Consumer(); - producer = new Sender(break_interval = 1 msec); + consumer = new Consumer(); + producer = new Sender(break_interval = 1 msec); - producer.out -> consumer.in; + producer.out -> consumer.in; } diff --git a/test/C/src/TimeoutZero.lf b/test/C/src/TimeoutZero.lf index e93ffa1ae5..3feee6e010 100644 --- a/test/C/src/TimeoutZero.lf +++ b/test/C/src/TimeoutZero.lf @@ -4,7 +4,7 @@ * * @author Soroush Bateni */ - target C { +target C { timeout: 0 sec }; diff --git a/test/C/src/concurrent/StarvationThreaded.lf b/test/C/src/concurrent/StarvationThreaded.lf index d9906a1297..2df6fa5cc9 100644 --- a/test/C/src/concurrent/StarvationThreaded.lf +++ b/test/C/src/concurrent/StarvationThreaded.lf @@ -7,7 +7,7 @@ */ 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); diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index 17311774af..c5cc8f690d 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -4,7 +4,7 @@ * * @author Soroush Bateni */ - target C { +target C { timeout: 11 msec, build-type: RelWithDebInfo, // logging: DEBUG @@ -58,8 +58,8 @@ reactor Consumer { } main reactor { - consumer = new[4] Consumer(); - producer = new[4] Sender(break_interval = 1 msec); + consumer = new[4] Consumer(); + producer = new[4] Sender(break_interval = 1 msec); - producer.out -> consumer.in; + producer.out -> consumer.in; } diff --git a/test/C/src/concurrent/TimeoutThreaded.lf b/test/C/src/concurrent/TimeoutThreaded.lf index 82508843b6..5dc3258a3b 100644 --- a/test/C/src/concurrent/TimeoutThreaded.lf +++ b/test/C/src/concurrent/TimeoutThreaded.lf @@ -41,8 +41,8 @@ reactor Consumer { } main reactor { - consumer = new[4] Consumer(); - producer = new[4] Sender(break_interval = 1 msec); + consumer = new[4] Consumer(); + producer = new[4] Sender(break_interval = 1 msec); - producer.out -> consumer.in; + producer.out -> consumer.in; } diff --git a/test/C/src/concurrent/TimeoutZeroThreaded.lf b/test/C/src/concurrent/TimeoutZeroThreaded.lf index e8982e6f51..92901db0e8 100644 --- a/test/C/src/concurrent/TimeoutZeroThreaded.lf +++ b/test/C/src/concurrent/TimeoutZeroThreaded.lf @@ -5,7 +5,7 @@ * * @author Soroush Bateni */ - target C { +target C { timeout: 0 sec, }; @@ -42,8 +42,8 @@ reactor Consumer { } main reactor { - consumer = new[4] Consumer(); - producer = new[4] Sender(break_interval = 1 msec); + consumer = new[4] Consumer(); + producer = new[4] Sender(break_interval = 1 msec); - producer.out -> consumer.in; + producer.out -> consumer.in; } diff --git a/test/C/src/docker/federated/DistributedCountContainerized.lf b/test/C/src/docker/federated/DistributedCountContainerized.lf index 058719b139..7218804392 100644 --- a/test/C/src/docker/federated/DistributedCountContainerized.lf +++ b/test/C/src/docker/federated/DistributedCountContainerized.lf @@ -4,7 +4,7 @@ * advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ - target C { +target C { timeout: 5 sec, logging: DEBUG, coordination: centralized, diff --git a/test/C/src/federated/ChainWithDelay.lf b/test/C/src/federated/ChainWithDelay.lf index b9490b7569..203dbde968 100644 --- a/test/C/src/federated/ChainWithDelay.lf +++ b/test/C/src/federated/ChainWithDelay.lf @@ -3,7 +3,7 @@ * * @author Edward A. Lee */ - target C { +target C { timeout: 3 msec } import Count from "../lib/Count.lf"; diff --git a/test/C/src/federated/DistributedCount.lf b/test/C/src/federated/DistributedCount.lf index 302d163b92..1a19ba1645 100644 --- a/test/C/src/federated/DistributedCount.lf +++ b/test/C/src/federated/DistributedCount.lf @@ -4,7 +4,7 @@ * advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ - target C { +target C { timeout: 5 sec, logging: DEBUG, coordination: centralized diff --git a/test/C/src/federated/LoopDistributedCentralized.lf b/test/C/src/federated/LoopDistributedCentralized.lf index e8d241c7b0..557045f5ec 100644 --- a/test/C/src/federated/LoopDistributedCentralized.lf +++ b/test/C/src/federated/LoopDistributedCentralized.lf @@ -20,7 +20,7 @@ preamble {= lf_schedule(actionref, 0); sleep(1); } - return NULL; + return NULL; } =} diff --git a/test/C/src/federated/LoopDistributedDouble.lf b/test/C/src/federated/LoopDistributedDouble.lf index 14b8451fe1..9c55a5cb96 100644 --- a/test/C/src/federated/LoopDistributedDouble.lf +++ b/test/C/src/federated/LoopDistributedDouble.lf @@ -20,7 +20,7 @@ preamble {= lf_schedule(actionref, 0); sleep(1); } - return NULL; + return NULL; } =} diff --git a/test/C/src/federated/TopLevelArtifacts.lf b/test/C/src/federated/TopLevelArtifacts.lf index 2ce9dbdb69..1c830ffaa6 100644 --- a/test/C/src/federated/TopLevelArtifacts.lf +++ b/test/C/src/federated/TopLevelArtifacts.lf @@ -7,7 +7,7 @@ * artifacts might be disallowed in the future. */ - target C { +target C { timeout: 1 msec }; diff --git a/test/C/src/multiport/MultiportFromBank.lf b/test/C/src/multiport/MultiportFromBank.lf index 62f9128eef..3b4c6c8fe1 100644 --- a/test/C/src/multiport/MultiportFromBank.lf +++ b/test/C/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportFromBankHierarchy.lf b/test/C/src/multiport/MultiportFromBankHierarchy.lf index 1f2de8805d..9e440c75c8 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf index d7fbf7a775..f71c2674c9 100644 --- a/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/C/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToBankDouble.lf b/test/C/src/multiport/MultiportToBankDouble.lf index 9417106b6c..277194d313 100644 --- a/test/C/src/multiport/MultiportToBankDouble.lf +++ b/test/C/src/multiport/MultiportToBankDouble.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients where the source - // has two reactions that write to the output. +// has two reactions that write to the output. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/multiport/MultiportToBankHierarchy.lf b/test/C/src/multiport/MultiportToBankHierarchy.lf index 55589af019..a286698d1c 100644 --- a/test/C/src/multiport/MultiportToBankHierarchy.lf +++ b/test/C/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target C { timeout: 2 sec, fast: true diff --git a/test/C/src/serialization/PersonProtocolBuffers.lf b/test/C/src/serialization/PersonProtocolBuffers.lf index 480482e6eb..62c5efd2e3 100644 --- a/test/C/src/serialization/PersonProtocolBuffers.lf +++ b/test/C/src/serialization/PersonProtocolBuffers.lf @@ -43,5 +43,5 @@ main reactor { // Extract and print the unpacked message. printf("Name: %s\n", unpacked->name); free(buffer); // Free the allocated serialized buffer - =} - } + =} +} diff --git a/test/C/src/serialization/ROSBuiltInSerialization.lf b/test/C/src/serialization/ROSBuiltInSerialization.lf index f3ecbc5f8b..bf90730bb8 100644 --- a/test/C/src/serialization/ROSBuiltInSerialization.lf +++ b/test/C/src/serialization/ROSBuiltInSerialization.lf @@ -21,14 +21,13 @@ * * @author Soroush Bateni */ - target CCpp { +target CCpp { cmake-include: "include/CMakeListsExtension.txt", timeout: 2 sec }; preamble {= #include "std_msgs/msg/int32.hpp" - =} reactor Sender { @@ -40,10 +39,9 @@ reactor Sender { timer t (0, 1 sec); reaction (t) -> out {= - std_msgs::msg::Int32 ros_message; - ros_message.data = self->count++; - lf_set(out, ros_message); - + std_msgs::msg::Int32 ros_message; + ros_message.data = self->count++; + lf_set(out, ros_message); =} } diff --git a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf index c26287f664..775b30c624 100644 --- a/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf +++ b/test/C/src/serialization/ROSBuiltInSerializationSharedPtr.lf @@ -21,14 +21,13 @@ * * @author Soroush Bateni */ - target CCpp { +target CCpp { cmake-include: "include/CMakeListsExtension.txt", timeout: 2 sec }; preamble {= #include "std_msgs/msg/int32.hpp" - =} reactor Sender { @@ -39,10 +38,9 @@ reactor Sender { timer t (0, 1 sec); reaction (t) -> out {= - auto ros_message = std::make_shared(); - ros_message->data = self->count++; - lf_set(out, ros_message); - + auto ros_message = std::make_shared(); + ros_message->data = self->count++; + lf_set(out, ros_message); =} } diff --git a/test/Cpp/src/ActionValues.lf b/test/Cpp/src/ActionValues.lf index 0564dc30e6..be6de2c7f3 100644 --- a/test/Cpp/src/ActionValues.lf +++ b/test/Cpp/src/ActionValues.lf @@ -39,9 +39,9 @@ main reactor ActionValues { =} reaction (shutdown) {= - if (!r1done || !r2done) { + if (!r1done || !r2done) { std::cerr << "ERROR: Expected 2 reaction invocations\n"; exit(1); - } + } =} } diff --git a/test/Cpp/src/GetMicroStep.lf b/test/Cpp/src/GetMicroStep.lf index 237ec6f812..98ae854abd 100644 --- a/test/Cpp/src/GetMicroStep.lf +++ b/test/Cpp/src/GetMicroStep.lf @@ -20,10 +20,10 @@ main reactor GetMicroStep { =} reaction(shutdown) {= - if (s != 11) { - std::cerr << "Error: unexpected state!\n"; - exit(2); - } - std::cout << "Success!\n"; + if (s != 11) { + std::cerr << "Error: unexpected state!\n"; + exit(2); + } + std::cout << "Success!\n"; =} } diff --git a/test/Cpp/src/Hello.lf b/test/Cpp/src/Hello.lf index 9802df5643..ab3fb05bb0 100644 --- a/test/Cpp/src/Hello.lf +++ b/test/Cpp/src/Hello.lf @@ -18,8 +18,8 @@ reactor HelloCpp(period:time(2 secs), message:{=std::string=}("Hello C++")) { // Print the current time. previous_time = get_logical_time(); std::cout << "Current time is " << previous_time << std::endl; - =} - reaction(a) {= + =} + reaction(a) {= count++; auto time = get_logical_time(); std::cout << "***** action " << count << " at time " diff --git a/test/Cpp/src/Import.lf b/test/Cpp/src/Import.lf index 8cbb6ca29f..a8fdfb1d4a 100644 --- a/test/Cpp/src/Import.lf +++ b/test/Cpp/src/Import.lf @@ -5,9 +5,9 @@ target Cpp{ import Imported from "lib/Imported.lf"; main reactor Import { - timer t; - a = new Imported(); - reaction(t) -> a.x {= - a.x.set(42); - =} + timer t; + a = new Imported(); + reaction(t) -> a.x {= + a.x.set(42); + =} } diff --git a/test/Cpp/src/Timeout_Test.lf b/test/Cpp/src/Timeout_Test.lf index 06a676360b..b7c66d7c89 100644 --- a/test/Cpp/src/Timeout_Test.lf +++ b/test/Cpp/src/Timeout_Test.lf @@ -37,8 +37,8 @@ reactor Consumer { } main reactor Timeout_Test { - consumer = new Consumer(); - producer = new Sender(break_interval = 1 msec); + consumer = new Consumer(); + producer = new Sender(break_interval = 1 msec); - producer.out -> consumer.in; + producer.out -> consumer.in; } diff --git a/test/Cpp/src/concurrent/AsyncCallback.lf b/test/Cpp/src/concurrent/AsyncCallback.lf index f5740ea0be..5123ae4a4c 100644 --- a/test/Cpp/src/concurrent/AsyncCallback.lf +++ b/test/Cpp/src/concurrent/AsyncCallback.lf @@ -26,7 +26,7 @@ main reactor AsyncCallback { // start new thread this->thread = std::thread([&] () { - // Simulate time passing before a callback occurs + // Simulate time passing before a callback occurs std::this_thread::sleep_for(100ms); // Schedule twice. If the action is not physical, these should // get consolidated into a single action triggering. If it is, diff --git a/test/Cpp/src/concurrent/AsyncCallback2.lf b/test/Cpp/src/concurrent/AsyncCallback2.lf index 2d74156c44..643294c3a2 100644 --- a/test/Cpp/src/concurrent/AsyncCallback2.lf +++ b/test/Cpp/src/concurrent/AsyncCallback2.lf @@ -19,7 +19,7 @@ main reactor AsyncCallback2 { reaction(t) -> a {= // start new thread auto thread = std::thread([&] () { - // Simulate time passing before a callback occurs + // Simulate time passing before a callback occurs std::this_thread::sleep_for(100ms); // Schedule twice. If the action is not physical, these should // get consolidated into a single action triggering. If it is, diff --git a/test/Cpp/src/concurrent/HelloThreaded.lf b/test/Cpp/src/concurrent/HelloThreaded.lf index 8aa73406e6..c6725d59e8 100644 --- a/test/Cpp/src/concurrent/HelloThreaded.lf +++ b/test/Cpp/src/concurrent/HelloThreaded.lf @@ -18,8 +18,8 @@ reactor HelloCpp(period:time(2 secs), message:{=std::string=}("Hello C++")) { // Print the current time. previous_time = get_logical_time(); std::cout << "Current time is " << previous_time << std::endl; - =} - reaction(a) {= + =} + reaction(a) {= count++; auto time = get_logical_time(); std::cout << "***** action " << count << " at time " diff --git a/test/Cpp/src/concurrent/ImportThreaded.lf b/test/Cpp/src/concurrent/ImportThreaded.lf index df294078af..0dbd8d40bf 100644 --- a/test/Cpp/src/concurrent/ImportThreaded.lf +++ b/test/Cpp/src/concurrent/ImportThreaded.lf @@ -3,9 +3,9 @@ target Cpp; import Imported from "../lib/Imported.lf"; main reactor { - timer t; - a = new Imported(); - reaction(t) -> a.x {= - a.x.set(42); - =} + timer t; + a = new Imported(); + reaction(t) -> a.x {= + a.x.set(42); + =} } diff --git a/test/Cpp/src/lib/LoopedActionSender.lf b/test/Cpp/src/lib/LoopedActionSender.lf index 06ba66c154..a6d9dcb323 100644 --- a/test/Cpp/src/lib/LoopedActionSender.lf +++ b/test/Cpp/src/lib/LoopedActionSender.lf @@ -6,15 +6,15 @@ * * @author Maiko Brants */ - target Cpp; +target Cpp; - /** +/** * @param take_a_break_after: Indicates how many messages are sent * in consecutive superdense time * @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); @@ -29,4 +29,4 @@ act.schedule(break_interval); } =} - } +} diff --git a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf index a0778d9b41..75f938c27d 100644 --- a/test/Cpp/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Cpp/src/multiport/BroadcastMultipleAfter.lf @@ -1,5 +1,5 @@ target Cpp{ - fast: true + fast: true } reactor Source(value:unsigned(42)) { diff --git a/test/Cpp/src/multiport/MultiportFromBank.lf b/test/Cpp/src/multiport/MultiportFromBank.lf index 84ac23fdaa..0b53ab5f5b 100644 --- a/test/Cpp/src/multiport/MultiportFromBank.lf +++ b/test/Cpp/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf index 764e40f2ac..40b89efd32 100644 --- a/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Cpp/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/multiport/MultiportToHierarchy.lf b/test/Cpp/src/multiport/MultiportToHierarchy.lf index 4a0883f134..d7fb946dea 100644 --- a/test/Cpp/src/multiport/MultiportToHierarchy.lf +++ b/test/Cpp/src/multiport/MultiportToHierarchy.lf @@ -1,5 +1,5 @@ // Check multiport output to multiport input, where the latter is a hierarchical reactor. - // Note that the destination reactor has width wider than the sender, so one input is dangling. +// Note that the destination reactor has width wider than the sender, so one input is dangling. target Cpp { timeout: 2 sec, fast: true diff --git a/test/Cpp/src/properties/Keepalive.lf b/test/Cpp/src/properties/Keepalive.lf index b4830e8a87..e5318980c4 100644 --- a/test/Cpp/src/properties/Keepalive.lf +++ b/test/Cpp/src/properties/Keepalive.lf @@ -16,7 +16,7 @@ main reactor { reaction(startup) -> a {= // start new thread this->thread = std::thread([&] () { - // Simulate time passing before a callback occurs + // Simulate time passing before a callback occurs std::this_thread::sleep_for(1s); a.schedule(); }); diff --git a/test/Python/src/ManualDelayedReaction.lf b/test/Python/src/ManualDelayedReaction.lf index 42aed21060..6a2e08362c 100644 --- a/test/Python/src/ManualDelayedReaction.lf +++ b/test/Python/src/ManualDelayedReaction.lf @@ -10,21 +10,21 @@ target Python { // That's the stuff that shall be generated for the after reactor GeneratedDelay { - input y_in; - output y_out; - state y_state(0); + input y_in; + output y_out; + state y_state(0); - // TODO: delay in act or the schedule call? - physical action act(0 msec); + // TODO: delay in act or the schedule call? + physical action act(0 msec); -reaction(y_in) -> act {= - self.y_state = y_in.value - act.schedule(MSEC(100)) -=} + reaction(y_in) -> act {= + self.y_state = y_in.value + act.schedule(MSEC(100)) + =} -reaction(act) -> y_out {= - y_out.set(self.y_state) - =} + reaction(act) -> y_out {= + y_out.set(self.y_state) + =} } reactor Source { output out; @@ -56,5 +56,4 @@ main reactor ManualDelayedReaction { // rewritten above source.out -> g.y_in; g.y_out -> sink.s_in; - } diff --git a/test/Python/src/docker/federated/DistributedCountContainerized.lf b/test/Python/src/docker/federated/DistributedCountContainerized.lf index 4b4b8d11b9..812ee15594 100644 --- a/test/Python/src/docker/federated/DistributedCountContainerized.lf +++ b/test/Python/src/docker/federated/DistributedCountContainerized.lf @@ -4,7 +4,7 @@ * advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ - target Python { +target Python { timeout: 5 sec, logging: DEBUG, coordination: centralized, diff --git a/test/Python/src/federated/ChainWithDelay.lf b/test/Python/src/federated/ChainWithDelay.lf index e8c253bf62..604259f446 100644 --- a/test/Python/src/federated/ChainWithDelay.lf +++ b/test/Python/src/federated/ChainWithDelay.lf @@ -3,7 +3,7 @@ * * @author Edward A. Lee */ - target Python { +target Python { timeout: 3 msec } import Count from "../lib/Count.lf"; diff --git a/test/Python/src/federated/DistributedCount.lf b/test/Python/src/federated/DistributedCount.lf index d3551994cf..bbc8500c59 100644 --- a/test/Python/src/federated/DistributedCount.lf +++ b/test/Python/src/federated/DistributedCount.lf @@ -4,7 +4,7 @@ * advancement of time (HLA or Ptides) is needed. * @author Edward A. Lee */ - target Python { +target Python { timeout: 5 sec, logging: DEBUG, coordination: centralized diff --git a/test/Python/src/federated/DistributedStop.lf b/test/Python/src/federated/DistributedStop.lf index 516298a336..0027ddb4de 100644 --- a/test/Python/src/federated/DistributedStop.lf +++ b/test/Python/src/federated/DistributedStop.lf @@ -1,8 +1,8 @@ /** -* Test for request_stop() in federated execution with centralized coordination. -* -* @author Soroush Bateni -*/ + * Test for request_stop() in federated execution with centralized coordination. + * + * @author Soroush Bateni + */ target Python; diff --git a/test/Python/src/federated/DistributedStopDecentralized.lf b/test/Python/src/federated/DistributedStopDecentralized.lf index 913948765e..7ac3f1723f 100644 --- a/test/Python/src/federated/DistributedStopDecentralized.lf +++ b/test/Python/src/federated/DistributedStopDecentralized.lf @@ -4,7 +4,7 @@ * @author Soroush Bateni */ - // reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target +// reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target target Python { coordination: decentralized diff --git a/test/Python/src/federated/DistributedStopZero.lf b/test/Python/src/federated/DistributedStopZero.lf index 58b4cb4f93..ce72ed15d4 100644 --- a/test/Python/src/federated/DistributedStopZero.lf +++ b/test/Python/src/federated/DistributedStopZero.lf @@ -5,7 +5,7 @@ * @author Soroush Bateni */ - // reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target +// reason for failing: get_microstep() and lf.tag_compare() are not not supported in python target target Python; diff --git a/test/Python/src/federated/failing/ClockSync.lf b/test/Python/src/federated/failing/ClockSync.lf index e8c91eb468..81d0ed47e8 100644 --- a/test/Python/src/federated/failing/ClockSync.lf +++ b/test/Python/src/federated/failing/ClockSync.lf @@ -8,7 +8,7 @@ * @author Edward A. Lee */ - // reason for failing: clock-sync and clock-sync-options not supported in the python target +// reason for failing: clock-sync and clock-sync-options not supported in the python target target Python { diff --git a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf index 127808794d..2d7464952a 100644 --- a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf +++ b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedence.lf @@ -6,7 +6,7 @@ * @author Soroush Bateni */ - // reason for failing: lf_comma_separated_time() not supported in the python target +// reason for failing: lf_comma_separated_time() not supported in the python target target Python { flags: "-Wall", diff --git a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf index ce0f5d9d20..c96dca8ba0 100644 --- a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf @@ -6,7 +6,7 @@ * @author Soroush Bateni */ - // reason for failing: lf_comma_separated_time() not supported in the python target +// reason for failing: lf_comma_separated_time() not supported in the python target target Python { diff --git a/test/Python/src/federated/failing/LoopDistributedDecentralized.lf b/test/Python/src/federated/failing/LoopDistributedDecentralized.lf index 3a0dc644cc..4258bf9c21 100644 --- a/test/Python/src/federated/failing/LoopDistributedDecentralized.lf +++ b/test/Python/src/federated/failing/LoopDistributedDecentralized.lf @@ -5,7 +5,7 @@ * @author Edward A. Lee */ - // reason for failing: lf_comma_separated_time() not supported in the python target +// reason for failing: lf_comma_separated_time() not supported in the python target target Python { coordination: decentralized, diff --git a/test/Python/src/federated/failing/LoopDistributedDouble.lf b/test/Python/src/federated/failing/LoopDistributedDouble.lf index 83bb77d0ea..46bcb9f585 100644 --- a/test/Python/src/federated/failing/LoopDistributedDouble.lf +++ b/test/Python/src/federated/failing/LoopDistributedDouble.lf @@ -21,7 +21,7 @@ preamble {= schedule(actionref, 0); sleep(1); } - return NULL; + return NULL; } =} diff --git a/test/Python/src/federated/failing/TopLevelArtifacts.lf b/test/Python/src/federated/failing/TopLevelArtifacts.lf index 9bb6e9b311..1a13726c6c 100644 --- a/test/Python/src/federated/failing/TopLevelArtifacts.lf +++ b/test/Python/src/federated/failing/TopLevelArtifacts.lf @@ -7,16 +7,16 @@ * artifacts might be disallowed in the future. */ - // reason for failing: strange error during compile time. lfc seeems to treat this file as C target. +// reason for failing: strange error during compile time. lfc seeems to treat this file as C target. - target Python { +target Python { timeout: 1 msec }; - import Count from "../lib/Count.lf"; - import TestCount from "../lib/TestCount.lf"; +import Count from "../lib/Count.lf"; +import TestCount from "../lib/TestCount.lf"; - federated reactor { +federated reactor { preamble {= import sys =} diff --git a/test/Python/src/lib/ImportedAgain.lf b/test/Python/src/lib/ImportedAgain.lf index 74abdf4f97..6070ab384d 100644 --- a/test/Python/src/lib/ImportedAgain.lf +++ b/test/Python/src/lib/ImportedAgain.lf @@ -3,12 +3,12 @@ target Python; //import Imported from "Imported.lf" reactor ImportedAgain { - //y = new Imported(); // FIXME: Address this bug - input x; - reaction(x) {= + //y = new Imported(); // FIXME: Address this bug + input x; + reaction(x) {= print("Received: " + str(x.value)) if (x.value != 42): print("ERROR: Expected input to be 42. Got: " + x.value) exit(1) - =} + =} } diff --git a/test/Python/src/multiport/Broadcast.lf b/test/Python/src/multiport/Broadcast.lf index a0f90309c1..6a0b434bca 100644 --- a/test/Python/src/multiport/Broadcast.lf +++ b/test/Python/src/multiport/Broadcast.lf @@ -21,8 +21,8 @@ reactor Destination(bank_index(0), delay(0)) { exit(1) if lf.time.logical_elapsed() != self.delay: - sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") - exit(2) + sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") + exit(2) self.received = True =} reaction(shutdown) {= diff --git a/test/Python/src/multiport/BroadcastMultipleAfter.lf b/test/Python/src/multiport/BroadcastMultipleAfter.lf index bca26a1f45..17f7053398 100644 --- a/test/Python/src/multiport/BroadcastMultipleAfter.lf +++ b/test/Python/src/multiport/BroadcastMultipleAfter.lf @@ -16,8 +16,8 @@ reactor Destination(bank_index(0), delay(0)) { exit(1) if lf.time.logical_elapsed() != self.delay: - sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") - exit(2) + sys.stderr.write(f"ERROR: Expected to receive input after {self.delay/1000000000} second(s).\n") + exit(2) self.received = True =} reaction(shutdown) {= diff --git a/test/Python/src/multiport/MultiportFromBank.lf b/test/Python/src/multiport/MultiportFromBank.lf index 7fd2427ebd..73176f2112 100644 --- a/test/Python/src/multiport/MultiportFromBank.lf +++ b/test/Python/src/multiport/MultiportFromBank.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportFromBankHierarchy.lf b/test/Python/src/multiport/MultiportFromBankHierarchy.lf index 94d3136dae..1fbe80d721 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchy.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf index 7074ff5b79..d3657bbae5 100644 --- a/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/Python/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToBankHierarchy.lf b/test/Python/src/multiport/MultiportToBankHierarchy.lf index 773fbb0130..af3b2bd9cf 100644 --- a/test/Python/src/multiport/MultiportToBankHierarchy.lf +++ b/test/Python/src/multiport/MultiportToBankHierarchy.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/MultiportToHierarchy.lf b/test/Python/src/multiport/MultiportToHierarchy.lf index f3d29a1d4a..981513dc13 100644 --- a/test/Python/src/multiport/MultiportToHierarchy.lf +++ b/test/Python/src/multiport/MultiportToHierarchy.lf @@ -1,5 +1,5 @@ // Check multiport output to multiport input, where the latter is a hierarchical reactor. - // Note that the destination reactor has width wider than the sender, so one input is dangling. +// Note that the destination reactor has width wider than the sender, so one input is dangling. target Python { timeout: 2 sec, fast: true diff --git a/test/Python/src/multiport/NestedBanks.lf b/test/Python/src/multiport/NestedBanks.lf index c6cfa4046f..572de19bb5 100644 --- a/test/Python/src/multiport/NestedBanks.lf +++ b/test/Python/src/multiport/NestedBanks.lf @@ -2,66 +2,66 @@ * Test of nested banks with multiports. * @author Edward A. Lee */ - target Python; - main reactor { - a = new[2] A(); - c = new[3] C(); - d = new D(); - e = new E(); +target Python; +main reactor { + a = new[2] A(); + c = new[3] C(); + d = new D(); + e = new E(); - (a.x)+ -> c.z, d.u, e.t; - } - 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)) { - output[2] y; - reaction(startup) -> y {= - base = self.a_bank_index * 4 + self.bank_index * 2 - y[0].set(base) - y[1].set(base + 1) - =} - } - reactor C(bank_index(0)) { - input[2] z; - f = new F(c_bank_index = bank_index); - g = new G(c_bank_index = bank_index); - z -> f.w, g.s; - } - reactor D { - input[2] u; - reaction(u) {= - for (i, p) in enumerate(u): - print(f"d.u[{i}] received {p.value}.") - if p.value != (6 + i): - sys.stderr.write(f"ERROR: Expected {6 + i} but received {p.value}.\n") - exit(1) - =} - } - reactor E { - input[8] t; - reaction(t) {= - for (i, p) in enumerate(t): - print(f"e.t[{i}] received {p.value}.") - =} - } - reactor F(c_bank_index(0)) { - input w; - reaction(w) {= - print(f"c[{self.c_bank_index}].f.w received {w.value}.") - if w.value != self.c_bank_index * 2: - sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2} but received {w.value}.\n") + (a.x)+ -> c.z, d.u, e.t; +} +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)) { + output[2] y; + reaction(startup) -> y {= + base = self.a_bank_index * 4 + self.bank_index * 2 + y[0].set(base) + y[1].set(base + 1) + =} +} +reactor C(bank_index(0)) { + input[2] z; + f = new F(c_bank_index = bank_index); + g = new G(c_bank_index = bank_index); + z -> f.w, g.s; +} +reactor D { + input[2] u; + reaction(u) {= + for (i, p) in enumerate(u): + print(f"d.u[{i}] received {p.value}.") + if p.value != (6 + i): + sys.stderr.write(f"ERROR: Expected {6 + i} but received {p.value}.\n") exit(1) - =} - } - reactor G(c_bank_index(0)) { - input s; - reaction(s) {= - print(f"c[{self.c_bank_index}].g.s received {s.value}.") - if s.value != (self.c_bank_index * 2 + 1): - sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2 + 1} but received {s.value}.\n") - exit(1) - =} - } + =} +} +reactor E { + input[8] t; + reaction(t) {= + for (i, p) in enumerate(t): + print(f"e.t[{i}] received {p.value}.") + =} +} +reactor F(c_bank_index(0)) { + input w; + reaction(w) {= + print(f"c[{self.c_bank_index}].f.w received {w.value}.") + if w.value != self.c_bank_index * 2: + sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2} but received {w.value}.\n") + exit(1) + =} +} +reactor G(c_bank_index(0)) { + input s; + reaction(s) {= + print(f"c[{self.c_bank_index}].g.s received {s.value}.") + if s.value != (self.c_bank_index * 2 + 1): + sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2 + 1} but received {s.value}.\n") + exit(1) + =} +} diff --git a/test/Rust/src/ActionValues.lf b/test/Rust/src/ActionValues.lf index 68c074e360..d4711dc594 100644 --- a/test/Rust/src/ActionValues.lf +++ b/test/Rust/src/ActionValues.lf @@ -26,7 +26,7 @@ main reactor ActionValues { =} reaction (shutdown) {= - assert!(self.r1done && self.r2done); - println!("Success") + assert!(self.r1done && self.r2done); + println!("Success") =} } diff --git a/test/Rust/src/CompositionWithPorts.lf b/test/Rust/src/CompositionWithPorts.lf index f03586cc8d..a81b651aa2 100644 --- a/test/Rust/src/CompositionWithPorts.lf +++ b/test/Rust/src/CompositionWithPorts.lf @@ -6,19 +6,19 @@ reactor Source { =} } reactor Sink { - input inport: i32; - reaction(inport) {= - if let Some(value) = ctx.get(inport) { - println!("received {}", value); - assert_eq!(76600, value); - } else { - unreachable!(); - } - =} + input inport: i32; + reaction(inport) {= + if let Some(value) = ctx.get(inport) { + println!("received {}", value); + assert_eq!(76600, value); + } else { + unreachable!(); + } + =} } main reactor CompositionWithPorts { - source = new Source(); - sink = new Sink(); + source = new Source(); + sink = new Sink(); - source.out -> sink.inport; + source.out -> sink.inport; } diff --git a/test/Rust/src/Import.lf b/test/Rust/src/Import.lf index eec4bf8539..bb6489debc 100644 --- a/test/Rust/src/Import.lf +++ b/test/Rust/src/Import.lf @@ -4,9 +4,9 @@ target Rust; import Imported from "lib/Imported.lf"; main reactor Import { - timer t; - a = new Imported(); - reaction(t) -> a.x {= - ctx.set(a__x, 42); - =} + timer t; + a = new Imported(); + reaction(t) -> a.x {= + ctx.set(a__x, 42); + =} } diff --git a/test/Rust/src/NativeListsAndTimes.lf b/test/Rust/src/NativeListsAndTimes.lf index 02435eb095..31281c0ae9 100644 --- a/test/Rust/src/NativeListsAndTimes.lf +++ b/test/Rust/src/NativeListsAndTimes.lf @@ -34,8 +34,8 @@ reactor Foo(x: i32(0), =} /* reactor Foo (p: i32[](1, 2)) { - state baz(p); // Implicit type i32[] - state baz({=p=}); // Implicit type i32[] + state baz(p); // Implicit type i32[] + state baz({=p=}); // Implicit type i32[] } */ diff --git a/test/Rust/src/PortConnectionInSelfOutSelf.lf b/test/Rust/src/PortConnectionInSelfOutSelf.lf index ac54f00d6d..548315992a 100644 --- a/test/Rust/src/PortConnectionInSelfOutSelf.lf +++ b/test/Rust/src/PortConnectionInSelfOutSelf.lf @@ -28,10 +28,10 @@ reactor Sink { } main reactor { - source = new Source(); - middle = new TestCase(); - sink = new Sink(); + source = new Source(); + middle = new TestCase(); + sink = new Sink(); - source.out -> middle.inp; - middle.out -> sink.inp; + source.out -> middle.inp; + middle.out -> sink.inp; } diff --git a/test/Rust/src/PortConnectionOutChildOutSelf.lf b/test/Rust/src/PortConnectionOutChildOutSelf.lf index 0a91cd1d60..4993c58c08 100644 --- a/test/Rust/src/PortConnectionOutChildOutSelf.lf +++ b/test/Rust/src/PortConnectionOutChildOutSelf.lf @@ -4,8 +4,8 @@ target Rust; reactor Child { output out: i32; reaction(startup) -> out {= - ctx.set(out, 76600); - println!("out := 76600") + ctx.set(out, 76600); + println!("out := 76600") =} } reactor Parent { diff --git a/test/Rust/src/SingleFileGeneration.lf b/test/Rust/src/SingleFileGeneration.lf index ca4b000f92..caa399f3a6 100644 --- a/test/Rust/src/SingleFileGeneration.lf +++ b/test/Rust/src/SingleFileGeneration.lf @@ -10,19 +10,19 @@ reactor Source { =} } reactor Sink { - input inport: i32; - reaction(inport) {= - if let Some(value) = ctx.get(inport) { - println!("received {}", value); - assert_eq!(76600, value); - } else { - unreachable!(); - } - =} + input inport: i32; + reaction(inport) {= + if let Some(value) = ctx.get(inport) { + println!("received {}", value); + assert_eq!(76600, value); + } else { + unreachable!(); + } + =} } main reactor { - source = new Source(); - sink = new Sink(); + source = new Source(); + sink = new Sink(); - source.out -> sink.inport; + source.out -> sink.inport; } diff --git a/test/Rust/src/Stop.lf b/test/Rust/src/Stop.lf index 1d8a2917b3..858d8151b2 100644 --- a/test/Rust/src/Stop.lf +++ b/test/Rust/src/Stop.lf @@ -3,9 +3,8 @@ * * @author Soroush Bateni */ - target Rust { +target Rust { timeout: 11 msec, - }; /** @@ -79,8 +78,8 @@ reactor Consumer { } main reactor Stop { - consumer = new Consumer(); - producer = new Sender(break_interval = 1 msec); + consumer = new Consumer(); + producer = new Sender(break_interval = 1 msec); - producer.out -> consumer.in_; + producer.out -> consumer.in_; } diff --git a/test/Rust/src/StopCleanup.lf b/test/Rust/src/StopCleanup.lf index 0d5a8bfd5e..02a5a2a0fd 100644 --- a/test/Rust/src/StopCleanup.lf +++ b/test/Rust/src/StopCleanup.lf @@ -1,8 +1,7 @@ /* Tests that ports are cleaned up before the shutdown wave executes. */ - target Rust { - - }; +target Rust { +}; reactor Sender { output out: u32; @@ -24,8 +23,8 @@ reactor Consumer { } main reactor StopCleanup { - consumer = new Consumer(); - producer = new Sender(); + consumer = new Consumer(); + producer = new Sender(); - producer.out -> consumer.in_; + producer.out -> consumer.in_; } diff --git a/test/Rust/src/StopDuringStartup.lf b/test/Rust/src/StopDuringStartup.lf index 0ae90c12ff..f2e98639bd 100644 --- a/test/Rust/src/StopDuringStartup.lf +++ b/test/Rust/src/StopDuringStartup.lf @@ -1,7 +1,7 @@ // tests that a request_stop called during startup is acted upon. target Rust { - timeout: 30 msec, + timeout: 30 msec, }; main reactor { diff --git a/test/Rust/src/StopNoEvent.lf b/test/Rust/src/StopNoEvent.lf index 231a486384..86c36c690e 100644 --- a/test/Rust/src/StopNoEvent.lf +++ b/test/Rust/src/StopNoEvent.lf @@ -1,5 +1,5 @@ /* Tests that `shutdown` is triggered even if the program exits because of an empty event queue. */ - target Rust; +target Rust; main reactor StopNoEvent { reaction(shutdown) {= diff --git a/test/Rust/src/StopTopology.lf b/test/Rust/src/StopTopology.lf index 6ac224a24f..825fee843f 100644 --- a/test/Rust/src/StopTopology.lf +++ b/test/Rust/src/StopTopology.lf @@ -1,8 +1,8 @@ /* Tests that shutdown wave occurs in topological order like a normal wave. */ - target Rust { +target Rust { timeout: 30 msec - }; +}; main reactor StopTopology { timer end(30 msec); // collides with timeout diff --git a/test/TypeScript/src/ArrayAsType.lf b/test/TypeScript/src/ArrayAsType.lf index 274c05c6a0..41f6f99c81 100644 --- a/test/TypeScript/src/ArrayAsType.lf +++ b/test/TypeScript/src/ArrayAsType.lf @@ -25,15 +25,15 @@ reactor Print(scale:number(1)) { msg += "Received: ["; for (let i = 0; i < 3; i++) { if (i > 0) msg += ", "; - msg += (x[i]); + msg += (x[i]); // For testing, check whether values match expectation. if ((x[i]) != scale * count) { failed = true; } count++; // For testing. } - msg += "]"; - console.log(msg); + msg += "]"; + console.log(msg); if (failed) { util.requestErrorStop("ERROR: Value received by Print does not match expectation!"); } diff --git a/test/TypeScript/src/ArrayPrint.lf b/test/TypeScript/src/ArrayPrint.lf index 306a6de14a..68299e2c8d 100644 --- a/test/TypeScript/src/ArrayPrint.lf +++ b/test/TypeScript/src/ArrayPrint.lf @@ -31,8 +31,8 @@ reactor Print(scale:number(1)) { } count++; // For testing. } - msg += "]"; - console.log(msg); + msg += "]"; + console.log(msg); if (failed) { util.requestErrorStop("ERROR: Value received by Print does not match expectation!"); } diff --git a/test/TypeScript/src/ParameterizedState.lf b/test/TypeScript/src/ParameterizedState.lf index d5ef18195e..81a9bad4b6 100644 --- a/test/TypeScript/src/ParameterizedState.lf +++ b/test/TypeScript/src/ParameterizedState.lf @@ -3,7 +3,7 @@ target TypeScript; reactor Foo(bar:number(42)) { state baz(bar); reaction (startup) {= - console.log("Baz: " + baz); + console.log("Baz: " + baz); =} } main reactor { diff --git a/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf b/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf index 99d5fe59db..7c869eed8b 100644 --- a/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf +++ b/test/TypeScript/src/docker/federated/DistributedCountContainerized.lf @@ -3,7 +3,7 @@ * * @author Hou Seng (Steven) Wong */ - target TypeScript { +target TypeScript { timeout: 5 sec, docker: true }; diff --git a/test/TypeScript/src/federated/DistributedCount.lf b/test/TypeScript/src/federated/DistributedCount.lf index 1940553c2a..52f22e9b53 100644 --- a/test/TypeScript/src/federated/DistributedCount.lf +++ b/test/TypeScript/src/federated/DistributedCount.lf @@ -6,7 +6,7 @@ * @author Edward A. Lee * @author Hokeun Kim */ - target TypeScript { +target TypeScript { timeout: 5 sec }; diff --git a/test/TypeScript/src/federated/StopAtShutdown.lf b/test/TypeScript/src/federated/StopAtShutdown.lf index bde91c3a7d..9d9b092487 100644 --- a/test/TypeScript/src/federated/StopAtShutdown.lf +++ b/test/TypeScript/src/federated/StopAtShutdown.lf @@ -4,7 +4,7 @@ * * Original bug discovered by Steven Wong */ - target TypeScript { +target TypeScript { timeout: 2 sec } diff --git a/test/TypeScript/src/lib/Imported.lf b/test/TypeScript/src/lib/Imported.lf index d06260e695..47c665fff6 100644 --- a/test/TypeScript/src/lib/Imported.lf +++ b/test/TypeScript/src/lib/Imported.lf @@ -8,6 +8,6 @@ reactor Imported { input x:number; a = new ImportedAgain(); reaction(x) -> a.x {= - a.x = (x as number); + a.x = (x as number); =} } diff --git a/test/TypeScript/src/multiport/BankReactionsInContainer.lf b/test/TypeScript/src/multiport/BankReactionsInContainer.lf index a973172aa6..193d94d961 100644 --- a/test/TypeScript/src/multiport/BankReactionsInContainer.lf +++ b/test/TypeScript/src/multiport/BankReactionsInContainer.lf @@ -24,7 +24,7 @@ reactor R { console.log("Inner received " + inp[i] + " inp bank " + this.getBankIndex() + ", channel " + i); received = true; if (inp[i] != this.getBankIndex() * 2 + i) { - util.requestErrorStop("Expected " + this.getBankIndex() * 2 + i + "."); + util.requestErrorStop("Expected " + this.getBankIndex() * 2 + i + "."); } } } diff --git a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf index 2db6644a39..ca8aa9baaa 100644 --- a/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf +++ b/test/TypeScript/src/multiport/MultiportFromBankHierarchyAfter.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients. - // Here, the bank is smaller than the width of the sending port. +// Here, the bank is smaller than the width of the sending port. target TypeScript { timeout: 2 sec }; diff --git a/test/TypeScript/src/multiport/MultiportToBankDouble.lf b/test/TypeScript/src/multiport/MultiportToBankDouble.lf index 3fcaa49ce6..41b44f7294 100644 --- a/test/TypeScript/src/multiport/MultiportToBankDouble.lf +++ b/test/TypeScript/src/multiport/MultiportToBankDouble.lf @@ -1,5 +1,5 @@ // Check multiport output to bank of recipients where the source - // has two reactions that write to the output. +// has two reactions that write to the output. target TypeScript { timeout: 2 sec }; diff --git a/test/TypeScript/src/multiport/MultiportToHierarchy.lf b/test/TypeScript/src/multiport/MultiportToHierarchy.lf index 32f2ea1326..051524fe12 100644 --- a/test/TypeScript/src/multiport/MultiportToHierarchy.lf +++ b/test/TypeScript/src/multiport/MultiportToHierarchy.lf @@ -1,5 +1,5 @@ // Check multiport output to multiport input, where the latter is a hierarchical reactor. - // Note that the destination reactor has width wider than the sender, so one input is dangling. +// Note that the destination reactor has width wider than the sender, so one input is dangling. target TypeScript { timeout: 2 sec, }; diff --git a/test/TypeScript/src/multiport/ReactionToContainedBank.lf b/test/TypeScript/src/multiport/ReactionToContainedBank.lf index b664553c20..8d7a151498 100644 --- a/test/TypeScript/src/multiport/ReactionToContainedBank.lf +++ b/test/TypeScript/src/multiport/ReactionToContainedBank.lf @@ -1,5 +1,5 @@ // Test reaction sending messages to a contained bank of reactors. - target TypeScript { +target TypeScript { timeout: 1 sec }; import TestCount from "../lib/TestCount.lf"; diff --git a/test/TypeScript/src/target/AfterNoTypes.lf b/test/TypeScript/src/target/AfterNoTypes.lf index edc7b78f4b..6f637cd486 100644 --- a/test/TypeScript/src/target/AfterNoTypes.lf +++ b/test/TypeScript/src/target/AfterNoTypes.lf @@ -9,7 +9,7 @@ reactor Foo { input x; output y; reaction(x) -> y {= - // Do something + // Do something =} } reactor Print { From 065468aa4b0678069845cab6c031e2f69a91f5ab Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 19 May 2022 12:22:18 -0700 Subject: [PATCH 47/58] [tests] Clean up after previous few commits. --- test/Python/src/multiport/NestedBanks.lf | 20 ++++++++++---------- test/TypeScript/src/NativeListsAndTimes.lf | 1 - 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/test/Python/src/multiport/NestedBanks.lf b/test/Python/src/multiport/NestedBanks.lf index 572de19bb5..055477e59e 100644 --- a/test/Python/src/multiport/NestedBanks.lf +++ b/test/Python/src/multiport/NestedBanks.lf @@ -33,27 +33,27 @@ reactor C(bank_index(0)) { reactor D { input[2] u; reaction(u) {= - for (i, p) in enumerate(u): - print(f"d.u[{i}] received {p.value}.") - if p.value != (6 + i): - sys.stderr.write(f"ERROR: Expected {6 + i} but received {p.value}.\n") - exit(1) + for (i, p) in enumerate(u): + print(f"d.u[{i}] received {p.value}.") + if p.value != (6 + i): + sys.stderr.write(f"ERROR: Expected {6 + i} but received {p.value}.\n") + exit(1) =} } reactor E { input[8] t; reaction(t) {= for (i, p) in enumerate(t): - print(f"e.t[{i}] received {p.value}.") + print(f"e.t[{i}] received {p.value}.") =} } reactor F(c_bank_index(0)) { input w; reaction(w) {= - print(f"c[{self.c_bank_index}].f.w received {w.value}.") - if w.value != self.c_bank_index * 2: - sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2} but received {w.value}.\n") - exit(1) + print(f"c[{self.c_bank_index}].f.w received {w.value}.") + if w.value != self.c_bank_index * 2: + sys.stderr.write(f"ERROR: Expected {self.c_bank_index * 2} but received {w.value}.\n") + exit(1) =} } reactor G(c_bank_index(0)) { diff --git a/test/TypeScript/src/NativeListsAndTimes.lf b/test/TypeScript/src/NativeListsAndTimes.lf index bee545bc24..5e27a379b7 100644 --- a/test/TypeScript/src/NativeListsAndTimes.lf +++ b/test/TypeScript/src/NativeListsAndTimes.lf @@ -18,7 +18,6 @@ main reactor (x:number(0), state baz(p); // Implicit type int[] state period(z); // Implicit type time reaction(tick) {= - var x = 0; // Target code =} From d8675a5c9f929204ba8ff0d7a8fb3dc66c334576 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 19 May 2022 19:45:53 -0700 Subject: [PATCH 48/58] Clean up after merge. --- ...tributedCountDecentralizedLateHierarchy.lf | 98 ------------------- ...stributedCentralizedPrecedenceHierarchy.lf | 69 ------------- 2 files changed, 167 deletions(-) delete mode 100644 test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf delete mode 100644 test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf diff --git a/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf b/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf deleted file mode 100644 index e8a203bd6c..0000000000 --- a/test/Python/src/federated/failing/DistributedCountDecentralizedLateHierarchy.lf +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Test a form of a distributed deterministic system - * where a federate that receives timestamped messages has a timer in addition to the messages - * as triggers. Therefore, careful coordination of the advancement of time using Ptides is needed. - * In addition, this test shows that the STP violation of the reaction - * is passed down the hierarchy until it is handled. - * - * @author Edward A. Lee - * @author Soroush Bateni - */ - -// reason for failing: in_.intended_tag are not supported in python target - -target Python { - timeout: 4900 msec, - coordination: decentralized -}; - -import Count from "../lib/Count.lf"; - -reactor ImportantActuator { - input in:int; - state success:int(0); - state success_stp_violation:int(0); - timer t(0, 10 usec); // Force a timer to be invoke periodically - // to ensure logical time will advance in the - // absence of incoming messages. - state c:int(0); - reaction(in) {= - tag_t current_tag = get_current_tag(); - printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", - lf.time.logical_elapsed(), - get_microstep(), - in->value, - in->intended_tag.time - get_start_time(), - in->intended_tag.microstep); - if (lf.tag_compare((tag_t){.time=current_tag.time - get_start_time(), .microstep=current_tag.microstep}, - (tag_t){.time=SEC(1) * self->c, .microstep=0}) == 0) { - self->success++; // Message was on-time - } - self->c++; - =} STP (0) {= - tag_t current_tag = get_current_tag(); - printf("Message violated STP offset by (%lld, %u).\n", - current_tag.time - in->intended_tag.time, - current_tag.microstep - in->intended_tag.microstep); - self->success_stp_violation++; - self->c++; - =} - reaction(t) {= - // Do nothing. - =} - - reaction(shutdown) {= - if ((self->success + self->success_stp_violation) != 5) { - fprintf(stderr, "Failed to detect STP violations in messages.\n"); - exit(1); - } else { - printf("Successfully detected STP violations (%d violations, %d on-time).\n", self->success_stp_violation, self->success); - } - =} -} - -reactor Print { - input in:int; - reaction(in) {= - tag_t current_tag = get_current_tag(); - printf("At tag (%lld, %u) received %d. Intended tag is (%lld, %u).\n", - current_tag.time - get_start_time(), - current_tag.microstep, - in->value, - in->intended_tag.time - get_start_time(), - in->intended_tag.microstep); - =} - -} - -reactor Receiver { - input in:int; - timer t(0, 10 msec); // Force a timer to be invoke periodically - // to ensure logical time will advance in the - // absence of incoming messages. - state c:int(0); - p = new Print(); - a = new ImportantActuator(); - in -> p.in; - in -> a.in; - - reaction(t) {= - // Do nothing. - =} -} - -federated reactor { - c = new Count(); - r = new Receiver(); - c.out -> r.in; // Indicating a 'logical' connection. -} diff --git a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf b/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf deleted file mode 100644 index c96dca8ba0..0000000000 --- a/test/Python/src/federated/failing/LoopDistributedCentralizedPrecedenceHierarchy.lf +++ /dev/null @@ -1,69 +0,0 @@ -/** - * This tests that the precedence order of reaction invocation is kept - * in the hierarchy of reactors when a feedback loop is present in centralized coordination. - * - * @author Edward A. Lee - * @author Soroush Bateni - */ - -// reason for failing: lf_comma_separated_time() not supported in the python target - - -target Python { - flags: "-Wall", - coordination: centralized, - coordination-options: {advance-message-interval: 100 msec}, - timeout: 5 sec -} - -reactor Contained (incr:int(1)) { - timer t(0, 1 sec); - input in:int; - state count:int(0); - state received_count:int(0); - reaction(t) {= - self->count += self->incr; - =} - reaction(in) {= - self->received_count = self->count; - =} - reaction(t) {= - if (self->received_count != self->count) { - lf_print_error_and_exit("reaction(t) was invoked before reaction(in). Precedence order was not kept."); - } - =} -} - -reactor Looper(incr:int(1), delay:time(0 msec)) { - input in:int; - output out:int; - state count:int(0); - timer t(0, 1 sec); - - c = new Contained(incr = incr); - - reaction(t) -> out {= - info_print("Sending network output %d", self->count); - 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_comma_separated_time(time_buffer, time_lag); - info_print("Received %d. Logical time is behind physical time by %s nsec.", in->value, time_buffer); - =} - in->c.in; - reaction(shutdown) {= - info_print("******* Shutdown invoked."); - if (self->count != 6 * self->incr) { - lf_print_error_and_exit("Failed to receive all six expected inputs."); - } - =} -} -federated reactor (delay:time(0)) { - left = new Looper(); - right = new Looper(incr = -1); - left.out -> right.in; - right.out -> left.in; -} From 1e2ac1f2ac2220b2847a4f043e7ab21ec84920ee Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Thu, 19 May 2022 19:54:30 -0700 Subject: [PATCH 49/58] [tests] Another ad hoc patch in LSP tests. --- org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java index 2c670086a7..69f7736ae8 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java @@ -29,7 +29,7 @@ class ErrorInserter { /** A basic error inserter builder on which more specific error inserters can be built. */ private static final Builder BASE_ERROR_INSERTER = new Builder() - .insertCondition((s0, s1) -> Stream.of(";", "}", "{").anyMatch(s0::endsWith)) + .insertCondition((s0, s1) -> Stream.of(s0, s1).allMatch(it -> Stream.of(";", "}", "{").anyMatch(it::endsWith))) .insertCondition((s0, s1) -> !s1.trim().startsWith("else")) .insertable(" 0 = 1;").insertable("some_undeclared_var1524263 = 9;").insertable(" ++;"); public static final Builder C = BASE_ERROR_INSERTER From 04f23bb2d2355f3c80ca088dd81dc4c2e6caf999 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 20 May 2022 08:39:10 -0700 Subject: [PATCH 50/58] Address Python LSP test failure. --- .../org/lflang/generator/python/PythonReactionGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 7c9d678ce5..5c7363349f 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -543,7 +543,7 @@ public static String generatePythonReaction(Reactor reactor, Reaction reaction, code.pr(generatePythonFunction( generatePythonSTPFunctionName(reactionIndex), "", - ASTUtils.toText(reaction.getStp().getCode()), + ASTUtils.toTaggedText(reaction.getStp().getCode()), reactionParameters )); } From a121c89efa99a29af07e7b0ce161364ee8521b10 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 20 May 2022 15:40:35 -0700 Subject: [PATCH 51/58] [lsp] Rename toText etc. and refactor accordingly. --- org.lflang/src/org/lflang/ASTUtils.java | 13 ++-- org.lflang/src/org/lflang/AstExtensions.kt | 12 +--- .../src/org/lflang/generator/CodeMap.java | 60 +++++++++++-------- .../src/org/lflang/generator/Range.java | 3 +- .../lflang/generator/ReactionInstance.java | 2 +- .../src/org/lflang/generator/TargetTypes.java | 2 +- .../org/lflang/generator/c/CGenerator.java | 4 +- .../generator/c/CReactionGenerator.java | 4 +- .../org/lflang/generator/cpp/CppExtensions.kt | 3 +- .../generator/cpp/CppMethodGenerator.kt | 4 +- .../generator/cpp/CppPreambleGenerator.kt | 6 +- .../generator/cpp/CppReactionGenerator.kt | 5 +- .../generator/cpp/CppReactorGenerator.kt | 6 +- .../python/PythonPreambleGenerator.java | 2 +- .../python/PythonReactionGenerator.java | 6 +- .../org/lflang/generator/rust/RustModel.kt | 8 +-- .../org/lflang/generator/rust/RustTypes.kt | 4 +- .../org/lflang/generator/ts/TSExtensions.kt | 7 +-- .../generator/ts/TSReactionGenerator.kt | 10 ++-- .../lflang/generator/ts/TSReactorGenerator.kt | 2 +- .../org/lflang/validation/LFValidator.java | 11 ++-- 21 files changed, 88 insertions(+), 86 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 0218451c20..abac97ddd2 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -762,26 +762,27 @@ public static List collectElements(Reactor definition, EStructuralFeature //// Utility functions for translating AST nodes into text /** - * Translate the given code into its textual representation. + * Translate the given code into its textual representation + * with {@code CodeMap.Correspondence} tags inserted. * @param node AST node to render as string. * @return Textual representation of the given argument. */ public static String toText(EObject node) { if (node == null) return null; - return ToText.instance.doSwitch(node); + return CodeMap.Correspondence.tag(node, toUntaggedText(node), node instanceof Code); } /** * Translate the given code into its textual representation - * with additional {@code CodeMap.Correspondence} tags inserted. + * without {@code CodeMap.Correspondence} tags. * @param node AST node to render as string. * @return Textual representation of the given argument. */ - public static String toTaggedText(EObject node) { + public static String toUntaggedText(EObject node) { if (node == null) return null; - return CodeMap.Correspondence.tag(node, toText(node), true); + return ToText.instance.doSwitch(node); } /** @@ -876,7 +877,7 @@ public static List elementToListOfStrings(Element value) { public static String baseType(Type type) { if (type != null) { if (type.getCode() != null) { - return toTaggedText(type.getCode()); + return toText(type.getCode()); } else { if (type.isTime()) { return "time"; diff --git a/org.lflang/src/org/lflang/AstExtensions.kt b/org.lflang/src/org/lflang/AstExtensions.kt index 19b773a21c..eb53d40f3d 100644 --- a/org.lflang/src/org/lflang/AstExtensions.kt +++ b/org.lflang/src/org/lflang/AstExtensions.kt @@ -138,13 +138,7 @@ val StateVar.isOfTimeType: Boolean get() = ASTUtils.isOfTimeType(this) /** * Translate this code element into its textual representation - * with additional {@code CodeMap.Correspondence} tags inserted. - * @see ASTUtils.toTaggedText - */ -fun EObject.toTaggedText(): String = ASTUtils.toTaggedText(this) - -/** - * Translate this code element into its textual representation. + * with {@code CodeMap.Correspondence} tags inserted. * @see ASTUtils.toText */ fun EObject.toText(): String = ASTUtils.toText(this) @@ -159,7 +153,7 @@ fun Time.toTimeValue(): TimeValue = ASTUtils.toTimeValue(this) */ val Type.baseType: String get() = when { - code != null -> code.toTaggedText() + code != null -> code.toText() isTime -> "time" else -> id + stars.orEmpty().joinToString() } @@ -172,7 +166,7 @@ val Type.baseType: String */ val String.isZero: Boolean get() = this.toIntOrNull() == 0 -val Code.isZero: Boolean get() = this.toTaggedText().isZero +val Code.isZero: Boolean get() = this.toText().isZero /** diff --git a/org.lflang/src/org/lflang/generator/CodeMap.java b/org.lflang/src/org/lflang/generator/CodeMap.java index 541135de91..dd621e07d0 100644 --- a/org.lflang/src/org/lflang/generator/CodeMap.java +++ b/org.lflang/src/org/lflang/generator/CodeMap.java @@ -27,16 +27,16 @@ public static class Correspondence { // represent any serious effort to embed the string representation of this object in generated code // without introducing a syntax error. Instead, it is done simply because it is easy. private static final Pattern PATTERN = Pattern.compile(String.format( - "/\\*Correspondence: (?%s) \\-> (?%s) \\(src=(?%s)\\)\\*/", + "/\\*Correspondence: (?%s) \\-> (?%s) \\(verbatim=(?true|false); src=(?%s)\\)\\*/", Position.removeNamedCapturingGroups(Range.PATTERN), Position.removeNamedCapturingGroups(Range.PATTERN), ".*?" )); - // TODO(peter): Add "private final boolean verbatim;" and make corresponding enhancements private final Path path; private final Range lfRange; private final Range generatedRange; + private final boolean verbatim; /** * Instantiates a Correspondence between @@ -49,10 +49,11 @@ public static class Correspondence { * associated with * {@code lfRange} */ - public Correspondence(Path path, Range lfRange, Range generatedRange) { + private Correspondence(Path path, Range lfRange, Range generatedRange, boolean verbatim) { this.path = path; this.lfRange = lfRange; this.generatedRange = generatedRange; + this.verbatim = verbatim; } /** @@ -86,25 +87,11 @@ public Range getGeneratedRange() { @Override public String toString() { return String.format( - "/*Correspondence: %s -> %s (src=%s)*/", - lfRange.toString(), generatedRange.toString(), path.toString() + "/*Correspondence: %s -> %s (verbatim=%b; src=%s)*/", + lfRange.toString(), generatedRange.toString(), verbatim, path.toString() ); } - /** - * Returns the Correspondence represented by - * {@code s}. - * @param s a String that represents a - * Correspondence, formatted like the - * output of - * {@code Correspondence::toString} - * @return the Correspondence represented by - * {@code s} - */ - public static Correspondence fromString(String s) { - return fromString(s, Position.ORIGIN); - } - /** * Returns the Correspondence represented by * {@code s}. @@ -123,7 +110,9 @@ public static Correspondence fromString(String s, Position relativeTo) { Range generatedRange = Range.fromString(matcher.group("generatedRange"), relativeTo); return new Correspondence( Path.of(matcher.group("path")), - lfRange, generatedRange + lfRange, + generatedRange, + Boolean.parseBoolean(matcher.group("verbatim")) ); } throw new IllegalArgumentException(String.format("Could not parse %s as a Correspondence.", s)); @@ -158,7 +147,8 @@ public static String tag(EObject astNode, String representation, boolean verbati return new Correspondence( lfPath, new Range(lfStart, lfStart.plus(verbatim ? representation : node.getText())), - new Range(Position.ORIGIN, Position.displacementOf(representation)) + new Range(Position.ORIGIN, Position.displacementOf(representation)), + verbatim ) + representation; } @@ -190,6 +180,13 @@ private static int indexOf(String s, String imperfectSubstring) { * to ranges in Lingua Franca files. */ private final Map> map; + /** + * A mapping from Lingua Franca source paths to mappings + * from ranges in the generated file represented by this + * to whether those ranges are copied verbatim from the + * source. + */ + private final Map> isVerbatimByLfSourceByRange; /* ------------------------- PUBLIC METHODS -------------------------- */ @@ -208,13 +205,14 @@ private static int indexOf(String s, String imperfectSubstring) { */ public static CodeMap fromGeneratedCode(String internalGeneratedCode) { Map> map = new HashMap<>(); + Map> isVerbatimByLfSourceByRange = new HashMap<>(); StringBuilder generatedCode = new StringBuilder(); Iterator it = internalGeneratedCode.lines().iterator(); int zeroBasedLine = 0; while (it.hasNext()) { - generatedCode.append(processGeneratedLine(it.next(), zeroBasedLine++, map)).append('\n'); + generatedCode.append(processGeneratedLine(it.next(), zeroBasedLine++, map, isVerbatimByLfSourceByRange)).append('\n'); } - return new CodeMap(generatedCode.toString(), map); + return new CodeMap(generatedCode.toString(), map, isVerbatimByLfSourceByRange); } /** @@ -251,8 +249,12 @@ public Set lfSourcePaths() { */ public Position adjusted(Path lfFile, Position generatedFilePosition) { NavigableMap mapOfInterest = map.get(lfFile); + Map isVerbatimByRange = isVerbatimByLfSourceByRange.get(lfFile); Map.Entry nearestEntry = mapOfInterest.floorEntry(Range.degenerateRange(generatedFilePosition)); if (nearestEntry == null) return Position.ORIGIN; + if (!isVerbatimByRange.get(nearestEntry.getKey())) { + return nearestEntry.getValue().getStartInclusive(); + } if (nearestEntry.getKey().contains(generatedFilePosition)) { return nearestEntry.getValue().getStartInclusive().plus( generatedFilePosition.minus(nearestEntry.getKey().getStartInclusive()) @@ -281,9 +283,14 @@ public Range adjusted(Path lfFile, Range generatedFileRange) { /* ------------------------- PRIVATE METHODS ------------------------- */ - private CodeMap(String generatedCode, Map> map) { + private CodeMap( + String generatedCode, Map> map, + Map> isVerbatimByLfSourceByRange + ) { this.generatedCode = generatedCode; this.map = map; + this.isVerbatimByLfSourceByRange = isVerbatimByLfSourceByRange; } /** @@ -299,7 +306,8 @@ private CodeMap(String generatedCode, Map> map) private static String processGeneratedLine( String line, int zeroBasedLineIndex, - Map> map + Map> map, + Map> isVerbatimByLfSourceByRange ) { Matcher matcher = Correspondence.PATTERN.matcher(line); StringBuilder cleanedLine = new StringBuilder(); @@ -312,6 +320,8 @@ private static String processGeneratedLine( ); if (!map.containsKey(c.path)) map.put(c.path, new TreeMap<>()); map.get(c.path).put(c.generatedRange, c.lfRange); + if (!isVerbatimByLfSourceByRange.containsKey(c.path)) isVerbatimByLfSourceByRange.put(c.path, new HashMap<>()); + isVerbatimByLfSourceByRange.get(c.path).put(c.generatedRange, c.verbatim); lastEnd = matcher.end(); } cleanedLine.append(line.substring(lastEnd)); diff --git a/org.lflang/src/org/lflang/generator/Range.java b/org.lflang/src/org/lflang/generator/Range.java index a24d7959ca..ffca1104d9 100644 --- a/org.lflang/src/org/lflang/generator/Range.java +++ b/org.lflang/src/org/lflang/generator/Range.java @@ -58,8 +58,7 @@ public Position getEndExclusive() { @Override public boolean equals(Object o) { - if (!(o instanceof Range)) return false; - Range r = (Range) o; + if (!(o instanceof Range r)) return false; return start.equals(r.start); } diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index c4b223fa86..a0f9d53432 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -81,7 +81,7 @@ public ReactionInstance( // If the reaction body starts with the magic string // UNORDERED_REACTION_MARKER, then mark it unordered, // overriding the argument. - String body = ASTUtils.toTaggedText(definition.getCode()); + String body = ASTUtils.toText(definition.getCode()); if (body != null && body.contains(UNORDERED_REACTION_MARKER)) { this.isUnordered = true; } diff --git a/org.lflang/src/org/lflang/generator/TargetTypes.java b/org.lflang/src/org/lflang/generator/TargetTypes.java index 3628fb2ebe..c667d45a20 100644 --- a/org.lflang/src/org/lflang/generator/TargetTypes.java +++ b/org.lflang/src/org/lflang/generator/TargetTypes.java @@ -238,7 +238,7 @@ default String getTargetExpr(Expression expr, InferredType type) { } else if (expr instanceof Literal) { return ASTUtils.addZeroToLeadingDot(((Literal) expr).getLiteral()); // here we don't escape } else if (expr instanceof Code) { - return ASTUtils.toTaggedText((Code) expr); + return ASTUtils.toText(expr); } else { throw new IllegalStateException("Invalid value " + expr); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 2d1720dc25..2eb2b45907 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -1198,7 +1198,7 @@ public void generateUserPreamblesForReactor(Reactor reactor) { for (Preamble p : convertToEmptyListIfNull(reactor.getPreambles())) { code.pr("// *********** From the preamble, verbatim:"); code.prSourceLineNumber(p.getCode()); - code.pr(toTaggedText(p.getCode())); + code.pr(toText(p.getCode())); code.pr("\n// *********** End of preamble."); } } @@ -2543,7 +2543,7 @@ protected String generateTopLevelPreambles() { if (this.mainDef != null) { var mainModel = (Model) toDefinition(mainDef.getReactorClass()).eContainer(); for (Preamble p : mainModel.getPreambles()) { - code.pr(toTaggedText(p.getCode())); + code.pr(toText(p.getCode())); } } return code.toString(); diff --git a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java index 86835c789a..384b15fec6 100644 --- a/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CReactionGenerator.java @@ -1180,7 +1180,7 @@ public static String generateReaction( boolean requiresType ) { var code = new CodeBuilder(); - var body = ASTUtils.toTaggedText(reaction.getCode()); + var body = ASTUtils.toText(reaction.getCode()); String init = generateInitializationForReaction( body, reaction, decl, reactionIndex, types, errorReporter, mainDef, @@ -1221,7 +1221,7 @@ public static String generateFunction(String header, String init, Code code) { function.indent(); function.pr(init); function.prSourceLineNumber(code); - function.pr(ASTUtils.toTaggedText(code)); + function.pr(ASTUtils.toText(code)); function.unindent(); function.pr("}"); return function.toString(); diff --git a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt index ab7b274268..03cd752049 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppExtensions.kt @@ -20,7 +20,6 @@ import org.lflang.lf.VarRef import org.lflang.lf.Visibility import org.lflang.lf.WidthSpec import org.lflang.toText -import org.lflang.toTaggedText import org.lflang.unreachable /************* @@ -99,7 +98,7 @@ fun WidthSpec.toCppCode(): String = terms.joinToString(" + ") { else "1" } } - it.code != null -> it.code.toTaggedText() + it.code != null -> it.code.toText() else -> it.width.toString() } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt index 3497a964c5..17aa30032c 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppMethodGenerator.kt @@ -29,7 +29,7 @@ import org.lflang.generator.PrependOperator import org.lflang.lf.Method import org.lflang.lf.MethodArgument import org.lflang.lf.Reactor -import org.lflang.toTaggedText +import org.lflang.toText /** A C++ code generator for state variables */ class CppMethodGenerator(private val reactor: Reactor) { @@ -45,7 +45,7 @@ class CppMethodGenerator(private val reactor: Reactor) { """ |${reactor.templateLine} |$targetType ${reactor.templateName}::Inner::$name(${cppArgs.joinToString(", ")})$constQualifier { - ${" | "..code.toTaggedText()} + ${" | "..code.toText()} |} """.trimMargin() } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt index 17e130edb7..9ec9b31b3e 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppPreambleGenerator.kt @@ -30,7 +30,7 @@ import org.lflang.generator.PrependOperator import org.lflang.lf.Preamble import org.lflang.model import org.lflang.scoping.LFGlobalScopeProvider -import org.lflang.toTaggedText +import org.lflang.toText import org.lflang.toUnixString @@ -60,7 +60,7 @@ class CppPreambleGenerator( |#include "reactor-cpp/reactor-cpp.hh" ${" |"..includes.joinToString(separator = "\n", prefix = "// include the preambles from imported files \n")} | - ${" |"..publicPreambles.joinToString(separator = "\n") { it.code.toTaggedText() }} + ${" |"..publicPreambles.joinToString(separator = "\n") { it.code.toText() }} """.trimMargin() } } @@ -79,7 +79,7 @@ class CppPreambleGenerator( |using namespace std::chrono_literals; |using namespace reactor::operators; | - ${" |"..privatePreambles.joinToString(separator = "\n") { it.code.toTaggedText() }} + ${" |"..privatePreambles.joinToString(separator = "\n") { it.code.toText() }} """.trimMargin() } } diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt index 2a03008378..f418255c35 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactionGenerator.kt @@ -30,7 +30,6 @@ import org.lflang.label import org.lflang.lf.* import org.lflang.priority import org.lflang.toText -import org.lflang.toTaggedText /** A C++ code generator for reactions and their function bodies */ class CppReactionGenerator( @@ -145,7 +144,7 @@ class CppReactionGenerator( |// reaction ${reaction.label} |${reactor.templateLine} ${" |"..getFunctionDefinitionSignature(reaction, "body")} { - ${" | "..reaction.code.toTaggedText()} + ${" | "..reaction.code.toText()} |} | """.trimMargin() @@ -156,7 +155,7 @@ class CppReactionGenerator( return """ |${reactor.templateLine} ${" |"..getFunctionDefinitionSignature(reaction, "deadline_handler")} { - ${" | "..reaction.deadline.code.toTaggedText()} + ${" | "..reaction.deadline.code.toText()} |} | """.trimMargin() diff --git a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt index eca65cb197..85556a83a9 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppReactorGenerator.kt @@ -28,7 +28,7 @@ import org.lflang.ErrorReporter import org.lflang.generator.PrependOperator import org.lflang.isGeneric import org.lflang.lf.Reactor -import org.lflang.toTaggedText +import org.lflang.toText import org.lflang.toUnixString /** @@ -61,11 +61,11 @@ class CppReactorGenerator(private val reactor: Reactor, fileConfig: CppFileConfi private fun publicPreamble() = reactor.preambles.filter { it.isPublic } - .joinToString(separator = "\n", prefix = "// public preamble\n") { it.code.toTaggedText() } + .joinToString(separator = "\n", prefix = "// public preamble\n") { it.code.toText() } private fun privatePreamble() = reactor.preambles.filter { it.isPrivate } - .joinToString(separator = "\n", prefix = "// private preamble\n") { it.code.toTaggedText() } + .joinToString(separator = "\n", prefix = "// private preamble\n") { it.code.toText() } /** Generate a C++ header file declaring the given reactor. */ fun generateHeader() = with(PrependOperator) { diff --git a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java index 0821ab0a5d..5b185e6c27 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonPreambleGenerator.java @@ -26,7 +26,7 @@ public class PythonPreambleGenerator { */ public static String generatePythonPreambles(List preambles) { List preamblesCode = new ArrayList<>(); - preambles.forEach(p -> preamblesCode.add(ASTUtils.toTaggedText(p.getCode()))); + preambles.forEach(p -> preamblesCode.add(ASTUtils.toText(p.getCode()))); return preamblesCode.size() > 0 ? String.join("\n", "# From the preamble, verbatim:", String.join("\n", preamblesCode), diff --git a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java index 5c7363349f..3e408685ae 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonReactionGenerator.java @@ -535,7 +535,7 @@ public static String generatePythonReaction(Reactor reactor, Reaction reaction, code.pr(generatePythonFunction( generatePythonReactionFunctionName(reactionIndex), inits.toString(), - ASTUtils.toTaggedText(reaction.getCode()), + ASTUtils.toText(reaction.getCode()), reactionParameters )); // Generate code for the STP violation handler function, if there is one. @@ -543,7 +543,7 @@ public static String generatePythonReaction(Reactor reactor, Reaction reaction, code.pr(generatePythonFunction( generatePythonSTPFunctionName(reactionIndex), "", - ASTUtils.toTaggedText(reaction.getStp().getCode()), + ASTUtils.toText(reaction.getStp().getCode()), reactionParameters )); } @@ -552,7 +552,7 @@ public static String generatePythonReaction(Reactor reactor, Reaction reaction, code.pr(generatePythonFunction( generatePythonDeadlineFunctionName(reactionIndex), "", - ASTUtils.toTaggedText(reaction.getDeadline().getCode()), + ASTUtils.toText(reaction.getDeadline().getCode()), reactionParameters )); } diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 6021be00fa..c3ec7bac97 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -334,7 +334,7 @@ sealed class ReactorComponent { ?.let { TimeValue(it.toLong(), DEFAULT_TIME_UNIT_IN_TIMER).toRustTimeExpr() } ?: throw InvalidLfSourceException("Not an integer literal", this) this is Time -> toRustTimeExpr() - this is Code -> toTaggedText().inBlock() + this is Code -> toText().inBlock() else -> RustTypes.getTargetExpr(this, InferredType.time()) } } @@ -390,7 +390,7 @@ fun WidthSpec.toRustExpr(): String = terms.joinToString(" + ") { when { it.parameter != null -> it.parameter.name it.port != null -> throw UnsupportedGeneratorFeatureException("Width specs that use a port") - it.code != null -> it.code.toTaggedText().inBlock() + it.code != null -> it.code.toText().inBlock() else -> it.width.toString() } } @@ -549,7 +549,7 @@ object RustModelBuilder { this[DepKind.Uses] = makeDeps { sources } this[DepKind.Effects] = makeDeps { effects } }, - body = n.code.toTaggedText(), + body = n.code.toText(), isStartup = n.triggers.any { it.isStartup }, isShutdown = n.triggers.any { it.isShutdown }, debugLabel = ASTUtils.label(n), @@ -577,7 +577,7 @@ object RustModelBuilder { typeParamList = reactor.typeParms.map { TypeParamInfo(targetCode = it.toText(), it.identifier, it.locationInfo()) }, - preambles = reactor.preambles.map { it.code.toTaggedText() }, + preambles = reactor.preambles.map { it.code.toText() }, stateVars = reactor.stateVars.map { StateVarInfo( lfName = it.name, diff --git a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt index 535e12f38f..f555aff7fb 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustTypes.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustTypes.kt @@ -24,7 +24,7 @@ package org.lflang.generator.rust -import org.lflang.ASTUtils.toTaggedText +import org.lflang.ASTUtils.toText import org.lflang.InferredType import org.lflang.TimeValue import org.lflang.generator.TargetCode @@ -54,7 +54,7 @@ object RustTypes : TargetTypes { else ident override fun getTargetExpr(expr: Expression, type: InferredType?): String = when (expr) { - is Code -> toTaggedText(expr).inBlock() + is Code -> toText(expr).inBlock() else -> super.getTargetExpr(expr, type) } diff --git a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt index e70489c0ef..9cf24511cb 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSExtensions.kt @@ -1,6 +1,5 @@ package org.lflang.generator.ts -import org.lflang.federated.FederateInstance import org.lflang.isBank import org.lflang.isMultiport import org.lflang.lf.Action @@ -8,7 +7,7 @@ import org.lflang.lf.Parameter import org.lflang.lf.Port import org.lflang.lf.Type import org.lflang.lf.WidthSpec -import org.lflang.toTaggedText +import org.lflang.toText /** * The following definition provide extension that are useful for TypeScript target. @@ -17,7 +16,7 @@ import org.lflang.toTaggedText */ fun WidthSpec.toTSCode(): String = terms.joinToString(" + ") { when { - it.parameter != null -> "${it.parameter.name}" + it.parameter != null -> it.parameter.name it.port != null -> with(it.port) { if (container?.isBank == true) { if ((variable as Port).isMultiport) "this.${container.name}.all().length * this.${container.name}.all()[0].${variable.name}.width()" @@ -27,7 +26,7 @@ fun WidthSpec.toTSCode(): String = terms.joinToString(" + ") { else "1" } } - it.code != null -> it.code.toTaggedText() + it.code != null -> it.code.toText() else -> it.width.toString() } } diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt index 1674b279cc..51d2178039 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactionGenerator.kt @@ -8,7 +8,7 @@ import org.lflang.isBank import org.lflang.isMultiport import org.lflang.lf.* import org.lflang.lf.Timer -import org.lflang.toTaggedText +import org.lflang.toText import java.util.* import kotlin.collections.HashSet @@ -87,7 +87,7 @@ class TSReactionGenerator( ${" | "..reactPrologue} | // =============== END deadline prologue | try { - ${" | "..reaction.deadline.code.toTaggedText()} + ${" | "..reaction.deadline.code.toText()} | } finally { | // =============== START deadline epilogue ${" | "..reactEpilogue} @@ -128,7 +128,7 @@ class TSReactionGenerator( ${" | "..reactPrologue} | // =============== END react prologue | try { - ${" | "..reaction.code.toTaggedText()} + ${" | "..reaction.code.toText()} | } finally { | // =============== START react epilogue ${" | "..reactEpilogue} @@ -453,8 +453,8 @@ class TSReactionGenerator( // TODO(hokeun): Find a better way to gracefully handle this skipping. // Do not add reactions created by generateNetworkOutputControlReactionBody // or generateNetworkInputControlReactionBody. - if (reaction.code.toTaggedText().contains("generateNetworkOutputControlReactionBody") - || reaction.code.toTaggedText().contains("generateNetworkInputControlReactionBody")) { + if (reaction.code.toText().contains("generateNetworkOutputControlReactionBody") + || reaction.code.toText().contains("generateNetworkInputControlReactionBody")) { continue; } if (federate.contains(reaction)) { diff --git a/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt b/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt index 55b3334552..0b00f8c351 100644 --- a/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt +++ b/org.lflang/src/org/lflang/generator/ts/TSReactorGenerator.kt @@ -89,7 +89,7 @@ class TSReactorGenerator( preambleCodes.add(with(PrependOperator) { """ |// *********** From the preamble, verbatim: - |${preamble.code.toTaggedText()} + |${preamble.code.toText()} | |// *********** End of preamble."""}.trimMargin()) } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 38502998ee..58a24836e2 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -32,7 +32,7 @@ import static org.lflang.ASTUtils.isOfTimeType; import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; -import static org.lflang.ASTUtils.toText; +import static org.lflang.ASTUtils.toUntaggedText; import java.io.IOException; import java.util.ArrayList; @@ -214,7 +214,7 @@ public void checkConnection(Connection connection) { Reactor reactor = ASTUtils.getEnclosingReactor(connection); String reactorName = reactor.getName(); error(String.format("Connection in reactor %s creates", reactorName) + - String.format("a cyclic dependency between %s and %s.", toText(lp), toText(rp)), + String.format("a cyclic dependency between %s and %s.", toUntaggedText(lp), toUntaggedText(rp)), Literals.CONNECTION__DELAY); } } @@ -756,6 +756,7 @@ public void checkReaction(Reaction reaction) { for (NamedInstance it : cycles) { if (it.getDefinition().equals(reaction)) { reactionInCycle = true; + break; } } if (reactionInCycle) { @@ -774,7 +775,7 @@ public void checkReaction(Reaction reaction) { } } if (triggerExistsInCycle) { - trigs.add(toText(tVarRef)); + trigs.add(toUntaggedText(tVarRef)); } } if (trigs.size() > 0) { @@ -793,7 +794,7 @@ public void checkReaction(Reaction reaction) { } } if (sourceExistInCycle) { - sources.add(toText(t)); + sources.add(toUntaggedText(t)); } } if (sources.size() > 0) { @@ -812,7 +813,7 @@ public void checkReaction(Reaction reaction) { } } if (effectExistInCycle) { - effects.add(toText(t)); + effects.add(toUntaggedText(t)); } } if (effects.size() > 0) { From 2d06ded191841ee099862247e50b5846390df3f5 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 20 May 2022 17:20:14 -0700 Subject: [PATCH 52/58] [lsp] Ad hoc patch over an NPE. --- .../src/org/lflang/generator/CodeMap.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/CodeMap.java b/org.lflang/src/org/lflang/generator/CodeMap.java index dd621e07d0..01af28f1d5 100644 --- a/org.lflang/src/org/lflang/generator/CodeMap.java +++ b/org.lflang/src/org/lflang/generator/CodeMap.java @@ -11,10 +11,13 @@ import java.util.regex.Pattern; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.util.LineAndColumn; +import org.lflang.lf.impl.ParameterReferenceImpl; + /** * Encapsulates data about the correspondence between * ranges of generated code and ranges of a Lingua Franca @@ -142,7 +145,7 @@ public static String tag(EObject astNode, String representation, boolean verbati Position lfStart = Position.fromOneBased( oneBasedLfLineAndColumn.getLine(), oneBasedLfLineAndColumn.getColumn() ); - final Path lfPath = Path.of(astNode.eResource().getURI().path()); + final Path lfPath = Path.of(bestEffortGetEResource(astNode).getURI().path()); if (verbatim) lfStart = lfStart.plus(node.getText().substring(0, indexOf(node.getText(), representation))); return new Correspondence( lfPath, @@ -152,6 +155,19 @@ public static String tag(EObject astNode, String representation, boolean verbati ) + representation; } + /** + * Return the {@code eResource} associated with the given AST node. + * This is a dangerous operation which can cause an unrecoverable error. + */ + private static Resource bestEffortGetEResource(EObject astNode) { + 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." + ); + } + /** * Make a best-effort attempt to find the index of * a near substring whose first line is expected to From 26df952ad58133b51b20d69d29210964f50a56e9 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 20 May 2022 17:52:09 -0700 Subject: [PATCH 53/58] [refactoring] Bugfixes related to function renaming. --- org.lflang/src/org/lflang/ASTUtils.java | 2 +- org.lflang/src/org/lflang/generator/python/PyUtil.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index abac97ddd2..227ac94e5b 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -919,7 +919,7 @@ public static boolean isZero(String literal) { } public static boolean isZero(Code code) { - return code != null && isZero(toText(code)); + return code != null && isZero(toUntaggedText(code)); } /** diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/src/org/lflang/generator/python/PyUtil.java index c6508f1d51..eecfa71ae9 100644 --- a/org.lflang/src/org/lflang/generator/python/PyUtil.java +++ b/org.lflang/src/org/lflang/generator/python/PyUtil.java @@ -144,7 +144,7 @@ public static String generateGILReleaseCode() { */ protected static String getPythonTargetValue(Expression expr) { String returnValue; - switch (ASTUtils.toText(expr)) { + switch (ASTUtils.toUntaggedText(expr)) { case "false": returnValue = "False"; break; @@ -164,4 +164,4 @@ protected static String getPythonTargetValue(Expression expr) { return returnValue; } -} \ No newline at end of file +} From 610d67e2ee0713f2ce77388fe82beb1238bb4bd5 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 20 May 2022 22:14:24 -0700 Subject: [PATCH 54/58] [refactoring] Bugfix related to function renaming. --- org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java index 26ca5b3108..c147fd6eaf 100644 --- a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java @@ -33,7 +33,7 @@ private static boolean isSharedPtrType(InferredType type, CTypes types) { } // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = Pattern.compile("^std::shared_ptr<(\\S+)>$"); + static final Pattern sharedPointerVariable = Pattern.compile("^/\\*.+\\*/std::shared_ptr<(\\S+)>$"); /** * Generate code for the body of a reaction that handles the From 7c84b6f5f75c83b6fc9cb3ef5b5432a823194189 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 20 May 2022 22:45:19 -0700 Subject: [PATCH 55/58] [refactoring] Bugfix related to function renaming. --- org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java index c147fd6eaf..3898f957fb 100644 --- a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java @@ -33,7 +33,7 @@ private static boolean isSharedPtrType(InferredType type, CTypes types) { } // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = Pattern.compile("^/\\*.+\\*/std::shared_ptr<(\\S+)>$"); + static final Pattern sharedPointerVariable = Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); /** * Generate code for the body of a reaction that handles the @@ -120,7 +120,7 @@ public static String generateNetworkReceiverBody( } else if (isSharedPtrType(portType, types)) { var matcher = sharedPointerVariable.matcher(portTypeStr); if (matcher.find()) { - portTypeStr = matcher.group(1); + portTypeStr = matcher.group("portTypeStr"); } } var ROSDeserializer = new FedROS2CPPSerialization(); From 1b6cadd980d24b3a0f29c33a353cdd575f8688da Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Fri, 20 May 2022 23:39:20 -0700 Subject: [PATCH 56/58] [refactoring] Bugfix related to function renaming. --- .../src/org/lflang/generator/c/CNetworkGenerator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java index 3898f957fb..150a3e6835 100644 --- a/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CNetworkGenerator.java @@ -33,7 +33,7 @@ private static boolean isSharedPtrType(InferredType type, CTypes types) { } // Regular expression pattern for shared_ptr types. - static final Pattern sharedPointerVariable = Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); + static final Pattern sharedPointerVariable = Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?((/\\*.*?\\*/)?(\\S+))+)>$"); /** * Generate code for the body of a reaction that handles the @@ -120,7 +120,7 @@ public static String generateNetworkReceiverBody( } else if (isSharedPtrType(portType, types)) { var matcher = sharedPointerVariable.matcher(portTypeStr); if (matcher.find()) { - portTypeStr = matcher.group("portTypeStr"); + portTypeStr = matcher.group("type"); } } var ROSDeserializer = new FedROS2CPPSerialization(); @@ -266,7 +266,7 @@ public static String generateNetworkSenderBody( } else if (isSharedPtrType(type, types)) { var matcher = sharedPointerVariable.matcher(typeStr); if (matcher.find()) { - typeStr = matcher.group(1); + typeStr = matcher.group("type"); } } var ROSSerializer = new FedROS2CPPSerialization(); From e933452e89c1d3badb0ab53196957c7be62e8708 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 23 May 2022 15:50:41 -0700 Subject: [PATCH 57/58] Address comments from code review. --- org.lflang/src/org/lflang/ASTUtils.java | 12 +++++++----- .../src/org/lflang/generator/python/PyUtil.java | 2 +- .../src/org/lflang/validation/LFValidator.java | 10 +++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 227ac94e5b..6f0f6921d3 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -764,22 +764,25 @@ public static List collectElements(Reactor definition, EStructuralFeature /** * Translate the given code into its textual representation * with {@code CodeMap.Correspondence} tags inserted. + * This method should be used to generate code. * @param node AST node to render as string. * @return Textual representation of the given argument. */ public static String toText(EObject node) { if (node == null) return null; - return CodeMap.Correspondence.tag(node, toUntaggedText(node), node instanceof Code); + return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); } /** * Translate the given code into its textual representation * without {@code CodeMap.Correspondence} tags. + * This method should be used for analyzing AST nodes in + * cases where they are easiest to analyze as strings. * @param node AST node to render as string. * @return Textual representation of the given argument. */ - public static String toUntaggedText(EObject node) { + public static String toOriginalText(EObject node) { if (node == null) return null; return ToText.instance.doSwitch(node); @@ -919,7 +922,7 @@ public static boolean isZero(String literal) { } public static boolean isZero(Code code) { - return code != null && isZero(toUntaggedText(code)); + return code != null && isZero(toOriginalText(code)); } /** @@ -1367,7 +1370,7 @@ public static boolean belongsTo(EObject eobject, Reactor reactor) { * @param parameter The parameter. * @param instantiations The (optional) list of instantiations. * - * @return The integer value of the parameter, or null if does not have an integer value. + * @return The integer value of the parameter, or null if it does not have an integer value. * * @throws IllegalArgumentException If an instantiation provided is not an * instantiation of the reactor class that is parameterized by the @@ -1381,7 +1384,6 @@ public static Integer initialValueInt(Parameter parameter, List i return null; } try { - // FIXME: why does this sum the values in the list?? result += Integer.decode(((Literal) expr).getLiteral()); } catch (NumberFormatException ex) { return null; diff --git a/org.lflang/src/org/lflang/generator/python/PyUtil.java b/org.lflang/src/org/lflang/generator/python/PyUtil.java index eecfa71ae9..3db866dfef 100644 --- a/org.lflang/src/org/lflang/generator/python/PyUtil.java +++ b/org.lflang/src/org/lflang/generator/python/PyUtil.java @@ -144,7 +144,7 @@ public static String generateGILReleaseCode() { */ protected static String getPythonTargetValue(Expression expr) { String returnValue; - switch (ASTUtils.toUntaggedText(expr)) { + switch (ASTUtils.toOriginalText(expr)) { case "false": returnValue = "False"; break; diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 58a24836e2..c07456d2a7 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -32,7 +32,7 @@ import static org.lflang.ASTUtils.isOfTimeType; import static org.lflang.ASTUtils.isZero; import static org.lflang.ASTUtils.toDefinition; -import static org.lflang.ASTUtils.toUntaggedText; +import static org.lflang.ASTUtils.toOriginalText; import java.io.IOException; import java.util.ArrayList; @@ -214,7 +214,7 @@ public void checkConnection(Connection connection) { Reactor reactor = ASTUtils.getEnclosingReactor(connection); String reactorName = reactor.getName(); error(String.format("Connection in reactor %s creates", reactorName) + - String.format("a cyclic dependency between %s and %s.", toUntaggedText(lp), toUntaggedText(rp)), + String.format("a cyclic dependency between %s and %s.", toOriginalText(lp), toOriginalText(rp)), Literals.CONNECTION__DELAY); } } @@ -775,7 +775,7 @@ public void checkReaction(Reaction reaction) { } } if (triggerExistsInCycle) { - trigs.add(toUntaggedText(tVarRef)); + trigs.add(toOriginalText(tVarRef)); } } if (trigs.size() > 0) { @@ -794,7 +794,7 @@ public void checkReaction(Reaction reaction) { } } if (sourceExistInCycle) { - sources.add(toUntaggedText(t)); + sources.add(toOriginalText(t)); } } if (sources.size() > 0) { @@ -813,7 +813,7 @@ public void checkReaction(Reaction reaction) { } } if (effectExistInCycle) { - effects.add(toUntaggedText(t)); + effects.add(toOriginalText(t)); } } if (effects.size() > 0) { From a8e68ffac5071786ddfc8fd6f4c7a78b3ceaa2ca Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 24 May 2022 13:59:48 -0700 Subject: [PATCH 58/58] Address comments from code review. --- org.lflang/src/org/lflang/ASTUtils.java | 12 ++++++------ .../src/org/lflang/generator/ReactionInstance.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/org/lflang/ASTUtils.java b/org.lflang/src/org/lflang/ASTUtils.java index 6f0f6921d3..404fbf1b0e 100644 --- a/org.lflang/src/org/lflang/ASTUtils.java +++ b/org.lflang/src/org/lflang/ASTUtils.java @@ -763,28 +763,28 @@ public static List collectElements(Reactor definition, EStructuralFeature /** * Translate the given code into its textual representation - * with {@code CodeMap.Correspondence} tags inserted. + * with {@code CodeMap.Correspondence} tags inserted, or + * return the empty string if {@code node} is {@code null}. * This method should be used to generate code. * @param node AST node to render as string. * @return Textual representation of the given argument. */ public static String toText(EObject node) { - if (node == null) - return null; + if (node == null) return ""; return CodeMap.Correspondence.tag(node, toOriginalText(node), node instanceof Code); } /** * Translate the given code into its textual representation - * without {@code CodeMap.Correspondence} tags. + * without {@code CodeMap.Correspondence} tags, or return + * the empty string if {@code node} is {@code null}. * This method should be used for analyzing AST nodes in * cases where they are easiest to analyze as strings. * @param node AST node to render as string. * @return Textual representation of the given argument. */ public static String toOriginalText(EObject node) { - if (node == null) - return null; + if (node == null) return ""; return ToText.instance.doSwitch(node); } diff --git a/org.lflang/src/org/lflang/generator/ReactionInstance.java b/org.lflang/src/org/lflang/generator/ReactionInstance.java index a0f9d53432..352f616ebe 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstance.java @@ -82,7 +82,7 @@ public ReactionInstance( // UNORDERED_REACTION_MARKER, then mark it unordered, // overriding the argument. String body = ASTUtils.toText(definition.getCode()); - if (body != null && body.contains(UNORDERED_REACTION_MARKER)) { + if (body.contains(UNORDERED_REACTION_MARKER)) { this.isUnordered = true; }