From 42c1f53c5f6c3fbfd1df5b84497fb0a1b38c893b Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Fri, 28 Jul 2023 13:27:01 +0900 Subject: [PATCH 01/10] Update package.json --- core/src/main/resources/lib/ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/ts/package.json b/core/src/main/resources/lib/ts/package.json index 4a28012180..4797fd56ed 100644 --- a/core/src/main/resources/lib/ts/package.json +++ b/core/src/main/resources/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#ts-level-assignment", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#ts-cyclic-dependencies", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From 050729ab02bd63ba7ebd57857a19d172e58b8a63 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Sat, 29 Jul 2023 16:49:14 +0900 Subject: [PATCH 02/10] Pass the TPO level info to network reactors --- .../federated/generator/FedASTUtils.java | 13 +++++++------ .../org/lflang/validation/AttributeSpec.java | 2 +- .../generator/ts/TSConstructorGenerator.kt | 19 ++++++++++++++----- .../generator/ts/TSInstanceGenerator.kt | 15 ++++++++------- .../lflang/generator/ts/TSReactorGenerator.kt | 13 +++++-------- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java b/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java index d38237c71b..5b4492942d 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java +++ b/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java @@ -43,6 +43,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IteratorExtensions; +import org.lflang.AttributeUtils; import org.lflang.InferredType; import org.lflang.MessageReporter; import org.lflang.TargetProperty.CoordinationType; @@ -240,11 +241,11 @@ private static void addNetworkReceiverReactor( .getParent() .reactorDefinition; // Top-level reactor. - // Add the attribute "_NetworkReactor" for the network receiver. + // Add the attribute "_networkReactor" for the network receiver. var a = factory.createAttribute(); - a.setAttrName("_NetworkReactor"); + a.setAttrName("_networkReactor"); var e = factory.createAttrParm(); - e.setValue("Receiver"); + e.setValue("\"receiver\""); a.getAttrParms().add(e); receiver.getAttributes().add(a); @@ -646,11 +647,11 @@ private static Reactor getNetworkSenderReactor( // Initialize Reactor and Reaction AST Nodes Reactor sender = factory.createReactor(); - // Add the attribute "_NetworkReactor" for the network sender. + // Add the attribute "_networkReactor" for the network sender. var a = factory.createAttribute(); - a.setAttrName("_NetworkReactor"); + a.setAttrName("_networkReactor"); var e = factory.createAttrParm(); - e.setValue("Sender"); + e.setValue("\"sender\""); a.getAttrParms().add(e); sender.getAttributes().add(a); diff --git a/core/src/main/java/org/lflang/validation/AttributeSpec.java b/core/src/main/java/org/lflang/validation/AttributeSpec.java index 9e69a28f1f..57405d2983 100644 --- a/core/src/main/java/org/lflang/validation/AttributeSpec.java +++ b/core/src/main/java/org/lflang/validation/AttributeSpec.java @@ -233,7 +233,7 @@ enum AttrParamType { "_tpoLevel", new AttributeSpec(List.of(new AttrParamSpec(VALUE_ATTR, AttrParamType.INT, false)))); ATTRIBUTE_SPECS_BY_NAME.put( - "_NetworkReactor", + "_networkReactor", new AttributeSpec(List.of(new AttrParamSpec(VALUE_ATTR, AttrParamType.STRING, false)))); } } diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt index b8c01a0ee7..0644319f4d 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt @@ -25,7 +25,7 @@ class TSConstructorGenerator( private fun initializeParameter(p: Parameter): String = "${p.name}: ${TSTypes.getInstance().getTargetType(p)} = ${TSTypes.getInstance().getTargetInitializer(p)}" - private fun generateConstructorArguments(reactor: Reactor): String { + private fun generateConstructorArguments(reactor: Reactor, isNetworkReactor: Boolean): String { val arguments = StringJoiner(", \n") if (reactor.isMain || reactor.isFederated) { arguments.add("timeout: TimeValue | undefined = undefined") @@ -46,10 +46,14 @@ class TSConstructorGenerator( arguments.add("fail?: () => void") } + if (isNetworkReactor) { + arguments.add("tpoLevel: number") + } + return arguments.toString() } - private fun generateSuperConstructorCall(reactor: Reactor, isFederate: Boolean): String = + private fun generateSuperConstructorCall(reactor: Reactor, isFederate: Boolean, isNetworkReactor: Boolean): String = if (reactor.isMain) { if (isFederate) { """ @@ -65,7 +69,11 @@ class TSConstructorGenerator( "super(timeout, keepAlive, fast, success, fail);" } } else { - "super(parent);" + if (isNetworkReactor) { + "super(parent, tpoLevel)" + } else { + "super(parent);" + } } // Generate code for setting target configurations. @@ -85,6 +93,7 @@ class TSConstructorGenerator( actions: TSActionGenerator, ports: TSPortGenerator, isFederate: Boolean, + isNetworkReactor: Boolean, isNetworkReceiver: Boolean ): String { val connections = TSConnectionGenerator(reactor.connections, messageReporter) @@ -93,9 +102,9 @@ class TSConstructorGenerator( return with(PrependOperator) { """ |constructor ( - ${" | "..generateConstructorArguments(reactor)} + ${" | "..generateConstructorArguments(reactor, isNetworkReactor)} |) { - ${" | "..generateSuperConstructorCall(reactor, isFederate)} + ${" | "..generateSuperConstructorCall(reactor, isFederate, isNetworkReactor)} ${" | "..generateTargetConfigurations(targetConfig)} ${" | "..instances.generateInstantiations()} ${" | "..timers.generateInstantiations()} diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt index 6cb6aea34f..2911503159 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt @@ -48,19 +48,20 @@ class TSInstanceGenerator( val childReactorInstantiations = LinkedList() var portID = 0 for (childReactor in childReactors) { - var isNetworkSender = false - var isNetworkReceiver = false - val networkReactorAttribute = AttributeUtils.findAttributeByName(childReactor.reactorClass, "_NetworkReactor") - if (networkReactorAttribute != null) { - isNetworkSender = networkReactorAttribute.getAttrParms().get(0).getName() == "Sender" - isNetworkReceiver = networkReactorAttribute.getAttrParms().get(0).getName() == "Receiver" - } + var tpoLevel = AttributeUtils.getFirstArgumentValue(AttributeUtils.findAttributeByName(childReactor, "_tpoLevel")); + val networkReactorAttributeValue = AttributeUtils.getFirstArgumentValue(AttributeUtils.findAttributeByName(childReactor.reactorClass, "_networkReactor")) + var isNetworkReceiver = networkReactorAttributeValue == "receiver" + var isNetworkSender = networkReactorAttributeValue == "sender" + val childReactorArguments = StringJoiner(", ") childReactorArguments.add("this") for (parameter in childReactor.reactorClass.toDefinition().parameters) { childReactorArguments.add(TSTypes.getInstance().getTargetInitializer(parameter, childReactor)) } + if (tpoLevel != null) { + childReactorArguments.add(tpoLevel.toString()); + } if (childReactor.isBank) { childReactorInstantiations.add( "this.${childReactor.name} = " + diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt index e84f012480..73da56bf4c 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSReactorGenerator.kt @@ -97,13 +97,10 @@ ${" |"..preamble.code.toText()} } val isFederate = AttributeUtils.isFederate(reactor) - val networkReactorAttribute = AttributeUtils.findAttributeByName(reactor, "_NetworkReactor") - var isNetworkSender = false - var isNetworkReceiver = false - if (networkReactorAttribute != null) { - isNetworkSender = networkReactorAttribute.getAttrParms().get(0).getName() == "Sender" - isNetworkReceiver = networkReactorAttribute.getAttrParms().get(0).getName() == "Receiver" - } + val networkReactorAttributeValue = AttributeUtils.getFirstArgumentValue(AttributeUtils.findAttributeByName(reactor, "_networkReactor")) + var isNetworkReactor = networkReactorAttributeValue != null + var isNetworkReceiver = networkReactorAttributeValue == "receiver" + var isNetworkSender = networkReactorAttributeValue == "sender" // NOTE: type parameters that are referenced in ports or actions must extend // Present in order for the program to type check. @@ -144,7 +141,7 @@ ${" |"..preamble.code.toText()} ${" | "..actionGenerator.generateClassProperties()} ${" | "..portGenerator.generateClassProperties()} ${" | "..constructorGenerator.generateConstructor(targetConfig, instanceGenerator, timerGenerator, parameterGenerator, - stateGenerator, actionGenerator, portGenerator, isFederate, isNetworkReceiver)} + stateGenerator, actionGenerator, portGenerator, isFederate, isNetworkReactor, isNetworkReceiver)} |} |// =============== END reactor class ${reactor.name} | From 3b6a39f72ac9d360133ae20e991bb48d2426d3be Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun <78055940+byeong-gil@users.noreply.github.com> Date: Sat, 29 Jul 2023 16:50:34 +0900 Subject: [PATCH 03/10] Update FedASTUtils.java --- .../main/java/org/lflang/federated/generator/FedASTUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java b/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java index 5b4492942d..dda752ff93 100644 --- a/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java +++ b/core/src/main/java/org/lflang/federated/generator/FedASTUtils.java @@ -43,7 +43,6 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.lflang.AttributeUtils; import org.lflang.InferredType; import org.lflang.MessageReporter; import org.lflang.TargetProperty.CoordinationType; From 6ded11576c52cc62eecedba059d9cb9d77eb44b5 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Mon, 31 Jul 2023 14:27:03 +0900 Subject: [PATCH 04/10] Handle network reactions without a TPO level --- .../kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt index 0644319f4d..fc8b942a2f 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSConstructorGenerator.kt @@ -47,7 +47,7 @@ class TSConstructorGenerator( } if (isNetworkReactor) { - arguments.add("tpoLevel: number") + arguments.add("tpoLevel?: number") } return arguments.toString() From 6c3916d6aa79fe56b0a40c7a70b2f8df22a29f1f Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Wed, 2 Aug 2023 09:58:53 +0900 Subject: [PATCH 05/10] Restore failing TS tests for testing --- .../src/federated/{failing => }/LoopDistributedCentralized.lf | 0 .../src/federated/{failing => }/LoopDistributedDouble.lf | 0 .../TypeScript/src/federated/{failing => }/PingPongDistributed.lf | 0 .../src/federated/{failing => }/PingPongDistributedPhysical.lf | 0 test/TypeScript/src/federated/{failing => }/SimpleFederated.lf | 0 test/TypeScript/src/federated/{failing => }/SpuriousDependency.lf | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename test/TypeScript/src/federated/{failing => }/LoopDistributedCentralized.lf (100%) rename test/TypeScript/src/federated/{failing => }/LoopDistributedDouble.lf (100%) rename test/TypeScript/src/federated/{failing => }/PingPongDistributed.lf (100%) rename test/TypeScript/src/federated/{failing => }/PingPongDistributedPhysical.lf (100%) rename test/TypeScript/src/federated/{failing => }/SimpleFederated.lf (100%) rename test/TypeScript/src/federated/{failing => }/SpuriousDependency.lf (100%) diff --git a/test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/LoopDistributedCentralized.lf similarity index 100% rename from test/TypeScript/src/federated/failing/LoopDistributedCentralized.lf rename to test/TypeScript/src/federated/LoopDistributedCentralized.lf diff --git a/test/TypeScript/src/federated/failing/LoopDistributedDouble.lf b/test/TypeScript/src/federated/LoopDistributedDouble.lf similarity index 100% rename from test/TypeScript/src/federated/failing/LoopDistributedDouble.lf rename to test/TypeScript/src/federated/LoopDistributedDouble.lf diff --git a/test/TypeScript/src/federated/failing/PingPongDistributed.lf b/test/TypeScript/src/federated/PingPongDistributed.lf similarity index 100% rename from test/TypeScript/src/federated/failing/PingPongDistributed.lf rename to test/TypeScript/src/federated/PingPongDistributed.lf diff --git a/test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf b/test/TypeScript/src/federated/PingPongDistributedPhysical.lf similarity index 100% rename from test/TypeScript/src/federated/failing/PingPongDistributedPhysical.lf rename to test/TypeScript/src/federated/PingPongDistributedPhysical.lf diff --git a/test/TypeScript/src/federated/failing/SimpleFederated.lf b/test/TypeScript/src/federated/SimpleFederated.lf similarity index 100% rename from test/TypeScript/src/federated/failing/SimpleFederated.lf rename to test/TypeScript/src/federated/SimpleFederated.lf diff --git a/test/TypeScript/src/federated/failing/SpuriousDependency.lf b/test/TypeScript/src/federated/SpuriousDependency.lf similarity index 100% rename from test/TypeScript/src/federated/failing/SpuriousDependency.lf rename to test/TypeScript/src/federated/SpuriousDependency.lf From 71c4fe2a802b9d90f1933908cd70fd54635c8c22 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Fri, 4 Aug 2023 10:56:39 +0900 Subject: [PATCH 06/10] Apply spotless --- .../DistributedCountPhysicalAfterDelay.lf | 34 +++++------ .../federated/LoopDistributedCentralized.lf | 48 ++++++++-------- .../src/federated/LoopDistributedDouble.lf | 56 +++++++++---------- .../src/federated/PingPongDistributed.lf | 42 +++++++------- .../federated/PingPongDistributedPhysical.lf | 38 ++++++------- .../src/federated/SpuriousDependency.lf | 9 +-- 6 files changed, 110 insertions(+), 117 deletions(-) rename test/TypeScript/src/federated/{failing => }/DistributedCountPhysicalAfterDelay.lf (50%) diff --git a/test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf b/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf similarity index 50% rename from test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf rename to test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf index 0ea0befda7..c6ab1190de 100644 --- a/test/TypeScript/src/federated/failing/DistributedCountPhysicalAfterDelay.lf +++ b/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -19,30 +19,30 @@ reactor Print { state c: number = 1 reaction(inp) {= - const elapsedTime = util.getElapsedLogicalTime(); - console.log(`At time ${elapsedTime}, received ${inp}`); - if (inp !== c) { - util.requestErrorStop(`ERROR: Expected to receive ${c}.`); - } - if (!elapsedTime.isLaterThan(TimeValue.msec(600))) { - util.requestErrorStop(`ERROR: Expected received time to be strictly greater than ${TimeValue.msec(600)}`); - } - c++; - console.log(`c = ${c}`); - util.requestStop(); + const elapsedTime = util.getElapsedLogicalTime(); + console.log(`At time ${elapsedTime}, received ${inp}`); + if (inp !== c) { + util.requestErrorStop(`ERROR: Expected to receive ${c}.`); + } + if (!elapsedTime.isLaterThan(TimeValue.msec(600))) { + util.requestErrorStop(`ERROR: Expected received time to be strictly greater than ${TimeValue.msec(600)}`); + } + c++; + console.log(`c = ${c}`); + util.requestStop(); =} reaction(shutdown) {= - if (c !== 2) { - util.requestErrorStop(`ERROR: Expected to receive 1 item. Received ${c - 1}.`); - } else { - console.log("SUCCESS: Successfully received 1 item."); - } + if (c !== 2) { + util.requestErrorStop(`ERROR: Expected to receive 1 item. Received ${c - 1}.`); + } else { + console.log("SUCCESS: Successfully received 1 item."); + } =} } federated reactor at localhost { - c = new Count(offset = 200 msec, period = 0) + c = new Count(offset = 200 msec, period=0) p = new Print() c.out ~> p.inp after 400 msec // Indicating a 'physical' connection with a 400 msec after delay. } diff --git a/test/TypeScript/src/federated/LoopDistributedCentralized.lf b/test/TypeScript/src/federated/LoopDistributedCentralized.lf index aebc87d619..15dafae904 100644 --- a/test/TypeScript/src/federated/LoopDistributedCentralized.lf +++ b/test/TypeScript/src/federated/LoopDistributedCentralized.lf @@ -15,50 +15,50 @@ reactor Looper(incr: number = 1, delay: time = 0 msec) { state count: number = 0 preamble {= - let stop = false; - // Function to trigger an action once every second. - function ping(act: any) { - if (!stop) { - console.log("Scheduling action."); - act.schedule(0, null); - setTimeout(ping, 1000, act); + let stop = false; + // Function to trigger an action once every second. + function ping(act: any) { + if (!stop) { + console.log("Scheduling action."); + act.schedule(0, null); + setTimeout(ping, 1000, act); + } } - } =} reaction(startup) -> a {= - // Start the ping function for triggering an action every second. - console.log("Starting ping function."); - ping(actions.a); + // Start the ping function for triggering an action every second. + console.log("Starting ping function."); + ping(actions.a); =} reaction(a) -> out {= - out = count; - count += incr; + out = count; + count += incr; =} reaction(inp) {= - let logical = util.getCurrentLogicalTime(); - let physical = util.getCurrentPhysicalTime(); + let logical = util.getCurrentLogicalTime(); + let physical = util.getCurrentPhysicalTime(); - let time_lag = physical.subtract(logical); + let time_lag = physical.subtract(logical); - console.log("Received " + inp + ". Logical time is behind physical time by " + time_lag + "."); + console.log("Received " + inp + ". Logical time is behind physical time by " + time_lag + "."); =} reaction(shutdown) {= - console.log("******* Shutdown invoked."); - // Stop the ping function that is scheduling actions. - stop = true; - if (count != 5 * incr) { - util.requestErrorStop("Failed to receive all five expected inputs."); - } + console.log("******* Shutdown invoked."); + // Stop the ping function that is scheduling actions. + stop = true; + if (count != 5 * incr) { + util.requestErrorStop("Failed to receive all five expected inputs."); + } =} } federated reactor LoopDistributedCentralized(delay: time = 0) { left = new Looper() - right = new Looper(incr = -1) + right = new Looper(incr=-1) left.out -> right.inp right.out -> left.inp } diff --git a/test/TypeScript/src/federated/LoopDistributedDouble.lf b/test/TypeScript/src/federated/LoopDistributedDouble.lf index 081c070048..f6b5b39d50 100644 --- a/test/TypeScript/src/federated/LoopDistributedDouble.lf +++ b/test/TypeScript/src/federated/LoopDistributedDouble.lf @@ -8,7 +8,7 @@ target TypeScript { timeout: 5 sec, keepAlive: true, coordination-options: { - advance-message-interval: 100 msec + advance-message-interval: 100 msec } } @@ -22,57 +22,57 @@ reactor Looper(incr: number = 1, delay: time = 0 msec) { timer t(0, 1 sec) preamble {= - let stop = false; - // Function to trigger an action once every second. - function ping(act: any) { - if (!stop) { - console.log("Scheduling action."); - act.schedule(0, null); - setTimeout(ping, 1000, act); + let stop = false; + // Function to trigger an action once every second. + function ping(act: any) { + if (!stop) { + console.log("Scheduling action."); + act.schedule(0, null); + setTimeout(ping, 1000, act); + } } - } =} reaction(startup) -> a {= - // Start the ping function for triggering an action every second. - console.log("Starting ping function."); - ping(actions.a); + // Start the ping function for triggering an action every second. + console.log("Starting ping function."); + ping(actions.a); =} reaction(a) -> out, out2 {= - if (count % 2 == 0) { - out = count; - } else { - out2 = count; - } - count += incr; + if (count % 2 == 0) { + out = count; + } else { + out2 = count; + } + count += incr; =} reaction(inp) {= - console.log("Received " + inp + " on inp at logical time " + util.getElapsedLogicalTime() + "."); + console.log("Received " + inp + " on inp at logical time " + util.getElapsedLogicalTime() + "."); =} reaction(inp2) {= - console.log("Received " + inp2 + " on inp2 at logical time " + util.getElapsedLogicalTime() + "."); + console.log("Received " + inp2 + " on inp2 at logical time " + util.getElapsedLogicalTime() + "."); =} reaction(t) {= - console.log("Timer triggered at logical time " + util.getElapsedLogicalTime() + "."); + console.log("Timer triggered at logical time " + util.getElapsedLogicalTime() + "."); =} reaction(shutdown) {= - console.log("******* Shutdown invoked."); - // Stop the ping function that is scheduling actions. - stop = true; - if (count != 5 * incr) { - util.requestErrorStop("Failed to receive all five expected inputs."); - } + console.log("******* Shutdown invoked."); + // Stop the ping function that is scheduling actions. + stop = true; + if (count != 5 * incr) { + util.requestErrorStop("Failed to receive all five expected inputs."); + } =} } federated reactor(delay: time = 0) { left = new Looper() - right = new Looper(incr = -1) + right = new Looper(incr=-1) left.out -> right.inp right.out -> left.inp right.out2 -> left.inp2 diff --git a/test/TypeScript/src/federated/PingPongDistributed.lf b/test/TypeScript/src/federated/PingPongDistributed.lf index 42cceae73c..e189bd44e0 100644 --- a/test/TypeScript/src/federated/PingPongDistributed.lf +++ b/test/TypeScript/src/federated/PingPongDistributed.lf @@ -8,18 +8,18 @@ reactor Ping(count: number = 10) { logical action serve reaction(startup, serve) -> send {= - console.log(`At logical time ${util.getElapsedLogicalTime()}, Ping sending ${pingsLeft}`); - send = pingsLeft; - pingsLeft = pingsLeft - 1; + console.log(`At logical time ${util.getElapsedLogicalTime()}, Ping sending ${pingsLeft}`); + send = pingsLeft; + pingsLeft = pingsLeft - 1; =} reaction(receive) -> serve {= - if (pingsLeft > 0){ - actions.serve.schedule(0, null); - } - else{ - util.requestStop(); - } + if (pingsLeft > 0){ + actions.serve.schedule(0, null); + } + else{ + util.requestStop(); + } =} } @@ -29,25 +29,25 @@ reactor Pong(expected: number = 10) { state count: number = 0 reaction(receive) -> send {= - count += 1; - console.log(`At logical time ${util.getElapsedLogicalTime()}, Pong received ${receive}`) - send = receive; - if (count == expected){ - util.requestStop(); - } + count += 1; + console.log(`At logical time ${util.getElapsedLogicalTime()}, Pong received ${receive}`) + send = receive; + if (count == expected){ + util.requestStop(); + } =} reaction(shutdown) {= - if (count != expected){ - util.requestErrorStop(`Pong expected to receive ${expected} inputs, but it received ${count}`); - } - console.log(`Pong received ${count} pings.`); + if (count != expected){ + util.requestErrorStop(`Pong expected to receive ${expected} inputs, but it received ${count}`); + } + console.log(`Pong received ${count} pings.`); =} } federated reactor PingPongDistributed(count: number = 10) { - ping = new Ping(count = count) - pong = new Pong(expected = count) + ping = new Ping(count=count) + pong = new Pong(expected=count) ping.send -> pong.receive pong.send -> ping.receive } diff --git a/test/TypeScript/src/federated/PingPongDistributedPhysical.lf b/test/TypeScript/src/federated/PingPongDistributedPhysical.lf index 298a7298d4..ef773e2446 100644 --- a/test/TypeScript/src/federated/PingPongDistributedPhysical.lf +++ b/test/TypeScript/src/federated/PingPongDistributedPhysical.lf @@ -32,16 +32,16 @@ reactor Ping(count: number = 10) { logical action serve reaction(startup, serve) -> send {= - console.log(`At logical time ${util.getElapsedLogicalTime()}, Ping sending ${pingsLeft}.`); - send = pingsLeft--; + console.log(`At logical time ${util.getElapsedLogicalTime()}, Ping sending ${pingsLeft}.`); + send = pingsLeft--; =} reaction(receive) -> serve {= - if (pingsLeft > 0) { - actions.serve.schedule(0, null); - } else { - util.requestStop(); - } + if (pingsLeft > 0) { + actions.serve.schedule(0, null); + } else { + util.requestStop(); + } =} } @@ -51,25 +51,25 @@ reactor Pong(expected: number = 10) { state count: number = 0 reaction(receive) -> send {= - count++; - console.log(`At logical time ${util.getElapsedLogicalTime()}, Pong receivedd ${receive}.`); - send = receive; - if (count === expected) { - util.requestStop(); - } + count++; + console.log(`At logical time ${util.getElapsedLogicalTime()}, Pong receivedd ${receive}.`); + send = receive; + if (count === expected) { + util.requestStop(); + } =} reaction(shutdown) {= - if (count !== expected) { - util.requestErrorStop(`Pong expected to received ${expected} inputs, but it received ${count}.`); - } - console.log(`Pong received ${count} pings.`); + if (count !== expected) { + util.requestErrorStop(`Pong expected to received ${expected} inputs, but it received ${count}.`); + } + console.log(`Pong received ${count} pings.`); =} } federated reactor(count: number = 10) { - ping = new Ping(count = count) - pong = new Pong(expected = count) + ping = new Ping(count=count) + pong = new Pong(expected=count) ping.send ~> pong.receive pong.send ~> ping.receive } diff --git a/test/TypeScript/src/federated/SpuriousDependency.lf b/test/TypeScript/src/federated/SpuriousDependency.lf index dc16319a70..39da8f0ea5 100644 --- a/test/TypeScript/src/federated/SpuriousDependency.lf +++ b/test/TypeScript/src/federated/SpuriousDependency.lf @@ -1,8 +1,7 @@ /** * This checks that a federated program does not deadlock when it is ambiguous, given the structure * of a federate, whether it is permissible to require certain network sender/receiver reactions to - * precede others inp the execution of a given tag. The version of LFC that was inp the master branch - * on 4/15/2023 resolved the ambiguity inp a way that does appear to result inp deadlock. + * precede others in the execution of a given tag. */ target TypeScript { timeout: 1 sec @@ -13,9 +12,7 @@ reactor Passthrough(id: number = 0) { output out: number reaction(inp) -> out {= - //lf_print("Hello from passthrough %d", self->id); console.log("Hello from passthrough " + id); - //lf_set(out, inp->value); out = inp; =} } @@ -41,11 +38,7 @@ reactor Check { reaction(inp) {= console.log("count is now " + ++count); =} reaction(shutdown) {= - // lf_print("******* Shutdown invoked."); console.log("******* Shutdown invoked."); - // if (self->count != 1) { - // lf_print_error_and_exit("Failed to receive expected input."); - // } if (count != 1) { util.reportError("Failed to receieve expected input."); } From 021166557349e38776a91bcfc53a57d7d961b361 Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Fri, 4 Aug 2023 11:19:24 +0900 Subject: [PATCH 07/10] Increment the port ID to match messages properly --- .../kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt | 2 +- .../src/federated/DistributedCountPhysicalAfterDelay.lf | 5 +---- test/TypeScript/src/federated/LoopDistributedDouble.lf | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt b/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt index 2911503159..3e01cdccbd 100644 --- a/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/ts/TSInstanceGenerator.kt @@ -78,7 +78,7 @@ class TSInstanceGenerator( // Assume that network receiver reactors are sorted by portID childReactorInstantiations.add( "this.registerNetworkReceiver(\n" - + "\t${portID},\n" + + "\t${portID++},\n" + "\tthis.${childReactor.name} as __NetworkReceiver\n)") } if (isNetworkSender) { diff --git a/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf b/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf index c6ab1190de..107cd847cb 100644 --- a/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf +++ b/test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf @@ -7,10 +7,7 @@ * @author Soroush Bateni * @author Byeong-gil Jun */ -target TypeScript { - logging: debug, - keepalive: true -} +target TypeScript import Count from "../lib/Count.lf" diff --git a/test/TypeScript/src/federated/LoopDistributedDouble.lf b/test/TypeScript/src/federated/LoopDistributedDouble.lf index f6b5b39d50..0facc3c6dc 100644 --- a/test/TypeScript/src/federated/LoopDistributedDouble.lf +++ b/test/TypeScript/src/federated/LoopDistributedDouble.lf @@ -6,7 +6,6 @@ */ target TypeScript { timeout: 5 sec, - keepAlive: true, coordination-options: { advance-message-interval: 100 msec } From 3891436dbe002ed49fdb3efa4bfee063bbee256f Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun <78055940+byeong-gil@users.noreply.github.com> Date: Wed, 16 Aug 2023 10:58:00 +0900 Subject: [PATCH 08/10] Update package.json --- core/src/main/resources/lib/ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/ts/package.json b/core/src/main/resources/lib/ts/package.json index 4797fd56ed..fc063d791e 100644 --- a/core/src/main/resources/lib/ts/package.json +++ b/core/src/main/resources/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#ts-cyclic-dependencies", + "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From 432ac5e19ebb27d1d98e86b9ddda1604d4f1241b Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Tue, 22 Aug 2023 15:13:13 -0700 Subject: [PATCH 09/10] Apply suggestions from code review --- core/src/main/resources/lib/ts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/ts/package.json b/core/src/main/resources/lib/ts/package.json index fc063d791e..04978d7322 100644 --- a/core/src/main/resources/lib/ts/package.json +++ b/core/src/main/resources/lib/ts/package.json @@ -2,7 +2,7 @@ "name": "LinguaFrancaDefault", "type": "commonjs", "dependencies": { - "@lf-lang/reactor-ts": "git://github.com/lf-lang/reactor-ts.git#master", + "@lf-lang/reactor-ts": "^0.6.0", "command-line-args": "^5.1.1", "command-line-usage": "^6.1.3" }, From b33ce99267ba4c845789b5a0691708a3253d29ab Mon Sep 17 00:00:00 2001 From: Byeong-gil Jun Date: Thu, 24 Aug 2023 19:47:06 +0900 Subject: [PATCH 10/10] Index 0 should be used to check the output's status --- .../java/org/lflang/federated/extensions/TSExtension.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/extensions/TSExtension.java b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java index f0000b7435..9ef81c6a23 100644 --- a/core/src/main/java/org/lflang/federated/extensions/TSExtension.java +++ b/core/src/main/java/org/lflang/federated/extensions/TSExtension.java @@ -109,8 +109,8 @@ public String generateNetworkSenderBody( CoordinationType coordinationType, MessageReporter messageReporter) { return """ - if (%1$s%2$s[sender_index as number] !== undefined) { - this.util.sendRTITimedMessage(%1$s%2$s[sender_index as number], %3$s, %4$s, %5$s); + if (%1$s%2$s[0] !== undefined) { + this.util.sendRTITimedMessage(%1$s%2$s[0], %3$s, %4$s, %5$s); } """ .formatted( @@ -136,7 +136,7 @@ public String generatePortAbsentReactionBody( return """ // If the output port has not been set for the current logical time, // send an ABSENT message to the receiving federate - if (%1$s%2$s === undefined) { + if (%1$s%2$s[0] === undefined) { this.util.sendRTIPortAbsent(%3$d, %4$d, %5$s); } """