From dcb91099ae902fbb4a31ff1f3324e2f7da905321 Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Sat, 24 Nov 2012 01:30:11 +0000 Subject: [PATCH] Fix resampling of operators in generateVariants. --- OFC/SecondLevel.hs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/OFC/SecondLevel.hs b/OFC/SecondLevel.hs index e3178ec..0fc69e5 100644 --- a/OFC/SecondLevel.hs +++ b/OFC/SecondLevel.hs @@ -289,7 +289,7 @@ getIdentType ofl2 name = case Map.lookup name (symbols ofl2) of Just (ValueTag baseType _) -> baseType _ -> error $ "Could not find type of symbol " ++ name -generateVariants :: OFL2 -> Expression e -> [Expression e] +generateVariants :: (Resamplable e, e ~ Expression a1) => OFL2 -> e -> [e] generateVariants ofl2 expr = case expr of IndexedPsincIdentifier _ _ -> resampled ofl2 expr IndexedScalarIdentifier _ _ -> resampled ofl2 expr @@ -314,19 +314,23 @@ generateVariants ofl2 expr = case expr of ConstReal _ -> resampled ofl2 expr ConstComplex _ -> resampled ofl2 expr where - unaryOp :: (Expression a -> Expression c) -> Expression a -> [Expression c] + unaryOp :: (Resamplable a, Resamplable r, a ~ Expression a1, r ~ Expression a2) + => (a -> r) -> a -> [r] unaryOp constructor e = do variant <- generateVariants ofl2 e - returnValid $ constructor variant - binaryOp :: (Expression a -> Expression b -> Expression r) -> Expression a -> Expression b -> [Expression r] + validResampling <- validResamplings $ constructor variant + return validResampling + binaryOp :: (Resamplable a, Resamplable b, Resamplable r, a ~ Expression a1, b ~ Expression a2, r ~ Expression a3) + => (a -> b -> r) -> a -> b -> [r] binaryOp constructor e1 e2 = do variant1 <- generateVariants ofl2 e1 variant2 <- generateVariants ofl2 e2 - returnValid $ constructor variant1 variant2 - returnValid :: Expression e -> [Expression e] - returnValid e = case getImplementationType ofl2 e of + validResampling <- validResamplings $ constructor variant1 variant2 + return validResampling + validResamplings :: (Resamplable e, e ~ Expression a1) => e -> [e] + validResamplings e = case getImplementationType ofl2 e of Left _ -> [] - Right _ -> [e] + Right _ -> resampled ofl2 e data Assignment = AssignPsinc (Expression PsincE) (Expression PsincE) | @@ -354,8 +358,8 @@ instance PrettyPrintable OFL2 where assignmentsDoc = text "Assignments: " $$ nest 1 (vcat $ map toDoc $ assignments ofl2) $$ text "Variants:" $$ nest 2 (vcat $ map variantsDoc $ assignments ofl2) - variantsDoc (AssignPsinc a b) = vcat $ map toDoc $ generateVariants ofl2 b - variantsDoc (AssignScalar a b) = vcat $ map toDoc $ generateVariants ofl2 b + variantsDoc (AssignPsinc _ b) = vcat $ map toDoc $ generateVariants ofl2 b + variantsDoc (AssignScalar _ b) = vcat $ map toDoc $ generateVariants ofl2 b symAssocToDoc (name, ValueTag baseType indexTypes) = text $ (show baseType) ++ " " ++ name ++ case indexTypes of [] -> "" -- 2.47.3