Skip to content

Commit 3e8834f

Browse files
committed
Add vm-specific opcode information
Now vm specific ops will not complain they are not defined on a non-targeted backend. (e.g "bootint")
1 parent 3e2c825 commit 3e8834f

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

docs/ops.markdown

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ correspond directly to NQP types.
4242
* % - this sigil indicates a hash parameter
4343
* ... - indicates variable args are accepted
4444

45+
VM-specific opcodes are denoted with a `jvm`, e.g. on the same line
46+
as the header. No annotation indicates this opcode should be supported on
47+
all nqp backends.
48+
4549
# Arithmetic Opcodes
4650

4751
## abs
@@ -863,42 +867,42 @@ didn't exist. May throw an exception.
863867

864868
Returns 0 if `$val` is 0, otherwise 1.
865869

866-
## bootarray
870+
## bootarray `jvm` `moar`
867871
* `bootarray()`
868872

869873
Returns a VM specific type object for a native array.
870874

871-
## boothash
875+
## boothash `jvm` `moar`
872876
* `boothash()`
873877

874878
Returns a VM specific type object for a native hash.
875879

876-
## bootint
880+
## bootint `jvm` `moar`
877881
* `bootint()`
878882

879883
Returns a VM specific type object that can box a native int.
880884

881-
## bootintarray
885+
## bootintarray `jvm` `moar`
882886
* `bootintarray()`
883887

884888
Returns a VM specific type object for a native array of int.
885889

886-
## bootnum
890+
## bootnum `jvm` `moar`
887891
* `bootnum()`
888892

889893
Returns a VM specific type object that can box a native num.
890894

891-
## bootnumarray
895+
## bootnumarray `jvm` `moar`
892896
* `bootnumarray()`
893897

894898
Returns a VM specific type object for a native array of num.
895899

896-
## bootstr
900+
## bootstr `jvm` `moar`
897901
* `bootstr()`
898902

899903
Returns a VM specific type object that can box a native str.
900904

901-
## bootstrarray
905+
## bootstrarray `jvm` `moar`
902906
* `bootstrarray()`
903907

904908
Returns a VM specific type object for a native array of str.

t/docs/opcodes.t

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
#! nqp
22

3+
my @vms := nqp::list('parrot', 'jvm', 'moar');
34
my %documented_ops := nqp::hash();
5+
for @vms -> $vm {
6+
%documented_ops{$vm} := nqp::hash();
7+
}
48

59
my @doc_lines := nqp::split("\n", nqp::readallfh(nqp::open("docs/ops.markdown","r")));
10+
my @opcode_vms := nqp::list();
611
for @doc_lines -> $line {
12+
my $match := $line ~~ /^ '##' \s* <[a..zA..Z0..9_]>+ \s* ('`' .* '`')? /;
13+
if (?$match) {
14+
if (!?$match[0]) {
15+
@opcode_vms := nqp::clone(@vms);
16+
} else {
17+
@opcode_vms := nqp::list();
18+
if $match[0] ~~ /jvm/ {
19+
nqp::push(@opcode_vms,"jvm");
20+
}
21+
if $match[0] ~~ /parrot/ {
22+
nqp::push(@opcode_vms,"parrot");
23+
}
24+
if $match[0] ~~ /moar/ {
25+
nqp::push(@opcode_vms,"moar");
26+
}
27+
}
28+
}
729
next unless $line ~~ / ^ '* ' .* '(' /;
830
$line := nqp::substr2($line, 3);
931
$line := nqp::split("(", $line)[0];
10-
%documented_ops{$line} := 1 ;
32+
for @opcode_vms -> $vm {
33+
%documented_ops{$vm}{$line} := 1 ;
34+
}
35+
1136
}
1237

1338
my %jvm_ops := nqp::hash();
@@ -27,10 +52,10 @@ for <if unless while until repeat_while repeat_until> -> $op_name {
2752
# All the jvm ops must be documented
2853

2954
for %jvm_ops -> $jvm_op {
30-
ok(%documented_ops{$jvm_op}, "JVM op '$jvm_op' is documented");
55+
ok(%documented_ops<jvm>{$jvm_op}, "JVM op '$jvm_op' is documented");
3156
}
3257

33-
for %documented_ops -> $doc_op {
58+
for %documented_ops<jvm> -> $doc_op {
3459
ok(%jvm_ops{$doc_op}, "documented op '$doc_op' exists in the JVM");
3560
}
3661

@@ -51,9 +76,9 @@ for <if unless while until repeat_while repeat_until> -> $op_name {
5176
# All the pvm ops must be documented
5277

5378
for %pvm_ops -> $pvm_op {
54-
ok(%documented_ops{$pvm_op}, "PVM op '$pvm_op' is documented");
79+
ok(%documented_ops<parrot>{$pvm_op}, "PVM op '$pvm_op' is documented");
5580
}
5681

57-
for %documented_ops -> $doc_op {
82+
for %documented_ops<parrot> -> $doc_op {
5883
ok(%pvm_ops{$doc_op}, "documented op '$doc_op' exists in the PVM");
5984
}

0 commit comments

Comments
 (0)