Skip to content

Commit 2aa4283

Browse files
committed
wip
1 parent 7bd81f1 commit 2aa4283

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

ghcjs/delivery-calculator/.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
use nix
1+
use flake . --impure

ghcjs/delivery-calculator/flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
}: let
1212
def = import ./default.nix;
1313
vsn = def.vsn;
14+
repo = def.repo;
1415
label = def.label;
1516
supportedSystems = [
1617
"x86_64-linux"
@@ -68,6 +69,9 @@
6869
app-release-latest = pkgs.writeShellApplication {
6970
name = "app-release-latest";
7071
text = ''
72+
export EM_CACHE=~/tmp/emscripten
73+
mkdir -p $EM_CACHE
74+
7175
javascript-unknown-ghcjs-cabal build
7276
out="./dist/latest"
7377
rm -rf "$out"

pub/functora/functora.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ common pkg-prelude
124124
if impl(ghc <9.6.1)
125125
build-depends: foldable1-classes-compat
126126

127+
if arch(javascript)
128+
js-sources: src/js/hashable.js
129+
127130
if ((impl(ghcjs) || arch(javascript)) || os(wasi))
128131
build-depends:
129132
, aeson

pub/functora/src/functora-ghcjs.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ common pkg
134134
if impl(ghc <9.6.1)
135135
build-depends: foldable1-classes-compat
136136

137+
if arch(javascript)
138+
js-sources: js/hashable.js
139+
137140
if (impl(ghcjs) || arch(javascript))
138141
build-depends:
139142
, ghcjs-base

pub/functora/src/js/hashable.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// fixme this function appears to deoptimize a lot due to smallint overflows
2+
function h$imul_shim(a, b) {
3+
var ah = (a >>> 16) & 0xffff;
4+
var al = a & 0xffff;
5+
var bh = (b >>> 16) & 0xffff;
6+
var bl = b & 0xffff;
7+
// the shift by 0 fixes the sign on the high part
8+
// the final |0 converts the unsigned value into a signed value
9+
return (((al * bl) | 0) + (((ah * bl + al * bh) << 16) >>> 0)) | 0;
10+
}
11+
12+
var h$mulInt32 = Math.imul ? Math.imul : h$imul_shim;
13+
14+
/* FNV-1 hash
15+
*
16+
* The FNV-1 hash description: http://isthe.com/chongo/tech/comp/fnv/
17+
* The FNV-1 hash is public domain: http://isthe.com/chongo/tech/comp/fnv/#public_domain
18+
*/
19+
function h$hashable_fnv_hash_offset(str_a, str_o_zero, o, len, hash) {
20+
return h$hashable_fnv_hash(str_a, o, len, hash);
21+
}
22+
23+
function h$hashable_fnv_hash(str_d, str_o, len, hash) {
24+
if (len > 0) {
25+
var d = str_d.u8;
26+
for (var i = 0; i < len; i++) {
27+
hash = h$mulInt32(hash, 16777619) ^ d[str_o + i];
28+
}
29+
}
30+
return hash;
31+
}
32+
33+
// int hashable_getRandomBytes(unsigned char *dest, int nbytes)
34+
function h$hashable_getRandomBytes(dest_d, dest_o, len) {
35+
if (len > 0) {
36+
var d = dest_d.u8;
37+
for (var i = 0; i < len; i++) {
38+
d[dest_o + i] = Math.floor(Math.random() * 256);
39+
}
40+
}
41+
return len;
42+
}

0 commit comments

Comments
 (0)