Skip to content
Snippets Groups Projects
Commit 0219962e authored by Régis Blanc's avatar Régis Blanc
Browse files

was setting type to already typed expression

parent fad34eb2
No related branches found
No related tags found
No related merge requests found
......@@ -15,9 +15,11 @@ object ImperativeCodeElimination extends Pass {
def apply(pgm: Program): Program = {
val allFuns = pgm.definedFunctions
allFuns.foreach(fd => fd.body.map(body => {
Logger.debug("Transforming to functional code the following function:\n" + fd, 5, "imperative")
parent = fd
val (res, scope, _) = toFunction(body)
fd.body = Some(scope(res))
Logger.debug("Resulting functional code is:\n" + fd, 5, "imperative")
}))
pgm
}
......@@ -58,14 +60,12 @@ object ImperativeCodeElimination extends Pass {
val thenVal = if(modifiedVars.isEmpty) tRes else Tuple(tRes +: modifiedVars.map(vId => tFun.get(vId) match {
case Some(newId) => newId.toVariable
case None => vId.toVariable
}))
thenVal.setType(iteType)
})).setType(iteType)
val elseVal = if(modifiedVars.isEmpty) eRes else Tuple(eRes +: modifiedVars.map(vId => eFun.get(vId) match {
case Some(newId) => newId.toVariable
case None => vId.toVariable
}))
elseVal.setType(iteType)
})).setType(iteType)
val iteExpr = IfExpr(cRes, replaceNames(cFun, tScope(thenVal)), replaceNames(cFun, eScope(elseVal))).setType(iteType)
......@@ -97,14 +97,14 @@ object ImperativeCodeElimination extends Pass {
val matchType = if(modifiedVars.isEmpty) resId.getType else TupleType(resId.getType +: freshIds.map(_.getType))
val csesVals = csesRes.zip(csesFun).map{
case (cRes, cFun) => (if(modifiedVars.isEmpty) cRes else Tuple(cRes +: modifiedVars.map(vId => cFun.get(vId) match {
case (cRes, cFun) => if(modifiedVars.isEmpty) cRes else Tuple(cRes +: modifiedVars.map(vId => cFun.get(vId) match {
case Some(newId) => newId.toVariable
case None => vId.toVariable
}))).setType(matchType)
})).setType(matchType)
}
val newRhs = csesVals.zip(csesScope).map{
case (cVal, cScope) => replaceNames(scrutFun, cScope(cVal)).setType(matchType)
case (cVal, cScope) => replaceNames(scrutFun, cScope(cVal))
}
val matchExpr = MatchExpr(scrutRes, cses.zip(newRhs).map{
case (SimpleCase(pat, _), newRhs) => SimpleCase(pat, newRhs)
......
......@@ -31,7 +31,7 @@ object Main {
}
private def defaultAction(program: Program, reporter: Reporter) : Unit = {
Logger.debug("Default action on program: " + program, 5, "main")
Logger.debug("Default action on program: " + program, 3, "main")
val passManager = new PassManager(Seq(EpsilonElimination, ImperativeCodeElimination, UnitElimination, FunctionClosure, FunctionHoisting, Simplificator))
val program2 = passManager.run(program)
val analysis = new Analysis(program2, reporter)
......
......@@ -8,7 +8,7 @@ class PassManager(passes: Seq[Pass]) {
passes.foldLeft(program)((pgm, pass) => {
Logger.debug("Running Pass: " + pass.description, 1, "passman")
val newPgm = pass(pgm)
Logger.debug("Resulting program: " + newPgm, 5, "passman")
Logger.debug("Resulting program: " + newPgm, 3, "passman")
newPgm
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment