Skip to content

Commit 37d8829

Browse files
committed
start support currying
1 parent b108b85 commit 37d8829

File tree

104 files changed

+2530
-2137
lines changed

Some content is hidden

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

104 files changed

+2530
-2137
lines changed

jscomp/js_config.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,27 @@ let runtime_set = String_set.of_list [
102102
"caml_lexer.js";
103103
"caml_string.js"
104104
]
105+
106+
107+
let prim = "Caml_primitive"
108+
109+
let exceptions = "Caml_exceptions"
110+
111+
let io = "Caml_io"
112+
113+
let sys = "Caml_sys"
114+
115+
let lex_parse = "Caml_lexer"
116+
117+
let obj_runtime = "Caml_obj_runtime"
118+
119+
let array = "Caml_array"
120+
121+
let format = "Caml_format"
122+
123+
let string = "Caml_string"
124+
125+
let float = "Caml_float"
126+
127+
let oo = "Caml_oo"
128+
let curry = "Caml_curry"

jscomp/js_config.mli

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,29 @@ val set_env : env -> unit
3030
val runtime_set : String_set.t
3131
val stdlib_set : String_set.t
3232

33+
val prim : string
34+
35+
val exceptions : string
36+
37+
val io : string
38+
39+
val oo : string
40+
41+
val sys : string
42+
43+
val lex_parse : string
44+
45+
val obj_runtime : string
46+
47+
val array : string
48+
49+
val format : string
50+
51+
val string : string
52+
53+
val float : string
54+
55+
val curry : string
56+
57+
3358

jscomp/js_dump.ml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,24 @@ and
393393
| Call (e, el, info) ->
394394
let action () =
395395
P.group f 1 (fun _ ->
396-
let () =
397-
match info with
398-
| {arity = NA } -> ipp_comment f (Some "!")
399-
| _ -> () in
400-
let cxt = expression 15 cxt f e in
401-
P.paren_group f 1 (fun _ -> arguments cxt f el ) )
396+
397+
match info with
398+
| {arity = NA } ->
399+
(* ipp_comment f (Some "!") *)
400+
P.string f Js_config.curry;
401+
P.string f L.dot;
402+
let len = List.length el in
403+
if len <= 8 then
404+
begin
405+
P.string f (Printf.sprintf "app%d" len);
406+
P.paren_group f 1 (fun _ -> arguments cxt f (e::el))
407+
end
408+
else assert false (* TODO *)
409+
(* let cxt = expression 15 cxt f e in *)
410+
(* P.paren_group f 1 (fun _ -> arguments cxt f el ) ) *)
411+
| _ ->
412+
let cxt = expression 15 cxt f e in
413+
P.paren_group f 1 (fun _ -> arguments cxt f el ) )
402414
in
403415
if l > 15 then P.paren_group f 1 action
404416
else action ()

jscomp/js_fold_basic.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ class count_hard_dependencies =
5454
| Qualified (id,kind,_) ->
5555
Hash_set.add hard_dependencies (Lam_module_ident.mk kind id); self
5656
| Id id -> self
57-
57+
method! expression x =
58+
match x with
59+
| {expression_desc = Call (_,_, {arity = NA}); _}
60+
(* see [Js_helper.Exp.runtime_var_dot] *)
61+
-> begin
62+
Hash_set.add hard_dependencies
63+
(Lam_module_ident.of_runtime (Ext_ident.create_js Js_config.curry));
64+
super#expression x
65+
end
66+
| _ -> super#expression x
5867
method get_hard_dependencies = hard_dependencies
5968
end
6069

jscomp/js_helper.ml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,6 @@
1818

1919
(* Author: Hongbo Zhang *)
2020

21-
22-
23-
let prim = "Caml_primitive"
24-
25-
let exceptions = "Caml_exceptions"
26-
27-
let io = "Caml_io"
28-
29-
let sys = "Caml_sys"
30-
31-
let lex_parse = "Caml_lexer"
32-
33-
let obj_runtime = "Caml_obj_runtime"
34-
35-
let array = "Caml_array"
36-
37-
let format = "Caml_format"
38-
39-
let string = "Caml_string"
40-
41-
let float = "Caml_float"
42-
43-
let oo = "Caml_oo"
44-
4521
let no_side_effect = Js_analyzer.no_side_effect_expression
4622

4723
type binary_op = ?comment:string -> J.expression -> J.expression -> J.expression

jscomp/js_helper.mli

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,7 @@
2222

2323
(** Creator utilities for the [J] module *)
2424

25-
val prim : string
2625

27-
val exceptions : string
28-
29-
val io : string
30-
31-
val oo : string
32-
33-
val sys : string
34-
35-
val lex_parse : string
36-
37-
val obj_runtime : string
38-
39-
val array : string
40-
41-
val format : string
42-
43-
val string : string
44-
45-
val float : string
4626

4727
val no_side_effect : J.expression -> bool
4828

jscomp/js_of_lam_string.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ module A = struct
6767
*)
6868

6969
let bytes_to_string e =
70-
E.runtime_call Js_helper.string "bytes_to_string" [e]
70+
E.runtime_call Js_config.string "bytes_to_string" [e]
7171

7272
let bytes_of_string s =
73-
E.runtime_call Js_helper.string "bytes_of_string" [s]
73+
E.runtime_call Js_config.string "bytes_of_string" [s]
7474
end
7575

7676
(* We use module B for string compilation, once the upstream can make changes to the
@@ -120,10 +120,10 @@ module B = struct
120120
*)
121121

122122
let bytes_to_string e =
123-
E.runtime_call Js_helper.string "bytes_to_string" [e]
123+
E.runtime_call Js_config.string "bytes_to_string" [e]
124124

125125
let bytes_of_string s =
126-
E.runtime_call Js_helper.string "bytes_of_string" [s]
126+
E.runtime_call Js_config.string "bytes_of_string" [s]
127127
end
128128

129129
(* include A *)

jscomp/lam_compile.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ and compile_recursive_let (cxt : Lam_compile_defs.cxt) (id : Ident.t) (arg : Lam
122122
could be improved for simple cases
123123
*)
124124
Js_output.of_block (
125-
b @ [S.exp(E.runtime_call Js_helper.prim "caml_update_dummy" [ E.var id; v])]),
125+
b @ [S.exp(E.runtime_call Js_config.prim "caml_update_dummy" [ E.var id; v])]),
126126
[id]
127127
(* S.define ~kind:Variable id (E.arr Mutable []):: *)
128128
| _ -> assert false
@@ -1143,7 +1143,7 @@ and
11431143

11441144
| Cached | Public None (* TODO: check -- 1. js object propagate 2. js object create *)
11451145
->
1146-
let get = E.runtime_ref Js_helper.oo "caml_get_public_method" in
1146+
let get = E.runtime_ref Js_config.oo "caml_get_public_method" in
11471147
let cache = !method_cache_id in
11481148
let () =
11491149
begin
@@ -1207,7 +1207,7 @@ and
12071207
end in
12081208
(* Js_output.make [S.unknown_lambda lam] ~value:(E.unit ()) *)
12091209
Js_output.handle_block_return st should_return lam (List.concat args_code)
1210-
(E.call (E.runtime_call Js_helper.oo "caml_get_public_method"
1210+
(E.call (E.runtime_call Js_config.oo "caml_get_public_method"
12111211
[obj'; label; E.int cache]) (obj'::args))
12121212
(* avoid duplicated compuattion *)
12131213
end

jscomp/lam_compile_global.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let get_exp (key : Lam_compile_env.key) : J.expression =
6666
if Ident.is_predef_exn id
6767
then
6868
begin
69-
E.runtime_ref Js_helper.exceptions id.name
69+
E.runtime_ref Js_config.exceptions id.name
7070
end
7171
else
7272
Lam_compile_env.query_and_add_if_not_exist (Lam_module_ident.of_ml id) env

jscomp/lam_compile_group.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta)
4141
| Single(_, ({name="stdout"|"stderr"|"stdin";_} as id),_ ),
4242
"pervasives.ml" ->
4343
Js_output.of_stmt @@ S.alias_variable id
44-
~exp:(E.runtime_ref Js_helper.io id.name)
44+
~exp:(E.runtime_ref Js_config.io id.name)
4545
(*
4646
we delegate [stdout, stderr, and stdin] into [caml_io] module,
4747
the motivation is to help dead code eliminatiion, it's helpful

0 commit comments

Comments
 (0)