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