pretty printing for expressions and types

This commit is contained in:
krangelov
2021-08-26 15:46:16 +02:00
parent 07bda06fb2
commit 275addfcbe
11 changed files with 572 additions and 11 deletions

View File

@@ -25,6 +25,7 @@ data PgfExn
data PgfText
data PgfItor
data PgfPGF
data PgfPrintContext
data PgfConcr
data PgfTypeHypo
data PgfMarshaller
@@ -51,9 +52,15 @@ foreign import ccall "&pgf_free"
foreign import ccall "pgf_abstract_name"
pgf_abstract_name :: Ptr PgfPGF -> IO (Ptr PgfText)
foreign import ccall "pgf_print_expr"
pgf_print_expr :: StablePtr Expr -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
foreign import ccall "pgf_read_expr"
pgf_read_expr :: Ptr PgfText -> Ptr PgfUnmarshaller -> IO (StablePtr Expr)
foreign import ccall "pgf_print_type"
pgf_print_type :: StablePtr Type -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
foreign import ccall "pgf_read_type"
pgf_read_type :: Ptr PgfText -> Ptr PgfUnmarshaller -> IO (StablePtr Type)
@@ -105,6 +112,16 @@ peekText ptr =
cs <- decode pptr end
return (((toEnum . fromEnum) x) : cs)
newTextEx :: Int -> String -> IO (Ptr a)
newTextEx offs s = do
ptr <- mallocBytes (offs + (#size PgfText) + size + 1)
let ptext = ptr `plusPtr` offs
(#poke PgfText, size) ptext (fromIntegral size :: CSize)
pokeUtf8CString s (ptext `plusPtr` (#const offsetof(PgfText, text)))
return ptr
where
size = utf8Length s
newText :: String -> IO (Ptr PgfText)
newText s = do
ptr <- mallocBytes ((#size PgfText) + size + 1)