Skip to content

Commit 55ad3c1

Browse files
committed
seperate chrome runtime support for normal block support
1 parent e870ed9 commit 55ad3c1

8 files changed

+280
-209
lines changed

jscomp/core/js_block_runtime.ml

+17-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let tag_is_zero (tag : J.expression) =
2828
| Number (Int {i = 0l; _}) -> true
2929
| _ -> false;;
3030

31-
let needBlockRuntimeInDebugMode
31+
let needChromeRuntime
3232
(tag : J.expression)
3333
(tag_info : J.tag_info) =
3434
match tag_info with
@@ -48,7 +48,7 @@ let tag_is_zero (tag : J.expression) =
4848
| Blk_extension_slot -> false
4949
| Blk_na -> not (tag_is_zero tag )
5050

51-
let needBlockRuntimeInReleaseMode (tag : J.expression) (tag_info : J.tag_info) =
51+
let needBlockRuntime (tag : J.expression) (tag_info : J.tag_info) =
5252
match tag_info with
5353
| Blk_variant _
5454
| Blk_module _
@@ -69,31 +69,34 @@ let needBlockRuntimeInReleaseMode (tag : J.expression) (tag_info : J.tag_info) =
6969
#end
7070
| Blk_extension_slot -> false
7171
(* converted to [Pcreate_extension] in the beginning*)
72-
73-
74-
(* Used to decide whether we should add [require('block')]*)
75-
let needBlockRuntime tag info =
76-
if !Js_config.debug then
77-
needBlockRuntimeInDebugMode tag info
78-
else needBlockRuntimeInReleaseMode tag info
79-
80-
8172

8273
let option_id =
8374
Ident.create_persistent Js_runtime_modules.option
8475
let curry_id =
8576
Ident.create_persistent Js_runtime_modules.curry
8677
let block_id =
8778
Ident.create_persistent Js_runtime_modules.block
79+
let caml_chrome_id =
80+
Ident.create_persistent Js_runtime_modules.caml_chrome_block
8881

8982
let check_additional_id (x : J.expression) =
9083
match x.expression_desc with
9184
| Optional_block(_,false) ->
9285
Some option_id
9386
| Call(_, _, {arity = NA}) ->
9487
Some curry_id
95-
| Caml_block(_,_,tag,tag_info) when
96-
needBlockRuntime tag tag_info ->
97-
Some block_id
88+
| Caml_block(_,_,tag,tag_info)
89+
->
90+
if not !Js_config.debug then
91+
if needBlockRuntime tag tag_info then
92+
Some block_id
93+
else None
94+
else
95+
if needChromeRuntime tag tag_info then
96+
(* This may depends on two modules, so in the runtime
97+
we let chrome depends on block
98+
*)
99+
Some caml_chrome_id
100+
else None
98101
| _ ->
99102
None

jscomp/core/js_block_runtime.mli

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@
2525
val tag_is_zero :
2626
J.expression -> bool
2727

28-
val needBlockRuntime:
28+
val needChromeRuntime:
2929
J.expression ->
3030
J.tag_info ->
31-
bool
31+
bool
32+
33+
val needBlockRuntime:
34+
J.expression ->
35+
J.tag_info ->
36+
bool
3237

3338
val check_additional_id :
3439
J.expression -> Ident.t option

jscomp/core/js_dump.ml

+68-54
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,40 @@ module Curry_gen = struct
9595
P.string f (Printf.sprintf "%d" len)
9696
end
9797

98-
let pp_block_dot f =
98+
let block_dot f =
9999
P.string f Js_runtime_modules.block;
100100
P.string f L.dot
101101

102102
let pp_block_create f =
103-
pp_block_dot f ;
103+
block_dot f ;
104104
P.string f L.caml_block_create
105105

106-
let pp_block_record f =
107-
pp_block_dot f ;
106+
let dbg_block_dot f =
107+
P.string f Js_runtime_modules.caml_chrome_block;
108+
P.string f L.dot
109+
110+
let dbg_block_create f =
111+
dbg_block_dot f ;
112+
P.string f L.caml_block_create
113+
114+
let dbg_record f =
115+
dbg_block_dot f ;
108116
P.string f L.block_record
109117

110118
let dbg_local_module f =
111-
pp_block_dot f;
119+
dbg_block_dot f;
112120
P.string f L.block_local_module
113121

114122
let dbg_poly_var f =
115-
pp_block_dot f;
123+
dbg_block_dot f;
116124
P.string f L.block_poly_var
117125

118126
let dbg_simple_variant f =
119-
pp_block_dot f ;
127+
dbg_block_dot f ;
120128
P.string f L.block_simple_variant
121129

122130
let dbg_variant f =
123-
pp_block_dot f ;
131+
dbg_block_dot f ;
124132
P.string f L.block_variant
125133

126134

@@ -860,56 +868,62 @@ and expression_desc cxt (level:int) f x : cxt =
860868
as an array, note exception or open variant it is outer-most is
861869
simply an array
862870
*)
863-
let needBlockRuntime = Js_block_runtime.needBlockRuntime tag tag_info in
864-
let is_debug = !Js_config.debug in
865-
if not needBlockRuntime then
866-
expression_desc cxt level f (Array (el, mutable_flag))
867-
else (
868-
match tag_info with
869-
| Blk_record labels ->
870-
pp_block_record f ;
871-
P.paren_group f 1 (fun _ -> arguments cxt f
872-
[E.array Immutable
873-
(Ext_array.to_list_f E.str labels);
874-
E.array mutable_flag
875-
(Ext_list.map el drop_comment) ]
876-
)
877-
| Blk_module (Some labels) ->
878-
dbg_local_module f;
879-
P.paren_group f 1 (fun _ -> arguments cxt f
880-
[E.array Immutable
881-
(Ext_list.map labels E.str);
882-
E.array mutable_flag
883-
(Ext_list.map el drop_comment)])
884-
| Blk_variant name ->
885-
dbg_poly_var f;
886-
P.paren_group f 1 (fun _ -> arguments cxt f [
887-
E.str name;
888-
E.array mutable_flag el])
889-
| Blk_constructor(name,number) when number = 1 && Js_block_runtime.tag_is_zero tag
890-
-> (* has to be debug mode *)
891-
dbg_simple_variant f ;
892-
P.paren_group f 1 (fun _ -> arguments cxt f
893-
[E.str name; E.array mutable_flag el])
894-
| Blk_constructor(name,number) when is_debug ->
895-
dbg_variant f ;
896-
P.paren_group f 1 (fun _ -> arguments cxt f
897-
[ E.str name; tag ; E.array mutable_flag el])
871+
if not !Js_config.debug then begin
872+
if not (Js_block_runtime.needBlockRuntime tag tag_info) then
873+
expression_desc cxt level f (Array (el, mutable_flag))
874+
else
875+
begin
876+
pp_block_create f;
877+
P.paren_group f 1 (fun _ -> arguments cxt f [tag; E.array mutable_flag el])
878+
end
879+
end
880+
else
881+
if not (Js_block_runtime.needChromeRuntime tag tag_info) then
882+
expression_desc cxt level f (Array (el, mutable_flag))
883+
else
884+
(
885+
match tag_info with
886+
| Blk_record labels ->
887+
dbg_record f ;
888+
P.paren_group f 1 (fun _ -> arguments cxt f
889+
[E.array Immutable
890+
(Ext_array.to_list_f E.str labels);
891+
E.array mutable_flag
892+
(Ext_list.map el drop_comment) ]
893+
)
894+
| Blk_module (Some labels) ->
895+
dbg_local_module f;
896+
P.paren_group f 1 (fun _ -> arguments cxt f
897+
[E.array Immutable
898+
(Ext_list.map labels E.str);
899+
E.array mutable_flag
900+
(Ext_list.map el drop_comment)])
901+
| Blk_variant name ->
902+
dbg_poly_var f;
903+
P.paren_group f 1 (fun _ -> arguments cxt f [
904+
E.str name;
905+
E.array mutable_flag el])
906+
| Blk_constructor(name,number)
907+
908+
-> (* has to be debug mode *)
909+
(if number = 1 && Js_block_runtime.tag_is_zero tag then
910+
dbg_simple_variant f
911+
else dbg_variant f) ;
912+
P.paren_group f 1 (fun _ -> arguments cxt f
913+
[E.str name; E.array mutable_flag el])
898914
#if OCAML_VERSION =~ ">4.03.0" then
899-
| Blk_record_inlined _ (* TODO: No support for debug mode yet *)
915+
| Blk_record_inlined _ (* TODO: No support for debug mode yet *)
900916
#end
901-
| Blk_constructor _
902-
| Blk_tuple
903-
| Blk_array
917+
| Blk_tuple
918+
| Blk_array
904919
#if OCAML_VERSION =~ ">4.03.0" then
905-
| Blk_record_ext _
920+
| Blk_record_ext _
906921
#end
907-
| Blk_extension_slot
908-
| Blk_na
909-
| Blk_module None ->
910-
pp_block_create f;
911-
P.paren_group f 1 (fun _ -> arguments cxt f [tag; E.array mutable_flag el])
912-
922+
| Blk_extension_slot
923+
| Blk_na
924+
| Blk_module None ->
925+
dbg_block_create f;
926+
P.paren_group f 1 (fun _ -> arguments cxt f [tag; E.array mutable_flag el])
913927
)
914928

915929
| Caml_block_tag e ->

jscomp/runtime/caml_chrome_debugger.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ external cacheSymbol : string -> symbol = "for"
205205
external addProp : 'a -> symbol -> <value: 'b> Js.t -> 'a =
206206
"defineProperty" [@@bs.scope "Object"] [@@bs.val]
207207

208-
208+
let __ = Block.__
209209
(* It won't affect [Object.keys] using [Object.defineProperty*)
210210
let record meta xs =
211211
setupOnce ();

jscomp/runtime/caml_chrome_debugger.mli

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
type obj = Caml_obj_extern.t
2626

27+
val __ : int -> obj -> obj
2728
val record : 'a -> obj -> obj
2829

2930
val variant : 'a -> int -> obj -> obj

0 commit comments

Comments
 (0)