new extension ORTH
[language-befunge.git] / lib / Language / Befunge / lib / ORTH.pm
blobd777b051d64bab57f891dfebd06e6687740aa759
2 # This file is part of Language::Befunge.
3 # Copyright (c) 2001-2008 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::ORTH;
12 use strict;
13 use warnings;
15 use Language::Befunge::Vector;
17 sub new { return bless {}, shift; }
19 # -- bit operations
21 sub A {
22 my ($self, $interp) = @_;
23 my $ip = $interp->get_curip();
25 # pop the values
26 my $b = $ip->spop;
27 my $a = $ip->spop;
29 # push the result
30 $ip->spush( $a&$b );
33 sub E {
34 my ($self, $interp) = @_;
35 my $ip = $interp->get_curip();
37 # pop the values
38 my $b = $ip->spop;
39 my $a = $ip->spop;
41 # push the result
42 $ip->spush( $a^$b );
45 sub O {
46 my ($self, $interp) = @_;
47 my $ip = $interp->get_curip();
49 # pop the values
50 my $b = $ip->spop;
51 my $a = $ip->spop;
53 # push the result
54 $ip->spush( $a|$b );
58 # -- push / get
60 sub G {
61 my ($self, $lbi) = @_;
62 my $ip = $lbi->get_curip;
64 my $x = $ip->spop;
65 my $y = $ip->spop;
66 my $v = Language::Befunge::Vector->new($x,$y);
67 my $val = $lbi->storage->get_value( $v );
68 $ip->spush( $val );
71 sub P {
72 my ($self, $lbi) = @_;
73 my $ip = $lbi->get_curip;
75 my $x = $ip->spop;
76 my $y = $ip->spop;
77 my $v = Language::Befunge::Vector->new($x,$y);
78 my $val = $ip->spop;
79 $lbi->storage->set_value( $v, $val );
83 # -- output
85 sub S {
86 my ($self, $lbi) = @_;
87 print $lbi->get_curip->spop_gnirts;
91 # -- coordinates & velocity changes
93 sub X {
94 my ($self, $lbi) = @_;
95 my $ip = $lbi->get_curip;
96 my $v = $ip->get_position;
97 my $x = $ip->spop;
98 $v->set_component(0,$x);
101 sub Y {
102 my ($self, $lbi) = @_;
103 my $ip = $lbi->get_curip;
104 my $v = $ip->get_position;
105 my $y = $ip->spop;
106 $v->set_component(1,$y);
109 sub V {
110 my ($self, $lbi) = @_;
111 my $ip = $lbi->get_curip;
112 my $v = $ip->get_delta;
113 my $dx = $ip->spop;
114 $v->set_component(0,$dx);
117 sub W {
118 my ($self, $lbi) = @_;
119 my $ip = $lbi->get_curip;
120 my $v = $ip->get_delta;
121 my $dy = $ip->spop;
122 $v->set_component(1,$dy);
126 # -- misc
128 sub Z {
129 my ($self, $lbi) = @_;
130 my $ip = $lbi->get_curip;
131 my $v = $ip->spop;
132 $lbi->_move_ip_once($ip) if $v == 0;
138 __END__
141 =head1 NAME
143 Language::Befunge::IP::lib::ORTH - Orthogonal Easement Library
147 =head1 DESCRIPTION
149 The ORTH fingerprint (0x4f525448) is designed to ease transition between the
150 Orthogonal programming language and Befunge-98 (or higher dimension Funges).
152 Even if transition from Orthogonal is not an issue, the ORTH library contains
153 some potentially interesting instructions not in standard Funge-98.
157 =head1 FUNCTIONS
159 =head2 new
161 Create a new ORTH instance.
164 =head2 Bit operations
166 =over 4
168 =item A( $a, $b )
170 Push back C<$a & $b> (bitwise AND).
173 =item O( $a, $b )
175 Push back C<$a | $b> (bitwise OR).
178 =item E( $a, $b )
180 Push back C<$a ^ $b> (bitwise XOR).
183 =back
187 =head2 Push & get
189 =over 4
191 =item G( $y, $x )
193 Push back value stored at coords ($x, $y). Note that Befunge get is C<g($x,$y)>
194 (ie, the arguments are reversed).
197 =item P( $v, $y, $x )
199 Store value C<$v> at coords ($x, $y). Note that Befunge put is C<p($v,$x,$y)> (ie,
200 the coordinates are reversed).
203 =back
207 =head2 Output
209 =over 4
211 =item S( 0gnirts )
213 Print popped 0gnirts on STDOUT.
215 =back
219 =head2 Coordinates & velocity changes
221 =over 4
223 =item X( $x )
225 Change X coordinate of IP to C<$x>.
228 =item Y( $y )
230 Change Y coordinate of IP to C<$y>.
233 =item V( $dx )
235 Change X coordinate of IP velocity to C<$dx>.
238 =item W( $dy )
240 Change Y coordinate of IP velocity to C<$dy>.
243 =back
247 =head1 SEE ALSO
249 L<Language::Befunge>, L<http://www.muppetlabs.com/~breadbox/orth/orth.html>
250 and L<http://catseye.tc/projects/funge98/library/ORTH.html>
253 =head1 AUTHOR
255 Jerome Quelin, C<< <jquelin@cpan.org> >>
258 =head1 COPYRIGHT & LICENSE
260 Copyright (c) 2001-2008 Jerome Quelin, all rights reserved.
262 This program is free software; you can redistribute it and/or modify
263 it under the same terms as Perl itself.
266 =cut