forked from knrafto/blc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblc.hs
More file actions
36 lines (30 loc) · 724 Bytes
/
blc.hs
File metadata and controls
36 lines (30 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Main where
import Control.Monad
import Data.Foldable (toList)
import System.Environment
import System.Exit
import System.IO
import Language.BLC.Compile
import Language.BLC.Core
main :: IO ()
main = do
args <- getArgs
case args of
[file] -> compileAndRun file
_ -> usage
usage :: IO ()
usage = do
hPutStrLn stderr "usage: blc [INPUT]"
exitFailure
ensureClosed :: Expr String -> IO ()
ensureClosed e = unless (null vars) $ do
hPutStrLn stderr "error: unbound variables:"
mapM_ (hPutStrLn stderr) vars
exitFailure
where
vars = toList e
compileAndRun :: FilePath -> IO ()
compileAndRun file = do
e <- compileFile file
ensureClosed e
runIO e