line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Compile::Generators; |
2
|
3
|
|
|
3
|
|
2895
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
119
|
|
3
|
3
|
|
|
3
|
|
85
|
use 5.006001; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
113
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
277
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
6548
|
use Module::Compile -base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $label = 'GENAAAA'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub pmc_compile { |
12
|
|
|
|
|
|
|
my ($class, $input) = @_; |
13
|
|
|
|
|
|
|
my $output; |
14
|
|
|
|
|
|
|
while ($output = $class->compile($input)) { |
15
|
|
|
|
|
|
|
last if $output eq $input; |
16
|
|
|
|
|
|
|
$input = $output; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
return $output; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub compile { |
22
|
|
|
|
|
|
|
my ($class, $source) = @_; |
23
|
|
|
|
|
|
|
return $source unless $source =~ |
24
|
|
|
|
|
|
|
/^(sub .*):generator (.*\n)((?s:.*?))(^\}.*\n)/m; |
25
|
|
|
|
|
|
|
my $start = "$1$2"; |
26
|
|
|
|
|
|
|
my $end = $4; |
27
|
|
|
|
|
|
|
my ($static, $dynamic) = split /^\s*\n/m, $3, 2; |
28
|
|
|
|
|
|
|
if (not defined $dynamic) { |
29
|
|
|
|
|
|
|
$dynamic = $static; |
30
|
|
|
|
|
|
|
$static = ''; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
while ($dynamic =~ s/^(\s*yield\s*(.*))/#$1\n \$__GEN_STATE__ = '$label'; return $2; ${label}:/m) { |
33
|
|
|
|
|
|
|
$label++; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
# $dynamic =~ s/^/ /mg; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $code = <<"_"; |
38
|
|
|
|
|
|
|
${start} my \$__GEN_STATE__ = undef; |
39
|
|
|
|
|
|
|
${static} |
40
|
|
|
|
|
|
|
return sub { |
41
|
|
|
|
|
|
|
goto \$__GEN_STATE__ if defined \$__GEN_STATE__; |
42
|
|
|
|
|
|
|
${dynamic} |
43
|
|
|
|
|
|
|
\$__GEN_STATE__ = '$label'; |
44
|
|
|
|
|
|
|
${label}: |
45
|
|
|
|
|
|
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
${end} |
48
|
|
|
|
|
|
|
_ |
49
|
|
|
|
|
|
|
$label++; |
50
|
|
|
|
|
|
|
$source =~ s/^sub .*:generator .*\n(?s:.*?)^\}.*\n/$code/m; |
51
|
|
|
|
|
|
|
return $source; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__DATA__ |