On 08/10/02 12:24 -0700, Brian Ingerson wrote:
> Hi all,
>
> I'm heading up to Seattle for the night to help a group of people
> bootstrap a project to get Inline functionality into Ruby. Should be
> interesting. I'll let you know how it turns out.
Well, I went to the meeting. The Ruby guys have a very simple Inline module
but it works. It is very different from Perl's Inline.
The best way to describe it is to show an example of how it might work in
Perl:
use Inline qw(inline);
print "Two dozen is ", dubble(12), "\n";
sub dubble {
inline q{
int x = SvIV(ST(0));
XSprePUSH;
PUSHi((IV)(x * 2));
XSRETURN(1);
}
}
So the first time dubble is called, it compiles/loads a single function
shared object call main_dubble.so. The cool part is that the symbol table is
then hacked to point to the C version instead of the Perl wrapper. That's
about it. They do the whole thing in a very small amount of code.
The obvious drawbacks are:
- No typemapping
- Must work the stack yourself
- Happens at runtime
- Lots of little single function objects
- Probably for scripts only
Still, I think it's clever and very tight. The one thing Inline::C can't do
is let you write unwrapped PPCODE style functions. Maybe this is a way to do
that. If we could rework it so that all the code got collected into one
shared object, then we could use it for modules as well.
Does anybody know how attributes work in Perl. I've never used them. Could I
do something like this:
use Inline C => INLINE;
sub dubble :inline {q{
int x = SvIV(ST(0));
XSprePUSH;
PUSHi((IV)(x * 2));
XSRETURN(1);
}}
and get all the right info at compile (or at least CHECK) time?
Cheers, Brian