Skip to content

Commit f9b69c3

Browse files
committed
caml_set_oo_id only used by OO not exception
1 parent d8a1145 commit f9b69c3

15 files changed

+39
-101
lines changed

jscomp/core/js_of_lam_exception.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,3 @@ let make exception_str : J.expression =
4545

4646

4747

48-
(* TODO: only used in camlinternalOO, split it off as a separate module? *)
49-
let caml_set_oo_id args =
50-
E.runtime_call Js_runtime_modules.exceptions "caml_set_oo_id" args
51-

jscomp/core/js_of_lam_exception.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
val caml_set_oo_id :
27-
J.expression list -> J.expression
2826

2927

3028
val make : J.expression -> J.expression

jscomp/core/lam_dispatch_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ let translate loc (prim_name : string)
584584
call Js_runtime_modules.caml_js_exceptions
585585
| "caml_set_oo_id" (* needed in {!camlinternalOO.set_id} *)
586586
->
587-
Js_of_lam_exception.caml_set_oo_id args
587+
call Js_runtime_modules.oo
588588

589589
| "caml_sys_get_argv"
590590
(** TODO: refine

jscomp/runtime/caml_exceptions.ml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,7 @@ type t = {
3636
{[ a = caml_set_oo_id([248,"tag", caml_oo_last_id++]) ]}
3737
*)
3838

39-
let%private id = ref 0
40-
41-
42-
(* see #251
43-
{[
44-
CAMLprim value caml_set_oo_id (value obj) {
45-
Field(obj, 1) = oo_last_id;
46-
oo_last_id += 2;
47-
return obj;
48-
}
49-
50-
]}*)
51-
let caml_set_oo_id (b : Caml_obj_extern.t) : Caml_obj_extern.t =
52-
Caml_obj_extern.set_field (Caml_obj_extern.repr b) 1 (Caml_obj_extern.repr id.contents);
53-
id .contents <- id.contents + 1;
54-
b
55-
(* FXIME: this is only relevant to OO module now *)
39+
let id = ref 0
5640

5741

5842
let create (str : string) : string =

jscomp/runtime/caml_hash.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let caml_hash (count : int) _limit (seed : nativeint)
125125
else if Js.typeof obj = "undefined" then
126126
()
127127
else if Js.typeof obj = "symbol" then
128-
assert false (* TODO *)
128+
()
129129
else if Js.typeof obj = "function" then
130130
()
131131
else

jscomp/runtime/caml_oo.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,28 @@ type closure
4545
let caml_methods_cache =
4646
Caml_array_extern.make 1000 0
4747

48+
(* refer to {!CamlinternalOO.create_obj_opt}*)
4849
external get_methods : obj -> closure array =
4950
"%field0"
5051

52+
(* see #251
53+
{[
54+
CAMLprim value caml_set_oo_id (value obj) {
55+
Field(obj, 1) = oo_last_id;
56+
oo_last_id += 2;
57+
return obj;
58+
}
5159
60+
]}*)
61+
let caml_set_oo_id (b : obj) : obj =
62+
Caml_obj_extern.set_field
63+
(Caml_obj_extern.repr b) 1
64+
(Caml_obj_extern.repr Caml_exceptions.id.contents);
65+
Caml_exceptions.id.contents <- Caml_exceptions.id.contents + 1;
66+
b
67+
68+
69+
5270
let caml_get_public_method
5371
(obj : obj)
5472
(tag : int) (cacheid : int) : closure =

jscomp/runtime/caml_oo.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ type obj
3333
type closure
3434

3535
val caml_get_public_method : obj -> int -> int -> closure
36+
37+
val caml_set_oo_id : obj -> obj

jscomp/stdlib-406/camlinternalMod.ml

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,3 @@ type shape =
1919
| Class
2020
| Module of shape array
2121
| Value of Obj.t
22-
#if BS then
23-
#else
24-
let overwrite o n =
25-
assert (Obj.size o >= Obj.size n);
26-
for i = 0 to Obj.size n - 1 do
27-
Obj.set_field o i (Obj.field n i)
28-
done
29-
30-
let rec init_mod loc shape =
31-
match shape with
32-
| Function ->
33-
(* Two code pointer words (curried and full application), arity
34-
and eight environment entries makes 11 words. *)
35-
let closure = Obj.new_block Obj.closure_tag 11 in
36-
let template =
37-
Obj.repr (fun _ -> raise (Undefined_recursive_module loc))
38-
in
39-
overwrite closure template;
40-
closure
41-
| Lazy ->
42-
Obj.repr (lazy (raise (Undefined_recursive_module loc)))
43-
| Class ->
44-
Obj.repr (CamlinternalOO.dummy_class loc)
45-
| Module comps ->
46-
Obj.repr (Array.map (init_mod loc) comps)
47-
| Value v ->
48-
v
49-
50-
let rec update_mod shape o n =
51-
match shape with
52-
| Function ->
53-
if Obj.tag n = Obj.closure_tag && Obj.size n <= Obj.size o
54-
then begin overwrite o n; Obj.truncate o (Obj.size n) (* PR#4008 *) end
55-
else overwrite o (Obj.repr (fun x -> (Obj.obj n : _ -> _) x))
56-
| Lazy ->
57-
if Obj.tag n = Obj.lazy_tag then
58-
Obj.set_field o 0 (Obj.field n 0)
59-
else if Obj.tag n = Obj.forward_tag then begin (* PR#4316 *)
60-
Obj.set_tag o Obj.forward_tag;
61-
Obj.set_field o 0 (Obj.field n 0)
62-
end else begin
63-
(* forwarding pointer was shortcut by GC *)
64-
Obj.set_tag o Obj.forward_tag;
65-
Obj.set_field o 0 n
66-
end
67-
| Class ->
68-
assert (Obj.tag n = 0 && Obj.size n = 4);
69-
overwrite o n
70-
| Module comps ->
71-
assert (Obj.tag n = 0 && Obj.size n >= Array.length comps);
72-
for i = 0 to Array.length comps - 1 do
73-
update_mod comps.(i) (Obj.field o i) (Obj.field n i)
74-
done
75-
| Value _ -> () (* the value is already there *)
76-
#end

jscomp/test/class6_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
var Mt = require("./mt.js");
44
var Block = require("../../lib/js/block.js");
55
var Curry = require("../../lib/js/curry.js");
6+
var Caml_oo = require("../../lib/js/caml_oo.js");
67
var Caml_obj = require("../../lib/js/caml_obj.js");
78
var Caml_oo_curry = require("../../lib/js/caml_oo_curry.js");
89
var CamlinternalOO = require("../../lib/js/camlinternalOO.js");
9-
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
1010

1111
var shared = ["x"];
1212

@@ -209,7 +209,7 @@ function functional_point_init($$class) {
209209
}),
210210
move,
211211
(function (self$6, d) {
212-
var copy = Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$6));
212+
var copy = Caml_oo.caml_set_oo_id(Caml_obj.caml_obj_dup(self$6));
213213
copy[x] = self$6[x] + d | 0;
214214
return copy;
215215
})

jscomp/test/class7_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
var Mt = require("./mt.js");
44
var Block = require("../../lib/js/block.js");
55
var Curry = require("../../lib/js/curry.js");
6+
var Caml_oo = require("../../lib/js/caml_oo.js");
67
var Caml_obj = require("../../lib/js/caml_obj.js");
78
var Caml_option = require("../../lib/js/caml_option.js");
89
var Caml_oo_curry = require("../../lib/js/caml_oo_curry.js");
910
var CamlinternalOO = require("../../lib/js/camlinternalOO.js");
10-
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
1111

1212
var shared = ["window"];
1313

@@ -86,7 +86,7 @@ var point = CamlinternalOO.make_class(shared$4, point_init);
8686

8787
var p = Curry._2(point[0], undefined, 55);
8888

89-
var q = Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(p));
89+
var q = Caml_oo.caml_set_oo_id(Caml_obj.caml_obj_dup(p));
9090

9191
Caml_oo_curry.js2(-933174511, 1, q, 7);
9292

@@ -136,7 +136,7 @@ function backup_init($$class) {
136136
CamlinternalOO.set_methods($$class, [
137137
save,
138138
(function (self$3) {
139-
var copy$1 = Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$3));
139+
var copy$1 = Caml_oo.caml_set_oo_id(Caml_obj.caml_obj_dup(self$3));
140140
self$3[copy] = Caml_option.some((copy$1[copy] = undefined, copy$1));
141141

142142
}),
@@ -234,7 +234,7 @@ function backup2_init($$class) {
234234
CamlinternalOO.set_methods($$class, [
235235
save,
236236
(function (self$5) {
237-
self$5[copy] = Caml_option.some(Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$5)));
237+
self$5[copy] = Caml_option.some(Caml_oo.caml_set_oo_id(Caml_obj.caml_obj_dup(self$5)));
238238

239239
}),
240240
restore,

0 commit comments

Comments
 (0)