Skip to content

Commit 6806a1b

Browse files
committed
phys_equal
1 parent 2ca7dbf commit 6806a1b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler/lib/generate.ml

+16
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ let plus_int x y =
343343

344344
let bool e = J.ECond (e, one, zero)
345345

346+
let bool_not e = J.ECond (e, zero, one)
347+
346348
(****)
347349

348350
let source_location ctx position pc =
@@ -1398,6 +1400,20 @@ let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t
13981400
| _ -> J.EBin (J.Plus, ca, cb)
13991401
in
14001402
return (add ca cb)
1403+
| Extern "%phys_equal", [x; y] ->
1404+
let* cx = access' ~ctx x in
1405+
let* cy = access' ~ctx y in
1406+
return (bool (J.call
1407+
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1408+
[ cx; cy ]
1409+
loc))
1410+
| Extern "%not_phys_equal", [x; y] ->
1411+
let* cx = access' ~ctx x in
1412+
let* cy = access' ~ctx y in
1413+
return (bool_not (J.call
1414+
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1415+
[ cx; cy ]
1416+
loc))
14011417
| Extern name, l -> (
14021418
let name = Primitive.resolve name in
14031419
match internal_prim name with

compiler/lib/parse_bytecode.ml

+13-2
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ module Hints = struct
358358
; layout : Lambda.bigarray_layout
359359
}
360360
| Hint_primitive of Primitive.description
361+
| Hint_phys_equal
361362

362363
module Int_table = Hashtbl.Make (Int)
363364

@@ -2222,23 +2223,33 @@ and compile infos pc state (instrs : instr list) =
22222223

22232224
if debug_parser ()
22242225
then Format.printf "%a = mk_bool(%a == %a)@." Var.print x Var.print y Var.print z;
2226+
let hints = Hints.find infos.hints pc in
2227+
let prim =
2228+
if List.mem Hints.Hint_phys_equal ~set:hints then Extern "%phys_equal" else Eq
2229+
in
22252230
compile
22262231
infos
22272232
(pc + 1)
22282233
(State.pop 1 state)
2229-
(Let (x, Prim (Eq, [ Pv y; Pv z ])) :: instrs)
2234+
(Let (x, Prim (prim, [ Pv y; Pv z ])) :: instrs)
22302235
| NEQ ->
22312236
let y = State.accu state in
22322237
let z = State.peek 0 state in
22332238
let x, state = State.fresh_var state in
22342239

22352240
if debug_parser ()
22362241
then Format.printf "%a = mk_bool(%a != %a)@." Var.print x Var.print y Var.print z;
2242+
let hints = Hints.find infos.hints pc in
2243+
let prim =
2244+
if List.mem Hints.Hint_phys_equal ~set:hints
2245+
then Extern "%not_phys_equal"
2246+
else Neq
2247+
in
22372248
compile
22382249
infos
22392250
(pc + 1)
22402251
(State.pop 1 state)
2241-
(Let (x, Prim (Neq, [ Pv y; Pv z ])) :: instrs)
2252+
(Let (x, Prim (prim, [ Pv y; Pv z ])) :: instrs)
22422253
| LTINT ->
22432254
let y = State.accu state in
22442255
let z = State.peek 0 state in

0 commit comments

Comments
 (0)