Skip to content

Commit e00da32

Browse files
committed
Split the Graphics.GL.Functions implementation into more manageable chunks.
1 parent 43ae841 commit e00da32

37 files changed

+50549
-49639
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
3.2.1.0
22
-------
33
* Updated OpenGL registry to r33061.
4+
* Split the `Graphics.GL.Functions` implementation into more manageable chunks.
45

56
3.2.0.0
67
-------

OpenGLRaw.cabal

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,38 @@ library
609609
other-modules:
610610
Graphics.GL.ExtensionPredicates
611611
Graphics.GL.Foreign
612+
Graphics.GL.Functions.F01
613+
Graphics.GL.Functions.F02
614+
Graphics.GL.Functions.F03
615+
Graphics.GL.Functions.F04
616+
Graphics.GL.Functions.F05
617+
Graphics.GL.Functions.F06
618+
Graphics.GL.Functions.F07
619+
Graphics.GL.Functions.F08
620+
Graphics.GL.Functions.F09
621+
Graphics.GL.Functions.F10
622+
Graphics.GL.Functions.F11
623+
Graphics.GL.Functions.F12
624+
Graphics.GL.Functions.F13
625+
Graphics.GL.Functions.F14
626+
Graphics.GL.Functions.F15
627+
Graphics.GL.Functions.F16
628+
Graphics.GL.Functions.F17
629+
Graphics.GL.Functions.F18
630+
Graphics.GL.Functions.F19
631+
Graphics.GL.Functions.F20
632+
Graphics.GL.Functions.F21
633+
Graphics.GL.Functions.F22
634+
Graphics.GL.Functions.F23
635+
Graphics.GL.Functions.F24
636+
Graphics.GL.Functions.F25
637+
Graphics.GL.Functions.F26
638+
Graphics.GL.Functions.F27
639+
Graphics.GL.Functions.F28
640+
Graphics.GL.Functions.F29
641+
Graphics.GL.Functions.F30
642+
Graphics.GL.Functions.F31
643+
Graphics.GL.Functions.F32
612644
c-sources:
613645
cbits/HsOpenGLRaw.c
614646
hs-source-dirs: src

RegistryProcessor/src/Main.hs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,40 +159,61 @@ printForeign sigMap = do
159159
SI.hPutStrLn h $ "module " ++ moduleName ++ " where"
160160
SI.hPutStrLn h ""
161161
SI.hPutStrLn h "import Foreign.C.Types"
162+
SI.hPutStrLn h "import Foreign.Marshal.Error ( throwIf )"
162163
SI.hPutStrLn h "import Foreign.Ptr"
164+
SI.hPutStrLn h $ "import " ++ moduleNameFor ["GetProcAddress"] ++ " ( getProcAddress )"
163165
SI.hPutStrLn h $ "import " ++ moduleNameFor ["Types"]
164166
SI.hPutStrLn h "import Numeric.Fixed"
165167
SI.hPutStrLn h "import Numeric.Half"
166168
SI.hPutStrLn h ""
169+
SI.hPutStrLn h "getCommand :: String -> IO (FunPtr a)"
170+
SI.hPutStrLn h "getCommand cmd ="
171+
SI.hPutStrLn h " throwIfNullFunPtr (\"unknown OpenGL command \" ++ cmd) $ getProcAddress cmd"
172+
SI.hPutStrLn h " where throwIfNullFunPtr :: String -> IO (FunPtr a) -> IO (FunPtr a)"
173+
SI.hPutStrLn h " throwIfNullFunPtr = throwIf (== nullFunPtr) . const"
174+
SI.hPutStrLn h ""
167175
mapM_ (SI.hPutStrLn h . uncurry makeImportDynamic) (M.assocs sigMap)
168176

177+
chunksOf :: Int -> [a] -> [[a]]
178+
chunksOf n = takeWhile (not . null) . L.unfoldr (Just . splitAt n)
179+
180+
justifyRight :: Int -> a -> [a] -> [a]
181+
justifyRight n c xs = reverse . take (max n (length xs)) . (++ repeat c) . reverse $ xs
182+
169183
printFunctions :: API -> Registry -> M.Map String String -> IO ()
170184
printFunctions api registry sigMap = do
171185
let comment =
172186
["All raw functions from the",
173187
"<http://www.opengl.org/registry/ OpenGL registry>."]
188+
cmds = chunksOf 100 . M.toAscList . commands $ registry
189+
mnames = [ [ "Functions", "F" ++ justifyRight 2 '0' (show i) ] |
190+
i <- [ 1 .. length cmds ] ]
174191
startModule ["Functions"] Nothing comment $ \moduleName h -> do
175192
SI.hPutStrLn h $ "module " ++ moduleName ++ " ("
176-
SI.hPutStrLn h . separate unCommandName . M.keys . commands $ registry
193+
SI.hPutStrLn h . separate (("module " ++) . moduleNameFor) $ mnames
177194
SI.hPutStrLn h ") where"
178195
SI.hPutStrLn h ""
179-
SI.hPutStrLn h "import Control.Monad.IO.Class ( MonadIO(..) )"
180-
SI.hPutStrLn h "import Foreign.Marshal.Error ( throwIf )"
181-
SI.hPutStrLn h "import Foreign.Ptr ( Ptr, FunPtr, nullFunPtr )"
182-
SI.hPutStrLn h "import System.IO.Unsafe ( unsafePerformIO )"
196+
mapM_ (SI.hPutStrLn h . ("import " ++) . moduleNameFor) mnames
197+
CM.zipWithM_ (printSubFunctions api registry sigMap) mnames cmds
198+
199+
printSubFunctions :: API -> Registry -> M.Map String String ->
200+
[String] -> [(CommandName, Command)] -> IO ()
201+
printSubFunctions api registry sigMap mname cmds = do
202+
let comment =
203+
["Raw functions from the",
204+
"<http://www.opengl.org/registry/ OpenGL registry>."]
205+
startModule mname (Just "{-# OPTIONS_HADDOCK hide #-}") comment $ \moduleName h -> do
206+
SI.hPutStrLn h $ "module " ++ moduleName ++ " ("
207+
SI.hPutStrLn h . separate unCommandName . map fst $ cmds
208+
SI.hPutStrLn h ") where"
183209
SI.hPutStrLn h ""
210+
SI.hPutStrLn h "import Control.Monad.IO.Class ( MonadIO(..) )"
211+
SI.hPutStrLn h "import Foreign.Ptr"
184212
SI.hPutStrLn h $ "import " ++ moduleNameFor ["Foreign"]
185-
SI.hPutStrLn h $ "import " ++ moduleNameFor ["GetProcAddress"] ++ " ( getProcAddress )"
186213
SI.hPutStrLn h $ "import " ++ moduleNameFor ["Types"]
214+
SI.hPutStrLn h "import System.IO.Unsafe ( unsafePerformIO )"
187215
SI.hPutStrLn h ""
188-
SI.hPutStrLn h "getCommand :: String -> IO (FunPtr a)"
189-
SI.hPutStrLn h "getCommand cmd ="
190-
SI.hPutStrLn h " throwIfNullFunPtr (\"unknown OpenGL command \" ++ cmd) $ getProcAddress cmd"
191-
SI.hPutStrLn h ""
192-
SI.hPutStrLn h "throwIfNullFunPtr :: String -> IO (FunPtr a) -> IO (FunPtr a)"
193-
SI.hPutStrLn h "throwIfNullFunPtr = throwIf (== nullFunPtr) . const"
194-
SI.hPutStrLn h ""
195-
mapM_ (SI.hPutStrLn h . showCommand api registry sigMap) (M.elems (commands registry))
216+
mapM_ (SI.hPutStrLn h . showCommand api registry sigMap . snd) cmds
196217

197218
type ExtensionParts = ([TypeName], [Enum'], [Command])
198219
type ExtensionModule = (ExtensionName, ExtensionName, ExtensionParts)

src/Graphics/GL/Foreign.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
module Graphics.GL.Foreign where
1818

1919
import Foreign.C.Types
20+
import Foreign.Marshal.Error ( throwIf )
2021
import Foreign.Ptr
22+
import Graphics.GL.GetProcAddress ( getProcAddress )
2123
import Graphics.GL.Types
2224
import Numeric.Fixed
2325
import Numeric.Half
2426

27+
getCommand :: String -> IO (FunPtr a)
28+
getCommand cmd =
29+
throwIfNullFunPtr ("unknown OpenGL command " ++ cmd) $ getProcAddress cmd
30+
where throwIfNullFunPtr :: String -> IO (FunPtr a) -> IO (FunPtr a)
31+
throwIfNullFunPtr = throwIf (== nullFunPtr) . const
32+
2533
foreign import CALLCONV "dynamic" dyn202
2634
:: FunPtr (GLDEBUGPROC -> Ptr a -> IO ())
2735
-> GLDEBUGPROC -> Ptr a -> IO ()

0 commit comments

Comments
 (0)