module Language.Lean.Internal.Options
( Options
, emptyOptions
, joinOptions
, OptionsPtr
, OutOptionsPtr
, withOptions
) where
import Foreign
import Foreign.C
import System.IO.Unsafe
import Language.Lean.Internal.Exception
import Language.Lean.Internal.Exception.Unsafe
newtype Options = Options (ForeignPtr Options)
withOptions :: Options -> (Ptr Options -> IO a) -> IO a
withOptions (Options o) = withForeignPtr $! o
type OptionsPtr = Ptr (Options)
type OutOptionsPtr = Ptr (OptionsPtr)
foreign import ccall unsafe "&lean_options_del"
lean_options_del_ptr :: FunPtr (OptionsPtr -> IO ())
instance IsLeanValue Options (Ptr Options) where
mkLeanValue = fmap Options . newForeignPtr lean_options_del_ptr
instance Monoid Options where
mempty = emptyOptions
mappend = joinOptions
emptyOptions :: Options
emptyOptions = tryGetLeanValue lean_options_mk_empty
joinOptions :: Options -> Options -> Options
joinOptions x y = tryGetLeanValue $ lean_options_join x y
lean_options_mk_empty :: (OutOptionsPtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_options_mk_empty a1 a2 =
let {a1' = id a1} in
let {a2' = id a2} in
lean_options_mk_empty'_ a1' a2' >>= \res ->
let {res' = toBool res} in
return (res')
lean_options_join :: (Options) -> (Options) -> (OutOptionsPtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_options_join a1 a2 a3 a4 =
(withOptions) a1 $ \a1' ->
(withOptions) a2 $ \a2' ->
let {a3' = id a3} in
let {a4' = id a4} in
lean_options_join'_ a1' a2' a3' a4' >>= \res ->
let {res' = toBool res} in
return (res')
instance Eq Options where
(==) = lean_options_eq
lean_options_eq :: (Options) -> (Options) -> (Bool)
lean_options_eq a1 a2 =
unsafePerformIO $
(withOptions) a1 $ \a1' ->
(withOptions) a2 $ \a2' ->
let {res = lean_options_eq'_ a1' a2'} in
let {res' = toBool res} in
return (res')
instance Show Options where
show = showOption
showOption :: Options -> String
showOption x = tryGetLeanValue $ lean_options_to_string x
lean_options_to_string :: (Options) -> (Ptr CString) -> (OutExceptionPtr) -> IO ((Bool))
lean_options_to_string a1 a2 a3 =
(withOptions) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_options_to_string'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
foreign import ccall unsafe "Language/Lean/Internal/Options.chs.h lean_options_mk_empty"
lean_options_mk_empty'_ :: ((OutOptionsPtr) -> ((OutExceptionPtr) -> (IO CInt)))
foreign import ccall unsafe "Language/Lean/Internal/Options.chs.h lean_options_join"
lean_options_join'_ :: ((OptionsPtr) -> ((OptionsPtr) -> ((OutOptionsPtr) -> ((OutExceptionPtr) -> (IO CInt)))))
foreign import ccall unsafe "Language/Lean/Internal/Options.chs.h lean_options_eq"
lean_options_eq'_ :: ((OptionsPtr) -> ((OptionsPtr) -> CInt))
foreign import ccall unsafe "Language/Lean/Internal/Options.chs.h lean_options_to_string"
lean_options_to_string'_ :: ((OptionsPtr) -> ((Ptr (Ptr CChar)) -> ((OutExceptionPtr) -> (IO CInt))))