On Tue Jul 10 05:40:52 2007, ptc wrote:
> In the file lib/Parrot/OpsFile.pm there is the todo item:
> 
>         # TODO: Complain about using, e.g. $3 in an op with only 2 args.
> 
> This needs to be implemented.

With the attached patch, the following op:

inline op if(invar INT, labelconst INT) {
    INTVAL a = $4;
    if ($1 != 0) {
        goto OFFSET($2);
    }
    goto NEXT();
}

will now break the build, and die with the message:

opcode 'if' uses '$4' but only has 2 parameters.

... I'd apply it, except that the following op breaks the build (and is already 
checked in. =-)

inline op not(invar PMC) :base_core {
  $2->vtable->i_logical_not(interp, $1);
  goto NEXT();
}



Index: lib/Parrot/OpsFile.pm
===================================================================
--- lib/Parrot/OpsFile.pm       (revision 26850)
+++ lib/Parrot/OpsFile.pm       (working copy)
@@ -494,8 +494,6 @@
         # on the mode of operation (function calls, switch statements, gotos
         # with labels, etc.).
         #
-        # RT#43719: Complain about using, e.g. $3 in an op with only 2 args.
-        #
 
         $branch   ||= $body =~ s/\bgoto\s+OFFSET\(\( (.*?) \)\)/{{+=$1}}/mg;
         $absolute ||= $body =~ s/\bgoto\s+ADDRESS\(\( (.*?) \)\)/{{=$1}}/mg;
@@ -535,6 +533,14 @@
 
         $body =~ s/\$(\d+)/[EMAIL PROTECTED]/mg;
 
+        # We can only reference as many parameters as we declare
+        my $max_arg_num = @$args;
+        my @found_args = ($body =~ m/{{@(\d+)}}/g);
+        foreach my $arg (@found_args) {
+          die "opcode '$short_name' uses '\$$arg' but only has $max_arg_num 
parameters.\n" if $arg > $max_arg_num;
+        }
+
+
         my $file_escaped = $file;
         $file_escaped =~ s|(\\)|$1$1|g;    # escape backslashes
         $op->body( $nolines ? $body : qq{#line $line "$file_escaped"\n$body} );

Reply via email to