Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add vm-specific opcode information
Now vm specific ops will not complain they are not defined
on a non-targeted backend. (e.g "bootint")
  • Loading branch information
coke committed Oct 9, 2013
1 parent 3e2c825 commit 3e8834f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
20 changes: 12 additions & 8 deletions docs/ops.markdown
Expand Up @@ -42,6 +42,10 @@ correspond directly to NQP types.
* % - this sigil indicates a hash parameter
* ... - indicates variable args are accepted

VM-specific opcodes are denoted with a `jvm`, e.g. on the same line
as the header. No annotation indicates this opcode should be supported on
all nqp backends.

# Arithmetic Opcodes

## abs
Expand Down Expand Up @@ -863,42 +867,42 @@ didn't exist. May throw an exception.

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

## bootarray
## bootarray `jvm` `moar`
* `bootarray()`

Returns a VM specific type object for a native array.

## boothash
## boothash `jvm` `moar`
* `boothash()`

Returns a VM specific type object for a native hash.

## bootint
## bootint `jvm` `moar`
* `bootint()`

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

## bootintarray
## bootintarray `jvm` `moar`
* `bootintarray()`

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

## bootnum
## bootnum `jvm` `moar`
* `bootnum()`

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

## bootnumarray
## bootnumarray `jvm` `moar`
* `bootnumarray()`

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

## bootstr
## bootstr `jvm` `moar`
* `bootstr()`

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

## bootstrarray
## bootstrarray `jvm` `moar`
* `bootstrarray()`

Returns a VM specific type object for a native array of str.
Expand Down
35 changes: 30 additions & 5 deletions t/docs/opcodes.t
@@ -1,13 +1,38 @@
#! nqp

my @vms := nqp::list('parrot', 'jvm', 'moar');
my %documented_ops := nqp::hash();
for @vms -> $vm {
%documented_ops{$vm} := nqp::hash();
}

my @doc_lines := nqp::split("\n", nqp::readallfh(nqp::open("docs/ops.markdown","r")));
my @opcode_vms := nqp::list();
for @doc_lines -> $line {
my $match := $line ~~ /^ '##' \s* <[a..zA..Z0..9_]>+ \s* ('`' .* '`')? /;
if (?$match) {
if (!?$match[0]) {
@opcode_vms := nqp::clone(@vms);
} else {
@opcode_vms := nqp::list();
if $match[0] ~~ /jvm/ {
nqp::push(@opcode_vms,"jvm");
}
if $match[0] ~~ /parrot/ {
nqp::push(@opcode_vms,"parrot");
}
if $match[0] ~~ /moar/ {
nqp::push(@opcode_vms,"moar");
}
}
}
next unless $line ~~ / ^ '* ' .* '(' /;
$line := nqp::substr2($line, 3);
$line := nqp::split("(", $line)[0];
%documented_ops{$line} := 1 ;
for @opcode_vms -> $vm {
%documented_ops{$vm}{$line} := 1 ;
}

}

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

for %jvm_ops -> $jvm_op {
ok(%documented_ops{$jvm_op}, "JVM op '$jvm_op' is documented");
ok(%documented_ops<jvm>{$jvm_op}, "JVM op '$jvm_op' is documented");
}

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

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

for %pvm_ops -> $pvm_op {
ok(%documented_ops{$pvm_op}, "PVM op '$pvm_op' is documented");
ok(%documented_ops<parrot>{$pvm_op}, "PVM op '$pvm_op' is documented");
}

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

0 comments on commit 3e8834f

Please sign in to comment.