Skip to content

Commit 9f82e75

Browse files
committed
CR
1 parent 9985abe commit 9f82e75

File tree

9 files changed

+30
-21
lines changed

9 files changed

+30
-21
lines changed

compiler/lib/generate.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,8 @@ let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t
14251425
if String.starts_with name ~prefix:"%"
14261426
then failwith (Printf.sprintf "Unresolved internal primitive: %s" name);
14271427
match Linker.inline ~name with
1428-
| Some f -> (
1428+
| Some (req, f)
1429+
when Option.is_none ctx.Ctx.exported_runtime || List.is_empty req -> (
14291430
let c = new Js_traverse.rename_variable ~esm:false in
14301431
let f = c#expression f in
14311432
match f with
@@ -1461,7 +1462,7 @@ let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t
14611462
let r = new subst sub in
14621463
return (r#expression body)
14631464
| _ -> assert false)
1464-
| None ->
1465+
| None | Some _ ->
14651466
let prim = Share.get_prim (runtime_fun ctx) name ctx.Ctx.share in
14661467
let* () = info ~need_loc:true (kind (Primitive.kind name)) in
14671468
let* args = list_map (fun x -> access' ~ctx x) l in

compiler/lib/linker.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,8 @@ let inline ~name =
795795
| { id; inline; _ } ->
796796
if inline
797797
then
798-
let code, _has_macro, _req, _deprecated = Hashtbl.find code_pieces id in
798+
let code, _has_macro, req, _deprecated = Hashtbl.find code_pieces id in
799799
match unpack code with
800-
| [ (Function_declaration (_, f), _) ] -> Some (Javascript.EFun (None, f))
800+
| [ (Function_declaration (_, f), _) ] -> Some (req, Javascript.EFun (None, f))
801801
| _ -> None
802802
else None

compiler/lib/linker.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ val missing : state -> string list
7171

7272
val origin : name:string -> string option
7373

74-
val inline : name:string -> Javascript.expression option
74+
val inline : name:string -> (string list * Javascript.expression) option
7575

7676
val deprecated : name:string -> bool

compiler/tests-compiler/call_gen.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ module M1 = struct
4242
let%expect_test "executed code" =
4343
compile_and_run code;
4444
[%expect {|
45-
10
46-
10
47-
14
48-
25 |}]
45+
10
46+
10
47+
14
48+
25
49+
|}]
4950

5051
let%expect_test "generated code" =
5152
let generated = compile_and_parse code in
@@ -148,5 +149,6 @@ module M2 = struct
148149
15
149150
20
150151
15
151-
20 |}]
152+
20
153+
|}]
152154
end

compiler/tests-compiler/gh1559.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ let () = my_ref := 2
6060
|}
6161
in
6262
Util.compile_and_run prog;
63-
[%expect {|
64-
1 |}];
63+
[%expect
64+
{| 1 |}];
6565
let program = Util.compile_and_parse prog in
6666
Util.print_program program;
6767
[%expect
@@ -165,8 +165,8 @@ let () = my_ref := 2
165165
|}
166166
in
167167
Util.compile_and_run prog;
168-
[%expect {|
169-
2 |}];
168+
[%expect
169+
{| 2 |}];
170170
let program = Util.compile_and_parse prog in
171171
Util.print_program program;
172172
[%expect

compiler/tests-compiler/unix_fs.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ in
136136
f (); Sys.chdir "/static"; f () |};
137137
[%expect {|
138138
File size: 3
139-
Failure("caml_unix_stat: not implemented")|}]
139+
Failure("caml_unix_stat: not implemented")
140+
|}]
140141

141142
let%expect_test "Unix.stat_dir" =
142143
compile_and_run
@@ -180,7 +181,8 @@ f (); Sys.chdir "/static"; f () |};
180181
{|
181182
File size: 3
182183
Failure("caml_unix_symlink: not implemented")
183-
Failure("caml_unix_stat: not implemented")|}]
184+
Failure("caml_unix_stat: not implemented")
185+
|}]
184186

185187
let%expect_test "Unix.symlink_Unix.readlink" =
186188
compile_and_run
@@ -247,7 +249,8 @@ in
247249
f (); Sys.chdir "/static"; f () |};
248250
[%expect {|
249251
File size: 3
250-
Failure("caml_unix_lstat: not implemented")|}]
252+
Failure("caml_unix_lstat: not implemented")
253+
|}]
251254

252255
let%expect_test "Unix.lstat_symlink" =
253256
compile_and_run

compiler/tests-full/stdlib.cma.expected.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@
746746
/*<<stdlib.ml:488:20>>*/ return output_bytes(stdout, s) /*<<stdlib.ml:488:41>>*/ ;
747747
}
748748
function print_int(i){
749-
/*<<stdlib.ml:489:56>>*/ return output_string(stdout, "" + i);
749+
/*<<stdlib.ml:266:2>>*/ return /*<<stdlib.ml:489:56>>*/ output_string
750+
(stdout, /*<<stdlib.ml:266:2>>*/ caml_format_int_special(i)) /*<<stdlib.ml:489:56>>*/ ;
750751
}
751752
function print_float(f){
752753
/*<<stdlib.ml:490:41>>*/ return /*<<stdlib.ml:490:60>>*/ output_string
@@ -771,7 +772,8 @@
771772
/*<<stdlib.ml:499:20>>*/ return output_bytes(stderr, s) /*<<stdlib.ml:499:41>>*/ ;
772773
}
773774
function prerr_int(i){
774-
/*<<stdlib.ml:500:56>>*/ return output_string(stderr, "" + i);
775+
/*<<stdlib.ml:266:2>>*/ return /*<<stdlib.ml:500:56>>*/ output_string
776+
(stderr, /*<<stdlib.ml:266:2>>*/ caml_format_int_special(i)) /*<<stdlib.ml:500:56>>*/ ;
775777
}
776778
function prerr_float(f){
777779
/*<<stdlib.ml:501:41>>*/ return /*<<stdlib.ml:501:60>>*/ output_string

compiler/tests-jsoo/test_unix.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ let%expect_test "Unix.read" =
149149
[%expect {|
150150
write failed
151151
bad file descriptor
152-
|}]
152+
|}]
153153

154154
let%expect_test "Unix.getenv" =
155155
Printf.printf "%s\n" (Sys.getenv "FOO");

runtime/js/format.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ function caml_finish_formatting(f, rawbuffer) {
143143

144144
//Provides: caml_format_int_special const
145145
//Alias: %caml_format_int_special
146+
//Requires: caml_string_of_jsstring
146147
//Inline
147148
function caml_format_int_special(x) {
148-
return "" + x;
149+
return caml_string_of_jsstring ("" + x);
149150
}

0 commit comments

Comments
 (0)