Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hints phys equal #1745

Draft
wants to merge 1 commit into
base: hints
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions compiler/lib/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ let plus_int x y =

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

let bool_not e = J.ECond (e, zero, one)

(****)

let source_location ctx position pc =
Expand Down Expand Up @@ -1398,6 +1400,20 @@ let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t
| _ -> J.EBin (J.Plus, ca, cb)
in
return (add ca cb)
| Extern "%phys_equal", [x; y] ->
let* cx = access' ~ctx x in
let* cy = access' ~ctx y in
return (bool (J.call
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
[ cx; cy ]
loc))
| Extern "%not_phys_equal", [x; y] ->
let* cx = access' ~ctx x in
let* cy = access' ~ctx y in
return (bool_not (J.call
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
[ cx; cy ]
loc))
| Extern name, l -> (
let name = Primitive.resolve name in
match internal_prim name with
Expand Down
15 changes: 13 additions & 2 deletions compiler/lib/parse_bytecode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ module Hints = struct
; layout : Lambda.bigarray_layout
}
| Hint_primitive of Primitive.description
| Hint_phys_equal

module Int_table = Hashtbl.Make (Int)

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

if debug_parser ()
then Format.printf "%a = mk_bool(%a == %a)@." Var.print x Var.print y Var.print z;
let hints = Hints.find infos.hints pc in
let prim =
if List.mem Hints.Hint_phys_equal ~set:hints then Extern "%phys_equal" else Eq
in
compile
infos
(pc + 1)
(State.pop 1 state)
(Let (x, Prim (Eq, [ Pv y; Pv z ])) :: instrs)
(Let (x, Prim (prim, [ Pv y; Pv z ])) :: instrs)
| NEQ ->
let y = State.accu state in
let z = State.peek 0 state in
let x, state = State.fresh_var state in

if debug_parser ()
then Format.printf "%a = mk_bool(%a != %a)@." Var.print x Var.print y Var.print z;
let hints = Hints.find infos.hints pc in
let prim =
if List.mem Hints.Hint_phys_equal ~set:hints
then Extern "%not_phys_equal"
else Neq
in
compile
infos
(pc + 1)
(State.pop 1 state)
(Let (x, Prim (Neq, [ Pv y; Pv z ])) :: instrs)
(Let (x, Prim (prim, [ Pv y; Pv z ])) :: instrs)
| LTINT ->
let y = State.accu state in
let z = State.peek 0 state in
Expand Down
Loading