summaryrefslogtreecommitdiff
path: root/src/runtime/haskell-bind/PGF2
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2017-01-26 10:17:02 +0000
committerkrasimir <krasimir@chalmers.se>2017-01-26 10:17:02 +0000
commit6af632dd185b176222724cce47a49428f1301752 (patch)
tree2fea848701ca17de3365b5d5621c085de1fbdaa2 /src/runtime/haskell-bind/PGF2
parentbe43d5dfdc777995d237e224da7f627426774527 (diff)
added mkMeta and unMeta in the Haskell binding
Diffstat (limited to 'src/runtime/haskell-bind/PGF2')
-rw-r--r--src/runtime/haskell-bind/PGF2/Expr.hsc19
-rw-r--r--src/runtime/haskell-bind/PGF2/FFI.hs6
2 files changed, 25 insertions, 0 deletions
diff --git a/src/runtime/haskell-bind/PGF2/Expr.hsc b/src/runtime/haskell-bind/PGF2/Expr.hsc
index 9fd0494bd..c18e97a13 100644
--- a/src/runtime/haskell-bind/PGF2/Expr.hsc
+++ b/src/runtime/haskell-bind/PGF2/Expr.hsc
@@ -152,6 +152,25 @@ unFloat (Expr expr master) =
else do n <- peek (plit `plusPtr` (#offset PgfLiteralFlt, val))
return (Just (realToFrac (n :: CDouble)))
+-- | Constructs a meta variable as an expression
+mkMeta :: Int -> Expr
+mkMeta id =
+ unsafePerformIO $ do
+ exprPl <- gu_new_pool
+ c_expr <- pgf_expr_meta (fromIntegral id) exprPl
+ exprFPl <- newForeignPtr gu_pool_finalizer exprPl
+ return (Expr c_expr exprFPl)
+
+-- | Decomposes an expression into a meta variable
+unMeta :: Expr -> Maybe Int
+unMeta (Expr expr master) =
+ unsafePerformIO $ do
+ c_meta <- pgf_expr_unmeta expr
+ if c_meta == nullPtr
+ then return Nothing
+ else do id <- (#peek PgfExprMeta, id) c_meta
+ return (Just (fromIntegral (id :: CInt)))
+
-- | parses a 'String' as an expression
readExpr :: String -> Maybe Expr
readExpr str =
diff --git a/src/runtime/haskell-bind/PGF2/FFI.hs b/src/runtime/haskell-bind/PGF2/FFI.hs
index 0e5ba250c..9051b1465 100644
--- a/src/runtime/haskell-bind/PGF2/FFI.hs
+++ b/src/runtime/haskell-bind/PGF2/FFI.hs
@@ -266,6 +266,12 @@ foreign import ccall "pgf/pgf.h pgf_expr_abs"
foreign import ccall "pgf/pgf.h pgf_expr_unabs"
pgf_expr_unabs :: PgfExpr -> IO (Ptr a)
+foreign import ccall "pgf/pgf.h pgf_expr_meta"
+ pgf_expr_meta :: CInt -> Ptr GuPool -> IO PgfExpr
+
+foreign import ccall "pgf/pgf.h pgf_expr_unmeta"
+ pgf_expr_unmeta :: PgfExpr -> IO (Ptr a)
+
foreign import ccall "pgf/pgf.h pgf_expr_string"
pgf_expr_string :: CString -> Ptr GuPool -> IO PgfExpr