Skip to content

Commit

Permalink
Merge branch 'main' into anmonteiro/rm-rescript-references
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Aug 11, 2023
2 parents 3a4a43b + 7af821b commit 2eaf1f5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
8 changes: 6 additions & 2 deletions jscomp/runtime/caml_hash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ let caml_hash (count : int) _limit (seed : int) (obj : Obj.t) : int =
hash.contents <-
caml_hash_mix_string hash.contents (Obj.magic obj : string);
num.contents <- num.contents - 1)
else if Js_internal.typeof obj = "boolean" then ()
else if Js_internal.typeof obj = "boolean" then (
let u = match (Obj.magic obj : bool) with false -> 0 | true -> 1 in
hash.contents <- caml_hash_mix_int hash.contents (u + u + 1);
num.contents <- num.contents - 1)
else if Js_internal.typeof obj = "undefined" then ()
else if Js_internal.typeof obj = "symbol" then ()
else if Js_internal.typeof obj = "function" then ()
Expand Down Expand Up @@ -130,7 +133,8 @@ let caml_hash (count : int) _limit (seed : int) (obj : Obj.t) : int =
}
return size
}|}]
obj (fun [@u] v -> push_back queue v) [@u])
obj (fun [@u] v -> push_back queue v)
[@u])
in
hash.contents <- caml_hash_mix_int hash.contents ((size lsl 10) lor 0)
(*tag*)
Expand Down
4 changes: 4 additions & 0 deletions jscomp/stdlib/bool.ml → jscomp/stdlib/bool.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ external ( && ) : bool -> bool -> bool = "%sequand"
external ( || ) : bool -> bool -> bool = "%sequor"
let equal : bool -> bool -> bool = ( = )
let compare : bool -> bool -> int = Stdlib.compare
#ifdef BS
let to_int = function false -> 0 | true -> 1
#else
external to_int : bool -> int = "%identity"
#endif
let to_float = function false -> 0. | true -> 1.

(*
Expand Down
6 changes: 6 additions & 0 deletions jscomp/stdlib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
(action
(run cppo -D=BS %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(deps bool.cppo.ml)
(target bool.ml)
(action
(run cppo -D=BS %{env:CPPO_FLAGS=} %{deps} -o %{target})))

(rule
(deps bytes.cppo.ml)
(target bytes.ml)
Expand Down
30 changes: 30 additions & 0 deletions test/blackbox-tests/stdlib-bool.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Test cases for Stdlib.Bool

$ . ./setup.sh
$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> EOF
$ cat > dune <<EOF
> (melange.emit
> (target js-out))
> EOF

$ cat > x.ml <<EOF
> let () = Js.log2 (Bool.to_int false) (Bool.to_int true)
> let () = Js.log2 (Bool.not false) (Bool.not true)
> let () =
> Js.log4
> (Bool.compare false true)
> (Bool.compare false false)
> (Bool.compare true true)
> (Bool.compare true false)
> EOF

$ dune build @melange

$ node _build/default/js-out/x.js
0 1
true false
-1 0 0 1

20 changes: 20 additions & 0 deletions test/blackbox-tests/stdlib-hash.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Test cases for Stdlib hashes

$ . ./setup.sh
$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> EOF
$ cat > dune <<EOF
> (melange.emit
> (target js-out))
> EOF

$ cat > x.ml <<EOF
> let x = Js.log2 (Bool.hash false) (Bool.hash true)
> EOF

$ dune build @melange

$ node _build/default/js-out/x.js
-2017569654 -190020389

0 comments on commit 2eaf1f5

Please sign in to comment.