blib/lib/Lingy/RT.pm

filter: Statementstmt 82.1% 262 / 319 Branchbran 62.5% 75 / 120 Conditioncond 56.8% 29 / 51 MC/DCmcdc 22.5% 7 / 31 Subroutinesub 87.5% 84 / 96 Podpod 0.0% 0 / 78 totaltotal 65.7% 457 / 695 CC 87 SCAR 24.8
CC
87
Cov
75%
repl
117.2
ns
42.5
get
6.0
CRAP 11.9
« blib/lib/Lingy/Numbers.pm ↑ Summary lib/Lingy/Reader.pm »
1 60 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::RT;
3  
4 60 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 60 ▶use Lingy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 60 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 60 ▶use Lingy::Evaluator;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 60 ▶use Lingy::Namespace;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 60 ▶use Lingy::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 60 ▶use constant LANG => 'Lingy';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 60 ▶use constant HOST => 'perl';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 60 ▶use constant env_class => 'Lingy::Env';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 60 ▶use constant printer_class => 'Lingy::Printer';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 60 ▶use constant reader_class => 'Lingy::Reader';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 60 ▶use constant RL => Lingy::ReadLine->new;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 60 my @class_names = (
21 ATOM,
22 BOOLEAN,
23 CHARACTER,
24 CLASS,
25 CLOJURE,
26 COMPILER,
27 EXCEPTION,
28 FUNCTION,
29 HASHMAP,
30 HASHSET,
31 KEYWORD,
32 LIST,
33 LISTTYPE,
34 MACRO,
35 NIL,
36 NUMBER,
37 REGEX,
38 SEQUENTIAL,
39 STRBUILD,
40 STRING,
41 SYMBOL,
42 SYSTEM,
43 VAR,
44 VECTOR,
45 NUMBERS,
46 RT,
47 TERM,
48 THREAD,
49 UTIL,
50  
51 ILLEGALARGUMENTEXCEPTION,
52 );
53 59 ▶sub class_names { \@class_names }
Subroutine class_names: called CC=1 SCAR=0.0
Pod undocumented
54  
55 60 my $current_ns_name;
56 143 ▶sub current_ns_name { $current_ns_name = $_[1] // $current_ns_name }
Subroutine current_ns_name: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[1] // $current_ns_name
l!l&&r!l&&!r
14210
MC/DC0%0/2
$_[1] // $current_ns_name
$_[1] $current_ns_name
Truth table66%2/3
A // B
A= $_[1]B= $current_ns_name
ABresult
1X1
011
000
57  
58 my %namespaces;
59 60 bless \%namespaces, 'lingy-internal';
60 373 ▶sub namespaces { \%namespaces }
Subroutine namespaces: called CC=1 SCAR=0.0
Pod undocumented
61 125432 ▶sub current_ns { $namespaces{$current_ns_name} }
Subroutine current_ns: called CC=1 SCAR=0.0
Pod undocumented
62  
63 60 my %classes;
64 0 ▶sub classes { \%classes }
Subroutine classes: not called CC=1 SCAR=6.9
Pod undocumented
65  
66 my %meta;
67 8880 ▶sub meta { \%meta }
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
68  
69 60 my $env;
70 142 ▶sub env { $env }
Subroutine env: called CC=1 SCAR=0.0
Pod undocumented
71 0 ▶sub ENV { $Lingy::Evaluator::ENV }
Subroutine ENV: not called CC=1 SCAR=6.9
72  
73 60 my $reader;
74 1 ▶sub reader { $reader }
Subroutine reader: called CC=1 SCAR=0.0
Pod undocumented
75  
76 60 my $printer;
77 7 ▶sub printer { $printer }
Subroutine printer: called CC=1 SCAR=0.0
Pod undocumented
78  
79 60 my $core_ns;
80 93685 ▶sub core_ns { $core_ns }
Subroutine core_ns: called CC=1 SCAR=0.0
Pod undocumented
81  
82 60 my $user_ns;
83 0 ▶sub user_ns { $user_ns }
Subroutine user_ns: not called CC=1 SCAR=6.9
Pod undocumented
84  
85 60 our $OK = 0;
86  
87 sub init {
88 58 ▶ my ($self) = @_;
Subroutine init: called CC=4 SCAR=13.9
Pod undocumented
89  
90 58 for my $package_name (@{RT->class_names}) {
91 1740 ▶ eval "require $package_name; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $package_name; 1" or die $@ 0 1740 1740
92 1740 my $class = CLASS->_new($package_name);
93 1740 my $class_name = $class->_name;
94 1740 $classes{$class_name} = $class;
95 1740 ▶ if ($class_name =~ /\.(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name =~ /\.(\w+)$/) 1740 0 1740
96 1740 $classes{$1} = $class;
97 }
98 }
99  
100 58 $env = $self->require_new($self->env_class);
101 58 $reader = $self->require_new($self->reader_class);
102 58 $printer = $self->require_new($self->printer_class);
103  
104 58 $core_ns = $self->core_namespace();
105 58 $user_ns = NAMESPACE->new('user')
106 ->refer(symbol($self->core_ns->_name))
107 ->current;
108  
109 58 $OK = 1;
110  
111 58 return $self;
112 }
113  
114 sub core_namespace {
115 58 ▶ my ($self) = (@_);
Subroutine core_namespace: called CC=6 SCAR=17.9
Pod undocumented
116  
117 58 my $ns = NAMESPACE->new('lingy.core', %classes)->current;
118  
119 58 $ns->{$_} = $classes{$_} for CORE::keys %classes;
120  
121 58 ▶ my $argv = @ARGV
Branch: 1 branch
BranchTrueFalseTotal
@ARGV ? : 17 41 58
122 ? LIST->new([
123 map STRING->new($_), @ARGV[1..$#ARGV]]
124 ) : NIL->new;
125  
126 # Define these functions first for bootstrapping:
127 58 $env->set(cons => \&cons);
128 58 $env->set(concat => \&concat);
129 58 ▶ $env->set(eval => sub { evaluate($_[0], $env) });
Subroutine __ANON__: called CC=1 SCAR=0.0
130  
131 # Clojure dynamic vars:
132 58 ▶ my $file = $ARGV[0] || "NO_SOURCE_PATH";
Condition100%2/2
$ARGV[0] || 'NO_SOURCE_PATH'
l!l
1741
MC/DC100%1/1
$ARGV[0] || 'NO_SOURCE_PATH'
$ARGV[0]
Truth table100%2/2
A
A= $ARGV[0]
Aresult
11
00
133 58 ▶ $file = Cwd::abs_path($file) unless $file eq "NO_SOURCE_PATH";
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq "NO_SOURCE_PATH" 16 42 58
134 58 $env->set('*file*', STRING->new($file));
135 58 $env->set('*command-line-args*', $argv);
136  
137 # Lingy dynamic vars:
138 58 $env->set('*LANG*', STRING->new($self->LANG));
139 58 $env->set('*HOST*', STRING->new($self->HOST));
140  
141 58 $Lingy::VERSION =~ /^(\d+)\.(\d+)\.(\d+)$/;
142 58 $self->rep("
143 (def *lingy-version*
144 {
145 :major $1
146 :minor $2
147 :incremental $3
148 :qualifier nil
149 })
150  
151 (def *clojure-version*
152 {
153 :major 1
154 :minor 11
155 :incremental 1
156 :qualifier nil
157 })
158 ");
159  
160 58 my $core_ly = $INC{'Lingy/RT.pm'};
161 58 $core_ly =~ s/RT\.pm$/core.ly/;
162 58 $self->rep($self->slurp_file($core_ly));
163  
164 58 ▶ unless ($ENV{LINGY_BUILDING_CORE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"LINGY_BUILDING_CORE"}) 58 0 58
165 58 my $core_clj = $core_ly;
166 58 $core_clj =~ s/\.ly$/.clj/;
167 58 $self->rep($self->slurp_file($core_clj));
168 }
169  
170 58 return $ns;
171 }
172  
173 sub require_new {
174 174 ▶ my $self = shift;
Subroutine require_new: called CC=2 SCAR=7.0
Pod undocumented
175 174 my $class = shift;
176 174 ▶ eval "require $class; 1" or
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class; 1" or die "Can't require '${class}':\n$@" 0 174 174
177 die "Can't require '$class':\n$@";
178 174 $class->new(@_);
179 }
180  
181 sub slurp_file {
182 142 ▶ my ($self, $file) = @_;
Subroutine slurp_file: called CC=2 SCAR=7.0
Pod undocumented
183 142 ▶ open my $slurp, '<', "$file" or
Branch: 1 branch
BranchTrueFalseTotal
open my $slurp, "<", "$file" or die "Couldn't read file '${file}'" 0 142 142
184 die "Couldn't read file '$file'";
185 142 local $/;
186 142 <$slurp>;
187 }
188  
189 sub is_lingy_class {
190 41689 ▶ my ($self, $class) = @_;
Subroutine is_lingy_class: called CC=2 SCAR=6.9
Pod undocumented
191 41689 ▶ $class->isa(CLASS) or $class =~ /^Lingy::\w/;
Branch: 1 branch
BranchTrueFalseTotal
$class->isa("Lingy::Class") or $class =~ /^Lingy::\w/ 41687 2 41689
192 }
193  
194 sub eval {
195 1 ▶ my ($self, $form) = @_;
Subroutine eval: called CC=1 SCAR=0.0
Pod undocumented
196 1 evaluate(
197 $form,
198 $env,
199 );
200 }
201  
202 sub rep {
203 1322 ▶ my ($self, $str) = @_;
Subroutine rep: called CC=1 SCAR=0.0
Pod undocumented
204 1322 map $printer->pr_str(evaluate($_, $env)),
205 $reader->read_str($str);
206 }
207  
208 60 use constant repl_intro_command =>
209 60 ▶ q<(println (str *LANG* " " (lingy-version) " [" *HOST* "]\n"))>;
Subroutine BEGIN: called CC=1 SCAR=0.0
210  
211 sub repl {
212 3 ▶ my ($self) = @_;
Subroutine repl: called CC=11 SCAR=47.6
Pod undocumented
213  
214 3 $self->RL->setup;
215  
216 $self->rep($self->repl_intro_command)
217 0 ▶ unless $ENV{LINGY_TEST};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"LINGY_TEST"} 0 0 0
218 0 my ($clojure_repl) = $self->rep("(identity *clojure-repl*)");
219 0 ▶ if ($clojure_repl eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($clojure_repl eq "true") 0 0 0
220 0 require Lingy::ClojureREPL;
221 0 Lingy::ClojureREPL->start();
222 }
223  
224 0 ▶ while (defined (my $line = $self->RL->readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->RL->readline)) 0 0 0
225 0 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 0 0
226  
227 0 my @forms = eval { $reader->read_str($line, 1) };
228 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
229 0 print "$@\n";
230 0 $self->RL->input;
231 0 next;
232 }
233  
234 0 for my $form (@forms) {
235 0 my $ret = eval {
236 0 $printer->pr_str(evaluate($form, $env));
237 };
238 0 my $err;
239 0 ▶ $err = $ret = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
240 0 chomp $ret;
241 0 print "$ret\n";
242 }
243  
244 0 ▶ my $input = $self->RL->input // next;
Condition0%0/2
$self->RL->input // (next)
l!l
00
MC/DC0%0/1
$self->RL->input // (next)
$self->RL->input
Truth table0%0/2
A
A= $self->RL->input
Aresult
11
00
245 0 ($clojure_repl) = $self->rep("(identity *clojure-repl*)");
246  
247 0 ▶ if ($input =~ s/^;;;// or $clojure_repl eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ s/^;;;// or $clojure_repl eq "true") 0 0 0
Condition0%0/3
$input =~ s/^;;;// or $clojure_repl eq "true"
l!l&&r!l&&!r
000
MC/DC0%0/2
$input =~ s/^;;;// or $clojure_repl eq "true"
$input =~ s/^;;;// $clojure_repl eq "true"
Truth table0%0/3
A or B
A= $input =~ s/^;;;//B= $clojure_repl eq "true"
ABresult
1X1
011
000
248 0 require Lingy::ClojureREPL;
249 0 Lingy::ClojureREPL->rep($input);
250 }
251 }
252 0 print "\n";
253 }
254  
255  
256 #------------------------------------------------------------------------------
257  
258 sub all_ns {
259 list([
260 0 ▶ map { $namespaces{$_} }
Subroutine all_ns: not called CC=1 SCAR=6.9
Pod undocumented
261 sort CORE::keys %namespaces
262 ]);
263 }
264  
265 sub apply {
266 8187 ▶ my ($fn, $args) = @_;
Subroutine apply: called CC=3 SCAR=11.0
Pod undocumented
267 8187 my $seq = pop(@$args);
268 8187 ▶ $seq = list([]) if ref($seq) eq NIL;
Branch: 1 branch
BranchTrueFalseTotal
if ref $seq eq "Lingy::Nil" 2 8185 8187
269 8187 push @$args, @$seq;
270 8187 ▶ ref($fn) eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $fn eq 'CODE' ? : 8021 166 8187
271 ? $fn->(@$args)
272 : evaluate($fn->(@$args));
273 }
274  
275 sub applyTo {
276 0 ▶ my ($obj, $meth, $args) = @_;
Subroutine applyTo: not called CC=1 SCAR=6.9
Pod undocumented
277 0 $meth = "$meth";
278 0 my @args = map unbox_val(evaluate($_, ENV())), @$args;
279 0 box_val $obj->$meth(@args);
280 }
281  
282 sub assoc {
283 16 ▶ my ($map, $key, $val) = @_;
Subroutine assoc: called CC=1 SCAR=0.0
Pod undocumented
284 16 $map->assoc($key, $val);
285 }
286  
287 9 ▶sub atom { ATOM->new($_[0]) }
Subroutine atom: called CC=1 SCAR=0.0
Pod undocumented
288  
289 sub booleanCast {
290 5 ▶ my ($val) = @_;
Subroutine booleanCast: called CC=4 SCAR=13.9
Pod undocumented
291 5 my $type = ref($val);
292 5 ▶ $type eq NIL ? false :
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'Lingy::Nil' ? : 1 4 5
$type eq 'Lingy::Boolean' && $$val == 0 ? : 2 2 4
Condition100%3/3
$type eq "Lingy::Boolean" and $$val == 0
!ll&&!rl&&r
112
MC/DC100%2/2
$type eq "Lingy::Boolean" and $$val == 0
$type eq "Lingy::Boolean" $$val == 0
Truth table100%3/3
A and B
A= $type eq "Lingy::Boolean"B= $$val == 0
ABresult
0X0
100
111
293 ($type eq BOOLEAN and $$val == 0) ? false :
294 true;
295 }
296  
297 sub charCast {
298 2 ▶ my ($char) = @_;
Subroutine charCast: called CC=3 SCAR=12.0
Pod undocumented
299 2 my $type = ref($char);
300 2 ▶ err "Class '$type' cannot be cast to 'lingy.lang.Character'"
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "Lingy::Symbol" or $type eq "Lingy::Number" 0 2 2
Condition33%1/3
$type eq "Lingy::Symbol" or $type eq "Lingy::Number"
l!l&&r!l&&!r
020
MC/DC0%0/2
$type eq "Lingy::Symbol" or $type eq "Lingy::Number"
$type eq "Lingy::Symbol" $type eq "Lingy::Number"
Truth table33%1/3
A or B
A= $type eq "Lingy::Symbol"B= $type eq "Lingy::Number"
ABresult
1X1
011
000
301 unless $type eq SYMBOL or $type eq NUMBER;
302 2 return CHARACTER->read($char);
303 }
304  
305 8235 ▶sub concat { list([map @$_, @_]) }
Subroutine concat: called CC=1 SCAR=0.0
Pod undocumented
306  
307 sub conj {
308 29 ▶ my ($o, @args) = @_;
Subroutine conj: called CC=5 SCAR=17.1
Pod undocumented
309 29 my $type = ref($o);
310 29 ▶ $type eq LIST ? list([reverse(@args), @$o]) :
Branch: 4 branches
BranchTrueFalseTotal
$type eq 'Lingy::List' ? : 5 24 29
$type eq 'Lingy::Vector' ? : 21 3 24
$type eq 'Lingy::HashMap' ? : 3 0 3
$type eq 'Lingy::Nil' ? : 0 0 0
311 $type eq VECTOR ? VECTOR->new([@$o, @args]) :
312 $type eq HASHMAP ? HASHMAP->new([%$o, map %$_, @args]) :
313 $type eq NIL ? nil :
314 err("conj first arg type '$type' not allowed");
315 }
316  
317 36767 ▶sub cons { list([$_[0], @{$_[1]}]) }
Subroutine cons: called CC=1 SCAR=0.0
Pod undocumented
318  
319 sub contains {
320 22 ▶ my ($map, $key) = @_;
Subroutine contains: called CC=4 SCAR=13.9
Pod undocumented
321 22 ▶ return false unless ref($map) eq HASHMAP;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $map eq "Lingy::HashMap" 0 22 22
322 22 ▶ $key =
Branch: 2 branches
BranchTrueFalseTotal
$key->isa('Lingy::String') ? : 3 19 22
$key->isa('Lingy::Symbol') ? : 16 3 19
323 $key->isa(STRING) ? qq<"$key> :
324 $key->isa(SYMBOL) ? qq<$key > :
325 "$key";
326 22 BOOLEAN->new(exists $map->{"$key"});
327 }
328  
329 sub count {
330 692 ▶ NUMBER->new(ref($_[0]) eq NIL ? 0 : scalar @{$_[0]});
Subroutine count: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'Lingy::Nil' ? : 1 691 692
331 }
332  
333 sub create_ns {
334 1 ▶ my ($name) = @_;
Subroutine create_ns: called CC=2 SCAR=7.1
Pod undocumented
335 1 ▶ err "Invalid ns name '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^\w+(\.\w+)*$/ 0 1 1
336 unless $name =~ /^\w+(\.\w+)*$/;
337 1 NAMESPACE->new($name)->refer(symbol($core_ns->_name));
338 }
339  
340 9 ▶sub deref { $_[0]->[0] }
Subroutine deref: called CC=1 SCAR=0.0
Pod undocumented
341  
342 sub dissoc {
343 5 ▶ my ($map, @keys) = @_;
Subroutine dissoc: called CC=3 SCAR=11.0
Pod undocumented
344 @keys = map {
345 5 ▶ $_->isa(STRING) ? qq<"$_> : "$_";
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('Lingy::String') ? : 6 2 8
346 } @keys;
347 5 $map = { %$map };
348 5 delete $map->{$_} for @keys;
349 5 HASHMAP->new([%$map]);
350 }
351  
352 sub eval_perl {
353 0 ▶ my ($perl) = @_;
Subroutine eval_perl: not called CC=2 SCAR=17.9
Pod undocumented
354 0 my $ret = eval "$perl";
355 0 ▶ err("$@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
356 0 return $ret;
357 }
358  
359 sub find_ns {
360 8 ▶ assert_args(\@_, SYMBOL);
Subroutine find_ns: called CC=2 SCAR=7.1
Pod undocumented
361 7 ▶ $namespaces{$_[0]} // nil;
Condition66%2/3
$namespaces{$_[0]} // nil()
l!l&&r!l&&!r
520
MC/DC0%0/2
$namespaces{$_[0]} // nil()
$namespaces{$_[0]} nil()
Truth table66%2/3
A // B
A= $namespaces{$_[0]}B= nil()
ABresult
1X1
011
000
362 }
363  
364 sub first {
365 ref($_[0]) eq NIL
366 255 ▶ ? nil : @{$_[0]} ? $_[0]->[0] : nil;
Subroutine first: called CC=3 SCAR=11.0
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
ref $_[0] eq 'Lingy::Nil' ? : 1 254 255
@{$_[0];} ? : 252 2 254
367 }
368  
369 sub get {
370 42 ▶ my ($map, $key, $default) = @_;
Subroutine get: called CC=6 SCAR=17.9
Pod undocumented
371 42 ▶ return nil unless ref($map) eq HASHMAP or ref($map) eq HASHSET;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $map eq "Lingy::HashMap" or ref $map eq "Lingy::HashSet" 1 41 42
Condition100%3/3
ref $map eq "Lingy::HashMap" or ref $map eq "Lingy::HashSet"
l!l&&r!l&&!r
3651
MC/DC100%2/2
ref $map eq "Lingy::HashMap" or ref $map eq "Lingy::HashSet"
ref $map eq "Lingy::HashMap" ref $map eq "Lingy::HashSet"
Truth table100%3/3
A or B
A= ref $map eq "Lingy::HashMap"B= ref $map eq "Lingy::HashSet"
ABresult
1X1
011
000
372 41 ▶ $key = qq<"$key> if $key->isa(STRING);
Branch: 1 branch
BranchTrueFalseTotal
if $key->isa("Lingy::String") 8 33 41
373 41 ▶ $map->{"$key"} // $default // nil;
Condition83%5/6
($$map{"$key"} // $default) // nil()
l!l&&r!l&&!r
3290
$$map{"$key"} // $default
l!l&&r!l&&!r
2849
MC/DC0%0/3
($$map{"$key"} // $default) // nil()
$$map{"$key"} $default nil()
Truth table75%3/4
A // B // C
A= $$map{"$key"}B= $defaultC= nil()
ABCresult
1XX1
01X1
0011
0000
374 }
375  
376 sub getenv {
377 0 ▶ my $val = $ENV{$_[0]};
Subroutine getenv: not called CC=2 SCAR=17.9
Pod undocumented
378 0 ▶ defined($val) ? string($val) : nil;
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
379 }
380  
381 9 ▶sub hash_map { HASHMAP->new([@_]) }
Subroutine hash_map: called CC=1 SCAR=0.0
Pod undocumented
382  
383 1 ▶sub hash_set { HASHSET->new([@_]) }
Subroutine hash_set: called CC=1 SCAR=0.0
Pod undocumented
384  
385 sub in_ns {
386 2 ▶ my ($name) = @_;
Subroutine in_ns: called CC=3 SCAR=11.3
Pod undocumented
387 2 ▶ err "Invalid ns name '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^\w+(\.\w+)*$/ 0 2 2
388 unless $name =~ /^\w+(\.\w+)*$/;
389 2 ▶ my $ns = $namespaces{$name} // NAMESPACE->new($name);
Condition66%2/3
$namespaces{$name} // "Lingy::Namespace"->new($name)
l!l&&r!l&&!r
110
MC/DC0%0/2
$namespaces{$name} // "Lingy::Namespace"->new($name)
$namespaces{$name} "Lingy::Namespace"->new($name)
Truth table66%2/3
A // B
A= $namespaces{$name}B= "Lingy::Namespace"->new($name)
ABresult
1X1
011
000
390 2 $ns->current;
391 }
392  
393 sub keys {
394 list([
395 map {
396 13 ▶ s/^"// ? string($_) :
Branch: 3 branches
BranchTrueFalseTotal
s/^"// ? : 11 2 13
s/^:// ? : 2 0 2
s/ $// ? : 0 0 0
397 s/^:// ? KEYWORD->new($_) :
398 s/ $// ? symbol($_) :
399 symbol("$_");
400 9 ▶ } CORE::keys %{$_[0]}
Subroutine keys: called CC=4 SCAR=13.9
Pod undocumented
401 ]);
402 }
403  
404 5 ▶sub keyword { KEYWORD->new($_[0]) }
Subroutine keyword: called CC=1 SCAR=0.0
Pod undocumented
405  
406 359 ▶sub list_ { list([@_]) }
Subroutine list_: called CC=1 SCAR=0.0
Pod undocumented
407  
408 sub macroexpand {
409 18 ▶ Lingy::Evaluator::macroexpand($_[0], $Lingy::Evaluator::ENV);
Subroutine macroexpand: called CC=1 SCAR=0.0
Pod undocumented
410 }
411  
412 sub map {
413 list([
414 15 ▶ map apply($_[0], [$_, []]), @{$_[1]}
Subroutine map: called CC=1 SCAR=0.0
Pod undocumented
415 ]);
416 }
417  
418 sub meta_get {
419 45 ▶ $meta{"$_[0]"} // nil;
Subroutine meta_get: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$meta{"$_[0]"} // nil()
l!l&&r!l&&!r
31140
MC/DC0%0/2
$meta{"$_[0]"} // nil()
$meta{"$_[0]"} nil()
Truth table66%2/3
A // B
A= $meta{"$_[0]"}B= nil()
ABresult
1X1
011
000
420 }
421  
422 sub more {
423 460 ▶ my ($list) = @_;
Subroutine more: called CC=3 SCAR=11.0
Pod undocumented
424 460 ▶ return list([]) if $list->isa(NIL) or not @$list;
Branch: 1 branch
BranchTrueFalseTotal
if $list->isa("Lingy::Nil") or not @$list 3 457 460
Condition100%3/3
$list->isa("Lingy::Nil") or not @$list
l!l&&r!l&&!r
12457
MC/DC100%2/2
$list->isa("Lingy::Nil") or not @$list
$list->isa("Lingy::Nil") not @$list
Truth table100%3/3
A or not(B)
A= $list->isa("Lingy::Nil")B= not @$list
ABresult
1X1
011
000
425 457 list([@{$list}[1..(@$list-1)]]);
426 }
427  
428 sub name {
429 2 ▶ string($_[0] =~ m{(.*?)/(.*)} ? $2 : "$_[0]");
Subroutine name: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[(.*?)/(.*)] ? : 1 1 2
430 }
431  
432 sub namespace {
433 2 ▶ $_[0] =~ m{(.*?)/(.*)} ? string($1) : nil;
Subroutine namespace: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ m[(.*?)/(.*)] ? : 1 1 2
434 }
435  
436 60 my $nextID = 1000;
437 sub nextID {
438 709 ▶ return $nextID = $_[1] if @_ == 2;
Subroutine nextID: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 345 364 709
439 364 string(++$nextID);
440 }
441  
442 sub ns {
443 14 ▶ my ($name, $args) = @_;
Subroutine ns: called CC=10 SCAR=37.5
Pod undocumented
444 14 ▶ err "Invalid ns name '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^\w+(?:\.\w+)*$/ 0 14 14
445 unless $name =~ /^\w+(?:\.\w+)*$/;
446  
447 14 my $ns;
448 14 ▶ $ns = $namespaces{$name} //
Condition66%2/3
$namespaces{$name} // "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
l!l&&r!l&&!r
1130
MC/DC0%0/2
$namespaces{$name} // "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
$namespaces{$name} "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
Truth table66%2/3
A // B
A= $namespaces{$name}B= "Lingy::Namespace"->new($name)->refer(symbol($core_ns->_name))
ABresult
1X1
011
000
449 NAMESPACE->new($name)->refer(symbol($core_ns->_name));
450 14 $ns->current;
451  
452 14 for my $arg (@$args) {
453 0 ▶ err "Invalid ns arg" unless
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->isa("Lingy::List") and @$arg >= 2 and ref $arg->[0] eq "Lingy::Keyword" 0 0 0
Condition0%0/6
$arg->isa("Lingy::List") and @$arg >= 2 and ref $arg->[0] eq "Lingy::Keyword"
!ll&&!rl&&r
000
$arg->isa("Lingy::List") and @$arg >= 2
!ll&&!rl&&r
000
MC/DC0%0/3
$arg->isa("Lingy::List") and @$arg >= 2 and ref $arg->[0] eq "Lingy::Keyword"
$arg->isa("Lingy::List") @$arg >= 2 ref $arg->[0] eq "Lingy::Keyword"
Truth table0%0/4
A and B and C
A= $arg->isa("Lingy::List")B= @$arg >= 2C= ref $arg->[0] eq "Lingy::Keyword"
ABCresult
0XX0
10X0
1100
1111
454 $arg->isa(LIST) and
455 @$arg >= 2 and
456 ref($arg->[0]) eq KEYWORD;
457  
458 0 my ($keyword, @args) = @$arg;
459 0 ▶ if ($$keyword eq ':use') {
Branch: 2 branches
BranchTrueFalseTotal
if ($$keyword eq ':use') { } 0 0 0
elsif ($$keyword eq ':import') { } 0 0 0
460 0 for my $spec (@args) {
461 0 evaluate(
462 list([
463 symbol('use'),
464 list([symbol('quote'), $spec]),
465 ]),
466 $Lingy::Evaluator::ENV,
467 );
468 }
469 }
470 elsif ($$keyword eq ':import') {
471 0 my (undef, @args) = @$arg;
472 0 evaluate(
473 list([ symbol('import'), @args ]),
474 $Lingy::Evaluator::ENV,
475 );
476 }
477 else {
478 0 err "Invalid keyword arg '$keyword' in ns";
479 }
480 }
481  
482 14 nil;
483 }
484  
485 234 ▶sub nth { $_[0][$_[1]] }
Subroutine nth: called CC=1 SCAR=0.0
Pod undocumented
486  
487 4 ▶sub number { NUMBER->new("$_[0]" + 0) }
Subroutine number: called CC=1 SCAR=0.0
Pod undocumented
488  
489 0 ▶sub pos_Q { $_[0] > 0 ? true : false }
Subroutine pos_Q: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > 0 ? : 0 0 0
490  
491 sub pr_str {
492 14 ▶ string(join ' ', map $printer->pr_str($_), @_);
Subroutine pr_str: called CC=1 SCAR=0.0
Pod undocumented
493 }
494  
495 sub println {
496 65 ▶ printf "%s\n", join ' ',
Subroutine println: called CC=1 SCAR=0.0
Pod undocumented
497 map $printer->pr_str($_, 1), @_;
498 65 nil;
499 }
500  
501 sub prn {
502 41 ▶ printf "%s\n", join ' ',
Subroutine prn: called CC=1 SCAR=0.0
Pod undocumented
503 map $printer->pr_str($_), @_;
504 41 nil;
505 }
506  
507 sub readString {
508 46 ▶ my @forms = Lingy::Reader->new->read_str($_[0]);
Subroutine readString: called CC=2 SCAR=6.9
Pod undocumented
509 46 ▶ return @forms ? $forms[0] : nil;
Branch: 1 branch
BranchTrueFalseTotal
@forms ? : 45 1 46
510 }
511  
512 sub readline {
513 0 ▶ my $l = RL->readline // return;
Subroutine readline: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
bless( {}, 'Lingy::ReadLine' )->readline // (return)
l!l
00
MC/DC0%0/1
bless( {}, 'Lingy::ReadLine' )->readline // (return)
bless( {}, 'Lingy::ReadLine' )->readline
Truth table0%0/2
A
A= bless( {}, 'Lingy::ReadLine' )->readline
Aresult
11
00
514 0 chomp $l;
515 0 string($l);
516 }
517  
518 60 our $require_ext = 'ly';
519 sub require {
520 outer:
521 12 ▶ for my $spec (@_) {
Subroutine require: called CC=6 SCAR=17.9
Pod undocumented
522 12 ▶ err "'require' only works with symbols"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "Lingy::Symbol" 0 12 12
523 unless ref($spec) eq SYMBOL;
524  
525 12 ▶ next if $namespaces{$$spec};
Branch: 1 branch
BranchTrueFalseTotal
if $namespaces{$$spec} 1 11 12
526  
527 11 my $name = $$spec;
528  
529 11 my $path = $name;
530 11 $path =~ s/^lingy\.lang\./Lingy./;
531 11 $path =~ s/^lingy\./Lingy\./;
532 11 my $module = $path;
533 11 $path =~ s/\./\//g;
534  
535 11 for my $inc (@INC) {
536 25 $inc =~ s{^([^/.])}{./$1};
537 25 my $inc_path = "$inc/$path";
538 25 ▶ if (-f "$inc_path.$require_ext") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$inc_path.$Lingy::RT::require_ext") 10 15 25
539 10 my $ns = $namespaces{$current_ns_name};
540 10 RT->rep(qq< (load-file "$inc_path.$require_ext") >);
541 10 $ns->current;
542 10 next outer;
543 }
544 }
545  
546 1 err "Can't find library for (require '$name)";
547 }
548 11 return nil;
549 }
550  
551 1 ▶sub reset_BANG { $_[0]->[0] = $_[1] }
Subroutine reset_BANG: called CC=1 SCAR=0.0
Pod undocumented
552  
553 sub resolve {
554 10 ▶ my ($symbol) = @_;
Subroutine resolve: called CC=4 SCAR=13.9
Pod undocumented
555 10 my ($ns_name, $sym_name, $var);
556 10 ▶ if ($symbol =~ /(.*?)\/(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[(.*?)/(.*)]) { } 4 6 10
557 4 ($ns_name, $sym_name) = ($1, $2);
558 }
559 else {
560 6 $ns_name = $current_ns_name;
561 6 $sym_name = $symbol;
562 }
563  
564 10 ▶ my $ns = $namespaces{$ns_name} or return nil;
Branch: 1 branch
BranchTrueFalseTotal
my $ns = $namespaces{$ns_name} or return nil() 2 8 10
565 8 ▶ if (exists $ns->{$sym_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ns->{$sym_name}) { } 4 4 8
566 4 $var = $ns_name . '/' . $sym_name;
567 } else {
568 4 return nil;
569 }
570 4 return VAR->new($var);
571 }
572  
573 sub seq {
574 54 ▶ my ($o) = @_;
Subroutine seq: called CC=2 SCAR=6.9
Pod undocumented
575 54 ▶ $o->can('_to_seq') or
Branch: 1 branch
BranchTrueFalseTotal
$o->can("_to_seq") or err(sprintf("Don't know how to create ISeq from: %s", $o->NAME)) 3 51 54
576 err(sprintf "Don't know how to create ISeq from: %s", $o->NAME); # XXX NAME is Class name not namespace
577 51 $o->_to_seq;
578 }
579  
580 26 ▶sub slurp { string(RT->slurp_file($_[0])) }
Subroutine slurp: called CC=1 SCAR=0.0
Pod undocumented
581  
582 sub sort {
583 list([
584 0 ▶ CORE::sort @{$_[0]}
Subroutine sort: not called CC=1 SCAR=6.9
Pod undocumented
585 ]);
586 }
587  
588 sub str {
589 string(
590 join '',
591 map $printer->pr_str($_, 1),
592 73 ▶ grep {ref($_) ne NIL}
Subroutine str: called CC=1 SCAR=0.0
Pod undocumented
593 @_
594 );
595 }
596  
597 sub swap_BANG {
598 10 ▶ my ($atom, $fn, $args) = @_;
Subroutine swap_BANG: called CC=1 SCAR=0.0
Pod undocumented
599 10 $atom->[0] = apply($fn, [[$atom->[0], @$args]]);
600 }
601  
602 5 ▶sub symbol_ { symbol("$_[0]") }
Subroutine symbol_: called CC=1 SCAR=0.0
Pod undocumented
603  
604 sub the_ns {
605 $_[0]->isa(NAMESPACE) ? $_[0] :
606 15 ▶ $_[0]->isa(SYMBOL) ? do {
Subroutine the_ns: called CC=4 SCAR=14.3
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->isa('Lingy::Namespace') ? : 8 7 15
$_[0]->isa('Lingy::Symbol') ? : 7 0 7
607 7 ▶ $namespaces{$_[0]} //
Condition66%2/3
$namespaces{$_[0]} // err("No namespace: '$_[0]' found")
l!l&&r!l&&!r
601
MC/DC0%0/2
$namespaces{$_[0]} // err("No namespace: '$_[0]' found")
$namespaces{$_[0]} err("No namespace: '$_[0]' found")
Truth table33%1/3
A // B
A= $namespaces{$_[0]}B= err("No namespace: '$_[0]' found")
ABresult
1X1
011
000
608 err "No namespace: '$_[0]' found";
609 } : err "Invalid argument for the-ns: '$_[0]'";
610 }
611  
612 sub time_ms {
613 2 ▶ require Time::HiRes;
Subroutine time_ms: called CC=1 SCAR=0.0
Pod undocumented
614 2 my ($s, $m) = Time::HiRes::gettimeofday();
615 2 NUMBER->new($s * 1000 + $m / 1000);
616 }
617  
618 sub type {
619 24 ▶ CLASS->_new(ref($_[0]));
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
620 }
621  
622 sub with_meta {
623 30 ▶ my ($o, $m) = @_;
Subroutine with_meta: called CC=2 SCAR=7.4
Pod undocumented
624 30 ▶ $o = ref($o) eq 'CODE' ? sub { goto &$o } : $o->clone;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
ref $o eq 'CODE' ? : 0 30 30
625 30 $meta{$o} = $m;
626 30 $o;
627 }
628  
629 5 ▶sub vals { list([ values %{$_[0]} ]) }
Subroutine vals: called CC=1 SCAR=0.0
Pod undocumented
630  
631 0 ▶sub var_ { VAR->new($_[0]) }
Subroutine var_: not called CC=1 SCAR=6.9
Pod undocumented
632  
633 419 ▶sub vec { VECTOR->new([@{$_[0]}]) }
Subroutine vec: called CC=1 SCAR=0.0
Pod undocumented
634  
635 3 ▶sub vector { VECTOR->new([@_]) }
Subroutine vector: called CC=1 SCAR=0.0
Pod undocumented
636  
637 60 1;
« blib/lib/Lingy/Numbers.pm ↑ Summary lib/Lingy/Reader.pm »