Skip to content

Commit e2cd0fa

Browse files
committed
remove all ts files using ml files instead
1 parent 4033a90 commit e2cd0fa

File tree

149 files changed

+2973
-4199
lines changed

Some content is hidden

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

149 files changed

+2973
-4199
lines changed

jscomp/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ echo "<<Test finished" >> ../build.compile
4646
cd ..
4747

4848

49+
ocamlbuild -cflags $OCAMLBUILD_CFLAGS -no-links js_generate_require.byte -- 2>> ./build.compile
50+
51+
echo "........" >> ./build.compile

jscomp/index.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<head>
2+
</head>
3+
4+
<body>
5+
6+
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.js"></script>
8+
<script src="./pre_load.js"></script>
9+
<!-- <script src="./require.js"></script> -->
10+
</body>

jscomp/js_config.ml

+71-69
Original file line numberDiff line numberDiff line change
@@ -31,78 +31,80 @@ let get_env () = !default_env
3131
let set_env env = default_env := env
3232

3333
let stdlib_set = String_set.of_list [
34-
"arg.js";
35-
"gc.js";
36-
"printexc.js";
37-
"array.js";
38-
"genlex.js";
39-
"printf.js";
40-
"arrayLabels.js";
41-
"hashtbl.js";
42-
"queue.js";
43-
"buffer.js";
44-
"int32.js";
45-
"random.js";
46-
"bytes.js";
47-
"int64.js";
48-
"scanf.js";
49-
"bytesLabels.js";
50-
"lazy.js";
51-
"set.js";
52-
"callback.js";
53-
"lexing.js";
54-
"sort.js";
55-
"camlinternalFormat.js";
56-
"list.js";
57-
"stack.js";
58-
"camlinternalFormatBasics.js";
59-
"listLabels.js";
60-
"stdLabels.js";
61-
"camlinternalLazy.js";
62-
"map.js";
63-
"std_exit.js";
64-
"camlinternalMod.js";
65-
"marshal.js";
66-
"stream.js";
67-
"camlinternalOO.js";
68-
"moreLabels.js";
69-
"string.js";
70-
"char.js";
71-
"nativeint.js";
72-
"stringLabels.js";
73-
"complex.js";
74-
"obj.js";
75-
"sys.js";
76-
"digest.js";
77-
"oo.js";
78-
"weak.js";
79-
"filename.js";
80-
"parsing.js";
81-
"format.js";
82-
"pervasives.js"
34+
"arg";
35+
"gc";
36+
"printexc";
37+
"array";
38+
"genlex";
39+
"printf";
40+
"arrayLabels";
41+
"hashtbl";
42+
"queue";
43+
"buffer";
44+
"int32";
45+
"random";
46+
"bytes";
47+
"int64";
48+
"scanf";
49+
"bytesLabels";
50+
"lazy";
51+
"set";
52+
"callback";
53+
"lexing";
54+
"sort";
55+
"camlinternalFormat";
56+
"list";
57+
"stack";
58+
"camlinternalFormatBasics";
59+
"listLabels";
60+
"stdLabels";
61+
"camlinternalLazy";
62+
"map";
63+
64+
(* "std_exit"; *)
65+
(* https://developer.mozilla.org/de/docs/Web/Events/beforeunload *)
66+
"camlinternalMod";
67+
"marshal";
68+
"stream";
69+
"camlinternalOO";
70+
"moreLabels";
71+
"string";
72+
"char";
73+
"nativeint";
74+
"stringLabels";
75+
"complex";
76+
"obj";
77+
"sys";
78+
"digest";
79+
"oo";
80+
"weak";
81+
"filename";
82+
"parsing";
83+
"format";
84+
"pervasives"
8385
]
8486

8587
let runtime_set = String_set.of_list [
86-
"caml_array.js";
87-
"caml_float.js";
88-
"caml_obj.js";
89-
"caml_bigarray.js";
90-
"caml_format.js";
91-
"caml_oo.js";
92-
"caml_c_ffi.js";
93-
"caml_int64.js";
94-
"caml_primitive.js";
95-
"caml_utils.js";
96-
"caml_builtin_exceptions.js";
97-
"caml_exceptions.js";
98-
"caml_curry.js";
99-
"caml_file.js";
100-
"caml_lexer.js";
101-
"caml_parser.js";
102-
"caml_string.js"
103-
(* "caml_sys.js"; *)
104-
(* "caml_unix.js"; *)
105-
(* "caml_io.js"; *)
88+
"caml_array";
89+
"caml_float";
90+
"caml_obj";
91+
"caml_bigarray";
92+
"caml_format";
93+
"caml_oo";
94+
"caml_c_ffi";
95+
"caml_int64";
96+
"caml_primitive";
97+
"caml_utils";
98+
"caml_builtin_exceptions";
99+
"caml_exceptions";
100+
"caml_curry";
101+
"caml_file";
102+
"caml_lexer";
103+
"caml_parser";
104+
"caml_string"
105+
(* "caml_sys"; *)
106+
(* "caml_unix"; *)
107+
(* "caml_io"; *)
106108
]
107109

108110

jscomp/js_generate_require.ml

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11

22
let std_files =
33
String_set.elements Js_config.stdlib_set
4-
|> List.map (fun x -> "./stdlib/" ^ Filename.chop_extension x )
4+
|> List.map
5+
(fun x -> "./stdlib/" ^ x )
56
let runtime_files =
67
String_set.elements Js_config.runtime_set
7-
|> List.map (fun x -> "./runtime/" ^ Filename.chop_extension x)
8+
|> List.map (fun x -> "./runtime/" ^ x)
89

910
let () =
10-
Ext_pervasives.with_file_as_chan "./pre_load.js" (fun chan ->
11-
output_string chan (Printf.sprintf "require([%s], function(){})"
12-
(String.concat ","
13-
(List.map (Printf.sprintf "%S" ) (std_files @ runtime_files))))
14-
)
11+
Ext_pervasives.with_file_as_chan "./pre_load.js"
12+
(fun chan ->
13+
output_string chan
14+
(Printf.sprintf "require([%s], function(){})"
15+
(String.concat ","
16+
(List.map (Printf.sprintf "%S" )
17+
(std_files @ runtime_files)
18+
))))

jscomp/js_of_lam_exception.ml

+23-3
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,35 @@ let match_exception_def (args : J.expression list) =
4040
| _ -> None
4141

4242
(* Sync up with [caml_set_oo_id] *)
43-
let make_exception id exception_str mutable_flag : J.expression =
43+
let make_exception exception_str mutable_flag : J.expression =
4444
{ expression_desc =
4545
Caml_block (
46-
[exception_str ;
47-
id],
46+
[exception_str ;
47+
E.runtime_call Js_config.builtin_exceptions "get_id" []
48+
],
4849
mutable_flag,
4950
(* TODO: combined with `_001` optimization *)
5051
E.obj_int_tag_literal (* (Obj.object_tag) *),
5152
NA
5253
);
5354
comment = None
5455
}
56+
57+
58+
59+
60+
let get_builtin_by_name name =
61+
E.runtime_ref Js_config.builtin_exceptions (String.lowercase name)
62+
63+
let caml_set_oo_id args =
64+
begin match match_exception_def args with
65+
| Some ( exception_str, mutable_flag)
66+
->
67+
make_exception exception_str mutable_flag
68+
| _ ->
69+
(**
70+
If we can guarantee this code path is never hit, we can do
71+
a better job for encoding of exception and extension?
72+
*)
73+
E.runtime_call Js_config.builtin_exceptions "caml_set_oo_id" args
74+
end

jscomp/js_of_lam_exception.mli

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818

1919
(* Author: Hongbo Zhang *)
2020

21-
val match_exception_def : J.expression list ->
22-
(J.expression * J.mutable_flag) option
23-
21+
22+
val get_builtin_by_name : string -> J.expression
2423

2524

26-
val make_exception :
27-
J.expression -> J.expression -> J.mutable_flag -> J.expression
2825

29-
26+
val caml_set_oo_id : J.expression list -> J.expression

jscomp/lam_compile_global.ml

+1-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ let get_exp (key : Lam_compile_env.key) : J.expression =
4747
match key with
4848
(id, env, expand) ->
4949
if Ident.is_predef_exn id
50-
then
51-
begin
52-
E.runtime_ref Js_config.builtin_exceptions id.name
53-
end
50+
then Js_of_lam_exception.get_builtin_by_name id.name
5451
else
5552
Lam_compile_env.query_and_add_if_not_exist (Lam_module_ident.of_ml id) env
5653
~not_found:(fun id -> assert false)

jscomp/lam_dispatch_primitive.ml

+9-18
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ let query (prim : Lam_compile_env.primitive_description)
395395
let _ = Callback.register "test function" f
396396
]}
397397
398-
[caml_named_value] is a c primitive but not OCaml/runtimedef.ml, so we don't needs
398+
[caml_named_value] is a c primitive but not belong to OCaml/runtimedef.ml,
399+
so we don't needs
399400
handle it
400401
*)
401402
E.unit
@@ -443,23 +444,7 @@ let query (prim : Lam_compile_env.primitive_description)
443444
benefit:
444445
less code side when serialzation, and more knowledge in jsir
445446
*)
446-
447-
begin match Js_of_lam_exception.match_exception_def args
448-
with
449-
| Some ( exception_str, mutable_flag)
450-
451-
->
452-
Js_of_lam_exception.make_exception
453-
(E.unchecked_prefix_inc
454-
(E.runtime_var_vid
455-
Js_config.builtin_exceptions
456-
"caml_oo_last_id"))
457-
exception_str mutable_flag
458-
459-
| _ ->
460-
E.runtime_call
461-
Js_config.builtin_exceptions prim.prim_name args
462-
end
447+
Js_of_lam_exception.caml_set_oo_id args
463448

464449
| "caml_sys_const_big_endian" ->
465450
(** return false *)
@@ -777,6 +762,12 @@ let query (prim : Lam_compile_env.primitive_description)
777762
E.runtime_call Js_config.oo prim.prim_name args
778763
(** TODO: Primitives not implemented yet ...*)
779764
| "caml_install_signal_handler"
765+
->
766+
begin match args with
767+
| [num; behavior]
768+
-> E.seq num behavior (*TODO:*)
769+
| _ -> assert false
770+
end
780771
| "caml_output_value_to_buffer"
781772
| "caml_marshal_data_size"
782773
| "caml_input_value_from_string"

jscomp/runtime/.depend

+44
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,77 @@
11
caml_array.cmi :
2+
caml_builtin_exceptions.cmi :
23
caml_exceptions.cmi :
4+
caml_float.cmi :
5+
caml_format.cmi :
6+
caml_lexer.cmi :
37
caml_obj.cmi :
48
caml_oo.cmi :
9+
caml_parser.cmi :
10+
caml_primitive.cmi :
511
caml_string.cmi :
12+
caml_sys.cmi :
13+
caml_utils.cmi :
614
caml_array.cmo : caml_array.cmi
715
caml_array.cmx : caml_array.cmi
16+
caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi
17+
caml_builtin_exceptions.cmx : caml_builtin_exceptions.cmi
818
caml_curry.cmo : caml_oo.cmi
919
caml_curry.cmx : caml_oo.cmx
1020
caml_exceptions.cmo : caml_exceptions.cmi
1121
caml_exceptions.cmx : caml_exceptions.cmi
22+
caml_float.cmo : caml_float.cmi
23+
caml_float.cmx : caml_float.cmi
24+
caml_format.cmo : caml_utils.cmi caml_format.cmi
25+
caml_format.cmx : caml_utils.cmx caml_format.cmi
1226
caml_int64.cmo :
1327
caml_int64.cmx :
28+
caml_io.cmo :
29+
caml_io.cmx :
30+
caml_lexer.cmo : caml_lexer.cmi
31+
caml_lexer.cmx : caml_lexer.cmi
1432
caml_obj.cmo : caml_obj.cmi
1533
caml_obj.cmx : caml_obj.cmi
1634
caml_oo.cmo : caml_oo.cmi
1735
caml_oo.cmx : caml_oo.cmi
36+
caml_parser.cmo : caml_parser.cmi
37+
caml_parser.cmx : caml_parser.cmi
38+
caml_primitive.cmo : caml_primitive.cmi
39+
caml_primitive.cmx : caml_primitive.cmi
1840
caml_string.cmo : caml_string.cmi
1941
caml_string.cmx : caml_string.cmi
42+
caml_sys.cmo : caml_sys.cmi
43+
caml_sys.cmx : caml_sys.cmi
44+
caml_utils.cmo : caml_utils.cmi
45+
caml_utils.cmx : caml_utils.cmi
2046
caml_array.cmo : caml_array.cmi
2147
caml_array.cmj : caml_array.cmi
48+
caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi
49+
caml_builtin_exceptions.cmj : caml_builtin_exceptions.cmi
2250
caml_curry.cmo : caml_oo.cmi
2351
caml_curry.cmj : caml_oo.cmj
2452
caml_exceptions.cmo : caml_exceptions.cmi
2553
caml_exceptions.cmj : caml_exceptions.cmi
54+
caml_float.cmo : caml_float.cmi
55+
caml_float.cmj : caml_float.cmi
56+
caml_format.cmo : caml_utils.cmi caml_format.cmi
57+
caml_format.cmj : caml_utils.cmj caml_format.cmi
2658
caml_int64.cmo :
2759
caml_int64.cmj :
60+
caml_io.cmo :
61+
caml_io.cmj :
62+
caml_lexer.cmo : caml_lexer.cmi
63+
caml_lexer.cmj : caml_lexer.cmi
2864
caml_obj.cmo : caml_obj.cmi
2965
caml_obj.cmj : caml_obj.cmi
3066
caml_oo.cmo : caml_oo.cmi
3167
caml_oo.cmj : caml_oo.cmi
68+
caml_parser.cmo : caml_parser.cmi
69+
caml_parser.cmj : caml_parser.cmi
70+
caml_primitive.cmo : caml_primitive.cmi
71+
caml_primitive.cmj : caml_primitive.cmi
3272
caml_string.cmo : caml_string.cmi
3373
caml_string.cmj : caml_string.cmi
74+
caml_sys.cmo : caml_sys.cmi
75+
caml_sys.cmj : caml_sys.cmi
76+
caml_utils.cmo : caml_utils.cmi
77+
caml_utils.cmj : caml_utils.cmi

0 commit comments

Comments
 (0)