Mercurial > hg > Others > Rakudo
comparison t/08-performance/02-qast-rewrites.t @ 0:c341f82e7ad7 default tip
Rakudo branch in cr.ie.u-ryukyu.ac.jp
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 Dec 2019 16:50:27 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c341f82e7ad7 |
---|---|
1 use lib <t/packages>; | |
2 use Test::Helpers::QAST; | |
3 use Test; | |
4 plan 4; | |
5 | |
6 subtest 'postfix-inc/dec on natives gets overwritten to prefix' => { | |
7 plan 8; | |
8 qast-is 「my int $i; $i++」, -> \v { | |
9 qast-contains-op v, 'add_i' | |
10 and not qast-contains-call v, '&prefix:<++>' | |
11 and not qast-contains-call v, '&postfix:<++>' | |
12 }, 'int, void context ++'; | |
13 | |
14 qast-is 「my int $i; my int $y; $y = 1 + $i++」, -> \v { | |
15 qast-contains-op v, 'add_i' | |
16 and not qast-contains-call v, '&prefix:<++>' | |
17 and not qast-contains-call v, '&postfix:<++>' | |
18 }, 'int, non-void context ++'; | |
19 | |
20 qast-is 「my int $i; $i--」, -> \v { | |
21 qast-contains-op v, 'sub_i' | |
22 and not qast-contains-call v, '&prefix:<-->' | |
23 and not qast-contains-call v, '&postfix:<-->' | |
24 }, 'int, void context --'; | |
25 | |
26 qast-is 「my int $i; my int $y; $y = 1 + $i--」, -> \v { | |
27 qast-contains-op v, 'sub_i' | |
28 and not qast-contains-call v, '&prefix:<-->' | |
29 and not qast-contains-call v, '&postfix:<-->' | |
30 }, 'int, non-void context --'; | |
31 | |
32 | |
33 qast-is 「my num $i = 2e0; $i++」, -> \v { | |
34 qast-contains-op v, 'add_n' | |
35 and not qast-contains-call v, '&prefix:<++>' | |
36 and not qast-contains-call v, '&postfix:<++>' | |
37 }, 'num, void context ++'; | |
38 | |
39 qast-is 「my num $i = 2e0; my num $y; $y = 1e0 + $i++」, -> \v { | |
40 qast-contains-op v, 'add_n' | |
41 and not qast-contains-call v, '&prefix:<++>' | |
42 and not qast-contains-call v, '&postfix:<++>' | |
43 }, 'num, non-void context ++'; | |
44 | |
45 qast-is 「my num $i = 2e0; $i--」, -> \v { | |
46 qast-contains-op v, 'sub_n' | |
47 and not qast-contains-call v, '&prefix:<-->' | |
48 and not qast-contains-call v, '&postfix:<-->' | |
49 }, 'num, void context --'; | |
50 | |
51 qast-is 「my num $i = 2e0; my int $y; $y = 1e0 + $i--」, -> \v { | |
52 qast-contains-op v, 'sub_n' | |
53 and not qast-contains-call v, '&prefix:<-->' | |
54 and not qast-contains-call v, '&postfix:<-->' | |
55 }, 'num, non-void context --'; | |
56 } | |
57 | |
58 | |
59 subtest '.dispatch:<.=> gets rewritten to simple ops' => { | |
60 plan +my @codes := | |
61 「(my Int $x .=new).="{"new"}"(42);」, | |
62 「my Int $x; .=new andthen .=new orelse .=new;」, | |
63 「my \foo .= new」, | |
64 「my Int \foo .= new」, | |
65 「my Int $a; .=new without $a」, | |
66 「my Int $a; .=new with $a」, | |
67 「my Int $a; $a .= new」, | |
68 「my @a; @a .= new」, 「my @a .= new」, | |
69 「my %a; %a .= new」, 「my %a .= new」, | |
70 「my &a; &a .= new」, 「my &a .= new」, | |
71 「my $b = "meows"; $b .= WHAT」, | |
72 「my @b = <z a b d e>; @b .= sort」, | |
73 ; | |
74 | |
75 for @codes -> \code { | |
76 qast-is code, :full, -> \v { | |
77 not qast-contains-callmethod v, 'dispatch:<.=>' | |
78 }, code; | |
79 } | |
80 } | |
81 | |
82 subtest 'for {}' => { | |
83 my @fors = 「for ^10 {}」, 「for 1..10 {}」, 「for 1..^10 {}」, 「for 1^..10 {}」, 「for 1^..^10 {}」, | |
84 「for 1...10 {}」, 「for 1, 2...10 {}」, 「for 10...2 {}」, 「for 1,3...9 {}」, 「for 9,7...1 {}」, | |
85 「for ^10 .reverse {}」,; | |
86 plan @fors + 2; | |
87 | |
88 for @fors { | |
89 qast-is $_, -> \v { | |
90 not qast-contains-op v, 'p6forstmt' | |
91 and not qast-contains-op v, 'p6for' | |
92 }, $_ ~ ' case gets optimized entirely'; | |
93 } | |
94 | |
95 qast-is 「for ^10 {}」, :target<ast>, -> \v { | |
96 qast-contains-op v, 'p6forstmt' | |
97 }, 'simple `for ^10 {}` case gets `p6forstmt` op to use'; | |
98 | |
99 qast-is 「for ^10 -> $, :$foo {}」, :target<ast>, -> \v { | |
100 qast-contains-op v, 'p6forstmt' | |
101 and not qast-contains-op v, 'p6for' | |
102 }, 'named arg does not accidentally get counted as a positional'; | |
103 } | |
104 | |
105 # https://github.com/rakudo/rakudo/issues/1981 | |
106 subtest 'nested metaops get fully rewritten away from &METAOP sub calls' => { | |
107 plan 2; | |
108 qast-is 「my $a; ($a //= 0) += 1」, -> \v { not qast-contains-call v, /METAOP/ }, '(//=)+='; | |
109 qast-is 「my $a; (((($a //= 0) += 1) //= 0) += 1)」, -> \v { not qast-contains-call v, /METAOP/ }, | |
110 '((((//=)+=) //=) +=)'; | |
111 } |