At 03:01 PM 9/9/2002 -0400, Aaron Sherman wrote: >I'd like to start a dialog
And since this thread is quiet, I'll throw some uneducated opinions on it to help it along. >about the P[arrot|erl] interface on the >matter of converting low-level types. ord and chr are Perl functions for >doing two very specialized conversions, but I'm thinking Parrot needs to >provide a general-purpose number/[bit]?string conversion ala Perl's >pack/unpack so that all of the conversion functions for all of Parrot's >client languages can be written in terms of them. I was kind of surprised to see ord as a core op when I was doing BASIC. And had actually written my hack to go both ways (chr/ord) in an early version of the interpreter. >Certainly sprintf, pack and unpack in Perl should use some underlying >tool of Parrot's, and not re-invent the wheel (though each of those will >obviously do heavy argument processing in a Perl-specific way, some of >which I've already done for sprintf). > >Should these conversions be individual instructions (e.g. "uint2string") >or should there be a single-target "pack" analog in the PBC? I like the idea of having a single pack/unpack instruction, with some kind of argument mechanism to determine exactly how to pack. I don't know of an analogue in other CPU instruction sets (except maybe BCD ops in 8086), as they're typically not interested in something as high minded as some of this is. And while we're wishing, I'm certain I wouldn't want it as platform dependant as Perl's pack() is. I'd like to be able to easily determine if I'm working with native ints or some other kind of int. If I want to I'd like to pack my ints to 16, 32, or 64 bits on a whim. Use BCD and BER and any other strange encoding schemes I want. And I want a pony, too. Something else to throw into the discussion is whether we want to use a template (at the PBC level) as pack does or not. My initial gut reaction is no, because then we'd wind up with things like: pack S0, "ccxxcc", P0 # where P0 is a PerlArray or something And I'm not sure if 1. the pack target should be a "string" or not and 2. if I really want to have to mess with a PerlArray just to do some byte-shifting in PBC. But not using a template means having to possibly execute lots of instructions to disassemble the source piece-by-piece, and keeping this canned set of PBC around as a library to do common functions. Then again, I drool at the prospect of doing an sprintf in PASM...