Skip to content

Commit e984329

Browse files
authored
Merge pull request #440 from bloomberg/bs_lambda
provide indirection for lambda -> bs_lambda
2 parents 285ae6e + cfc6dcf commit e984329

Some content is hidden

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

56 files changed

+2684
-1272
lines changed

jscomp/bin/compiler.ml

Lines changed: 1524 additions & 814 deletions
Large diffs are not rendered by default.

jscomp/compiler.odocl

Lines changed: 0 additions & 1 deletion
This file was deleted.

jscomp/core.mllib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ config_util
77

88

99

10-
10+
lam
1111
lam_mk
12-
lam_comb
12+
lam_print
1313
lam_compile_env
1414
lam_dispatch_primitive
1515
lam_stats

jscomp/js_cmj_format.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
(* TODO: add a magic number *)
3333
type cmj_value = {
3434
arity : Lam_stats.function_arities ;
35-
closed_lambda : Lambda.lambda option ;
35+
closed_lambda : Lam.t option ;
3636
(** Either constant or closed functor *)
3737
}
3838

jscomp/js_cmj_format.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
type cmj_value = {
5656
arity : Lam_stats.function_arities ;
57-
closed_lambda : Lambda.lambda option ;
57+
closed_lambda : Lam.t option ;
5858
(* Either constant or closed functor *)
5959
}
6060

jscomp/js_implementation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let implementation ppf sourcefile outputprefix =
7676
match
7777
Lam_compile_group.lambda_as_module
7878
finalenv current_signature
79-
sourcefile outputprefix lambda with
79+
sourcefile outputprefix ((* Obj.magic *) lambda ) with
8080
| e -> e
8181
| exception e ->
8282
(* Save to a file instead so that it will not scare user *)

jscomp/js_output.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ let handle_name_tail
8080
let handle_block_return
8181
(st : st)
8282
(should_return : Lam_compile_defs.return_type)
83-
(lam : Lambda.lambda) (block : J.block) exp : t =
83+
(lam : Lam.t) (block : J.block) exp : t =
8484
match st, should_return with
8585
| Declare (kind,n), False ->
8686
make (block @ [ S.define ~kind n exp])

jscomp/js_output.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ val dummy : t
6868
val handle_name_tail :
6969
Lam_compile_defs.st ->
7070
Lam_compile_defs.return_type ->
71-
Lambda.lambda -> J.expression -> t
71+
Lam.t -> J.expression -> t
7272

7373
val handle_block_return :
7474
Lam_compile_defs.st ->
7575
Lam_compile_defs.return_type ->
76-
Lambda.lambda ->
76+
Lam.t ->
7777
J.block -> J.expression -> t
7878

7979
val concat : t list -> t

jscomp/js_stmt_make.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ let try_ ?comment ?with_ ?finally body : t =
347347
comment
348348
}
349349

350-
let unknown_lambda ?(comment="unknown") (lam : Lambda.lambda ) : t =
350+
let unknown_lambda ?(comment="unknown") (lam : Lam.t ) : t =
351351
exp @@ E.str ~comment ~pure:false (Lam_util.string_of_lambda lam)
352352

353353
(* TODO:

jscomp/js_stmt_make.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ val exp : ?comment:string -> J.expression -> t
9595

9696
val return : ?comment:string -> J.expression -> t
9797

98-
val unknown_lambda : ?comment:string -> Lambda.lambda -> t
98+
val unknown_lambda : ?comment:string -> Lam.t -> t
9999

100100
val return_unit : ?comment:string -> unit -> t
101101
(** for ocaml function which returns unit

jscomp/lam_comb.ml renamed to jscomp/lam.ml

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,40 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
26-
27-
28-
29-
type t = Lambda.lambda
30-
31-
type binop = t -> t -> t
32-
33-
type triop = t -> t -> t -> t
34-
35-
type unop = t -> t
36-
25+
type primitive = Lambda.primitive
26+
type switch = Lambda.lambda_switch =
27+
{ sw_numconsts: int;
28+
sw_consts: (int * t) list;
29+
sw_numblocks: int;
30+
sw_blocks: (int * t) list;
31+
sw_failaction : t option}
32+
and t = Lambda.lambda =
33+
| Lvar of Ident.t
34+
| Lconst of Lambda.structured_constant
35+
| Lapply of t * t list * Lambda.apply_info
36+
| Lfunction of Lambda.function_kind * Ident.t list * t
37+
| Llet of Lambda.let_kind * Ident.t * t * t
38+
| Lletrec of (Ident.t * t) list * t
39+
| Lprim of primitive * t list
40+
| Lswitch of t * switch
41+
| Lstringswitch of t * (string * t) list * t option
42+
| Lstaticraise of int * t list
43+
| Lstaticcatch of t * (int * Ident.t list) * t
44+
| Ltrywith of t * Ident.t * t
45+
| Lifthenelse of t * t * t
46+
| Lsequence of t * t
47+
| Lwhile of t * t
48+
| Lfor of Ident.t * t * t * Asttypes.direction_flag * t
49+
| Lassign of Ident.t * t
50+
| Lsend of Lambda.meth_kind * t * t * t list * Location.t
51+
| Levent of t * Lambda.lambda_event
52+
| Lifused of Ident.t * t
3753

3854

3955
module Prim = struct
40-
type t = Lambda.primitive
56+
type t = primitive
4157
let js_is_nil : t =
42-
Lambda.Pccall{ prim_name = "js_is_nil";
58+
Pccall{ prim_name = "js_is_nil";
4359
prim_arity = 1 ;
4460
prim_alloc = false;
4561
prim_native_name = "js_is_nil";
@@ -49,7 +65,7 @@ module Prim = struct
4965
}
5066

5167
let js_is_undef : t =
52-
Lambda.Pccall{ prim_name = "js_is_undef";
68+
Pccall{ prim_name = "js_is_undef";
5369
prim_arity = 1 ;
5470
prim_alloc = false;
5571
prim_native_name = "js_is_undef";
@@ -59,7 +75,7 @@ module Prim = struct
5975
}
6076

6177
let js_is_nil_undef : t =
62-
Lambda.Pccall{ prim_name = "js_is_nil_undef";
78+
Pccall{ prim_name = "js_is_nil_undef";
6379
prim_arity = 1 ;
6480
prim_alloc = false;
6581
prim_native_name = "js_is_nil_undef";
@@ -70,6 +86,29 @@ module Prim = struct
7086

7187
end
7288

89+
90+
91+
92+
93+
94+
type binop = t -> t -> t
95+
96+
type triop = t -> t -> t -> t
97+
98+
type unop = t -> t
99+
100+
101+
let var id : t = Lvar id
102+
let const ct : t = Lconst ct
103+
let apply fn args info : t = Lapply(fn,args, info)
104+
let function_ kind ids body : t =
105+
Lfunction(kind, ids, body)
106+
107+
let let_ kind id e body : t
108+
= Llet (kind,id,e,body)
109+
let letrec bindings body : t =
110+
Lletrec(bindings,body)
111+
73112
let if_ (a : t) (b : t) c =
74113
match a with
75114
| Lconst v ->
@@ -328,3 +367,8 @@ let prim (prim : Prim.t) (ll : t list) : t =
328367

329368
let not x : t =
330369
prim Pnot [x]
370+
371+
372+
let free_variables = Lambda.free_variables
373+
374+
let subst_lambda = Lambda.subst_lambda

jscomp/lam_comb.mli renamed to jscomp/lam.mli

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,60 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
type primitive = Lambda.primitive
26+
27+
28+
type switch = Lambda.lambda_switch =
29+
{ sw_numconsts: int;
30+
sw_consts: (int * t) list;
31+
sw_numblocks: int;
32+
sw_blocks: (int * t) list;
33+
sw_failaction : t option}
34+
and t = Lambda.lambda = private
35+
| Lvar of Ident.t
36+
| Lconst of Lambda.structured_constant
37+
| Lapply of t * t list * Lambda.apply_info
38+
| Lfunction of Lambda.function_kind * Ident.t list * t
39+
| Llet of Lambda.let_kind * Ident.t * t * t
40+
| Lletrec of (Ident.t * t) list * t
41+
| Lprim of primitive * t list
42+
| Lswitch of t * switch
43+
| Lstringswitch of t * (string * t) list * t option
44+
| Lstaticraise of int * t list
45+
| Lstaticcatch of t * (int * Ident.t list) * t
46+
| Ltrywith of t * Ident.t * t
47+
| Lifthenelse of t * t * t
48+
| Lsequence of t * t
49+
| Lwhile of t * t
50+
| Lfor of Ident.t * t * t * Asttypes.direction_flag * t
51+
| Lassign of Ident.t * t
52+
| Lsend of Lambda.meth_kind * t * t * t list * Location.t
53+
| Levent of t * Lambda.lambda_event
54+
| Lifused of Ident.t * t
55+
56+
57+
module Prim : sig
58+
type t = primitive
59+
val js_is_nil : t
60+
val js_is_undef : t
61+
val js_is_nil_undef : t
62+
end
2563

26-
type t = Lambda.lambda
2764

2865
type binop = t -> t -> t
2966

3067
type triop = t -> t -> t -> t
3168

3269
type unop = t -> t
3370

71+
val var : Ident.t -> t
72+
val const : Lambda.structured_constant -> t
73+
val apply : t -> t list -> Lambda.apply_info -> t
74+
val function_ : Lambda.function_kind -> Ident.t list -> t -> t
75+
val let_ : Lambda.let_kind -> Ident.t -> t -> t -> t
76+
val letrec : (Ident.t * t) list -> t -> t
3477
val if_ : triop
35-
val switch : t -> Lambda.lambda_switch -> t
78+
val switch : t -> switch -> t
3679
val stringswitch : t -> (string * t) list -> t option -> t
3780

3881
val true_ : t
@@ -65,9 +108,6 @@ val for_ :
65108
t ->
66109
t -> Asttypes.direction_flag -> t -> t
67110

68-
module Prim : sig
69-
type t = Lambda.primitive
70-
val js_is_nil : t
71-
val js_is_undef : t
72-
val js_is_nil_undef : t
73-
end
111+
val free_variables : t -> Lambda.IdentSet.t
112+
113+
val subst_lambda : t Ident.tbl -> t -> t

jscomp/lam_analysis.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929

30-
let rec no_side_effects (lam : Lambda.lambda) : bool =
30+
let rec no_side_effects (lam : Lam.t) : bool =
3131
match lam with
3232
| Lvar _
3333
| Lconst _
@@ -227,7 +227,7 @@ let really_big () = raise Too_big_to_inline
227227

228228
let big_lambda = 1000
229229

230-
let rec size (lam : Lambda.lambda) =
230+
let rec size (lam : Lam.t) =
231231
try
232232
match lam with
233233
| Lvar _ -> 1
@@ -277,7 +277,7 @@ and size_constant x =
277277
-> List.fold_left (fun acc x -> acc + size_constant x ) 0 str
278278
| Const_float_array xs -> List.length xs
279279

280-
and size_lams acc (lams : Lambda.lambda list) =
280+
and size_lams acc (lams : Lam.t list) =
281281
List.fold_left (fun acc l -> acc + size l ) acc lams
282282

283283
let exit_inline_size = 7
@@ -286,7 +286,7 @@ let small_inline_size = 5
286286
Actually this patten is quite common in GADT, people have to write duplicated code
287287
due to the type system restriction
288288
*)
289-
let rec eq_lambda (l1 : Lambda.lambda) (l2 : Lambda.lambda) =
289+
let rec eq_lambda (l1 : Lam.t) (l2 : Lam.t) =
290290
match (l1, l2) with
291291
| Lvar i1, Lvar i2 -> Ident.same i1 i2
292292
| Lconst c1, Lconst c2 -> c1 = c2 (* *)
@@ -393,7 +393,7 @@ let free_variables (export_idents : Ident_set.t ) (params : stats Ident_map.t )
393393
else { env with top = false}
394394
else env
395395
in
396-
let rec iter (top : env) (lam : Lambda.lambda) =
396+
let rec iter (top : env) (lam : Lam.t) =
397397
match lam with
398398
| Lvar v -> map_use top v
399399
| Lconst _ -> ()
@@ -495,7 +495,7 @@ let is_closed_with_map exports params body =
495495
(* TODO: We can relax this a bit later,
496496
but decide whether to inline it later in the call site
497497
*)
498-
let safe_to_inline (lam : Lambda.lambda) =
498+
let safe_to_inline (lam : Lam.t) =
499499
match lam with
500500
| Lfunction _ -> true
501501
| Lconst (Const_pointer _ | Const_immstring _ ) -> true

jscomp/lam_analysis.mli

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
(** A module which provides some basic analysis over lambda expression *)
3131

3232
(** No side effect, but it might depend on data store *)
33-
val no_side_effects : Lambda.lambda -> bool
33+
val no_side_effects : Lam.t -> bool
3434

35-
val size : Lambda.lambda -> int
35+
val size : Lam.t -> int
3636

37-
val eq_lambda : Lambda.lambda -> Lambda.lambda -> bool
37+
val eq_lambda : Lam.t -> Lam.t -> bool
3838
(** a conservative version of comparing two lambdas, mostly
3939
for looking for similar cases in switch
4040
*)
4141

4242
(** [is_closed_by map lam]
4343
return [true] if all unbound variables
4444
belongs to the given [map] *)
45-
val is_closed_by : (* Lambda. *) Ident_set.t -> Lambda.lambda -> bool
45+
val is_closed_by : (* Lambda. *) Ident_set.t -> Lam.t -> bool
4646

47-
val is_closed : Lambda.lambda -> bool
47+
val is_closed : Lam.t -> bool
4848

4949

5050

@@ -67,14 +67,14 @@ type stats =
6767

6868
val is_closed_with_map :
6969
Ident_set.t ->
70-
Ident.t list -> Lambda.lambda -> bool * stats Ident_map.t
70+
Ident.t list -> Lam.t -> bool * stats Ident_map.t
7171

7272
val param_map_of_list : Ident.t list -> stats Ident_map.t
7373

74-
val free_variables : Ident_set.t -> stats Ident_map.t -> Lambda.lambda -> stats Ident_map.t
74+
val free_variables : Ident_set.t -> stats Ident_map.t -> Lam.t -> stats Ident_map.t
7575

7676
val small_inline_size : int
7777
val exit_inline_size : int
7878

7979

80-
val safe_to_inline : Lambda.lambda -> bool
80+
val safe_to_inline : Lam.t -> bool

0 commit comments

Comments
 (0)