on master help sign in
Merge pull request #4660 from rbarreiro/issue_4656

fix #4656

commitafd5c9a5cacb90d4e13084e131c3065b0c214f8d authorNiklas Larsson <metaniklas@gmail.com> dateWed 27 Feb 2019, 01:10 (8 years ago) parentf59d33d8882622
6 files changed+30−4
src/IRTS/JavaScript/Codegen.hs+7−4 test/TestData.hs+1 test/ffi012/expected+1 test/ffi012/ffi012+3 test/ffi012/ffi012.idr+14 test/ffi012/run+4
src/IRTS/JavaScript/Codegen.hs+7−4
@@ -108,22 +108,25 @@ makeExportDecls :: Map Name LDecl -> ExportIFace -> [Text]
108108makeExportDecls defs (Export _ _ e) =
109109 concatMap makeExport e
110110 where
111− uncurryF name argTy (Just args) =
112− if length argTy == length args then name
111+ uncurryF name argTy (Just args) retTy =
112+ if length argTy == length args then
113+ case (retTy, length args) of
114+ (FIO _, 0) -> T.concat ["function(){return ", name, "()()}"]
115+ _ -> name
113116 else T.concat [ "function(){ return "
114117 , name
115118 , ".apply(this, Array.prototype.slice.call(arguments, 0,", T.pack $ show $ length args,"))"
116119 , T.concat $ map (\x -> T.concat ["(arguments[", T.pack $ show x , "])"]) [length args .. (length argTy - 1)]
117120 , "}"
118121 ]
119− uncurryF name argTy Nothing = name
122+ uncurryF name argTy Nothing retTy = name
120123
121124 makeExport (ExportData _) =
122125 []
123126 makeExport (ExportFun name (FStr exportname) retTy argTy) =
124127 [T.concat [ T.pack $ exportname
125128 , ": "
126− , uncurryF (jsName name) argTy (getArgList' name defs)
129+ , uncurryF (jsName name) argTy (getArgList' name defs) retTy
127130 ]
128131 ]
129132
test/TestData.hs+1
@@ -140,6 +140,7 @@ testFamiliesData = [
140140 , ( 9, C_CG )
141141 , ( 10, NODE_CG )
142142 , ( 11, NODE_CG )
143+ , ( 12, NODE_CG )
143144 ]),
144145 ("folding", "Folding",
145146 [ ( 1, ANY )]),
test/ffi012/expectednew file+1
@@ -0,0 +1 @@
1+Hello?
test/ffi012/ffi012new file+3
@@ -0,0 +1,3 @@
1+l = require("./lib.js");
2+
3+l.f()
test/ffi012/ffi012.idrnew file+14
@@ -0,0 +1,14 @@
1+module Main
2+
3+export
4+f : JS_IO ()
5+f = do
6+ let res = ()
7+ let res2 = res
8+ let res3 = res
9+ putStrLn' "Hello?"
10+
11+lib : FFI_Export FFI_JS "" []
12+lib =
13+ Fun f "f" $
14+ End
test/ffi012/runnew file+4
@@ -0,0 +1,4 @@
1+#!/usr/bin/env bash
2+${IDRIS:-idris} $@ ffi012.idr --interface -o lib.js
3+node ./ffi012
4+rm -f *.ibc lib.js