ref: 4491fed30b2fceec400a9fd8e4b4349bab180ef6
parent: b35dfd403b5714ad0ba12f7a799318f9c054569c
author: Lennart Augustsson <lennart@augustsson.net>
date: Sun Mar 31 15:42:14 EDT 2024
Move Exn
--- a/TODO
+++ b/TODO
@@ -36,6 +36,8 @@
- implement ForeignPtr with finalizers for this.
* Use finalizers for alloca?
* Better naming of internal identifiers
+* Implement Exception properly
+* GADT syntax
Bugs:
* Missing IO in ccall show wrong location
--- a/ghc/Compat.hs
+++ b/ghc/Compat.hs
@@ -4,7 +4,6 @@
{-# LANGUAGE DataKinds #-}-- Functions for GHC that are defined in the UHS libs.
module Compat(module Compat, Type) where
---import Control.Exception
import Data.Char
import Data.Maybe
--import qualified Control.Monad as M
@@ -54,18 +53,6 @@
padLeft :: Int -> String -> String
padLeft n s = replicate (n - length s) ' ' ++ s
-
-------- Exception --------
-
---newtype Exn = Exn String
--- deriving (Show)
---instance Exception Exn
-
-type Exn = SomeException
-
-exnToString :: Exn -> String
-exnToString = trunc . show
- where trunc = head . lines
------- IO --------
--- /dev/null
+++ b/ghc/Control/Exn.hs
@@ -1,0 +1,9 @@
+module Control.Exn(Exn, exnToString) where
+import Control.Exception
+
+type Exn = SomeException
+
+exnToString :: Exn -> String
+exnToString = trunc . show
+ where trunc = head . lines
+
--- a/lib/AllOfLib.hs
+++ b/lib/AllOfLib.hs
@@ -2,11 +2,11 @@
-- See LICENSE file for full license.
module AllOfLib(main) where
-- Only used to save the compilation cache.
-import Compat
import Control.Applicative
import Control.DeepSeq
import Control.Error
import Control.Exception
+import Control.Exception.Exn
import Control.Monad
import Control.Monad.Fail
import Control.Monad.ST
@@ -91,6 +91,7 @@
import System.IO.MD5
import System.IO.PrintOrRun
import System.IO.Serialize
+import System.IO.TimeMilli
import System.Info
import System.Process
import Text.PrettyPrint.HughesPJ
--- a/lib/Control/Exception.hs
+++ b/lib/Control/Exception.hs
@@ -1,3 +1,5 @@
+-- Copyright 2023 Lennart Augustsson
+-- See LICENSE file for full license.
module Control.Exception(
catch, try,
throwIO,
@@ -7,14 +9,9 @@
SomeException,
) where
import Primitives
-import Prelude
+import Control.Exn
type SomeException = Exn
-
-newtype Exn = Exn String
-
-exnToString :: Exn -> String
-exnToString (Exn s) = s
catch :: forall a . IO a -> (Exn -> IO a) -> IO a
catch ioa hdl = primCatch ioa (hdl . Exn)
--- /dev/null
+++ b/lib/Control/Exn.hs
@@ -1,0 +1,11 @@
+-- Copyright 2024 Lennart Augustsson
+-- See LICENSE file for full license.
+module Control.Exn(Exn(..), exnToString) where
+
+-- Temporary exception type until we get proper exceptions.
+
+newtype Exn = Exn String
+
+exnToString :: Exn -> String
+exnToString (Exn s) = s
+
--- a/lib/Control/Monad.hs
+++ b/lib/Control/Monad.hs
@@ -1,3 +1,5 @@
+-- Copyright 2023 Lennart Augustsson
+-- See LICENSE file for full license.
module Control.Monad(
Functor(..),
Monad(..),
--- a/lib/System/Console/SimpleReadline.hs
+++ b/lib/System/Console/SimpleReadline.hs
@@ -11,7 +11,6 @@
import Control.Monad
import Data.Char
import System.IO
---Ximport Compat
foreign import ccall "GETRAW" c_getRaw :: IO Int
--- a/src/MicroHs/Interactive.hs
+++ b/src/MicroHs/Interactive.hs
@@ -1,7 +1,7 @@
module MicroHs.Interactive(module MicroHs.Interactive) where
-import Prelude
import Data.List
import Control.Exception
+import Control.Exn
import MicroHs.Compile
import MicroHs.CompileCache
import MicroHs.Desugar(LDef)
@@ -15,7 +15,6 @@
import MicroHs.TypeCheck(ValueExport(..), TypeExport(..), TModule(..))
import Unsafe.Coerce
import System.Console.SimpleReadline
-import Compat
import MicroHs.Instances(compiledWithGHC)
type IState = (String, Flags, Cache)
--
⑨