~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to t/docs/opcodes.t

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! nqp
 
2
 
 
3
my @*vms := nqp::list('parrot', 'jvm', 'moar');
 
4
 
 
5
my %documented_ops := find_documented_opcodes();
 
6
 
 
7
my %ops := hash_of_vms();
 
8
 
 
9
%ops<jvm> := find_opcodes(
 
10
    :file("src/vm/jvm/QAST/Compiler.nqp"),
 
11
    :keywords(<map_classlib_core_op add_core_op map_jvm_core_op>)
 
12
);
 
13
 
 
14
%ops<parrot> := find_opcodes(
 
15
    :file("src/vm/parrot/QAST/Operations.nqp"),
 
16
    :keywords(<add_core_op add_core_pirop_mapping>)
 
17
);
 
18
 
 
19
%ops<moar> := find_opcodes(
 
20
    :file("src/vm/moar/QAST/QASTOperationsMAST.nqp"),
 
21
    :keywords(<add_core_op add_core_moarop_mapping>)
 
22
);
 
23
 
 
24
# Most backends programmatically add these ops - to keep our cheating simple,
 
25
# add them to each of the backends manually
 
26
for <if unless while until repeat_while repeat_until> -> $op_name {
 
27
    for @*vms -> $vm {
 
28
        %ops{$vm}{$op_name} := 1;
 
29
    }
 
30
}
 
31
 
 
32
# Are ops that are implemented documented? Fail once per opcode
 
33
my %combined_ops := nqp::hash();
 
34
for @*vms -> $vm {
 
35
    for %ops{$vm} -> $op {
 
36
        if !%combined_ops{$op} {
 
37
            %combined_ops{$op} := nqp::list($vm);
 
38
        } else {
 
39
            nqp::push(%combined_ops{$op}, $vm);
 
40
        }
 
41
    }
 
42
}
 
43
 
 
44
for %combined_ops -> $opcode {
 
45
    my $vms := nqp::join(";", %combined_ops{$opcode});
 
46
    ok(%documented_ops<any>{$opcode}, "Opcode '$opcode' ($vms) is documented");
 
47
}
 
48
 
 
49
# Do documented opcodes actually exist? Fail once per vm if not.
 
50
for @*vms -> $vm {
 
51
    for %documented_ops{$vm} -> $doc_op {
 
52
        ok(%ops{$vm}{$doc_op}, "documented op '$doc_op' exists in $vm");
 
53
    }
 
54
}
 
55
 
 
56
sub find_opcodes(:$file, :@keywords) {
 
57
    my %ops := nqp::hash();
 
58
    my @lines := nqp::split("\n", nqp::readallfh(nqp::open($file,"r")));
 
59
    for @lines -> $line {
 
60
        next unless $line ~~ / @keywords /;
 
61
        $line := nqp::split("'", $line)[1];
 
62
        next unless nqp::chars($line);
 
63
        %ops{$line} := 1;
 
64
    }
 
65
    return %ops;
 
66
}
 
67
 
 
68
sub hash_of_vms() {
 
69
    my %hash := nqp::hash();
 
70
    for @*vms -> $vm {
 
71
        %hash{$vm} := nqp::hash();
 
72
    }
 
73
    return %hash;
 
74
}
 
75
 
 
76
sub find_documented_opcodes() {
 
77
    my %documented_ops := hash_of_vms();
 
78
    %documented_ops<any> := nqp::hash();
 
79
 
 
80
    my @doc_lines := nqp::split("\n", nqp::readallfh(nqp::open("docs/ops.markdown","r")));
 
81
    my @opcode_vms := nqp::list();
 
82
    for @doc_lines -> $line {
 
83
        my $match := $line ~~ /^ '##' \s* <[a..zA..Z0..9_]>+ \s* ('`' .* '`')? /;
 
84
        if (?$match) {
 
85
            if (!?$match[0]) {
 
86
                @opcode_vms := nqp::clone(@*vms);
 
87
            } else {
 
88
                @opcode_vms := nqp::list();
 
89
                if $match[0] ~~ /jvm/ {
 
90
                    nqp::push(@opcode_vms,"jvm");
 
91
                }
 
92
                if $match[0] ~~ /parrot/ {
 
93
                    nqp::push(@opcode_vms,"parrot");
 
94
                }
 
95
                if $match[0] ~~ /moar/ {
 
96
                    nqp::push(@opcode_vms,"moar");
 
97
                }
 
98
            }
 
99
        }
 
100
        next unless $line ~~ / ^ '* ' .* '(' /;
 
101
        $line := nqp::substr2($line, 3);
 
102
        $line := nqp::split("(", $line)[0];
 
103
        for @opcode_vms -> $vm {
 
104
            %documented_ops{$vm}{$line} := 1 ;
 
105
        }
 
106
        %documented_ops<any>{$line} := 1 ;
 
107
    
 
108
    }
 
109
    return %documented_ops;
 
110
}