yhccore-0.9: Yhc's Internal Core language.



In: x -> y x

x is bound

y is free



data FreeVar a Source


collectAllVars :: CoreExpr -> [CoreVarName]Source

Which variables are mentioned in an expression

collectBoundVars :: CoreExpr -> [CoreVarName]Source

Which variables are introduced at any point, i.e. LHS of a case alternative, or by a let

collectFreeVars :: CoreExpr -> [CoreVarName]Source

Which variables are in the used in an expression before being defined. No variable will occur more than once

countFreeVar :: CoreVarName -> CoreExpr -> IntSource

Count the number of uses of a free variable. If a variable is used in different branches of a case, it is only considered to be the maximum of these two branches.

replaceFreeVars :: [(CoreVarName, CoreExpr)] -> CoreExpr -> CoreExprSource

Replace all free occurances of variables with a new expression

uniqueBoundVarsCore :: Core -> FreeVar CoreSource

Make a whole Core program have unique free variables.

uniqueBoundVarsFunc :: CoreFunc -> FreeVar CoreFuncSource

Make a whole function have unique free variables

uniqueBoundVars :: CoreExpr -> FreeVar CoreExprSource

Replace all variables which are locally defined with new names from the given list. Raises an error if not enough free variables are supplied

If any in the new list clashes with a name in collectFreeVars this will return a program with different semantics!

Property: collectFreeVars (uniqueFreeVarsWith newvars x) subset newvars