# New Ticket Created by "Clinton A. Pierce"
# Please include the string: [netlabs #716]
# in the subject line of all future correspondence about this issue.
# <URL: http://bugs6.perl.org/rt2/Ticket/Display.html?id=716 >
Background:
String variables in BASIC are stored in the P21 PMC. When I ty to
set a variable I say:
save "variablename"
save "value"
bsr SSTORE
And to restore it I call:
save "variablename"
bsr SFETCH
The code for these is located in basicvar.pasm and for your convenience:
SSTORE: pushs
restore S1 # Value
restore S0 # Name
set P21[S0], S1
pops
ret
SFETCH: pushs
pushi
restore S0 # Name
set S1, P21, S0
length I0, S1 # Works around an odd bug (may no longer exist)
ne I0, 0, SNOTNULL
set S1, ""
SNOTNUL: save S1
popi
pops
ret
When I run this code the store looks like this (from parrot -t):
PC=2241; OP=703 (bsr_ic); ARGS=(-1043)
PC=1198; OP=676 (pushs)
PC=1199; OP=693 (restore_s); ARGS=(S1="Y")
PC=1201; OP=693 (restore_s); ARGS=(S0="HELLO")
PC=1203; OP=215 (set_keyed_p_s_s); ARGS=(P21=002F8040, S0="Y", S1="HELLO")
PC=1207; OP=672 (pops)
PC=1208; OP=738 (ret)
The bsr's there, the push, two restores and the proper call to set_keyed.
Now when I go to fetch that value:
PC=5277; OP=703 (bsr_ic); ARGS=(-4068)
PC=1209; OP=676 (pushs)
PC=1210; OP=674 (pushi)
PC=1211; OP=693 (restore_s); ARGS=(S0="Y")
PC=1213; OP=152 (set_s_p_s); ARGS=(S1="Y", P21=002F8040, S0="Y")
Cannot fetch string out of non-string key!
There's the bsr, I save off the string and integer pointers restore the
variable name to fetch and then try to fetch it...and it crashes.
Notes:
* Other than the "new", these are the only keyed accesses to P21
in the trace.
* To reproduce for yourself:
1. Start basic.pl
2. Type LET Y$='HELLO'
3. Type PRINT Y$
* Curiously enough, fetching on a key that doesn't yet exist doesn't
(and correctly doesn't) throw this error and just returns the empty
string. [So if you leave off the LET Y$ part of the example off, it
works fine.]
Good luck.