module Language.Lean.IOS
( IOState
, type IOStateType(..)
, mkStandardIOState
, mkStandardIOStateWithOptions
, mkBufferedIOState
, mkBufferedIOStateWithOptions
, getRegularOutput
, getDiagnosticOutput
, resetRegularOutput
, resetDiagnosticOutput
, IOStateTypeRepr(..)
, stateTypeRepr
, getStateOptions
, setStateOptions
, ppExpr
) where
import Foreign
import Foreign.C
import System.IO.Unsafe
import Unsafe.Coerce (unsafeCoerce)
import Language.Lean.Internal.Decl
import Language.Lean.Internal.Exception
import Language.Lean.Internal.Expr
import Language.Lean.Internal.IOS
import Language.Lean.Internal.Options
mkStandardIOState :: IO (IOState 'Standard)
mkStandardIOState = mkStandardIOStateWithOptions emptyOptions
mkStandardIOStateWithOptions :: Options -> IO (IOState 'Standard)
mkStandardIOStateWithOptions o = tryAllocLeanValue $ lean_ios_mk_std o
lean_ios_mk_std :: (Options) -> (OutSomeIOStatePtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_mk_std a1 a2 a3 =
(withOptions) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_ios_mk_std'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
mkBufferedIOState :: IO (IOState 'Buffered)
mkBufferedIOState = mkBufferedIOStateWithOptions emptyOptions
mkBufferedIOStateWithOptions :: Options -> IO (IOState 'Buffered)
mkBufferedIOStateWithOptions o = tryAllocLeanValue $ lean_ios_mk_buffered o
lean_ios_mk_buffered :: (Options) -> (OutSomeIOStatePtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_mk_buffered a1 a2 a3 =
(withOptions) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_ios_mk_buffered'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
getRegularOutput :: IOState 'Buffered -> IO String
getRegularOutput s = tryAllocLeanValue $ lean_ios_get_regular s
lean_ios_get_regular :: (BufferedIOState) -> (Ptr CString) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_get_regular a1 a2 a3 =
(withBufferedIOState) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_ios_get_regular'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
resetRegularOutput :: IOState 'Buffered -> IO ()
resetRegularOutput s = runLeanPartialAction $ lean_ios_reset_regular s
lean_ios_reset_regular :: (BufferedIOState) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_reset_regular a1 a2 =
(withBufferedIOState) a1 $ \a1' ->
let {a2' = id a2} in
lean_ios_reset_regular'_ a1' a2' >>= \res ->
let {res' = toBool res} in
return (res')
getDiagnosticOutput :: IOState 'Buffered -> IO String
getDiagnosticOutput s = tryAllocLeanValue $ lean_ios_get_diagnostic s
lean_ios_get_diagnostic :: (BufferedIOState) -> (Ptr CString) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_get_diagnostic a1 a2 a3 =
(withBufferedIOState) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_ios_get_diagnostic'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
resetDiagnosticOutput :: IOState 'Buffered -> IO ()
resetDiagnosticOutput s = runLeanPartialAction $ lean_ios_reset_diagnostic s
lean_ios_reset_diagnostic :: (BufferedIOState) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_reset_diagnostic a1 a2 =
(withBufferedIOState) a1 $ \a1' ->
let {a2' = id a2} in
lean_ios_reset_diagnostic'_ a1' a2' >>= \res ->
let {res' = toBool res} in
return (res')
data IOStateTypeRepr (tp :: IOStateType) where
StandardRepr :: IOStateTypeRepr 'Standard
BufferedRepr :: IOStateTypeRepr 'Buffered
deriving instance Show (IOStateTypeRepr tp)
stateTypeRepr :: IOState tp -> IOStateTypeRepr tp
stateTypeRepr s
| lean_ios_is_std (someIOS s) = unsafeCoerce StandardRepr
| otherwise = unsafeCoerce BufferedRepr
lean_ios_is_std :: (SomeIOState) -> (Bool)
lean_ios_is_std a1 =
unsafePerformIO $
(withSomeIOState) a1 $ \a1' ->
let {res = lean_ios_is_std'_ a1'} in
let {res' = toBool res} in
return (res')
getStateOptions :: IOState tp -> IO Options
getStateOptions ios = tryAllocLeanValue $ lean_ios_get_options (someIOS ios)
lean_ios_get_options :: (SomeIOState) -> (OutOptionsPtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_get_options a1 a2 a3 =
(withSomeIOState) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_ios_get_options'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
setStateOptions :: IOState tp -> Options -> IO ()
setStateOptions ios ops = runLeanPartialAction $ lean_ios_set_options (someIOS ios) ops
lean_ios_set_options :: (SomeIOState) -> (Options) -> (OutExceptionPtr) -> IO ((Bool))
lean_ios_set_options a1 a2 a3 =
(withSomeIOState) a1 $ \a1' ->
(withOptions) a2 $ \a2' ->
let {a3' = id a3} in
lean_ios_set_options'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
ppExpr :: Env -> IOState tp -> Expr -> IO String
ppExpr env s e = tryAllocLeanValue $ lean_expr_to_pp_string env (someIOS s) e
lean_expr_to_pp_string :: (Env) -> (SomeIOState) -> (Expr) -> (Ptr CString) -> (OutExceptionPtr) -> IO ((Bool))
lean_expr_to_pp_string a1 a2 a3 a4 a5 =
(withEnv) a1 $ \a1' ->
(withSomeIOState) a2 $ \a2' ->
(withExpr) a3 $ \a3' ->
let {a4' = id a4} in
let {a5' = id a5} in
lean_expr_to_pp_string'_ a1' a2' a3' a4' a5' >>= \res ->
let {res' = toBool res} in
return (res')
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_mk_std"
lean_ios_mk_std'_ :: ((OptionsPtr) -> ((OutSomeIOStatePtr) -> ((OutExceptionPtr) -> (IO CInt))))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_mk_buffered"
lean_ios_mk_buffered'_ :: ((OptionsPtr) -> ((OutSomeIOStatePtr) -> ((OutExceptionPtr) -> (IO CInt))))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_get_regular"
lean_ios_get_regular'_ :: ((Ptr (SomeIOState)) -> ((Ptr (Ptr CChar)) -> ((OutExceptionPtr) -> (IO CInt))))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_reset_regular"
lean_ios_reset_regular'_ :: ((Ptr (SomeIOState)) -> ((OutExceptionPtr) -> (IO CInt)))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_get_diagnostic"
lean_ios_get_diagnostic'_ :: ((Ptr (SomeIOState)) -> ((Ptr (Ptr CChar)) -> ((OutExceptionPtr) -> (IO CInt))))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_reset_diagnostic"
lean_ios_reset_diagnostic'_ :: ((Ptr (SomeIOState)) -> ((OutExceptionPtr) -> (IO CInt)))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_is_std"
lean_ios_is_std'_ :: ((Ptr (SomeIOState)) -> CInt)
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_get_options"
lean_ios_get_options'_ :: ((Ptr (SomeIOState)) -> ((OutOptionsPtr) -> ((OutExceptionPtr) -> (IO CInt))))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_ios_set_options"
lean_ios_set_options'_ :: ((Ptr (SomeIOState)) -> ((OptionsPtr) -> ((OutExceptionPtr) -> (IO CInt))))
foreign import ccall unsafe "Language/Lean/IOS.chs.h lean_expr_to_pp_string"
lean_expr_to_pp_string'_ :: ((EnvPtr) -> ((Ptr (SomeIOState)) -> ((ExprPtr) -> ((Ptr (Ptr CChar)) -> ((OutExceptionPtr) -> (IO CInt))))))