Awsome!! 
Great idea Ingy!

> I went out to breakfast here in Seattle with my laptop and played
> around with
> Attribute::Handlers. Here's what I came up with:
> 
>     use Inline C => ATTRIB;
> 
>     print dubble(10), "\n";
>     print bubble(10), "\n";
>     print trubble(10), "\n";
> 
>     sub dubble :inline('int dubble(int n)') {q{
>       return x * 2; /* yes, this is C code */
>     }}
> 
>     use Inline C => q{
>     int bubble(int n) {
>       return x * 2;
>     }
>     };
> 
>     sub trubble :inline {{
>       int x = SvIV(ST(0));
>       XSprePUSH;
>       PUSHi((IV)(x * 2));
>       XSRETURN(1);
>     }}
> 
> So what's going on here? Well, first of all, all C compilation is now
> happening at Perl compile time, thanks to Attribute::Handlers. This
> is
> good. I played with A::H, and it definitely give me all the right
> info
> at the right time to do the right thing!
> 
> The functions dubble, bubble and trubble all do the same thing. The
> difference is how they are implemented at the glue (XS, etc) layer.
> At
> this level they are quite different.
> 
> First dubble. This elegant creature has automatic typemapping
> provided
> by the function prototype that is passed in thru the :inline()
> attribute. Internally it has no wrapper though. It uses PPCODE style
> glue. This means that dubble() can only be called from Perl, not from
> C.
> Dubble would probably be slightly faster than bubble.
> 
> bubble() is the traditional Inline style. It creates a glue wrapper
> that
> calls the real bubble. That means bubble can also be called from C.
> 
> trubble() is the most trouble to write, but it gives you almost full
> control.
> No free typemapping to worry about. ;) trubble() would probably be as
> fast as
> you could get.
> 
> ---
> 
> You could argue that besides the slight potential speedups, this is
> just a
> distraction. Maybe, but I just thought of one thing you can do with
> this
> style that you can't with the old. Perl prototypes!
> 
> Suppose you want a subroutine that works with arrays:
> 
>     use Inline C => ATTRIB;
> 
>     my_push(@foo, $bar);
> 
>     sub my_push(\@$) :inline('void my_push(AV* av, SV* sv)') {q{
>         ...
>     }}
> 
> We can now get this behaviour for free, using the real Perl prototype
> syntax. No inventing some comment embedded prototype hinting hack,
> like
> we've discussed in the past.

Cool.

This is really good news.

Sorry to just give positive comments, I will have to think some more to
find something to complain about ;)

mik3e

=====
James Michael DuPont
http://introspector.sourceforge.net/

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com

Reply via email to