File Coverage

blib/lib/Language/Befunge/lib/REFC.pm
Criterion Covered Total %
statement 9 20 45.0
branch n/a
condition n/a
subroutine 3 6 50.0
pod 3 3 100.0
total 15 29 51.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of Language::Befunge.
3             # Copyright (c) 2001-2009 Jerome Quelin, all rights reserved.
4             #
5             # This program is free software; you can redistribute it and/or modify
6             # it under the same terms as Perl itself.
7             #
8             #
9              
10             package Language::Befunge::lib::REFC;
11              
12 1     1   3907 use strict;
  1         2  
  1         43  
13 1     1   5 use warnings;
  1         2  
  1         28  
14              
15 1     1   7 use Language::Befunge::Vector;
  1         1  
  1         13  
16              
17 0     0 1   sub new { return bless {}, shift; }
18              
19             my @vectors;
20              
21              
22             #
23             # $id = R( $x, $y )
24             #
25             # 'Reference' pops a vector off the stack, and pushes a scalar value back onto
26             # the stack, unique within an internal list of references, which refers to that
27             # vector.
28             #
29             sub R {
30 0     0 1   my ($self, $lbi) = @_;
31 0           my $ip = $lbi->get_curip;
32 0           my $v = $ip->spop_vec;
33 0           push @vectors, $v;
34 0           $ip->spush( $#vectors );
35             }
36              
37              
38             #
39             # ($x, $y) = D( $id )
40             #
41             # 'Dereference' pops a scalar value off the stack, and pushes the vector back
42             # onto the stack which corresponds to that unique reference value.
43             #
44             sub D {
45 0     0 1   my ($self, $lbi) = @_;
46 0           my $ip = $lbi->get_curip;
47 0           my $id = $ip->spop;
48 0           my $v = $vectors[$id];
49 0           $ip->spush( $v->get_component(0), $v->get_component(1) );
50             }
51              
52              
53             1;
54              
55             __END__