on master help sign in
Use just-built dynamic RTS during library typecheck
27e3c69David Christiansen
Makefile+2−2
@@ -17,8 +17,8 @@ test:
17 make -C test
17 make -C test
18
18
19relib:
19relib:
20− make -C lib IDRIS=../dist/build/idris/idris clean
20+ make -C lib IDRIS=../dist/build/idris/idris RTS=../dist/build/rts/libidris_rts clean
21− make -C effects IDRIS=../dist/build/idris/idris clean
21+ make -C effects IDRIS=../dist/build/idris/idris DIST=../dist/build clean
22 $(CABAL) install $(CABALFLAGS)
22 $(CABAL) install $(CABALFLAGS)
23
23
24linecount:
24linecount:
Setup.hs+17
@@ -28,8 +28,11 @@ mvn verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "mv
28(<//>) = (Px.</>)
28(<//>) = (Px.</>)
29idrisCmd local = Px.joinPath $ splitDirectories $
29idrisCmd local = Px.joinPath $ splitDirectories $
30 ".." <//> buildDir local <//> "idris" <//> "idris"
30 ".." <//> buildDir local <//> "idris" <//> "idris"
31+rtsDir local = Px.joinPath $ splitDirectories $
32+ ".." <//> buildDir local <//> "rts" <//> "libidris_rts"
31#else
33#else
32idrisCmd local = ".." </> buildDir local </> "idris" </> "idris"
34idrisCmd local = ".." </> buildDir local </> "idris" </> "idris"
35+rtsDir local = ".." </> buildDir local </> "rts" </> "libidris_rts"
33#endif
36#endif
34
37
35cleanStdLib verbosity
38cleanStdLib verbosity
@@ -53,11 +56,13 @@ installStdLib pkg local verbosity copy
53 [ "-C", "lib", "install"
56 [ "-C", "lib", "install"
54 , "TARGET=" ++ idir
57 , "TARGET=" ++ idir
55 , "IDRIS=" ++ icmd
58 , "IDRIS=" ++ icmd
59+ , "RTS=" ++ rtsDir local
56 ]
60 ]
57 make verbosity
61 make verbosity
58 [ "-C", "effects", "install"
62 [ "-C", "effects", "install"
59 , "TARGET=" ++ idir
63 , "TARGET=" ++ idir
60 , "IDRIS=" ++ icmd
64 , "IDRIS=" ++ icmd
65+ , "RTS=" ++ rtsDir local
61 ]
66 ]
62 let idirRts = idir </> "rts"
67 let idirRts = idir </> "rts"
63 putStrLn $ "Installing run time system in " ++ idirRts
68 putStrLn $ "Installing run time system in " ++ idirRts
@@ -65,6 +70,7 @@ installStdLib pkg local verbosity copy
65 [ "-C", "rts", "install"
70 [ "-C", "rts", "install"
66 , "TARGET=" ++ idirRts
71 , "TARGET=" ++ idirRts
67 , "IDRIS=" ++ icmd
72 , "IDRIS=" ++ icmd
73+ , "RTS=" ++ rtsDir local
68 ]
74 ]
69
75
70installJavaLib pkg local verbosity copy version = do
76installJavaLib pkg local verbosity copy version = do
@@ -99,16 +105,25 @@ checkStdLib local verbosity
99 make verbosity
105 make verbosity
100 [ "-C", "lib", "check"
106 [ "-C", "lib", "check"
101 , "IDRIS=" ++ icmd
107 , "IDRIS=" ++ icmd
108+ , "RTS=" ++ rtsDir local
102 ]
109 ]
103 make verbosity
110 make verbosity
104 [ "-C", "effects", "check"
111 [ "-C", "effects", "check"
105 , "IDRIS=" ++ icmd
112 , "IDRIS=" ++ icmd
113+ , "RTS=" ++ rtsDir local
106 ]
114 ]
107 make verbosity
115 make verbosity
108 [ "-C", "rts", "check"
116 [ "-C", "rts", "check"
109 , "IDRIS=" ++ icmd
117 , "IDRIS=" ++ icmd
110 ]
118 ]
111
119
120+buildRTS dir verbosity
121+ = do putStrLn "Building RTS..."
122+ make verbosity
123+ [ "-C", "rts", "build"
124+ , "DIST=../" ++ dir
125+ ]
126+
112checkJavaLib verbosity = mvn verbosity [ "-f", "java" </> "pom.xml", "package" ]
127checkJavaLib verbosity = mvn verbosity [ "-f", "java" </> "pom.xml", "package" ]
113
128
114javaFlag flags =
129javaFlag flags =
@@ -155,6 +170,8 @@ main = do
155 cleanJavaLib verb
170 cleanJavaLib verb
156 , postBuild = \ _ flags _ lbi -> do
171 , postBuild = \ _ flags _ lbi -> do
157 let verb = S.fromFlag $ S.buildVerbosity flags
172 let verb = S.fromFlag $ S.buildVerbosity flags
173+ let distdir = buildDir lbi
174+ buildRTS distdir verb
158 checkStdLib lbi verb
175 checkStdLib lbi verb
159 when (javaFlag $ configFlags lbi) (checkJavaLib verb)
176 when (javaFlag $ configFlags lbi) (checkJavaLib verb)
160 }
177 }
effects/Makefile+3−3
@@ -1,13 +1,13 @@
1
1
2check: .PHONY
2check: .PHONY
3− $(IDRIS) --build effects.ipkg
3+ $(IDRIS) --dynamicrts $(RTS) --build effects.ipkg
4
4
5recheck: clean check
5recheck: clean check
6
6
7install:
7install:
8− $(IDRIS) --install effects.ipkg
8+ $(IDRIS) --dynamicrts $(RTS) --install effects.ipkg
9
9
10clean: .PHONY
10clean: .PHONY
11− $(IDRIS) --clean effects.ipkg
11+ $(IDRIS) --dynamicrts $(RTS) --clean effects.ipkg
12
12
13.PHONY:
13.PHONY:
lib/Makefile+3−3
@@ -1,14 +1,14 @@
1
1
2check: .PHONY
2check: .PHONY
3− $(IDRIS) --build base.ipkg
3+ $(IDRIS) --dynamicrts $(RTS) --build base.ipkg
4
4
5recheck: clean check
5recheck: clean check
6
6
7install:
7install:
8− $(IDRIS) --install base.ipkg
8+ $(IDRIS) --dynamicrts $(RTS) --install base.ipkg
9
9
10clean: .PHONY
10clean: .PHONY
11− $(IDRIS) --clean base.ipkg
11+ $(IDRIS) --dynamicrts $(RTS) --clean base.ipkg
12
12
13linecount: .PHONY
13linecount: .PHONY
14 wc -l *.idr Network/*.idr Language/*.idr Prelude/*.idr Data/*.idr Control/Monad/*.idr Control/*.idr
14 wc -l *.idr Network/*.idr Language/*.idr Prelude/*.idr Data/*.idr Control/Monad/*.idr Control/*.idr
rts/Makefile+5
@@ -20,6 +20,11 @@ $(LIBTARGET) : $(OBJS)
20$(DYLIBTARGET) : $(OBJS)
20$(DYLIBTARGET) : $(OBJS)
21 $(CC) $(CFLAGS) -shared -o $(DYLIBTARGET) $(OBJS)
21 $(CC) $(CFLAGS) -shared -o $(DYLIBTARGET) $(OBJS)
22
22
23+build: $(DYLIBTARGET)
24+ mkdir -p $(DIST)/rts
25+ install $(DYLIBTARGET) $(DIST)/rts
26+
27+
23install : .PHONY
28install : .PHONY
24 mkdir -p $(TARGET)
29 mkdir -p $(TARGET)
25 install $(LIBTARGET) $(DYLIBTARGET) $(HDRS) $(TARGET)
30 install $(LIBTARGET) $(DYLIBTARGET) $(HDRS) $(TARGET)
src/Idris/AbsSyntaxTree.hs+1
@@ -232,6 +232,7 @@ data Opt = Filename String
232 | UseTarget Target
232 | UseTarget Target
233 | OutputTy OutputType
233 | OutputTy OutputType
234 | Extension LanguageExt
234 | Extension LanguageExt
235+ | DynamicRTS FilePath
235 deriving (Show, Eq)
236 deriving (Show, Eq)
236
237
237-- Parsed declarations
238-- Parsed declarations
src/Idris/REPL.hs+5−9
@@ -496,6 +496,7 @@ parseArgs ("--dumpdefuns":n:ns) = DumpDefun n : (parseArgs ns)
496parseArgs ("--dumpcases":n:ns) = DumpCases n : (parseArgs ns)
496parseArgs ("--dumpcases":n:ns) = DumpCases n : (parseArgs ns)
497parseArgs ("--target":n:ns) = UseTarget (parseTarget n) : (parseArgs ns)
497parseArgs ("--target":n:ns) = UseTarget (parseTarget n) : (parseArgs ns)
498parseArgs ("-XTypeProviders":ns) = Extension TypeProviders : (parseArgs ns)
498parseArgs ("-XTypeProviders":ns) = Extension TypeProviders : (parseArgs ns)
499+parseArgs ("--dynamicrts":f:ns) = DynamicRTS f : (parseArgs ns)
499parseArgs (n:ns) = Filename n : (parseArgs ns)
500parseArgs (n:ns) = Filename n : (parseArgs ns)
500
501
501helphead =
502helphead =
@@ -552,15 +553,6 @@ idrisMain opts =
552 [] -> setIBCSubDir ""
553 [] -> setIBCSubDir ""
553 (d:_) -> setIBCSubDir d
554 (d:_) -> setIBCSubDir d
554 setImportDirs importdirs
555 setImportDirs importdirs
555− -- attempt to load the RTS as a shared lib in the interpreter
556− idrisCatch (do rtslib <- lift (getDataFileName $ "rts" </> "libidris_rts")
557− handle <- lift (tryLoadLib rtslib)
558− case handle of
559− Nothing -> return ()
560− Just x -> do i <- getIState
561− let libs = idris_dynamic_libs i
562− putIState $ i { idris_dynamic_libs = x:libs })
563− (\e -> iputStrLn (show e))
564
556
565 addPkgDir "base"
557 addPkgDir "base"
566 mapM_ addPkgDir pkgdirs
558 mapM_ addPkgDir pkgdirs
@@ -645,6 +637,10 @@ getLanguageExt :: Opt -> Maybe LanguageExt
645getLanguageExt (Extension e) = Just e
637getLanguageExt (Extension e) = Just e
646getLanguageExt _ = Nothing
638getLanguageExt _ = Nothing
647
639
640+getDynamicRTS :: Opt -> Maybe FilePath
641+getDynamicRTS (DynamicRTS f) = Just f
642+getDynamicRTS _ = Nothing
643+
648opt :: (Opt -> Maybe a) -> [Opt] -> [a]
644opt :: (Opt -> Maybe a) -> [Opt] -> [a]
649opt = mapMaybe
645opt = mapMaybe
650
646
src/Main.hs+17
@@ -29,6 +29,7 @@ import Idris.Imports
29import Idris.Error
29import Idris.Error
30
30
31import Util.System ( getLibFlags, getIdrisLibDir, getIncFlags )
31import Util.System ( getLibFlags, getIdrisLibDir, getIncFlags )
32+import Util.DynamicLinker
32
33
33import Pkg.Package
34import Pkg.Package
34
35
@@ -48,6 +49,7 @@ runIdris opts = do
48 when (ShowIncs `elem` opts) $ liftIO showIncs
49 when (ShowIncs `elem` opts) $ liftIO showIncs
49 when (ShowLibs `elem` opts) $ liftIO showLibs
50 when (ShowLibs `elem` opts) $ liftIO showLibs
50 when (ShowLibdir `elem` opts) $ liftIO showLibdir
51 when (ShowLibdir `elem` opts) $ liftIO showLibdir
52+ loadRTS opts
51 case opt getPkgClean opts of
53 case opt getPkgClean opts of
52 [] -> return ()
54 [] -> return ()
53 fs -> do liftIO $ mapM_ cleanPkg fs
55 fs -> do liftIO $ mapM_ cleanPkg fs
@@ -94,3 +96,18 @@ usagemsg = "Idris version " ++ ver ++ "\n" ++
94 "\t--link Show C library directories and exit (for C linking)\n" ++
96 "\t--link Show C library directories and exit (for C linking)\n" ++
95 "\t--include Show C include directories and exit (for C linking)\n" ++
97 "\t--include Show C include directories and exit (for C linking)\n" ++
96 "\t--target [target] Type the target: C, Java, bytecode, javascript, node\n"
98 "\t--target [target] Type the target: C, Java, bytecode, javascript, node\n"
99+
100+-- | Attempt to load the RTS as a shared lib in the interpreter
101+loadRTS :: [Opt] -> Idris ()
102+loadRTS opts = (flip idrisCatch) (\e -> iputStrLn (show e)) $
103+ do rtslib <- liftIO $
104+ case listToMaybe . catMaybes . map getDynamicRTS $ opts of
105+ Just path -> return path
106+ Nothing -> getDataFileName ("rts" </> "libidris_rts")
107+ handle <- liftIO (tryLoadLib rtslib)
108+ case handle of
109+ Nothing -> return ()
110+ Just x -> do i <- getIState
111+ let libs = idris_dynamic_libs i
112+ putIState $ i { idris_dynamic_libs = x:libs }
113+