-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrc-ast-promises
executable file
·41 lines (35 loc) · 1.34 KB
/
rc-ast-promises
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
#!/usr/local/bin/raku
## improve on 'rc-ast-dump', via Proc::Async timeout/kill
# 2022-03-14
# needs explicit '$fh.close' or doesn't flush the print buffer, truncates AST
# concurrency/async boiler-plate from manual
# add timings, variable time-out, to aid in fine-tuning 'big lists' vs 'infinite lists'
# fgrep '&infix:<*>' ast/* | perl -npe 's/:.*//' | sort -u
shell 'rm -f ast/*';
(flat 0, 'A'..'Z').race.map: -> $dir {
for run('find', $dir, :out).out.lines -> $path {
next if 1 == $path.chars;
my $file = $path.subst(/^.*\//, '');
next if $file ~~ /\. ( \d+ | jvm ) $/;
next if $file ~~ /Left_factorials | Fibonacci_word_fractal/; # rapidly consume all memory
next if grep { / 'MOAR: BROKEN' / }, slurp $path;
my $t = now;
gen-ast $path, $file, 90;
printf "%5.1f %s\n", now - $t, $path;
}
}
sub gen-ast ($path, $file, $time-out) {
my $proc = Proc::Async.new('/usr/local/bin/raku', '--target=ast', $path);
my $fh = "ast/$file".IO.open :w;
$proc.stdout.tap(-> $v { $fh.print: $v });
my $result = await Promise.anyof(
my $promise = $proc.start,
Promise.in($time-out).then: {
unless $promise {
note "timeout on $file";
$proc.kill;
}
}
).then: { $promise.result }
$fh.close;
}