Skip to content

Commit 3005b70

Browse files
committed
add test support for rescript syntax
1 parent 78781b4 commit 3005b70

File tree

6 files changed

+103
-6
lines changed

6 files changed

+103
-6
lines changed

jscomp/test/build.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ o test/hash_collision_test.cmi test/hash_collision_test.cmj : cc test/hash_colli
338338
o test/hash_test.cmi test/hash_test.cmj : cc test/hash_test.ml | test/mt.cmj test/mt_global.cmj $stdlib
339339
o test/hashtbl_test.cmi test/hashtbl_test.cmj : cc test/hashtbl_test.ml | test/mt.cmj $stdlib
340340
o test/hello.foo.cmi test/hello.foo.cmj : cc test/hello.foo.ml | $stdlib
341+
o test/hello_res.cmj : cc_cmi test/hello_res.res | test/hello_res.cmi $stdlib
342+
o test/hello_res.cmi : cc test/hello_res.resi | $stdlib
341343
o test/http_types.cmi test/http_types.cmj : cc test/http_types.ml | $stdlib
342344
o test/ignore_test.cmi test/ignore_test.cmj : cc test/ignore_test.ml | test/mt.cmj $stdlib
343345
o test/imm_map_bench.cmi test/imm_map_bench.cmj : cc test/imm_map_bench.ml | $stdlib

jscomp/test/hello_res.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
var List = require("../../lib/js/list.js");
4+
5+
var b = List.length({
6+
hd: 1,
7+
tl: {
8+
hd: 2,
9+
tl: {
10+
hd: 3,
11+
tl: /* [] */0
12+
}
13+
}
14+
});
15+
16+
var a = b - 1 | 0;
17+
18+
console.log("hello, res");
19+
20+
exports.a = a;
21+
/* b Not a pure module */

lib/4.06.1/unstable/bspack.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11958,6 +11958,7 @@ val as_ppx : bool ref
1195811958

1195911959
val mono_empty_array : bool ref
1196011960
val customize_runtime : string option ref
11961+
val as_pp: bool ref
1196111962
end = struct
1196211963
#1 "js_config.ml"
1196311964
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -12053,6 +12054,8 @@ let as_ppx = ref false
1205312054
let mono_empty_array = ref true
1205412055

1205512056
let customize_runtime = ref None
12057+
12058+
let as_pp = ref false
1205612059
end
1205712060
module Map_gen : sig
1205812061
#1 "map_gen.mli"

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17802,6 +17802,7 @@ val as_ppx : bool ref
1780217802

1780317803
val mono_empty_array : bool ref
1780417804
val customize_runtime : string option ref
17805+
val as_pp: bool ref
1780517806
end = struct
1780617807
#1 "js_config.ml"
1780717808
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -17897,6 +17898,8 @@ let as_ppx = ref false
1789717898
let mono_empty_array = ref true
1789817899

1789917900
let customize_runtime = ref None
17901+
17902+
let as_pp = ref false
1790017903
end
1790117904
module Bs_cmi_load
1790217905
= struct

lib/4.06.1/whole_compiler.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294198,6 +294198,7 @@ val as_ppx : bool ref
294198294198

294199294199
val mono_empty_array : bool ref
294200294200
val customize_runtime : string option ref
294201+
val as_pp: bool ref
294201294202
end = struct
294202294203
#1 "js_config.ml"
294203294204
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -294293,6 +294294,8 @@ let as_ppx = ref false
294293294294
let mono_empty_array = ref true
294294294295

294295294296
let customize_runtime = ref None
294297+
294298+
let as_pp = ref false
294296294299
end
294297294300
module Ast_config : sig
294298294301
#1 "ast_config.mli"
@@ -412510,7 +412513,12 @@ let after_parsing_sig ppf outputprefix ast =
412510412513
ast
412511412514

412512412515
end;
412513-
if !Js_config.syntax_only then
412516+
if !Js_config.as_pp then begin
412517+
output_string stdout Config.ast_intf_magic_number;
412518+
output_value stdout (!Location.input_name : string);
412519+
output_value stdout ast;
412520+
end;
412521+
if !Js_config.syntax_only then
412514412522
Warnings.check_fatal()
412515412523
else
412516412524
begin
@@ -412613,6 +412621,11 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
412613412621
Ml ~output:(outputprefix ^ Literals.suffix_ast)
412614412622
ast
412615412623
end ;
412624+
if !Js_config.as_pp then begin
412625+
output_string stdout Config.ast_impl_magic_number;
412626+
output_value stdout (!Location.input_name : string);
412627+
output_value stdout ast;
412628+
end;
412616412629
if !Js_config.syntax_only then
412617412630
Warnings.check_fatal ()
412618412631
else
@@ -435086,7 +435099,8 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
435086435099

435087435100
"-as-ppx", set Js_config.as_ppx,
435088435101
"*internal*As ppx for editor integration";
435089-
435102+
"-as-pp", unit_call(fun _ -> Js_config.as_pp := true ; Js_config.syntax_only := true),
435103+
"*internal*As pp to interact with native tools";
435090435104
"-no-alias-deps", set Clflags.transparent_modules,
435091435105
"*internal*Do not record dependencies for module aliases";
435092435106

scripts/ninja.js

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ function ocamlDepForBscAsync(files, dir, depsMap) {
617617
function depModulesForBscAsync(files, dir, depsMap) {
618618
let ocamlFiles = files.filter((x) => x.endsWith(".ml") || x.endsWith(".mli"));
619619
let reFiles = files.filter((x) => x.endsWith(".re") || x.endsWith(".rei"));
620+
let resFiles = files.filter((x) => x.endsWith(".res") || x.endsWith(".resi"));
620621
/**
621622
*
622623
* @param {(value:void) =>void} resolve
@@ -672,11 +673,22 @@ function depModulesForBscAsync(files, dir, depsMap) {
672673
cb(resolve, reject)
673674
);
674675
}),
676+
new Promise((resolve, reject) => {
677+
cp.exec(
678+
`${getOcamldepFile()} -pp '../../${
679+
process.platform
680+
}/bsc.byte -as-pp' -modules -one-line -native -ml-synonym .res -mli-synonym .resi ${resFiles.join(
681+
" "
682+
)}`,
683+
config,
684+
cb(resolve, reject)
685+
);
686+
}),
675687
];
676688
}
677689

678690
/**
679-
* @typedef {('HAS_ML' | 'HAS_MLI' | 'HAS_BOTH' | 'HAS_RE' | 'HAS_REI' | 'HAS_BOTH_RE')} FileInfo
691+
* @typedef {('HAS_ML' | 'HAS_MLI' | 'HAS_BOTH' | 'HAS_RE' | 'HAS_RES' | 'HAS_REI' | 'HAS_RESI' | 'HAS_BOTH_RE' | 'HAS_BOTH_RES')} FileInfo
680692
* @param {string[]} sourceFiles
681693
* @returns {Map<string, FileInfo>}
682694
* We make a set to ensure that `sourceFiles` are not duplicated
@@ -696,8 +708,12 @@ function collectTarget(sourceFiles) {
696708
allTargets.set(name, "HAS_MLI");
697709
} else if (ext === ".re") {
698710
allTargets.set(name, "HAS_RE");
711+
} else if (ext === ".res") {
712+
allTargets.set(name, "HAS_RES");
699713
} else if (ext === ".rei") {
700714
allTargets.set(name, "HAS_REI");
715+
} else if (ext === ".resi") {
716+
allTargets.set(name, "HAS_RESI");
701717
}
702718
} else {
703719
switch (existExt) {
@@ -711,6 +727,11 @@ function collectTarget(sourceFiles) {
711727
allTargets.set(name, "HAS_BOTH_RE");
712728
}
713729
break;
730+
case "HAS_RES":
731+
if (ext === ".resi") {
732+
allTargets.set(name, "HAS_BOTH_RES");
733+
}
734+
break;
714735
case "HAS_MLI":
715736
if (ext === ".ml") {
716737
allTargets.set(name, "HAS_BOTH");
@@ -721,8 +742,14 @@ function collectTarget(sourceFiles) {
721742
allTargets.set(name, "HAS_BOTH_RE");
722743
}
723744
break;
745+
case "HAS_RESI":
746+
if (ext === ".res") {
747+
allTargets.set(name, "HAS_BOTH_RES");
748+
}
749+
break;
724750
case "HAS_BOTH_RE":
725751
case "HAS_BOTH":
752+
case "HAS_BOTH_RES":
726753
break;
727754
}
728755
}
@@ -743,13 +770,16 @@ function scanFileTargets(allTargets, collIn) {
743770
switch (ext) {
744771
case "HAS_MLI":
745772
case "HAS_REI":
773+
case "HAS_RESI":
746774
coll.push(`${mod}.cmi`);
747775
break;
776+
case "HAS_BOTH_RES":
748777
case "HAS_BOTH_RE":
749778
case "HAS_BOTH":
750779
coll.push(`${mod}.cmi`, `${mod}.cmj`);
751780
break;
752781
case "HAS_RE":
782+
case "HAS_RES":
753783
case "HAS_ML":
754784
coll.push(`${mod}.cmi`, `${mod}.cmj`);
755785
break;
@@ -777,7 +807,9 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) {
777807
let input_ml = mod + ".ml";
778808
let input_mli = mod + ".mli";
779809
let input_re = mod + ".re";
810+
let input_res = mod + ".res";
780811
let input_rei = mod + ".rei";
812+
let input_resi = mod + ".resi";
781813
/**
782814
* @type {Override[]}
783815
*/
@@ -806,14 +838,25 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) {
806838
mk([ouptput_cmj], [input_re], "cc_cmi");
807839
mk([output_cmi], [input_rei], "cc");
808840
break;
841+
case "HAS_BOTH_RES":
842+
mk([ouptput_cmj], [input_res], "cc_cmi");
843+
mk([output_cmi], [input_resi], "cc");
844+
break;
809845
case "HAS_RE":
810846
mk([output_cmi, ouptput_cmj], [input_re], "cc");
811847
break;
848+
case "HAS_RES":
849+
mk([output_cmi, ouptput_cmj], [input_res], "cc");
850+
break;
812851
case "HAS_ML":
813852
mk([output_cmi, ouptput_cmj], [input_ml]);
814853
break;
815854
case "HAS_REI":
816855
mk([output_cmi], [input_rei], "cc");
856+
break;
857+
case "HAS_RESI":
858+
mk([output_cmi], [input_resi], "cc");
859+
break;
817860
case "HAS_MLI":
818861
mk([output_cmi], [input_mli]);
819862
break;
@@ -1428,13 +1471,15 @@ function getVendorConfigNinja() {
14281471
return `
14291472
ocamlopt = ${prefix}/ocamlopt.opt
14301473
ocamllex = ${prefix}/ocamllex.opt
1474+
ocamlc = ${prefix}/ocamlc.opt
14311475
ocamlmklib = ${prefix}/ocamlmklib
14321476
ocaml = ${prefix}/ocaml
14331477
`;
14341478
}
14351479
function getEnnvConfigNinja() {
14361480
return `
1437-
ocamlopt = ocamlopt.opt
1481+
ocamlopt = ocamlopt.opt
1482+
ocamlc = ocamlc.opt
14381483
ocamllex = ocamllex.opt
14391484
ocamlmklib = ocamlmklib
14401485
ocaml = ocaml
@@ -1462,6 +1507,8 @@ function preprocessorNinjaSync() {
14621507
${getVendorConfigNinja()}
14631508
rule link
14641509
command = $ocamlopt -g -I +compiler-libs $flags $libs $in -o $out
1510+
rule bytelink
1511+
command = $ocamlc -g -I +compiler-libs $flags $libs $in -o $out
14651512
o ${cppoFile}: link ${cppoMonoFile}
14661513
libs = unix.cmxa str.cmxa
14671514
generator = true
@@ -1497,10 +1544,17 @@ ${cppoList("outcome_printer", [
14971544
])}
14981545
o ../${
14991546
process.platform
1500-
}/refmt.exe: link ${refmtMainPath}/refmt_main3.mli ${refmtMainPath}/refmt_main3.ml
1501-
libs = ocamlcommon.cmxa
1547+
}/refmt.exe: bytelink ${refmtMainPath}/refmt_main3.mli ${refmtMainPath}/refmt_main3.ml
1548+
libs = ocamlcommon.cma
15021549
flags = -I ${refmtMainPath} -I +compiler-libs -w -40-30-3 -no-alias-deps
15031550
generator = true
1551+
o ../${
1552+
process.platform
1553+
}/bsc.byte: bytelink ${refmtMainPath}/whole_compiler.mli ${refmtMainPath}/whole_compiler.ml
1554+
libs = ocamlcommon.cma
1555+
flags = -custom ./stubs/ext_basic_hash_stubs.c -I ${refmtMainPath} -I +compiler-libs -w -40-30-3 -no-alias-deps
1556+
generator = true
1557+
15041558
rule copy
15051559
command = cp $in $out
15061560
description = $in -> $out

0 commit comments

Comments
 (0)