| 1 | 53 | ▶ | use strict; use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | package Lingy::Fn; | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 53 | ▶ | use base 'Lingy::Class'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 53 | ▶ | use Lingy::Common; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 53 | ▶ | use Sub::Name 'subname'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 53 | *list = \&Lingy::Common::list; | |||||||||||||
| 11 | 53 | *symbol = \&Lingy::Common::symbol; | |||||||||||||
| 12 | sub err; | ||||||||||||||
| 13 | 53 | *err = \&Lingy::Common::err; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 7925 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||
| 16 | 7925 | my ($class, $ast, $env) = @_; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 7925 | my (undef, @exprs) = @$ast; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 7925 | my $name = \'AFn'; | |||||||||||||
| 21 | 7925 | ▶ | $name = shift @exprs if ref($exprs[0]) eq SYMBOL; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | 7925 | ▶ | shift @exprs if ref($exprs[0]) eq STRING; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 7925 | ▶ | shift @exprs if ref($exprs[0]) eq HASHMAP; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | 7925 | ▶ | @exprs = (list([@exprs])) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | if ref($exprs[0]) eq VECTOR; | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 7925 | my $functions = []; | |||||||||||||
| 30 | 7925 | my $variadic = ''; | |||||||||||||
| 31 | |||||||||||||||
| 32 | 7925 | for my $expr (@exprs) { | |||||||||||||
| 33 | 9935 | ▶ | err "fn expr is not a list" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | unless ref($expr) eq LIST; | ||||||||||||||
| 35 | 9935 | my ($sig, @body) = @$expr; | |||||||||||||
| 36 | 9935 | ▶ | err "fn signature not a vector" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | unless ref($sig) eq VECTOR; | ||||||||||||||
| 38 | 9934 | ▶ | my $arity = (grep {$$_ eq '&'} @$sig) ? -1 : @$sig; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 9934 | ▶ | if ($arity == -1) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 40 | 2741 | $variadic = @$sig - 1; | |||||||||||||
| 41 | } elsif ($variadic) { | ||||||||||||||
| 42 | 1 | ▶ | err "Can't have fixed arity function " . | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | "with more params than variadic function" | ||||||||||||||
| 44 | if @$sig > $variadic; | ||||||||||||||
| 45 | } | ||||||||||||||
| 46 | 9933 | ▶ | @body = (list([ symbol('do'), @body ])) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | if @body > 1; | ||||||||||||||
| 48 | 9933 | ▶ | if (exists $functions->[$arity+1]) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 2 | ▶ | err $arity == -1 | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | ? "Can't have more than 1 variadic overload" | ||||||||||||||
| 51 | : "Can't have 2 overloads with same arity"; | ||||||||||||||
| 52 | } | ||||||||||||||
| 53 | 9931 | $functions->[$arity+1] = [$sig, @body]; | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 99897 | ▶ | subname $name => bless sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||
| 57 | 99897 | my $arity = @_; | |||||||||||||
| 58 | 99897 | ▶ | my $function = | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 59 | $functions->[$arity+1] ? $functions->[$arity+1] : | ||||||||||||||
| 60 | $arity >= (@$functions-1) ? $functions->[0] : undef; | ||||||||||||||
| 61 | 99897 | ▶ | err "Wrong number of args ($arity) passed to function" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | unless defined $function; | ||||||||||||||
| 63 | 99892 | my ($sig, $ast) = @$function; | |||||||||||||
| 64 | |||||||||||||||
| 65 | return ( | ||||||||||||||
| 66 | 99892 | $ast, | |||||||||||||
| 67 | Lingy::Env->new( | ||||||||||||||
| 68 | outer => $env, | ||||||||||||||
| 69 | binds => $sig, | ||||||||||||||
| 70 | exprs => \@_, | ||||||||||||||
| 71 | ), | ||||||||||||||
| 72 | ); | ||||||||||||||
| 73 | 7921 | }, $class; | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 13 | ▶ | sub clone { | ||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 77 | 13 | my ($fn) = @_; | |||||||||||||
| 78 | 13 | ▶ | bless sub { goto &$fn }, ref($fn); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 0 | ▶ | sub unbox { $_[0] } | ||||||||||||
|
Subroutine
unbox: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 82 | |||||||||||||||
| 83 | 53 | 1; | |||||||||||||