Returning a variable reference

Ross Hutton hutton at
Wed Nov 24 01:36:41 CET 1999

Thanks to both Ben and Tom for their suggestions: The problem isn't
just one of indirection. It's being able to point inside (and modify) 
different lists with the same variable which I think is a NoNo in python
(most likely for safety reasons as pointed out by Ben). I should have been
more specific about the particular problem in my original post.

I think I've come up with a more appropriate solution (skip to end of post
if you're interested).

>Here's an idea; objects are lvalues. An excessively simple example
Problem with this is I need an lvalue that can point into either one
of two pre-existing lists.

>Uhm... Actually I think you're making trouble for yourself.  Use a
>list (or an array if you want bytewise access and can't afford to
>waste a little memory) for your memory area and return the index as
>your "address".  

I'm already doing this. I use separate lists for memory and
registers. Problem is that the same instruction needs to be able to
modify an element of either depending on an embedded 'rrr' code (eg:
A=111, B=000, (HL)=110).

At present I use a separate decoder routine that matches an opcode to
a valid z80 instruction and extracts the rrr code(s) if present. It
would be very nice for this routine to return an lvalue (that could
point to an element of either the register list or the memory list) for the
subsequent z80 instruction to use/modify. 

At present for every instruction that could be direct/indirect I
insert code to handle the indirect case as a special case (not very clean).

Another solution that I thought of is to reserve an area in the memory
list for all the registers to point to and make every register access
an indirect one.

Ahh, I think I've just seen the light. Rather than trying to pass an
lvalue up the chain I should be passing the rrr code down to lower
access functions (get(rrr) and set(rrr,value)) and have them do the
dirty work.

Many thanks again to Tom and Ben for their suggestions. You got me talking
to myself and that's probably not such a bad thing. 

It's quite interesting learning Python which is in many ways a lovely
language (problem is that I keep thinking in C). I was amazed when I
did some function pointer work without even looking in a manual. I
just assigned a function to a variable and called the variable as a
function. I just wrote code the way I thought it should work (and was
quite surprised when it did).

Ross (remove all chaff to reply)

More information about the Python-list mailing list