on master help sign in
Added --dumpc flag
4ff3b25Edwin Brady
CHANGELOG+3
@@ -4,10 +4,13 @@ New in 0.9.4:
4User visible changes:
4User visible changes:
5
5
6* Simple packaging system
6* Simple packaging system
7+* Added --dumpc flag for displaying generated code
7
8
8Internal changes:
9Internal changes:
9
10
10* Improve overloading resolution (especially where this is a type error)
11* Improve overloading resolution (especially where this is a type error)
12+* Various important bug fixes with evaluation and compilation
13+* More aggressive compile-time evaluation
11
14
12New in 0.9.3:
15New in 0.9.3:
13-------------
16-------------
src/IRTS/CodegenC.hs+7−4
@@ -16,7 +16,8 @@ import Control.Monad
16
16
17data DbgLevel = NONE | DEBUG | TRACE
17data DbgLevel = NONE | DEBUG | TRACE
18
18
19+codegenC :: Maybe FilePath -> -- dump output
19−codegenC :: [(Name, SDecl)] ->
20+ [(Name, SDecl)] ->
20 String -> -- output file name
21 String -> -- output file name
21 Bool -> -- generate executable if True, only .o if False
22 Bool -> -- generate executable if True, only .o if False
22 [FilePath] -> -- include files
23 [FilePath] -> -- include files
@@ -24,7 +25,7 @@ codegenC :: [(Name, SDecl)] ->
24 String -> -- extra compiler flags
25 String -> -- extra compiler flags
25 DbgLevel ->
26 DbgLevel ->
26 IO ()
27 IO ()
27−codegenC defs out exec incs objs libs dbg
28+codegenC dump defs out exec incs objs libs dbg
28 = do -- print defs
29 = do -- print defs
29 let bc = map toBC defs
30 let bc = map toBC defs
30 let h = concatMap toDecl (map fst bc)
31 let h = concatMap toDecl (map fst bc)
@@ -45,12 +46,14 @@ codegenC defs out exec incs objs libs dbg
45 " " ++ tmpn ++
46 " " ++ tmpn ++
46 " `idris --link` `idris --include` " ++ libs ++
47 " `idris --link` `idris --include` " ++ libs ++
47 " -o " ++ out
48 " -o " ++ out
48− -- putStrLn cout
49+ case dump of
50+ Just co -> do writeFile co cout
51+ Nothing -> return ()
49 exit <- system gcc
52 exit <- system gcc
50 when (exit /= ExitSuccess) $
53 when (exit /= ExitSuccess) $
51 putStrLn ("FAILURE: " ++ gcc)
54 putStrLn ("FAILURE: " ++ gcc)
52
55
53−headers [] = "#include <idris_rts.h>\n#include <idris_stdfgn.h>\n#include<assert.h>\n"
56+headers [] = "#include <idris_rts.h>\n#include <idris_stdfgn.h>\n#include <assert.h>\n"
54headers (x : xs) = "#include <" ++ x ++ ">\n" ++ headers xs
57headers (x : xs) = "#include <" ++ x ++ ">\n" ++ headers xs
55
58
56debug TRACE = "#define IDRIS_TRACE\n\n"
59debug TRACE = "#define IDRIS_TRACE\n\n"
src/IRTS/Compiler.hs+2−1
@@ -46,9 +46,10 @@ compile target f tm
46
46
47 -- iputStrLn $ showSep "\n" (map show (toAlist defuns))
47 -- iputStrLn $ showSep "\n" (map show (toAlist defuns))
48 let checked = checkDefs defuns (toAlist defuns)
48 let checked = checkDefs defuns (toAlist defuns)
49+ dumpC <- getDumpC
49 case checked of
50 case checked of
50 OK c -> case target of
51 OK c -> case target of
51− ViaC -> liftIO $ codegenC c f True hdrs
52+ ViaC -> liftIO $ codegenC dumpC c f True hdrs
52 (concatMap mkObj objs)
53 (concatMap mkObj objs)
53 (concatMap mkLib libs) NONE
54 (concatMap mkLib libs) NONE
54 ViaJava -> liftIO $ codegenJava c f
55 ViaJava -> liftIO $ codegenJava c f
src/IRTS/LParser.hs+1−1
@@ -54,7 +54,7 @@ fovm f = do defs <- parseFOVM f
54 let checked = checkDefs defuns (toAlist defuns)
54 let checked = checkDefs defuns (toAlist defuns)
55-- print checked
55-- print checked
56 case checked of
56 case checked of
57− OK c -> codegenC c "a.out" True ["math.h"] "" "" TRACE
57+ OK c -> codegenC Nothing c "a.out" True ["math.h"] "" "" TRACE
58 Error e -> fail $ show e
58 Error e -> fail $ show e
59
59
60parseFOVM :: FilePath -> IO [(Name, LDecl)]
60parseFOVM :: FilePath -> IO [(Name, LDecl)]
src/Idris/AbsSyntax.hs+12
@@ -194,6 +194,18 @@ setLogLevel l = do i <- get
194 let opt' = opts { opt_logLevel = l }
194 let opt' = opts { opt_logLevel = l }
195 put (i { idris_options = opt' } )
195 put (i { idris_options = opt' } )
196
196
197+setCmdLine :: [Opt] -> Idris ()
198+setCmdLine opts = do i <- get
199+ let iopts = idris_options i
200+ put (i { idris_options = iopts { opt_cmdline = opts } })
201+
202+getDumpC :: Idris (Maybe FilePath)
203+getDumpC = do i <- get
204+ return $ findC (opt_cmdline (idris_options i))
205+ where findC [] = Nothing
206+ findC (DumpC x : _) = Just x
207+ findC (_ : xs) = findC xs
208+
197logLevel :: Idris Int
209logLevel :: Idris Int
198logLevel = do i <- get
210logLevel = do i <- get
199 return (opt_logLevel (idris_options i))
211 return (opt_logLevel (idris_options i))
src/Idris/AbsSyntaxTree.hs+4−2
@@ -31,11 +31,12 @@ data IOption = IOption { opt_logLevel :: Int,
31 opt_repl :: Bool,
31 opt_repl :: Bool,
32 opt_verbose :: Bool,
32 opt_verbose :: Bool,
33 opt_ibcsubdir :: FilePath,
33 opt_ibcsubdir :: FilePath,
34− opt_importdirs :: [FilePath]
34+ opt_importdirs :: [FilePath],
35+ opt_cmdline :: [Opt] -- remember whole command line
35 }
36 }
36 deriving (Show, Eq)
37 deriving (Show, Eq)
37
38
38−defaultOpts = IOption 0 False False True False False True True "" []
39+defaultOpts = IOption 0 False False True False False True True "" [] []
39
40
40-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
41-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
41-- without typechecking).
42-- without typechecking).
@@ -171,6 +172,7 @@ data Opt = Filename String
171 | WarnOnly
172 | WarnOnly
172 | Pkg String
173 | Pkg String
173 | BCAsm String
174 | BCAsm String
175+ | DumpC String
174 | FOVM String
176 | FOVM String
175 deriving (Show, Eq)
177 deriving (Show, Eq)
176
178
src/Idris/REPL.hs+2
@@ -392,6 +392,7 @@ parseArgs ("--install":n:ns) = PkgInstall n : (parseArgs ns)
392parseArgs ("--clean":n:ns) = PkgClean n : (parseArgs ns)
392parseArgs ("--clean":n:ns) = PkgClean n : (parseArgs ns)
393parseArgs ("--bytecode":n:ns) = NoREPL : BCAsm n : (parseArgs ns)
393parseArgs ("--bytecode":n:ns) = NoREPL : BCAsm n : (parseArgs ns)
394parseArgs ("--fovm":n:ns) = NoREPL : FOVM n : (parseArgs ns)
394parseArgs ("--fovm":n:ns) = NoREPL : FOVM n : (parseArgs ns)
395+parseArgs ("--dumpc":n:ns) = DumpC n : (parseArgs ns)
395parseArgs (n:ns) = Filename n : (parseArgs ns)
396parseArgs (n:ns) = Filename n : (parseArgs ns)
396
397
397help =
398help =
@@ -434,6 +435,7 @@ idrisMain opts =
434 let pkgdirs = opt getPkgDir opts
435 let pkgdirs = opt getPkgDir opts
435 setREPL runrepl
436 setREPL runrepl
436 setVerbose runrepl
437 setVerbose runrepl
438+ setCmdLine opts
437 when (Verbose `elem` opts) $ setVerbose True
439 when (Verbose `elem` opts) $ setVerbose True
438 mapM_ makeOption opts
440 mapM_ makeOption opts
439 -- if we have the --fovm flag, drop into the first order VM testing
441 -- if we have the --fovm flag, drop into the first order VM testing
src/Main.hs+1
@@ -80,6 +80,7 @@ usagemsg = "Idris version " ++ ver ++ "\n" ++
80 "\t--noprelude Don't import the prelude\n" ++
80 "\t--noprelude Don't import the prelude\n" ++
81 "\t--typeintype Disable universe checking\n" ++
81 "\t--typeintype Disable universe checking\n" ++
82 "\t--log [level] Set debugging log level\n" ++
82 "\t--log [level] Set debugging log level\n" ++
83+ "\t--dumpc [file] Dump generated C code\n" ++
83 "\t--libdir Show library install directory and exit\n" ++
84 "\t--libdir Show library install directory and exit\n" ++
84 "\t--link Show C library directories and exit (for C linking)\n" ++
85 "\t--link Show C library directories and exit (for C linking)\n" ++
85 "\t--include Show C include directories and exit (for C linking)\n"
86 "\t--include Show C include directories and exit (for C linking)\n"