diff options
author | Josh Meredith <joshmeredith2008@gmail.com> | 2023-05-08 14:51:54 +0000 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2023-05-17 11:43:34 -0400 |
commit | 6c5fcaba04c122c68c16703c2d8349b9cd68f7d2 (patch) | |
tree | 7f91b56611e5ed81d444eff2258444069823c254 | |
parent | 5292bdf87f1a6e5a48375beb3cdea6785a2fecbd (diff) | |
download | haskell-6c5fcaba04c122c68c16703c2d8349b9cd68f7d2.tar.gz |
JS: Implement h$clock_gettime in the JavaScript RTS (#23360)
(cherry picked from commit 5e3f9bb57680a40f6a9531e41dc2617c5f028e5c)
-rw-r--r-- | libraries/base/tests/Concurrent/all.T | 2 | ||||
-rw-r--r-- | rts/js/time.js | 20 | ||||
-rw-r--r-- | rts/rts.cabal.in | 1 |
3 files changed, 22 insertions, 1 deletions
diff --git a/libraries/base/tests/Concurrent/all.T b/libraries/base/tests/Concurrent/all.T index 05fdf1d303..f8826a08d3 100644 --- a/libraries/base/tests/Concurrent/all.T +++ b/libraries/base/tests/Concurrent/all.T @@ -1,3 +1,3 @@ test('Chan002', extra_run_opts('100'), compile_and_run, ['']) test('Chan003', extra_run_opts('200'), compile_and_run, ['']) -test('ThreadDelay001', js_broken(22374), compile_and_run, ['']) +test('ThreadDelay001', normal, compile_and_run, ['']) diff --git a/rts/js/time.js b/rts/js/time.js new file mode 100644 index 0000000000..0ea6be1f54 --- /dev/null +++ b/rts/js/time.js @@ -0,0 +1,20 @@ +function h$clock_gettime(when, p_d, p_o) { + var is64 = p_d.i3.length == 4 && p_o == 0; + var o = p_o >> 2; + var t = Date.now ? Date.now() : new Date().getTime(); + var tf = Math.floor(t / 1000); + var tn = 1000000 * (t - (1000 * tf)); + + if (is64) { + p_d.i3[o] = tf|0; + p_d.i3[o+1] = 0; + p_d.i3[o+2] = tn|0; + p_d.i3[o+3] = 0; + } else { + p_d.i3[o] = tf|0; + p_d.i3[o+1] = tn|0; + } + return 0; +} + +function h$CLOCK_REALTIME() { return 0; } diff --git a/rts/rts.cabal.in b/rts/rts.cabal.in index e3f7c4a9b7..fa29674bfe 100644 --- a/rts/rts.cabal.in +++ b/rts/rts.cabal.in @@ -99,6 +99,7 @@ library js/verify.js js/weak.js js/globals.js + js/time.js install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h |