@@ -34,23 +34,22 @@ module E = Js_exp_make
34
34
(* If it is the return value, since it is a side-effect call,
35
35
we return unit, otherwise just return it
36
36
*)
37
- let decorate_side_effect ( { continuation = st ;_} : Lam_compile_context.t ) e : E.t =
37
+ let ensure_value_unit ( st : Lam_compile_context.continuation ) e : E.t =
38
38
match st with
39
39
| EffectCall (ReturnTrue _ ) | NeedValue (ReturnTrue _)
40
40
| Assign _ | Declare _ | NeedValue _ -> E. seq e E. unit
41
41
| EffectCall ReturnFalse -> e
42
42
(* NeedValue should return a meaningful expression*)
43
43
44
44
let translate loc
45
- ({ meta = { env; _} ; _} as cxt : Lam_compile_context.t )
45
+ (cxt : Lam_compile_context.t )
46
46
(prim : Lam_primitive.t )
47
47
(args : J.expression list ) : J.expression =
48
48
match prim with
49
49
| Pis_not_none ->
50
- begin match args with
51
- | [arg] -> Js_of_lam_option. is_not_none arg
52
- | _ -> assert false
53
- end
50
+ (match args with
51
+ | [arg] -> Js_of_lam_option. is_not_none arg
52
+ | _ -> assert false )
54
53
| Pcreate_extension s
55
54
->
56
55
Js_of_lam_exception. make (E. str s)
@@ -63,42 +62,37 @@ let translate loc
63
62
| Praw_js_code_stmt s ->
64
63
E. raw_js_code Stmt s
65
64
| Pjs_runtime_apply ->
66
- begin match args with
67
- | [f ; args] ->
68
- E. flat_call f args
69
- | _ -> assert false
70
- end
65
+ (match args with
66
+ | [f ; args] ->
67
+ E. flat_call f args
68
+ | _ -> assert false )
71
69
| Pjs_apply ->
72
- begin match args with
73
- | fn :: rest ->
74
- E. call ~info: {arity= Full ; call_info = Call_na } fn rest
75
- | _ -> assert false
76
- end
77
-
70
+ (match args with
71
+ | fn :: rest ->
72
+ E. call ~info: {arity= Full ; call_info = Call_na } fn rest
73
+ | _ -> assert false )
78
74
| Pnull_to_opt ->
79
- begin match args with
80
- | [e] ->
81
- begin match e.expression_desc with
82
- | Var _ | Undefined | Null ->
83
- Js_of_lam_option. null_to_opt e
84
- | _ ->
85
- E. runtime_call Js_runtime_modules. js_primitive
86
- " null_to_opt" args
87
- end
88
- | _ -> assert false
89
- end
75
+ (match args with
76
+ | [e] ->
77
+ (match e.expression_desc with
78
+ | Var _ | Undefined | Null ->
79
+ Js_of_lam_option. null_to_opt e
80
+ | _ ->
81
+ E. runtime_call Js_runtime_modules. js_primitive
82
+ " null_to_opt" args)
83
+ | _ -> assert false )
84
+
90
85
| Pundefined_to_opt ->
91
- begin match args with
92
- | [e] ->
93
- begin match e.expression_desc with
94
- | Var _ | Undefined | Null ->
95
- Js_of_lam_option. undef_to_opt e
96
- | _ ->
97
- E. runtime_call Js_runtime_modules. js_primitive
98
- " undefined_to_opt" args
99
- end
100
- | _ -> assert false
101
- end
86
+ (match args with
87
+ | [e] ->
88
+ (match e.expression_desc with
89
+ | Var _ | Undefined | Null ->
90
+ Js_of_lam_option. undef_to_opt e
91
+ | _ ->
92
+ E. runtime_call Js_runtime_modules. js_primitive
93
+ " undefined_to_opt" args )
94
+ | _ -> assert false )
95
+
102
96
| Pnull_undefined_to_opt ->
103
97
begin match args with
104
98
| [e] ->
@@ -170,43 +164,43 @@ let translate loc
170
164
E. runtime_call Js_runtime_modules. module_ " update_mod" args
171
165
| Psome ->
172
166
begin match args with
173
- | [arg ] ->
174
- begin match arg.J. expression_desc with
175
- | Null
176
- | Object _
177
- | Number _
178
- | Caml_block _
179
- | Array _
180
- | Str _
181
- ->
182
- (* This makes sense when type info
183
- is not available at the definition
184
- site, and inline recovered it
185
- *)
186
- E. optional_not_nest_block arg
187
- | _ -> E. optional_block arg
188
- end
189
- | _ -> assert false
167
+ | [arg ] ->
168
+ begin match arg.J. expression_desc with
169
+ | Null
170
+ | Object _
171
+ | Number _
172
+ | Caml_block _
173
+ | Array _
174
+ | Str _
175
+ ->
176
+ (* This makes sense when type info
177
+ is not available at the definition
178
+ site, and inline recovered it
179
+ *)
180
+ E. optional_not_nest_block arg
181
+ | _ -> E. optional_block arg
182
+ end
183
+ | _ -> assert false
190
184
end
191
185
| Psome_not_nest ->
192
186
begin match args with
193
- | [arg] -> E. optional_not_nest_block arg
194
- | _ -> assert false
187
+ | [arg] -> E. optional_not_nest_block arg
188
+ | _ -> assert false
195
189
end
196
190
| Pmakeblock (tag , tag_info , mutable_flag ) -> (* RUNTIME *)
197
191
Js_of_lam_block. make_block
198
192
(Js_op_util. of_lam_mutable_flag mutable_flag)
199
193
tag_info (E. small_int tag) args
200
194
| Pval_from_option ->
201
195
begin match args with
202
- | [ e ] ->
203
- Js_of_lam_option. val_from_option e
204
- | _ -> assert false
196
+ | [ e ] ->
197
+ Js_of_lam_option. val_from_option e
198
+ | _ -> assert false
205
199
end
206
200
| Pval_from_option_not_nest ->
207
201
begin match args with
208
- | [ e ] -> e
209
- | _ -> assert false
202
+ | [ e ] -> e
203
+ | _ -> assert false
210
204
end
211
205
| Pfield (i , fld_info ) ->
212
206
begin match args with
@@ -583,17 +577,15 @@ let translate loc
583
577
*)
584
578
| Pbytessetu
585
579
| Pbytessets ->
586
- begin match args with
587
- | [e;e0;e1] -> decorate_side_effect cxt
588
- (Js_of_lam_string. set_byte e e0 e1)
589
-
590
- | _ -> assert false
591
- end
580
+ (match args with
581
+ | [e;e0;e1] -> ensure_value_unit cxt.continuation
582
+ (Js_of_lam_string. set_byte e e0 e1)
583
+ | _ -> assert false )
592
584
| Pbytesrefu ->
593
- begin match args with
594
- | [e;e1] -> Js_of_lam_string. ref_byte e e1
595
- | _ -> assert false
596
- end
585
+ ( match args with
586
+ | [e;e1] -> Js_of_lam_string. ref_byte e e1
587
+ | _ -> assert false )
588
+
597
589
598
590
| Pbytesrefs ->
599
591
begin match args with
@@ -633,48 +625,38 @@ let translate loc
633
625
| _ -> assert false
634
626
end
635
627
| Psetfield (i , field_info ) ->
636
- begin match args with
637
- | [e0;e1] -> (* * RUNTIME *)
638
- decorate_side_effect cxt
639
- (Js_of_lam_block. set_field field_info e0 (Int32. of_int i) e1)
640
- (* TODO: get rid of [E.unit ()]*)
641
- | _ -> assert false
642
- end
628
+ (match args with
629
+ | [e0;e1] -> (* * RUNTIME *)
630
+ ensure_value_unit cxt.continuation
631
+ (Js_of_lam_block. set_field field_info e0 (Int32. of_int i) e1)
632
+ (* TODO: get rid of [E.unit ()]*)
633
+ | _ -> assert false )
643
634
| Psetfloatfield (i,field_info)
644
635
-> (* * RUNTIME -- RETURN VALUE SHOULD BE UNIT *)
645
- begin
646
- match args with
647
- | [e;e0] ->
648
- decorate_side_effect cxt
649
- (Js_of_lam_float_record. set_double_field field_info e (Int32. of_int i) e0 )
650
- | _ -> assert false
651
- end
652
-
653
-
654
- | Pfloatfield (i , field_info ) -> (* * RUNTIME *)
655
- begin
656
- match args with
657
- | [e] ->
658
- Js_of_lam_float_record. get_double_feild field_info e
659
- (Int32. of_int i)
660
- | _ -> assert false
661
- end
662
- | Parrayrefu _kind ->
663
- begin match args with
664
- | [e;e1] -> Js_of_lam_array. ref_array e e1 (* Todo: Constant Folding *)
665
- | _ -> assert false
666
- end
667
- | Parrayrefs _kind ->
636
+ (match args with
637
+ | [e;e0] ->
638
+ ensure_value_unit cxt.continuation
639
+ (Js_of_lam_float_record. set_double_field field_info e (Int32. of_int i) e0 )
640
+ | _ -> assert false )
641
+ | Pfloatfield (i , field_info ) -> (* * RUNTIME *)
642
+ (match args with
643
+ | [e] ->
644
+ Js_of_lam_float_record. get_double_feild field_info e
645
+ (Int32. of_int i)
646
+ | _ -> assert false )
647
+ | Parrayrefu ->
648
+ (match args with
649
+ | [e;e1] -> Js_of_lam_array. ref_array e e1 (* Todo: Constant Folding *)
650
+ | _ -> assert false )
651
+ | Parrayrefs ->
668
652
Lam_dispatch_primitive. translate loc " caml_array_get" args
669
- | Pmakearray kind ->
670
- Js_of_lam_array. make_array Mutable kind args
671
- | Parraysetu _kind ->
672
- begin match args with (* wrong*)
673
- | [e;e0;e1] -> decorate_side_effect cxt @@ Js_of_lam_array. set_array e e0 e1
674
- | _ -> assert false
675
- end
676
-
677
- | Parraysets _kind ->
653
+ | Pmakearray _kind ->
654
+ Js_of_lam_array. make_array Mutable args
655
+ | Parraysetu ->
656
+ (match args with (* wrong*)
657
+ | [e;e0;e1] -> ensure_value_unit cxt.continuation (Js_of_lam_array. set_array e e0 e1)
658
+ | _ -> assert false )
659
+ | Parraysets ->
678
660
Lam_dispatch_primitive. translate loc " caml_array_set" args
679
661
| Pccall prim ->
680
662
Lam_dispatch_primitive. translate loc prim.prim_name args
@@ -780,12 +762,11 @@ let translate loc
780
762
| Pstring_load_64 unsafe
781
763
-> Js_long. get64 args
782
764
783
- | Plazyforce
784
- (* | Plazyforce -> *)
785
- (* let parm = Ident.create "prim" in *)
786
- (* Lfunction(Curried, [parm], *)
787
- (* Matching.inline_lazy_force (Lvar parm) Location.none) *)
788
- (* It is inlined, this should not appear here *)
765
+ | Plazyforce
766
+ (* let parm = Ident.create "prim" in
767
+ Lfunction(Curried, [parm],
768
+ Matching.inline_lazy_force (Lvar parm) Location.none)
769
+ It is inlined, this should not appear here *)
789
770
| Pbittest
790
771
791
772
| Pstring_set_16 _
0 commit comments