line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lox::Callable; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
4
|
1
|
|
|
1
|
|
3
|
use Lox::Bool; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
120
|
|
5
|
|
|
|
|
|
|
use overload |
6
|
0
|
|
|
0
|
|
0
|
'""' => sub { '' }, |
7
|
0
|
|
|
0
|
|
0
|
'!' => sub { $False }, |
8
|
0
|
|
|
0
|
|
0
|
'bool' => sub { $True }, # only false and nil are untrue in Lox |
9
|
1
|
|
|
1
|
|
6
|
fallback => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.02; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
0
|
3
|
my ($class, $args) = @_; |
15
|
1
|
|
|
|
|
6
|
return bless { %$args }, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
0
|
|
sub arity { $_[0]->{arity} } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub call { |
21
|
0
|
|
|
0
|
0
|
|
my ($self, $interpreter, @args) = @_; |
22
|
0
|
|
|
0
|
|
|
my $sub = sub { $self->{call}->($interpreter, @args) }; |
|
0
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return $self->call_catch_return($interpreter, $sub); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub call_catch_return { |
27
|
0
|
|
|
0
|
0
|
|
my ($self, $interpreter, $sub) = @_; |
28
|
0
|
|
|
|
|
|
my $retval = eval { $sub->() }; |
|
0
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if ($@) { |
30
|
0
|
0
|
|
|
|
|
if ($@ =~ /^return/) { |
31
|
0
|
|
|
|
|
|
return delete $interpreter->{returning}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
|
die $@; # we don't handle this exception |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
return $retval; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |