G'day all.

The optimizer needs to know what operands are INTs and which are
actually code targets in disguise in order to be able to restructure
code.

The patch below gives one simple solution, but I'm not sure that it's
the "best".  I suspect that code processors (including optimizers) might
need to know a lot of different kinds of metadata about various ops
(e.g. do they have side effects? could they throw exceptions?) so
this kind of information might be better specified differently.

Thoughts?

Cheers,
Andrew Bromage


Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.119
diff -u -r1.119 core.ops
--- core.ops    3 Apr 2002 23:03:37 -0000       1.119
+++ core.ops    7 Apr 2002 02:42:11 -0000
@@ -782,11 +782,11 @@
 
 =item B<eq>(in STR, in STR)
 
-=item B<eq>(in INT, in INT, in INT)
+=item B<eq>(in INT, in INT, in LABEL)
 
-=item B<eq>(in NUM, in NUM, in INT)
+=item B<eq>(in NUM, in NUM, in LABEL)
 
-=item B<eq>(in STR, in STR, in INT)
+=item B<eq>(in STR, in STR, in LABEL)
 
 Branch if $1 is equal to $2.
 
@@ -815,21 +815,21 @@
   goto NEXT();
 }
 
-inline op eq(in INT, in INT, in INT) {
+inline op eq(in INT, in INT, in LABEL) {
   if ($1 == $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op eq(in NUM, in NUM, in INT) {
+inline op eq(in NUM, in NUM, in LABEL) {
   if ($1 == $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op eq(in STR, in STR, in INT) {
+op eq(in STR, in STR, in LABEL) {
   if (string_compare(interpreter, $1, $2) == 0) {
     goto OFFSET($3);
   }
@@ -845,11 +845,11 @@
 
 =item B<ne>(in STR, in STR)
 
-=item B<ne>(in INT, in INT, in INT)
+=item B<ne>(in INT, in INT, in LABEL)
 
-=item B<ne>(in NUM, in NUM, in INT)
+=item B<ne>(in NUM, in NUM, in LABEL)
 
-=item B<ne>(in STR, in STR, in INT)
+=item B<ne>(in STR, in STR, in LABEL)
 
 Branch if $1 is not equal to $2.
 
@@ -878,21 +878,21 @@
   goto NEXT();
 }
 
-inline op ne(in INT, in INT, in INT) {
+inline op ne(in INT, in INT, in LABEL) {
   if ($1 != $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op ne(in NUM, in NUM, in INT) {
+inline op ne(in NUM, in NUM, in LABEL) {
   if ($1 != $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op ne(in STR, in STR, in INT) {
+op ne(in STR, in STR, in LABEL) {
   if (string_compare(interpreter, $1, $2) != 0) {
     goto OFFSET($3);
   }
@@ -902,33 +902,33 @@
 
 ########################################
 
-=item B<lt>(in INT, in INT, in INT)
+=item B<lt>(in INT, in INT, in LABEL)
 
-=item B<lt>(in NUM, in NUM, in INT)
+=item B<lt>(in NUM, in NUM, in LABEL)
 
-=item B<lt>(in PMC, in PMC, in INT)
+=item B<lt>(in PMC, in PMC, in LABEL)
 
-=item B<lt>(in STR, in STR, in INT)
+=item B<lt>(in STR, in STR, in LABEL)
 
 Branch if $1 is less than $2.
 
 =cut
 
-inline op lt(in INT, in INT, in INT) {
+inline op lt(in INT, in INT, in LABEL) {
   if ($1 < $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op lt(in NUM, in NUM, in INT) {
+inline op lt(in NUM, in NUM, in LABEL) {
   if ($1 < $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op lt(in STR, in STR, in INT) {
+op lt(in STR, in STR, in LABEL) {
   if (string_compare(interpreter, $1, $2) < 0) {
     goto OFFSET($3);
   }
@@ -938,31 +938,31 @@
 
 ########################################
 
-=item B<le>(in INT, in INT, in INT)
+=item B<le>(in INT, in INT, in LABEL)
 
-=item B<le>(in NUM, in NUM, in INT)
+=item B<le>(in NUM, in NUM, in LABEL)
 
-=item B<le>(in STR, in STR, in INT)
+=item B<le>(in STR, in STR, in LABEL)
 
 Branch if $1 is less than or equal to $2.
 
 =cut
 
-inline op le(in INT, in INT, in INT) {
+inline op le(in INT, in INT, in LABEL) {
   if ($1 <= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op le(in NUM, in NUM, in INT) {
+inline op le(in NUM, in NUM, in LABEL) {
   if ($1 <= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op le(in STR, in STR, in INT) {
+op le(in STR, in STR, in LABEL) {
   if (string_compare(interpreter, $1, $2) <= 0) {
     goto OFFSET($3);
   }
@@ -972,31 +972,31 @@
 
 ########################################
 
-=item B<gt>(in INT, in INT, in INT)
+=item B<gt>(in INT, in INT, in LABEL)
 
-=item B<gt>(in NUM, in NUM, in INT)
+=item B<gt>(in NUM, in NUM, in LABEL)
 
-=item B<gt>(in STR, in STR, in INT)
+=item B<gt>(in STR, in STR, in LABEL)
 
 Branch if $1 is greater than $2.
 
 =cut
 
-inline op gt(in INT, in INT, in INT) {
+inline op gt(in INT, in INT, in LABEL) {
   if ($1 > $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op gt(in NUM, in NUM, in INT) {
+inline op gt(in NUM, in NUM, in LABEL) {
   if ($1 > $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op gt(in STR, in STR, in INT) {
+op gt(in STR, in STR, in LABEL) {
   if (string_compare(interpreter, $1, $2) > 0) {
     goto OFFSET($3);
   }
@@ -1006,31 +1006,31 @@
 
 ########################################
 
-=item B<ge>(in INT, in INT, in INT)
+=item B<ge>(in INT, in INT, in LABEL)
 
-=item B<ge>(in NUM, in NUM, in INT)
+=item B<ge>(in NUM, in NUM, in LABEL)
 
-=item B<ge>(in STR, in STR, in INT)
+=item B<ge>(in STR, in STR, in LABEL)
 
 Branch if $1 is greater than or equal to $2.
 
 =cut
 
-inline op ge(in INT, in INT, in INT) {
+inline op ge(in INT, in INT, in LABEL) {
   if ($1 >= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-inline op ge(in NUM, in NUM, in INT) {
+inline op ge(in NUM, in NUM, in LABEL) {
   if ($1 >= $2) {
     goto OFFSET($3);
   }
   goto NEXT();
 }
 
-op ge(in STR, in STR, in INT) {
+op ge(in STR, in STR, in LABEL) {
   if (string_compare(interpreter, $1, $2) >= 0) {
     goto OFFSET($3);
   }
@@ -1039,40 +1039,40 @@
 
 ########################################
 
-=item B<if>(in INT, in INT)
+=item B<if>(in INT, in LABEL)
 
-=item B<if>(in NUM, in INT)
+=item B<if>(in NUM, in LABEL)
 
-=item B<if>(in PMC, in INT)
+=item B<if>(in PMC, in LABEL)
 
-=item B<if>(in STR, in INT)
+=item B<if>(in STR, in LABEL)
 
 Check register $1. If true, branch by $2.
 
 =cut
 
-inline op if(in INT, in INT) {
+inline op if(in INT, in LABEL) {
   if ($1 != 0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-inline op if(in NUM, in INT) {
+inline op if(in NUM, in LABEL) {
   if ($1 != 0.0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op if (in STR, in INT) {
+op if (in STR, in LABEL) {
   if (string_bool($1)) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op if(in PMC, in INT) {
+op if(in PMC, in LABEL) {
   if ($1->vtable->get_bool(interpreter, $1)) {
     goto OFFSET($2);
   }
@@ -1086,40 +1086,40 @@
 
 ###############################################################################
 
-=item B<unless>(in INT, in INT)
+=item B<unless>(in INT, in LABEL)
 
-=item B<unless>(in NUM, in INT)
+=item B<unless>(in NUM, in LABEL)
 
-=item B<unless>(in PMC, in INT)
+=item B<unless>(in PMC, in LABEL)
 
-=item B<unless>(in STR, in INT)
+=item B<unless>(in STR, in LABEL)
 
 Check register $1. If false, branch by $2.
 
 =cut
 
-inline op unless(in INT, in INT) {
+inline op unless(in INT, in LABEL) {
   if ($1 == 0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-inline op unless(in NUM, in INT) {
+inline op unless(in NUM, in LABEL) {
   if ($1 == 0.0) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op unless (in STR, in INT) {
+op unless (in STR, in LABEL) {
   if (!string_bool($1)) {
     goto OFFSET($2);
   }
   goto NEXT();
 }
 
-op unless(in PMC, in INT) {
+op unless(in PMC, in LABEL) {
   if (!$1->vtable->get_bool(interpreter, $1)) {
     goto OFFSET($2);
   }
@@ -2571,27 +2571,27 @@
 
 ########################################
 
-=item B<branch>(in INT)
+=item B<branch>(in LABEL)
 
 Branch forward or backward by the amount in $1.
 
 =cut
 
-inline op branch (in INT) {
+inline op branch (in LABEL) {
   goto OFFSET($1);
 }
 
 
 ########################################
 
-=item B<bsr>(in INT)
+=item B<bsr>(in LABEL)
 
 Branch to the location specified by $1. Push the current location onto the call
 stack for later returning.
 
 =cut
 
-inline op bsr (in INT) {
+inline op bsr (in LABEL) {
   stack_push(interpreter, interpreter->control_stack, expr NEXT(),  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
   goto OFFSET($1);
 }
@@ -2611,13 +2611,13 @@
 
 ########################################
 
-=item B<jump>(out INT)
+=item B<jump>(out LABEL)
 
 Jump to the address held in register $1.
 
 =cut
 
-inline op jump(out INT) {
+inline op jump(out LABEL) {
   goto OFFSET($1);
 }
 
Index: interpreter.c
===================================================================
RCS file: /cvs/public/parrot/interpreter.c,v
retrieving revision 1.82
diff -u -r1.82 interpreter.c
--- interpreter.c       2 Apr 2002 06:24:14 -0000       1.82
+++ interpreter.c       7 Apr 2002 02:42:11 -0000
@@ -248,6 +248,7 @@
             break;
 
         case PARROT_ARG_I:
+        case PARROT_ARG_L:
             pc_prederef[i] = (void *)&interpreter->int_reg.registers[pc[i]];
             break;
 
@@ -264,6 +265,7 @@
             break;
 
         case PARROT_ARG_IC:
+        case PARROT_ARG_LC:
             pc_prederef[i] = (void *)&pc[i];
             break;
 
@@ -288,7 +290,9 @@
             break;
         }
 
-        if (opinfo->types[i] != PARROT_ARG_IC && pc_prederef[i] == 0) {
+        if (opinfo->types[i] != PARROT_ARG_IC
+               && opinfo->types[i] != PARROT_ARG_LC
+               && pc_prederef[i] == 0) {
             internal_exception(INTERP_ERROR,
                                "Prederef generated a NULL pointer for arg of type 
%d!\n",
                                opinfo->types[i]);

Index: rx.ops
===================================================================
RCS file: /cvs/public/parrot/rx.ops,v
retrieving revision 1.17
diff -u -r1.17 rx.ops
--- rx.ops      2 Apr 2002 20:35:52 -0000       1.17
+++ rx.ops      7 Apr 2002 02:42:11 -0000
@@ -428,14 +428,14 @@
 
 ########################################
 
-=item C<rx_popindex>(in pmc, in int)
+=item C<rx_popindex>(in pmc, in label)
 
 Pops an index off the stack.  If it pops a mark off instead, it branches to the 
 second parameter.
 
 =cut
 
-op rx_popindex(in pmc, in int) {
+op rx_popindex(in pmc, in label) {
        RX_dUNPACK($1);
        INTVAL i;
        
@@ -507,14 +507,14 @@
 
 ########################################
 
-=item C<rx_advance>(in pmc, in int)
+=item C<rx_advance>(in pmc, in label)
 
 Increments (or decrements, if the C<r> modifier is used) the start index one
 character.  Branches to the second parameter if it goes past the end of the string.
 
 =cut
 
-op rx_advance(in pmc, in int) {
+op rx_advance(in pmc, in label) {
        RX_dUNPACK($1);
 
        if(!RxReverse_test(rx)) {
@@ -668,7 +668,7 @@
 
 ########################################
 
-=item C<rx_literal>(in pmc, in str, in int)
+=item C<rx_literal>(in pmc, in str, in label)
 
 Matches the exact string (sensitive to the C<i> modifier) passed in the second
 parameter.
@@ -677,7 +677,7 @@
 
 =cut
 
-op rx_literal(in pmc, in str, in int) {
+op rx_literal(in pmc, in str, in label) {
        UINTVAL i;
        RX_dUNPACK($1);
 
@@ -698,13 +698,13 @@
 
 ########################################
 
-=item C<rx_is_w>(in pmc, in int)
+=item C<rx_is_w>(in pmc, in label)
 
 Matches a word character (usually C<\w>).
 
 =cut
 
-op rx_is_w(in pmc, in int) {
+op rx_is_w(in pmc, in label) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -721,13 +721,13 @@
 
 ########################################
 
-=item C<rx_is_d>(in pmc, in int)
+=item C<rx_is_d>(in pmc, in label)
 
 Matches a number character (usually C<\d>).
 
 =cut
 
-op rx_is_d(in pmc, in int) {
+op rx_is_d(in pmc, in label) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -743,13 +743,13 @@
 
 ########################################
 
-=item C<rx_is_s>(in pmc, in int)
+=item C<rx_is_s>(in pmc, in label)
 
 Matches a whitespace character (usually C<\s>).
 
 =cut
 
-op rx_is_s(in pmc, in int) {
+op rx_is_s(in pmc, in label) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -766,7 +766,7 @@
 
 ########################################
 
-=item C<rx_oneof>(in pmc, in str, in int)
+=item C<rx_oneof>(in pmc, in str, in label)
 
 Matches if the current character is one of the characters in the second parameter.
 Sensitive to the C<i> modifier.
@@ -778,7 +778,7 @@
 
 =cut
 
-op rx_oneof(in pmc, in str, in int) {
+op rx_oneof(in pmc, in str, in label) {
        RX_dUNPACK($1);
        Bitmap bitmap;
 
@@ -801,14 +801,14 @@
 
 ########################################
 
-=item C<rx_oneof_bmp>(in pmc, in pmc, in int)
+=item C<rx_oneof_bmp>(in pmc, in pmc, in label)
 
 This op has the exact same behavior as C<rx_oneof>, except that the second parameter 
 is a ParrotPointer to a bitmap generated by C<rx_makebmp>.
 
 =cut
 
-op rx_oneof_bmp(in pmc, in pmc, in int) {
+op rx_oneof_bmp(in pmc, in pmc, in label) {
        RX_dUNPACK($1);
        
        RxAssertMore(rx, $3);
@@ -844,14 +844,14 @@
 
 ########################################
 
-=item C<rx_dot>(in pmc, in int)
+=item C<rx_dot>(in pmc, in label)
 
 Matches any character except a newline (C<\n>).  (If the C<s> modifier is used, 
 matches any character at all.)
 
 =cut
 
-op rx_dot(in pmc, in int) {
+op rx_dot(in pmc, in label) {
        RX_dUNPACK($1);
 
        RxAssertMore(rx, $2);
@@ -873,14 +873,14 @@
 
 ########################################
 
-=item C<rx_zwa_boundary>(in pmc, in int)
+=item C<rx_zwa_boundary>(in pmc, in label)
 
 Matches if the one of the previous character and the next character is a word
 character, and the other one is not (usually C<\b>).
 
 =cut
 
-op rx_zwa_boundary(in pmc, in int) {
+op rx_zwa_boundary(in pmc, in label) {
        RX_dUNPACK($1);
        BOOLVAL one, two;
 
@@ -898,7 +898,7 @@
 
 ########################################
 
-=item C<rx_zwa_atbeginning>(in pmc, in int)
+=item C<rx_zwa_atbeginning>(in pmc, in label)
 
 Matches at the beginning of the string.  If the C<m> modifier is used, matches at the
 beginning of any line.
@@ -907,7 +907,7 @@
 
 =cut
 
-op rx_zwa_atbeginning(in pmc, in int) {
+op rx_zwa_atbeginning(in pmc, in label) {
        RX_dUNPACK($1);
        
        if(RxMultiline_test(rx)) {
@@ -926,7 +926,7 @@
 
 ########################################
 
-=item C<rx_zwa_atend>(in pmc, in int)
+=item C<rx_zwa_atend>(in pmc, in label)
 
 Matches at the end of the string.  If the C<m> modifier is used, matches at the
 end of any line.
@@ -935,7 +935,7 @@
 
 =cut
 
-op rx_zwa_atend(in pmc, in int) {
+op rx_zwa_atend(in pmc, in label) {
        RX_dUNPACK($1);
 
        if(RxMultiline_test(rx)) {
Index: include/parrot/op.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/op.h,v
retrieving revision 1.9
diff -u -r1.9 op.h
--- include/parrot/op.h 4 Mar 2002 03:17:21 -0000       1.9
+++ include/parrot/op.h 7 Apr 2002 02:42:11 -0000
@@ -26,11 +26,13 @@
     PARROT_ARG_OP,
 
     PARROT_ARG_IC,
+    PARROT_ARG_LC,
     PARROT_ARG_NC,
     PARROT_ARG_PC,
     PARROT_ARG_SC,
 
     PARROT_ARG_I,
+    PARROT_ARG_L,
     PARROT_ARG_N,
     PARROT_ARG_P,
     PARROT_ARG_S
Index: lib/Parrot/OpsFile.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpsFile.pm,v
retrieving revision 1.17
diff -u -r1.17 OpsFile.pm
--- lib/Parrot/OpsFile.pm       15 Feb 2002 03:24:57 -0000      1.17
+++ lib/Parrot/OpsFile.pm       7 Apr 2002 02:42:12 -0000
@@ -171,7 +171,7 @@
       my @temp = ();
 
       foreach my $arg (@args) {
-       my ($use, $type) = $arg =~ m/^(in|out|inout)\s+(INT|NUM|STR|PMC)$/i;
+       my ($use, $type) = $arg =~ m/^(in|out|inout)\s+(INT|NUM|STR|PMC|LABEL)$/i;
 
         die "Unrecognized arg format '$arg' in '$_'!" unless defined($use) and 
defined($type);
 
Index: lib/Parrot/OpTrans/C.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpTrans/C.pm,v
retrieving revision 1.5
diff -u -r1.5 C.pm
--- lib/Parrot/OpTrans/C.pm     16 Feb 2002 04:38:18 -0000      1.5
+++ lib/Parrot/OpTrans/C.pm     7 Apr 2002 02:42:12 -0000
@@ -54,11 +54,13 @@
   'op' => "cur_opcode[%ld]",
 
   'i'  => "interpreter->int_reg.registers[cur_opcode[%ld]]",
+  'l'  => "interpreter->int_reg.registers[cur_opcode[%ld]]",
   'n'  => "interpreter->num_reg.registers[cur_opcode[%ld]]",
   'p'  => "interpreter->pmc_reg.registers[cur_opcode[%ld]]",
   's'  => "interpreter->string_reg.registers[cur_opcode[%ld]]",
   
   'ic' => "cur_opcode[%ld]",
+  'lc' => "cur_opcode[%ld]",
   'nc' => "interpreter->code->const_table->constants[cur_opcode[%ld]]->number",
   'pc' => "%ld /* ERROR: Don't know how to handle PMC constants yet! */",
   'sc' => "interpreter->code->const_table->constants[cur_opcode[%ld]]->string",
Index: lib/Parrot/OpTrans/CGoto.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpTrans/CGoto.pm,v
retrieving revision 1.7
diff -u -r1.7 CGoto.pm
--- lib/Parrot/OpTrans/CGoto.pm 30 Mar 2002 19:02:30 -0000      1.7
+++ lib/Parrot/OpTrans/CGoto.pm 7 Apr 2002 02:42:12 -0000
@@ -118,11 +118,13 @@
   'op' => "cur_opcode[%ld]",
 
   'i'  => "interpreter->int_reg.registers[cur_opcode[%ld]]",
+  'l'  => "interpreter->int_reg.registers[cur_opcode[%ld]]",
   'n'  => "interpreter->num_reg.registers[cur_opcode[%ld]]",
   'p'  => "interpreter->pmc_reg.registers[cur_opcode[%ld]]",
   's'  => "interpreter->string_reg.registers[cur_opcode[%ld]]",
 
   'ic' => "cur_opcode[%ld]",
+  'lc' => "cur_opcode[%ld]",
   'nc' => "interpreter->code->const_table->constants[cur_opcode[%ld]]->number",
   'pc' => "%ld /* ERROR: Don't know how to handle PMC constants yet! */",
   'sc' => "interpreter->code->const_table->constants[cur_opcode[%ld]]->string",
Index: lib/Parrot/OpTrans/CPrederef.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpTrans/CPrederef.pm,v
retrieving revision 1.10
diff -u -r1.10 CPrederef.pm
--- lib/Parrot/OpTrans/CPrederef.pm     21 Feb 2002 18:20:26 -0000      1.10
+++ lib/Parrot/OpTrans/CPrederef.pm     7 Apr 2002 02:42:12 -0000
@@ -116,11 +116,13 @@
     'op' => "cur_opcode[%ld]",
 
     'i'  => "(*(INTVAL *)cur_opcode[%ld])",
+    'l'  => "(*(INTVAL *)cur_opcode[%ld])",
     'n'  => "(*(FLOATVAL *)cur_opcode[%ld])",
     'p'  => "(*(PMC **)cur_opcode[%ld])",
     's'  => "(*(STRING **)cur_opcode[%ld])",
 
     'ic' => "(*(INTVAL *)cur_opcode[%ld])",
+    'lc' => "(*(INTVAL *)cur_opcode[%ld])",
     'nc' => "(*(FLOATVAL *)cur_opcode[%ld])",
     'pc' => "%ld /* ERROR: Don't know how to handle PMC constants yet! */",
     'sc' => "(*(STRING **)cur_opcode[%ld])",

Reply via email to