Symbol Crunching

main
dbalakri 2023-12-06 01:16:09 -05:00
parent d44516a90e
commit 643571fe8a
1 changed files with 23 additions and 5 deletions

View File

@ -40,7 +40,7 @@ object BDD
++ (schema.globals:Map[String, Type|(Code,Type)])
)
def recur(rule: bdd.BDD, pathNames: Map[bdd.Pathed.Path, (Code, Type)], boundVars: Map[String, Type]): Code =
def recur(rule: bdd.BDD, pathNames: Map[bdd.Pathed.Path, (Code, Type)], boundVars: Map[String, Type], symCount: Int): Code =
rule match {
case bdd.NoRewrite => onFail
case bdd.PickByType(path, types, elseBranch) =>
@ -53,7 +53,21 @@ object BDD
Code.IfElifElse(
types.map { case (targetType, andThen) =>
{
val nodeName = "root"+path.map { "_child"+_ }.mkString+"_as_"+targetType.scalaType
// val newSymCount = symCount
// val nodeName = "root"+path.map { "_child"+_ }.mkString+"_as_"+targetType.scalaType
val nodeNameString = "root"+path.map { "_child"+_ }.mkString+"_as_"+targetType.scalaType
// println("Type nodeNameString: "+nodeNameString)
val nameCount = if (nodeNameString.length() >= 30){
("Sym_"+symCount, symCount + 1)
} else {
(nodeNameString, symCount)
}
val nodeName = nameCount._1
val newSymCount = nameCount._2
// println("Type nodeName being used: "+nodeName)
val newPathNames: Map[bdd.Pathed.Path, (Code, Type)] =
targetType match {
case Type.Node(node) =>
@ -85,12 +99,12 @@ object BDD
)++recur(
andThen,
pathNames ++ newPathNames ++ Map(path -> (Code.Literal(nodeName), targetType)),
boundVars,
boundVars, newSymCount
).block
)
}
}.toSeq,
recur(elseBranch, pathNames, boundVars)
recur(elseBranch, pathNames, boundVars, symCount)
)
case bdd.PickByMatch(path, pattern, bindings, onMatch, onFail) =>
val target = pathNames.get(path)
@ -110,12 +124,14 @@ object BDD
onMatch,
pathNames,
boundVars,
symCount,
),
onFail =
_ => recur(
onFail,
pathNames,
boundVars,
symCount,
),
name = None,
scope = scope
@ -144,7 +160,8 @@ object BDD
)++recur(
andThen,
pathNames,
boundVars ++ Map(symbol -> exprType)
boundVars ++ Map(symbol -> exprType),
symCount
).block
)
}
@ -155,6 +172,7 @@ object BDD
Seq.empty -> (root, family)
),
Map.empty,
1
)
}
}