CljPerl/Evaler.pm

filter: Statementstmt 84.1% 784 / 932 Branchbran 63.8% 415 / 650 Conditioncond 65.7% 142 / 216 MC/DCmcdc 33.6% 41 / 122 Subroutinesub 97.3% 36 / 37 Podpod 0.0% 0 / 25 totaltotal 71.5% 1418 / 1982 CC 426 SCAR 67.6
CC
426
Cov
75%
builtin
1519.2
perlfunc_call
307.0
_eval
98.7
CRAP 866.4
↑ Summary CljPerl/Printer.pm »
1 package CljPerl::Evaler;
2
3 # use strict;
4 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶ use CljPerl::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶ use CljPerl::Var;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶ use CljPerl::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶ use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶ use Coro;
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 2 our $VERSION = '0.10';
13
14 2 our $namespace_key = "0namespace0";
15
16 3 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 3 my $class = shift;
18 3 my @default_namespace = ();
19 3 my @scopes = ({$namespace_key=>\@default_namespace});
20 3 my @file_stack = ();
21 3 my @caller = ();
22 3 my $self = {class=>$class,
23 scopes=>\@scopes,
24 loaded_files=>{},
25 file_stack=>\@file_stack,
26 caller=>\@caller,
27 exception=>undef,
28 quotation_scope=>0,
29 syntaxquotation_scope=>0};
30 3 bless $self;
31 3 return $self;
32 }
33
34 2726 ▶ sub scopes {
Subroutine scopes: called CC=1 SCAR=0.0
Pod undocumented
35 2726 my $self = shift;
36 2726 return $self->{scopes};
37 }
38
39 117 ▶ sub push_scope {
Subroutine push_scope: called CC=1 SCAR=0.0
Pod undocumented
40 117 my $self = shift;
41 117 my $context = shift;
42 117 my %c = %{$context};
43 117 my @ns = @{$c{$namespace_key}};
44 117 $c{$namespace_key} = \@ns;
45 117 unshift @{$self->scopes()}, \%c;
46 }
47
48 116 ▶ sub pop_scope {
Subroutine pop_scope: called CC=1 SCAR=0.0
Pod undocumented
49 116 my $self = shift;
50 116 shift @{$self->scopes()};
51 }
52
53 2485 ▶ sub current_scope {
Subroutine current_scope: called CC=1 SCAR=0.0
Pod undocumented
54 2485 my $self = shift;
55 2485 my $scope = @{$self->scopes()}[0];
56 2485 return $scope;
57 }
58
59 117 ▶ sub push_caller {
Subroutine push_caller: called CC=1 SCAR=0.0
Pod undocumented
60 117 my $self = shift;
61 117 my $ast = shift;
62 117 unshift @{$self->{caller}}, $ast;
63 }
64
65 117 ▶ sub pop_caller {
Subroutine pop_caller: called CC=1 SCAR=0.0
Pod undocumented
66 117 my $self = shift;
67 117 shift @{$self->{caller}};
68 }
69
70 4 ▶ sub caller_size {
Subroutine caller_size: called CC=1 SCAR=0.0
Pod undocumented
71 4 my $self = shift;
72 4 scalar @{$self->{caller}};
73 }
74
75 4 ▶ sub push_namespace {
Subroutine push_namespace: called CC=1 SCAR=0.0
Pod undocumented
76 4 my $self = shift;
77 4 my $namespace = shift;
78 4 my $scope = $self->current_scope();
79 4 unshift @{$scope->{$namespace_key}}, $namespace;
80 }
81
82 4 ▶ sub pop_namespace {
Subroutine pop_namespace: called CC=1 SCAR=0.0
Pod undocumented
83 4 my $self = shift;
84 4 my $scope = $self->current_scope();
85 4 shift @{$scope->{$namespace_key}};
86 }
87
88 1482 ▶ sub current_namespace {
Subroutine current_namespace: called CC=2 SCAR=6.9
Pod undocumented
89 1482 my $self = shift;
90 1482 my $scope = $self->current_scope();
91 1482 my $namespace = @{$scope->{$namespace_key}}[0];
92 1482 ▶ return "" if(!defined $namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $namespace 1424 58 1482
93 58 return $namespace;
94 }
95
96 314 ▶ sub new_var {
Subroutine new_var: called CC=1 SCAR=0.0
Pod undocumented
97 314 my $self = shift;
98 314 my $name = shift;
99 314 my $value = shift;
100 314 my $scope = $self->current_scope();
101 314 $name = $self->current_namespace() . "#" . $name;
102 314 $scope->{$name} = CljPerl::Var->new($name, $value);
103 }
104
105 593 ▶ sub var {
Subroutine var: called CC=4 SCAR=14.0
Pod undocumented
106 593 my $self = shift;
107 593 my $name = shift;
108 593 my $scope = $self->current_scope();
109 593 ▶ if(exists $scope->{$name}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $scope->{$name}) { } 6 587 593
elsif (exists $$scope{$self->current_namespace . '#' . $name}) { } 581 6 587
elsif (exists $$scope{'#' . $name}) { } 6 0 6
110 6 return $scope->{$name};
111 } elsif(exists $scope->{$self->current_namespace() . "#" . $name}){
112 581 return $scope->{$self->current_namespace() . "#" . $name};
113 } elsif(exists $scope->{"#" . $name}) {
114 6 return $scope->{"#" . $name};
115 };
116 0 return undef;
117 }
118
119 13 ▶ sub current_file {
Subroutine current_file: called CC=2 SCAR=6.9
Pod undocumented
120 13 my $self = shift;
121 13 my $sd = scalar @{$self->{file_stack}};
122 13 ▶ if($sd == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sd == 0) { } 6 7 13
123 6 return ".";
124 } else {
125 7 return ${$self->{file_stack}}[$sd-1];
126 }
127 }
128
129 8 ▶ sub search_file {
Subroutine search_file: called CC=7 SCAR=19.7
Pod undocumented
130 8 my $self = shift;
131 8 my $file = shift;
132 8 foreach my $ext ("", ".clp") {
133 13 ▶ if(-f "$file$ext") {
Branch: 3 branches
BranchTrueFalseTotal
if (-f "$file$ext") { } 2 11 13
elsif (-f dirname($self->current_file) . "/$file$ext") { } 2 9 11
elsif (-f $file . $ext) { } 0 9 9
134 2 return "$file$ext";
135 } elsif(-f dirname($self->current_file()) . "/$file$ext") {
136 2 return dirname($self->current_file()) . "/$file$ext";
137 } elsif(-f $file . $ext) {
138 0 return $file . $ext;
139 };
140 9 foreach my $p (@INC) {
141 49 ▶ if(-f "$p/$file$ext") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$p/$file$ext") 4 45 49
142 4 return "$p/$file$ext";
143 };
144 }
145 }
146 0 CljPerl::Logger::error("cannot find " . $file);
147 }
148
149 8 ▶ sub load {
Subroutine load: called CC=3 SCAR=11.0
Pod undocumented
150 8 my $self = shift;
151 8 my $file = shift;
152 CljPerl::Logger::error("cannot require file " . $file . " in non-global scope")
153 8 ▶ if scalar @{$self->scopes()} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self->scopes;} > 1 0 8 8
154 8 $file = File::Spec->rel2abs($self->search_file($file));
155 8 ▶ return 1 if exists $self->{loaded_files}->{$file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"loaded_files"}{$file} 1 7 8
156 7 $self->{loaded_files}->{$file} = 1;
157 7 push @{$self->{file_stack}}, $file;
158 7 my $res = $self->read($file);
159 7 pop @{$self->{file_stack}};
160 7 return $res;
161 }
162
163 7 ▶ sub read {
Subroutine read: called CC=1 SCAR=0.0
Pod undocumented
164 7 my $self = shift;
165 7 my $file = shift;
166 7 my $reader = CljPerl::Reader->new();
167 7 $reader->read_file($file);
168 7 my $res = undef;
169 7 ▶ $reader->ast()->each(sub {$res = $self->_eval($_[0])});
Subroutine __ANON__: called CC=1 SCAR=0.0
170 7 return $res;
171 }
172
173 2 ▶ sub eval {
Subroutine eval: called CC=1 SCAR=0.0
Pod undocumented
174 2 my $self = shift;
175 2 my $str = shift;
176 2 my $reader = CljPerl::Reader->new();
177 2 $reader->read_string($str);
178 2 my $res = undef;
179 2 ▶ $reader->ast()->each(sub {$res = $self->_eval($_[0])});
Subroutine __ANON__: called CC=1 SCAR=0.0
180 2 return $res;
181 }
182
183 2 our $builtin_funcs = {
184 "eval"=>1,
185 "syntax"=>1,
186 "catch"=>1,
187 "exception-label"=>1,
188 "exception-message"=>1,
189 "throw"=>1,
190 "def"=>1,
191 "set!"=>1,
192 "let"=>1,
193 "fn"=>1,
194 "defmacro"=>1,
195 "gen-sym"=>1,
196 "list"=>1,
197 "car"=>1,
198 "cdr"=>1,
199 "cons"=>1,
200 "if"=>1,
201 "while"=>1,
202 "begin"=>1,
203 "length"=>1,
204 "reverse"=>1,
205 "object-id"=>1,
206 "type"=>1,
207 "perlobj-type"=>1,
208 "meta"=>1,
209 "apply"=>1,
210 "append"=>1,
211 "keys"=>1,
212 "namespace-begin"=>1,
213 "namespace-end"=>1,
214 "perl->clj"=>1,
215 "clj->string"=>1,
216 "!"=>1,
217 "not"=>1,
218 "+"=>1,
219 "-"=>1,
220 "*"=>1,
221 "/"=>1,
222 "%"=>1,
223 "=="=>1,
224 "!="=>1,
225 ">"=>1,
226 ">="=>1,
227 "<"=>1,
228 "<="=>1,
229 "."=>1,
230 "->"=>1,
231 "eq"=>1,
232 "ne"=>1,
233 "and"=>1,
234 "or"=>1,
235 "equal"=>1,
236 "require"=>1,
237 "read"=>1,
238 "println"=>1,
239 "coro"=>1,
240 "coro-suspend"=>1,
241 "coro-sleep"=>1,
242 "coro-yield"=>1,
243 "coro-resume"=>1,
244 "coro-wake"=>1,
245 "coro-join"=>1,
246 "coro-current"=>1,
247 "coro-main"=>1,
248 "xml-name"=>1,
249 "trace-vars"=>1};
250
251 2 our $empty_list = CljPerl::Seq->new("list");
252 2 our $true = CljPerl::Atom->new("bool", "true");
253 2 our $false = CljPerl::Atom->new("bool", "false");
254 2 our $nil = CljPerl::Atom->new("nil", "nil");
255
256 1342 ▶ sub bind {
Subroutine bind: called CC=37 SCAR=36.3
Pod undocumented
257 1342 my $self = shift;
258 1342 my $ast = shift;
259 1342 my $class = $ast->class();
260 1342 my $type = $ast->type();
261 1342 my $value = $ast->value();
262 1342 ▶ if($type eq "symbol" and $value eq "true") {
Branch: 9 branches
BranchTrueFalseTotal
if ($type eq 'symbol' and $value eq 'true') { } 9 1333 1342
elsif ($type eq 'symbol' and $value eq 'false') { } 7 1326 1333
elsif ($type eq 'symbol' and $value eq 'nil') { } 0 1326 1326
elsif ($type eq 'accessor') { } 3 1323 1326
elsif ($type eq 'sender') { } 0 1323 1323
elsif ($type eq 'syntaxquotation' or $type eq 'quotation') { } 89 1234 1323
elsif ($type eq 'symbol' and $self->{'syntaxquotation_scope'} == 0 and $self->{'quotation_scope'} == 0 or $type eq 'dequotation' and $self->{'syntaxquotation_scope'} > 0) { } 971 263 1234
elsif ($type eq 'symbol' and $self->{'quotation_scope'} > 0) { } 48 215 263
elsif ($class eq 'Seq') { } 109 106 215
Condition100%3/3
$type eq "symbol" and $value eq "true"
!ll&&!rl&&r
33110029
MC/DC100%2/2
$type eq "symbol" and $value eq "true"
$type eq "symbol" $value eq "true"
Truth table100%3/3
A and B
A= $type eq "symbol"B= $value eq "true"
ABresult
0X0
100
111
263 9 return $true;
264 ▶ } elsif($type eq "symbol" and $value eq "false") {
Condition100%3/3
$type eq "symbol" and $value eq "false"
!ll&&!rl&&r
3319957
MC/DC100%2/2
$type eq "symbol" and $value eq "false"
$type eq "symbol" $value eq "false"
Truth table100%3/3
A and B
A= $type eq "symbol"B= $value eq "false"
ABresult
0X0
100
111
265 7 return $false;
266 ▶ } elsif($type eq "symbol" and $value eq "nil") {
Condition66%2/3
$type eq "symbol" and $value eq "nil"
!ll&&!rl&&r
3319950
MC/DC0%0/2
$type eq "symbol" and $value eq "nil"
$type eq "symbol" $value eq "nil"
Truth table66%2/3
A and B
A= $type eq "symbol"B= $value eq "nil"
ABresult
0X0
100
111
267 0 return $nil;
268 } elsif($type eq "accessor") {
269 3 return CljPerl::Atom->new("accessor", $self->bind($value));
270 } elsif($type eq "sender") {
271 0 return CljPerl::Atom->new("sender", $self->bind($value));
272 ▶ } elsif($type eq "syntaxquotation" or $type eq "quotation") {
Condition100%3/3
$type eq "syntaxquotation" or $type eq "quotation"
l!l&&r!l&&!r
50391234
MC/DC100%2/2
$type eq "syntaxquotation" or $type eq "quotation"
$type eq "syntaxquotation" $type eq "quotation"
Truth table100%3/3
A or B
A= $type eq "syntaxquotation"B= $type eq "quotation"
ABresult
1X1
011
000
273 89 ▶ $self->{syntaxquotation_scope} += 1 if $type eq "syntaxquotation";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "syntaxquotation" 50 39 89
274 89 ▶ $self->{quotation_scope} += 1 if $type eq "quotation";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "quotation" 39 50 89
275 89 my $r = $self->bind($value);
276 89 ▶ $self->{syntaxquotation_scope} -= 1 if $type eq "syntaxquotation";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "syntaxquotation" 50 39 89
277 89 ▶ $self->{quotation_scope} -= 1 if $type eq "quotation";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "quotation" 39 50 89
278 89 return $r;
279 ▶ } elsif(($type eq "symbol" and $self->{syntaxquotation_scope} == 0
Condition91%11/12
$type eq "symbol" and $self->{"syntaxquotation_scope"} == 0 and $self->{"quotation_scope"} == 0 or $type eq "dequotation" and $self->{"syntaxquotation_scope"} > 0
l!l&&r!l&&!r
850121263
$type eq "symbol" and $self->{"syntaxquotation_scope"} == 0 and $self->{"quotation_scope"} == 0
!ll&&!rl&&r
33648850
$type eq "symbol" and $self->{"syntaxquotation_scope"} == 0
!ll&&!rl&&r
23997898
$type eq "dequotation" and $self->{"syntaxquotation_scope"} > 0
!ll&&!rl&&r
2630121
MC/DC80%4/5
$type eq "symbol" and $self->{"syntaxquotation_scope"} == 0 and $self->{"quotation_scope"} == 0 or $type eq "dequotation" and $self->{"syntaxquotation_scope"} > 0
$type eq "symbol" $self->{"syntaxquotation_scope"} == 0 $self->{"quotation_scope"} == 0 $type eq "dequotation" $self->{"syntaxquotation_scope"} > 0
Truth table50%5/10
A and B and C or D and E
A= $type eq "symbol"B= $self->{"syntaxquotation_scope"} == 0C= $self->{"quotation_scope"} == 0D= $type eq "dequotation"E= $self->{"syntaxquotation_scope"} > 0
ABCDEresult
111XX1
0XX111
10X111
110111
0XX0X0
0XX100
10X0X0
10X100
1100X0
110100
280 and $self->{quotation_scope} == 0) or
281 ($type eq "dequotation" and $self->{syntaxquotation_scope} > 0)) {
282 $ast->error("dequotation should be in syntax quotation scope")
283 971 ▶ if ($type eq "dequotation" and $self->{syntaxquotation_scope} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "dequotation" and $self->{"syntaxquotation_scope"} == 0 0 971 971
Condition66%2/3
$type eq "dequotation" and $self->{"syntaxquotation_scope"} == 0
!ll&&!rl&&r
8501210
MC/DC0%0/2
$type eq "dequotation" and $self->{"syntaxquotation_scope"} == 0
$type eq "dequotation" $self->{"syntaxquotation_scope"} == 0
Truth table66%2/3
A and B
A= $type eq "dequotation"B= $self->{"syntaxquotation_scope"} == 0
ABresult
0X0
100
111
284 971 my $name = $value;
285 971 ▶ if($type eq "dequotation" and $value =~ /^@(\S+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "dequotation" and $value =~ /^@(\S+)$/) 37 934 971
Condition100%3/3
$type eq "dequotation" and $value =~ /^@(\S+)$/
!ll&&!rl&&r
8508437
MC/DC100%2/2
$type eq "dequotation" and $value =~ /^@(\S+)$/
$type eq "dequotation" $value =~ /^@(\S+)$/
Truth table100%3/3
A and B
A= $type eq "dequotation"B= $value =~ /^@(\S+)$/
ABresult
0X0
100
111
286 37 $name = $1;
287 }
288 971 ▶ return $ast if exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/;
Branch: 1 branch
BranchTrueFalseTotal
if exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/ 504 467 971
Condition100%3/3
exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/
l!l&&r!l&&!r
5031467
MC/DC100%2/2
exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/
exists $builtin_funcs->{$name} $name =~ /^(\.|->)\S+$/
Truth table100%3/3
A or B
A= exists $builtin_funcs->{$name}B= $name =~ /^(\.|->)\S+$/
ABresult
1X1
011
000
289 467 my $var = $self->var($name);
290 467 ▶ $ast->error("unbound symbol") if !defined $var;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var 0 467 467
291 467 return $var->value();
292 ▶ } elsif($type eq "symbol"
Condition100%3/3
$type eq "symbol" and $self->{"quotation_scope"} > 0
!ll&&!rl&&r
1189748
MC/DC100%2/2
$type eq "symbol" and $self->{"quotation_scope"} > 0
$type eq "symbol" $self->{"quotation_scope"} > 0
Truth table100%3/3
A and B
A= $type eq "symbol"B= $self->{"quotation_scope"} > 0
ABresult
0X0
100
111
293 and $self->{quotation_scope} > 0) {
294 48 my $q = CljPerl::Atom->new("quotation", $value);
295 48 return $q;
296 } elsif($class eq "Seq") {
297 109 ▶ return $empty_list if $type eq "list" and $ast->size() == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "list" and $ast->size == 0 2 107 109
Condition100%3/3
$type eq "list" and $ast->size == 0
!ll&&!rl&&r
41032
MC/DC100%2/2
$type eq "list" and $ast->size == 0
$type eq "list" $ast->size == 0
Truth table100%3/3
A and B
A= $type eq "list"B= $ast->size == 0
ABresult
0X0
100
111
298 107 my $list = CljPerl::Seq->new("list");
299 107 $list->type($type);
300 107 foreach my $i (@{$value}) {
301 298 ▶ if($i->type() eq "dequotation" and $i->value() =~ /^@/){
Branch: 1 branch
BranchTrueFalseTotal
if ($i->type eq 'dequotation' and $i->value =~ /^@/) { } 37 261 298
Condition100%3/3
$i->type eq "dequotation" and $i->value =~ /^@/
!ll&&!rl&&r
1798237
MC/DC100%2/2
$i->type eq "dequotation" and $i->value =~ /^@/
$i->type eq "dequotation" $i->value =~ /^@/
Truth table100%3/3
A and B
A= $i->type eq "dequotation"B= $i->value =~ /^@/
ABresult
0X0
100
111
302 37 my $dl = $self->bind($i);
303 37 ▶ $i->error("~@ should be given a list but got " . $dl->type()) if $dl->type() ne "list";
Branch: 1 branch
BranchTrueFalseTotal
if $dl->type ne "list" 0 37 37
304 37 foreach my $di (@{$dl->value()}){
305 59 $list->append($di);
306 };
307 } else {
308 261 $list->append($self->bind($i));
309 }
310 }
311 107 return $list;
312 };
313 106 return $ast;
314 }
315
316 1841 ▶ sub _eval {
Subroutine _eval: called CC=77 SCAR=45.9
317 1841 my $self = shift;
318 1841 my $ast = shift;
319 1841 my $class = $ast->class();
320 1841 my $type = $ast->type();
321 1841 my $value = $ast->value();
322 1841 ▶ if($type eq "list") {
Branch: 9 branches
BranchTrueFalseTotal
if ($type eq 'list') { } 649 1192 1841
elsif ($type eq 'accessor') { } 33 1159 1192
elsif ($type eq 'sender') { } 1 1158 1159
elsif ($type eq 'symbol') { } 858 300 1158
elsif ($type eq 'syntaxquotation') { } 49 251 300
elsif ($type eq 'quotation') { } 39 212 251
elsif ($class eq 'Seq' and $type eq 'vector') { } 5 207 212
elsif ($class eq 'Seq' and $type eq 'map' || $type eq 'meta') { } 14 193 207
elsif ($class eq 'Seq' and $type eq 'xml') { } 11 364 375
323 649 my $size = $ast->size();
324 649 ▶ if($size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 0) 5 644 649
325 5 return $empty_list;
326 };
327 644 my $f = $self->_eval($ast->first());
328 644 my $ftype = $f->type();
329 644 my $fvalue = $f->value();
330 644 ▶ if($ftype eq "symbol") {
Branch: 6 branches
BranchTrueFalseTotal
if ($ftype eq 'symbol') { } 503 141 644
elsif ($ftype eq 'key accessor') { } 11 130 141
elsif ($ftype eq 'index accessor') { } 22 108 130
elsif ($ftype eq 'function') { } 66 42 108
elsif ($ftype eq 'perlfunction') { } 0 42 42
elsif ($ftype eq 'macro') { } 42 0 42
331 503 return $self->builtin($f, $ast);
332 } elsif($ftype eq "key accessor") {
333 11 ▶ $ast->error("key accessor expects >= 1 arguments") if $size == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size == 1 0 11 11
334 11 my $m = $self->_eval($ast->second());
335 11 my $mtype = $m->type();
336 11 my $mvalue = $m->value();
337 11 ▶ $ast->error("key accessor expects a map or meta as the first arguments but got " . $mtype)
Branch: 1 branch
BranchTrueFalseTotal
if $mtype ne "map" and $mtype ne "meta" 0 11 11
Condition66%2/3
$mtype ne "map" and $mtype ne "meta"
!ll&&!rl&&r
470
MC/DC0%0/2
$mtype ne "map" and $mtype ne "meta"
$mtype ne "map" $mtype ne "meta"
Truth table66%2/3
A and B
A= $mtype ne "map"B= $mtype ne "meta"
ABresult
0X0
100
111
338 if $mtype ne "map" and $mtype ne "meta";
339 11 ▶ if($size == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($size == 2) { } 7 4 11
elsif ($size == 3) { } 4 0 4
340 #$ast->error("key " . $fvalue . " does not exist")
341 7 ▶ return $nil if ! exists $mvalue->{$fvalue};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $mvalue->{$fvalue} 0 7 7
342 7 return $mvalue->{$fvalue};
343 } elsif($size == 3) {
344 4 my $v = $self->_eval($ast->third());
345 4 ▶ if($v->type() eq "nil"){
Branch: 1 branch
BranchTrueFalseTotal
if ($v->type eq 'nil') { } 0 4 4
346 0 delete $mvalue->{$fvalue};
347 0 return $nil;
348 } else {
349 4 $mvalue->{$fvalue} = $v;
350 4 return $mvalue->{$fvalue};
351 };
352 } else {
353 0 $ast->error("key accessor expects <= 2 arguments");
354 }
355 } elsif($ftype eq "index accessor") {
356 22 ▶ $ast->error("index accessor expects >= 1 arguments") if $size == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size == 1 0 22 22
357 22 my $v = $self->_eval($ast->second());
358 22 my $vtype = $v->type();
359 22 my $vvalue = $v->value();
360 22 ▶ $ast->error("index accessor expects a vector or list or xml as the first arguments but got " . $vtype)
Branch: 1 branch
BranchTrueFalseTotal
if $vtype ne "vector" and $vtype ne "list" and $vtype ne "xml" 0 22 22
Condition83%5/6
$vtype ne "vector" and $vtype ne "list" and $vtype ne "xml"
!ll&&!rl&&r
1840
$vtype ne "vector" and $vtype ne "list"
!ll&&!rl&&r
1084
MC/DC0%0/3
$vtype ne "vector" and $vtype ne "list" and $vtype ne "xml"
$vtype ne "vector" $vtype ne "list" $vtype ne "xml"
Truth table75%3/4
A and B and C
A= $vtype ne "vector"B= $vtype ne "list"C= $vtype ne "xml"
ABCresult
0XX0
10X0
1100
1111
361 if $vtype ne "vector" and $vtype ne "list"
362 and $vtype ne "xml";
363 22 ▶ $ast->error("index is bigger than size") if $fvalue >= scalar @{$vvalue};
Branch: 1 branch
BranchTrueFalseTotal
if $fvalue >= scalar @{$vvalue;} 0 22 22
364 22 ▶ if($size == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($size == 2) { } 21 1 22
elsif ($size == 3) { } 1 0 1
365 21 return $vvalue->[$fvalue];
366 } elsif($size == 3) {
367 1 $vvalue->[$fvalue] = $self->_eval($ast->third());
368 1 return $vvalue->[$fvalue];
369 } else {
370 0 $ast->error("index accessor expects <= 2 arguments");
371 }
372 } elsif($ftype eq "function") {
373 66 my $scope = $f->{context};
374 66 my $fn = $fvalue;
375 66 my $fargs = $fn->second();
376 66 my @rargs = $ast->slice(1 .. $size-1);
377 66 my @rrargs = ();
378 66 foreach my $arg (@rargs) {
379 103 push @rrargs, $self->_eval($arg);
380 };
381 66 $self->push_scope($scope);
382 66 $self->push_caller($fn);
383 66 my $rest_args = undef;
384 66 my $i = 0;
385 66 my $fargsvalue = $fargs->value();
386 66 my $fargsn = scalar @{$fargsvalue};
387 66 my $rrargsn = scalar @rrargs;
388 66 ▶ for($i=0; $i < $fargsn; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $fargsn) 104 66 170
389 104 my $name = $fargsvalue->[$i]->value();
390 104 ▶ if($name eq "&"){
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq '&') { } 4 100 104
391 4 $i++;
392 4 $name = $fargsvalue->[$i]->value();
393 4 $rest_args = CljPerl::Seq->new("list");
394 4 $self->new_var($name, $rest_args);
395 } else {
396 100 ▶ $ast->error("real arguments < formal arguments") if $i >= $rrargsn;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $rrargsn 0 100 100
397 100 $self->new_var($name, $rrargs[$i]);
398 }
399 };
400 66 ▶ if(defined $rest_args){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rest_args) { } 4 62 66
401 4 $i -= 2;
402 4 ▶ for(; $i < $rrargsn; $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $rrargsn) 3 4 7
403 3 $rest_args->append($rrargs[$i]);
404 }
405 } else {
406 62 ▶ $ast->error("real arguments > formal arguments") if $i < $rrargsn;
Branch: 1 branch
BranchTrueFalseTotal
if $i < $rrargsn 0 62 62
407 };
408 66 my @body = $fn->slice(2 .. $fn->size()-1);
409 66 my $res;
410 66 foreach my $b (@body){
411 96 $res = $self->_eval($b);
412 };
413 65 $self->pop_scope();
414 65 $self->pop_caller();
415 65 return $res;
416 } elsif($ftype eq "perlfunction") {
417 0 my $meta = undef;
418 0 ▶ $meta = $self->_eval($ast->second()) if defined $ast->second() and $ast->second()->type() eq "meta";
Branch: 1 branch
BranchTrueFalseTotal
if defined $ast->second and $ast->second->type eq "meta" 0 0 0
Condition0%0/3
defined $ast->second and $ast->second->type eq "meta"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ast->second and $ast->second->type eq "meta"
defined $ast->second $ast->second->type eq "meta"
Truth table0%0/3
A and B
A= defined $ast->secondB= $ast->second->type eq "meta"
ABresult
0X0
100
111
419 0 my $perl_func = $f->value();
420 0 ▶ my @args = $ast->slice((defined $meta ? 2 : 1) .. $size-1);
Branch: 1 branch
BranchTrueFalseTotal
defined $meta ? : 0 0 0
421 0 return $self->perlfunc_call($perl_func, $meta, \@args);
422 } elsif($ftype eq "macro") {
423 42 my $scope = $f->{context};
424 42 my $fn = $fvalue;
425 42 my $fargs = $fn->third();
426 42 my @rargs = $ast->slice(1 .. $ast->size()-1);
427 42 $self->push_scope($scope);
428 42 $self->push_caller($fn);
429 42 my $rest_args = undef;
430 42 my $i = 0;
431 42 my $fargsvalue = $fargs->value();
432 42 my $fargsn = scalar @{$fargsvalue};
433 42 my $rargsn = scalar @rargs;
434 42 ▶ for($i=0; $i < $fargsn; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $fargsn) 115 42 157
435 115 my $name = $fargsvalue->[$i]->value();
436 115 ▶ if($name eq "&"){
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq '&') { } 40 75 115
437 40 $i++;
438 40 $name = $fargsvalue->[$i]->value();
439 40 $rest_args = CljPerl::Seq->new("list");
440 40 $self->new_var($name, $rest_args);
441 } else {
442 75 ▶ $ast->error("real arguments < formal arguments") if $i >= $rargsn;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $rargsn 0 75 75
443 75 $self->new_var($name, $rargs[$i]);
444 }
445 };
446 42 ▶ if(defined $rest_args){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rest_args) { } 40 2 42
447 40 $i -= 2;
448 40 ▶ for(; $i < $rargsn; $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $rargsn) 62 40 102
449 62 $rest_args->append($rargs[$i]);
450 }
451 } else {
452 2 ▶ $ast->error("real arguments > formal arguments") if $i < $rargsn;
Branch: 1 branch
BranchTrueFalseTotal
if $i < $rargsn 0 2 2
453 };
454 42 my @body = $fn->slice(3 .. $fn->size()-1);
455 42 my $res;
456 42 foreach my $b (@body){
457 42 $res = $self->_eval($b);
458 };
459 42 $self->pop_scope();
460 42 $self->pop_caller();
461 42 return $self->_eval($res);
462 } else {
463 0 $ast->error("expect a function or function name or index/key accessor");
464 };
465 } elsif($type eq "accessor") {
466 33 my $av = $self->_eval($value);
467 33 my $a = CljPerl::Atom->new("unknown", $av->value());
468 33 my $at = $av->type();
469 33 ▶ if($at eq "number") {
Branch: 2 branches
BranchTrueFalseTotal
if ($at eq 'number') { } 22 11 33
elsif ($at eq 'string' or $at eq 'keyword') { } 11 0 11
470 22 $a->type("index accessor");
471 ▶ } elsif($at eq "string" or $at eq "keyword") {
Condition66%2/3
$at eq "string" or $at eq "keyword"
l!l&&r!l&&!r
650
MC/DC0%0/2
$at eq "string" or $at eq "keyword"
$at eq "string" $at eq "keyword"
Truth table66%2/3
A or B
A= $at eq "string"B= $at eq "keyword"
ABresult
1X1
011
000
472 11 $a->type("key accessor");
473 } else {
474 0 $ast->error("unsupport type " . $at . " for accessor but got " . $at);
475 }
476 33 return $a;
477 } elsif($type eq "sender") {
478 1 my $sn = $self->_eval($value);
479 1 ▶ $ast->error("sender expects a string or keyword but got " . $type)
Branch: 1 branch
BranchTrueFalseTotal
if $sn->type ne "string" and $sn->type ne "keyword" 0 1 1
Condition33%1/3
$sn->type ne "string" and $sn->type ne "keyword"
!ll&&!rl&&r
100
MC/DC0%0/2
$sn->type ne "string" and $sn->type ne "keyword"
$sn->type ne "string" $sn->type ne "keyword"
Truth table33%1/3
A and B
A= $sn->type ne "string"B= $sn->type ne "keyword"
ABresult
0X0
100
111
480 if $sn->type() ne "string"
481 and $sn->type() ne "keyword";
482 1 my $s = CljPerl::Atom->new("symbol", $sn->value());
483 1 return $self->bind($s);
484 } elsif($type eq "symbol") {
485 858 return $self->bind($ast);
486 } elsif($type eq "syntaxquotation") {
487 49 return $self->bind($ast);
488 } elsif($type eq "quotation") {
489 39 return $self->bind($ast);
490 ▶ } elsif($class eq "Seq" and $type eq "vector") {
Condition100%3/3
$class eq "Seq" and $type eq "vector"
!ll&&!rl&&r
182255
MC/DC100%2/2
$class eq "Seq" and $type eq "vector"
$class eq "Seq" $type eq "vector"
Truth table100%3/3
A and B
A= $class eq "Seq"B= $type eq "vector"
ABresult
0X0
100
111
491 5 my $v = CljPerl::Atom->new("vector");
492 5 my @vv = ();
493 5 foreach my $i (@{$value}) {
494 14 push @vv, $self->_eval($i);
495 }
496 5 $v->value(\@vv);
497 5 return $v;
498 ▶ } elsif($class eq "Seq" and ($type eq "map" or $type eq "meta")) {
Condition100%6/6
$class eq "Seq" and $type eq "map" || $type eq "meta"
!ll&&!rl&&r
1821114
$type eq "map" or $type eq "meta"
l!l&&r!l&&!r
8611
MC/DC100%3/3
$class eq "Seq" and $type eq "map" || $type eq "meta"
$class eq "Seq" $type eq "map" $type eq "meta"
Truth table100%4/4
A and B or C
A= $class eq "Seq"B= $type eq "map"C= $type eq "meta"
ABCresult
0XX0
1000
11X1
1011
499 14 my $m = CljPerl::Atom->new("map");
500 14 my %mv = ();
501 14 my $n = scalar @{$value};
502 14 ▶ $ast->error($type . " should have even number of items") if ($n%2) != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n % 2 != 0 0 14 14
503 14 ▶ for(my $i=0; $i<$n; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 14 14 28
504 14 my $k = $self->_eval($value->[$i]);
505 14 ▶ $ast->error($type . " expects keyword or string as key but got " . $k->type())
Branch: 1 branch
BranchTrueFalseTotal
if $k->type ne "keyword" and $k->type ne "string" 0 14 14
Condition66%2/3
$k->type ne "keyword" and $k->type ne "string"
!ll&&!rl&&r
1220
MC/DC0%0/2
$k->type ne "keyword" and $k->type ne "string"
$k->type ne "keyword" $k->type ne "string"
Truth table66%2/3
A and B
A= $k->type ne "keyword"B= $k->type ne "string"
ABresult
0X0
100
111
506 if ($k->type() ne "keyword"
507 and $k->type() ne "string");
508 14 my $v = $self->_eval($value->[$i+1]);
509 14 $mv{$k->value()} = $v;
510 };
511 14 $m->value(\%mv);
512 14 ▶ $m->type("meta") if $type eq "meta";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "meta" 6 8 14
513 14 return $m;
514 ▶ } elsif($class eq "Seq" and $type eq "xml") {
Condition66%2/3
$class eq "Seq" and $type eq "xml"
!ll&&!rl&&r
182011
MC/DC50%1/2
$class eq "Seq" and $type eq "xml"
$class eq "Seq" $type eq "xml"
Truth table66%2/3
A and B
A= $class eq "Seq"B= $type eq "xml"
ABresult
0X0
100
111
515 11 my $size = $ast->size();
516 11 ▶ $ast->error("xml expects >= 1 arguments") if $size == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 0 11 11
517 11 my $first = $ast->first();
518 11 my $firsttype = $first->type();
519 11 ▶ if($firsttype ne "symbol") {
Branch: 1 branch
BranchTrueFalseTotal
if ($firsttype ne "symbol") 2 9 11
520 2 $first = $self->_eval($first);
521 2 $firsttype = $first->type();
522 };
523 11 ▶ $ast->error("xml expects a symbol or string or keyword as name but got " . $firsttype)
Branch: 1 branch
BranchTrueFalseTotal
if $firsttype ne "symbol" and $firsttype ne "string" and $firsttype ne "keyword" 0 11 11
Condition50%3/6
$firsttype ne "symbol" and $firsttype ne "string" and $firsttype ne "keyword"
!ll&&!rl&&r
1100
$firsttype ne "symbol" and $firsttype ne "string"
!ll&&!rl&&r
920
MC/DC0%0/3
$firsttype ne "symbol" and $firsttype ne "string" and $firsttype ne "keyword"
$firsttype ne "symbol" $firsttype ne "string" $firsttype ne "keyword"
Truth table50%2/4
A and B and C
A= $firsttype ne "symbol"B= $firsttype ne "string"C= $firsttype ne "keyword"
ABCresult
0XX0
10X0
1100
1111
524 if $firsttype ne "symbol"
525 and $firsttype ne "string"
526 and $firsttype ne "keyword";
527 11 my @items = ();
528 11 my $xml = CljPerl::Atom->new("xml", \@items);
529 11 $xml->{name} = $first->value();
530 11 my @rest = $ast->slice(1 .. $size-1);
531 11 foreach my $i (@rest) {
532 14 my $iv = $self->_eval($i);
533 14 my $it = $iv->type();
534 14 ▶ $ast->error("xml expects string or xml or meta or list as items but got " . $it)
Branch: 1 branch
BranchTrueFalseTotal
if $it ne "string" and $it ne "xml" and $it ne "meta" and $it ne "list" 0 14 14
Condition88%8/9
$it ne "string" and $it ne "xml" and $it ne "meta" and $it ne "list"
!ll&&!rl&&r
1220
$it ne "string" and $it ne "xml" and $it ne "meta"
!ll&&!rl&&r
932
$it ne "string" and $it ne "xml"
!ll&&!rl&&r
635
MC/DC0%0/4
$it ne "string" and $it ne "xml" and $it ne "meta" and $it ne "list"
$it ne "string" $it ne "xml" $it ne "meta" $it ne "list"
Truth table80%4/5
A and B and C and D
A= $it ne "string"B= $it ne "xml"C= $it ne "meta"D= $it ne "list"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
535 if $it ne "string"
536 and $it ne "xml"
537 and $it ne "meta"
538 and $it ne "list";
539 14 ▶ if($it eq "meta") {
Branch: 2 branches
BranchTrueFalseTotal
if ($it eq 'meta') { } 3 11 14
elsif ($it eq 'list') { } 2 9 11
540 3 $xml->meta($iv);
541 } elsif($it eq "list") {
542 2 foreach my $i (@{$iv->value()}) {
543 4 push @items, $i;
544 };
545 } else {;
546 9 push @items, $iv;
547 };
548 };
549 11 return $xml;
550 };
551 182 return $ast;
552 }
553
554 503 ▶ sub builtin {
Subroutine builtin: called CC=252 SCAR=73.3
Pod undocumented
555 503 my $self = shift;
556 503 my $f = shift;
557 503 my $ast = shift;
558 503 my $size = $ast->size();
559 #my $f = $ast->first();
560 503 my $fn = $f->value();
561
562 # (eval "bla bla bla")
563 503 ▶ if($fn eq "eval") {
Branch: 54 branches
BranchTrueFalseTotal
if ($fn eq 'eval') { } 1 502 503
elsif ($fn eq 'syntax') { } 5 497 502
elsif ($fn eq 'throw') { } 2 495 497
elsif ($fn eq 'exception-label') { } 1 494 495
elsif ($fn eq 'exception-message') { } 1 493 494
elsif ($fn eq 'catch') { } 2 491 493
elsif ($fn eq 'def') { } 60 431 491
elsif ($fn eq 'set!') { } 33 398 431
elsif ($fn eq 'let') { } 9 389 398
elsif ($fn eq 'fn') { } 58 331 389
elsif ($fn eq 'defmacro') { } 21 310 331
elsif ($fn eq 'gen-sym') { } 2 308 310
elsif ($fn eq 'require') { } 3 305 308
elsif ($fn eq 'read') { } 0 305 305
elsif ($fn eq 'list') { } 9 296 305
elsif ($fn eq 'car') { } 1 295 296
elsif ($fn eq 'cdr') { } 1 294 295
elsif ($fn eq 'cons') { } 6 288 294
elsif ($fn eq 'if') { } 19 269 288
elsif ($fn eq 'while') { } 6 263 269
elsif ($fn eq 'begin') { } 3 260 263
elsif ($fn =~ m[^(\+|\-|\*|/|\%)$]) { } 25 235 260
elsif ($fn =~ /^(==|>|<|>=|<=|!=)$/) { } 25 210 235
elsif ($fn eq 'xml-name') { } 3 207 210
elsif ($fn =~ /^(eq|ne)$/) { } 6 201 207
elsif ($fn eq 'equal') { } 11 190 201
elsif ($fn eq '!' or $fn eq 'not') { } 1 189 190
elsif ($fn eq 'and') { } 2 187 189
elsif ($fn eq 'or') { } 2 185 187
elsif ($fn eq 'length') { } 12 173 185
elsif ($fn eq 'reverse') { } 1 172 173
elsif ($fn eq 'append') { } 11 161 172
elsif ($fn eq 'keys') { } 1 160 161
elsif ($fn eq 'namespace-begin') { } 4 156 160
elsif ($fn eq 'namespace-end') { } 4 152 156
elsif ($fn eq 'object-id') { } 1 151 152
elsif ($fn eq 'type') { } 7 144 151
elsif ($fn eq 'perlobj-type') { } 0 144 144
elsif ($fn eq 'apply') { } 3 141 144
elsif ($fn eq 'meta') { } 13 128 141
elsif ($fn eq 'clj->string') { } 1 127 128
elsif ($fn =~ /^(\.|->)(\S*)$/) { } 14 113 127
elsif ($fn eq 'perl->clj') { } 6 107 113
elsif ($fn eq 'println') { } 100 7 107
elsif ($fn eq 'coro') { } 1 6 7
elsif ($fn eq 'coro-suspend') { } 0 6 6
elsif ($fn eq 'coro-sleep') { } 1 5 6
elsif ($fn eq 'coro-yield') { } 0 5 5
elsif ($fn eq 'coro-resume') { } 2 3 5
elsif ($fn eq 'coro-wake') { } 0 3 3
elsif ($fn eq 'join-coro') { } 0 3 3
elsif ($fn eq 'coro-current') { } 2 1 3
elsif ($fn eq 'coro-main') { } 1 0 1
elsif ($fn eq 'trace-vars') { } 0 0 0
564 1 ▶ $ast->error("eval expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
565 1 my $s = $ast->second();
566 1 ▶ $ast->error("eval expects 1 string as argument but got " . $s->type()) if $s->type() ne "string";
Branch: 1 branch
BranchTrueFalseTotal
if $s->type ne "string" 0 1 1
567 1 return $self->eval($s->value());
568 } elsif($fn eq "syntax") {
569 5 ▶ $ast->error("syntax expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 5 5
570 5 return $self->bind($ast->second());
571 } elsif($fn eq "throw") {
572 2 ▶ $ast->error("throw expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 2 2
573 2 my $label = $ast->second();
574 2 ▶ $ast->error("throw expects a symbol as the first argument but got " . $label->type()) if $label->type() ne "symbol";
Branch: 1 branch
BranchTrueFalseTotal
if $label->type ne "symbol" 0 2 2
575 2 my $msg = $self->_eval($ast->third());
576 2 ▶ $ast->error("throw expects a string as the second argument but got " . $msg->type()) if $msg->type() ne "string";
Branch: 1 branch
BranchTrueFalseTotal
if $msg->type ne "string" 0 2 2
577 2 my $e = CljPerl::Atom->new("exception", $msg->value());
578 2 $e->{label} = $label->value();
579 2 my @caller = @{$self->{caller}};
580 2 $e->{caller} = \@caller;
581 2 $self->{exception} = $e;
582 2 die $msg->value();
583 } elsif($fn eq "exception-label") {
584 1 ▶ $ast->error("exception-label expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
585 1 my $e = $self->_eval($ast->second());
586 1 ▶ $ast->error("exception-label expects an exception as argument but got " . $e->type()) if $e->type() ne "exception";
Branch: 1 branch
BranchTrueFalseTotal
if $e->type ne "exception" 0 1 1
587 1 return CljPerl::Atom->new("string", $e->{label});
588 } elsif($fn eq "exception-message") {
589 1 ▶ $ast->error("exception-message expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
590 1 my $e = $self->_eval($ast->second());
591 1 ▶ $ast->error("exception-message expects an exception as argument but got " . $e->type()) if $e->type() ne "exception";
Branch: 1 branch
BranchTrueFalseTotal
if $e->type ne "exception" 0 1 1
592 1 return CljPerl::Atom->new("string", $e->value());
593 } elsif($fn eq "catch") {
594 2 ▶ $ast->error("catch expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 2 2
595 2 my $handler = $self->_eval($ast->third());
596 2 ▶ $ast->error("catch expects a function/lambda as the second argument but got " . $handler->type()) if $handler->type() ne "function";
Branch: 1 branch
BranchTrueFalseTotal
if $handler->type ne "function" 0 2 2
597 2 my $res;
598 2 my $saved_caller_depth = $self->caller_size();
599 2 eval {
600 2 $res = $self->_eval($ast->second());
601 };
602 2 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 0 2
603 2 my $e = $self->{exception};
604 2 ▶ if(!defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $e) 0 2 2
605 0 $e = CljPerl::Atom->new("exception", "unkown expection");
606 0 $e->{label} = "undef";
607 0 my @ec = ();
608 0 $e->{caller} = \@ec;
609 };
610 2 ▶ $ast->error("catch expects an exception for handler but got " . $e->type()) if $e->type() ne "exception";
Branch: 1 branch
BranchTrueFalseTotal
if $e->type ne "exception" 0 2 2
611 2 my $i = $self->caller_size();
612 2 ▶ for(;$i > $saved_caller_depth; $i--){
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $saved_caller_depth) 1 2 3
613 1 $self->pop_caller();
614 };
615 2 my $call_handler = CljPerl::Seq->new("list");
616 2 $call_handler->append($handler);
617 2 $call_handler->append($e);
618 2 $self->{exception} = undef;
619 2 return $self->_eval($call_handler);
620 };
621 0 return $res;
622 # (def ^{} name value)
623 } elsif($fn eq "def") {
624 60 ▶ $ast->error($fn . " expects 2 arguments") if $size > 4 or $size < 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size > 4 or $size < 3 0 60 60
Condition33%1/3
$size > 4 or $size < 3
l!l&&r!l&&!r
0060
MC/DC0%0/2
$size > 4 or $size < 3
$size > 4 $size < 3
Truth table33%1/3
A or B
A= $size > 4B= $size < 3
ABresult
1X1
011
000
625 60 ▶ if($size == 3){
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 3) { } 58 2 60
626 58 ▶ $ast->error($fn . " expects a symbol as the first argument but got " . $ast->second()->type()) if $ast->second()->type() ne "symbol";
Branch: 1 branch
BranchTrueFalseTotal
if $ast->second->type ne "symbol" 0 58 58
627 58 my $name = $ast->second()->value();
628 58 ▶ $ast->error($name . " is a reserved word") if exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/;
Branch: 1 branch
BranchTrueFalseTotal
if exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/ 0 58 58
Condition33%1/3
exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/
l!l&&r!l&&!r
0058
MC/DC0%0/2
exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/
exists $builtin_funcs->{$name} $name =~ /^(\.|->)\S+$/
Truth table33%1/3
A or B
A= exists $builtin_funcs->{$name}B= $name =~ /^(\.|->)\S+$/
ABresult
1X1
011
000
629 58 $self->new_var($name);
630 58 my $value = $self->_eval($ast->third());
631 58 $self->var($name)->value($value);
632 58 return $value;
633 } else {
634 2 my $meta = $self->_eval($ast->second());
635 2 ▶ $ast->error($fn . " expects a meta as the first argument but got " . $meta->type()) if $meta->type() ne "meta";
Branch: 1 branch
BranchTrueFalseTotal
if $meta->type ne "meta" 0 2 2
636 2 ▶ $ast->error($fn . " expects a symbol as the first argument but got " . $ast->third()->type()) if $ast->third()->type() ne "symbol";
Branch: 1 branch
BranchTrueFalseTotal
if $ast->third->type ne "symbol" 0 2 2
637 2 my $name = $ast->third()->value();
638 2 ▶ $ast->error($name . " is a reserved word") if exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/;
Branch: 1 branch
BranchTrueFalseTotal
if exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/ 0 2 2
Condition33%1/3
exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/
l!l&&r!l&&!r
002
MC/DC0%0/2
exists $builtin_funcs->{$name} or $name =~ /^(\.|->)\S+$/
exists $builtin_funcs->{$name} $name =~ /^(\.|->)\S+$/
Truth table33%1/3
A or B
A= exists $builtin_funcs->{$name}B= $name =~ /^(\.|->)\S+$/
ABresult
1X1
011
000
639 2 $self->new_var($name);
640 2 my $value = $self->_eval($ast->fourth());
641 2 $value->meta($meta);
642 2 $self->var($name)->value($value);
643 2 return $value;
644 }
645 # (set! name value)
646 } elsif($fn eq "set!") {
647 33 ▶ $ast->error($fn . " expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 33 33
648 33 ▶ $ast->error($fn . " expects a symbol as the first argument but got " . $ast->second()->type()) if $ast->second()->type() ne "symbol";
Branch: 1 branch
BranchTrueFalseTotal
if $ast->second->type ne "symbol" 0 33 33
649 33 my $name = $ast->second()->value();
650 33 ▶ $ast->error("undefine variable " . $name) if !defined $self->var($name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->var($name) 0 33 33
651 33 my $value = $self->_eval($ast->third());
652 33 $self->var($name)->value($value);
653 33 return $value;
654 } elsif($fn eq "let") {
655 9 ▶ $ast->error($fn . " expects >=3 arguments") if $size < 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 3 0 9 9
656 9 my $vars = $ast->second();
657 9 ▶ $ast->error($fn . " expects a list [name value ...] as the first argument") if $vars->type() ne "vector";
Branch: 1 branch
BranchTrueFalseTotal
if $vars->type ne "vector" 0 9 9
658 9 my $varssize = $vars->size();
659 9 ▶ $ast->error($fn . " expects [name value ...] pairs as the first argument") if $varssize%2 != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $varssize % 2 != 0 0 9 9
660 9 my $varvs = $vars->value();
661 9 $self->push_scope($self->current_scope());
662 9 $self->push_caller($ast);
663 9 ▶ for(my $i=0; $i < $varssize; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $varssize) 14 9 23
664 14 my $n = $varvs->[$i];
665 14 my $v = $varvs->[$i+1];
666 14 ▶ $ast->error($fn . " expects a symbol as name but got " . $n->type()) if $n->type() ne "symbol";
Branch: 1 branch
BranchTrueFalseTotal
if $n->type ne "symbol" 0 14 14
667 14 $self->new_var($n->value(), $self->_eval($v));
668 };
669 9 my @body = $ast->slice(2 .. $size-1);
670 9 my $res = $nil;
671 9 foreach my $b (@body){
672 10 $res = $self->_eval($b);
673 };
674 9 $self->pop_scope();
675 9 $self->pop_caller();
676 9 return $res;
677 # (fn [args ...] body)
678 } elsif($fn eq "fn") {
679 58 ▶ $ast->error("fn expects >= 3 arguments") if $size < 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 3 0 58 58
680 58 my $args = $ast->second();
681 58 my $argstype = $args->type();
682 58 ▶ $ast->error("fn expects [arg ...] as formal argument list") if $argstype ne "vector";
Branch: 1 branch
BranchTrueFalseTotal
if $argstype ne "vector" 0 58 58
683 58 my $argsvalue = $args->value();
684 58 my $argssize = $args->size();
685 58 my $i = 0;
686 58 foreach my $arg (@{$argsvalue}) {
687 85 ▶ $arg->error("formal argument should be a symbol but got " . $arg->type()) if $arg->type() ne "symbol";
Branch: 1 branch
BranchTrueFalseTotal
if $arg->type ne "symbol" 0 85 85
688 85 ▶ if($arg->value() eq "&"
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->value eq "&" and $argssize != $i + 2 || $$argsvalue[$i + 1]->value eq "&") 0 85 85
Condition50%3/6
$arg->value eq "&" and $argssize != $i + 2 || $$argsvalue[$i + 1]->value eq "&"
!ll&&!rl&&r
7960
$argssize != $i + 2 or $$argsvalue[$i + 1]->value eq "&"
l!l&&r!l&&!r
006
MC/DC0%0/3
$arg->value eq "&" and $argssize != $i + 2 || $$argsvalue[$i + 1]->value eq "&"
$arg->value eq "&" $argssize != $i + 2 $$argsvalue[$i + 1]->value eq "&"
Truth table50%2/4
A and B or C
A= $arg->value eq "&"B= $argssize != $i + 2C= $$argsvalue[$i + 1]->value eq "&"
ABCresult
0XX0
1000
11X1
1011
689 and ($argssize != $i + 2 or $argsvalue->[$i+1]->value() eq "&")) {
690 0 $arg->error("only 1 non-& should follow &");
691 };
692 85 $i ++;
693 }
694 58 my $nast = CljPerl::Atom->new("function", $ast);
695 58 my %c = %{$self->current_scope()};
696 58 my @ns = @{$c{$namespace_key}};
697 58 $c{$namespace_key} = \@ns;
698 58 $nast->{context} = \%c;
699 58 return $nast;
700 # (defmacro name [args ...] body)
701 } elsif($fn eq "defmacro") {
702 21 ▶ $ast->error("defmacro expects >= 4 arguments") if $size < 4;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 4 0 21 21
703 21 my $name = $ast->second()->value();
704 21 my $args = $ast->third();
705 21 ▶ $ast->error("defmacro expect [arg ...] as formal argument list") if $args->type() ne "vector";
Branch: 1 branch
BranchTrueFalseTotal
if $args->type ne "vector" 0 21 21
706 21 my $i = 0;
707 21 foreach my $arg (@{$args->value()}) {
708 61 ▶ $arg->error("formal argument should be a symbol but got " . $arg->type()) if $arg->type() ne "symbol";
Branch: 1 branch
BranchTrueFalseTotal
if $arg->type ne "symbol" 0 61 61
709 61 ▶ if($arg->value() eq "&"
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->value eq "&" and $args->size != $i + 2 || $args->value->[$i + 1]->value eq "&") 0 61 61
Condition50%3/6
$arg->value eq "&" and $args->size != $i + 2 || $args->value->[$i + 1]->value eq "&"
!ll&&!rl&&r
44170
$args->size != $i + 2 or $args->value->[$i + 1]->value eq "&"
l!l&&r!l&&!r
0017
MC/DC0%0/3
$arg->value eq "&" and $args->size != $i + 2 || $args->value->[$i + 1]->value eq "&"
$arg->value eq "&" $args->size != $i + 2 $args->value->[$i + 1]->value eq "&"
Truth table50%2/4
A and B or C
A= $arg->value eq "&"B= $args->size != $i + 2C= $args->value->[$i + 1]->value eq "&"
ABCresult
0XX0
1000
11X1
1011
710 and ($args->size() != $i + 2 or $args->value()->[$i+1]->value() eq "&")) {
711 0 $arg->error("only 1 non-& should follow &");
712 };
713 61 $i ++;
714 }
715 21 my $nast = CljPerl::Atom->new("macro", $ast);
716 21 my %c = %{$self->current_scope()};
717 21 my @ns = @{$c{$namespace_key}};
718 21 $c{$namespace_key} = \@ns;
719 21 $nast->{context} = \%c;
720 21 $self->new_var($name, $nast);
721 21 return $nast;
722 # (gen-sym)
723 } elsif($fn eq "gen-sym") {
724 2 ▶ $ast->error("gen-sym expects 0/1 argument") if $size > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size > 2 0 2 2
725 2 my $s = CljPerl::Atom->new("symbol");
726 2 ▶ if($size == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 2) { } 1 1 2
727 1 my $pre = $self->_eval($ast->second());
728 1 ▶ $ast->("gen-sym expects string as argument") if $pre->type ne "string";
Branch: 1 branch
BranchTrueFalseTotal
if $pre->type ne "string" 0 1 1
729 1 $s->value($pre->value() . $s->object_id());
730 } else {
731 1 $s->value($s->object_id());
732 };
733 2 return $s;
734 # (require "filename")
735 } elsif($fn eq "require") {
736 3 ▶ $ast->error("require expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 3 3
737 3 my $m = $ast->second();
738 3 ▶ if($m->type() eq "symbol" or $m->type() eq "keyword") {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->type eq 'symbol' or $m->type eq 'keyword') { } 1 2 3
Condition66%2/3
$m->type eq "symbol" or $m->type eq "keyword"
l!l&&r!l&&!r
102
MC/DC50%1/2
$m->type eq "symbol" or $m->type eq "keyword"
$m->type eq "symbol" $m->type eq "keyword"
Truth table66%2/3
A or B
A= $m->type eq "symbol"B= $m->type eq "keyword"
ABresult
1X1
011
000
739 } else {
740 2 $m = $self->_eval($m);
741 2 ▶ $ast->error("require expects a string but got " . $m->type())
Branch: 1 branch
BranchTrueFalseTotal
if $m->type ne "string" 0 2 2
742 if $m->type() ne "string";
743 };
744 3 return $self->load($m->value());
745 } elsif($fn eq "read") {
746 0 ▶ $ast->error("read expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 0 0
747 0 my $f = $self->_eval($ast->second());
748 0 ▶ $ast->error("read expects a string but got " . $f->type())
Branch: 1 branch
BranchTrueFalseTotal
if $f->type ne "string" 0 0 0
749 if $f->type() ne "string";
750 0 return $self->read($f->value());
751 # (list 'a 'b 'c)
752 } elsif($fn eq "list") {
753 9 ▶ return $emtpy_list if $size == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size == 1 0 9 9
754 9 my @vs = $ast->slice(1 .. $size-1);
755 9 my $r = CljPerl::Seq->new("list");
756 9 foreach my $i (@vs) {
757 11 $r->append($self->_eval($i));
758 };
759 9 return $r;
760 # (car list)
761 } elsif($fn eq "car") {
762 1 ▶ $ast->error("car expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
763 1 my $v = $self->_eval($ast->second());
764 1 ▶ $ast->error("car expects 1 list as argument but got " . $v->type()) if $v->type() ne "list";
Branch: 1 branch
BranchTrueFalseTotal
if $v->type ne "list" 0 1 1
765 1 my $fv = $v->first();
766 1 return $fv;
767 # (cdr list)
768 } elsif($fn eq "cdr") {
769 1 ▶ $ast->error("cdr expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
770 1 my $v = $self->_eval($ast->second());
771 1 ▶ $ast->error("cdr expects 1 list as argument but got " . $v->type()) if $v->type() ne "list";
Branch: 1 branch
BranchTrueFalseTotal
if $v->type ne "list" 0 1 1
772 1 ▶ return $empty_list if($v->size()==0);
Branch: 1 branch
BranchTrueFalseTotal
if $v->size == 0 0 1 1
773 1 my @vs = $v->slice(1 .. $v->size()-1);
774 1 my $r = CljPerl::Seq->new("list");
775 1 $r->value(\@vs);
776 1 return $r;
777 # (cons item list)
778 } elsif($fn eq "cons") {
779 6 ▶ $ast->error("cons expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 6 6
780 6 my $fv = $self->_eval($ast->second());
781 6 my $rvs = $self->_eval($ast->third());
782 6 ▶ $ast->error("cons expects 1 list as the second argument but got " . $rvs->type()) if $rvs->type() ne "list";
Branch: 1 branch
BranchTrueFalseTotal
if $rvs->type ne "list" 0 6 6
783 6 my @vs = ();
784 6 ▶ @vs = $rvs->slice(0 .. $rvs->size()-1) if $rvs->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rvs->size > 0 3 3 6
785 6 unshift @vs, $fv;
786 6 my $r = CljPerl::Seq->new("list");
787 6 $r->value(\@vs);
788 6 return $r;
789 # (if cond true_clause false_clause)
790 } elsif($fn eq "if") {
791 19 ▶ $ast->error("if expects 2 or 3 arguments") if $size > 4 or $size < 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size > 4 or $size < 3 0 19 19
Condition33%1/3
$size > 4 or $size < 3
l!l&&r!l&&!r
0019
MC/DC0%0/2
$size > 4 or $size < 3
$size > 4 $size < 3
Truth table33%1/3
A or B
A= $size > 4B= $size < 3
ABresult
1X1
011
000
792 19 my $cond = $self->_eval($ast->second());
793 19 ▶ $ast->error("if expects a bool as the first argument but got " . $cond->type()) if $cond->type() ne "bool";
Branch: 1 branch
BranchTrueFalseTotal
if $cond->type ne "bool" 0 19 19
794 19 ▶ if($cond->value() eq "true") {
Branch: 2 branches
BranchTrueFalseTotal
if ($cond->value eq 'true') { } 10 9 19
elsif ($ast->size == 4) { } 5 4 9
795 10 return $self->_eval($ast->third());
796 } elsif($ast->size() == 4) {
797 5 return $self->_eval($ast->fourth());
798 } else {
799 4 return $nil;
800 };
801 # (while cond body)
802 } elsif($fn eq "while") {
803 6 ▶ $ast->error("while expects >= 2 arguments") if $size < 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 3 0 6 6
804 6 my $cond = $self->_eval($ast->second());
805 6 ▶ $ast->error("while expects a bool as the first argument but got " . $cond->type()) if $cond->type() ne "bool";
Branch: 1 branch
BranchTrueFalseTotal
if $cond->type ne "bool" 0 6 6
806 6 my $res = $nil;
807 6 my @body = $ast->slice(2 .. $size-1);
808 6 ▶ while ($cond->value() eq "true") {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond->value eq "true") 17 6 23
809 17 foreach my $i (@body) {
810 39 $res = $self->_eval($i);
811 }
812 17 $cond = $self->_eval($ast->second());
813 }
814 6 return $res;
815 # (begin body)
816 } elsif($fn eq "begin") {
817 3 ▶ $ast->error("being expects >= 1 arguments") if $size < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 2 0 3 3
818 3 my $res = $nil;
819 3 my @body = $ast->slice(1 .. $size-1);
820 3 foreach my $i (@body) {
821 15 $res = $self->_eval($i);
822 }
823 3 return $res;
824 # + - & / % operations
825 } elsif($fn =~ /^(\+|\-|\*|\/|\%)$/) {
826 25 ▶ $ast->error($fn . " expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 25 25
827 25 my $v1 = $self->_eval($ast->second());
828 25 my $v2 = $self->_eval($ast->third());
829 25 ▶ $ast->error($fn . " expects number as arguments but got " . $v1->type() . " and " . $v2->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v1->type ne "number" or $v2->type ne "number" 0 25 25
Condition33%1/3
$v1->type ne "number" or $v2->type ne "number"
l!l&&r!l&&!r
0025
MC/DC0%0/2
$v1->type ne "number" or $v2->type ne "number"
$v1->type ne "number" $v2->type ne "number"
Truth table33%1/3
A or B
A= $v1->type ne "number"B= $v2->type ne "number"
ABresult
1X1
011
000
830 if $v1->type() ne "number" or $v2->type() ne "number";
831 25 my $vv1 = $v1->value();
832 25 my $vv2 = $v2->value();
833 25 my $r = CljPerl::Atom->new("number", eval("$vv1 $fn $vv2"));
834 25 return $r;
835 # == > < >= <= != logic operations
836 } elsif($fn =~ /^(==|>|<|>=|<=|!=)$/) {
837 25 ▶ $ast->error($fn . " expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 25 25
838 25 my $v1 = $self->_eval($ast->second());
839 25 my $v2 = $self->_eval($ast->third());
840 25 ▶ $ast->error($fn . " expects number as arguments but got " . $v1->type() . " and " . $v2->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v1->type ne "number" or $v2->type ne "number" 0 25 25
Condition33%1/3
$v1->type ne "number" or $v2->type ne "number"
l!l&&r!l&&!r
0025
MC/DC0%0/2
$v1->type ne "number" or $v2->type ne "number"
$v1->type ne "number" $v2->type ne "number"
Truth table33%1/3
A or B
A= $v1->type ne "number"B= $v2->type ne "number"
ABresult
1X1
011
000
841 if $v1->type() ne "number" or $v2->type() ne "number";
842 25 my $vv1 = $v1->value();
843 25 my $vv2 = $v2->value();
844 25 my $r = eval("$vv1 $fn $vv2");
845 25 ▶ if($r){
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 15 10 25
846 15 return $true;
847 } else {
848 10 return $false;
849 }
850 } elsif($fn eq "xml-name") {
851 3 ▶ $ast->error($fn . " expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 3 3
852 3 my $v = $self->_eval($ast->second());
853 3 ▶ $ast->error($fn . " expects xml as argument but got " . $v->type()) if $v->type() ne "xml";
Branch: 1 branch
BranchTrueFalseTotal
if $v->type ne "xml" 0 3 3
854 3 return CljPerl::Atom->new("string", $v->{name});
855 # eq ne for string comparing
856 } elsif($fn =~ /^(eq|ne)$/) {
857 6 ▶ $ast->error($fn . " expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 6 6
858 6 my $v1 = $self->_eval($ast->second());
859 6 my $v2 = $self->_eval($ast->third());
860 6 ▶ $ast->error($fn . " expects string as arguments but got " . $v1->type() . " and " . $v2->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v1->type ne "string" or $v2->type ne "string" 0 6 6
Condition33%1/3
$v1->type ne "string" or $v2->type ne "string"
l!l&&r!l&&!r
006
MC/DC0%0/2
$v1->type ne "string" or $v2->type ne "string"
$v1->type ne "string" $v2->type ne "string"
Truth table33%1/3
A or B
A= $v1->type ne "string"B= $v2->type ne "string"
ABresult
1X1
011
000
861 if $v1->type() ne "string" or $v2->type() ne "string";
862 6 my $vv1 = $v1->value();
863 6 my $vv2 = $v2->value();
864 6 my $r = eval("'$vv1' $fn '$vv2'");
865 6 ▶ if($r){
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 3 3 6
866 3 return $true;
867 } else {
868 3 return $false;
869 }
870 # (equal a b)
871 } elsif($fn eq "equal") {
872 11 ▶ $ast->error($fn . " expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 11 11
873 11 my $v1 = $self->_eval($ast->second());
874 11 my $v2 = $self->_eval($ast->third());
875 11 my $r = 0;
876 11 ▶ if($v1->type() ne $v2->type()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($v1->type ne $v2->type) { } 1 10 11
elsif ($v1->type eq 'string' or $v1->type eq 'keyword' or $v1->type eq 'quotation' or $v1->type eq 'bool' or $v1->type eq 'nil') { } 7 3 10
elsif ($v1->type eq 'number') { } 0 3 3
877 1 $r = 0;
878 ▶ } elsif($v1->type() eq "string"
Condition83%10/12
$v1->type eq "string" or $v1->type eq "keyword" or $v1->type eq "quotation" or $v1->type eq "bool" or $v1->type eq "nil"
l!l&&r!l&&!r
703
$v1->type eq "string" or $v1->type eq "keyword" or $v1->type eq "quotation" or $v1->type eq "bool"
l!l&&r!l&&!r
703
$v1->type eq "string" or $v1->type eq "keyword" or $v1->type eq "quotation"
l!l&&r!l&&!r
523
$v1->type eq "string" or $v1->type eq "keyword"
l!l&&r!l&&!r
325
MC/DC60%3/5
$v1->type eq "string" or $v1->type eq "keyword" or $v1->type eq "quotation" or $v1->type eq "bool" or $v1->type eq "nil"
$v1->type eq "string" $v1->type eq "keyword" $v1->type eq "quotation" $v1->type eq "bool" $v1->type eq "nil"
Truth table66%4/6
A or B or C or D or E
A= $v1->type eq "string"B= $v1->type eq "keyword"C= $v1->type eq "quotation"D= $v1->type eq "bool"E= $v1->type eq "nil"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
879 or $v1->type() eq "keyword"
880 or $v1->type() eq "quotation"
881 or $v1->type() eq "bool"
882 or $v1->type() eq "nil"){
883 7 $r = $v1->value() eq $v2->value();
884 } elsif($v1->type() eq "number"){
885 0 $r = $v1->value() == $v2->value();
886 } else {
887 3 $r = $v1->value() eq $v2->value();
888 };
889 11 ▶ if($r){
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 7 4 11
890 7 return $true;
891 } else {
892 4 return $false;
893 };
894 # (! true_or_false)
895 ▶ } elsif($fn eq "!" or $fn eq "not") {
Condition66%2/3
$fn eq "!" or $fn eq "not"
l!l&&r!l&&!r
10189
MC/DC50%1/2
$fn eq "!" or $fn eq "not"
$fn eq "!" $fn eq "not"
Truth table66%2/3
A or B
A= $fn eq "!"B= $fn eq "not"
ABresult
1X1
011
000
896 1 ▶ $ast->error("!/not expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
897 1 my $v = $self->_eval($ast->second());
898 1 ▶ $ast->error("!/not expects a bool as the first argument but got " . $v->type()) if $v->type() ne "bool";
Branch: 1 branch
BranchTrueFalseTotal
if $v->type ne "bool" 0 1 1
899 1 ▶ if($v->value() eq "true") {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->value eq 'true') { } 0 1 1
900 0 return $false;
901 } else {
902 1 return $true;
903 };
904 # (and/or true_or_false true_or_false)
905 } elsif($fn eq "and") {
906 2 ▶ $ast->error($fn . " expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 2 2
907 2 my $v1 = $self->_eval($ast->second());
908 2 ▶ $ast->error($fn . " expects bool as arguments but got " . $v1->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v1->type ne "bool" 0 2 2
909 if $v1->type() ne "bool";
910 2 ▶ return $false if $v1->value() eq "false";
Branch: 1 branch
BranchTrueFalseTotal
if $v1->value eq "false" 0 2 2
911 2 my $v2 = $self->_eval($ast->third());
912 2 ▶ $ast->error($fn . " expects bool as arguments but got " . $v2->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v2->type ne "bool" 0 2 2
913 if $v2->type() ne "bool";
914 2 ▶ if($v2->value() eq "true") {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2->value eq 'true') { } 1 1 2
915 1 return $true;
916 } else {
917 1 return $false;
918 };
919 } elsif($fn eq "or") {
920 2 ▶ $ast->error($fn . " expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 2 2
921 2 my $v1 = $self->_eval($ast->second());
922 2 ▶ $ast->error($fn . " expects bool as arguments but got " . $v1->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v1->type ne "bool" 0 2 2
923 if $v1->type() ne "bool";
924 2 ▶ return $true if $v1->value() eq "true";
Branch: 1 branch
BranchTrueFalseTotal
if $v1->value eq "true" 1 1 2
925 1 my $v2 = $self->_eval($ast->third());
926 1 ▶ $ast->error($fn . " expects bool as arguments but got " . $v2->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v2->type ne "bool" 0 1 1
927 if $v2->type() ne "bool";
928 1 ▶ if($v2->value() eq "true") {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2->value eq 'true') { } 0 1 1
929 0 return $true;
930 } else {
931 1 return $false;
932 };
933 # (length list_or_vector_or_xml_or_map_or_string)
934 } elsif($fn eq "length") {
935 12 ▶ $ast->error("length expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 12 12
936 12 my $v = $self->_eval($ast->second());
937 12 my $r = CljPerl::Atom->new("number", 0);
938 12 ▶ if($v->type() eq "string"){
Branch: 3 branches
BranchTrueFalseTotal
if ($v->type eq 'string') { } 1 11 12
elsif ($v->type eq 'list' or $v->type eq 'vector' or $v->type eq 'xml') { } 10 1 11
elsif ($v->type eq 'map') { } 1 0 1
939 1 $r->value(length($v->value()));
940 ▶ } elsif($v->type() eq "list" or $v->type() eq "vector" or $v->type() eq "xml"){
Condition100%6/6
$v->type eq "list" or $v->type eq "vector" or $v->type eq "xml"
l!l&&r!l&&!r
821
$v->type eq "list" or $v->type eq "vector"
l!l&&r!l&&!r
443
MC/DC100%3/3
$v->type eq "list" or $v->type eq "vector" or $v->type eq "xml"
$v->type eq "list" $v->type eq "vector" $v->type eq "xml"
Truth table100%4/4
A or B or C
A= $v->type eq "list"B= $v->type eq "vector"C= $v->type eq "xml"
ABCresult
1XX1
01X1
0011
0000
941 10 $r->value(scalar @{$v->value()});
942 } elsif($v->type() eq "map") {
943 1 $r->value(scalar %{$v->value()});
944 } else {
945 0 $ast->error("unexpected type " . $v->type() . " of argument for length");
946 };
947 12 return $r;
948 # (reverse list_or_vector_or_xml_or_string)
949 } elsif($fn eq "reverse") {
950 1 ▶ $ast->error("length expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
951 1 my $v = $self->_eval($ast->second());
952 1 my $r;
953 1 ▶ if($v->type() eq "string"){
Branch: 3 branches
BranchTrueFalseTotal
if ($v->type eq 'string') { } 0 1 1
elsif ($v->type eq 'list') { } 1 0 1
elsif ($v->type eq 'vector' or $v->type eq 'xml') { } 0 0 0
954 0 $r = CljPerl::Atom->new("string", 0);
955 0 $r->value(reverse($v->value()));
956 } elsif($v->type() eq "list") {
957 1 $r = CljPerl::Seq->new("list");
958 1 my @vv = reverse @{$v->value()};
959 1 $r->value(\@vv);
960 ▶ } elsif($v->type() eq "vector" or $v->type() eq "xml"){
Condition0%0/3
$v->type eq "vector" or $v->type eq "xml"
l!l&&r!l&&!r
000
MC/DC0%0/2
$v->type eq "vector" or $v->type eq "xml"
$v->type eq "vector" $v->type eq "xml"
Truth table0%0/3
A or B
A= $v->type eq "vector"B= $v->type eq "xml"
ABresult
1X1
011
000
961 0 $r = CljPerl::Atom->new($v->type());
962 0 my @vv = reverse @{$v->value()};
963 0 $r->value(\@vv);
964 } else {
965 0 $ast->error("unexpected type " . $v->type() . " of argument for reverse");
966 };
967 1 return $r;
968 # (append list1 list2)
969 } elsif($fn eq "append") {
970 11 ▶ $ast->error("append expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 11 11
971 11 my $v1 = $self->_eval($ast->second());
972 11 my $v2 = $self->_eval($ast->third());
973 11 my $v1type = $v1->type();
974 11 my $v2type = $v2->type();
975 11 ▶ $ast->error("append expects string or list or vector as arguments but got " . $v1type . " and " . $v2type)
Branch: 1 branch
BranchTrueFalseTotal
if $v1type ne $v2type or $v1type ne "string" and $v1type ne "list" and $v1type ne "vector" and $v1type ne "map" 0 11 11
Condition75%9/12
$v1type ne $v2type or $v1type ne "string" and $v1type ne "list" and $v1type ne "vector" and $v1type ne "map"
l!l&&r!l&&!r
0011
$v1type ne "string" and $v1type ne "list" and $v1type ne "vector" and $v1type ne "map"
!ll&&!rl&&r
1010
$v1type ne "string" and $v1type ne "list" and $v1type ne "vector"
!ll&&!rl&&r
911
$v1type ne "string" and $v1type ne "list"
!ll&&!rl&&r
182
MC/DC0%0/5
$v1type ne $v2type or $v1type ne "string" and $v1type ne "list" and $v1type ne "vector" and $v1type ne "map"
$v1type ne $v2type $v1type ne "string" $v1type ne "list" $v1type ne "vector" $v1type ne "map"
Truth table66%4/6
A or B and C and D and E
A= $v1type ne $v2typeB= $v1type ne "string"C= $v1type ne "list"D= $v1type ne "vector"E= $v1type ne "map"
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
976 if (($v1type ne $v2type)
977 or ($v1type ne "string"
978 and $v1type ne "list"
979 and $v1type ne "vector"
980 and $v1type ne "map"));
981 11 ▶ if($v1type eq "string") {
Branch: 2 branches
BranchTrueFalseTotal
if ($v1type eq 'string') { } 1 10 11
elsif ($v1type eq 'list' or $v1type eq 'vector') { } 9 1 10
982 1 return CljPerl::Atom->new("string", $v1->value() . $v2->value());
983 ▶ } elsif($v1type eq "list" or $v1type eq "vector") {
Condition100%3/3
$v1type eq "list" or $v1type eq "vector"
l!l&&r!l&&!r
811
MC/DC100%2/2
$v1type eq "list" or $v1type eq "vector"
$v1type eq "list" $v1type eq "vector"
Truth table100%3/3
A or B
A= $v1type eq "list"B= $v1type eq "vector"
ABresult
1X1
011
000
984 9 my @r = ();
985 9 push @r, @{$v1->value()};
986 9 push @r, @{$v2->value()};
987 9 ▶ if($v1type eq "list"){
Branch: 1 branch
BranchTrueFalseTotal
if ($v1type eq 'list') { } 8 1 9
988 8 return CljPerl::Seq->new("list", \@r);
989 } else {
990 1 return CljPerl::Atom->new("vector", \@r);
991 };
992 } else {
993 1 my %r = (%{$v1->value()}, %{$v2->value()});
994 1 return CljPerl::Atom->new("map", \%r);
995 };
996 # (keys map)
997 } elsif($fn eq "keys") {
998 1 ▶ $ast->error("keys expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
999 1 my $v = $self->_eval($ast->second());
1000 1 ▶ $ast->error("keys expects map as arguments but got " . $v->type()) if $v->type() ne "map";
Branch: 1 branch
BranchTrueFalseTotal
if $v->type ne "map" 0 1 1
1001 1 my @r = ();
1002 1 foreach my $k (keys %{$v->value()}) {
1003 2 push @r, CljPerl::Atom->new("keyword", $k);
1004 };
1005 1 return CljPerl::Seq->new("list", \@r);
1006 # (namespace-begin "ns")
1007 } elsif($fn eq "namespace-begin") {
1008 4 ▶ $ast->error("namespace-begin expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 4 4
1009 4 my $v = $ast->second();
1010 4 ▶ if($v->type() eq "symbol" or $v->type() eq "keyword") {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->type eq 'symbol' or $v->type eq 'keyword') { } 1 3 4
Condition66%2/3
$v->type eq "symbol" or $v->type eq "keyword"
l!l&&r!l&&!r
103
MC/DC50%1/2
$v->type eq "symbol" or $v->type eq "keyword"
$v->type eq "symbol" $v->type eq "keyword"
Truth table66%2/3
A or B
A= $v->type eq "symbol"B= $v->type eq "keyword"
ABresult
1X1
011
000
1011 } else {
1012 3 $v = $self->_eval($v);
1013 3 ▶ $ast->error("namespace-begin expects string as argument but got " . $v->type())
Branch: 1 branch
BranchTrueFalseTotal
if $v->type ne "string" 0 3 3
1014 if $v->type() ne "string";
1015 };
1016 4 $self->push_namespace($v->value());
1017 4 return $v;
1018 # (namespace-end)
1019 } elsif($fn eq "namespace-end") {
1020 4 ▶ $ast->error("namespace-end expects 0 argument") if $size != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 1 0 4 4
1021 4 $self->pop_namespace();
1022 4 return $nil;
1023 # (object-id obj)
1024 } elsif($fn eq "object-id") {
1025 1 ▶ $ast->error("object-id expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
1026 1 my $v = $self->_eval($ast->second());
1027 1 return CljPerl::Atom->new("string", $v->object_id());
1028 # (type obj)
1029 } elsif($fn eq "type") {
1030 7 ▶ $ast->error("type expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 7 7
1031 7 my $v = $self->_eval($ast->second());
1032 7 return CljPerl::Atom->new("string", $v->type());
1033 # (perlobj-type obj)
1034 } elsif($fn eq "perlobj-type") {
1035 0 ▶ $ast->error("perlobj-type expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 0 0
1036 0 my $v = $self->_eval($ast->second());
1037 0 ▶ $ast->error("perlobj-type expects perlobject as argument but got " . $v->type()) if($v->type() ne "perlobject");
Branch: 1 branch
BranchTrueFalseTotal
if $v->type ne "perlobject" 0 0 0
1038 0 return CljPerl::Atom->new("string", ref($v->value()));
1039 # (apply fn list)
1040 } elsif($fn eq "apply") {
1041 3 ▶ $ast->error("apply expects 2 arguments") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 3 3
1042 3 my $f = $self->_eval($ast->second());
1043 $ast->error("apply expects function as the first argument but got " . $f->type())
1044 if ($f->type() ne "function"
1045 3 ▶ and !($f->type() eq "symbol" and exists $builtin_funcs->{$f->value()}));
Branch: 1 branch
BranchTrueFalseTotal
if $f->type ne "function" and not $f->type eq "symbol" && exists $$builtin_funcs{$f->value} 0 3 3
Condition50%3/6
$f->type ne "function" and not $f->type eq "symbol" && exists $$builtin_funcs{$f->value}
!ll&&!rl&&r
210
$f->type eq 'symbol' && exists $$builtin_funcs{$f->value}
!ll&&!rl&&r
001
MC/DC0%0/3
$f->type ne "function" and not $f->type eq "symbol" && exists $$builtin_funcs{$f->value}
$f->type ne "function" $f->type eq 'symbol' exists $$builtin_funcs{$f->value}
Truth table50%2/4
A and not(B && C)
A= $f->type ne "function"B= $f->type eq 'symbol'C= exists $$builtin_funcs{$f->value}
ABCresult
0XX0
1110
10X1
1101
1046 3 my $l = $self->_eval($ast->third());
1047 3 ▶ $ast->error("apply expects list as the first argument but got " . $l->type()) if $l->type() ne "list";
Branch: 1 branch
BranchTrueFalseTotal
if $l->type ne "list" 0 3 3
1048 3 my $n = CljPerl::Seq->new("list");
1049 3 $n->append($f);
1050 3 foreach my $i (@{$l->value()}) {
1051 3 $n->append($i);
1052 }
1053 3 return $self->_eval($n);
1054 # (meta obj)
1055 } elsif($fn eq "meta") {
1056 13 ▶ $ast->error("meta expects 1 or 2 arguments") if $size < 2 or $size > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 2 or $size > 3 0 13 13
Condition33%1/3
$size < 2 or $size > 3
l!l&&r!l&&!r
0013
MC/DC0%0/2
$size < 2 or $size > 3
$size < 2 $size > 3
Truth table33%1/3
A or B
A= $size < 2B= $size > 3
ABresult
1X1
011
000
1057 13 my $v = $self->_eval($ast->second());
1058 13 ▶ if($size == 3){
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 3) 1 12 13
1059 1 my $vm = $self->_eval($ast->third());
1060 1 ▶ $ast->error("meta expects 1 meta data as the second arguments but got " . $vm->type()) if $vm->type() ne "meta";
Branch: 1 branch
BranchTrueFalseTotal
if $vm->type ne "meta" 0 1 1
1061 1 $v->meta($vm);
1062 }
1063 13 my $m = $v->meta();
1064 13 ▶ $ast->error("no meta data in " . CljPerl::Printer::to_string($v)) if !defined $m;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 0 13 13
1065 13 return $m;
1066 } elsif($fn eq "clj->string") {
1067 1 ▶ $ast->error("clj->string expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
1068 1 my $v = $self->_eval($ast->second());
1069 1 return CljPerl::Atom->new("string", CljPerl::Printer::to_string($v));
1070 # (.namespace function args...)
1071 } elsif($fn =~ /^(\.|->)(\S*)$/) {
1072 14 my $blessed = $1;
1073 14 my $ns = $2;
1074 14 ▶ $ast->error(". expects > 1 arguments") if $size < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 2 0 14 14
1075 14 ▶ $ast->error(". expects a symbol or keyword or stirng as the first argument but got " . $ast->second()->type())
Branch: 1 branch
BranchTrueFalseTotal
if $ast->second->type ne "symbol" and $ast->second->type ne "keyword" and $ast->second->type ne "string" 0 14 14
Condition33%2/6
$ast->second->type ne "symbol" and $ast->second->type ne "keyword" and $ast->second->type ne "string"
!ll&&!rl&&r
1400
$ast->second->type ne "symbol" and $ast->second->type ne "keyword"
!ll&&!rl&&r
1400
MC/DC0%0/3
$ast->second->type ne "symbol" and $ast->second->type ne "keyword" and $ast->second->type ne "string"
$ast->second->type ne "symbol" $ast->second->type ne "keyword" $ast->second->type ne "string"
Truth table25%1/4
A and B and C
A= $ast->second->type ne "symbol"B= $ast->second->type ne "keyword"C= $ast->second->type ne "string"
ABCresult
0XX0
10X0
1100
1111
1076 if ($ast->second()->type() ne "symbol"
1077 and $ast->second()->type() ne "keyword"
1078 and $ast->second()->type() ne "string");
1079 14 my $perl_func = $ast->second()->value();
1080 14 ▶ if($perl_func eq "require") {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_func eq 'require') { } 0 14 14
1081 0 ▶ $ast->error(". require expects 1 argument") if $size != 3;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 3 0 0 0
1082 0 my $m = $ast->third();
1083 0 ▶ if($m->type() eq "keyword" or $m->type() eq "symbol") {
Branch: 2 branches
BranchTrueFalseTotal
if ($m->type eq 'keyword' or $m->type eq 'symbol') { } 0 0 0
elsif ($m->type eq 'string') { } 0 0 0
Condition0%0/3
$m->type eq "keyword" or $m->type eq "symbol"
l!l&&r!l&&!r
000
MC/DC0%0/2
$m->type eq "keyword" or $m->type eq "symbol"
$m->type eq "keyword" $m->type eq "symbol"
Truth table0%0/3
A or B
A= $m->type eq "keyword"B= $m->type eq "symbol"
ABresult
1X1
011
000
1084 } elsif($m->type() eq "string") {
1085 0 $m = $self->_eval($ast->third());
1086 } else {
1087 0 $ast->error(". require expects a string but got " . $m->type());
1088 };
1089 0 my $mn = $m->value();
1090 0 $mn =~ s/::/\//g;
1091 0 foreach my $ext ("", ".pm") {
1092 0 ▶ if(-f $mn . $ext) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $mn . $ext) 0 0 0
1093 0 require $mn . $ext;
1094 0 return $true;
1095 };
1096 0 foreach my $p (@INC) {
1097 0 ▶ if(-f "$p/$mn$ext") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$p/$mn$ext") 0 0 0
1098 0 require "$p/$mn$ext";
1099 0 return $true;
1100 };
1101 }
1102 }
1103 0 $ast->error("cannot find $mn");
1104 } else {
1105 14 ▶ $ns = "CljPerl" if ! defined $ns or $ns eq "";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ns or $ns eq "" 13 1 14
Condition66%2/3
not defined $ns or $ns eq ""
l!l&&r!l&&!r
0131
MC/DC50%1/2
not defined $ns or $ns eq ""
not defined $ns $ns eq ""
Truth table66%2/3
not(A) or B
A= not defined $nsB= $ns eq ""
ABresult
1X1
011
000
1106 14 my $meta = undef;
1107 14 ▶ $meta = $self->_eval($ast->third()) if defined $ast->third() and $ast->third()->type() eq "meta";
Branch: 1 branch
BranchTrueFalseTotal
if defined $ast->third and $ast->third->type eq "meta" 0 14 14
Condition66%2/3
defined $ast->third and $ast->third->type eq "meta"
!ll&&!rl&&r
1130
MC/DC0%0/2
defined $ast->third and $ast->third->type eq "meta"
defined $ast->third $ast->third->type eq "meta"
Truth table66%2/3
A and B
A= defined $ast->thirdB= $ast->third->type eq "meta"
ABresult
0X0
100
111
1108 14 $perl_func = $ns . "::" . $perl_func;
1109 14 ▶ my @rest = $ast->slice((defined $meta ? 3 : 2) .. $size-1);
Branch: 1 branch
BranchTrueFalseTotal
defined $meta ? : 0 14 14
1110 14 ▶ unshift @rest, CljPerl::Atom->new("string", $ns) if $blessed eq "->";
Branch: 1 branch
BranchTrueFalseTotal
if $blessed eq "->" 0 14 14
1111 14 return $self->perlfunc_call($perl_func, $meta, \@rest);
1112 }
1113 # (perl->clj o)
1114 } elsif($fn eq "perl->clj") {
1115 6 ▶ $ast->error("perl->clj expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 6 6
1116 6 my $o = $self->_eval($ast->second());
1117 6 ▶ $ast->error("perl->clj expects perlobject as argument but got " . $o->type()) if $o->type() ne "perlobject";
Branch: 1 branch
BranchTrueFalseTotal
if $o->type ne "perlobject" 0 6 6
1118 6 return &perl2clj($o->value());
1119 # (println obj)
1120 } elsif($fn eq "println") {
1121 100 ▶ $ast->error("println expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 100 100
1122 100 print CljPerl::Printer::to_string($self->_eval($ast->second())) . "\n";
1123 100 return $nil;
1124 } elsif($fn eq "coro") {
1125 1 ▶ $ast->error("coro expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 1 1
1126 1 my $b = $self->_eval($ast->second());
1127 1 ▶ $ast->error("core expects a function as argument but got " . $b->type()) if $b->type() ne "function";
Branch: 1 branch
BranchTrueFalseTotal
if $b->type ne "function" 0 1 1
1128 1 ▶ my $coro = new Coro sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1129 1 my $evaler = CljPerl::Evaler->new();
1130 1 my $fc = CljPerl::Seq->new("list");
1131 1 $fc->append($b);
1132 1 $evaler->_eval($fc);
1133 1 };
1134 1 $coro->ready();
1135 1 return CljPerl::Atom->new("coroutine", $coro);
1136 } elsif($fn eq "coro-suspend") {
1137 0 ▶ $ast->error("coro-suspend expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 0 0
1138 0 my $coro = $self->_eval($ast->second());
1139 0 ▶ $ast->error("coro-suspend expects a coroutine as argument but got " . $coro->type()) if $coro->type() ne "coroutine";
Branch: 1 branch
BranchTrueFalseTotal
if $coro->type ne "coroutine" 0 0 0
1140 0 $coro->value()->suspend();
1141 0 return $coro;
1142 } elsif($fn eq "coro-sleep") {
1143 1 ▶ $ast->error("coro-sleep expects 0 argument") if $size != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 1 0 1 1
1144 1 $Coro::current->suspend();
1145 1 cede;
1146 1 return CljPerl::Atom->new("coroutine", $Coro::current);
1147 } elsif($fn eq "coro-yield") {
1148 0 ▶ $ast->error("coro-yield expects 0 argument") if $size != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 1 0 0 0
1149 0 cede;
1150 0 return CljPerl::Atom->new("coroutine", $Coro::current);
1151 } elsif($fn eq "coro-resume") {
1152 2 ▶ $ast->error("coro-resume expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 2 2
1153 2 my $coro = $self->_eval($ast->second());
1154 2 ▶ $ast->error("coro-resume expects a coroutine as argument but got " . $coro->type()) if $coro->type() ne "coroutine";
Branch: 1 branch
BranchTrueFalseTotal
if $coro->type ne "coroutine" 0 2 2
1155 2 $coro->value()->resume();
1156 2 $coro->value()->cede_to();
1157 2 return $coro;
1158 } elsif($fn eq "coro-wake") {
1159 0 ▶ $ast->error("coro-wake expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 0 0
1160 0 my $coro = $self->_eval($ast->second());
1161 0 ▶ $ast->error("coro-wake expects a coroutine as argument but got " . $coro->type()) if $coro->type() ne "coroutine";
Branch: 1 branch
BranchTrueFalseTotal
if $coro->type ne "coroutine" 0 0 0
1162 0 $coro->value()->resume();
1163 0 return $coro;
1164 } elsif($fn eq "join-coro") {
1165 0 ▶ $ast->error("join-coro expects 1 argument") if $size != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 2 0 0 0
1166 0 my $coro = $self->_eval($ast->second());
1167 0 ▶ $ast->error("join-coro expects a coroutine as argument but got " . $coro->type()) if $coro->type() ne "coroutine";
Branch: 1 branch
BranchTrueFalseTotal
if $coro->type ne "coroutine" 0 0 0
1168 0 $coro->value()->join();
1169 0 return $coro;
1170 } elsif($fn eq "coro-current") {
1171 2 ▶ $ast->error("coro-current expects 0 argument") if $size != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 1 0 2 2
1172 2 return CljPerl::Atom->new("coroutine", $Coro::current);
1173 } elsif($fn eq "coro-main") {
1174 1 ▶ $ast->error("coro-main expects 0 argument") if $size != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 1 0 1 1
1175 1 return CljPerl::Atom->new("coroutine", $Coro::main);
1176 } elsif($fn eq "trace-vars") {
1177 0 ▶ $ast->error("trace-vars expects 0 argument") if $size != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size != 1 0 0 0
1178 0 $self->trace_vars();
1179 0 return $nil;
1180 };
1181
1182 0 return $ast;
1183 }
1184
1185 14 ▶ sub perlfunc_call {
Subroutine perlfunc_call: called CC=25 SCAR=57.3
Pod undocumented
1186 14 my $self = shift;
1187 14 my $perl_func = shift;
1188 14 my $meta = shift;
1189 14 my $rargs = shift;
1190 14 my $ret_type = "scalar";
1191 14 my @fargtypes = ();
1192 14 ▶ if(defined $meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta) 0 14 14
1193 0 ▶ if(exists $meta->value()->{"return"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $meta->value->{"return"}) 0 0 0
1194 0 my $rt = $meta->value()->{"return"};
1195 0 ▶ $ast->error("return expects a string or keyword but got " . $rt->type())
Branch: 1 branch
BranchTrueFalseTotal
if $rt->type ne "string" and $rt->type ne "keyword" 0 0 0
Condition0%0/3
$rt->type ne "string" and $rt->type ne "keyword"
!ll&&!rl&&r
000
MC/DC0%0/2
$rt->type ne "string" and $rt->type ne "keyword"
$rt->type ne "string" $rt->type ne "keyword"
Truth table0%0/3
A and B
A= $rt->type ne "string"B= $rt->type ne "keyword"
ABresult
0X0
100
111
1196 if $rt->type() ne "string"
1197 and $rt->type() ne "keyword";
1198 0 $ret_type = $rt->value();
1199 };
1200 0 ▶ if(exists $meta->value()->{"arguments"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $meta->value->{"arguments"}) 0 0 0
1201 0 my $ats = $meta->value()->{"arguments"};
1202 0 ▶ $ast->error("arguments expect a vector but got " . $ats->type()) if $ats->type() ne "vector";
Branch: 1 branch
BranchTrueFalseTotal
if $ats->type ne "vector" 0 0 0
1203 0 foreach my $arg (@{$ats->value()}) {
1204 0 ▶ $ast->error("arguments expect a vector of string or keyword but got " . $arg->type())
Branch: 1 branch
BranchTrueFalseTotal
if $arg->type ne "string" and $arg->type ne "keyword" 0 0 0
Condition0%0/3
$arg->type ne "string" and $arg->type ne "keyword"
!ll&&!rl&&r
000
MC/DC0%0/2
$arg->type ne "string" and $arg->type ne "keyword"
$arg->type ne "string" $arg->type ne "keyword"
Truth table0%0/3
A and B
A= $arg->type ne "string"B= $arg->type ne "keyword"
ABresult
0X0
100
111
1205 if $arg->type() ne "string"
1206 and $arg->type() ne "keyword";
1207 0 push @fargtypes, $arg->value();
1208 };
1209 };
1210 };
1211 14 my @args = ();
1212 14 my $i = 0;
1213 14 foreach my $arg (@{$rargs}) {
1214 22 my $pobj = $self->clj2perl($self->_eval($arg));
1215 22 ▶ if($i < scalar @fargtypes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @fargtypes) { } 0 22 22
1216 0 my $ft = $fargtypes[$i];
1217 0 ▶ if($ft eq "scalar") {
Branch: 4 branches
BranchTrueFalseTotal
if ($ft eq 'scalar') { } 0 0 0
elsif ($ft eq 'array') { } 0 0 0
elsif ($ft eq 'hash') { } 0 0 0
elsif ($ft eq 'ref') { } 0 0 0
1218 0 push @args, $pobj;
1219 } elsif($ft eq "array") {
1220 0 push @args, @{$pobj};
1221 } elsif($ft eq "hash") {
1222 0 push @args, %{$pobj};
1223 } elsif($ft eq "ref") {
1224 0 push @args, \$pobj;
1225 } else {
1226 0 push @args, $pobj;
1227 };
1228 } else {
1229 22 ▶ if(ref($pobj) eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $pobj eq 'ARRAY') { } 0 22 22
elsif (ref $pobj eq 'HASH') { } 0 22 22
1230 0 push @args, @{$pobj};
1231 } elsif(ref($pobj) eq "HASH") {
1232 0 push @args, %{$pobj};
1233 } else {
1234 22 push @args, $pobj;
1235 };
1236 };
1237 22 $i ++;
1238 };
1239
1240 14 ▶ if($ret_type eq "scalar") {
Branch: 7 branches
BranchTrueFalseTotal
if ($ret_type eq 'scalar') { } 14 0 14
elsif ($ret_type eq 'ref-scalar') { } 0 0 0
elsif ($ret_type eq 'array') { } 0 0 0
elsif ($ret_type eq 'ref-array') { } 0 0 0
elsif ($ret_type eq 'hash') { } 0 0 0
elsif ($ret_type eq 'ref-hash') { } 0 0 0
elsif ($ret_type eq 'nil') { } 0 0 0
1241 14 my $r = $perl_func->(@args);
1242 14 return &wrap_perlobj($r);
1243 } elsif($ret_type eq "ref-scalar") {
1244 0 my $r = $perl_func->(@args);
1245 0 return &wrap_perlobj(\$r);
1246 } elsif($ret_type eq "array") {
1247 0 my @r = $perl_func->(@args);
1248 0 return &wrap_perlobj(@r);
1249 } elsif($ret_type eq "ref-array") {
1250 0 my @r = $perl_func->(@args);
1251 0 return &wrap_perlobj(\@r);
1252 } elsif($ret_type eq "hash") {
1253 0 my %r = $perl_func->(@args);
1254 0 return &wrap_perlobj(%r);
1255 } elsif($ret_type eq "ref-hash") {
1256 0 my %r = $perl_func->(@args);
1257 0 return &wrap_perlobj(\%r);
1258 } elsif($ret_type eq "nil") {
1259 0 $perl_func->(@args);
1260 0 return $nil;
1261 } else {
1262 0 my $r = \$perl_func->(@args);
1263 0 return &wrap_perlobj($r);
1264 };
1265
1266 }
1267
1268 25 ▶ sub clj2perl {
Subroutine clj2perl: called CC=15 SCAR=35.0
Pod undocumented
1269 25 my $self = shift;
1270 25 my $ast = shift;
1271 25 my $type = $ast->type();
1272 25 my $value = $ast->value();
1273 25 ▶ if($type eq "string" or $type eq "number"
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq 'string' or $type eq 'number' or $type eq 'quotation' or $type eq 'keyword' or $type eq 'perlobject') { } 21 4 25
elsif ($type eq 'bool') { } 0 4 4
elsif ($type eq 'nil') { } 1 3 4
elsif ($type eq 'list' or $type eq 'vector') { } 0 3 3
elsif ($type eq 'map') { } 0 3 3
elsif ($type eq 'function') { } 3 0 3
Condition75%9/12
$type eq "string" or $type eq "number" or $type eq "quotation" or $type eq "keyword" or $type eq "perlobject"
l!l&&r!l&&!r
1654
$type eq "string" or $type eq "number" or $type eq "quotation" or $type eq "keyword"
l!l&&r!l&&!r
1609
$type eq "string" or $type eq "number" or $type eq "quotation"
l!l&&r!l&&!r
1609
$type eq "string" or $type eq "number"
l!l&&r!l&&!r
1609
MC/DC40%2/5
$type eq "string" or $type eq "number" or $type eq "quotation" or $type eq "keyword" or $type eq "perlobject"
$type eq "string" $type eq "number" $type eq "quotation" $type eq "keyword" $type eq "perlobject"
Truth table50%3/6
A or B or C or D or E
A= $type eq "string"B= $type eq "number"C= $type eq "quotation"D= $type eq "keyword"E= $type eq "perlobject"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1274 or $type eq "quotation" or $type eq "keyword"
1275 or $type eq "perlobject") {
1276 21 return $value;
1277 } elsif($type eq "bool") {
1278 0 ▶ if($value eq "true") {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq 'true') { } 0 0 0
1279 0 return 1;
1280 } else {
1281 0 return 0;
1282 }
1283 } elsif($type eq "nil") {
1284 1 return undef;
1285 ▶ } elsif($type eq "list" or $type eq "vector") {
Condition33%1/3
$type eq "list" or $type eq "vector"
l!l&&r!l&&!r
003
MC/DC0%0/2
$type eq "list" or $type eq "vector"
$type eq "list" $type eq "vector"
Truth table33%1/3
A or B
A= $type eq "list"B= $type eq "vector"
ABresult
1X1
011
000
1286 0 my @r = ();
1287 0 foreach my $i (@{$value}) {
1288 0 push @r, $self->clj2perl($i);
1289 };
1290 0 return \@r;
1291 } elsif($type eq "map") {
1292 0 my %r = ();
1293 0 foreach my $k (keys %{$value}) {
1294 0 $r{$k} = $self->clj2perl($value->{$k});
1295 };
1296 0 return \%r;
1297 } elsif($type eq "function") {
1298 3 ▶ my $f = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1299 3 my @args = @_;
1300 3 my $cljf = CljPerl::Seq->new("list");
1301 3 $cljf->append($ast);
1302 3 foreach my $arg (@args) {
1303 3 $cljf->append(&perl2clj($arg));
1304 };
1305 3 return $self->clj2perl($self->_eval($cljf));
1306 3 };
1307 3 return $f;
1308 } else {
1309 0 $ast->error("unsupported type " . $type . " for clj2perl object conversion");
1310 }
1311 }
1312
1313 14 ▶ sub wrap_perlobj {
Subroutine wrap_perlobj: called CC=2 SCAR=8.4
Pod undocumented
1314 14 my $v = shift;
1315 14 ▶ while(ref($v) eq "REF") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "REF") 0 14 14
1316 0 $v = ${$v};
1317 }
1318 14 return CljPerl::Atom->new("perlobject", $v);
1319 }
1320
1321 13 ▶ sub perl2clj {
Subroutine perl2clj: called CC=9 SCAR=26.5
Pod undocumented
1322 13 my $v = shift; #$ast->value();
1323 13 ▶ if(! defined ref($v) or ref($v) eq ""){
Branch: 5 branches
BranchTrueFalseTotal
if (not defined ref $v or ref $v eq '') { } 6 7 13
elsif (ref $v eq 'SCALAR') { } 0 7 7
elsif (ref $v eq 'HASH') { } 0 7 7
elsif (ref $v eq 'ARRAY') { } 4 3 7
elsif (ref $v eq 'CODE') { } 0 3 3
Condition66%2/3
not defined ref $v or ref $v eq ""
l!l&&r!l&&!r
067
MC/DC50%1/2
not defined ref $v or ref $v eq ""
not defined ref $v ref $v eq ""
Truth table66%2/3
not(A) or B
A= not defined ref $vB= ref $v eq ""
ABresult
1X1
011
000
1324 6 return CljPerl::Atom->new("string", $v);
1325 } elsif(ref($v) eq "SCALAR") {
1326 0 return CljPerl::Atom->new("string", ${$v});
1327 } elsif(ref($v) eq "HASH") {
1328 0 my %m = ();
1329 0 foreach my $k (keys %{$v}) {
1330 0 $m{$k} = &perl2clj($v->{$k});
1331 };
1332 0 return CljPerl::Atom->new("map", \%m);
1333 } elsif(ref($v) eq "ARRAY") {
1334 4 my @a = ();
1335 4 foreach my $i (@{$v}) {
1336 4 push @a, &perl2clj($i);
1337 };
1338 4 return CljPerl::Atom->new("vector", \@a);
1339 } elsif(ref($v) eq "CODE") {
1340 0 return CljPerl::Atom->new("perlfunction", $v);
1341 } else {
1342 3 return CljPerl::Atom->new("perlobject", $v);
1343 #$ast->error("expect a reference of scalar or hash or array");
1344 };
1345 }
1346
1347 0 ▶ sub trace_vars {
Subroutine trace_vars: not called CC=2 SCAR=17.9
Pod undocumented
1348 0 my $self = shift;
1349 0 print @{$self->scopes()} . "\n";
1350 0 foreach my $vn (keys %{$self->current_scope()}) {
1351 0 print "$vn\n" # . CljPerl::Printer::to_string(${$self->current_scope()}{$vn}->value()) . "\n";
1352 };
1353 }
1354
1355 2 1;
↑ Summary CljPerl/Printer.pm »