Below is a patch doing five things:
1) rename $nvivsiz to $sizeof_float  
      which should be easier to understand

2) rename the inner $count to $num_params
       which should avoid some confusion

3) change $num_i and $num_n to $num_ints and $num_floats respectively
       which should help clarify what they do

4) make the precedence of the RETURN_OFFSET calculation explicit

5) eliminate the 80 lines of redundant read_ops and associated pod

Obviously, I'm not a wizard at any of this, the changes here are all
small things aimed at making the environment simpler and easier to work
with.  If these kinds of changes are worthwhile, I'll keep moving
through assemble.pl and disassemble.pl (and maybe into the VM itself,
but don't hold your breath).

-pate

? opCode.patch
Index: Opcode.pm
===================================================================
RCS file: /home/perlcvs/parrot/Parrot/Opcode.pm,v
retrieving revision 1.7
diff -u -r1.7 Opcode.pm
--- Opcode.pm   2001/09/20 14:39:17     1.7
+++ Opcode.pm   2001/09/20 18:27:45
@@ -8,8 +8,7 @@
 my $fingerprint;
 my $revision;
 
-my $nvivsize;
-$nvivsize = $PConfig{nvsize}/$PConfig{ivsize};
+my $sizeof_float = $PConfig{nvsize}/$PConfig{ivsize};
 
 sub _load {
     my $file = @_ ? shift : "opcode_table";
@@ -32,9 +31,9 @@
 
        my($name, @params) = split /\s+/;
        if (@params && $params[0] =~ /^\d+$/) {
-           my $count = shift @params;
+           my $num_params = shift @params;
            die "$file, line $.: opcode $name parameters don't match count\n"
-             if ($count != @params);
+             if ($num_params != @params);
        }
 
        warn "$file, line $.: opcode $name redefined\n" if $opcode{$name};
@@ -44,9 +43,10 @@
        $opcode{$name}{CODE}  = ($name eq "end") ? 0 : $count++;
        $opcode{$name}{FUNC}  = $name;
 
-       my $num_i = () = grep {/i/} @params;
-       my $num_n = () = grep {/n/} @params;
-       $opcode{$name}{RETURN_OFFSET} = 1 + $num_i + $num_n * $nvivsize;
+       my $num_ints = () = grep {/i/} @params;
+       my $num_floats = () = grep {/n/} @params;
+       $opcode{$name}{RETURN_OFFSET} = 
+           1 + $num_ints + ($num_floats * $sizeof_float);
     }
 }
 
@@ -112,91 +112,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 * $nvivsize;
-    }
-
-    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

Reply via email to