Skip to content

Commit 9a73ef9

Browse files
committed
snapshot
1 parent 87f9353 commit 9a73ef9

23 files changed

+3019
-3184
lines changed

Diff for: jscomp/Docs.md

+46
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,52 @@ The directory containing unit-test files, some unit tests are copied from OCaml
4040
## ounit_tests
4141
## others (belt/stdlib/node bindings)
4242

43+
## uncurry
44+
45+
```ocaml
46+
f a b [@bs]
47+
```
48+
49+
```ocaml
50+
(unsafeFullApply ((opaque f) a b ))
51+
```
52+
case 0
53+
54+
```ocaml
55+
type 'a fn0 = {
56+
_0 : 'a
57+
}
58+
```
59+
create:
60+
```
61+
{_0 = fun () -> ...}
62+
```
63+
`(unit -> int) fn0` is different from `(unit -> int) fn1`
64+
65+
When `f` is an external, without opaque
66+
```ocaml
67+
apply (Obj.magic f a b) ==> apply (f a b)
68+
```
69+
70+
`fun [@bs] a b -> c ` is the same as `fun [@bs] a -> fun b -> c `
71+
from the view of parsetree
72+
73+
74+
75+
`unit -> int [@bs]` --> `int Js.arity0`
76+
77+
`f () [@bs]` --> `(run0 f)`
78+
79+
`fun [@bs] () -> body` -> `fn_mk0 (fun () -> ...)`
80+
81+
It is special handled due to `fn_mk0`, otherwise it will have arity 1
82+
83+
We can `-open Js.Uncurry` to make names look pretty
84+
85+
```
86+
bucklescript$bsc -bs-syntax-only -dsource -bs-eval 'let h1 x = fun%x y -> x y'
87+
let h1 x = [%x fun y -> x y]
88+
```
4389

4490
# bspack
4591

Diff for: jscomp/main/builtin_cmi_datasets.ml

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

Diff for: jscomp/main/builtin_cmj_datasets.ml

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

Diff for: jscomp/test/class_type_ffi_test.js

-58
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var Curry = require("../../lib/js/curry.js");
43

54
function sum_float_array(arr) {
65
var v = 0;
@@ -36,66 +35,9 @@ function f(x) {
3635
return x.fight();
3736
}
3837

39-
function ff(fn, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) {
40-
return fn(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
41-
}
42-
43-
function ff2(fn, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) {
44-
return fn(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
45-
}
46-
47-
function off2(o, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) {
48-
return o.huge_method(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
49-
}
50-
51-
function mk_f(param) {
52-
return (function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) {
53-
return Curry.app(a0, [
54-
a1,
55-
a2,
56-
a3,
57-
a4,
58-
a5,
59-
a6,
60-
a7,
61-
a8,
62-
a9,
63-
a10,
64-
a11,
65-
a12
66-
]);
67-
});
68-
}
69-
70-
function omk_f(param) {
71-
return {
72-
huge_methdo: (function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) {
73-
return Curry.app(a0, [
74-
a1,
75-
a2,
76-
a3,
77-
a4,
78-
a5,
79-
a6,
80-
a7,
81-
a8,
82-
a9,
83-
a10,
84-
a11,
85-
a12
86-
]);
87-
})
88-
};
89-
}
90-
9138
exports.sum_float_array = sum_float_array;
9239
exports.sum_int_array = sum_int_array;
9340
exports.sum_poly = sum_poly;
9441
exports.test_set = test_set;
9542
exports.f = f;
96-
exports.ff = ff;
97-
exports.ff2 = ff2;
98-
exports.off2 = off2;
99-
exports.mk_f = mk_f;
100-
exports.omk_f = omk_f;
10143
/* No side effect */

Diff for: jscomp/test/class_type_ffi_test.ml

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ let f (x : < bark : string -> unit [@bs.meth] ; fight : unit -> unit [@bs.meth]
4848
(* This type is generated on the fly -- in which case
4949
it can not be nominal
5050
*)
51-
let ff
51+
(* let ff
5252
(fn :('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9 -> 'a10 -> 'a11 -> 'a12 [@bs])) a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
53-
fn a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 [@bs]
53+
fn a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 [@bs] *)
5454

5555

56-
let ff2
56+
(* let ff2
5757
fn a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
58-
fn a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 [@bs]
58+
fn a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 [@bs] *)
5959

6060
(* Test [fn_run_method] *)
61-
let off2 o a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
62-
o##huge_method a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12
61+
(* let off2 o a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
62+
o##huge_method a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 *)
6363

6464
(* Test [fn_mk] *)
65-
let mk_f () =
65+
(* let mk_f () =
6666
fun [@bs] a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 ->
67-
a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12
67+
a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 *)
6868

6969
(* Test [fn_method] *)
70-
let omk_f ()=
70+
(* let omk_f ()=
7171
object
7272
method huge_methdo a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
7373
a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12
74-
end [@bs]
74+
end [@bs] *)

Diff for: jscomp/test/event_ffi.js

+7-36
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@
22

33
var List = require("../../lib/js/list.js");
44
var Curry = require("../../lib/js/curry.js");
5-
var Caml_int32 = require("../../lib/js/caml_int32.js");
65

76
function h0(x) {
87
return x();
98
}
109

1110
function h00(x) {
12-
return Curry._1(x(), /* () */0);
11+
return x();
1312
}
1413

15-
function h1(x) {
16-
return (function (param) {
17-
return x(param);
18-
});
14+
function h1(x, y) {
15+
return x(y);
1916
}
2017

2118
function h10(x) {
2219
return x(3);
2320
}
2421

2522
function h30(x) {
26-
return (function (param) {
27-
return x(3, 3, param);
23+
return (function (a) {
24+
return x(3, 3, a);
2825
});
2926
}
3027

@@ -36,10 +33,10 @@ function h34(x) {
3633
return Curry._1(x(1, 2, 3), 4);
3734
}
3835

39-
function ocaml_run(param, param$1) {
36+
function ocaml_run(b, c) {
4037
return (function (x, y, z) {
4138
return (x + y | 0) + z | 0;
42-
})(1, param, param$1);
39+
})(1, b, c);
4340
}
4441

4542
function a0() {
@@ -61,29 +58,6 @@ function a3(x, y, z) {
6158
return (x + y | 0) + z | 0;
6259
}
6360

64-
function a4(x, y, z, param) {
65-
var u = (Caml_int32.imul(x, x) + Caml_int32.imul(y, y) | 0) + Caml_int32.imul(z, z) | 0;
66-
return (function (d) {
67-
return u + d | 0;
68-
})(param);
69-
}
70-
71-
function a44(x, y, z, d) {
72-
var u = (Caml_int32.imul(x, x) + Caml_int32.imul(y, y) | 0) + Caml_int32.imul(z, z) | 0;
73-
return u + d | 0;
74-
}
75-
76-
function b44(param) {
77-
return (function (x, y, z, d) {
78-
return /* tuple */[
79-
x,
80-
y,
81-
z,
82-
d
83-
];
84-
});
85-
}
86-
8761
function xx(param) {
8862
return (function (param) {
8963
console.log(3);
@@ -105,9 +79,6 @@ exports.a0 = a0;
10579
exports.a1 = a1;
10680
exports.a2 = a2;
10781
exports.a3 = a3;
108-
exports.a4 = a4;
109-
exports.a44 = a44;
110-
exports.b44 = b44;
11182
exports.test_as = test_as;
11283
exports.xx = xx;
11384
/* No side effect */

Diff for: jscomp/test/event_ffi.ml

+19-15
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,38 @@ let () =
3333
3434
*)
3535

36-
let h0 x = Js.Internal.fn_run0 x
36+
let h0 x = x () [@bs]
3737
(* {[
3838
function h0 (x){
3939
return x ()
4040
}
4141
]}
4242
*)
43-
let h00 x = Js.Internal.fn_run0 x ()
43+
let h00 x = x () [@bs]
4444

45-
let h1 x = Js.Internal.fn_run1 x
46-
let h10 x = Js.Internal.fn_run1 x 3
45+
let h1 x = (fun y -> x y [@bs]) (* weird case *)
46+
(*
47+
bucklescript$bsc -bs-syntax-only -dsource -bs-eval 'let h1 x = fun y -> x y'
48+
let h1 x y = x y
49+
*)
50+
let h10 x = x 3 [@bs]
4751

48-
let h30 x = Js.Internal.fn_run3 x 3 3
49-
let h33 x = Js.Internal.fn_run3 x 1 2 3
50-
let h34 x = Js.Internal.fn_run3 x 1 2 3 4
52+
let h30 x = fun [@bs] a -> x 3 3 a [@bs]
53+
let h33 x = x 1 2 3 [@bs]
54+
let h34 x = (x 1 2 3 [@bs]) 4
5155

5256

53-
let ocaml_run = Js.Internal.fn_run3 (Js.Internal.fn_mk3 (fun x y z -> x + y + z)) 1
57+
let ocaml_run = fun[@bs] b c -> (fun [@bs] x y z -> x + y + z) 1 b c[@bs]
5458

55-
let a0 = Js.Internal.fn_mk0 (fun _ -> Js.log "hi")
56-
let a1 () = Js.Internal.fn_mk1 (fun x -> x )
57-
let a2 = Js.Internal.fn_mk2 (fun x y -> x + y)
58-
let a3 = Js.Internal.fn_mk3 (fun x y z -> x + y + z )
59-
let a4 = Js.Internal.fn_mk4 (fun x y z -> let u = x * x + y * y + z * z in fun d -> u + d)
59+
let a0 = (fun [@bs] () -> Js.log "hi")
60+
let a1 () = (fun[@bs] x -> x )
61+
let a2 = (fun[@bs] x y -> x + y)
62+
let a3 = (fun [@bs] x y z -> x + y + z )
63+
(* let a4 = Js.Internal.fn_mk4 (fun x y z -> let u = x * x + y * y + z * z in fun d -> u + d) *)
6064

61-
let a44 = Js.Internal.fn_mk4 (fun x y z d -> let u = x * x + y * y + z * z in u + d)
65+
(* let a44 = Js.Internal.fn_mk4 (fun x y z d -> let u = x * x + y * y + z * z in u + d) *)
6266

63-
let b44 () = Js.Internal.fn_mk4 (fun x y z d -> (x,y,z,d))
67+
(* let b44 () = Js.Internal.fn_mk4 (fun x y z d -> (x,y,z,d)) *)
6468
(* polymoprhic restriction *)
6569

6670
let test_as : ('a -> 'a) -> (_ as 'b) -> 'b = List.map

Diff for: jscomp/test/ffi_arity_test.js

+7-56
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ var v = [
2121
1,
2222
2,
2323
3
24-
].map((function (param, param$1) {
25-
return f(param)(param$1);
24+
].map((function (a, b) {
25+
return f(a)(b);
2626
}));
2727

2828
var vv = [
2929
1,
3030
2,
3131
3
32-
].map((function (prim, prim$1) {
33-
return prim + prim$1 | 0;
32+
].map((function (a, b) {
33+
return a + b | 0;
3434
}));
3535

3636
var hh = [
3737
"1",
3838
"2",
3939
"3"
40-
].map((function (prim) {
41-
return parseInt(prim);
40+
].map((function (x) {
41+
return parseInt(x);
4242
}));
4343

4444
function u() {
@@ -112,56 +112,7 @@ Mt.from_pair_suites("Ffi_arity_test", /* :: */[
112112
]);
113113
})
114114
],
115-
/* :: */[
116-
/* tuple */[
117-
"File \"ffi_arity_test.ml\", line 48, characters 4-11",
118-
(function (param) {
119-
return /* Eq */Block.__(0, [
120-
[
121-
1,
122-
2,
123-
3
124-
].map((function (x) {
125-
return (function (y) {
126-
return x + y | 0;
127-
});
128-
})).map((function (y) {
129-
return Caml_int32.imul(Curry._1(y, 0), Curry._1(y, 1));
130-
})),
131-
[
132-
2,
133-
6,
134-
12
135-
]
136-
]);
137-
})
138-
],
139-
/* :: */[
140-
/* tuple */[
141-
"File \"ffi_arity_test.ml\", line 53, characters 4-11",
142-
(function (param) {
143-
return /* Eq */Block.__(0, [
144-
[
145-
1,
146-
2,
147-
3
148-
].map((function (x, param) {
149-
var y = Caml_int32.imul(x, x);
150-
return (function (i) {
151-
return y + i | 0;
152-
})(param);
153-
})),
154-
[
155-
1,
156-
5,
157-
11
158-
]
159-
]);
160-
})
161-
],
162-
/* [] */0
163-
]
164-
]
115+
/* [] */0
165116
]
166117
]
167118
]);

0 commit comments

Comments
 (0)