updating copyright
[language-befunge.git] / lib / Language / Befunge / lib / REFC.pm
blob02277f3cc4412fecb89705733ee761439dc5cd29
2 # This file is part of Language::Befunge.
3 # Copyright (c) 2001-2009 Jerome Quelin, all rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
10 package Language::Befunge::lib::REFC;
12 use strict;
13 use warnings;
15 use Language::Befunge::Vector;
17 sub new { return bless {}, shift; }
19 my @vectors;
23 # $id = R( $x, $y )
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.
29 sub R {
30 my ($self, $lbi) = @_;
31 my $ip = $lbi->get_curip;
32 my $v = $ip->spop_vec;
33 push @vectors, $v;
34 $ip->spush( $#vectors );
39 # ($x, $y) = D( $id )
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.
44 sub D {
45 my ($self, $lbi) = @_;
46 my $ip = $lbi->get_curip;
47 my $id = $ip->spop;
48 my $v = $vectors[$id];
49 $ip->spush( $v->get_component(0), $v->get_component(1) );
55 __END__
58 =head1 NAME
60 Language::Befunge::IP::lib::REFC - Referenced cells extension
64 =head1 DESCRIPTION
67 The REFC fingerprint (0x52454643) allows vectors to be encoded into and
68 decoded from single scalar cell values.
70 Note that the internal list of references is considered shared among all
71 IP's.
75 =head1 FUNCTIONS
77 =head2 new
79 Create a new REFC instance.
82 =head2 De/Referencing
84 =over 4
86 =item $id = R( $x, $y )
88 C<Reference> pops a vector off the stack, and pushes a scalar value back onto
89 the stack, unique within an internal list of references, which refers to that
90 vector.
93 =item ($x, $y) = D( $id )
95 C<Dereference> pops a scalar value off the stack, and pushes the vector back
96 onto the stack which corresponds to that unique reference value.
99 =back
103 =head1 SEE ALSO
105 L<Language::Befunge>, L<http://catseye.tc/projects/funge98/library/REFC.html>.
109 =head1 AUTHOR
111 Jerome Quelin, C<< <jquelin@cpan.org> >>
114 =head1 COPYRIGHT & LICENSE
116 Copyright (c) 2001-2009 Jerome Quelin, all rights reserved.
118 This program is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.
122 =cut