From: Axel S. <A....@ke...> - 2007-11-08 13:58:59
|
Wed Nov 7 16:04:51 PST 2007 Peter Gavin <pg...@gm...> * c2hs: added definitions for succ, pred, enumFrom{,To,ThenTo}; also add support for bitwise and, or, xor, and complement hunk ./tools/c2hs/gen/GenBind.hs 120 +import Data.Bits ((.&.), (.|.), xor, complement) + hunk ./tools/c2hs/gen/GenBind.hs 579 - if enumAuto then "\n" else "\n" ++ enumInst hident enumVals + if enumAuto then "\n" else "\n" ++ enumInst hident enumVals (elem "Eq" userDerive) hunk ./tools/c2hs/gen/GenBind.hs 627 -enumInst :: String -> [(String, Maybe CExpr)] -> String -enumInst ident list = +enumInst :: String -> [(String, Maybe CExpr)] -> Bool -> String +enumInst ident list haveEq = hunk ./tools/c2hs/gen/GenBind.hs 630 - ++ fromDef list 0 ++ "\n" ++ toDef list 0 + ++ fromDef list 0 ++ "\n" ++ toDef list 0 ++ "\n" + ++ succDef names ++ "\n" ++ predDef names ++ "\n" + ++ enumFromToDef names hunk ./tools/c2hs/gen/GenBind.hs 634 + names = map fst list hunk ./tools/c2hs/gen/GenBind.hs 662 + succDef [] = " succ _ = undefined\n" + succDef [x] = " succ _ = undefined\n" + succDef (x:x':xs) = + " succ " ++ x ++ " = " ++ x' ++ "\n" + ++ succDef (x':xs) + predDef [] = " pred _ = undefined\n" + predDef [x] = " pred _ = undefined\n" + predDef (x:x':xs) = + " pred " ++ x' ++ " = " ++ x ++ "\n" + ++ predDef (x':xs) + enumFromToDef [] = "" + enumFromToDef names = + if haveEq + then " enumFromTo x y | x == y = [ y ]\n" + ++ " | otherwise = x : enumFromTo (succ x) y\n" + ++ " enumFrom x = enumFromTo x " ++ last names ++ "\n" + ++ " enumFromThenTo _ _ _ = undefined\n" + else "" + hunk ./tools/c2hs/gen/GenBind.hs 1892 +applyBin cpos CAndOp (IntResult x) + (IntResult y) = return $ IntResult (x .&. y) +applyBin cpos COrOp (IntResult x) + (IntResult y) = return $ IntResult (x .|. y) +applyBin cpos CXorOp (IntResult x) + (IntResult y) = return $ IntResult (x `xor` y) hunk ./tools/c2hs/gen/GenBind.hs 1923 -applyUnary cpos CCompOp _ = [_$_] - todo "GenBind.applyUnary: ~ not yet implemented." +applyUnary cpos CCompOp (IntResult x) = return (IntResult (complement x)) |