Skip to content

Commit 148ecda

Browse files
committed
caml_fresh_oo_id/caml_set_oo_id support
1 parent e7fcbf0 commit 148ecda

7 files changed

+46
-20
lines changed

Diff for: jscomp/core/js_of_lam_exception.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,7 @@ let caml_set_oo_id args =
7878
(* -> *)
7979
(* make_exception exception_str *)
8080
(* | _ -> *)
81-
8281
(* end *)
82+
83+
let caml_fresh_oo_id args =
84+
E.runtime_call Js_runtime_modules.exceptions "caml_fresh_oo_id" args

Diff for: jscomp/core/js_of_lam_exception.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
val get_builtin_by_name : string -> J.expression
3232

3333

34-
val caml_set_oo_id : J.expression list -> J.expression
34+
val caml_set_oo_id :
35+
J.expression list -> J.expression
36+
37+
val caml_fresh_oo_id :
38+
J.expression list -> J.expression
39+
3540
val make : J.expression -> J.expression
3641
(* val make_extension : J.expression -> J.expression *)

Diff for: jscomp/core/lam_convert.ml

+23-11
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,18 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
229229
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
230230
| Blk_extension_slot ->
231231
let info : Lam_tag_info.t = Blk_extension_slot in
232+
(
233+
#if OCAML_VERSION =~ ">4.03.0" then
234+
match args with
235+
| [ Lconst (Const_string name);
236+
Lprim {primitive = Pccall {prim_name = "caml_fresh_oo_id"} ; }
237+
] ->
238+
prim ~primitive:(Pcreate_extension name) ~args:[] loc
239+
| _ ->
240+
#end
232241
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
242+
)
243+
233244
| Blk_na ->
234245
let info : Lam_tag_info.t = Blk_na in
235246
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
@@ -400,32 +411,33 @@ let convert (exports : Ident_set.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
400411
let may_depends = Lam_module_ident.Hash_set.create 0 in
401412

402413
let rec
403-
convert_ccall (a : Primitive_compat.t) (args : Lambda.lambda list) loc : Lam.t =
404-
let prim_name = a.prim_name in
414+
convert_ccall (a_prim : Primitive_compat.t) (args : Lambda.lambda list) loc : Lam.t =
415+
let prim_name = a_prim.prim_name in
405416
let prim_name_len = String.length prim_name in
406-
match External_ffi_types.from_string a.prim_native_name with
417+
match External_ffi_types.from_string a_prim.prim_native_name with
407418
| Ffi_normal ->
408419
if prim_name_len > 0 && String.unsafe_get prim_name 0 = '#' then
409-
convert_js_primitive a args loc
420+
convert_js_primitive a_prim args loc
410421
else
411422
(* COMPILER CHECK *)
412423
(* Here the invariant we should keep is that all exception
413424
created should be captured
414425
*)
415-
(match prim_name , args with
426+
(
427+
#if OCAML_VERSION =~ ">4.03.0" then
428+
#else
429+
match prim_name , args with
416430
| "caml_set_oo_id" ,
417-
[ Lprim (Pmakeblock(tag,Blk_extension_slot, _
418-
#if OCAML_VERSION =~ ">4.03.0" then
419-
,_ (*FIXME caml_set_oo_id is no longer needed?*)
420-
#end
421-
),
431+
[ Lprim (Pmakeblock(tag,Blk_extension_slot, _),
422432
Lconst (Const_base(Const_string(name,_))) :: _,
423433
loc
424434
)]
425435
-> prim ~primitive:(Pcreate_extension name) ~args:[] loc
426436
| _ , _->
437+
#end
427438
let args = Ext_list.map args convert_aux in
428-
prim ~primitive:(Pccall a) ~args loc)
439+
prim ~primitive:(Pccall a_prim) ~args loc
440+
)
429441
| Ffi_obj_create labels ->
430442
let args = Ext_list.map args convert_aux in
431443
prim ~primitive:(Pjs_object_create labels) ~args loc

Diff for: jscomp/core/lam_dispatch_primitive.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,15 @@ let translate loc (prim_name : string)
581581
(** Note we captured [exception/extension] creation in the early pass, this primitive is
582582
like normal one to set the identifier *)
583583

584+
#if OCAML_VERSION =~ ">4.03.0" then
585+
| "caml_fresh_oo_id"
586+
->
587+
Js_of_lam_exception.caml_fresh_oo_id args
588+
#else
584589
| "caml_set_oo_id"
585590
->
586591
Js_of_lam_exception.caml_set_oo_id args
587-
592+
#end
588593
| "caml_sys_const_big_endian" ->
589594
(** return false *)
590595
E.bool Sys.big_endian

Diff for: jscomp/runtime/caml_exceptions.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ let caml_set_oo_id (b : Caml_builtin_exceptions.exception_block) =
5252
id := Nativeint.add !id 1n;
5353
b
5454

55-
let get_id () =
55+
56+
let caml_fresh_oo_id () =
5657
id := Nativeint.add !id 1n; !id
5758

5859
let object_tag = 248
5960

6061
let create (str : string) : Caml_builtin_exceptions.exception_block =
61-
let v = ( str, get_id ()) in
62+
let v = ( str, caml_fresh_oo_id ()) in
6263
Bs_obj.set_tag (Obj.repr v) object_tag;
6364
v
6465

Diff for: jscomp/runtime/caml_exceptions.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
val caml_set_oo_id :
3232
Caml_builtin_exceptions.exception_block -> Caml_builtin_exceptions.exception_block
3333

34-
val get_id : unit -> nativeint
34+
val caml_fresh_oo_id :
35+
unit -> nativeint
3536

3637
val create : string -> Caml_builtin_exceptions.exception_block
3738
(* val makeExtension : string -> Caml_builtin_exceptions.exception_block *)

Diff for: lib/js/caml_exceptions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ function caml_set_oo_id(b) {
99
return b;
1010
}
1111

12-
function get_id(param) {
12+
function caml_fresh_oo_id(param) {
1313
id[0] += 1;
1414
return id[0];
1515
}
1616

1717
function create(str) {
18-
var v_001 = get_id(/* () */0);
18+
var v_001 = caml_fresh_oo_id(/* () */0);
1919
var v = /* tuple */[
2020
str,
2121
v_001
@@ -40,7 +40,7 @@ function isCamlExceptionOrOpenVariant(e) {
4040
}
4141

4242
exports.caml_set_oo_id = caml_set_oo_id;
43-
exports.get_id = get_id;
43+
exports.caml_fresh_oo_id = caml_fresh_oo_id;
4444
exports.create = create;
4545
exports.isCamlExceptionOrOpenVariant = isCamlExceptionOrOpenVariant;
4646
/* No side effect */

0 commit comments

Comments
 (0)