| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Primitive System.Exit simple bindings to Haskell functions |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible #-} |
| 8 |
|
| 9 |
module System.Exit.Primitive where |
| 10 |
|
| 11 |
open import Agda.Builtin.Int using (Int) |
| 12 |
open import Agda.Builtin.IO using (IO) |
| 13 |
|
| 14 |
data ExitCode : Set where |
| 15 |
ExitSuccess : ExitCode |
| 16 |
ExitFailure : Int → ExitCode |
| 17 |
|
| 18 |
{-# FOREIGN GHC data AgdaExitCode = AgdaExitSuccess | AgdaExitFailure Integer #-} |
| 19 |
{-# COMPILE GHC ExitCode = data AgdaExitCode (AgdaExitSuccess | AgdaExitFailure) #-} |
| 20 |
|
| 21 |
{-# FOREIGN GHC import qualified System.Exit as SE #-} |
| 22 |
|
| 23 |
{-# FOREIGN GHC |
| 24 |
toExitCode :: AgdaExitCode -> SE.ExitCode |
| 25 |
toExitCode AgdaExitSuccess = SE.ExitSuccess |
| 26 |
toExitCode (AgdaExitFailure n) = SE.ExitFailure (fromIntegral n) |
| 27 |
|
| 28 |
fromExitCode :: SE.ExitCode -> AgdaExitCode |
| 29 |
fromExitCode SE.ExitSuccess = AgdaExitSuccess |
| 30 |
fromExitCode (SE.ExitFailure n) = AgdaExitFailure (fromIntegral n) |
| 31 |
#-} |
| 32 |
|
| 33 |
postulate |
| 34 |
exitWith : ∀ {a} {A : Set a} → ExitCode → IO A |
| 35 |
|
| 36 |
{-# COMPILE GHC exitWith = \ _ _ -> SE.exitWith . toExitCode #-} |