Mildew/AST/Helpers.pm

filter: Statementstmt 29.6% 35 / 118 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 32.4% 12 / 37 Podpod 0.0% 0 / 23 totaltotal 20.4% 47 / 230 CC 21 SCAR 20.7
CC
21
Cov
22%
move_CONTROL
22.9
XXX
20.0
name_components
20.0
CRAP 7.9
« VAST/colonpair.pm ↑ Summary VAST/args.pm »
1 package Mildew::AST::Helpers;
2 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 $Mildew::AST::Helpers::VERSION = '0.05';
4 }
5 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 our @EXPORT = qw(string reg integer call FETCH lookup capturize let fcall name_components empty_sig routine code move_CONTROL XXX trailing_return varname lookupf curlies named_and_positional dump lookup_package YYY wrap_in_block);
7 4 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Term::ANSIColor qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use PadWalker qw(peek_my);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use YAML::XS qw(Dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub YYY {
Subroutine YYY: not called CC=1 SCAR=0.2
Pod undocumented
15 4 ▶ use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 # Mildew::prune($_[0]);
17 0 die Dump($_[0]);
18 }
19 0 ▶sub string($) {
Subroutine string: not called CC=1 SCAR=6.9
Pod undocumented
20 0 Mildew::AST::StringConstant->new(value=>$_[0]);
21 }
22  
23 0 ▶sub reg($) {
Subroutine reg: not called CC=1 SCAR=6.9
Pod undocumented
24 0 Mildew::AST::Reg->new(name=>$_[0]);
25 }
26  
27 0 ▶sub integer($) {
Subroutine integer: not called CC=1 SCAR=6.9
Pod undocumented
28 0 Mildew::AST::IntegerConstant->new(value=>$_[0]);
29 }
30  
31  
32 0 ▶sub call {
Subroutine call: not called CC=3 SCAR=24.8
Pod undocumented
33 0 ▶ Mildew::AST::Call->new(identifier=>string($_[0]),capture=>Mildew::AST::Capture->new(invocant => $_[1],positional => $_[2]//[],named => $_[3]//[]));
Condition0%0/4
$_[2] // []
l!l
00
$_[3] // []
l!l
00
MC/DC0%0/1
$_[2] // []
$_[2]
MC/DC0%0/1
$_[3] // []
$_[3]
Truth table0%0/2
A
A= $_[2]
Aresult
11
00
Truth table0%0/2
A
A= $_[3]
Aresult
11
00
34 }
35  
36 0 ▶sub FETCH {
Subroutine FETCH: not called CC=1 SCAR=6.9
37 0 my $arg = shift;
38 0 call FETCH => $arg
39 }
40  
41 0 ▶sub lookup {
Subroutine lookup: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my $thing = shift;
43 0 call lookup => reg '$scope',[string $thing];
44 }
45 0 ▶sub lookupf {
Subroutine lookupf: not called CC=1 SCAR=6.9
Pod undocumented
46 0 FETCH(lookup(@_));
47 }
48  
49 0 ▶sub curlies {
Subroutine curlies: not called CC=1 SCAR=6.9
Pod undocumented
50 0 my $thing = shift;
51 0 call 'postcircumfix:{ }' => reg '$scope',[string $thing];
52 }
53  
54 0 ▶sub fcall {
Subroutine fcall: not called CC=2 SCAR=17.9
Pod undocumented
55 0 my $func = shift;
56 0 ▶ unless (ref $func) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $func) 0 0 0
57 0 $func = FETCH(lookup($func));
58 }
59 0 call 'postcircumfix:( )' => $func, [capturize(@_)];
60 }
61 0 ▶sub capturize {
Subroutine capturize: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my ($pos,$named) = @_;
63 0 ▶ Mildew::AST::Call->new(
Condition0%0/4
$pos // []
l!l
00
$named // []
l!l
00
MC/DC0%0/1
$pos // []
$pos
MC/DC0%0/1
$named // []
$named
Truth table0%0/2
A
A= $pos
Aresult
11
00
Truth table0%0/2
A
A= $named
Aresult
11
00
64 identifier => string "new",
65 capture => Mildew::AST::Capture->new(
66 invocant => FETCH(lookup("capture")),
67 positional => $pos // [],
68 named => $named // []
69 )
70 )
71 }
72  
73 0 ▶sub let {
Subroutine let: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my ($value,$block) = @_;
75 0 my $adhoc_sig = $Mildew::adhoc_sig;
76 0 ▶ Mildew::AST::Let->new(value=>$value,block=>sub { local $Mildew::adhoc_sig = $adhoc_sig;$block->(@_)});
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 }
78  
79 0 ▶sub empty_sig {
Subroutine empty_sig: not called CC=1 SCAR=6.9
Pod undocumented
80 0 Mildew::AST::Call->new
81 ( identifier => string 'new',
82 capture => Mildew::AST::Capture->new
83 ( invocant => FETCH(lookup('AdhocSignature')),
84 positional => [],
85 named =>
86 [ string 'BIND' => Mildew::AST::Block->new
87 ( regs => [qw(interpreter scope capture)],
88 stmts => trailing_return([]))]));
89 }
90  
91 0 ▶sub block_sig {
Subroutine block_sig: not called CC=1 SCAR=6.9
Pod undocumented
92 0 Mildew::AST::Call->new
93 ( identifier => string 'new',
94 capture => Mildew::AST::Capture->new
95 ( invocant => FETCH(lookup('AdhocSignature')),
96 positional => [],
97 named =>
98 [ string 'BIND' => Mildew::AST::Block->new
99 ( regs => [qw(interpreter scope capture)],
100 stmts => trailing_return([
101 call BIND => curlies('$_'),[call positional => reg '$capture',[integer 0]]
102 ]))]));
103 }
104  
105 0 ▶sub routine {
Subroutine routine: not called CC=1 SCAR=2.2
Pod undocumented
106 0 my ($mold, $sig) = @_;
107 4 ▶ use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 0 my $realcode = $mold->emit_m0ld;
109 0 unshift @{$realcode->stmts},
110 call(STORE => call('postcircumfix:{ }' => reg '$scope', [ string '&?ROUTINE' ]), [ call(continuation => reg '$interpreter') ]),
111 call(STORE => call('postcircumfix:{ }' => reg '$scope', [ string '&?BLOCK' ]), [ call(continuation => reg '$interpreter') ]),
112 call(set_control => call(continuation => reg '$interpreter'),
113 [
114 call new => FETCH(lookup('Code')),[],
115 [
116 string 'signature' => block_sig(),
117 string 'outer' => reg '$scope',
118 string 'mold' =>
119 Mildew::AST::Block->new
120 ( regs => ['interpreter','scope'],
121 stmts =>
122 [ call( "setr" =>
123 ( call "back" => (call "continuation" => reg '$interpreter' )),
124 [ call( handle_return =>
125 call('new' => FETCH(lookup('ControlExceptionReturn'))),
126 [ FETCH(lookup('$_')),FETCH(lookup('&?ROUTINE')) ] )]),
127  
128 call( "goto" => reg '$interpreter',
129 [ call("back" => call("continuation" => reg '$interpreter'))])])]]);
130  
131 0 call new => FETCH(lookup('Code')),[],
132 [ string 'mold' => $realcode,
133 string 'outer' => reg '$scope',
134 string 'signature' => $sig ];
135 }
136  
137 0 ▶sub code {
Subroutine code: not called CC=2 SCAR=12.2
Pod undocumented
138 0 my ($mold,$sig) = @_;
139 0 my $realcode = $mold->emit_m0ld;
140 0 unshift @{$realcode->stmts},
141 call(STORE=> call('postcircumfix:{ }' => reg '$scope', [ string '&?BLOCK' ]), [ call(continuation => reg '$interpreter') ]);
142  
143 4 ▶ use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 0 ▶ call new => FETCH(lookup('Code')),[],
Branch: 1 branch
BranchTrueFalseTotal
$sig ? : 0 0 0
145 [ string 'mold' => $realcode,
146 string 'outer' => reg '$scope',
147 string 'signature' => ($sig ? $sig : empty_sig )];
148 }
149  
150 0 ▶sub move_CONTROL {
Subroutine move_CONTROL: not called CC=5 SCAR=31.3
Pod undocumented
151 0 my $statementlist = shift;
152  
153 0 my @statementlist;
154 4 ▶ use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
155 0 for (@{$statementlist}) {
156 0 my $sc = $_->{statement_control};
157 0 ▶ if (defined $sc && ($sc->isa('VAST::statement_control__S_CATCH') || $sc->isa('VAST::statement_control__S_CONTROL'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sc and $sc->isa('VAST::statement_control__S_CATCH') || $sc->isa('VAST::statement_control__S_CONTROL')) { } 0 0 0
Condition0%0/6
defined $sc and $sc->isa("VAST::statement_control__S_CATCH") || $sc->isa("VAST::statement_control__S_CONTROL")
!ll&&!rl&&r
000
$sc->isa("VAST::statement_control__S_CATCH") or $sc->isa("VAST::statement_control__S_CONTROL")
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $sc and $sc->isa("VAST::statement_control__S_CATCH") || $sc->isa("VAST::statement_control__S_CONTROL")
defined $sc $sc->isa("VAST::statement_control__S_CATCH") $sc->isa("VAST::statement_control__S_CONTROL")
Truth table0%0/4
A and B or C
A= defined $scB= $sc->isa("VAST::statement_control__S_CATCH")C= $sc->isa("VAST::statement_control__S_CONTROL")
ABCresult
0XX0
1000
11X1
1011
158 0 unshift @statementlist,$_;
159 } else {
160 0 push @statementlist,$_;
161 }
162 }
163 0 return @statementlist;
164 }
165  
166 0 ▶sub XXX {
Subroutine XXX: not called CC=4 SCAR=30.0
Pod undocumented
167 0 my $where = '';
168 0 my $m = peek_my(1)->{'$m'};
169 0 ▶ if ($m && ref ${$m}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m and ref ${$m;}) 0 0 0
Condition0%0/3
$m and ref ${$m;}
!ll&&!rl&&r
000
MC/DC0%0/2
$m and ref ${$m;}
$m ref ${$m;}
Truth table0%0/3
A and B
A= $mB= ref ${$m;}
ABresult
0X0
100
111
170 0 ▶ my $back = ${$m}->{POS} > 200 ? 200 : ${$m}->{POS};
Branch: 1 branch
BranchTrueFalseTotal
${$m;}->{'POS'} > 200 ? : 0 0 0
171 0 my ($before,) = substr($::ORIG,${$m}->{POS}-$back,$back) =~ /( (?:.*\n)? (?:.*\n)? .* \n? )$/x;
172 0 my ($after,) = substr($::ORIG,${$m}->{POS}) =~ /^(.* (?:\n.*)? (?:\n.*)? \n?)/x;
173 0 $where = GREEN.$before.RED.$after.RESET;
174 0 shift;
175 }
176 0 confess "unimplemented: \n".$where.(join ' ',@_);
177 }
178  
179 0 ▶sub trailing_return {
Subroutine trailing_return: not called CC=2 SCAR=17.9
Pod undocumented
180 0 my ($stmts,) = @_;
181 0 my @stmts = (@{$stmts});
182 0 ▶ $stmts[-1] = call(setr => call(back=>call(continuation => reg '$interpreter')),[$stmts[-1]]) if $stmts[-1];
Branch: 1 branch
BranchTrueFalseTotal
if $stmts[-1] 0 0 0
183 0 [@stmts,call(goto => reg '$interpreter',[call back=>call(continuation => reg '$interpreter')])];
184 }
185  
186 0 ▶sub varname {
Subroutine varname: not called CC=2 SCAR=17.9
Pod undocumented
187 0 my $var = shift;
188 0 ▶ ($var->{sigil}{TEXT} || '') . $var->{desigilname}{longname}{name}{identifier}{TEXT};
Condition0%0/2
$var->{'sigil'}{'TEXT'} || ''
l!l
00
MC/DC0%0/1
$var->{'sigil'}{'TEXT'} || ''
$var->{'sigil'}{'TEXT'}
Truth table0%0/2
A
A= $var->{'sigil'}{'TEXT'}
Aresult
11
00
189 }
190 0 ▶sub name_components {
Subroutine name_components: not called CC=4 SCAR=30.0
Pod undocumented
191 0 my $m = shift;
192 0 ▶ if ($m->{sublongname}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($m->{'sublongname'}) { } 0 0 0
elsif ($m->{'morename'}) { } 0 0 0
elsif ($m->{'desigilname'}) { } 0 0 0
193 0 $m->{sublongname}->components;
194 } elsif ($m->{morename}) {
195 0 ($m->{identifier}{TEXT},map {$_->{TEXT}} @{$m->{morename}[0]{identifier}});
196 } elsif ($m->{desigilname}) {
197 0 $m->{desigilname}{longname}->components;
198 } else {
199 0 XXX;
200 }
201 }
202  
203 0 ▶sub named_and_positional {
Subroutine named_and_positional: not called CC=1 SCAR=6.9
Pod undocumented
204 0 [grep { ref $_ ne 'Mildew::AST::Pair' } @_],[map { $_->key, $_->value } grep { ref eq 'Mildew::AST::Pair' } @_]
205 }
206  
207  
208 0 ▶sub lookup_package {
Subroutine lookup_package: not called CC=2 SCAR=17.9
Pod undocumented
209 0 my $package = lookup(shift(@_).'::');
210 0 for my $part (@_) {
211 0 $package = call('postcircumfix:{ }'=>FETCH($package),[string($part.'::')]);
212 }
213 0 $package;
214 }
215  
216 0 ▶sub wrap_in_block {
Subroutine wrap_in_block: not called CC=2 SCAR=17.9
Pod undocumented
217 0 my ($ast,$scope) = @_;
218 0 ▶ Mildew::AST::Block->new(regs=>['interpreter','scope'],stmts=>trailing_return([fcall(call(new => FETCH(lookup('Code')),[],[string 'outer'=>($scope // reg '$scope'),string 'signature'=>empty_sig(),string 'mold' => $ast]))]));
Condition0%0/3
$scope // &reg("\$scope")
l!l&&r!l&&!r
000
MC/DC0%0/2
$scope // &reg("\$scope")
$scope &reg("\$scope")
Truth table0%0/3
A // B
A= $scopeB= &reg("\$scope")
ABresult
1X1
011
000
219 }
220  
221 4 1;
« VAST/colonpair.pm ↑ Summary VAST/args.pm »