Skip to content

Commit

Permalink
Optimize by not including bindings for case _ => [[ P ]]
Browse files Browse the repository at this point in the history
  • Loading branch information
KentShikama committed Jul 5, 2017
1 parent 897b2ca commit 7be2062
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/main/scala/rholang/rosette/Roselang.scala
Original file line number Diff line number Diff line change
Expand Up @@ -735,20 +735,24 @@ extends StrFoldCtxtVisitor {
Location(continuation: StrTermCtxt, _) <- visitDispatch(pm.proc_, Here());
Location(remainder: StrTermCtxt, _) <- acc
) yield {

def createProcForPatternBindings = {
val procTerm = B(_abs)(B(_list)(pattern), continuation)
B("")(procTerm, pTerm) // TODO: Potentially allow StrTermPtdCtxtBr without Namespace ?
}

val matchTerm = B(_match)(pTerm, pattern)
val matchTrueTerm = if (hasVariable(pm.ppattern_)) {
createProcForPatternBindings
} else {
if (isWild(pm.ppattern_)) {
// Assumes VarPtWild comes at the end of a list of case statements
continuation
} else {
def createProcForPatternBindings = {
val procTerm = B(_abs)(B(_list)(pattern), continuation)
B("")(procTerm, pTerm) // TODO: Potentially allow StrTermPtdCtxtBr without Namespace ?
}

val matchTerm = B(_match)(pTerm, pattern)
val matchTrueTerm = if (hasVariable(pm.ppattern_)) {
createProcForPatternBindings
} else {
continuation
}
val ifTerm = B(_if)(matchTerm, matchTrueTerm, remainder)
L(ifTerm, Top())
}
val ifTerm = B(_if)(matchTerm, matchTrueTerm, remainder)
L(ifTerm, Top())
}
}
case _ => throw new UnexpectedPMBranchType(e)
Expand All @@ -768,6 +772,18 @@ extends StrFoldCtxtVisitor {
)
}

def isWild(p: PPattern): Boolean = {
p match {
case pPtVar: PPtVar => {
pPtVar.varpattern_ match {
case wild : VarPtWild => true
case _ => false
}
}
case _ => false
}
}

def hasVariable(p: PPattern): Boolean = {
// TODO: Fill in rest of cases
p match {
Expand Down

0 comments on commit 7be2062

Please sign in to comment.