forked from NetLogo/Tortoise
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge back upstream changes. No substantial conflicts.
- Loading branch information
Showing
22 changed files
with
789 additions
and
251 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
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
35 changes: 35 additions & 0 deletions
35
compiler/shared/src/main/scala/MultiAssignTransformer.scala
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,35 @@ | ||
// (C) Uri Wilensky. https://github.com/NetLogo/Tortoise | ||
|
||
package org.nlogo.tortoise.compiler | ||
|
||
import org.nlogo.core.{ AstTransformer, ProcedureDefinition, ReporterApp, Statement, Statements } | ||
import org.nlogo.core.prim.{ _let, _multiletitem } | ||
|
||
object MultiAssignTransformer { | ||
// NetLogo desktop creates synthetic let statements for _multilet that get their values from an intermediate construct | ||
// that holds the list of values to be assigned. This is necessary there because they can't translate it to a real | ||
// destructured assignment. In JavaScript we can use a destructured assignment language construct, so we have no need | ||
// of the synthetic extras. So we sot them. -Jeremy B November 2023 | ||
object MultiLetRemover extends AstTransformer { | ||
private def dropMultiLetStmts(stmts: Seq[Statement]): Seq[Statement] = { | ||
val results = stmts.filter( (s) => { | ||
!(s.command.isInstanceOf[_let] && | ||
s.args.length == 1 && | ||
s.args(0).isInstanceOf[ReporterApp] && | ||
s.args(0).asInstanceOf[ReporterApp].reporter.isInstanceOf[_multiletitem]) | ||
}) | ||
results | ||
} | ||
|
||
override def visitStatements(statements: Statements): Statements = { | ||
val newStmts = dropMultiLetStmts(statements.stmts).map(super.visitStatement) | ||
statements.copy(stmts = newStmts) | ||
} | ||
|
||
} | ||
|
||
def apply(pd: ProcedureDefinition): ProcedureDefinition = | ||
( | ||
MultiLetRemover.visitProcedureDefinition | ||
)(pd) | ||
} |
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.