Skip to content

Commit 4df61f9

Browse files
committed
phys_equal
1 parent 9b6d4bf commit 4df61f9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler/lib/generate.ml

Lines changed: 16 additions & 0 deletions
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 =
@@ -1393,6 +1395,20 @@ let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t
13931395
| _ -> J.EBin (J.Plus, ca, cb)
13941396
in
13951397
return (add ca cb)
1398+
| Extern "%phys_equal", [x; y] ->
1399+
let* cx = access' ~ctx x in
1400+
let* cy = access' ~ctx y in
1401+
return (bool (J.call
1402+
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1403+
[ cx; cy ]
1404+
loc))
1405+
| Extern "%not_phys_equal", [x; y] ->
1406+
let* cx = access' ~ctx x in
1407+
let* cy = access' ~ctx y in
1408+
return (bool_not (J.call
1409+
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1410+
[ cx; cy ]
1411+
loc))
13961412
| Extern name, l -> (
13971413
let name = Primitive.resolve name in
13981414
match internal_prim name with

compiler/lib/parse_bytecode.ml

Lines changed: 13 additions & 2 deletions
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

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

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

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

0 commit comments

Comments
 (0)