On Wed, Sep 19, 2001 at 01:40:31PM -0400, Pat Eyler wrote: > I realize that the $count inside the if block shown masks the $count > declared outside the while loop, but (to me) this would be easier to > understand if the inner $count where changed to $numParams -- it is more > obvious on casual reading that $count and $count are two different > things. Am I missing something? No, you aren't. That IS confusing. > 2) It also appears that a second (older?) version of read_ops and an > associated pile of pod is still in the Opcode.pm file can this be > trimmed (removing about 80 lines from the file)? Where on earth did that come from? Patch attached to rename the second $count, and to remove the duplicate code. - Damien
Index: Parrot/Opcode.pm =================================================================== RCS file: /home/perlcvs/parrot/Parrot/Opcode.pm,v retrieving revision 1.6 diff -u -r1.6 Opcode.pm --- Parrot/Opcode.pm 2001/09/18 00:32:15 1.6 +++ Parrot/Opcode.pm 2001/09/20 07:23:44 @@ -28,9 +28,9 @@ my($name, @params) = split /\s+/; if (@params && $params[0] =~ /^\d+$/) { - my $count = shift @params; + my $nparams = shift @params; die "$file, line $.: opcode $name parameters don't match count\n" - if ($count != @params); + if ($nparams != @params); } warn "$file, line $.: opcode $name redefined\n" if $opcode{$name}; @@ -108,91 +108,5 @@ The fingerprint() function returns the MD5 signature (in hex) of the opcode table. - -=cut -package Parrot::Opcode; - -use strict; -use Symbol; - -sub read_ops { - my $file = @_ ? shift : "opcode_table"; - - my $fh = gensym; - open $fh, $file or die "$file: $!\n"; - - my %opcode; - my $count = 1; - while (<$fh>) { - s/#.*//; - s/^\s+//; - chomp; - next unless $_; - - my($name, @params) = split /\s+/; - if (@params && $params[0] =~ /^\d+$/) { - my $count = shift @params; - die "$file, line $.: opcode $name parameters don't match count\n" - if ($count != @params); - } - - warn "$file, line $.: opcode $name redefined\n" if $opcode{$name}; - - $opcode{$name}{ARGS} = @params; - $opcode{$name}{TYPES} = \@params; - $opcode{$name}{CODE} = ($name eq "end") ? 0 : $count++; - $opcode{$name}{FUNC} = "Parrot_op_$name"; - - my $num_i = () = grep {/i/} @params; - my $num_n = () = grep {/n/} @params; - $opcode{$name}{RETURN_OFFSET} = 1 + $num_i + $num_n * 2; - } - - return %opcode; -} - -1; - - -__END__ - -=head1 NAME - -Parrot::Opcode - Read opcode definitions - -=head1 SYNOPSIS - - use Parrot::Opcode; - - %opcodes = Parrot::Opcode::read_ops(); - -=head1 DESCRIPTION - -The read_ops() function parses the Parrot opcode_table file, and -returns the contents as a hash. The hash key is the opcode name; -values are hashrefs containing the following fields: - -=over - -=item CODE - -The opcode number. - -=item ARGS - -The opcode argument count. - -=item TYPES - -The opcode argument types, as an arrayref. - -=item FUNC - -The name of the C function implementing this op. - -=back - -read_ops() takes an optional argument: the file to read the opcode table -from. =cut