@@ -257,14 +257,16 @@ execApp' env ctxt (EP _ (UN "mkForeign") _) (_:fn:(EHandle h):rest)
257 execApp' env ctxt ioUnit rest
257 execApp' env ctxt ioUnit rest
259execApp' env ctxt (EP _ (UN "mkForeign") _) (_:fn:(EPtr p):rest)
259execApp' env ctxt (EP _ (UN "mkForeign") _) (_:fn:(EPtr p):rest)
260− | Just (FFun "isNull" _ _) <- foreignFromTT fn = let res = if p == nullPtr then 1 else 0 in
260+ | Just (FFun "isNull" _ _) <- foreignFromTT fn = let res = ioWrap . EConstant . I $
261+ if p == nullPtr then 1 else 0
261− execApp' env ctxt (EConstant (I res)) rest
262+ in execApp' env ctxt res rest
263−execApp' env ctxt f@(EP _ (UN "mkForeign") _) args@(ty:fn:xs) | Just (FFun _ argTs retT) <- foreignFromTT fn
264+execApp' env ctxt f@(EP _ (UN "mkForeign") _) args@(ty:fn:xs) | Just (FFun f argTs retT) <- foreignFromTT fn
264 , length xs >= length argTs =
265 , length xs >= length argTs =
265 do res <- stepForeign (ty:fn:take (length argTs) xs)
266 do res <- stepForeign (ty:fn:take (length argTs) xs)
266 case res of
267 case res of
267− Nothing -> fail "Could not call foreign function"
268+ Nothing -> fail $ "Could not call foreign function \"" ++ f ++
269+ "\" with args " ++ show (take (length argTs) xs)
268 Just r -> return (mkEApp r (drop (length argTs) xs))
270 Just r -> return (mkEApp r (drop (length argTs) xs))
269 | otherwise = return (mkEApp f args)
271 | otherwise = return (mkEApp f args)