@@ -10,7 +10,7 @@ import Data.Either (lefts,rights)
1010import Data.List (intercalate,partition)
1111import Parse.Parser (parseProgram, preParse)
1212import Rename
13−import Libraries (libraries)
13+import qualified Libraries as Libs
1414import Types.Types ((-:))
1515import Types.Hints (hints)
1616import Types.Unify
@@ -32,29 +32,30 @@ checkTypes modul =
3232check :: Module -> Either String Module
3333check = checkMistakes >=> checkTypes
3434
35−buildFromSource :: String -> Either String Module
36−buildFromSource src = check =<< parseProgram src
35+buildFromSource :: Bool -> String -> Either String Module
36+buildFromSource withPrelude src = (check . add) =<< (parseProgram src)
37+ where add = if withPrelude then Libs.addPrelude else id
3738
38−build :: FilePath -> IO (Either String [Module])
39−build root = do
39+build :: Bool -> FilePath -> IO (Either String [Module])
40+build withPrelude root = do
4041 names <- getSortedModuleNames root
4142 case names of
4243 Left err -> return (Left err)
4344 Right ns -> do srcs <- zipWithM buildFile' [1..] ns
4445 return (sequence srcs)
4546 where
46− buildFile' n name = putStrLn (msg n name) >> buildFile name
47+ buildFile' n name = putStrLn (msg n name) >> buildFile withPrelude name
4748 msg n name = "["++show n++" of "++show (length ns)++"] Compiling "++name
4849
49−buildFile :: String -> IO (Either String Module)
50−buildFile moduleName =
50+buildFile :: Bool -> String -> IO (Either String Module)
51+buildFile withPrelude moduleName =
5152 let filePath = toFilePath moduleName in
5253 case isNative moduleName of
5354 True -> return (Right $ Module [moduleName] [] [] [])
5455 --return (Left "Can't do that yet")
5556 --Right `liftM` readFile filePath
5657 False -> do txt <- readFile filePath
57− return $ buildFromSource txt
58+ return $ buildFromSource withPrelude txt
5859
5960
6061getSortedModuleNames :: FilePath -> IO (Either String [String])
@@ -87,7 +88,7 @@ readDeps seen root = do
8788 where realDeps = filter (`notElem` builtIns) deps
8889 newDeps = filter (`notElem` seen) realDeps
8990 seen' = root : seen ++ newDeps
90− builtIns = Map.keys libraries
91+ builtIns = Map.keys Libs.libraries
9192
9293isNative name = takeWhile (/='.') name == "Native"
9394toFilePath name = map swapDots name ++ ext