[use PrimInfo for getting basic properties of types, try to be smarter about figuring them out statically, stop relying on C preprocessor macros for these constants
John Meacham <john@repetae.net>**20070531110103] hunk ./C/FromGrin2.hs 523
+    PrimTypeInfo { primArgTy = arg, primTypeInfo = PrimMinBound } -> return $ expressionRaw ("prim_minbound(" ++ tyToC Op.HintUnsigned arg ++ ")")
+    PrimTypeInfo { primArgTy = arg, primTypeInfo = PrimMaxBound } -> return $ expressionRaw ("prim_maxbound(" ++ tyToC Op.HintUnsigned arg ++ ")")
+    PrimTypeInfo { primArgTy = arg, primTypeInfo = PrimUMaxBound } -> return $ expressionRaw ("prim_umaxbound(" ++ tyToC Op.HintUnsigned arg ++ ")")
hunk ./C/Prims.hs 67
-data PrimTypeInfo = PrimSizeOf | PrimMaxBound | PrimMinBound | PrimAlignmentOf | PrimTypeIsSigned  | PrimUMaxBound
+data PrimTypeInfo = PrimSizeOf | PrimMaxBound | PrimMinBound | PrimAlignmentOf | PrimUMaxBound
hunk ./C/Prims.hs 71
+primStaticTypeInfo :: Op.Ty -> PrimTypeInfo -> Maybe Integer
+primStaticTypeInfo (Op.TyBits (Op.Bits b) _) w = Just ans where
+    bits = toInteger b
+    ans = case w of
+        PrimSizeOf -> bits `div` 8
+        PrimAlignmentOf ->  bits `div` 8
+        primMinBound -> negate $ 2^(bits - 1)
+        primMaxBound -> 2^(bits - 1) - 1
+        primUMaxBound -> 2^bits - 1
+primStaticTypeInfo _ _ = Nothing
+
hunk ./C/Prims.hs 157
-    pprint PrimTypeInfo { primArgTy = at, primTypeInfo = PrimTypeIsSigned } = text "is_signed" <> parens (tshow at)
hunk ./data/PrimitiveOperators-in.hs 64
-oper_aIa op ct' a b = EPrim (binOp op ct ot_int ct) [a,b] (rawType ct') where    
+oper_aIa op ct' a b = EPrim (binOp op ct ot_int ct) [a,b] (rawType ct') where
hunk ./data/PrimitiveOperators-in.hs 196
-prim_const cn s st t et = ELit litCons { litName = cn, litArgs = [EPrim (APrim (CConst s t) mempty) [] st], litType = et }
hunk ./data/PrimitiveOperators-in.hs 197
-prim_minbound, prim_maxbound :: Name -> E -> ExtType -> E -> E
-prim_minbound dc dt s e = f s where
-    f "HsChar" = boxup $ ELit $ LitInt 0 (rawType "bits32")
-    f s | Just pt <- genericPrimitiveInfo s = boxup $ case primTypeIsSigned pt of
-        False -> ELit $ LitInt 0 (rawType s)
-        True -> ELit $ LitInt (negate $ 2 ^ (8 * primTypeSizeOf pt - 1)) (rawType s)
-    f _ = e
-    boxup a =  ELit litCons { litName = dc, litArgs = [a], litType = dt }
-prim_maxbound dc dt s e = f s where
-    f "HsChar" = boxup $ ELit $ LitInt 0x10ffff (rawType "bits32")
-    f s | Just pt <- genericPrimitiveInfo s = boxup $ case primTypeIsSigned pt of
-        False -> ELit $ LitInt (2 ^ (8 * primTypeSizeOf pt)) (rawType s)
-        True -> ELit $ LitInt (2 ^ (8 * primTypeSizeOf pt - 1) - 1) (rawType s)
-    f _ = e
-    boxup a =  ELit litCons { litName = dc, litArgs = [a], litType = dt }
+prim_minbound, prim_maxbound, prim_uminbound, prim_umaxbound :: Name -> E -> ExtType ->  E
+prim_uminbound dc dt s = prim_number dc 0 (rawType s) dt
+prim_umaxbound = prim_bound PrimUMaxBound
+prim_maxbound = prim_bound PrimMaxBound
+prim_minbound = prim_bound PrimMinBound
hunk ./data/PrimitiveOperators-in.hs 203
+prim_bound pt dc dt s = (ELit (litCons { litName = dc, litArgs = [rp], litType = dt })) where
+    rt = rawType s
+    Just at = Op.readTy s
+    rp | Just n <- primStaticTypeInfo at pt = (ELit (LitInt (fromInteger n) rt))
+       | otherwise = EPrim (APrim (PrimTypeInfo { primArgTy = at, primRetTy = at, primTypeInfo = pt }) mempty) [] rt
hunk ./data/PrimitiveOperators-in.hs 209
-prim_sizeof s | Just pt <- genericPrimitiveInfo s = let
-    rp = ELit $ LitInt (fromIntegral (primTypeSizeOf pt)) tIntzh
-    in (ELit (litCons { litName = dc_Int, litArgs = [rp], litType = tInt }))
hunk ./data/PrimitiveOperators-in.hs 210
-    rp = EPrim (APrim (PrimTypeInfo { primArgTy = stringToOpTy s, primRetTy = ot_int, primTypeInfo = PrimSizeOf }) mempty) [] tIntzh
+    Just at = Op.readTy s
+    rp | Just n <- primStaticTypeInfo at PrimSizeOf = (ELit (LitInt (fromInteger n) tIntzh))
+       | otherwise = EPrim (APrim (PrimTypeInfo { primArgTy = stringToOpTy s, primRetTy = ot_int, primTypeInfo = PrimSizeOf }) mempty) [] tIntzh
hunk ./data/jhc_rts.c 91
+
+#define prim_umaxbound(t) ((t)~((t)0))
+#define prim_maxbound(t) ((t)(~((t)1 << (sizeof(t)*8 - 1))))
+#define prim_minbound(t) ((t)(((t)1 << (sizeof(t)*8 - 1))))
hunk ./utils/op_process.prl 74
-
-#    return 'u' if /^uint/;
-#    return '' if /^int/;
-#    return 'f' if /^float/;
-#    return 'f' if /^double/;
-#    return 'u' if /unsigned/;
-#    return 'u' if /HsChar/;
-#    return 'u' if /HsPtr/;
-#    return 'u' if /HsFunPtr/;
-#    return '';
-
hunk ./utils/op_process.prl 88
-#    push @fl, \@a unless $add eq 'int';
-#    push @in, \@a unless $add eq 'float';
hunk ./utils/op_process.prl 193
-    push @inst, "[] :=> IsIn $prelude_bounded $tycon";
+    push @inst, "[] :=> IsIn $prelude_bounded $tycon" if $vtype ne 'f';
hunk ./utils/op_process.prl 195
-    #push @cmeth, "($foreign_storable, toInstName \"Foreign.Storable.sizeOf.$d->[0]\", ELam (v0 $t) \$ " . const("sizeof($d->[1])","tInt") . ")";
hunk ./utils/op_process.prl 198
-    push @cmeth, "($prelude_bounded, toInstName \"Jhc.Enum.maxBound.$d->[0]\", " . "prim_maxbound $cncons $t \"$d->[1]\" (" . const($cncons, $d->[3],$t,"$d->[1]") . "))";
-    push @cmeth, "($prelude_bounded, toInstName \"Jhc.Enum.minBound.$d->[0]\", " . "prim_minbound $cncons $t \"$d->[1]\" (" . const($cncons,$d->[4],$t,"$d->[1]") . "))";
+    push @cmeth, "($prelude_bounded, toInstName \"Jhc.Enum.maxBound.$d->[0]\", " . "prim_${vtype}maxbound $cncons $t \"$d->[1]\")" if $vtype ne 'f';;
+    push @cmeth, "($prelude_bounded, toInstName \"Jhc.Enum.minBound.$d->[0]\", " . "prim_${vtype}minbound $cncons $t \"$d->[1]\")" if $vtype ne 'f';;
hunk ./utils/op_process.prl 226
-        #push @inst, "[] :=> IsIn (toHsName \"$c->[2]\") (TCon \$ Tycon (toHsName \"$d->[0]\") Star)\n" unless $seen{$c->[2],$d->[0]}++;