summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2006-11-13 09:05:17 +0000
committersimonpj@microsoft.com <unknown>2006-11-13 09:05:17 +0000
commit3738ecf8fc636d714baa172ae71fa680e3b14fd8 (patch)
tree8991921cf0bce0dc24c003cc7c51732063f51397 /compiler
parentfed8458637fecad51631507a5eabcc4af374de24 (diff)
downloadhaskell-3738ecf8fc636d714baa172ae71fa680e3b14fd8.tar.gz
Fixups to PelRules (esp using intResult, wordResult)
In PrelRules we carefully use 'intResult' to trim off the overflow in compile-time calculations, but we were not doing so consistently. This patch fixes that, I think, and adds type signatures
Diffstat (limited to 'compiler')
-rw-r--r--compiler/prelude/PrelRules.lhs18
1 files changed, 12 insertions, 6 deletions
diff --git a/compiler/prelude/PrelRules.lhs b/compiler/prelude/PrelRules.lhs
index 8604647a70..6ca928c010 100644
--- a/compiler/prelude/PrelRules.lhs
+++ b/compiler/prelude/PrelRules.lhs
@@ -223,39 +223,45 @@ cmpOp cmp l1 l2
--------------------------
-negOp (MachFloat 0.0) = Nothing -- can't represent -0.0 as a Rational
-negOp (MachFloat f) = Just (mkFloatVal (-f))
+negOp :: Literal -> Maybe CoreExpr -- Negate
+negOp (MachFloat 0.0) = Nothing -- can't represent -0.0 as a Rational
+negOp (MachFloat f) = Just (mkFloatVal (-f))
negOp (MachDouble 0.0) = Nothing
negOp (MachDouble d) = Just (mkDoubleVal (-d))
negOp (MachInt i) = intResult (-i)
negOp l = Nothing
--------------------------
+intOp2 :: (Integer->Integer->Integer) -> Literal -> Literal -> Maybe CoreExpr
intOp2 op (MachInt i1) (MachInt i2) = intResult (i1 `op` i2)
intOp2 op l1 l2 = Nothing -- Could find LitLit
+intOp2Z :: (Integer->Integer->Integer) -> Literal -> Literal -> Maybe CoreExpr
+-- Like intOp2, but Nothing if i2=0
intOp2Z op (MachInt i1) (MachInt i2)
- | i2 /= 0 = Just (mkIntVal (i1 `op` i2))
+ | i2 /= 0 = intResult (i1 `op` i2)
intOp2Z op l1 l2 = Nothing -- LitLit or zero dividend
--------------------------
#if __GLASGOW_HASKELL__ >= 500
+wordOp2 :: (Integer->Integer->Integer) -> Literal -> Literal -> Maybe CoreExpr
wordOp2 op (MachWord w1) (MachWord w2)
= wordResult (w1 `op` w2)
wordOp2 op l1 l2 = Nothing -- Could find LitLit
#endif
+wordOp2Z :: (Integer->Integer->Integer) -> Literal -> Literal -> Maybe CoreExpr
wordOp2Z op (MachWord w1) (MachWord w2)
- | w2 /= 0 = Just (mkWordVal (w1 `op` w2))
+ | w2 /= 0 = wordResult (w1 `op` w2)
wordOp2Z op l1 l2 = Nothing -- LitLit or zero dividend
#if __GLASGOW_HASKELL__ >= 500
wordBitOp2 op l1@(MachWord w1) l2@(MachWord w2)
- = Just (mkWordVal (w1 `op` w2))
+ = wordResult (w1 `op` w2)
#else
-- Integer is not an instance of Bits, so we operate on Word64
wordBitOp2 op l1@(MachWord w1) l2@(MachWord w2)
- = Just (mkWordVal ((fromIntegral::Word64->Integer) (fromIntegral w1 `op` fromIntegral w2)))
+ = wordResult ((fromIntegral::Word64->Integer) (fromIntegral w1 `op` fromIntegral w2))
#endif
wordBitOp2 op l1 l2 = Nothing -- Could find LitLit