definition:
|
rnExpr :: [(VarIndex, VarIndex)] -> Renaming (AExpr a)
rnExpr ren xs (AVar a x) = case lookup x ren of
Nothing -> (xs, AVar a x)
Just w -> (xs, AVar a w)
rnExpr _ xs l@(ALit _ _) = (xs, l)
rnExpr ren xs (AComb a ct qn es) = let (xs1, es') = mapAccumL (rnExpr ren) xs es
in (xs1, AComb a ct qn es')
rnExpr ren xs (AFree a vs e)
= let (xs1, vs') = takeVars xs vs
vsNoAnn = map fst vs
ren1 = zip vsNoAnn vs' ++ filter ((`notElem` vsNoAnn) . fst) ren
(xs2, e') = rnExpr ren1 xs1 e
in (xs2, AFree a (swapAnn vs' vs) e')
rnExpr ren xs (ALet a ds e)
= let (vs, es) = unzip ds
(xs1, vs') = takeVars xs ds
vsNoAnn = map fst vs
ren1 = zip vsNoAnn vs' ++ filter ((`notElem` vsNoAnn) . fst) ren
(xs2, es') = mapAccumL (rnExpr ren1) xs1 es
(xs3, e') = rnExpr ren1 xs2 e
in (xs3, ALet a (zip (swapAnn vs' vs) es') e')
rnExpr ren xs (AOr a e1 e2) = let (xs1, e1') = rnExpr ren xs e1
(xs2, e2') = rnExpr ren xs1 e2
in (xs2, AOr a e1' e2')
rnExpr ren xs (ACase a ct e bs)
= let (xs1, e') = rnExpr ren xs e
(xs2, bs') = mapAccumL (rnBranchExpr ren) xs1 bs
in (xs2, ACase a ct e' bs')
rnExpr ren xs (ATyped a e ty) = let (xs1, e') = rnExpr ren xs e
in (xs1, ATyped a e' ty)
|
iotype:
|
{(_,_,{AVar}) |-> {(,)} || (_,_,{ALit}) |-> {(,)} || (_,_,{AComb}) |-> {(,)} || (_,_,{AFree}) |-> {(,)} || (_,_,{ALet}) |-> {(,)} || (_,_,{AOr}) |-> {(,)} || (_,_,{ACase}) |-> {(,)} || (_,_,{ATyped}) |-> {(,)}}
|