Skip to content

Commit

Permalink
Generate ".inch" file with type signatures and datatype declarations
Browse files Browse the repository at this point in the history
Ignore-this: 35d00c133e9f023bb73118c332b337c7

darcs-hash:20111021092259-e29d1-f7cafbbbae33cd095f9fc6f70d50b4d5af240ab7.gz
  • Loading branch information
adamgundry committed Oct 21, 2011
1 parent 9e9cf5b commit 34899b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion inch.cabal
Expand Up @@ -30,7 +30,8 @@ Executable inch
presburger == 0.3.*,
pretty == 1.0.*,
mtl == 2.0.*,
containers == 0.4.*
containers == 0.4.*,
filepath == 1.2.*
Other-modules: Language.Inch.BwdFwd,
Language.Inch.Check,
Language.Inch.Context
Expand Down
16 changes: 13 additions & 3 deletions src/Language/Inch/Main.lhs
Expand Up @@ -3,7 +3,9 @@
> import Control.Monad.State
> import System.Environment
> import System.Exit
> import System.FilePath

> import Language.Inch.Syntax
> import Language.Inch.Parser
> import Language.Inch.PrettyPrinter
> import Language.Inch.ProgramCheck
Expand All @@ -19,19 +21,27 @@
> [original, input, output] -> do
> s <- readFile input
> case preprocess original s of
> Right z -> writeFile output z
> Right (y, z) -> do
> writeFile (replaceExtension original ".inch") y
> writeFile output z
> Left s -> putStrLn (me ++ " " ++ s) >> exitFailure
> _ -> putStrLn $ help me


> modHeader Nothing = ""
> modHeader (Just m) = "module " ++ m ++ " where\n"

> preprocess :: String -> String -> Either String String
> preprocess :: String -> String -> Either String (String, String)
> preprocess fn s = case parseProgram fn s of
> Right (p, mn) -> case runCheckProg p of
> Right (p', st) -> case runStateT (eraseProg p') st of
> Right (p'', st) -> Right $ modHeader mn ++ show (prettyProgram p'')
> Right (p'', st) -> Right (sigs p', erased)
> where
> sigs = show . prettyProgram . filter dataOrSigDecl
> dataOrSigDecl (SigDecl _ _) = True
> dataOrSigDecl (DataDecl _ _ _) = True
> dataOrSigDecl (FunDecl _ _) = False
> erased = modHeader mn ++ show (prettyProgram p'')
> Left err -> Left $ "erase error:\n" ++ renderMe err ++ "\n"

> Left err -> Left $ "type-checking failed:\n"
Expand Down

0 comments on commit 34899b6

Please sign in to comment.