File Coverage

blib/lib/Language/P/Toy/Value/Code.pm
Criterion Covered Total %
statement 27 28 96.4
branch 4 4 100.0
condition 3 4 75.0
subroutine 6 7 85.7
pod 1 4 25.0
total 41 47 87.2


line stmt bran cond sub pod time code
1             package Language::P::Toy::Value::Code;
2              
3 100     100   893 use strict;
  100         208  
  100         3446  
4 100     100   586 use warnings;
  100         199  
  100         2801  
5 100     100   549 use base qw(Language::P::Toy::Value::Any);
  100         329  
  100         52067  
6              
7             __PACKAGE__->mk_ro_accessors( qw(bytecode stack_size lexicals outer closed) );
8              
9 0     0 0 0 sub type { 9 }
10 2     2 0 8 sub is_subroutine { 0 }
11              
12             sub new {
13 83     83 1 332 my( $class, $args ) = @_;
14 83         682 my $self = $class->SUPER::new( $args );
15              
16 83   100     1680 $self->{stack_size} ||= 0;
17 83   50     530 $self->{closed} ||= [];
18              
19 83         604 return $self;
20             }
21              
22             sub call {
23 2991     2991 0 4381 my( $self, $runtime, $pc, $context ) = @_;
24 2991         7466 my $frame = $runtime->push_frame( $self->stack_size + 2 );
25              
26 2991         5047 my $stack = $runtime->{_stack};
27 2991 100       8126 if( $self->lexicals ) {
28 15         89 my $pad = $self->lexicals->new_scope( undef );
29 15         34 $stack->[$frame - 1] = $pad;
30             } else {
31 2976         15200 $stack->[$frame - 1] = 'no_pad';
32             }
33 2991 100       7418 if( $self->stack_size ) {
34             # FIXME lexical values initialization
35 2846         15777 foreach my $slot ( 0 .. $self->stack_size ) {
36 8332         80280 $stack->[$frame - 2 - $slot] = Language::P::Toy::Value::StringNumber->new;
37             }
38             }
39 2991         32176 $stack->[$frame - 2] = [ $pc, $runtime->{_bytecode}, $context ];
40              
41 2991         10150 $runtime->set_bytecode( $self->bytecode );
42             }
43              
44             1;