Skip to content

Commit dc64e09

Browse files
authored
Merge pull request #4423 from BuckleScript/change_names
fix #4407 compatibility layer between debug mode and non-debug mode
2 parents 910baf6 + b4d92a9 commit dc64e09

Some content is hidden

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

73 files changed

+826
-616
lines changed

jscomp/core/js_dump.ml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
5151
*)
5252

53-
53+
let name_symbol = Js_op.Symbol_name
5454
module P = Ext_pp
5555
module E = Js_exp_make
5656
(* module S = Js_stmt_make *)
@@ -125,11 +125,11 @@ let exn_block_as_obj
125125
| _ -> assert false in
126126
Object (
127127
if stack then
128-
Ext_list.mapi_append el (fun i e -> field_name i, e)
129-
["Error",
128+
Ext_list.mapi_append el (fun i e -> Js_op.Lit (field_name i), e)
129+
[ Js_op.Lit "Error",
130130
E.new_ (E.js_global "Error") []
131131
]
132-
else Ext_list.mapi el (fun i e -> field_name i, e)
132+
else Ext_list.mapi el (fun i e -> Js_op.Lit (field_name i), e)
133133
)
134134

135135
let rec iter_lst cxt (f : P.t) ls element inter =
@@ -812,10 +812,13 @@ and expression_desc cxt ~(level:int) f x : cxt =
812812
E.runtime_call Js_runtime_modules.option "some" [e])
813813
| Caml_block(el,_, _, Blk_module fields) ->
814814
expression_desc cxt ~level f (Object (
815-
(Ext_list.map_combine fields el Ext_ident.convert)))
815+
(Ext_list.map_combine
816+
fields el
817+
(fun x -> Js_op.Lit (Ext_ident.convert x) ))))
816818
(*name convention of Record is slight different from modules*)
817819
| Caml_block(el,_, _, Blk_record fields) ->
818-
expression_desc cxt ~level f (Object ((Ext_list.combine_array fields el )))
820+
expression_desc cxt ~level f (Object
821+
((Ext_list.combine_array fields el (fun i -> Js_op.Lit i))))
819822

820823
| Caml_block(el,_,_, Blk_poly_var name) ->
821824
begin match el with
@@ -825,13 +828,13 @@ and expression_desc cxt ~(level:int) f x : cxt =
825828
~level
826829
f
827830
(Object
828-
((Literals.polyvar_hash,
831+
((Js_op.Lit Literals.polyvar_hash,
829832
if !Js_config.debug then hash
830833
else {hash with comment = Some name}
831834
) ::
832-
(Literals.polyvar_value, value) ::
835+
(Js_op.Lit Literals.polyvar_value, value) ::
833836
if !Js_config.debug then
834-
["name", E.str name]
837+
[name_symbol, E.str name]
835838
else []
836839
)
837840
)
@@ -843,11 +846,11 @@ and expression_desc cxt ~(level:int) f x : cxt =
843846
let objs =
844847
let tails =
845848
Ext_list.combine_array_append p.fields el
846-
(if !Js_config.debug then ["NAME",E.str p.name]
849+
(if !Js_config.debug then [name_symbol,E.str p.name]
847850
else []
848-
) in
851+
) (fun i -> Js_op.Lit i) in
849852
if p.num_nonconst = 1 then tails
850-
else (L.tag,
853+
else (Js_op.Lit L.tag,
851854
if !Js_config.debug then tag else {tag with comment = Some p.name}) :: tails in
852855
if p.num_nonconst = 1 && not !Js_config.debug then
853856
pp_comment_option f (Some p.name);
@@ -858,17 +861,17 @@ and expression_desc cxt ~(level:int) f x : cxt =
858861
let tails =
859862
Ext_list.mapi_append el (fun i e ->
860863
(match is_cons, i with
861-
| true, 0 -> Literals.hd
862-
| true, 1 -> Literals.tl
864+
| true, 0 -> Js_op.Lit Literals.hd
865+
| true, 1 -> Js_op.Lit Literals.tl
863866
| _ ->
864-
"_" ^ string_of_int i) , e )
867+
Js_op.Lit ("_" ^ string_of_int i)) , e )
865868
(if !Js_config.debug then
866-
["NAME", E.str p.name]
869+
[name_symbol, E.str p.name]
867870
else []) in
868871
if p.num_nonconst = 1 then
869872
tails
870873
else
871-
(L.tag,
874+
(Js_op.Lit L.tag,
872875
if !Js_config.debug then tag else {tag with comment = Some p.name}) :: tails
873876
in
874877
if p.num_nonconst = 1 && not !Js_config.debug

jscomp/core/js_dump_property.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ let property_access f s =
8787
Js_dump_string.pp_string f s
8888
end
8989

90-
let property_key f s =
91-
if obj_property_no_need_quot s then
92-
P.string f s
93-
else Js_dump_string.pp_string f s
90+
let property_key f (s : J.property_name) =
91+
match s with
92+
| Lit s ->
93+
if obj_property_no_need_quot s then
94+
P.string f s
95+
else Js_dump_string.pp_string f s
96+
| Symbol_name ->
97+
P.string f
98+
{|[Symbol.for("name")]|}

jscomp/core/js_dump_property.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ val property_access :
3131

3232
val property_key :
3333
Ext_pp.t ->
34-
string ->
34+
J.property_name ->
3535
unit

jscomp/core/js_op.ml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,10 @@ type property = Lam_compat.let_kind =
146146
| Variable
147147

148148

149-
type property_name = (* private *)
150-
(* TODO: FIXME [caml_uninitialized_obj] seems to be a bug*)
151-
(* | Key of *)
152-
string
153-
(* | Int_key of int *)
154-
(* | Tag *)
155-
(* | Length *)
156-
149+
type property_name =
150+
| Lit of string
151+
| Symbol_name
152+
157153
type 'a access =
158154
| Getter
159155
| Setter

jscomp/core/lam_compile_external_obj.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
4848
| [] , [] -> [], [], []
4949
| {obj_arg_label = Obj_label {name = label; }; obj_arg_type = Arg_cst cst } :: labels , args ->
5050
let accs, eff, assign = aux labels args in
51-
(label, Lam_compile_const.translate_arg_cst cst )::accs, eff, assign
51+
(Js_op.Lit label, Lam_compile_const.translate_arg_cst cst )::accs, eff, assign
5252
(* | {obj_arg_label = EmptyCst _ } :: rest , args -> assert false *)
5353
| {obj_arg_label = Obj_empty }::labels, arg::args
5454
-> (* unit type*)
@@ -63,7 +63,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
6363
| Splice2 _
6464
| Splice0 -> assert false
6565
| Splice1 x ->
66-
(label, x) :: accs , Ext_list.append new_eff eff , assign
66+
(Js_op.Lit label, x) :: accs , Ext_list.append new_eff eff , assign
6767
end (* evaluation order is undefined *)
6868

6969
| ({obj_arg_label = Obj_optional {name = label}; obj_arg_type } as arg_kind)::labels, arg::args
@@ -77,7 +77,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
7777
| Splice2 _
7878
| Splice0 -> assert false
7979
| Splice1 x ->
80-
(label, x) :: accs , Ext_list.append new_eff eff , assign
80+
(Js_op.Lit label, x) :: accs , Ext_list.append new_eff eff , assign
8181
end )
8282
~not_sure:(fun _ -> accs, eff , (arg_kind,arg)::assign )
8383
| {obj_arg_label = Obj_empty | Obj_label _ | Obj_optional _ } :: _ , [] -> assert false

jscomp/core/lam_convert.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ let prim = Lam.prim
3232
let lam_extension_id loc (head : Lam.t) =
3333
prim ~primitive:lam_caml_id ~args:[head] loc
3434

35+
let lazy_block_info : Lam_tag_info.t =
36+
Blk_record
37+
[|Literals.lazy_done;
38+
Literals.lazy_val|]
3539

3640
let unbox_extension info (args : Lam.t list) mutable_flag loc =
3741
prim ~primitive:(Pmakeblock (0,info,mutable_flag)) ~args loc
@@ -281,15 +285,15 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
281285
[ Lam.const Const_js_true ;
282286
result
283287
] in
284-
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY_DONE";"value"|],Mutable)) ~args loc
288+
prim ~primitive:(Pmakeblock (tag,lazy_block_info,Mutable)) ~args loc
285289
| [computation] ->
286290
let args =
287291
[ Lam.const Const_js_false ;
288292
(* FIXME: arity 0 does not get proper supported*)
289293
prim ~primitive:(Pjs_fn_make 0) ~args:[Lam.function_ ~arity:1 ~params:[Ident.create "param"] ~body:computation]
290294
loc
291295
] in
292-
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY_DONE";"value"|],Mutable)) ~args loc
296+
prim ~primitive:(Pmakeblock (tag,lazy_block_info,Mutable)) ~args loc
293297

294298
| _ -> assert false
295299
end

jscomp/ext/ext_list.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ let rec map_combine l1 l2 f =
7676
| (_, _) ->
7777
invalid_arg "Ext_list.map_combine"
7878

79-
let rec combine_array_unsafe arr l i j acc =
79+
let rec combine_array_unsafe arr l i j acc f =
8080
if i = j then acc
8181
else
8282
match l with
8383
| [] -> invalid_arg "Ext_list.combine"
8484
| h :: tl ->
85-
(Array.unsafe_get arr i , h) ::
86-
combine_array_unsafe arr tl (i + 1) j acc
85+
(f (Array.unsafe_get arr i) , h) ::
86+
combine_array_unsafe arr tl (i + 1) j acc f
8787

88-
let combine_array_append arr l acc =
88+
let combine_array_append arr l acc f =
8989
let len = Array.length arr in
90-
combine_array_unsafe arr l 0 len acc
90+
combine_array_unsafe arr l 0 len acc f
9191

92-
let combine_array arr l =
92+
let combine_array arr l f =
9393
let len = Array.length arr in
94-
combine_array_unsafe arr l 0 len []
94+
combine_array_unsafe arr l 0 len [] f
9595

9696
let rec map_split_opt
9797
(xs : 'a list) (f : 'a -> 'b option * 'c option)

jscomp/ext/ext_list.mli

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ val map_combine :
3737
val combine_array:
3838
'a array ->
3939
'b list ->
40-
('a * 'b) list
40+
('a -> 'c) ->
41+
('c * 'b) list
4142

4243
val combine_array_append:
4344
'a array ->
4445
'b list ->
45-
('a * 'b) list ->
46-
('a * 'b) list
46+
('c * 'b) list ->
47+
('a -> 'c) ->
48+
('c * 'b) list
4749

4850
val has_string :
4951
string list ->

jscomp/ext/literals.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ let ns_sep = "-"
142142
let exception_id = "RE_EXN_ID"
143143

144144
let polyvar_hash = "HASH"
145-
let polyvar_value = "value"
145+
let polyvar_value = "VAL"
146146

147147
let cons = "::"
148148
let hd = "hd"
149-
let tl = "tl"
149+
let tl = "tl"
150+
151+
let lazy_done = "LAZY_DONE"
152+
let lazy_val = "VAL"

jscomp/ext/literals.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ val polyvar_value : string
144144

145145
val cons : string
146146
val hd : string
147-
val tl : string
147+
val tl : string
148+
val lazy_done : string
149+
val lazy_val : string

0 commit comments

Comments
 (0)