At 9:04 PM +0100 12/2/03, Sterling Hughes wrote:
Hey,

I'm right now looking at getting a proper implementation of array/string
offsets done for the PHP compiler.

Here's the problem, in PHP you can access indices of both string's an
array's in the same way, meaning:

[Snip PHP treating strings as character arrays]


To have this available easily using Perl's types, get_pmc_keyed() would
need to be implemented in the PerlString PMC.  Currently (for the sake
of nice looking mandelbrot demos), we just assume is a native string and
do the offset from that string (which parrot/imc does support.)

Should PerlString support a get_pmc_keyed() method (according to Perl
5/6 semantics), or is this a point where its about time to start implementing
our own PMCs?

This... could be a problem. Perl, using a perl string as an array, should treat it as a symbolic reference if that's enabled. And, strictly speaking, if PHP is handed a PerlInteger it ought to treat it the same way as a PerlString. Or not, but it'd be reasonable as they're really facets of the same base type.


I can see a number of solutions here, some of which involve compiler hackery. The thing that first springs to mind is to have the PHP compiler emit a check of some sort before use, and either do array access or substring access. That's got a certain appeal to it, as it means we don't have to do anything. :) (Well, not true--we have to provide sufficient easily queryable metadata to tell if a variable is more or less an array, or a string, but we ought to so that anyway)

If that's not a reasonable option, and I can see it not being so, that makes things somewhat more interesting. Definitely calls for at least one custom PMC for PHP, and potentially an automatic wrapping function to throw a PHPStringWrapper (or whatever) around anything stringlike that comes back from an 'external' function call. That requires a bit more work on parrot's part, though, and, while I'd like to do this at some point (for JVM and .NET native library wrapping) I hadn't intended to do it yet, for lack of time and need.
--
Dan


--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to