-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen.ml
110 lines (98 loc) · 2.86 KB
/
gen.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
open Printf
let dir_rows = ref 1
let dir_cols = ref 1
let mod_rows = ref 1
let mod_cols = ref 1
let comment_size = ref 5000
let count n =
Array.to_list (Array.init n (fun k -> k+1))
let write_directory basedir dir_row dir_col =
let dirname = sprintf "%s/dir_%d_%d" basedir dir_row dir_col in
Unix.mkdir dirname 0o777;
for row = 1 to !mod_rows do
for col = 1 to !mod_cols do
let deps =
if row = 1 then
if dir_row = 1 then
[]
else
List.flatten
(List.map
(fun k ->
List.map
(fun j ->
sprintf "M_%d_%d_%d_%d.f()" (dir_row-1) j !mod_rows k
)
(count !dir_cols)
)
(count !mod_cols)
)
else
List.map
(fun k -> sprintf "M_%d_%d_%d_%d.f()" dir_row dir_col (row-1) k)
(count !mod_cols) in
let deps =
List.rev ("()" :: (List.rev deps)) in
let str_deps = String.concat ";\n " deps in
let comment = String.make !comment_size 'X' in
let mod_text = sprintf "/* %s */
let f = () => {
%s
}
"
comment
str_deps in
let modname = sprintf "%s/m_%d_%d_%d_%d" dirname
dir_row dir_col row col in
let f = open_out (sprintf "%s.res" modname) in
output_string f mod_text;
close_out f ;
let f = open_out (sprintf "%s.resi" modname) in
output_string f "let f: unit => unit";
close_out f
done
done
let bsconfig = {|
{
"name": "test",
"sources" : {
"dir": "src",
"subdirs" : true
}
}
|}
let packagejson = {|{}|}
let write basedir =
let () = Unix.mkdir basedir 0o777 in
let f = open_out (Filename.concat basedir "bsconfig.json") in
output_string f bsconfig ;
let () = close_out f in
let f = open_out (Filename.concat basedir "package.json") in
output_string f packagejson ;
let () = close_out f in
let basedir = (Filename.concat basedir "src") in
let () = Unix.mkdir basedir 0o777 in
for row = 1 to !dir_rows do
for col = 1 to !dir_cols do
write_directory basedir row col
done
done
let () =
let basedir = ref "." in
Arg.parse
[
"-n", Arg.Int (fun n -> dir_rows := n;
dir_cols := n;
mod_rows := n;
mod_cols := n),
"<n> set all of -dir-rows, -dir-cols, -mod-rows, -mod-cols to the same value";
"-row", Arg.Int (fun n -> dir_rows := n), "<n> set row";
"-col", Arg.Int (fun n -> dir_cols := n), "<n> set col";
"-mrow", Arg.Int (fun n -> mod_rows := n), "<n> set mod-row";
"-mcol", Arg.Int (fun n -> mod_cols := n), "<n> set mod-col";
]
(fun d ->
basedir := d
)
(sprintf "usage: %s [basedir]" (Filename.basename Sys.argv.(0)));
write !basedir