8 my @variants = qw(c3 cv sm);
10 $SIG{__WARN__
} = sub { die $_[0] };
12 my %fnmap = ( # default category mappings
13 'caosVM_agent.cpp' => 'Agents',
14 'caosVM_camera.cpp' => 'Cameras',
15 'caosVM_core.cpp' => 'Core functions',
16 'caosVM_creatures.cpp' => 'Creatures',
17 'caosVM_compound.cpp' => 'Compound agents',
18 'caosVM_debug.cpp' => 'Debugging',
19 'caosVM_files.cpp' => 'Files',
20 'caosVM_flow.cpp' => 'Flow control',
21 'caosVM_genetics.cpp' => 'Genetics',
22 'caosVM_history.cpp' => 'History',
23 'caosVM_input.cpp' => 'Input',
24 'caosVM_map.cpp' => 'Map',
25 'caosVM_motion.cpp' => 'Motion',
26 'caosVM_net.cpp' => 'Networking',
27 'caosVM_ports.cpp' => 'Ports',
28 'caosVM_resources.cpp' => 'Resources',
29 'caosVM_scripts.cpp' => 'Scripts',
30 'caosVM_sounds.cpp' => 'Sound',
31 'caosVM_time.cpp' => 'Time',
32 'caosVM_variables.cpp' => 'Variables',
33 'caosVM_vectors.cpp' => 'Vectors',
34 'caosVM_vehicles.cpp' => 'Vehicles',
35 'caosVM_world.cpp' => 'World',
43 my $missing_status = 0;
49 if (m/STUB|TODO/ && defined $prev && !defined $prev->{status
}) {
50 $prev->{status
} = 'stub';
56 $_ =~ s/^\s* \** \s*//x; # accept leading * etc
61 # eg MOWS (command), LAWN (agent)
62 (\S
+) \s
* \
((\w
+)\
) \s
*
65 # we parse this in more detail later
73 my ($cns, $cname, $ctype, $argdata) = ($1, $2, $3, $4);
78 my $fullname = ($cns ?
"$cns " : "") . $cname;
82 if ($ctype eq 'command') {
87 if ($cns && $cns ne '') {
89 $_ =~ s/[^a-zA-Z0-9_]//g;
93 $_ =~ s/[^a-zA-Z0-9_]//g;
96 $impl = "caosVM::$impl";
97 my $stackdelta = ($ctype eq 'command' ?
0 : 1);
102 while ($argdata =~ s/.*?(\w+)\s*\(([^)]+)\)\s*//) {
103 my ($argname, $argtype) = ($1, $2);
108 $stackdelta-- unless $argtype =~ /variable/;
112 DOCLINE
: while (<>) {
113 last DOCLINE
if m{\*/};
114 $_ =~ m{^\s* (?: \* \s* )* (.*?) \s*$}x;
117 shift @lines while (@lines && $lines[0] eq '');
118 pop @lines while (@lines && $lines[-1] eq '');
125 if ($ctype eq 'command') {
126 $evalcost{default} = 1;
128 $evalcost{default} = 0;
131 while (@lines && ($lines[0] =~ s{^\%([a-zA-Z]+)\s+}{} || $lines[0] =~ m{^\s*$})) {
132 my $l = shift @lines;
135 if ($1 eq 'pragma') {
136 unless ($l =~ m{(\w+)\s*(.*)}) {
141 if ($pragma{$1} eq '') {
144 } elsif ($1 eq 'status') {
146 die "Set status twice";
150 } elsif ($1 eq 'category') {
152 die "set category twice";
155 } elsif ($1 eq 'cost') {
156 if ($l =~ m{^\s*(-?\d+)\s*$}) {
157 $evalcost{default} = $1;
158 } elsif ($l =~ m{(\S+)\s+(-?\d+)\s*$}) {
160 my @variants = split ',', $1;
161 for my $v (@variants) {
162 $evalcost{$v} = $cost;
165 die "malformed cost directive";
168 die "Unrecognized directive: $1";
174 print STDERR
"Missing \%status for $fullname\n";
178 $cat = lc $fnmap{$file} || 'unknown';
181 $stackdelta = $pragma{stackdelta
} if defined $pragma{stackdelta
};
182 $stackdelta = "INT_MAX" if lc $pragma{stackdelta
} eq "any";
183 die "Deprecated use of pragma retc for $fullname" if defined $pragma{retc
};
186 if ($pragma{implementation
}) {
187 $impl = $pragma{implementation
};
189 if ($pragma{saveimpl
}) {
190 $saveimpl = $pragma{saveimpl
};
192 if ($ctype eq 'variable') {
194 $saveimpl =~ s/caosVM::v/caosVM::s/;
196 $saveimpl = "caosVM::dummy_cmd";
199 $firstline =~ s/^\s*//;
200 my $desc = join("\n", @lines);
208 syntaxstring
=> $firstline,
209 description
=> @lines ?
$desc : undef,
211 implementation
=> $impl,
212 saveimpl
=> $saveimpl,
215 evalcost
=> \
%evalcost,
216 stackdelta
=> $stackdelta,
219 $cd->{pragma
} = \
%pragma;
221 if ($cns && $cns ne '') {
222 $cd->{namespace
} = lc $cns;
224 unless ($cd->{status
}) {
225 $cd->{status
} = 'probablyok';
230 if ($pragma{variants
}) {
231 @v = grep { $_ ne ''; } split ' ', $pragma{variants
};
242 if (exists $data{$v}{$key}) {
243 print STDERR
"Name collision for ($key) in variant $v\n";
246 $data{$v}{$key} = $cd;
250 if ($missing_status) {
251 print STDERR
"$missing_status commands are missing \%status, fixit.\n";
255 for my $key (keys %{$data{all
}}) {
256 for my $variant (keys %data) {
257 next if $variant eq 'all';
258 if (exists $data{$variant}{$key}) {
259 print STDERR
"Name collision for ($key) in variant $variant\n";
262 $data{$variant}{$key} = $data{all
}{$key};
270 namespaces
=> [keys %ns],