Some nicer death code

This commit is contained in:
Adam Sampson 2006-10-30 23:30:25 +00:00
parent 181a084ab7
commit af9271a48e
2 changed files with 13 additions and 6 deletions

View File

@ -1,12 +1,12 @@
-- Parses across the AST
-- Passes across the AST
--module ASTPasses (astPasses) where
module ASTPasses where
module ASTPasses (astPasses) where
import qualified AST as A
import List
import Data.Generics
import Control.Monad.State
import Metadata
import qualified AST as A
{- FIXME: Passes to add:
calculate types
@ -114,8 +114,7 @@ uniqueNamesPass p = evalState (doAny p) (0, [])
(_, vars) <- get
let s' = case lookup s vars of
Just n -> n
Nothing -> "(not-declared-" ++ s ++ ")"
--Nothing -> error $ "Name " ++ s ++ " not declared before use"
Nothing -> dieP m $ "Name " ++ s ++ " not declared before use"
return $ A.Name m s'
cStyleNamesPass :: A.Process -> A.Process

View File

@ -20,3 +20,11 @@ formatSourcePos m = case findSourcePos m of
Just (SourcePos f l c) -> "<@" ++ show l ++ ":" ++ show c ++ ">"
Nothing -> "<?>"
die :: Monad m => String -> m a
die s = error $ "error: " ++ s
dieP :: Monad m => Meta -> String -> m a
dieP m s = case findSourcePos m of
Just (SourcePos f l c) -> die $ f ++ ":" ++ (show l) ++ ":" ++ (show c) ++ ": " ++ s
Nothing -> die $ "unknown position: " ++ s