The compiler translates Z-code into PIR, then compiles and runs it. The
image of the Z-file (where the Z-machine stores its global variables
and other useful things) is stored in a global called Image. So if you
need to access one of the Z-machine's global variables, you emit code
like:
.local pmc image
image = global 'Image'
.GET_WORD($I181 , image, 692)
where the last line is a macro that pulls the global variable out of
the Z-machine memory. But Leo was smart and, while translating, says to
only load image (i.e. to only output the first two lines) once per
Z-code subroutine.
Now here's the problem. My Z-code emitted code like this:
if $I17 == 3 goto L1234
.local pmc image
image = global 'Image'
.GET_WORD($I181 , image, 692)
L1234:
print "yes, blah"
.GET_WORD($I182 , image, 692)
If $I17==3, then when we get to the second GET_WORD we exit with an
error because we don't know what image is.
So I think to avoid these problems I need to declare image at the top
of every Z-code sub. My question is, is there any cost associated with
always declaring this array holding 50-500K ints, other than having one
P register always full? Since everything else in the translated code is
integers & strings I'm not really worried about filling my P registers.
The only other option I can think of is keeping track of how my scopes
are nesting while translating, which sounds like a disaster.
This is what I get for trying to develop in PIR after ignoring the
mailing list for 6 months and not reading the basic docs.
Thanks,
-Amir Karger
It's better to write me at myfullname@gmail
Thanks,
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
> So I think to avoid these problems I need to declare image at the top
> of every Z-code sub. My question is, is there any cost associated with
> always declaring this array holding 50-500K ints, other than having one
> P register always full?
No not at all. just emit the 'image' declaration and the global fetch
on top of each subroutine. If image isn't used below, the register
occupied by image will even be reused.
You could even avoid the global lookup (if image isn't used), by making
.GETWORD a bit smarter:
.macro GET_WORD(RES, IDX)
.local pmc image
unless_null image , .$ok
image = global ".."
.local $ok:
.RES = image[.IDX] # or some such
...
.endm
But that's probably not worth the effort.
leo