diff options
Diffstat (limited to 'src/runtime/haskell-bind')
| -rw-r--r-- | src/runtime/haskell-bind/PGF2.hsc | 7 | ||||
| -rw-r--r-- | src/runtime/haskell-bind/PGF2/Expr.hsc | 19 | ||||
| -rw-r--r-- | src/runtime/haskell-bind/PGF2/FFI.hs | 6 |
3 files changed, 31 insertions, 1 deletions
diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc index cdafb6eb9..1f8d07c12 100644 --- a/src/runtime/haskell-bind/PGF2.hsc +++ b/src/runtime/haskell-bind/PGF2.hsc @@ -31,7 +31,12 @@ module PGF2 (-- * PGF Fun,functions, functionsByCat, functionType, hasLinearization, -- ** Expressions Expr,showExpr,readExpr, - mkAbs,unAbs,mkApp,unApp,mkStr,unStr,mkInt,unInt,mkFloat,unFloat, + mkAbs,unAbs, + mkApp,unApp, + mkStr,unStr, + mkInt,unInt, + mkFloat,unFloat, + mkMeta,unMeta, -- ** Types Type(..), Hypo, BindType(..), startCat, showType, 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 |
