Skip to content

Commit 357b23c

Browse files
committed
Split Block module into Caml_splice_call
This function about supporting bs.splice is rarely used
1 parent 8046bc8 commit 357b23c

13 files changed

+160
-98
lines changed

jscomp/core/js_runtime_modules.ml

+1
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ let option = "Caml_option"
5252
let module_ = "Caml_module"
5353
let missing_polyfill = "Caml_missing_polyfill"
5454
let caml_js_exceptions = "Caml_js_exceptions"
55+
let caml_splice_call = "Caml_splice_call"

jscomp/core/lam_compile_external_call.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ module E = Js_exp_make
3030

3131
let splice_fn_apply fn args =
3232
E.runtime_call
33-
Js_runtime_modules.block
33+
Js_runtime_modules.caml_splice_call
3434
"spliceApply"
3535
[fn; E.array Immutable args]
3636
let splice_obj_fn_apply obj name args =
3737
E.runtime_call
38-
Js_runtime_modules.block
38+
Js_runtime_modules.caml_splice_call
3939
"spliceObjApply"
4040
[obj; E.str name; E.array Immutable args]
4141

jscomp/runtime/block.ml

-27
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,3 @@ let polyVar meta xs =
6262
xs |. addProp (cacheSymbol "BsPolyVar") [%obj {value = meta}]
6363

6464

65-
let spliceApply : obj -> obj -> obj = fun%raw fn args -> {|
66-
var i, argLen;
67-
argLen = args.length
68-
var applied = []
69-
for(i = 0; i < argLen - 1; ++i){
70-
applied.push(args[i])
71-
}
72-
var lastOne = args[argLen - 1]
73-
for(i = 0; i < lastOne.length; ++i ){
74-
applied.push(lastOne[i])
75-
}
76-
return fn.apply(null,applied)
77-
|}
78-
79-
let spliceObjApply : obj -> obj -> obj -> obj = fun%raw obj name args -> {|
80-
var i, argLen;
81-
argLen = args.length
82-
var applied = []
83-
for(i = 0; i < argLen - 1; ++i){
84-
applied.push(args[i])
85-
}
86-
var lastOne = args[argLen - 1]
87-
for(i = 0; i < lastOne.length; ++i ){
88-
applied.push(lastOne[i])
89-
}
90-
return (obj[name]).apply(obj,applied)
91-
|}

jscomp/runtime/block.mli

-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,3 @@ val localModule : 'a -> obj -> obj
4141

4242
val polyVar : 'a -> obj -> obj
4343

44-
val spliceApply : obj -> obj -> obj
45-
46-
val spliceObjApply : obj -> obj -> obj -> obj

jscomp/runtime/caml_splice_call.ml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(* Copyright (C) 2019- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
type obj = Caml_obj_extern.t
27+
28+
let spliceApply : obj -> obj -> obj = fun%raw fn args -> {|
29+
var i, argLen;
30+
argLen = args.length
31+
var applied = []
32+
for(i = 0; i < argLen - 1; ++i){
33+
applied.push(args[i])
34+
}
35+
var lastOne = args[argLen - 1]
36+
for(i = 0; i < lastOne.length; ++i ){
37+
applied.push(lastOne[i])
38+
}
39+
return fn.apply(null,applied)
40+
|}
41+
42+
let spliceObjApply : obj -> obj -> obj -> obj = fun%raw obj name args -> {|
43+
var i, argLen;
44+
argLen = args.length
45+
var applied = []
46+
for(i = 0; i < argLen - 1; ++i){
47+
applied.push(args[i])
48+
}
49+
var lastOne = args[argLen - 1]
50+
for(i = 0; i < lastOne.length; ++i ){
51+
applied.push(lastOne[i])
52+
}
53+
return (obj[name]).apply(obj,applied)
54+
|}

jscomp/runtime/caml_splice_call.mli

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(* Copyright (C) 2019- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
type obj = Caml_obj_extern.t
27+
28+
val spliceApply : obj -> obj -> obj
29+
30+
val spliceObjApply : obj -> obj -> obj -> obj

jscomp/runtime/release.ninja

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ build runtime/caml_parser.cmj : cc runtime/caml_parser.ml | runtime/caml_obj_ext
5454
build runtime/caml_parser.cmi : cc runtime/caml_parser.mli | runtime/bs_stdlib_mini.cmi runtime/caml_obj_extern.cmj runtime/js.cmi runtime/js.cmj
5555
build runtime/caml_primitive.cmj : cc runtime/caml_primitive.ml | runtime/caml_bytes_extern.cmj runtime/caml_primitive.cmi
5656
build runtime/caml_primitive.cmi : cc runtime/caml_primitive.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
57+
build runtime/caml_splice_call.cmj : cc runtime/caml_splice_call.ml | runtime/caml_obj_extern.cmj runtime/caml_splice_call.cmi
58+
build runtime/caml_splice_call.cmi : cc runtime/caml_splice_call.mli | runtime/bs_stdlib_mini.cmi runtime/caml_obj_extern.cmj runtime/js.cmi runtime/js.cmj
5759
build runtime/caml_string.cmj : cc runtime/caml_string.ml | runtime/caml_builtin_exceptions.cmj runtime/caml_char.cmj runtime/caml_string.cmi runtime/caml_string_extern.cmj
5860
build runtime/caml_string.cmi : cc runtime/caml_string.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
5961
build runtime/caml_sys.cmj : cc runtime/caml_sys.ml | runtime/caml_array_extern.cmj runtime/caml_builtin_exceptions.cmj runtime/caml_nativeint_extern.cmj runtime/caml_sys.cmi runtime/caml_undefined_extern.cmj runtime/js.cmj
@@ -75,4 +77,4 @@ build runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj : cc runtime/caml_oo_c
7577
build runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
7678
build runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
7779
build runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.ml | runtime/bs_stdlib_mini.cmi runtime/caml_array.cmj runtime/caml_array_extern.cmj runtime/js.cmi runtime/js.cmj
78-
build runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/block.cmi runtime/block.cmj runtime/caml_array.cmi runtime/caml_array.cmj runtime/caml_builtin_exceptions.cmi runtime/caml_builtin_exceptions.cmj runtime/caml_bytes.cmi runtime/caml_bytes.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_float.cmi runtime/caml_float.cmj runtime/caml_format.cmi runtime/caml_format.cmj runtime/caml_gc.cmi runtime/caml_gc.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_int32.cmi runtime/caml_int32.cmj runtime/caml_int64.cmi runtime/caml_int64.cmj runtime/caml_io.cmi runtime/caml_io.cmj runtime/caml_lexer.cmi runtime/caml_lexer.cmj runtime/caml_md5.cmi runtime/caml_md5.cmj runtime/caml_missing_polyfill.cmi runtime/caml_missing_polyfill.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_oo.cmi runtime/caml_oo.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_parser.cmi runtime/caml_parser.cmj runtime/caml_primitive.cmi runtime/caml_primitive.cmj runtime/caml_string.cmi runtime/caml_string.cmj runtime/caml_sys.cmi runtime/caml_sys.cmj runtime/caml_utils.cmi runtime/caml_utils.cmj runtime/caml_weak.cmi runtime/caml_weak.cmj runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj runtime/caml_bytes_extern.cmi runtime/caml_bytes_extern.cmj runtime/caml_char.cmi runtime/caml_char.cmj runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj runtime/caml_int32_extern.cmi runtime/caml_int32_extern.cmj runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj runtime/caml_obj_extern.cmi runtime/caml_obj_extern.cmj runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj
80+
build runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/block.cmi runtime/block.cmj runtime/caml_array.cmi runtime/caml_array.cmj runtime/caml_builtin_exceptions.cmi runtime/caml_builtin_exceptions.cmj runtime/caml_bytes.cmi runtime/caml_bytes.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_float.cmi runtime/caml_float.cmj runtime/caml_format.cmi runtime/caml_format.cmj runtime/caml_gc.cmi runtime/caml_gc.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_int32.cmi runtime/caml_int32.cmj runtime/caml_int64.cmi runtime/caml_int64.cmj runtime/caml_io.cmi runtime/caml_io.cmj runtime/caml_lexer.cmi runtime/caml_lexer.cmj runtime/caml_md5.cmi runtime/caml_md5.cmj runtime/caml_missing_polyfill.cmi runtime/caml_missing_polyfill.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_oo.cmi runtime/caml_oo.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_parser.cmi runtime/caml_parser.cmj runtime/caml_primitive.cmi runtime/caml_primitive.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/caml_string.cmi runtime/caml_string.cmj runtime/caml_sys.cmi runtime/caml_sys.cmj runtime/caml_utils.cmi runtime/caml_utils.cmj runtime/caml_weak.cmi runtime/caml_weak.cmj runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj runtime/caml_bytes_extern.cmi runtime/caml_bytes_extern.cmj runtime/caml_char.cmi runtime/caml_char.cmj runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj runtime/caml_int32_extern.cmi runtime/caml_int32_extern.cmj runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj runtime/caml_obj_extern.cmi runtime/caml_obj_extern.cmj runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj

jscomp/test/module_splice_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var Mt = require("./mt.js");
44
var Block = require("../../lib/js/block.js");
55
var JoinClasses = require("./joinClasses");
6+
var Caml_splice_call = require("../../lib/js/caml_splice_call.js");
67

78
var suites = /* record */[/* contents : [] */0];
89

@@ -28,7 +29,7 @@ function eq(loc, param) {
2829
}
2930

3031
function joinClasses(prim) {
31-
return Block.spliceApply(JoinClasses, [prim]);
32+
return Caml_splice_call.spliceApply(JoinClasses, [prim]);
3233
}
3334

3435
var a = JoinClasses(1, 2, 3);

jscomp/test/splice_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
var Mt = require("./mt.js");
4-
var Block = require("../../lib/js/block.js");
54
var Caml_array = require("../../lib/js/caml_array.js");
5+
var Caml_splice_call = require("../../lib/js/caml_splice_call.js");
66

77
var suites = /* record */[/* contents : [] */0];
88

@@ -31,7 +31,7 @@ eq("File \"splice_test.ml\", line 28, characters 5-12", a, /* array */[
3131

3232
function dynamic(arr) {
3333
var a = /* array */[];
34-
Block.spliceObjApply(a, "push", [
34+
Caml_splice_call.spliceObjApply(a, "push", [
3535
1,
3636
arr
3737
]);
@@ -71,7 +71,7 @@ eq("File \"splice_test.ml\", line 50, characters 7-14", a$1, /* array */[
7171

7272
function dynamic$1(arr) {
7373
var a = /* array */[];
74-
Block.spliceObjApply(a, "push", [
74+
Caml_splice_call.spliceObjApply(a, "push", [
7575
1,
7676
arr
7777
]);
@@ -101,7 +101,7 @@ dynamic$1(/* array */[
101101
var Pipe = /* module */[/* dynamic */dynamic$1];
102102

103103
function f1(c) {
104-
return Block.spliceApply(Math.max, [
104+
return Caml_splice_call.spliceApply(Math.max, [
105105
1,
106106
c
107107
]);

lib/4.02.3/unstable/js_compiler.ml

+27-27
Large diffs are not rendered by default.

lib/4.02.3/whole_compiler.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -70886,7 +70886,7 @@ let option = "Caml_option"
7088670886
let module_ = "Caml_module"
7088770887
let missing_polyfill = "Caml_missing_polyfill"
7088870888
let caml_js_exceptions = "Caml_js_exceptions"
70889-
70889+
let caml_splice_call = "Caml_splice_call"
7089070890
end
7089170891
module Lam_compile_util : sig
7089270892
#1 "lam_compile_util.mli"
@@ -94848,12 +94848,12 @@ module E = Js_exp_make
9484894848

9484994849
let splice_fn_apply fn args =
9485094850
E.runtime_call
94851-
Js_runtime_modules.block
94851+
Js_runtime_modules.caml_splice_call
9485294852
"spliceApply"
9485394853
[fn; E.array Immutable args]
9485494854
let splice_obj_fn_apply obj name args =
9485594855
E.runtime_call
94856-
Js_runtime_modules.block
94856+
Js_runtime_modules.caml_splice_call
9485794857
"spliceObjApply"
9485894858
[obj; E.str name; E.array Immutable args]
9485994859

lib/js/block.js

-30
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,10 @@ function polyVar(meta, xs) {
3737
});
3838
}
3939

40-
function spliceApply (fn,args){
41-
var i, argLen;
42-
argLen = args.length
43-
var applied = []
44-
for(i = 0; i < argLen - 1; ++i){
45-
applied.push(args[i])
46-
}
47-
var lastOne = args[argLen - 1]
48-
for(i = 0; i < lastOne.length; ++i ){
49-
applied.push(lastOne[i])
50-
}
51-
return fn.apply(null,applied)
52-
};
53-
54-
function spliceObjApply (obj,name,args){
55-
var i, argLen;
56-
argLen = args.length
57-
var applied = []
58-
for(i = 0; i < argLen - 1; ++i){
59-
applied.push(args[i])
60-
}
61-
var lastOne = args[argLen - 1]
62-
for(i = 0; i < lastOne.length; ++i ){
63-
applied.push(lastOne[i])
64-
}
65-
return (obj[name]).apply(obj,applied)
66-
};
67-
6840
exports.__ = __;
6941
exports.record = record;
7042
exports.variant = variant;
7143
exports.simpleVariant = simpleVariant;
7244
exports.localModule = localModule;
7345
exports.polyVar = polyVar;
74-
exports.spliceApply = spliceApply;
75-
exports.spliceObjApply = spliceObjApply;
7646
/* No side effect */

lib/js/caml_splice_call.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
4+
function spliceApply (fn,args){
5+
var i, argLen;
6+
argLen = args.length
7+
var applied = []
8+
for(i = 0; i < argLen - 1; ++i){
9+
applied.push(args[i])
10+
}
11+
var lastOne = args[argLen - 1]
12+
for(i = 0; i < lastOne.length; ++i ){
13+
applied.push(lastOne[i])
14+
}
15+
return fn.apply(null,applied)
16+
};
17+
18+
function spliceObjApply (obj,name,args){
19+
var i, argLen;
20+
argLen = args.length
21+
var applied = []
22+
for(i = 0; i < argLen - 1; ++i){
23+
applied.push(args[i])
24+
}
25+
var lastOne = args[argLen - 1]
26+
for(i = 0; i < lastOne.length; ++i ){
27+
applied.push(lastOne[i])
28+
}
29+
return (obj[name]).apply(obj,applied)
30+
};
31+
32+
exports.spliceApply = spliceApply;
33+
exports.spliceObjApply = spliceObjApply;
34+
/* No side effect */

0 commit comments

Comments
 (0)