line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Language-Befunge |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2003 by Jerome Quelin. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
2
|
|
|
2
|
|
17070
|
use 5.010; |
|
2
|
|
|
|
|
5
|
|
10
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
28
|
|
11
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Language::Befunge::Storage::Generic::Sparse; |
14
|
|
|
|
|
|
|
# ABSTRACT: a generic N-dimensional LaheySpace |
15
|
|
|
|
|
|
|
$Language::Befunge::Storage::Generic::Sparse::VERSION = '5.000'; |
16
|
2
|
|
|
2
|
|
7
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
96
|
|
17
|
2
|
|
|
2
|
|
364
|
use Language::Befunge::Vector; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
29
|
|
18
|
2
|
|
|
2
|
|
386
|
use Language::Befunge::IP; |
|
2
|
|
|
|
|
38
|
|
|
2
|
|
|
|
|
41
|
|
19
|
2
|
|
|
2
|
|
20
|
use base 'Language::Befunge::Storage'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
622
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# -- CONSTRUCTOR |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# new( dimensions ) |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# Creates a new Lahey Space. |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
sub new { |
30
|
12
|
|
|
12
|
1
|
468
|
my $package = shift; |
31
|
12
|
|
|
|
|
12
|
my $dimensions = shift; |
32
|
12
|
|
|
|
|
22
|
my %args = @_; |
33
|
12
|
|
|
|
|
43
|
my $usage = "Usage: $package->new(\$dimensions, Wrapping => \$wrapping)"; |
34
|
12
|
100
|
|
|
|
33
|
croak $usage unless defined $dimensions; |
35
|
11
|
100
|
|
|
|
25
|
croak $usage unless $dimensions > 0; |
36
|
10
|
100
|
|
|
|
24
|
croak $usage unless exists $args{Wrapping}; |
37
|
|
|
|
|
|
|
my $self = { |
38
|
|
|
|
|
|
|
nd => $dimensions, |
39
|
|
|
|
|
|
|
wrapping => $args{Wrapping}, |
40
|
9
|
|
|
|
|
21
|
}; |
41
|
9
|
|
|
|
|
14
|
bless $self, $package; |
42
|
9
|
|
|
|
|
15
|
$self->clear(); |
43
|
9
|
|
|
|
|
18
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# -- PUBLIC METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# clear( ) |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# Clear the torus. |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
sub clear { |
55
|
15
|
|
|
15
|
1
|
537
|
my $self = shift; |
56
|
15
|
|
|
|
|
40
|
$$self{min} = Language::Befunge::Vector->new_zeroes($$self{nd}); |
57
|
15
|
|
|
|
|
28
|
$$self{max} = Language::Befunge::Vector->new_zeroes($$self{nd}); |
58
|
15
|
|
|
|
|
19
|
$$self{torus} = {}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# my $val = get_value( vector ) |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
# Return the number stored in the torus at the specified location. If |
66
|
|
|
|
|
|
|
# the value hasn't yet been set, it defaults to the ordinal value of a |
67
|
|
|
|
|
|
|
# space (ie, #32). |
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
# B!\> As in Funge, code and data share the same playfield, the |
70
|
|
|
|
|
|
|
# number returned can be either an instruction B a data (or even |
71
|
|
|
|
|
|
|
# both... Eh, that's Funge! :o) ). |
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
sub get_value { |
74
|
1372
|
|
|
1372
|
1
|
1059
|
my ($self, $v) = @_; |
75
|
1372
|
|
|
|
|
1744
|
my $str = "$v"; |
76
|
1372
|
100
|
|
|
|
2622
|
return 32 unless exists $$self{torus}{$str}; |
77
|
568
|
|
|
|
|
732
|
return $$self{torus}{$str}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# |
82
|
|
|
|
|
|
|
# set_value( vector, value ) |
83
|
|
|
|
|
|
|
# |
84
|
|
|
|
|
|
|
# Write the supplied value in the torus at the specified location. |
85
|
|
|
|
|
|
|
# |
86
|
|
|
|
|
|
|
# B!\> As in Funge, code and data share the same playfield, the |
87
|
|
|
|
|
|
|
# number stored can be either an instruction B a data (or even |
88
|
|
|
|
|
|
|
# both... Eh, that's Funge! :o) ). |
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
sub set_value { |
91
|
394
|
|
|
394
|
1
|
283
|
my ($self, $v, $val) = @_; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# update min/max |
94
|
394
|
|
|
|
|
515
|
$self->expand($v); |
95
|
394
|
|
|
|
|
507
|
my $str = "$v"; |
96
|
394
|
|
|
|
|
772
|
$$self{torus}{$str} = $val; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |