1
0
forked from GitHub/gf-core

Added 'functions' and 'functionType' to py-bindings.

This commit is contained in:
jordi.saludes
2010-07-27 15:42:48 +00:00
parent 42fc14b85c
commit aa9907d00b
3 changed files with 64 additions and 24 deletions

View File

@@ -1,4 +1,6 @@
{-# LANGUAGE ForeignFunctionInterface #-}
-- GF Python bindings -- Jordi Saludes, upc.edu 2010
module PyGF where
import PGF
@@ -226,8 +228,27 @@ gf_inferexpr ppgf pexp ptype = do
let Right (_,t) = inferExpr pgf exp
poke ptype t
foreign export ccall gf_functions :: Ptr PGF -> IO (Ptr ())
gf_functions ppgf = do
pgf <- peek ppgf
listToPy pyCId $ functions pgf
foreign export ccall gf_functiontype :: Ptr PGF -> Ptr CId -> IO (Ptr Type)
gf_functiontype ppgf pcid = do
pgf <- peek ppgf
cid <- peek pcid
case functionType pgf cid of
Just t -> do
ptp <- pyType
poke ptp t
return ptp
_ -> return nullPtr
foreign import ccall "newLang" pyLang :: IO (Ptr Language)
foreign import ccall "newTree" pyTree :: IO (Ptr Tree)
foreign import ccall "newgfType" pyType :: IO (Ptr Type)
foreign import ccall "newCId" pyCId :: IO (Ptr CId)
foreign import ccall "newExpr" pyExpr :: IO (Ptr Expr)
foreign import ccall "newList" pyList :: IO (Ptr ())