Skip to content

Compiler: allow to inline primitives defined in the js runtime into the generated code #1928

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

hhugo
Copy link
Member

@hhugo hhugo commented Apr 10, 2025

and move compilation of some primitives out of generate.ml into the runtime

@@ -1292,7 +1273,7 @@
/*<<obj.ml:107:4>>*/ return runtime.caml_ephe_create(l) /*<<obj.ml:107:12>>*/ ;
}
function length(x){
/*<<obj.ml:109:17>>*/ return x.length - 3 | 0;
/*<<obj.ml:109:17>>*/ return x.length - 1 - 2 | 0;
Copy link
Member

@vouillon vouillon Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why this is no longer simplified.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously optimized by

  register_bin_prims
    [ "%int_add"; "caml_int32_add"; "caml_nativeint_add" ]
    `Pure
    (fun cx cy _ ->
      match cx, cy with
      | J.EBin (J.Minus, cz, J.ENum n), J.ENum m ->
          to_int (J.EBin (J.Plus, cz, J.ENum (J.Num.add m (J.Num.neg n))))
      | _ -> to_int (plus_int cx cy));
  register_bin_prims
    [ "%int_sub"; "caml_int32_sub"; "caml_nativeint_sub" ]
    `Pure
    (fun cx cy _ ->
      match cx, cy with
      | J.EBin (J.Minus, cz, J.ENum n), J.ENum m ->
          to_int (J.EBin (J.Minus, cz, J.ENum (J.Num.add n m)))
      | _ -> to_int (J.EBin (J.Minus, cx, cy)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants