Edwin Steiner wrote:
> [...]
> As to strong typing: I don't expect that it will be possible on the
> really low level. Of course it's no problem when calling C-functions
> with arguments on the C-stack. But if you have a virtual stack machine
> (Perl stack) or even convert to machine code (TIL) you loose type-safety
> anyway.
>
> I took the following from the Perl 5.7.0 source (pp.c):
>
> PP(pp_av2arylen)
> {
> djSP;
> AV *av = (AV*)TOPs;
> [...]
> }
>
> You see, while the Perl5 stack is a stack of SV*s it is used to hold
> an AV* without any scruples. It really wouldn't make any sense to
> wrap the AV* in a scalar ref just to call an opcode function.
> So making sp an SV** is mainly for convenience because you don't have
> to cast in the majority of cases, not for type-safety.
>
> My point is that while it is perfectly possible to use different
> pointer types it might not make much sense (at least not for type-safety
> on the lowest level).
>
Agreed, but I think there's a difference for functions used by C extensions:
int av_len(AV *);
/* I guess I can't pass a SV* here without an explicit cast, right? */
vs.
int av_len(SV *);
This is silly, but you can see that, at least in 5.005, sv_magic takes a
SV*, even when assigning magic to an array or a hash. However I agree that
SV* is a good base type for PMC's, so that the stack being SV** is ok. void*
would be much worse!!!
> I thought of the `tie'-like thing because of Dan's:
>
> " The vtable stuff won't be exposed outside the core. This means embedding
> programs and extensions will *not* be using it. Generally speaking,
it'll
> be opcode functions only that'll be hitting the vtables. "
I understand the point of view. I think Dan believes the vtable API is too
complicated to cope with directly, but I actually disagree with that. I
prefer one structure where all the functions are grouped rather than having
several sv_, av_, ... functions. And nothing more direct to tie a variable
than fill in the function pointers in a (v)table, rather than calling
sv_magic, casting the array to (SV*), setting the entry '~' of the magic
table, lighting some candles, and singing something exoteric.
- Branden