At 12:01 PM 8/2/00 +0100, Andy Wardley wrote:
>Nick:
> > PUSHMARK;
> > XPUSHs(sv_2mortal(newSVpv('DeepThought'));
> > XPUSHs(sv_2mortal(newSViv(42));
> > PUTBACK;
> > count = perl_call_method("Consider",G_EVAL);
> > SPAGAIN;
> > if (count >= 1) {
> >   answer = SvIV(POPs));
> > }
> >
> >You _want_ to keep that???
>
>Tim:
> > There may be scope for having two levels of API. One high level clean
> > simple etc and the other a lower-level more performance oriented API.
> > The former could be implemented in terms of the latter.
>
>Indeed.  XS is hard, fast, dirty and ugly (in a sickly, beautiful
>kinda way), but there's nothing to stop you from wrapping it all up
>into a less efficent, but prettier API (with the possible exception
>of reference counting).

Reference counting is going to be a fun one, that's for sure.

I'd like the interface to be something like:

   stat = perl_get_value(sv *, int what, &destination)

with shortcut functions for the common cases (int, float, string) of:

   stat = perl_get_int(sv *, &destination)

Presumably in the implementation perl_get_int would just call the sv's 
gimme_int function and return the result. If at some point we yank out the 
guts of an sv and replace it with something else the functions would behave 
differently behind the scenes, but still work OK for extensions, since they 
don't know squat about the guts of an sv.

There may be a speed hit with the extra layer of abstraction, but there may 
not be, and even if there is it might well get lost in the noise. I'll 
withhold judgement until we've got something to look at.

>One of the nice things about the Ruby API is that there is an (almost)
>1:1 mapping between what you can do in the Ruby language and what you
>can do in the Ruby API.
>
>The clarity of the API makes it fairly painless to take a Ruby module
>and re-write it in C for speed and efficiency.  Even if they're not
>getting the raw, low-level performance of XS, they're getting bigger
>wins than running interpreted code.

I hadn't considered this as a target, but it does make quite a bit of 
sense. Perl could certainly benefit from something like this, though I 
think one of the targets is efficient byteloading and bytecompiling of 
modules that might mitigate this some. OTOH, nothing beats code compiled to 
assembly for speed. (Well, usually...)

Now if you'd all excuse me, I've a bunch of RFCs to get written. :)

                                        Dan

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

Reply via email to