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::ORTH; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6358
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
13
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
7
|
use Language::Befunge::Vector; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
1
|
|
sub new { return bless {}, shift; } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# -- bit operations |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# $v = A( $a, $b ) |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# push $a & $b back onto the stack (bitwise AND) |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
sub A { |
28
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
29
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# pop the values |
32
|
0
|
|
|
|
|
|
my $b = $ip->spop; |
33
|
0
|
|
|
|
|
|
my $a = $ip->spop; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# push the result |
36
|
0
|
|
|
|
|
|
$ip->spush( $a&$b ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# $v = E( $a, $b ) |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
# push $a ^ $b back onto the stack (bitwise XOR) |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
sub E { |
46
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
47
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip(); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# pop the values |
50
|
0
|
|
|
|
|
|
my $b = $ip->spop; |
51
|
0
|
|
|
|
|
|
my $a = $ip->spop; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# push the result |
54
|
0
|
|
|
|
|
|
$ip->spush( $a^$b ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# $v = O( $a, $b ) |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# push $a | $b back onto the stack (bitwise OR) |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
sub O { |
64
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
65
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip(); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# pop the values |
68
|
0
|
|
|
|
|
|
my $b = $ip->spop; |
69
|
0
|
|
|
|
|
|
my $a = $ip->spop; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# push the result |
72
|
0
|
|
|
|
|
|
$ip->spush( $a|$b ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# -- push / get |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
# $v = G( $y, $x ) |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
# push back value stored at coords ($x, $y). note that befunge get is g($x,$y) |
82
|
|
|
|
|
|
|
# (ie, the arguments are reversed). |
83
|
|
|
|
|
|
|
# |
84
|
|
|
|
|
|
|
sub G { |
85
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
86
|
0
|
|
|
|
|
|
my $ip = $lbi->get_curip; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $x = $ip->spop; |
89
|
0
|
|
|
|
|
|
my $y = $ip->spop; |
90
|
0
|
|
|
|
|
|
my $v = Language::Befunge::Vector->new($x,$y); |
91
|
0
|
|
|
|
|
|
my $val = $lbi->get_storage->get_value( $v ); |
92
|
0
|
|
|
|
|
|
$ip->spush( $val ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
# P( $v, $y, $x ) |
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
# store value $v at coords ($x, $y). note that befunge put is p($v,$x,$y) (ie, |
100
|
|
|
|
|
|
|
# the coordinates are reversed). |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
sub P { |
103
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
104
|
0
|
|
|
|
|
|
my $ip = $lbi->get_curip; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $x = $ip->spop; |
107
|
0
|
|
|
|
|
|
my $y = $ip->spop; |
108
|
0
|
|
|
|
|
|
my $v = Language::Befunge::Vector->new($x,$y); |
109
|
0
|
|
|
|
|
|
my $val = $ip->spop; |
110
|
0
|
|
|
|
|
|
$lbi->get_storage->set_value( $v, $val ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# -- output |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# |
117
|
|
|
|
|
|
|
# S( 0gnirts ) |
118
|
|
|
|
|
|
|
# |
119
|
|
|
|
|
|
|
# print popped 0gnirts on stdout. |
120
|
|
|
|
|
|
|
# |
121
|
|
|
|
|
|
|
sub S { |
122
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
123
|
0
|
|
|
|
|
|
print $lbi->get_curip->spop_gnirts; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# -- coordinates & velocity changes |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# |
130
|
|
|
|
|
|
|
# X( $x ) |
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
# Change X coordinate of IP to $x. |
133
|
|
|
|
|
|
|
# |
134
|
|
|
|
|
|
|
sub X { |
135
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
136
|
0
|
|
|
|
|
|
my $ip = $lbi->get_curip; |
137
|
0
|
|
|
|
|
|
my $v = $ip->get_position; |
138
|
0
|
|
|
|
|
|
my $x = $ip->spop; |
139
|
0
|
|
|
|
|
|
$v->set_component(0,$x); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# |
143
|
|
|
|
|
|
|
# Y( $y ) |
144
|
|
|
|
|
|
|
# |
145
|
|
|
|
|
|
|
# Change Y coordinate of IP to $y. |
146
|
|
|
|
|
|
|
# |
147
|
|
|
|
|
|
|
sub Y { |
148
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
149
|
0
|
|
|
|
|
|
my $ip = $lbi->get_curip; |
150
|
0
|
|
|
|
|
|
my $v = $ip->get_position; |
151
|
0
|
|
|
|
|
|
my $y = $ip->spop; |
152
|
0
|
|
|
|
|
|
$v->set_component(1,$y); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# |
157
|
|
|
|
|
|
|
# V( $dx ) |
158
|
|
|
|
|
|
|
# |
159
|
|
|
|
|
|
|
# Change X coordinate of IP velocity to $dx. |
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
sub V { |
162
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
163
|
0
|
|
|
|
|
|
my $ip = $lbi->get_curip; |
164
|
0
|
|
|
|
|
|
my $v = $ip->get_delta; |
165
|
0
|
|
|
|
|
|
my $dx = $ip->spop; |
166
|
0
|
|
|
|
|
|
$v->set_component(0,$dx); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# |
171
|
|
|
|
|
|
|
# W( $dy ) |
172
|
|
|
|
|
|
|
# |
173
|
|
|
|
|
|
|
# Change Y coordinate of IP velocity to $dy. |
174
|
|
|
|
|
|
|
# |
175
|
|
|
|
|
|
|
sub W { |
176
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
177
|
0
|
|
|
|
|
|
my $ip = $lbi->get_curip; |
178
|
0
|
|
|
|
|
|
my $v = $ip->get_delta; |
179
|
0
|
|
|
|
|
|
my $dy = $ip->spop; |
180
|
0
|
|
|
|
|
|
$v->set_component(1,$dy); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# -- misc |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# |
187
|
|
|
|
|
|
|
# Z( $bool ) |
188
|
|
|
|
|
|
|
# |
189
|
|
|
|
|
|
|
# Test the top stack element, and if zero, skip over the next cell (i.e., add |
190
|
|
|
|
|
|
|
# the delta twice to the current position). |
191
|
|
|
|
|
|
|
# |
192
|
|
|
|
|
|
|
sub Z { |
193
|
0
|
|
|
0
|
1
|
|
my ($self, $lbi) = @_; |
194
|
0
|
|
|
|
|
|
my $ip = $lbi->get_curip; |
195
|
0
|
|
|
|
|
|
my $v = $ip->spop; |
196
|
0
|
0
|
|
|
|
|
$lbi->_move_ip_once($ip) if $v == 0; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
__END__ |