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::SUBR; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
4788
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
13
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
14
|
1
|
|
|
1
|
|
12
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use Language::Befunge::Vector; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
|
sub new { return bless {}, shift; } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub A { |
21
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
22
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
23
|
0
|
|
|
|
|
|
$ip->extdata('SUBR', 0); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub C { |
27
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
28
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
29
|
0
|
|
|
|
|
|
my $count = $ip->spop; |
30
|
0
|
|
|
|
|
|
my $to = $ip->spop_vec; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# set new position |
33
|
0
|
|
0
|
|
|
|
my $is_rel = $ip->extdata('SUBR') // 0; |
34
|
0
|
|
|
|
|
|
my $from = $ip->get_position; |
35
|
0
|
0
|
|
|
|
|
$to += $ip->get_storage if $is_rel; |
36
|
0
|
|
|
|
|
|
$ip->set_position($to); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# new delta is (1, 0, ...) |
39
|
0
|
|
|
|
|
|
my $old = $ip->get_delta; |
40
|
0
|
|
|
|
|
|
my $new = Language::Befunge::Vector->new_zeroes( $to->get_dims ); |
41
|
0
|
|
|
|
|
|
$new->set_component(0,1); |
42
|
0
|
|
|
|
|
|
$ip->set_delta($new); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# mess with stack |
45
|
0
|
|
|
|
|
|
my @stack = $ip->spop_mult($count); |
46
|
0
|
|
|
|
|
|
$ip->spush_vec( $from ); |
47
|
0
|
|
|
|
|
|
$ip->spush_vec( $old ); |
48
|
0
|
|
|
|
|
|
$ip->spush_args( @stack ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub J { |
52
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
53
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# compute where to jump |
56
|
0
|
|
0
|
|
|
|
my $is_rel = $ip->extdata('SUBR') // 0; |
57
|
0
|
|
|
|
|
|
my $vec = $ip->spop_vec; |
58
|
0
|
0
|
|
|
|
|
$vec += $ip->get_storage if $is_rel; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# new delta is (1, 0, ...) |
61
|
0
|
|
|
|
|
|
my $delta = Language::Befunge::Vector->new_zeroes( $vec->get_dims ); |
62
|
0
|
|
|
|
|
|
$delta->set_component(0,1); |
63
|
0
|
|
|
|
|
|
$ip->set_delta( $delta ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# set new position |
66
|
0
|
|
|
|
|
|
$ip->set_position($vec); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub O { |
70
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
71
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
72
|
0
|
|
|
|
|
|
$ip->extdata('SUBR', 1); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub R { |
76
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
77
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
78
|
0
|
|
|
|
|
|
my $count = $ip->spop; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# mess with stack |
81
|
0
|
|
|
|
|
|
my @stack = $ip->spop_mult($count); |
82
|
0
|
|
|
|
|
|
my $delta = $ip->spop_vec; |
83
|
0
|
|
|
|
|
|
my $pos = $ip->spop_vec; |
84
|
0
|
|
|
|
|
|
$ip->spush_args( @stack ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# set new position |
87
|
0
|
|
|
|
|
|
$ip->set_position($pos); |
88
|
0
|
|
|
|
|
|
$ip->set_delta($delta); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |