On Feb-23, Leopold Toetsch wrote:
>
> Good.
> One minor note - and it is my fault to haven't documented that in the 
> first place - I did revert all the other changes, they are necessary for 
> pbc2c compiled code.
> Of course, it would be better, to have another set of macros, that 
> state: "This offset ought to be a real PBC offset".

Oops, sorry, I didn't mean to commit that part until I figured out
what was going on.

I think I kind of have a grasp on what's going on, now. So I've
attached two possible patches. The first just implements a new macro
OP_SIZE that can be used to calculate relative offsets. The second
goes further, and replaces expr_offset() for the pbc2c version so that
it computes start_code-relative offsets. Nothing appears to be using
the current version, which would only work for constant offsets
anyway. (The second also includes the OP_SIZE macro, but doesn't use
it -- so apply one or the other.)

I feel that my grasp of the situation is tenuous enough that I don't
want to commit the second without someone checking it over, and the
first isn't needed if the second is applied.

I also noticed that rx.ops doesn't look like it'll work with pbc2c
because it uses 'goto OFFSET' in a macro, and
Parrot::OpTrans::Compiled needs to know the relative PC of the current
instruction.

And finally, jsr seems to be broken with pbc2c (and maybe other cores,
I don't know.)
Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.260
diff -p -u -b -r1.260 core.ops
--- core.ops    23 Feb 2003 09:58:29 -0000      1.260
+++ core.ops    23 Feb 2003 18:59:36 -0000
@@ -19,10 +19,10 @@ Parrot's core library of ops.
 =head1 NOTE
 
 Some branching ops use B<CUR_OPCODE + size> as branch destination and
-not B<expr NEXT()>. This is done, to get a branch destination in terms
+not B<expr NEXT()>. This is done to get a branch destination in terms
 of offsets in the normal core, and not in terms of the running core.
 
-This is needed, for all branching ops, that might leave the actual
+This is needed for all branching ops that might leave the actual
 core, so that the branch offset can be recalculated to the other core,
 Currently used in the native run core generated by B<pbc2c.pl>.
 
@@ -3799,7 +3799,7 @@ stack for later returning.
 =cut
 
 inline op bsr (in INT) {
-  stack_push(interpreter, &interpreter->ctx.control_stack, CUR_OPCODE + 2,  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
+  stack_push(interpreter, &interpreter->ctx.control_stack, CUR_OPCODE + OP_SIZE,  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
   goto OFFSET($1);
 }
 
@@ -3815,7 +3815,7 @@ location onto the call stack for later r
 
 inline op jsr(in INT) {
   opcode_t * loc;
-  stack_push(interpreter, &interpreter->ctx.control_stack, CUR_OPCODE + 2,  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
+  stack_push(interpreter, &interpreter->ctx.control_stack, CUR_OPCODE + OP_SIZE,  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
   loc = INTVAL2PTR(opcode_t *, $1);
   goto ADDRESS(loc);
 }
@@ -4592,7 +4592,7 @@ inline op invoke() {
   opcode_t *dest;
   PMC * p = interpreter->ctx.pmc_reg.registers[0];
 
-  dest = (opcode_t *)p->vtable->invoke(interpreter, p, CUR_OPCODE + 1);
+  dest = (opcode_t *)p->vtable->invoke(interpreter, p, CUR_OPCODE + OP_SIZE);
 
   goto ADDRESS(dest);
 }
@@ -4601,7 +4601,7 @@ inline op invoke(in PMC) {
   opcode_t *dest;
   PMC * p = $1;
 
-  dest = (opcode_t *)p->vtable->invoke(interpreter, p, CUR_OPCODE + 2);
+  dest = (opcode_t *)p->vtable->invoke(interpreter, p, CUR_OPCODE + OP_SIZE);
 
   goto ADDRESS(dest);
 }
Index: lib/Parrot/Op.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/Op.pm,v
retrieving revision 1.9
diff -p -u -b -r1.9 Op.pm
--- lib/Parrot/Op.pm    22 Apr 2002 02:40:59 -0000      1.9
+++ lib/Parrot/Op.pm    23 Feb 2003 18:59:37 -0000
@@ -202,6 +202,7 @@ sub _substitute {
   s/{{-=([^{]*?)}}/     $trans->goto_offset(-$1); /me;
   s/{{=([^*][^{]*?)}}/  $trans->goto_address($1); /me;
 
+  s/{{\^(-?\d+)}}/      $1                        /me;
   s/{{\^\+([^{]*?)}}/   $trans->expr_offset($1);  /me;
   s/{{\^-([^{]*?)}}/    $trans->expr_offset(-$1); /me;
   s/{{\^([^{]*?)}}/     $trans->expr_address($1); /me;
Index: lib/Parrot/OpsFile.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpsFile.pm,v
retrieving revision 1.31
diff -p -u -b -r1.31 OpsFile.pm
--- lib/Parrot/OpsFile.pm       22 Jan 2003 15:57:24 -0000      1.31
+++ lib/Parrot/OpsFile.pm       23 Feb 2003 18:59:37 -0000
@@ -232,7 +232,7 @@ sub read_ops
     }
 
     #
-    # Accummulate the code into the op's body:
+    # Accumulate the code into the op's body:
     #
 
     if ($seen_op) {
@@ -301,6 +301,7 @@ sub make_op
       #   expr OFFSET(X)     {{^+X}}  PC + X        Relative address
       #   expr NEXT()        {{^+S}}  PC + S        Where S is op size
       #   expr ADDRESS(X)    {{^X}}   X             Absolute address
+      #   OP_SIZE            {{^S}}   S             op size
       #
       #   HALT()             {{=0}}   PC' = 0       Halts run_ops loop, no resume
       #
@@ -327,6 +328,7 @@ sub make_op
       $absolute ||= $body =~ s/\bgoto\s+ADDRESS\(\( (.*?) \)\)/{{=$1}}/mg;
                     $body =~ s/\bexpr\s+OFFSET\(\( (.*?) \)\)/{{^+$1}}/mg;
                     $body =~ s/\bexpr\s+ADDRESS\(\( (.*?) \)\)/{{^$1}}/mg;
+                    $body =~ s/\bOP_SIZE\b/{{^$op_size}}/mg;
 
       $branch   ||= $body =~ s/\bgoto\s+OFFSET\((.*?)\)/{{+=$1}}/mg;
                     $body =~ s/\bgoto\s+NEXT\(\)/{{+=$op_size}}/mg;
Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.260
diff -p -u -b -r1.260 core.ops
--- core.ops    23 Feb 2003 09:58:29 -0000      1.260
+++ core.ops    23 Feb 2003 19:19:09 -0000
@@ -16,16 +16,6 @@ core.ops
 
 Parrot's core library of ops.
 
-=head1 NOTE
-
-Some branching ops use B<CUR_OPCODE + size> as branch destination and
-not B<expr NEXT()>. This is done, to get a branch destination in terms
-of offsets in the normal core, and not in terms of the running core.
-
-This is needed, for all branching ops, that might leave the actual
-core, so that the branch offset can be recalculated to the other core,
-Currently used in the native run core generated by B<pbc2c.pl>.
-
 =cut
 
 # ' for emacs
@@ -3799,7 +3789,7 @@ stack for later returning.
 =cut
 
 inline op bsr (in INT) {
-  stack_push(interpreter, &interpreter->ctx.control_stack, CUR_OPCODE + 2,  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
+  stack_push(interpreter, &interpreter->ctx.control_stack, expr NEXT(),  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
   goto OFFSET($1);
 }
 
@@ -3815,7 +3805,7 @@ location onto the call stack for later r
 
 inline op jsr(in INT) {
   opcode_t * loc;
-  stack_push(interpreter, &interpreter->ctx.control_stack, CUR_OPCODE + 2,  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
+  stack_push(interpreter, &interpreter->ctx.control_stack, expr NEXT(),  
STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL);
   loc = INTVAL2PTR(opcode_t *, $1);
   goto ADDRESS(loc);
 }
@@ -4592,7 +4582,7 @@ inline op invoke() {
   opcode_t *dest;
   PMC * p = interpreter->ctx.pmc_reg.registers[0];
 
-  dest = (opcode_t *)p->vtable->invoke(interpreter, p, CUR_OPCODE + 1);
+  dest = (opcode_t *)p->vtable->invoke(interpreter, p, expr NEXT());
 
   goto ADDRESS(dest);
 }
@@ -4601,7 +4591,7 @@ inline op invoke(in PMC) {
   opcode_t *dest;
   PMC * p = $1;
 
-  dest = (opcode_t *)p->vtable->invoke(interpreter, p, CUR_OPCODE + 2);
+  dest = (opcode_t *)p->vtable->invoke(interpreter, p, expr NEXT());
 
   goto ADDRESS(dest);
 }
Index: lib/Parrot/Op.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/Op.pm,v
retrieving revision 1.9
diff -p -u -b -r1.9 Op.pm
--- lib/Parrot/Op.pm    22 Apr 2002 02:40:59 -0000      1.9
+++ lib/Parrot/Op.pm    23 Feb 2003 19:19:09 -0000
@@ -202,6 +202,7 @@ sub _substitute {
   s/{{-=([^{]*?)}}/     $trans->goto_offset(-$1); /me;
   s/{{=([^*][^{]*?)}}/  $trans->goto_address($1); /me;
 
+  s/{{\^(-?\d+)}}/      $1                        /me;
   s/{{\^\+([^{]*?)}}/   $trans->expr_offset($1);  /me;
   s/{{\^-([^{]*?)}}/    $trans->expr_offset(-$1); /me;
   s/{{\^([^{]*?)}}/     $trans->expr_address($1); /me;
Index: lib/Parrot/OpsFile.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpsFile.pm,v
retrieving revision 1.31
diff -p -u -b -r1.31 OpsFile.pm
--- lib/Parrot/OpsFile.pm       22 Jan 2003 15:57:24 -0000      1.31
+++ lib/Parrot/OpsFile.pm       23 Feb 2003 19:19:09 -0000
@@ -232,7 +232,7 @@ sub read_ops
     }
 
     #
-    # Accummulate the code into the op's body:
+    # Accumulate the code into the op's body:
     #
 
     if ($seen_op) {
@@ -301,6 +301,7 @@ sub make_op
       #   expr OFFSET(X)     {{^+X}}  PC + X        Relative address
       #   expr NEXT()        {{^+S}}  PC + S        Where S is op size
       #   expr ADDRESS(X)    {{^X}}   X             Absolute address
+      #   OP_SIZE            {{^S}}   S             op size
       #
       #   HALT()             {{=0}}   PC' = 0       Halts run_ops loop, no resume
       #
@@ -327,6 +328,7 @@ sub make_op
       $absolute ||= $body =~ s/\bgoto\s+ADDRESS\(\( (.*?) \)\)/{{=$1}}/mg;
                     $body =~ s/\bexpr\s+OFFSET\(\( (.*?) \)\)/{{^+$1}}/mg;
                     $body =~ s/\bexpr\s+ADDRESS\(\( (.*?) \)\)/{{^$1}}/mg;
+                    $body =~ s/\bOP_SIZE\b/{{^$op_size}}/mg;
 
       $branch   ||= $body =~ s/\bgoto\s+OFFSET\((.*?)\)/{{+=$1}}/mg;
                     $body =~ s/\bgoto\s+NEXT\(\)/{{+=$op_size}}/mg;
Index: lib/Parrot/OpTrans/Compiled.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpTrans/Compiled.pm,v
retrieving revision 1.10
diff -p -u -b -r1.10 Compiled.pm
--- lib/Parrot/OpTrans/Compiled.pm      3 Feb 2003 16:18:59 -0000       1.10
+++ lib/Parrot/OpTrans/Compiled.pm      23 Feb 2003 19:19:09 -0000
@@ -16,7 +16,6 @@ use vars qw(@ISA);
 sub defines
 {
   return <<END;
-#define CUR_OPCODE cur_opcode
 #define REL_PC (cur_opcode - start_code)
 #define IREG(i) interpreter->ctx.int_reg.registers[i]
 #define NREG(i) interpreter->ctx.num_reg.registers[i]
@@ -85,9 +84,17 @@ sub goto_address
 }
 
 
+#
+# expr_offset()
+#
+# On offset expression is always an offset from start_code, because
+# the 'ret' instruction may be in a different runops core. 'ret' will
+# always treat saved addresses as relative to start_code, because that
+# interpretation is global across all runops cores.
+#
 sub expr_offset {
     my ($self, $offset) = @_;
-    return sprintf("&&PC_%d", $self->pc + $offset);
+    return sprintf("start_code + %d + %s", $self->pc, $offset);
 }
 
 #

Reply via email to