Skip to content

Commit 0ead167

Browse files
committed
Add script to find undocumented NQP ops
1 parent 7729dad commit 0ead167

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tools/find-undocumented-ops.p6

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env perl6
2+
sub MAIN (Str:D $nqp-folder, Str:D $moar-folder, Bool :$moar-names, Bool :$moar-and-nqp-names) {
3+
my $nqp-doc-file = make-io($nqp-folder, "docs/ops.markdown");
4+
my $moar-oplist = make-io($moar-folder, "src/core/oplist");
5+
my $mast-ops = make-io($nqp-folder, "src/vm/moar/QAST/QASTOperationsMAST.nqp");
6+
my @moar-ops;
7+
my %moar-to-nqp-mapping;
8+
my @ops;
9+
my token lq { <["'“‘]> }
10+
my token rq { <["'”’]> }
11+
for $mast-ops.lines {
12+
if /'QAST::MASTOperations.add_core_moarop_mapping('
13+
\s* <lq> $<nqp>=(\S+) <rq> \s* ',' \s*
14+
<lq> $<moar>=(\S+) <rq> /
15+
{
16+
%moar-to-nqp-mapping{~$<moar>} = ~$<nqp>;
17+
}
18+
}
19+
for $moar-oplist.lines {
20+
next if / ^ \s* '#' / or / ^ \s* $ /;
21+
my $op = .split(/\s+/, 2)[0];
22+
@moar-ops.push: $op;
23+
}
24+
my $docs = $nqp-doc-file.IO.slurp;
25+
if $moar-and-nqp-names {
26+
"## Moar-Op NQP-Op".note;
27+
}
28+
elsif $moar-names {
29+
"## Moar-Op".note;
30+
}
31+
else {
32+
"## NQP-Op".note;
33+
}
34+
for @moar-ops -> $op {
35+
if %moar-to-nqp-mapping{$op}:exists {
36+
if !$docs.contains(%moar-to-nqp-mapping{$op}) {
37+
if $moar-and-nqp-names {
38+
"%moar-to-nqp-mapping{$op} $op".say;
39+
}
40+
elsif $moar-names {
41+
$op.say;
42+
}
43+
else {
44+
%moar-to-nqp-mapping{$op}.say;
45+
}
46+
47+
}
48+
}
49+
}
50+
}
51+
multi sub make-io (Str:D $path) {
52+
my $io = $path.IO;
53+
die "Error could not find '$io'" unless $io.e;
54+
$io;
55+
}
56+
multi sub make-io (Str:D $folder, Str:D $subpath) {
57+
my $io = $folder.IO.child($subpath);
58+
die "Error could not find '$io'" unless $io.e;
59+
$io;
60+
}

0 commit comments

Comments
 (0)