line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lox::Instance; |
2
|
1
|
|
|
1
|
|
6
|
use Lox::Bool; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
116
|
|
3
|
|
|
|
|
|
|
use overload ( |
4
|
0
|
|
|
0
|
|
0
|
'""' => sub { $_[0]->klass->name . ' instance' }, |
5
|
0
|
|
|
0
|
|
0
|
'bool' => sub { $True }, |
6
|
0
|
|
|
0
|
|
0
|
'!' => sub { $False }, |
7
|
1
|
|
|
|
|
16
|
fallback => 0, |
8
|
1
|
|
|
1
|
|
5
|
); |
|
1
|
|
|
|
|
2
|
|
9
|
1
|
|
|
1
|
|
85
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
273
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.02; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
0
|
|
my ($class, $args) = @_; |
15
|
0
|
|
|
|
|
|
return bless { %$args }, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
0
|
|
sub fields { $_[0]->{fields} } |
19
|
0
|
|
|
0
|
0
|
|
sub klass { $_[0]->{klass} } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub get { |
22
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
23
|
0
|
0
|
|
|
|
|
if (my $field = $self->fields->{$name->lexeme}) { |
|
|
0
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return $field; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif (my $method = $self->klass->find_method($name->lexeme)) { |
27
|
0
|
|
|
|
|
|
return $method->bind($self); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
Lox::runtime_error($name, sprintf 'Undefined property \'%s\'', $name->lexeme); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub set { |
33
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $value) = @_; |
34
|
0
|
|
|
|
|
|
$self->fields->{$name->lexeme} = $value; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |