1
0
forked from GitHub/gf-core

added PGF(pIdent,pExpr)

This commit is contained in:
krangelov
2021-09-14 09:34:00 +02:00
parent cf7673525f
commit 22f62be511
9 changed files with 166 additions and 91 deletions

View File

@@ -73,6 +73,8 @@ foreign import ccall "pgf_print_expr"
foreign import ccall "pgf_read_expr"
pgf_read_expr :: Ptr PgfText -> Ptr PgfUnmarshaller -> IO (StablePtr Expr)
foreign import ccall pgf_read_expr_ex :: Ptr PgfText -> Ptr CString -> Ptr PgfUnmarshaller -> IO (StablePtr Expr)
foreign import ccall "pgf_print_type"
pgf_print_type :: StablePtr Type -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
@@ -137,20 +139,10 @@ foreign import ccall pgf_set_abstract_flag :: Ptr PgfDB -> Ptr PgfRevision -> Pt
-- Texts
peekText :: Ptr PgfText -> IO String
peekText ptr =
alloca $ \pptr -> do
size <- ((#peek PgfText, size) ptr) :: IO CSize
let c_text = castPtr ptr `plusPtr` (#offset PgfText, text)
poke pptr c_text
decode pptr (c_text `plusPtr` fromIntegral size)
where
decode pptr end = do
ptr <- peek pptr
if ptr >= end
then return []
else do x <- pgf_utf8_decode pptr
cs <- decode pptr end
return (((toEnum . fromEnum) x) : cs)
peekText ptr = do
size <- ((#peek PgfText, size) ptr) :: IO CSize
let c_text = castPtr ptr `plusPtr` (#offset PgfText, text)
peekUtf8CString c_text (c_text `plusPtr` fromIntegral size)
newTextEx :: Int -> String -> IO (Ptr a)
newTextEx offs s = do
@@ -180,6 +172,19 @@ withText s fn =
where
size = utf8Length s
peekUtf8CString c_start c_end =
alloca $ \pptr -> do
poke pptr c_start
decode pptr c_end
where
decode pptr end = do
ptr <- peek pptr
if ptr >= end
then return []
else do x <- pgf_utf8_decode pptr
cs <- decode pptr end
return (((toEnum . fromEnum) x) : cs)
pokeUtf8CString s ptr =
alloca $ \pptr ->
poke pptr ptr >> encode s pptr