Commit 17bf0a57 authored by rl@cse.unsw.edu.au's avatar rl@cse.unsw.edu.au
Browse files

Refactoring

parent facf3d6c
......@@ -231,17 +231,23 @@ data Repr = ProdRepr {
, void_bottom :: CoreExpr
}
mkVoid :: VM Repr
mkVoid = do
tycon <- builtin voidTyCon
var <- builtin voidVar
return $ VoidRepr {
void_tycon = tycon
, void_bottom = Var var
}
mkProduct :: [Type] -> VM Repr
mkProduct tys
voidRepr :: VM Repr
voidRepr
= do
tycon <- builtin voidTyCon
var <- builtin voidVar
return $ VoidRepr {
void_tycon = tycon
, void_bottom = Var var
}
unboxedProductRepr :: [Type] -> VM Repr
unboxedProductRepr [] = voidRepr
unboxedProductRepr [ty] = return $ IdRepr ty
unboxedProductRepr tys = boxedProductRepr tys
boxedProductRepr :: [Type] -> VM Repr
boxedProductRepr tys
= do
tycon <- builtin (prodTyCon arity)
let [data_con] = tyConDataCons tycon
......@@ -259,14 +265,10 @@ mkProduct tys
where
arity = length tys
mkSubProduct :: [Type] -> VM Repr
mkSubProduct [] = mkVoid
mkSubProduct [ty] = return $ IdRepr ty
mkSubProduct tys = mkProduct tys
mkSum :: [Repr] -> VM Repr
mkSum [repr] = return repr
mkSum reprs
sumRepr :: [Repr] -> VM Repr
sumRepr [] = voidRepr
sumRepr [repr] = boxRepr repr
sumRepr reprs
= do
tycon <- builtin (sumTyCon arity)
(arr_tycon, _) <- parrayReprTyCon
......@@ -284,6 +286,11 @@ mkSum reprs
where
arity = length reprs
boxRepr :: Repr -> VM Repr
boxRepr (VoidRepr {}) = boxedProductRepr []
boxRepr (IdRepr ty) = boxedProductRepr [ty]
boxRepr repr = return repr
reprType :: Repr -> Type
reprType (ProdRepr { prod_tycon = tycon, prod_components = tys })
= mkTyConApp tycon tys
......@@ -347,8 +354,7 @@ arrReprVars repr
mkRepr :: TyCon -> VM Repr
mkRepr vect_tc
| [tys] <- rep_tys = mkProduct tys
| otherwise = mkSum =<< mapM mkSubProduct rep_tys
= sumRepr =<< mapM unboxedProductRepr rep_tys
where
rep_tys = map dataConRepArgTys $ tyConDataCons vect_tc
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment