From b6dbbb3c441586d4d0e0f7dd979ec28a7e1babd1 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Sat, 23 Jan 2016 11:09:19 -0500 Subject: [PATCH] support caml_fmod_float --- jscomp/j_helper.ml | 6 ++++++ jscomp/j_helper.mli | 2 +- jscomp/lam_dispatch_primitive.ml | 17 ++++++++++++++--- jscomp/test/.depend | 4 ++++ jscomp/test/primitive_reg_test.d.ts | 2 ++ jscomp/test/primitive_reg_test.js | 10 ++++++++++ jscomp/test/primitive_reg_test.ml | 1 + jscomp/test/test.mllib | 3 ++- jscomp/test/test_react.ml | 2 +- 9 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 jscomp/test/primitive_reg_test.d.ts create mode 100644 jscomp/test/primitive_reg_test.js create mode 100644 jscomp/test/primitive_reg_test.ml diff --git a/jscomp/j_helper.ml b/jscomp/j_helper.ml index 065ef81c53..a26e2ec475 100644 --- a/jscomp/j_helper.ml +++ b/jscomp/j_helper.ml @@ -350,6 +350,12 @@ module Exp = struct let float_minus ?comment (e0 : t) (e1 : t) : t = {comment ; expression_desc = Bin (Minus,e0,e1)} + + + let float_mod ?comment e1 e2 : J.expression = + { comment ; + expression_desc = Bin (Mod, e1,e2) + } let obj ?comment properties : t = {expression_desc = Object properties; comment } diff --git a/jscomp/j_helper.mli b/jscomp/j_helper.mli index fd40527dc5..e6c67e95a6 100644 --- a/jscomp/j_helper.mli +++ b/jscomp/j_helper.mli @@ -162,7 +162,7 @@ module Exp : sig val float_minus : binary_op val float_notequal : binary_op - + val float_mod : binary_op val not : t -> t val call : ?comment:string -> ?info:Js_call_info.t -> t -> t list -> t diff --git a/jscomp/lam_dispatch_primitive.ml b/jscomp/lam_dispatch_primitive.ml index cc721d3129..b8a94e72c8 100644 --- a/jscomp/lam_dispatch_primitive.ml +++ b/jscomp/lam_dispatch_primitive.ml @@ -264,9 +264,17 @@ let query (prim : Lam_compile_env.primitive_description) | "caml_copysign_float" | "caml_expm1_float" | "caml_hypot_float" - (* "caml_fmod_float"; TODO: *) + -> E.runtime_call J_helper.float prim.prim_name args + | "caml_fmod_float" + (* float module like js number module *) + -> + begin match args with + | [e0;e1] -> E.float_mod e0 e1 + | _ -> assert false + end + | "caml_string_equal" -> begin match args with @@ -655,8 +663,11 @@ let query (prim : Lam_compile_env.primitive_description) | _ -> assert false end | _ -> - E.str ~comment:"Missing primitve" ~pure:false prim.prim_name; - (* raise X.NA *) (* Fall back, maybe spit out a warning*) + + let comment = "Missing primitve" in + Ext_log.warn __LOC__ "%s" (Printf.sprintf "%s: %s\n" comment prim.prim_name) ; + E.str ~comment ~pure:false prim.prim_name; + (* raise X.NA *) (* Fall back, maybe spit out a warning*) end in v with X.NA -> diff --git a/jscomp/test/.depend b/jscomp/test/.depend index 1ec446fde2..e496dabc9a 100644 --- a/jscomp/test/.depend +++ b/jscomp/test/.depend @@ -121,6 +121,8 @@ obj_test.cmo : mt.cmo obj_test.cmx : mt.cmx of_string_test.cmo : mt.cmo of_string_test.cmx : mt.cmx +primitive_reg_test.cmo : +primitive_reg_test.cmx : qcc.cmo : ../stdlib/sys.cmi ../stdlib/string.cmi ../stdlib/printf.cmi \ ../stdlib/list.cmi ../stdlib/char.cmi ../stdlib/bytes.cmi \ ../stdlib/array.cmi @@ -461,6 +463,8 @@ obj_test.cmo : mt.cmo obj_test.cmo : mt.cmo of_string_test.cmo : mt.cmo of_string_test.cmo : mt.cmo +primitive_reg_test.cmo : +primitive_reg_test.cmo : qcc.cmo : ../stdlib/sys.cmi ../stdlib/string.cmi ../stdlib/printf.cmi \ ../stdlib/list.cmi ../stdlib/char.cmi ../stdlib/bytes.cmi \ ../stdlib/array.cmi diff --git a/jscomp/test/primitive_reg_test.d.ts b/jscomp/test/primitive_reg_test.d.ts new file mode 100644 index 0000000000..ff037eaa0e --- /dev/null +++ b/jscomp/test/primitive_reg_test.d.ts @@ -0,0 +1,2 @@ +export var x: (prim : any, prim : any) => any ; + diff --git a/jscomp/test/primitive_reg_test.js b/jscomp/test/primitive_reg_test.js new file mode 100644 index 0000000000..105b436175 --- /dev/null +++ b/jscomp/test/primitive_reg_test.js @@ -0,0 +1,10 @@ +// Generated CODE, PLEASE EDIT WITH CARE +"use strict"; + + +function x(prim, prim$1) { + return prim % prim$1; +} + +exports.x = x; +/* No side effect */ diff --git a/jscomp/test/primitive_reg_test.ml b/jscomp/test/primitive_reg_test.ml new file mode 100644 index 0000000000..74b7c26baa --- /dev/null +++ b/jscomp/test/primitive_reg_test.ml @@ -0,0 +1 @@ +let x = mod_float diff --git a/jscomp/test/test.mllib b/jscomp/test/test.mllib index 4b90ee0aed..7d996914f6 100644 --- a/jscomp/test/test.mllib +++ b/jscomp/test/test.mllib @@ -144,4 +144,5 @@ obj_test demo_page complex_test inline_edge_cases -inline_regression_test \ No newline at end of file +inline_regression_test +primitive_reg_test \ No newline at end of file diff --git a/jscomp/test/test_react.ml b/jscomp/test/test_react.ml index be7f312c00..00941413a4 100644 --- a/jscomp/test/test_react.ml +++ b/jscomp/test/test_react.ml @@ -7,7 +7,7 @@ class type doc = object method getElementById : string -> html_element end -external doc : doc = "doc" [@@js.global] +external doc : doc = "doc" [@@js.global "doc"] class type console = object