in PIR, a BigInt is turning into a string against my will -- what am I doing wrong?

0 views
Skip to first unread message

Eric Hanchrow

unread,
Feb 17, 2007, 12:21:45 PM2/17/07
to perl6-i...@perl.org
(This is with parrot built from the subversion trunk, revision 16999)
Here's a bit of PIR that demonstrates my problem:

.sub 'main' :main
load_bytecode 'dumper.pir'
.local ResizablePMCArray fields
split fields, ",", "hey,you"
_dumper (fields)

.local pmc big
new big, .BigInt
_dumper (big)

set big, "1234567890987654321"
_dumper (big)

unshift fields, big
_dumper (fields)
.end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
./parrot mutate.pir
"VAR1" => ResizableStringArray (size:2) [
"hey",
"you"
]
"VAR1" => PMC 'BigInt' { ... }
"VAR1" => PMC 'BigInt' { ... }
"VAR1" => ResizableStringArray (size:3) [
"1234567890987654321",
"hey",
"you"
]

;;;;;;

what's puzzling is that "big" starts out as a BigInt, but seems to get
transformed into a string when I put it into the array. I wanted that
last dumped value to contain a BigInt followed by two strings, but
instead it's three strings. I would have thought that making my
"fields" variable be a ResizablePMCArray would have sufficed to ensure
that, but as far as I can tell, "fields" gets transformed from a
ResizablePMCArray to a ResizableStringArray after I assign the return
value of "split" from it. What must I do to get what I want?

Thanks
--

ハ ハ
ミ^・^ミ
`~~~´

Patrick R. Michaud

unread,
Feb 17, 2007, 10:27:05 PM2/17/07
to Eric Hanchrow, perl6-i...@perl.org
On Sat, Feb 17, 2007 at 09:21:45AM -0800, Eric Hanchrow wrote:
> (This is with parrot built from the subversion trunk, revision 16999)
> Here's a bit of PIR that demonstrates my problem:
>
> .sub 'main' :main
> load_bytecode 'dumper.pir'
> .local ResizablePMCArray fields
> split fields, ",", "hey,you"

AFAIK, symbols like fields can't be typed beyond int, num, string, or
pmc. So the ".local" statement above should read:

.local pmc fields

The 'split' opcode always returns a ResizableStringArray.
It might be easier to think of it as

fields = split ",", "hey,you"

(You can actually write it this way -- it's the same thing.)

So, when the BigInt is unshifted into the ResizableStringArray,
it's morphed into a string.

Hope this helps. :-)

Pm

Reply all
Reply to author
Forward
0 new messages