module Vectorise.Vect
( Vect, VVar, VExpr, VBind
, vectorised
, lifted
, mapVect
, vVarType
, vNonRec
, vRec
, vVar
, vType
, vTick
, vLet
, vLams
, vVarApps
, vCaseDEFAULT
)
where
import CoreSyn
import Type ( Type )
import Var
type Vect a = (a,a)
type VVar = Vect Var
type VExpr = Vect CoreExpr
type VBind = Vect CoreBind
vectorised :: Vect a -> a
vectorised = fst
lifted :: Vect a -> a
lifted = snd
mapVect :: (a -> b) -> Vect a -> Vect b
mapVect f (x, y) = (f x, f y)
zipWithVect :: (a -> b -> c) -> Vect a -> Vect b -> Vect c
zipWithVect f (x1, y1) (x2, y2) = (f x1 x2, f y1 y2)
vVarType :: VVar -> Type
vVarType = varType . vectorised
vVar :: VVar -> VExpr
vVar = mapVect Var
vType :: Type -> VExpr
vType ty = (Type ty, Type ty)
vTick :: Tickish Id -> VExpr -> VExpr
vTick = mapVect . Tick
vNonRec :: VVar -> VExpr -> VBind
vNonRec = zipWithVect NonRec
vRec :: [VVar] -> [VExpr] -> VBind
vRec vs es = (Rec (zip vvs ves), Rec (zip lvs les))
where
(vvs, lvs) = unzip vs
(ves, les) = unzip es
vLet :: VBind -> VExpr -> VExpr
vLet = zipWithVect Let
vLams :: Var
-> [VVar]
-> VExpr
-> VExpr
vLams lc vs (ve, le)
= (mkLams vvs ve, mkLams (lc:lvs) le)
where
(vvs, lvs) = unzip vs
vVarApps :: Var -> VExpr -> [VVar] -> VExpr
vVarApps lc (ve, le) vvs
= (ve `mkVarApps` vs, le `mkVarApps` (lc : ls))
where
(vs, ls) = unzip vvs
vCaseDEFAULT :: VExpr
-> VVar
-> Type
-> Type
-> VExpr
-> VExpr
vCaseDEFAULT (vscrut, lscrut) (vbndr, lbndr) vty lty (vbody, lbody)
= (Case vscrut vbndr vty (mkDEFAULT vbody),
Case lscrut lbndr lty (mkDEFAULT lbody))
where
mkDEFAULT e = [(DEFAULT, [], e)]