From 22773909bf8d0e3e194411e8b9f504a51dae30bf Mon Sep 17 00:00:00 2001 From: krasimir Date: Tue, 30 Jun 2015 20:42:19 +0000 Subject: [PATCH] add function 'functions' in the Haskell binding to the C runtime --- src/runtime/haskell-bind/PGF2.hsc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc index 77de6d857..dc3566627 100644 --- a/src/runtime/haskell-bind/PGF2.hsc +++ b/src/runtime/haskell-bind/PGF2.hsc @@ -26,6 +26,8 @@ module PGF2 (-- * CId graphvizAbstractTree,graphvizParseTree, -- * Morphology MorphoAnalysis, lookupMorpho, fullFormLexicon, + -- * Generation + functions, generateAll, -- * Exceptions PGFError(..), -- * Grammar specific callbacks @@ -524,6 +526,26 @@ alignWords lang e = unsafePerformIO $ (fids :: [CInt]) <- peekArray (fromIntegral (n_fids :: CInt)) (ptr `plusPtr` (#offset PgfAlignmentPhrase, fids)) return (phrase, map fromIntegral fids) +functions :: PGF -> [Fun] +functions p = + unsafePerformIO $ + withGuPool $ \tmpPl -> + allocaBytes (#size GuMapItor) $ \itor -> do + exn <- gu_new_exn tmpPl + ref <- newIORef [] + fptr <- wrapMapItorCallback (getFunctions ref) + (#poke GuMapItor, fn) itor fptr + pgf_iter_functions (pgf p) itor exn + freeHaskellFunPtr fptr + fs <- readIORef ref + return (reverse fs) + where + getFunctions :: IORef [String] -> MapItorCallback + getFunctions ref itor key value exn = do + names <- readIORef ref + name <- peekCString (castPtr key) + writeIORef ref $! (name : names) + ----------------------------------------------------------------------------- -- Helper functions