File tree Expand file tree Collapse file tree 9 files changed +22
-21
lines changed Expand file tree Collapse file tree 9 files changed +22
-21
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ type primitive =
46
46
(* Globals *)
47
47
| Pgetglobal of ident
48
48
| Psetglobal of ident
49
+ | Pglobal_exception of ident
49
50
(* Operations on heap blocks *)
50
51
| Pmakeblock of int * tag_info * mutable_flag
51
52
| Pfield of int * field_dbg_info
@@ -553,7 +554,11 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args : t =
553
554
| _ -> assert false
554
555
end
555
556
| Ploc loc -> assert false (* already compiled away here*)
556
- | Pgetglobal id -> prim ~primitive: (Pgetglobal id) ~args
557
+ | Pgetglobal id ->
558
+ if Ident. is_predef_exn id then
559
+ prim ~primitive: (Pglobal_exception id) ~args
560
+ else
561
+ prim ~primitive: (Pgetglobal id) ~args
557
562
| Psetglobal id -> prim ~primitive: (Psetglobal id) ~args
558
563
| Pmakeblock (tag,info, mutable_flag)
559
564
-> prim ~primitive: (Pmakeblock (tag,info,mutable_flag)) ~args
@@ -592,7 +597,7 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args : t =
592
597
begin match args with
593
598
| [Lprim {primitive = Pmakeblock (0 , _, _) ;
594
599
args = [
595
- Lprim {primitive = Pgetglobal ({name = " Assert_failure" } as id); args = [] };
600
+ Lprim {primitive = Pglobal_exception ({name = " Assert_failure" } as id); args = [] };
596
601
_
597
602
]
598
603
} ] when Ident. global id
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ type primitive =
51
51
| Pbytes_of_string
52
52
| Pgetglobal of ident
53
53
| Psetglobal of ident
54
+ | Pglobal_exception of ident
54
55
| Pmakeblock of int * Lambda .tag_info * Asttypes .mutable_flag
55
56
| Pfield of int * Lambda .field_dbg_info
56
57
| Psetfield of int * bool * Lambda .set_field_dbg_info
Original file line number Diff line number Diff line change @@ -72,7 +72,8 @@ let rec no_side_effects (lam : Lam.t) : bool =
72
72
73
73
74
74
75
- | Pgetglobal _
75
+ | Pgetglobal _
76
+ | Pglobal_exception _
76
77
| Pmakeblock _ (* whether it's mutable or not *)
77
78
| Pfield _
78
79
| Pfloatfield _
@@ -188,7 +189,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
188
189
args = [Lconst _]; _},exn ,
189
190
Lifthenelse (Lprim {args =
190
191
[Lvar exn1;
191
- Lprim {primitive = Pgetglobal ({name= " Not_found" }); args = [] ; _}]
192
+ Lprim {primitive = Pglobal_exception ({name= " Not_found" }); args = [] ; _}]
192
193
; _},
193
194
then_, _)) when Ident. same exn1 exn
194
195
(* * we might put this in an optimization pass
Original file line number Diff line number Diff line change @@ -1464,7 +1464,7 @@ and
1464
1464
Lifthenelse
1465
1465
(Lprim {primitive = Pintcomp (Ceq );
1466
1466
args = [Lvar id2 ;
1467
- Lprim {primitive = Pgetglobal {name = " Not_found" }; _}]},
1467
+ Lprim {primitive = Pglobal_exception {name = " Not_found" }; _}]},
1468
1468
cont, _reraise )
1469
1469
)
1470
1470
| Ltrywith (
@@ -1473,7 +1473,7 @@ and
1473
1473
id,
1474
1474
Lifthenelse (Lprim {primitive = Pintcomp (Ceq );
1475
1475
args = [
1476
- Lprim { primitive = Pgetglobal {name = " Not_found" ; _}; _}; Lvar id2 ]},
1476
+ Lprim { primitive = Pglobal_exception {name = " Not_found" ; _}; _}; Lvar id2 ]},
1477
1477
cont, _reraise )
1478
1478
)) when Ident. same id id2
1479
1479
->
Original file line number Diff line number Diff line change @@ -63,10 +63,7 @@ let query_lambda id env =
63
63
let get_exp (key : Lam_compile_env.key ) : J.expression =
64
64
match key with
65
65
(id , env , expand ) ->
66
- if Ident. is_predef_exn id
67
- then Js_of_lam_exception. get_builtin_by_name id.name
68
- else
69
- Lam_compile_env. query_and_add_if_not_exist
66
+ Lam_compile_env. query_and_add_if_not_exist
70
67
(Lam_module_ident. of_ml id)
71
68
(Has_env env)
72
69
~not_found: (fun id -> assert false )
Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ let translate
54
54
| Pjs_fn_runmethod _
55
55
-> assert false (* already handled by {!Lam_compile} *)
56
56
| Pjs_fn_method _ -> assert false
57
+ | Pglobal_exception id ->
58
+ Js_of_lam_exception. get_builtin_by_name id.name
57
59
| Pstringadd ->
58
60
begin match args with
59
61
| [a;b] ->
Original file line number Diff line number Diff line change @@ -131,10 +131,7 @@ let collect_helper (meta : Lam_stats.meta) (lam : Lam.t) =
131
131
132
132
and collect (lam : Lam.t ) =
133
133
match lam with
134
- (* | Lprim (Pgetglobal ident ,[] ) * )
135
- (* -> *)
136
- (* if not @@ Ident.is_predef_exn ident then *)
137
- (* Lam_util.add_required_module ident meta *)
134
+
138
135
(** TODO:
139
136
how about module aliases..
140
137
record dependency
Original file line number Diff line number Diff line change @@ -111,6 +111,8 @@ let primitive ppf (prim : Lam.primitive) = match prim with
111
111
| Pjs_fn_runmethod i -> fprintf ppf " js_fn_runmethod_%i" i
112
112
| Pdebugger -> fprintf ppf " debugger"
113
113
| Pgetglobal id -> fprintf ppf " global %a" Ident. print id
114
+ | Pglobal_exception id ->
115
+ fprintf ppf " global exception %a" Ident. print id
114
116
| Psetglobal id -> fprintf ppf " setglobal %a" Ident. print id
115
117
| Pmakeblock (tag , _ , Immutable) -> fprintf ppf " makeblock %i" tag
116
118
| Pmakeblock (tag , _ , Mutable) -> fprintf ppf " makemutable %i" tag
Original file line number Diff line number Diff line change @@ -65,16 +65,12 @@ let sort_dag_args param_args =
65
65
66
66
67
67
let add_required_module (x : Ident.t ) (meta : Lam_stats.meta ) =
68
- if not @@ Ident. is_predef_exn x then
69
- meta.required_modules < - Lam_module_ident. of_ml x :: meta.required_modules
68
+ meta.required_modules < - Lam_module_ident. of_ml x :: meta.required_modules
70
69
71
70
let add_required_modules ( x : Ident.t list ) (meta : Lam_stats.meta ) =
72
71
let required_modules =
73
- Ext_list. filter_map
74
- (fun x ->
75
- if Ident. is_predef_exn x then
76
- None
77
- else Some ( Lam_module_ident. of_ml x)) x
72
+ List. map
73
+ (fun x -> Lam_module_ident. of_ml x) x
78
74
@ meta.required_modules in
79
75
meta.required_modules < - required_modules
80
76
You can’t perform that action at this time.
0 commit comments