Bryan --

> > > static void **
> > > prederef(void ** pc_prederef, struct Parrot_Interp * interpreter)
> > > {
> > >   size_t      offset = pc_prederef - interpreter->prederef_code;
> > >   opcode_t *  pc     = ((opcode_t *)interpreter->code->byte_code) +
> > > offset;
> >
> > This is supposed to be calculating offset = # opcodes not # bytes.
> > I didn't look it up, and I don't do lots of address arithmetic code,
> > but I assumed that pointer differences give offsets that can be passed
> > into array indexing / pointer arithmetic to get back where I want. 
> 
> Offsets are given in terms of the objects pointed to.  In the above code, 
> you've two pointers to pointers, so the byte difference would be offset * 
> sizeof(void *).  But then you add that offset to a pointer to an opcode_t, 
> so the byte difference would be offset * sizeof(opcode).

OK. So it sounds like offset gets set to the equivalent of the array index
to get to pc_prederef from interpreter->prederef_code. That's good. Adding
that to interpreter->code->byte_code (treated as an opcode_t *), gets us
to the corresponding opcode of the bytecode array.

> I didn't mean to be alarmist - if you've a one-to-one mapping between the 
> opcode_t stream and the corresponding void * stream, then you're safe, as 
> you're simply scaling the sizes.

Yes. There's a one-to-one mapping.

> But you may want to document that.  It's quite scary looking on first 
> glance.  :-)

:)    OK. I'll slap some comments on it next time I'm in there. Thanks
for taking the time to examine the code.


Regards,

-- Gregor

Reply via email to