on master help sign in
fix #4656
8882622Rui Barreiro
src/IRTS/JavaScript/Codegen.hs+7−4
@@ -108,22 +108,25 @@ makeExportDecls :: Map Name LDecl -> ExportIFace -> [Text]
108makeExportDecls defs (Export _ _ e) =
108makeExportDecls defs (Export _ _ e) =
109 concatMap makeExport e
109 concatMap makeExport e
110 where
110 where
111− uncurryF name argTy (Just args) =
111+ uncurryF name argTy (Just args) retTy =
112− if length argTy == length args then name
112+ if length argTy == length args then
113+ case (retTy, length args) of
114+ (FIO _, 0) -> T.concat ["function(){return ", name, "()()}"]
115+ _ -> name
113 else T.concat [ "function(){ return "
116 else T.concat [ "function(){ return "
114 , name
117 , name
115 , ".apply(this, Array.prototype.slice.call(arguments, 0,", T.pack $ show $ length args,"))"
118 , ".apply(this, Array.prototype.slice.call(arguments, 0,", T.pack $ show $ length args,"))"
116 , T.concat $ map (\x -> T.concat ["(arguments[", T.pack $ show x , "])"]) [length args .. (length argTy - 1)]
119 , T.concat $ map (\x -> T.concat ["(arguments[", T.pack $ show x , "])"]) [length args .. (length argTy - 1)]
117 , "}"
120 , "}"
118 ]
121 ]
119− uncurryF name argTy Nothing = name
122+ uncurryF name argTy Nothing retTy = name
120
123
121 makeExport (ExportData _) =
124 makeExport (ExportData _) =
122 []
125 []
123 makeExport (ExportFun name (FStr exportname) retTy argTy) =
126 makeExport (ExportFun name (FStr exportname) retTy argTy) =
124 [T.concat [ T.pack $ exportname
127 [T.concat [ T.pack $ exportname
125 , ": "
128 , ": "
126− , uncurryF (jsName name) argTy (getArgList' name defs)
129+ , uncurryF (jsName name) argTy (getArgList' name defs) retTy
127 ]
130 ]
128 ]
131 ]
129
132
test/TestData.hs+1
@@ -140,6 +140,7 @@ testFamiliesData = [
140 , ( 9, C_CG )
140 , ( 9, C_CG )
141 , ( 10, NODE_CG )
141 , ( 10, NODE_CG )
142 , ( 11, NODE_CG )
142 , ( 11, NODE_CG )
143+ , ( 12, NODE_CG )
143 ]),
144 ]),
144 ("folding", "Folding",
145 ("folding", "Folding",
145 [ ( 1, ANY )]),
146 [ ( 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