| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# This file is part of Inline::Befunge. |
|
3
|
|
|
|
|
|
|
# Copyright (c) 2001-2007 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 Inline::Befunge; |
|
11
|
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
92457
|
use strict; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
133
|
|
|
13
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
99
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
29
|
use Carp; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
257
|
|
|
16
|
3
|
|
|
3
|
|
2797
|
use Language::Befunge; |
|
|
3
|
|
|
|
|
240493
|
|
|
|
3
|
|
|
|
|
43
|
|
|
17
|
|
|
|
|
|
|
require Inline; # use Inline forbidden. |
|
18
|
|
|
|
|
|
|
our @ISA = qw! Inline !; # not "use base" (use will take precedence over require) |
|
19
|
|
|
|
|
|
|
our $VERSION = '1.1.1'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub register { |
|
23
|
|
|
|
|
|
|
return |
|
24
|
0
|
|
|
0
|
1
|
0
|
{ language => 'Befunge', |
|
25
|
|
|
|
|
|
|
aliases => [ 'befunge', 'BEFUNGE', 'bef', 'BEF' ], |
|
26
|
|
|
|
|
|
|
type => 'interpreted', |
|
27
|
|
|
|
|
|
|
suffix => 'bef', |
|
28
|
|
|
|
|
|
|
}; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub validate { |
|
32
|
2
|
|
|
2
|
1
|
140
|
my $self = shift; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Initializes funcs. |
|
35
|
2
|
|
|
|
|
18
|
$self->{ILSM}{DEBUG} = 0; |
|
36
|
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
84
|
while(@_ >= 2) { |
|
38
|
0
|
|
|
|
|
0
|
my ($key, $value) = (shift, shift); |
|
39
|
0
|
0
|
|
|
|
0
|
$key eq "DEBUG" and $self->{ILSM}{DEBUG} = $value, next; |
|
40
|
0
|
|
|
|
|
0
|
croak "Unsupported option found: '$key'."; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub build { |
|
46
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
47
|
|
|
|
|
|
|
# The magic incantations to register. |
|
48
|
0
|
|
|
|
|
0
|
my $path = $self->{API}{install_lib}."/auto/".$self->{API}{modpname}; |
|
49
|
0
|
0
|
|
|
|
0
|
$self->mkpath($path) unless -d $path; |
|
50
|
0
|
|
|
|
|
0
|
my $file = $self->{API}{location}; |
|
51
|
0
|
0
|
|
|
|
0
|
open FOO_OBJ, "> $file" or croak "Can't open $file for output\n$!"; |
|
52
|
0
|
|
|
|
|
0
|
print FOO_OBJ $self->{API}{code}; |
|
53
|
0
|
|
|
|
|
0
|
close FOO_OBJ; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub load { |
|
58
|
|
|
|
|
|
|
# Fetch object and package. |
|
59
|
2
|
|
|
2
|
1
|
9
|
my $self = shift; |
|
60
|
2
|
|
50
|
|
|
11
|
my $pkg = $self->{API}{pkg} || 'main'; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Fetch code and create the interpreter. |
|
63
|
2
|
|
|
|
|
6
|
my $code = $self->{API}{code}; |
|
64
|
2
|
|
|
|
|
108
|
my $bef = $self->{ILSM}{bef} = Language::Befunge->new; |
|
65
|
2
|
|
|
|
|
97770
|
$bef->store_code( $code ); |
|
66
|
2
|
|
|
|
|
1589
|
$bef->set_DEBUG( $self->{ILSM}{DEBUG} ); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Parse the code. |
|
69
|
|
|
|
|
|
|
# Each subroutine should be: |
|
70
|
|
|
|
|
|
|
# ;:subname1; < @ ,,,,"foo"a |
|
71
|
|
|
|
|
|
|
# ;:subname2; |
|
72
|
|
|
|
|
|
|
# etc. |
|
73
|
0
|
|
|
|
|
|
my $funcs = $bef->get_torus->labels_lookup; |
|
74
|
0
|
|
|
|
|
|
$self->{ILSM}{funcs} = join " ", sort keys %$funcs; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
foreach my $subname ( keys %$funcs ) { |
|
77
|
3
|
|
|
3
|
|
1855
|
no strict 'refs'; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
1193
|
|
|
78
|
0
|
|
|
|
|
|
*{"${pkg}::$subname"} = |
|
79
|
|
|
|
|
|
|
sub { |
|
80
|
|
|
|
|
|
|
# Cosmetics. |
|
81
|
0
|
|
|
0
|
|
|
$bef->debug( "\n-= SUBROUTINE $subname =-\n" ); |
|
82
|
0
|
|
|
|
|
|
$bef->set_file( "Inline-$subname" ); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Create the first Instruction Pointer. |
|
85
|
0
|
|
|
|
|
|
my $ip = Language::Befunge::IP->new ; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Move the IP at the beginning of the function. |
|
88
|
0
|
|
|
|
|
|
my $pos = Language::Befunge::Vector->new( 2, |
|
89
|
|
|
|
|
|
|
$funcs->{$subname}[0], |
|
90
|
|
|
|
|
|
|
$funcs->{$subname}[1], |
|
91
|
|
|
|
|
|
|
); |
|
92
|
0
|
|
|
|
|
|
$ip->set_position($pos); |
|
93
|
0
|
|
|
|
|
|
my $delta = Language::Befunge::Vector->new( 2, |
|
94
|
|
|
|
|
|
|
$funcs->{$subname}[2], |
|
95
|
|
|
|
|
|
|
$funcs->{$subname}[3], |
|
96
|
|
|
|
|
|
|
); |
|
97
|
0
|
|
|
|
|
|
$ip->set_delta($delta); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Fill the stack with arguments. |
|
100
|
0
|
|
|
|
|
|
$ip->spush_args( @_ ); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Initialize the interpreter. |
|
103
|
0
|
|
|
|
|
|
$bef->set_ips( [ $ip ] ); |
|
104
|
|
|
|
|
|
|
#$bef->set_kcounter(-1); |
|
105
|
0
|
|
|
|
|
|
$bef->set_retval(0); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Loop as long as there are IPs. |
|
108
|
0
|
|
|
|
|
|
$bef->next_tick while scalar @{ $bef->get_ips }; |
|
|
0
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Return the exit code and the TOSS. |
|
111
|
|
|
|
|
|
|
# return $bef->lastip->end eq '@' ? |
|
112
|
|
|
|
|
|
|
# @{ $bef->lastip->toss } # return the TOSS. |
|
113
|
|
|
|
|
|
|
# : $bef->retval; # return exit code. |
|
114
|
0
|
|
|
|
|
|
return $bef->get_retval; # quick'n'dirty bugfix |
|
115
|
0
|
|
|
|
|
|
}; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub info { |
|
122
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
123
|
0
|
|
|
|
|
|
my $text = <<'END'; |
|
124
|
|
|
|
|
|
|
The following functions have been defined via Inline::Befunge: |
|
125
|
|
|
|
|
|
|
$self->{ILSM}{funcs} |
|
126
|
|
|
|
|
|
|
END |
|
127
|
0
|
|
|
|
|
|
return $text; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
|
132
|
|
|
|
|
|
|
__END__ |