Skip to content

Commit c81c578

Browse files
committed
[refact] use array representaion per discussion of rescript-lang#24 (rescript-lang#287)
1 parent a078dce commit c81c578

File tree

121 files changed

+9182
-14366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+9182
-14366
lines changed

jscomp/js_config.ml

+3
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ let weak = "Caml_weak"
145145
let backtrace = "Caml_backtrace"
146146
let gc = "Caml_gc"
147147
let int32 = "Caml_int32"
148+
let block = "Block"
149+
148150
let runtime_set =
149151
[
152+
block;
150153
int32;
151154
gc ;
152155
backtrace;

jscomp/js_config.mli

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ val default_gen_tds : bool ref
3434
val runtime_set : String_set.t
3535
val stdlib_set : String_set.t
3636

37+
val block : string
3738
val int32 : string
3839
val gc : string
3940
val backtrace : string

jscomp/js_dump.ml

+7-14
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ module L = struct
110110
let ge = ">="
111111
let plus_plus = "++" (* FIXME: use (i = i + 1 | 0) instead *)
112112
let minus_minus = "--"
113+
let caml_block = "Block"
114+
let caml_block_create = "__"
113115
end
114116
let return_indent = (String.length L.return / Ext_pp.indent_length)
115117

@@ -892,28 +894,19 @@ and
892894

893895
| Number (Int { i = 0l ; _}) ,
894896
(Blk_tuple | Blk_array | Blk_variant _ | Blk_record _ | Blk_na | Blk_module _
895-
| Blk_constructor (_, 1)
897+
| Blk_constructor (_, 1) (* Sync up with {!Js_dump}*)
896898
)
897-
(* Hack to optimize option which is really pervasive in ocaml,
898-
we need concrete benchmark to support this
899-
*)
900899
-> expression_desc cxt l f (Array (el, mutable_flag))
901900
(* TODO: for numbers like 248, 255 we can reverse engineer to make it
902901
[Obj.xx_flag], but we can not do this in runtime libraries
903902
*)
904903

905904
| _, _
906905
->
907-
expression_desc cxt l f
908-
(J.Object (
909-
let length, rev_list =
910-
List.fold_left (fun (i,acc) v ->
911-
(i+1, (Js_op.Int_key i, v) :: acc)
912-
) (0, []) el in
913-
List.rev_append rev_list
914-
[(Js_op.Length, E.small_int length) ; (Js_op.Tag, tag)]
915-
)
916-
)
906+
P.string f L.caml_block;
907+
P.string f L.dot ;
908+
P.string f L.caml_block_create;
909+
P.paren_group f 1 (fun _ -> arguments cxt f [tag; E.arr mutable_flag el])
917910
end
918911
| Caml_block_tag e ->
919912
P.group f 1 (fun _ ->

jscomp/js_fold_basic.ml

+17-4
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,24 @@ class count_hard_dependencies =
5858
match x with
5959
| {expression_desc = Call (_,_, {arity = NA}); _}
6060
(* see [Js_exp_make.runtime_var_dot] *)
61-
-> begin
61+
->
62+
Hash_set.add hard_dependencies
63+
(Lam_module_ident.of_runtime (Ext_ident.create_js Js_config.curry));
64+
super#expression x
65+
| {expression_desc = Caml_block(_,_, tag, tag_info); _}
66+
->
67+
begin match tag.expression_desc, tag_info with
68+
| Number (Int { i = 0l ; _}) ,
69+
(Blk_tuple | Blk_array | Blk_variant _ | Blk_record _ | Blk_na | Blk_module _
70+
| Blk_constructor (_, 1)
71+
) (*Sync up with {!Js_dump}*)
72+
-> ()
73+
| _, _
74+
->
6275
Hash_set.add hard_dependencies
63-
(Lam_module_ident.of_runtime (Ext_ident.create_js Js_config.curry));
64-
super#expression x
65-
end
76+
(Lam_module_ident.of_runtime (Ext_ident.create_js Js_config.block));
77+
end;
78+
super#expression x
6679
| _ -> super#expression x
6780
method get_hard_dependencies = hard_dependencies
6881
end

jscomp/runtime/.depend

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
block.cmi :
12
caml_array.cmi :
23
caml_backtrace.cmi :
34
caml_bigarray.cmi :
4-
caml_block.cmi :
55
caml_builtin_exceptions.cmi :
66
caml_exceptions.cmi : caml_builtin_exceptions.cmi
77
caml_float.cmi :
@@ -21,14 +21,14 @@ caml_string.cmi :
2121
caml_sys.cmi :
2222
caml_utils.cmi :
2323
caml_weak.cmi :
24+
block.cmo : block.cmi
25+
block.cmx : block.cmi
2426
caml_array.cmo : js.cmo caml_array.cmi
2527
caml_array.cmx : js.cmx caml_array.cmi
2628
caml_backtrace.cmo : caml_backtrace.cmi
2729
caml_backtrace.cmx : caml_backtrace.cmi
2830
caml_bigarray.cmo : caml_bigarray.cmi
2931
caml_bigarray.cmx : caml_bigarray.cmi
30-
caml_block.cmo : caml_block.cmi
31-
caml_block.cmx : caml_block.cmi
3232
caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi
3333
caml_builtin_exceptions.cmx : caml_builtin_exceptions.cmi
3434
caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi
@@ -79,14 +79,14 @@ js_error.cmo :
7979
js_error.cmx :
8080
typed_array.cmo :
8181
typed_array.cmx :
82+
block.cmo : block.cmi
83+
block.cmj : block.cmi
8284
caml_array.cmo : js.cmo caml_array.cmi
8385
caml_array.cmj : js.cmj caml_array.cmi
8486
caml_backtrace.cmo : caml_backtrace.cmi
8587
caml_backtrace.cmj : caml_backtrace.cmi
8688
caml_bigarray.cmo : caml_bigarray.cmi
8789
caml_bigarray.cmj : caml_bigarray.cmi
88-
caml_block.cmo : caml_block.cmi
89-
caml_block.cmj : caml_block.cmi
9090
caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi
9191
caml_builtin_exceptions.cmj : caml_builtin_exceptions.cmi
9292
caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi

jscomp/runtime/block.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Generated CODE, PLEASE EDIT WITH CARE
2+
'use strict';
3+
4+
5+
function __(tag, block) {
6+
block.tag = tag;
7+
return block;
8+
}
9+
10+
exports.__ = __;
11+
/* No side effect */

jscomp/runtime/caml_block.ml jscomp/runtime/block.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121
(* Note that when we introduce it in {!Js_dump}
2222
we need introduce dependency properly *)
23-
let create tag block =
23+
let __ tag block =
2424
Obj.set_tag block tag; block

jscomp/runtime/caml_block.mli jscomp/runtime/block.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818

1919
(* Author: Hongbo Zhang *)
2020

21-
val create : int -> Obj.t -> Obj.t
21+
22+
val __ : int -> Obj.t -> Obj.t

jscomp/runtime/caml_obj.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");
5+
var Block = require("./block");
56

67
function caml_obj_dup(x) {
78
var len = x.length;
@@ -36,11 +37,7 @@ function caml_obj_truncate(x, new_size) {
3637
}
3738

3839
function caml_lazy_make_forward(x) {
39-
return {
40-
0: x,
41-
length: 1,
42-
tag: 250
43-
};
40+
return Block.__(250, [x]);
4441
}
4542

4643
function caml_update_dummy(x, y) {

jscomp/runtime/runtime.mllib

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ caml_utils
1010
caml_sys
1111
caml_io
1212
caml_float
13-
caml_block
13+
1414
caml_lexer
1515
caml_parser
1616
caml_primitive
@@ -29,3 +29,4 @@ fn
2929
js_error
3030
caml_curry
3131
curry
32+
block

0 commit comments

Comments
 (0)