On 26/09/02 11:42 -0700, Neil Watkiss wrote:
> Brian Ingerson [26/09/02 11:27 -0700]:
> > I sometimes wish that typemaps could be improved upon. They are not
> > quite XS. They are just the little transformations that are so common
> > that you want to factor them out of your code and into a common place.
> >
> > For instance, if every Inline function you wrote looked like:
> >
> > SV* foo(SV* x, SV* y) {
> >
> > You wouldn't need any typemaps. You'd just disassemble and reassemble
> > all the SVs right in your function.
>
> Gisle Aas, author of libwww-perl, actually prefers this even for quite large
> projects :)
>
> > I actually like this approach better for small to medium projects. Even
> > if you start accumulating duplicate code, you can refactor the type
> > mapping stuff into internal static functions. The C compiler may very
> > well inline them anyway, so no performance worries. The nice thing about
> > avoiding typemaps is that your code stays in the Perl source file. That
> > is especially nice for CPAN modules, where any custom typemaps would be
> > tossed after build/installation.
>
> Would it be possible to extend Inline so this could work?
>
> use Inline C => <<'C_CODE', TYPEMAP => <<'TYPEMAP';
>
> /* some C code */
>
> C_CODE
>
> # Typemap!
>
> TYPEMAP
>
> Perhaps the interface could be improved somewhat, but the idea is you keep
> the typemap right there with your C code, and Inline writes it to a typemap
> for you before compiling. Does that make sense?
It does make a certain amount of sense. This was the train of thought I
was following when I realized, "Hey. Why not just put the typemaps right
in the code?". Short ones could be macros and longer ones could be
static functions. Certainly people are more familiar with these, than
with the typemap syntax. I'd like to know of a situation where using the
above syntax would be more elegant.
One other radical approach I'm considering is to invent an Inline syntax for
embedding extra Inline semantics write into the C source. I would probably do
this using specially formatted comments. For instance:
use Inline C
__END__
__C__
/* Inline: typemap: 'foo *'
*typemap code here*
*/
void bar(foo* my_foo) {
}
We've discussed this technique before for prototyping.
I've started working with Hugo on integrating parts of Inline into
5.9. The idea is that we'll be able to port many of the existing XS
modules to Inline. This means that Inline will have some fairly
sophisticated use cases. As we search for ways to integrate some of XS
more subtle capabilities, I would consider techniques like the above
for filling in the gaps.
Cheers, Brian