-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #942 from lf-lang/ts-multiport
Adds bank & multiport support in TypeScript code generator with > 30 multiport tests implemented.
- Loading branch information
Showing
59 changed files
with
2,005 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
* @author Marten Lohstroh | ||
*/ | ||
target C { | ||
threads: 1, | ||
keepalive: true | ||
}; | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule reactor-ts
updated
58 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.lflang.generator.ts | ||
|
||
import org.lflang.isBank | ||
import org.lflang.isMultiport | ||
import org.lflang.lf.Parameter | ||
import org.lflang.lf.Port | ||
import org.lflang.lf.Type | ||
import org.lflang.lf.WidthSpec | ||
import org.lflang.toText | ||
|
||
/** | ||
* The following definition provide extension that are useful for TypeScript target. | ||
* | ||
* @author {Hokeun Kim <[email protected]>} | ||
*/ | ||
fun WidthSpec.toTSCode(): String = terms.joinToString(" + ") { | ||
when { | ||
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()" | ||
else "this.${container.name}.all().length" | ||
} else { | ||
if ((variable as Port).isMultiport) "this.${container.name}.${variable.name}.width()" | ||
else "1" | ||
} | ||
} | ||
it.code != null -> it.code.toText() | ||
else -> it.width.toString() | ||
} | ||
} | ||
|
||
private fun Type.getTargetType(): String = TSTypes.getTargetType(this) | ||
|
||
/** | ||
* Return a TS type for the specified port. | ||
* If the type has not been specified, return | ||
* "Present" which is the base type for ports. | ||
* @param port The port | ||
* @return The TS type. | ||
*/ | ||
fun getPortType(port: Port): String { | ||
if (port.type != null) { | ||
return port.type.getTargetType() | ||
} else { | ||
return "Present" | ||
} | ||
} | ||
|
||
fun Parameter.getTargetType(): String = TSTypes.getTargetType(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.