在GHCJS下,如何getCurrentTime运作?在time库本身中,这是使用FFI实现的,调用操作系统提供的功能.但是,time开头没有任何行:
foreign import javascript ...
Run Code Online (Sandbox Code Playgroud)
我检查了shimsGHCJS用来修补库的存储库.它修补了时区获取功能,但没有提及getCurrentTime.我发现的唯一远程关闭的东西是在ghcjs-boot哪里old-time修补:
#ifdef ghcjs_HOST_OS
type CTimeVal = ()
type CTimeZone = ()
...
foreign import ccall unsafe "HsTime.h __hscore_gettimeofday"
gettimeofday :: Ptr CTimeVal -> Ptr CTimeZone -> IO CInt
...
Run Code Online (Sandbox Code Playgroud)
但是这有两个问题.一个是它不是正确的库(old-time而不是time).另一个是它仍在使用C FFI.我不明白在使用GHCJS进行编译时如何使用C FFI.
那么,哪里getCurrentTime可以为GHCJS填充?
在回复关于grepping ghcjs源的评论时,如果我getTime在GHCJS的源代码中搜索(我相信这将是使用的javascript函数),我基本上什么也得不到.但是,通过all.jsgreping GHCJS为使用的项目生成的文件getCurrentTime,我得到:
ag '\bgetTime\b' all.js
20948: h$log((("elapsed time: " + (h$RTS_597.getTime() - h$RTS_595.getTime())) + "ms"));
22863: var atime = goog.math.Long.fromNumber(fs.atime.getTime());
22864: var mtime = goog.math.Long.fromNumber(fs.mtime.getTime());
22865: var ctime = goog.math.Long.fromNumber(fs.ctime.getTime());
Run Code Online (Sandbox Code Playgroud)
后三者来自某种文件系统垫片.
我在生成的javascript中找到了这个:
function h$gettimeofday(tv_v,tv_o,tz_v,tz_o) {
var now = Date.now();
tv_v.dv.setInt32(tv_o, (now / 1000)|0, true);
tv_v.dv.setInt32(tv_o + 4, ((now % 1000) * 1000)|0, true);
if(tv_v.len >= tv_o + 12) {
tv_v.dv.setInt32(tv_o + 8, ((now % 1000) * 1000)|0, true);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是如何将其联系起来的问题仍然存在.