on master help sign in
Make functions work in JS FFI
0011835Edwin Brady
src/IRTS/CodegenJavaScript.hs+10
@@ -1351,6 +1351,14 @@ toAType (FCon i)
1351 | i == sUN "JS_IntNative" = ATInt ITNative
1351 | i == sUN "JS_IntNative" = ATInt ITNative
1352toAType t = error (show t ++ " not defined in toAType")
1352toAType t = error (show t ++ " not defined in toAType")
1353
1353
1354+toFnType (FApp c [_,_,s,t])
1355+ | c == sUN "JS_Fn" = toFnType t
1356+toFnType (FApp c [_,_,r])
1357+ | c == sUN "JS_FnIO" = FFunctionIO
1358+toFnType (FApp c [_,r])
1359+ | c == sUN "JS_FnBase" = FFunction
1360+toFnType t = error (show t ++ " not defined in toFnType")
1361+
1354toFType (FCon c)
1362toFType (FCon c)
1355 | c == sUN "JS_Str" = FString
1363 | c == sUN "JS_Str" = FString
1356 | c == sUN "JS_Float" = FArith ATFloat
1364 | c == sUN "JS_Float" = FArith ATFloat
@@ -1358,5 +1366,7 @@ toFType (FCon c)
1358 | c == sUN "JS_Unit" = FUnit
1366 | c == sUN "JS_Unit" = FUnit
1359toFType (FApp c [_,ity])
1367toFType (FApp c [_,ity])
1360 | c == sUN "JS_IntT" = FArith (toAType ity)
1368 | c == sUN "JS_IntT" = FArith (toAType ity)
1369+toFType (FApp c [_,fty])
1370+ | c == sUN "JS_FnT" = toFnType fty
1361toFType t = error (show t ++ " not yet defined in toFType")
1371toFType t = error (show t ++ " not yet defined in toFType")
1362
1372
src/Idris/Erasure.hs+7−1
@@ -199,8 +199,14 @@ buildDepMap ci ctx mainName = addPostulates $ dfs S.empty M.empty [mainName]
199 , it "MkIO" [2]
199 , it "MkIO" [2]
200 , it "prim__IO" [1]
200 , it "prim__IO" [1]
201
201
202+ -- temporary hacks for preventing erasure of these in foreign
203+ -- calls. TODO: make this not a hack, and possible to set
204+ -- in Idris source
205+ , it "MkJsFn" [1]
206+ , it "MkRaw" [1]
207+
202 , [(pairCon, Arg 2),
208 , [(pairCon, Arg 2),
203− (pairCon, Arg 3)] -- TMP HACK
209+ (pairCon, Arg 3)] -- Used in foreign calls
204
210
205 -- these have been discovered as builtins but are not listed
211 -- these have been discovered as builtins but are not listed
206 -- among Idris.Primitives.primitives
212 -- among Idris.Primitives.primitives