[clean up code some, add Addr_ and FunAddr_ unboxed newtypes for when you need to use a specific calling convention with foreign code
John Meacham <john@repetae.net>**20090227090327
 Ignore-this: ac1d1b85e7b532959bfda923a9ce6d36
] hunk ./DataConstructors.hs 27
-    lookupCType',
hunk ./DataConstructors.hs 89
-tipe' (TCon (Tycon n k)) | Just n' <- lookup n primitiveAliases = return $ ELit litCons { litName = n', litType = kind k }
+tipe' (TCon (Tycon n k)) | Just n' <- Map.lookup n primitiveAliases = return $ ELit litCons { litName = n', litType = kind k }
hunk ./DataConstructors.hs 373
--- which C types these convert to in FFI specifications for
--- figuring out calling conventions. not necessarily related
--- to the representation.
--- ideally, these could be set via a pragma
-
-typeTable = Map.fromList [
-    (tc_Char,"wchar_t"),
-    (tc_Int, "int"),
-    (tc_Int8, "int8_t"),
-    (tc_Int16, "int16_t"),
-    (tc_Int32, "int32_t"),
-    (tc_Int64, "int64_t"),
-    (tc_IntMax, "intmax_t"),
-    (tc_IntPtr, "intptr_t"),
-    (tc_Word, "unsigned"),
-    (tc_Word8, "uint8_t"),
-    (tc_Word16, "uint16_t"),
-    (tc_Word32, "uint32_t"),
-    (tc_Word64, "uint64_t"),
-    (tc_WordMax, "uintmax_t"),
-    (tc_WordPtr, "uintptr_t"),
-    (tc_Float, "float"),
-    (tc_Double, "double"),
-    (tc_Addr, "HsPtr"),
-    (tc_FunAddr, "HsFunPtr"),
-
-    (tc_CChar, "char"),
-    (tc_CShort, "short"),
-    (tc_CInt, "int"),
-    (tc_CLong, "long"),
-
-    (tc_CSChar, "signed char"),
-
-    (tc_CUChar, "unsigned char"),
-    (tc_CUShort, "unsigned short"),
-    (tc_CUInt, "unsigned int"),
-    (tc_CULong, "unsigned long"),
-
-    (tc_CWchar, "wchar_t"),
-    (tc_CWint, "wint_t"),
-    (tc_CTime, "time_t"),
-    (tc_CSize, "size_t"),
-    (tc_Unit,  "void"),
-    (tc_World__,  "void")
-    ]
-
hunk ./DataConstructors.hs 406
-            ExtTypeVoid -> ExtTypeVoid 
+            ExtTypeVoid -> ExtTypeVoid
hunk ./DataConstructors.hs 410
-    g (ELit LitCons { litName = c }) 
+    g (ELit LitCons { litName = c })
hunk ./DataConstructors.hs 420
--- | Finds the internal constructor, E field type, and C field type
--- for an FFI-able single-field, single-constructor datatype like
--- 'Int' (or a newtype thereof)
-lookupCType' dataTable e = do
-    ExtTypeBoxed a b c <- lookupExtTypeInfo dataTable e 
-    return (a,b,c)
-{-
-    = g ecase followAliases (mappend dataTablePrims dataTable) e of
-    ELit LitCons { litName = c, litArgs = [] }
-        | Just Constructor { conChildren = DataNormal [cn] }  <- getConstructor c dataTable,
-          Just Constructor { conOrigSlots = [SlotNormal st@(ELit LitCons { litName = n, litArgs = [] })] } <- getConstructor cn dataTable
-            -> return (cn,st,show n)
-    ELit LitCons { litName = c, litArgs = [] } | Just cn  <- getConstructor c dataTable -> fail $ "lookupCType: " ++ show cn
-    e' -> fail $ "lookupCType': " ++ show (e,e')
-    -}
-
-
hunk ./DataConstructors.hs 519
-    newDataTable = DataTable (Map.mapWithKey fixupMap $ Map.fromList [ (conName x,procNewTypes x) | x <- ds', conName x `notElem` map fst primitiveAliases ])
+    newDataTable = DataTable (Map.mapWithKey fixupMap $ Map.fromList [ (conName x,procNewTypes x) | x <- ds', conName x `notElem` mkeys primitiveAliases ])
hunk ./DataConstructors.hs 814
-primitiveAliases = [
+-- | list of declared data types that map
+-- directly to primitive real types
+
+primitiveAliases :: Map.Map Name Name
+primitiveAliases = Map.fromList [
hunk ./DataConstructors.hs 834
+
+-- mapping of primitive types to the C calling convention used
+-- when passing to/from foreign functions
+
+rawExtTypeMap :: Map.Map Name ExtType
hunk ./DataConstructors.hs 859
+-- which C types these convert to in FFI specifications for
+-- figuring out calling conventions. not necessarily related
+-- to the representation.
+--
+-- ideally, these could be set via a pragma
+
+typeTable :: Map.Map Name ExtType
+typeTable = Map.fromList [
+    (tc_Char,"wchar_t"),
+    (tc_Int, "int"),
+    (tc_Int8, "int8_t"),
+    (tc_Int16, "int16_t"),
+    (tc_Int32, "int32_t"),
+    (tc_Int64, "int64_t"),
+    (tc_IntMax, "intmax_t"),
+    (tc_IntPtr, "intptr_t"),
+    (tc_Word, "unsigned"),
+    (tc_Word8, "uint8_t"),
+    (tc_Word16, "uint16_t"),
+    (tc_Word32, "uint32_t"),
+    (tc_Word64, "uint64_t"),
+    (tc_WordMax, "uintmax_t"),
+    (tc_WordPtr, "uintptr_t"),
+    (tc_Float, "float"),
+    (tc_Double, "double"),
+    (tc_Addr, "HsPtr"),
+    (tc_FunAddr, "HsFunPtr"),
+
+    (tc_Addr_, "HsPtr"),
+    (tc_FunAddr_, "HsFunPtr"),
+
+    (tc_CChar, "char"),
+    (tc_CShort, "short"),
+    (tc_CInt, "int"),
+    (tc_CLong, "long"),
+
+    (tc_CSChar, "signed char"),
+
+    (tc_CUChar, "unsigned char"),
+    (tc_CUShort, "unsigned short"),
+    (tc_CUInt, "unsigned int"),
+    (tc_CULong, "unsigned long"),
+
+    (tc_CWchar, "wchar_t"),
+    (tc_CWint, "wint_t"),
+    (tc_CTime, "time_t"),
+    (tc_CSize, "size_t"),
+    (tc_Unit,  "void"),
+    (tc_World__,  "void")
+    ]
+
hunk ./E/FromHs.hs 89
-    f (TCon (Tycon n k)) | Just n' <- lookup n primitiveAliases = ELit litCons { litName = n', litType = kind k }
+    f (TCon (Tycon n k)) | Just n' <- Map.lookup n primitiveAliases = ELit litCons { litName = n', litType = kind k }
hunk ./data/names.txt 37
+Addr_      Jhc.Types.Addr_
+FunAddr_   Jhc.Types.FunAddr_
+
hunk ./lib/base/Jhc/Prim.hs 20
-type Addr__ = BitsPtr_
hunk ./lib/base/Jhc/Prim.hs 23
+type Addr__ = BitsPtr_
+
+-- these exist simply to modify the calling
+-- convention with unboxed types
+newtype Addr_ = Addr_ BitsPtr_
+newtype FunAddr_ = FunAddr_ BitsPtr_