summaryrefslogtreecommitdiff
path: root/src/Obs/Abstract.idr
diff options
context:
space:
mode:
authorGreg Brown <greg.brown01@ed.ac.uk>2022-12-18 21:09:33 +0000
committerGreg Brown <greg.brown01@ed.ac.uk>2022-12-18 21:09:33 +0000
commit9452d3aee15b8943684828320324b3da37efb397 (patch)
tree2a003869b12291afed6b01215fb4177bd2d05c0f /src/Obs/Abstract.idr
parentff4c5f15f354aa8da7bb5868d913dbbef23832a3 (diff)
Introduce better logging.
Led to immediate bug fixes for Pi types.
Diffstat (limited to 'src/Obs/Abstract.idr')
-rw-r--r--src/Obs/Abstract.idr26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/Obs/Abstract.idr b/src/Obs/Abstract.idr
index 0915152..90616d4 100644
--- a/src/Obs/Abstract.idr
+++ b/src/Obs/Abstract.idr
@@ -3,6 +3,7 @@ module Obs.Abstract
import Data.Fin
import Data.String
+import Obs.Logging
import Obs.Syntax
import Obs.Term
@@ -11,31 +12,17 @@ import Text.Bounded
%default total
-public export
Context : Nat -> Type
Context n = List (String, Fin n)
bind : Context n -> String -> Context (S n)
bind ctx str = (str, 0) :: map (mapSnd FS) ctx
-Error : Type -> Type
-Error = Either (Bounds, String)
-
-report : Bounds -> String -> Error a
-report = curry Left
-
export
-printErr : Error a -> IO a
-printErr (Left (b, str)) = do
- () <- putStrLn "error: \{show b.startLine}:\{show b.startCol}-\{show b.endLine}:\{show b.endCol}: \{str}"
- exitFailure
-printErr (Right x) = pure x
-
-export
-abstractSyntax : Context n -> Syntax -> Error (Term n)
+abstractSyntax : Context n -> Syntax -> Logging ann (Term n)
abstractSyntax ctx (Var var) = do
let Just i = lookup var.val ctx
- | Nothing => report var.bounds "unbound variable: \{var.val}"
+ | Nothing => inScope "unbound variable" $ fatal var
pure (Var var i)
abstractSyntax ctx (Sort bounds s) = pure (Sort bounds s)
abstractSyntax ctx (Pi bounds var a b) = do
@@ -57,8 +44,7 @@ abstractSyntax ctx (Absurd bounds a t) = do
t <- abstractSyntax ctx t
pure (Absurd bounds a t)
-export
-abstractDefinition : Context n -> Definition -> Error (Definition n)
+abstractDefinition : Context n -> Definition -> Logging ann (Definition n)
abstractDefinition ctx def = pure $ MkDefinition
{ name = def.name
, bounds = def.bounds
@@ -67,12 +53,12 @@ abstractDefinition ctx def = pure $ MkDefinition
}
export
-abstractBlock : (defs : List Definition) -> Error (Block (length defs))
+abstractBlock : (defs : List Definition) -> Logging ann (Block (length defs))
abstractBlock defs =
let asContext : Block n -> Context n
asContext [] = []
asContext (defs :< def) = bind (asContext defs) def.name
- in let helper : Block n -> (defs : List Definition) -> Error (Block (length defs + n))
+ in let helper : Block n -> (defs : List Definition) -> Logging ann (Block (length defs + n))
helper blk [] = pure blk
helper blk (def :: defs) = do
def <- abstractDefinition (asContext blk) def