on master help sign in
Support linking external .o files in new compiler
b49000aEdwin Brady
contribs/lib/SQLite3/sqlexpr.idr+15−15
@@ -66,21 +66,21 @@ data SQL = SELECT SelVar SQL Clause
66 | CREATE SQL (List (Value, ColType , Constr))
66 | CREATE SQL (List (Value, ColType , Constr))
67
67
68-- remember to remove these funcs later
68-- remember to remove these funcs later
69−foldr1 : (a -> a -> a) -> List a -> a
69+-- foldr1 : (a -> a -> a) -> List a -> a
70−foldr1 f [x] = x
70+-- foldr1 f [x] = x
71−foldr1 f (x::xs) = f x (foldr1 f xs)
71+-- foldr1 f (x::xs) = f x (foldr1 f xs)
72−
72+
73−
73+
74−unwords' : List (List Char) -> List Char
74+-- unwords' : List (List Char) -> List Char
75−unwords' [] = []
75+-- unwords' [] = []
76−unwords' ws = (foldr1 addSpace ws)
76+-- unwords' ws = (foldr1 addSpace ws)
77− where
77+-- where
78− addSpace : List Char -> List Char -> List Char
78+-- addSpace : List Char -> List Char -> List Char
79− addSpace w s = w ++ (' ' :: s)
79+-- addSpace w s = w ++ (' ' :: s)
80−
80+--
81−
81+--
82−unwords : List String -> String
82+-- unwords : List String -> String
83−unwords = pack . unwords' . map unpack
83+-- unwords = pack . unwords' . map unpack
84
84
85-----------------------------------------------------------
85-----------------------------------------------------------
86-- | This function replaces values with question mark
86-- | This function replaces values with question mark
contribs/lib/SQLite3/sqlite3api.c+1−1
@@ -267,7 +267,7 @@ const unsigned char* sqlite3_get_val_text(void* p,int nCol){
267 DBinfo* dbi =(DBinfo*) p;
267 DBinfo* dbi =(DBinfo*) p;
268 int rc,i, val, counter;
268 int rc,i, val, counter;
269 const unsigned char* text_val;
269 const unsigned char* text_val;
270− array =(unsigned char *) GC_malloc(1000*sizeof(char));
270+ array =(unsigned char *) malloc(1000*sizeof(char));
271 text_val =sqlite3_column_text(dbi->ppStmt, nCol);
271 text_val =sqlite3_column_text(dbi->ppStmt, nCol);
272 memcpy(array, text_val, strlen(text_val));
272 memcpy(array, text_val, strlen(text_val));
273 return array;
273 return array;
idris.cabal+1−1
@@ -1,5 +1,5 @@
1Name: idris
1Name: idris
2−Version: 0.9.3
2+Version: 0.9.3.1
3License: BSD3
3License: BSD3
4License-file: LICENSE
4License-file: LICENSE
5Author: Edwin Brady
5Author: Edwin Brady
lib/prelude/fin.idr+4
@@ -13,3 +13,7 @@ instance Eq (Fin n) where
13 eq (fS k) (fS k') = eq k k'
13 eq (fS k) (fS k') = eq k k'
14 eq _ _ = False
14 eq _ _ = False
15
15
16+wkn : Fin n -> Fin (S n)
17+wkn fO = fO
18+wkn (fS k) = fS (wkn k)
19+
rts/idris_rts.h+1−1
@@ -72,7 +72,7 @@ typedef void(*func)(VM*, VAL*);
72#define GETPTR(x) (((VAL)(x))->info.ptr)
72#define GETPTR(x) (((VAL)(x))->info.ptr)
73#define GETFLOAT(x) (((VAL)(x))->info.f)
73#define GETFLOAT(x) (((VAL)(x))->info.f)
74
74
75−#define TAG(x) (ISINT(x) ? (-1) : ( (x)->ty == CON ? (x)->info.c.tag : (-1)) )
75+#define TAG(x) (ISINT(x) || x == NULL ? (-1) : ( (x)->ty == CON ? (x)->info.c.tag : (-1)) )
76
76
77// Integers, floats and operators
77// Integers, floats and operators
78
78
src/IRTS/CodegenC.hs+6−3
@@ -22,10 +22,11 @@ codegenC :: [(Name, SDecl)] ->
22 String -> -- output file name
22 String -> -- output file name
23 Bool -> -- generate executable if True, only .o if False
23 Bool -> -- generate executable if True, only .o if False
24 [FilePath] -> -- include files
24 [FilePath] -> -- include files
25+ String -> -- extra object files
25 String -> -- extra compiler flags
26 String -> -- extra compiler flags
26 DbgLevel ->
27 DbgLevel ->
27 IO ()
28 IO ()
28−codegenC defs out exec incs libs dbg
29+codegenC defs out exec incs objs libs dbg
29 = do -- print defs
30 = do -- print defs
30 let bc = map toBC defs
31 let bc = map toBC defs
31 let h = concatMap toDecl (map fst bc)
32 let h = concatMap toDecl (map fst bc)
@@ -38,7 +39,9 @@ codegenC defs out exec incs libs dbg
38 hPutStr tmph cout
39 hPutStr tmph cout
39 hFlush tmph
40 hFlush tmph
40 hClose tmph
41 hClose tmph
41− let gcc = "gcc -x c " ++
42+ let useclang = False
43+ let comp = if useclang then "clang" else "gcc"
44+ let gcc = comp ++ " -I. " ++ objs ++ " -x c " ++
42 (if exec then "" else " - c ") ++
45 (if exec then "" else " - c ") ++
43 gccDbg dbg ++
46 gccDbg dbg ++
44 " " ++ tmpn ++
47 " " ++ tmpn ++
@@ -150,7 +153,7 @@ bcc i (ERROR str) = indent i ++ "fprintf(stderr, " ++ show str ++ "); assert(0);
150
153
151c_irts FInt l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
154c_irts FInt l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
152c_irts FChar l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
155c_irts FChar l x = l ++ "MKINT((i_int)(" ++ x ++ "))"
153−c_irts FString l x = l ++ "MKSTR(" ++ x ++ ")"
156+c_irts FString l x = l ++ "MKSTR(vm, " ++ x ++ ")"
154c_irts FUnit l x = x
157c_irts FUnit l x = x
155c_irts FPtr l x = l ++ "MKPTR(vm, " ++ x ++ ")"
158c_irts FPtr l x = l ++ "MKPTR(vm, " ++ x ++ ")"
156c_irts FDouble l x = l ++ "MKFLOAT(vm, " ++ x ++ ")"
159c_irts FDouble l x = l ++ "MKFLOAT(vm, " ++ x ++ ")"
src/IRTS/Compiler.hs+8−1
@@ -27,6 +27,9 @@ compileC f tm = do checkMVs
27 used <- mapM (allNames []) tmnames
27 used <- mapM (allNames []) tmnames
28 defsIn <- mkDecls tm (concat used)
28 defsIn <- mkDecls tm (concat used)
29 maindef <- irMain tm
29 maindef <- irMain tm
30+ objs <- getObjectFiles
31+ libs <- getLibs
32+ hdrs <- getHdrs
30 let defs = defsIn ++ [(MN 0 "runMain", maindef)]
33 let defs = defsIn ++ [(MN 0 "runMain", maindef)]
31 -- iputStrLn $ showSep "\n" (map show defs)
34 -- iputStrLn $ showSep "\n" (map show defs)
32 let (nexttag, tagged) = addTags 0 (liftAll defs)
35 let (nexttag, tagged) = addTags 0 (liftAll defs)
@@ -36,7 +39,9 @@ compileC f tm = do checkMVs
36 let checked = checkDefs defuns (toAlist defuns)
39 let checked = checkDefs defuns (toAlist defuns)
37 case checked of
40 case checked of
38 OK c -> do -- iputStrLn $ showSep "\n" (map show c)
41 OK c -> do -- iputStrLn $ showSep "\n" (map show c)
39− liftIO $ codegenC c f True [] "" NONE
42+ liftIO $ codegenC c f True hdrs
43+ (concatMap mkObj objs)
44+ (concatMap mkLib libs) NONE
40 Error e -> fail $ show e
45 Error e -> fail $ show e
41 where checkMVs = do i <- get
46 where checkMVs = do i <- get
42 case idris_metavars i \\ primDefs of
47 case idris_metavars i \\ primDefs of
@@ -45,6 +50,8 @@ compileC f tm = do checkMVs
45 inDir d h = do let f = d ++ "/" ++ h
50 inDir d h = do let f = d ++ "/" ++ h
46 ex <- doesFileExist f
51 ex <- doesFileExist f
47 if ex then return f else return h
52 if ex then return f else return h
53+ mkObj f = f ++ " "
54+ mkLib l = "-l" ++ l ++ " "
48
55
49irMain :: TT Name -> Idris LDecl
56irMain :: TT Name -> Idris LDecl
50irMain tm = do i <- ir tm
57irMain tm = do i <- ir tm
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 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)]