on master help sign in
Add test for FFI export (ffi006)
commite9c96d40c4a271d46f9fd602ec3fa31df058308c authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSat 7 Mar 2015, 22:04 (12 years ago) parent5ae43bb
6 files changed+56−7
idris.cabal+4 test/Makefile+1−7 test/ffi006/expected+2 test/ffi006/ffi006.c+14 test/ffi006/ffi006.idr+30 test/ffi006/run+5
idris.cabal+4
@@ -394,6 +394,10 @@ Extra-source-files:
394394 test/ffi005/*.idr
395395 test/ffi005/run
396396 test/ffi005/expected
397+ test/ffi006/*.idr
398+ test/ffi006/*.c
399+ test/ffi006/run
400+ test/ffi006/expected
397401
398402 test/idrisdoc001/run
399403 test/idrisdoc001/expected
test/Makefile+1−7
@@ -7,14 +7,8 @@ test: $(TESTS)
77%.test:
88 @perl ./runtest.pl $(patsubst %.test,%,$@)
99
10−test_java:
11− @perl ./runtest.pl without primitives004 --codegen Java
12−
1310test_js:
14− @perl ./runtest.pl without sugar004 reg029 reg052 io001 dsl002 io003 effects001 effects002 effects003 buffer001 basic007 basic011 primitives004 --codegen node
15−
16−test_llvm:
17− @perl ./runtest.pl without primitives003 primitives004 sugar004 io003 buffer001 --codegen llvm
11+ @perl ./runtest.pl without sugar004 reg029 reg052 io001 dsl002 io003 effects001 effects002 effects003 buffer001 basic007 basic011 primitives004 ffi006 --codegen node
1812
1913update:
2014 /usr/bin/env perl ./runtest.pl all -u
test/ffi006/expectednew file+2
@@ -0,0 +1,2 @@
1+Ready to show...
2+[10, 20, 30, 40]
test/ffi006/ffi006.cnew file+14
@@ -0,0 +1,14 @@
1+#include "testHdr.h"
2+
3+int main() {
4+
5+ VM* vm = idris_vm();
6+
7+ ListInt x = cons(vm, 10, cons(vm, 20, nil(vm)));
8+ ListInt y = cons(vm, 30, cons(vm, 40, nil(vm)));
9+ ListInt z = addLists(vm, x, y);
10+
11+ printf("%s\n", showList(vm, z));
12+
13+ close_vm(vm);
14+}
test/ffi006/ffi006.idrnew file+30
@@ -0,0 +1,30 @@
1+import Data.List
2+
3+addLists : List Int -> List Int -> List Int
4+addLists xs ys = xs ++ ys
5+
6+nil : List Int
7+nil = []
8+
9+cons : Int -> List Int -> List Int
10+cons x xs = x :: xs
11+
12+show' : List Int -> IO String
13+show' xs = do putStrLn "Ready to show..."
14+ return (show xs)
15+
16+testList : FFI_Export FFI_C "testHdr.h" []
17+testList = Data (List Int) "ListInt" $
18+ Data (List Nat) "ListNat" $
19+ Fun addLists "addLists" $
20+ Fun nil "nil" $
21+ Fun cons "cons" $
22+ Data Nat "Nat" $
23+ Fun Strings.length "lengthS" $
24+ Fun show' "showList" $
25+ End
26+
27+-- main : IO ()
28+-- main = do s <- show' 42
29+-- putStrLn s
30+
test/ffi006/runnew file+5
@@ -0,0 +1,5 @@
1+#!/usr/bin/env bash
2+idris $@ ffi006.idr --interface -o ffi006.o
3+cc ffi006.c ffi006.o `idris --include` `idris --link` -o ffi006
4+./ffi006
5+rm -f ffi006 *.ibc *.o *.h