{-# LINE 1 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
----------------------------------------------------------------------------
-- |
-- Module      :  Data.Emacs.Module.Raw.Env
-- Copyright   :  (c) Sergey Vinokurov 2018
-- License     :  Apache-2.0 (see LICENSE)
-- Maintainer  :  serg.foo@gmail.com
--
-- Low-level and, hopefully, low-overhead wrappers around @struct emacs_env@.
----------------------------------------------------------------------------

{-# LANGUAGE DataKinds                #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell          #-}
{-# LANGUAGE UnliftedFFITypes         #-}

{-# OPTIONS_HADDOCK not-home #-}

module Data.Emacs.Module.Raw.Env
  ( EnumFuncallExit(..)
  , EnumProcessInputResult(..)
  , Env
  , CBoolean
  , isTruthy
  , isNonTruthy
  , isValidEnv

  , makeGlobalRef
  , freeGlobalRef

  , nonLocalExitCheck
  , nonLocalExitGet
  , nonLocalExitSignal
  , nonLocalExitThrow
  , nonLocalExitClear

  , variadicFunctionArgs
  , makeFunction

  , funcall
  , funcallPrimitive
  , intern
  , typeOf
  , isNotNil
  , eq

  , extractInteger
  , makeInteger
  , extractFloat
  , makeFloat
  , copyStringContents
  , makeString
  , makeUnibyteString
  , makeUserPtr
  , getUserPtr
  , setUserPtr
  , getUserFinaliser
  , setUserFinaliser
  , vecGet
  , vecSet
  , vecSize
  , setFunctionFinalizer
  , processInput
  ) where

import Control.Monad.IO.Class

import Data.Coerce
import Foreign
import Foreign.C
import Prettyprinter

import Data.Emacs.Module.NonNullPtr
import Data.Emacs.Module.Raw.Env.Internal as Env
import Data.Emacs.Module.Raw.Env.TH
import Data.Emacs.Module.Raw.Value
import Data.Emacs.Module.Raw.Value.Internal

import Data.Emacs.Module.NonNullPtr.Internal



newtype EnumFuncallExit = EnumFuncallExit { EnumFuncallExit -> CInt
unEnumFuncallExit :: CInt }

instance Pretty EnumFuncallExit where
  pretty :: forall ann. EnumFuncallExit -> Doc ann
pretty (EnumFuncallExit (CInt Int32
x)) = Int32 -> Doc ann
forall ann. Int32 -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int32
x

newtype EnumProcessInputResult = EnumProcessInputResult { EnumProcessInputResult -> CInt
unEnumProcessInputResult :: CInt }

instance Pretty EnumProcessInputResult where
  pretty :: forall ann. EnumProcessInputResult -> Doc ann
pretty (EnumProcessInputResult (CInt Int32
x)) = Int32 -> Doc ann
forall ann. Int32 -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int32
x

-- | A wrapper around C value that denotes true or false.
newtype CBoolean = CBoolean (Word8)
{-# LINE 94 "src/Data/Emacs/Module/Raw/Env.hsc" #-}

{-# INLINE isTruthy #-}
-- | Check whether a 'CBoolean' denotes true.
isTruthy :: CBoolean -> Bool
isTruthy :: CBoolean -> Bool
isTruthy (CBoolean Word8
a) = Word8
a Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0

{-# INLINE isNonTruthy #-}
-- | Check whether a 'CBoolean' denotes false.
isNonTruthy :: CBoolean -> Bool
isNonTruthy :: CBoolean -> Bool
isNonTruthy (CBoolean Word8
a) = Word8
a Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
0



{-# INLINE isValidEnv #-}
-- | Check wheter passed @emacs_env@ structure has expected size so that
-- we will be able to access all of its fields.
isValidEnv :: MonadIO m => Env -> m Bool
isValidEnv :: forall (m :: * -> *). MonadIO m => Env -> m Bool
isValidEnv Env
env = IO Bool -> m Bool
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
  CPtrdiff
realSize <- ((\Ptr Environment
hsc_ptr -> Ptr Environment -> Int -> IO CPtrdiff
forall b. Ptr b -> Int -> IO CPtrdiff
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Environment
hsc_ptr Int
0)) (Env -> Ptr Environment
Env.toPtr Env
env)
{-# LINE 113 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
  pure $ expectedSize <= realSize
  where
    expectedSize :: CPtrdiff
    expectedSize :: CPtrdiff
expectedSize = ((CPtrdiff
320))
{-# LINE 117 "src/Data/Emacs/Module/Raw/Env.hsc" #-}

$(wrapEmacsFunc "makeGlobalRefTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 16)) |]
{-# LINE 120 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> IO (RawValue 'Pinned) |])

{-# INLINE makeGlobalRef #-}
makeGlobalRef
  :: forall m p. MonadIO m
  => Env
  -> RawValue p
  -> m (RawValue 'Pinned)
makeGlobalRef :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m (RawValue 'Pinned)
makeGlobalRef Env
env RawValue p
x =
  IO (RawValue 'Pinned) -> m (RawValue 'Pinned)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (RawValue 'Pinned) -> m (RawValue 'Pinned))
-> IO (RawValue 'Pinned) -> m (RawValue 'Pinned)
forall a b. (a -> b) -> a -> b
$ Env -> RawValue p -> IO (RawValue 'Pinned)
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m (RawValue 'Pinned)
makeGlobalRefTH Env
env RawValue p
x


$(wrapEmacsFunc "freeGlobalRefTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 24)) |]
{-# LINE 134 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> RawValue 'Pinned -> IO () |])

{-# INLINE freeGlobalRef #-}
freeGlobalRef
  :: forall m. MonadIO m
  => Env
  -> RawValue 'Pinned
  -> m ()
freeGlobalRef :: forall (m :: * -> *). MonadIO m => Env -> RawValue 'Pinned -> m ()
freeGlobalRef Env
env RawValue 'Pinned
x =
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Env -> RawValue 'Pinned -> IO ()
forall (m :: * -> *). MonadIO m => Env -> RawValue 'Pinned -> m ()
freeGlobalRefTH Env
env RawValue 'Pinned
x


$(wrapEmacsFunc "nonLocalExitCheckTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 32)) |]
{-# LINE 148 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> IO EnumFuncallExit |])

{-# INLINE nonLocalExitCheck #-}
nonLocalExitCheck
  :: MonadIO m
  => Env
  -> m EnumFuncallExit
nonLocalExitCheck :: forall (m :: * -> *). MonadIO m => Env -> m EnumFuncallExit
nonLocalExitCheck = Env -> m EnumFuncallExit
forall (m :: * -> *). MonadIO m => Env -> m EnumFuncallExit
nonLocalExitCheckTH


$(wrapEmacsFunc "nonLocalExitGetTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 48)) |]
{-# LINE 160 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> NonNullPtr (RawValue 'Regular) -> NonNullPtr (RawValue 'Regular) -> IO EnumFuncallExit |])

{-# INLINE nonLocalExitGet #-}
nonLocalExitGet
  :: MonadIO m
  => Env
  -> NonNullPtr (RawValue 'Regular) -- ^ Symbol output
  -> NonNullPtr (RawValue 'Regular) -- ^ Data output
  -> m EnumFuncallExit
nonLocalExitGet :: forall (m :: * -> *).
MonadIO m =>
Env
-> NonNullPtr (RawValue 'Regular)
-> NonNullPtr (RawValue 'Regular)
-> m EnumFuncallExit
nonLocalExitGet = Env
-> NonNullPtr (RawValue 'Regular)
-> NonNullPtr (RawValue 'Regular)
-> m EnumFuncallExit
forall (m :: * -> *).
MonadIO m =>
Env
-> NonNullPtr (RawValue 'Regular)
-> NonNullPtr (RawValue 'Regular)
-> m EnumFuncallExit
nonLocalExitGetTH


$(wrapEmacsFunc "nonLocalExitSignalTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 56)) |]
{-# LINE 174 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p1 p2. Env -> RawValue p1 -> RawValue p2 -> IO () |])

{-# INLINE nonLocalExitSignal #-}
nonLocalExitSignal
  :: MonadIO m
  => Env
  -> RawValue p1 -- ^ Error symbol
  -> RawValue p2 -- ^ Error data
  -> m ()
nonLocalExitSignal :: forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> RawValue p2 -> m ()
nonLocalExitSignal = Env -> RawValue p1 -> RawValue p2 -> m ()
forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> RawValue p2 -> m ()
nonLocalExitSignalTH


$(wrapEmacsFunc "nonLocalExitThrowTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 64)) |]
{-# LINE 188 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p1 p2. Env -> RawValue p1 -> RawValue p2 -> IO () |])

{-# INLINE nonLocalExitThrow #-}
nonLocalExitThrow
  :: MonadIO m
  => Env
  -> RawValue p1 -- ^ Tag, a symbol
  -> RawValue p2 -- ^ Value
  -> m ()
nonLocalExitThrow :: forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> RawValue p2 -> m ()
nonLocalExitThrow = Env -> RawValue p1 -> RawValue p2 -> m ()
forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> RawValue p2 -> m ()
nonLocalExitThrowTH


$(wrapEmacsFunc "nonLocalExitClearTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 40)) |]
{-# LINE 202 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> IO () |])

{-# INLINE nonLocalExitClear #-}
nonLocalExitClear
  :: MonadIO m
  => Env
  -> m ()
nonLocalExitClear :: forall (m :: * -> *). MonadIO m => Env -> m ()
nonLocalExitClear = Env -> m ()
forall (m :: * -> *). MonadIO m => Env -> m ()
nonLocalExitClearTH


variadicFunctionArgs :: CPtrdiff
variadicFunctionArgs :: CPtrdiff
variadicFunctionArgs = (-CPtrdiff
2)
{-# LINE 214 "src/Data/Emacs/Module/Raw/Env.hsc" #-}

$(wrapEmacsFunc "makeFunctionTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 72)) |]
{-# LINE 217 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall a o. Env -> CPtrdiff -> CPtrdiff -> FunPtr (RawFunctionType o a) -> CString -> Ptr a -> IO (RawValue 'Regular) |])

{-# INLINE makeFunction #-}
makeFunction
  :: forall m o a. MonadIO m
  => Env
  -> CPtrdiff        -- ^ Minimum arity
  -> CPtrdiff        -- ^ Maximum arity
  -> RawFunction o a -- ^ Implementation
  -> CString         -- ^ Documentation
  -> Ptr a           -- ^ Extra data
  -> m (RawValue 'Regular)
makeFunction :: forall (m :: * -> *) (o :: Pinning) a.
MonadIO m =>
Env
-> CPtrdiff
-> CPtrdiff
-> RawFunction o a
-> CString
-> Ptr a
-> m (RawValue 'Regular)
makeFunction =
  (Env
 -> CPtrdiff
 -> CPtrdiff
 -> FunPtr (RawFunctionType o a)
 -> CString
 -> Ptr a
 -> m (RawValue 'Regular))
-> Env
-> CPtrdiff
-> CPtrdiff
-> RawFunction o a
-> CString
-> Ptr a
-> m (RawValue 'Regular)
forall a b. Coercible a b => a -> b
coerce
    (Env
-> CPtrdiff
-> CPtrdiff
-> FunPtr (RawFunctionType o a)
-> CString
-> Ptr a
-> m (RawValue 'Regular)
forall (m :: * -> *) a (o :: Pinning).
MonadIO m =>
Env
-> CPtrdiff
-> CPtrdiff
-> FunPtr (RawFunctionType o a)
-> CString
-> Ptr a
-> m (RawValue 'Regular)
makeFunctionTH ::
         Env
      -> CPtrdiff
      -> CPtrdiff
      -> FunPtr (RawFunctionType o a)
      -> CString
      -> Ptr a
      -> m (RawValue 'Regular))


$(wrapEmacsFunc "funcallTH" Safe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 80)) |]
{-# LINE 243 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p1 p2. Env -> RawValue p1 -> CPtrdiff -> NonNullPtr (RawValue p2) -> IO (RawValue 'Regular) |])

{-# INLINE funcall #-}
funcall
  :: MonadIO m
  => Env
  -> RawValue p1              -- ^ Function
  -> CPtrdiff                 -- ^ Number of arguments
  -> NonNullPtr (RawValue p2) -- ^ Actual arguments
  -> m (RawValue 'Regular)
funcall :: forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env
-> RawValue p1
-> CPtrdiff
-> NonNullPtr (RawValue p2)
-> m (RawValue 'Regular)
funcall = Env
-> RawValue p1
-> CPtrdiff
-> NonNullPtr (RawValue p2)
-> m (RawValue 'Regular)
forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env
-> RawValue p1
-> CPtrdiff
-> NonNullPtr (RawValue p2)
-> m (RawValue 'Regular)
funcallTH


$(wrapEmacsFunc "funcallPrimitiveTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 80)) |]
{-# LINE 258 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p1 p2. Env -> RawValue p1 -> CPtrdiff -> NonNullPtr (RawValue p2) -> IO (RawValue 'Regular) |])

{-# INLINE funcallPrimitive #-}
funcallPrimitive
  :: MonadIO m
  => Env
  -> RawValue p1              -- ^ Function
  -> CPtrdiff                 -- ^ Number of arguments
  -> NonNullPtr (RawValue p2) -- ^ Actual arguments
  -> m (RawValue 'Regular)
funcallPrimitive :: forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env
-> RawValue p1
-> CPtrdiff
-> NonNullPtr (RawValue p2)
-> m (RawValue 'Regular)
funcallPrimitive = Env
-> RawValue p1
-> CPtrdiff
-> NonNullPtr (RawValue p2)
-> m (RawValue 'Regular)
forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env
-> RawValue p1
-> CPtrdiff
-> NonNullPtr (RawValue p2)
-> m (RawValue 'Regular)
funcallPrimitiveTH


$(wrapEmacsFunc "internTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 88)) |]
{-# LINE 273 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> CString -> IO (RawValue 'Regular) |])

{-# INLINE intern #-}
intern
  :: MonadIO m
  => Env
  -> CString
  -> m (RawValue 'Regular)
intern :: forall (m :: * -> *).
MonadIO m =>
Env -> CString -> m (RawValue 'Regular)
intern = Env -> CString -> m (RawValue 'Regular)
forall (m :: * -> *).
MonadIO m =>
Env -> CString -> m (RawValue 'Regular)
internTH


$(wrapEmacsFunc "typeOfTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 96)) |]
{-# LINE 286 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> IO (RawValue 'Regular) |])

{-# INLINE typeOf #-}
typeOf
  :: MonadIO m
  => Env
  -> RawValue p
  -> m (RawValue 'Regular)
typeOf :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m (RawValue 'Regular)
typeOf = Env -> RawValue p -> m (RawValue 'Regular)
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m (RawValue 'Regular)
typeOfTH


$(wrapEmacsFunc "isNotNilTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 104)) |]
{-# LINE 299 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> IO CBoolean |])

{-# INLINE isNotNil #-}
isNotNil
  :: MonadIO m
  => Env
  -> RawValue p
  -> m CBoolean
isNotNil :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CBoolean
isNotNil = Env -> RawValue p -> m CBoolean
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CBoolean
isNotNilTH


$(wrapEmacsFunc "eqTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 112)) |]
{-# LINE 312 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p1 p2. Env -> RawValue p1 -> RawValue p2 -> IO CBoolean |])

{-# INLINE eq #-}
eq
  :: MonadIO m
  => Env
  -> RawValue p1
  -> RawValue p2
  -> m CBoolean
eq :: forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> RawValue p2 -> m CBoolean
eq = Env -> RawValue p1 -> RawValue p2 -> m CBoolean
forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> RawValue p2 -> m CBoolean
eqTH


$(wrapEmacsFunc "extractIntegerTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 120)) |]
{-# LINE 326 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> IO CIntMax |])

{-# INLINE extractInteger #-}
extractInteger
  :: MonadIO m
  => Env
  -> RawValue p
  -> m CIntMax
extractInteger :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CIntMax
extractInteger = Env -> RawValue p -> m CIntMax
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CIntMax
extractIntegerTH


$(wrapEmacsFunc "makeIntegerTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 128)) |]
{-# LINE 339 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> CIntMax -> IO (RawValue 'Regular) |])

{-# INLINE makeInteger #-}
makeInteger
  :: MonadIO m
  => Env
  -> CIntMax
  -> m (RawValue 'Regular)
makeInteger :: forall (m :: * -> *).
MonadIO m =>
Env -> CIntMax -> m (RawValue 'Regular)
makeInteger = Env -> CIntMax -> m (RawValue 'Regular)
forall (m :: * -> *).
MonadIO m =>
Env -> CIntMax -> m (RawValue 'Regular)
makeIntegerTH


$(wrapEmacsFunc "extractFloatTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 136)) |]
{-# LINE 352 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> IO CDouble |])

{-# INLINE extractFloat #-}
extractFloat
  :: MonadIO m
  => Env
  -> RawValue p
  -> m CDouble
extractFloat :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CDouble
extractFloat = Env -> RawValue p -> m CDouble
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CDouble
extractFloatTH


$(wrapEmacsFunc "makeFloatTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 144)) |]
{-# LINE 365 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> CDouble -> IO (RawValue 'Regular) |])

{-# INLINE makeFloat #-}
makeFloat
  :: MonadIO m
  => Env
  -> CDouble
  -> m (RawValue 'Regular)
makeFloat :: forall (m :: * -> *).
MonadIO m =>
Env -> CDouble -> m (RawValue 'Regular)
makeFloat = Env -> CDouble -> m (RawValue 'Regular)
forall (m :: * -> *).
MonadIO m =>
Env -> CDouble -> m (RawValue 'Regular)
makeFloatTH


$(wrapEmacsFunc "copyStringContentsTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 152)) |]
{-# LINE 378 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> CString -> NonNullPtr CPtrdiff -> IO CBoolean |])

{-# INLINE copyStringContents #-}
-- |  Copy the content of the Lisp string VALUE to BUFFER as an utf8
-- null-terminated string.
--
-- SIZE must point to the total size of the buffer.  If BUFFER is
-- NULL or if SIZE is not big enough, write the required buffer size
-- to SIZE and return true.
--
-- Note that SIZE must include the last null byte (e.g. "abc" needs
-- a buffer of size 4).
--
-- Return true if the string was successfully copied.
copyStringContents
  :: MonadIO m
  => Env
  -> RawValue p          -- ^ Emacs value that holds a string
  -> CString             -- ^ Destination, may be NULL
  -> NonNullPtr CPtrdiff -- ^ SIZE pointer
  -> m CBoolean
copyStringContents :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> CString -> NonNullPtr CPtrdiff -> m CBoolean
copyStringContents = Env -> RawValue p -> CString -> NonNullPtr CPtrdiff -> m CBoolean
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> CString -> NonNullPtr CPtrdiff -> m CBoolean
copyStringContentsTH


$(wrapEmacsFunc "makeStringTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 160)) |]
{-# LINE 404 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> CString -> CPtrdiff -> IO (RawValue 'Regular) |])

{-# INLINE makeString #-}
makeString
  :: MonadIO m
  => Env
  -> CString  -- ^ Utf8-encoded string, may contain null bytes and is
              -- not required to be terminated with one.
  -> CPtrdiff -- ^ Length.
  -> m (RawValue 'Regular)
makeString :: forall (m :: * -> *).
MonadIO m =>
Env -> CString -> CPtrdiff -> m (RawValue 'Regular)
makeString = Env -> CString -> CPtrdiff -> m (RawValue 'Regular)
forall (m :: * -> *).
MonadIO m =>
Env -> CString -> CPtrdiff -> m (RawValue 'Regular)
makeStringTH


$(wrapEmacsFunc "makeUnibyteStringTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 312)) |]
{-# LINE 419 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> CString -> CPtrdiff -> IO (RawValue 'Regular) |])

{-# INLINE makeUnibyteString #-}
makeUnibyteString
  :: MonadIO m
  => Env
  -> CString  -- ^ Any string, may contain anything bytes and is
              -- not required to be terminated with null byte.
  -> CPtrdiff -- ^ Length.
  -> m (RawValue 'Regular)
makeUnibyteString :: forall (m :: * -> *).
MonadIO m =>
Env -> CString -> CPtrdiff -> m (RawValue 'Regular)
makeUnibyteString = Env -> CString -> CPtrdiff -> m (RawValue 'Regular)
forall (m :: * -> *).
MonadIO m =>
Env -> CString -> CPtrdiff -> m (RawValue 'Regular)
makeUnibyteStringTH


$(wrapEmacsFunc "makeUserPtrTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 168)) |]
{-# LINE 434 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall a. Env -> FinalizerPtr a -> Ptr a -> IO (RawValue 'Regular) |])

{-# INLINE makeUserPtr #-}
makeUserPtr
  :: forall m a. MonadIO m
  => Env
  -> FinalizerPtr a
  -> Ptr a
  -> m (RawValue 'Regular)
makeUserPtr :: forall (m :: * -> *) a.
MonadIO m =>
Env -> FinalizerPtr a -> Ptr a -> m (RawValue 'Regular)
makeUserPtr = Env -> FinalizerPtr a -> Ptr a -> m (RawValue 'Regular)
forall (m :: * -> *) a.
MonadIO m =>
Env -> FinalizerPtr a -> Ptr a -> m (RawValue 'Regular)
makeUserPtrTH


$(wrapEmacsFunc "getUserPtrTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 176)) |]
{-# LINE 448 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p a. Env -> RawValue p -> IO (Ptr a) |])

{-# INLINE getUserPtr #-}
getUserPtr
  :: MonadIO m
  => Env
  -> RawValue p
  -> m (Ptr a)
getUserPtr :: forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> m (Ptr a)
getUserPtr = Env -> RawValue p -> m (Ptr a)
forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> m (Ptr a)
getUserPtrTH


$(wrapEmacsFunc "setUserPtrTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 184)) |]
{-# LINE 461 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p a. Env -> RawValue p -> Ptr a -> IO () |])

{-# INLINE setUserPtr #-}
setUserPtr
  :: MonadIO m
  => Env
  -> RawValue p
  -> Ptr a
  -> m ()
setUserPtr :: forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> Ptr a -> m ()
setUserPtr = Env -> RawValue p -> Ptr a -> m ()
forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> Ptr a -> m ()
setUserPtrTH


$(wrapEmacsFunc "getUserFinaliserTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 192)) |]
{-# LINE 475 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p a. Env -> RawValue p -> IO (FinalizerPtr a) |])

{-# INLINE getUserFinaliser #-}
getUserFinaliser
  :: MonadIO m
  => Env
  -> RawValue p
  -> m (FinalizerPtr a)
getUserFinaliser :: forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> m (FinalizerPtr a)
getUserFinaliser = Env -> RawValue p -> m (FinalizerPtr a)
forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> m (FinalizerPtr a)
getUserFinaliserTH


$(wrapEmacsFunc "setUserFinaliserTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 200)) |]
{-# LINE 488 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p a. Env -> RawValue p -> FinalizerPtr a -> IO () |])

{-# INLINE setUserFinaliser #-}
setUserFinaliser
  :: MonadIO m
  => Env
  -> RawValue p
  -> FinalizerPtr a
  -> m ()
setUserFinaliser :: forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> FinalizerPtr a -> m ()
setUserFinaliser = Env -> RawValue p -> FinalizerPtr a -> m ()
forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> FinalizerPtr a -> m ()
setUserFinaliserTH


$(wrapEmacsFunc "vecGetTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 208)) |]
{-# LINE 502 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> CPtrdiff -> IO (RawValue 'Regular) |])

{-# INLINE vecGet #-}
vecGet
  :: MonadIO m
  => Env
  -> RawValue p
  -> CPtrdiff
  -> m (RawValue 'Regular)
vecGet :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> CPtrdiff -> m (RawValue 'Regular)
vecGet = Env -> RawValue p -> CPtrdiff -> m (RawValue 'Regular)
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> CPtrdiff -> m (RawValue 'Regular)
vecGetTH


$(wrapEmacsFunc "vecSetTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 216)) |]
{-# LINE 516 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p1 p2. Env -> RawValue p1 -> CPtrdiff -> RawValue p2 -> IO () |])

{-# INLINE vecSet #-}
vecSet
  :: MonadIO m
  => Env
  -> RawValue p1
  -> CPtrdiff
  -> RawValue p2
  -> m ()
vecSet :: forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> CPtrdiff -> RawValue p2 -> m ()
vecSet = Env -> RawValue p1 -> CPtrdiff -> RawValue p2 -> m ()
forall (m :: * -> *) (p1 :: Pinning) (p2 :: Pinning).
MonadIO m =>
Env -> RawValue p1 -> CPtrdiff -> RawValue p2 -> m ()
vecSetTH


$(wrapEmacsFunc "vecSizeTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 224)) |]
{-# LINE 531 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p. Env -> RawValue p -> IO CPtrdiff |])

{-# INLINE vecSize #-}
vecSize
  :: MonadIO m
  => Env
  -> RawValue p
  -> m CPtrdiff
vecSize :: forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CPtrdiff
vecSize = Env -> RawValue p -> m CPtrdiff
forall (m :: * -> *) (p :: Pinning).
MonadIO m =>
Env -> RawValue p -> m CPtrdiff
vecSizeTH


-- These are mostly of administrative interest.

$(wrapEmacsFunc "setFunctionFinalizerTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 288)) |]
{-# LINE 546 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| forall p a. Env -> RawValue p -> FinalizerPtr a -> IO () |])

{-# INLINE setFunctionFinalizer #-}
setFunctionFinalizer
  :: MonadIO m
  => Env
  -> RawValue p
  -> FinalizerPtr a
  -> m ()
setFunctionFinalizer :: forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> FinalizerPtr a -> m ()
setFunctionFinalizer = Env -> RawValue p -> FinalizerPtr a -> m ()
forall (m :: * -> *) (p :: Pinning) a.
MonadIO m =>
Env -> RawValue p -> FinalizerPtr a -> m ()
setFunctionFinalizerTH

$(wrapEmacsFunc "processInputTH" Unsafe
   [e| ((\hsc_ptr -> peekByteOff hsc_ptr 240)) |]
{-# LINE 559 "src/Data/Emacs/Module/Raw/Env.hsc" #-}
   [t| Env -> IO EnumProcessInputResult |])

{-# INLINE processInput #-}
-- | Processes pending input events and returns whether the module
-- function should quit.
processInput
  :: MonadIO m
  => Env
  -> m EnumProcessInputResult
processInput :: forall (m :: * -> *). MonadIO m => Env -> m EnumProcessInputResult
processInput = Env -> m EnumProcessInputResult
forall (m :: * -> *). MonadIO m => Env -> m EnumProcessInputResult
processInputTH