{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Language.R.Globals
( baseEnv
, emptyEnv
, globalEnv
, nilValue
, missingArg
, unboundValue
, isRInteractive
, signalHandlersPtr
#ifndef mingw32_HOST_OS
, inputHandlers
#endif
, pokeRVariables
) where
import Control.Memory.Region
import Control.Monad ((<=<))
import Foreign
( Ptr
, StablePtr
, deRefStablePtr
, newStablePtr
, peek
, poke
)
import Foreign.C.Types (CInt)
import Foreign.R (SEXP)
import qualified Foreign.R as R
#ifndef mingw32_HOST_OS
import qualified Foreign.R.EventLoop as R
#endif
import System.IO.Unsafe (unsafePerformIO)
type RVariables =
( Ptr (SEXP G 'R.Env)
, Ptr (SEXP G 'R.Env)
, Ptr (SEXP G 'R.Env)
, Ptr (SEXP G 'R.Nil)
, Ptr (SEXP G 'R.Symbol)
, Ptr (SEXP G 'R.Symbol)
, Ptr CInt
, Ptr CInt
#ifndef mingw32_HOST_OS
, Ptr (Ptr R.InputHandler)
#endif
)
foreign import ccall "missing_r.h &" rVariables :: Ptr (StablePtr RVariables)
pokeRVariables :: RVariables -> IO ()
pokeRVariables = poke rVariables <=< newStablePtr
( baseEnvPtr
, emptyEnvPtr
, globalEnvPtr
, nilValuePtr
, unboundValuePtr
, missingArgPtr
, isRInteractive
, signalHandlersPtr
#ifndef mingw32_HOST_OS
, inputHandlersPtr
#endif
) = unsafePerformIO $ peek rVariables >>= deRefStablePtr
unboundValue :: SEXP G 'R.Symbol
unboundValue = unsafePerformIO $ peek unboundValuePtr
nilValue :: SEXP G 'R.Nil
nilValue = unsafePerformIO $ peek nilValuePtr
missingArg :: SEXP G 'R.Symbol
missingArg = unsafePerformIO $ peek missingArgPtr
baseEnv :: SEXP G 'R.Env
baseEnv = unsafePerformIO $ peek baseEnvPtr
emptyEnv :: SEXP G 'R.Env
emptyEnv = unsafePerformIO $ peek emptyEnvPtr
globalEnv :: SEXP G 'R.Env
globalEnv = unsafePerformIO $ peek globalEnvPtr
#ifndef mingw32_HOST_OS
inputHandlers :: Ptr R.InputHandler
inputHandlers = unsafePerformIO $ peek inputHandlersPtr
#endif