Skip to content

Commit 37d8829

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

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

+24
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

+25
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

+18-6
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

+10-1
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

-24
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

-20
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

+4-4
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

+3-3
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

+1-1
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

+1-1
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

jscomp/lam_dispatch_primitive.ml

+16-16
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ let query (prim : Lam_compile_env.primitive_description)
263263
| "caml_hypot_float"
264264

265265
->
266-
E.runtime_call Js_helper.float prim.prim_name args
266+
E.runtime_call Js_config.float prim.prim_name args
267267
| "caml_fmod_float"
268268
(* float module like js number module *)
269269
->
@@ -329,7 +329,7 @@ let query (prim : Lam_compile_env.primitive_description)
329329
E.uninitialized_array v
330330
(* TODO: inline and spits out a warning when i is negative *)
331331
| _ ->
332-
E.runtime_call Js_helper.string prim.prim_name args
332+
E.runtime_call Js_config.string prim.prim_name args
333333
end
334334

335335
| "caml_string_get"
@@ -343,7 +343,7 @@ let query (prim : Lam_compile_env.primitive_description)
343343
| "caml_blit_string"
344344
| "caml_blit_bytes"
345345
->
346-
E.runtime_call Js_helper.string prim.prim_name args
346+
E.runtime_call Js_config.string prim.prim_name args
347347

348348
| "caml_register_named_value" ->
349349
(**
@@ -423,12 +423,12 @@ let query (prim : Lam_compile_env.primitive_description)
423423
([ tag; str ;
424424
E.prefix_inc
425425
(E.runtime_var_vid
426-
Js_helper.exceptions
426+
Js_config.exceptions
427427
"caml_oo_last_id")
428428
], flag)
429429
}
430430
| _ ->
431-
E.runtime_call Js_helper.exceptions prim.prim_name args
431+
E.runtime_call Js_config.exceptions prim.prim_name args
432432
end
433433

434434
| "caml_sys_const_big_endian" ->
@@ -455,12 +455,12 @@ let query (prim : Lam_compile_env.primitive_description)
455455
| "caml_sys_random_seed"
456456
| "caml_sys_getenv"
457457
| "caml_sys_system_command" ->
458-
E.runtime_call Js_helper.sys prim.prim_name args
458+
E.runtime_call Js_config.sys prim.prim_name args
459459
| "caml_lex_engine"
460460
| "caml_new_lex_engine"
461461
| "caml_parse_engine"
462462
| "caml_set_parser_trace" ->
463-
E.runtime_call Js_helper.lex_parse prim.prim_name args
463+
E.runtime_call Js_config.lex_parse prim.prim_name args
464464

465465
| "caml_array_sub"
466466
| "caml_array_concat"
@@ -469,7 +469,7 @@ let query (prim : Lam_compile_env.primitive_description)
469469

470470
| "caml_array_blit"
471471
| "caml_make_vect" ->
472-
E.runtime_call Js_helper.array prim.prim_name args
472+
E.runtime_call Js_config.array prim.prim_name args
473473
| "caml_ml_flush"
474474
| "caml_ml_out_channels_list"
475475
| "caml_ml_open_descriptor_in"
@@ -478,7 +478,7 @@ let query (prim : Lam_compile_env.primitive_description)
478478
| "caml_ml_output"
479479
| "caml_ml_input_char"
480480
->
481-
E.runtime_call Js_helper.io prim.prim_name args
481+
E.runtime_call Js_config.io prim.prim_name args
482482

483483
| "caml_obj_dup" ->
484484
(** Note currently is an Array copy function, this is tightly coupled with
@@ -490,7 +490,7 @@ let query (prim : Lam_compile_env.primitive_description)
490490
match args with
491491
| [ a ] when Js_helper.is_constant a -> a
492492
| _ ->
493-
E.runtime_call Js_helper.obj_runtime prim.prim_name args
493+
E.runtime_call Js_config.obj_runtime prim.prim_name args
494494
end
495495
| "caml_obj_block" ->
496496
(** TODO: Optimize for [CamlinternalOO] input
@@ -504,7 +504,7 @@ let query (prim : Lam_compile_env.primitive_description)
504504
{expression_desc = Number (Int { i = 0;_}); _} ] ->
505505
E.arr Immutable [E.int tag] (** size 0*)
506506
| _ ->
507-
E.runtime_call Js_helper.obj_runtime prim.prim_name args
507+
E.runtime_call Js_config.obj_runtime prim.prim_name args
508508

509509
end
510510
| "caml_obj_is_block"
@@ -514,7 +514,7 @@ let query (prim : Lam_compile_env.primitive_description)
514514

515515
| "caml_obj_truncate"
516516
| "caml_lazy_make_forward" ->
517-
E.runtime_call Js_helper.obj_runtime prim.prim_name args
517+
E.runtime_call Js_config.obj_runtime prim.prim_name args
518518

519519
| "caml_format_float"
520520
| "caml_format_int"
@@ -524,7 +524,7 @@ let query (prim : Lam_compile_env.primitive_description)
524524
| "caml_int_of_string" (* what is the semantics?*)
525525
| "caml_int32_of_string"
526526
| "caml_nativeint_of_string" ->
527-
E.runtime_call Js_helper.format prim.prim_name args
527+
E.runtime_call Js_config.format prim.prim_name args
528528

529529

530530
(* "caml_alloc_dummy"; *)
@@ -549,10 +549,10 @@ let query (prim : Lam_compile_env.primitive_description)
549549
| "caml_int32_bswap"
550550
| "caml_nativeint_bswap"
551551
| "caml_int64_bswap"
552-
-> E.runtime_call Js_helper.prim prim.prim_name args
552+
-> E.runtime_call Js_config.prim prim.prim_name args
553553
| "caml_get_public_method"
554554
->
555-
E.runtime_call Js_helper.oo prim.prim_name args
555+
E.runtime_call Js_config.oo prim.prim_name args
556556
(** TODO: Primitives not implemented yet ...*)
557557
| "caml_install_signal_handler"
558558
| "caml_output_value_to_buffer"
@@ -596,7 +596,7 @@ let query (prim : Lam_compile_env.primitive_description)
596596
| "caml_ml_seek_out_64"
597597
| "caml_ml_set_binary_mode"
598598
| "caml_sys_getcwd" (* check browser or nodejs *)
599-
-> E.runtime_call Js_helper.prim prim.prim_name args
599+
-> E.runtime_call Js_config.prim prim.prim_name args
600600

601601

602602
| "js_function_length"

jscomp/runtime/.depend

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ caml_oo.cmi :
33
caml_string.cmi :
44
caml_array.cmo : caml_array.cmi
55
caml_array.cmx : caml_array.cmi
6+
caml_curry.cmo :
7+
caml_curry.cmx :
68
caml_oo.cmo : caml_oo.cmi
79
caml_oo.cmx : caml_oo.cmi
810
caml_string.cmo : caml_string.cmi
911
caml_string.cmx : caml_string.cmi
10-
curry.cmo :
11-
curry.cmx :
1212
caml_array.cmo : caml_array.cmi
1313
caml_array.cmj : caml_array.cmi
14+
caml_curry.cmo :
15+
caml_curry.cmj :
1416
caml_oo.cmo : caml_oo.cmi
1517
caml_oo.cmj : caml_oo.cmi
1618
caml_string.cmo : caml_string.cmi
1719
caml_string.cmj : caml_string.cmi
18-
curry.cmo :
19-
curry.cmj :

0 commit comments

Comments
 (0)