Re: Announcing C::Blocks, a different way to interface Perl and C code

[email protected] (David Mertens) Mon, 3 Aug 2015 20:53:25 -0400
Newsgroups perl.xs,perl.inline
Message-ID <CA+4ieYVChw2QPW_WccZSAHC_ieJs_iiJUQJ78j0wTzqxgu-93A@mail.gmail.com>
--001a11c31528b159c0051c71b6c0
Content-Type: text/plain; charset=UTF-8

A follow-up to this email:

On Fri, May 23, 2014 at 8:35 AM, David Mertens <[email protected]>
wrote:

> Hey everyone,
>
> C::Blocks is a new TinyCC-based module, presently only available on
> github. (1) It jit-compiles blocks of C code, building and inserting OPs
> into the Perl OP tree, making invocation of C code essentially free. (2) It
> will allow different blocks of C code to share function and struct
> declarations, thus removing the need to always recompile perl.h, an
> otherwise major cost of jit-compiling C code that can interface with Perl
> and Perl data structures.
>
> I am currently seeking help and encouragement to squash the segfaults that
> currently prevent the completion of the second feature. :-)
>

It took a lot longer than I had expected, but I finally completed the
second feature listed above and released the first "alpha" release of
C::Blocks <https://metacpan.org/pod/C::Blocks> today.

It took a long time because ultimately I had to create my own fork of the
Tiny C Compiler <https://github.com/run4flat/tinycc> that supports extended
symbol tables. I released an Alien distribution
<https://metacpan.org/pod/Alien::TinyCCx> with (what I believe to be a
nearly complete implementation of) extended symbol table support late last
week, and it seems to be passing its test suite decently well
<http://matrix.cpantesters.org/?dist=Alien-TinyCCx+0.06> on a fair number
of platforms. Alien::TinyCCx is doing particularly well on Linux and decent
on Windows. I'm a bit annoyed it's not passing on Macs because it works on
my Mac. That'll get fixed soonish, I hope.

It's still rough around the edges, but it's surprisingly fast. I have a
number of examples
<https://metacpan.org/source/DCMERTENS/C-Blocks-0.01/examples> that might
give you an idea of how it works. I am particularly fond of my "port"
<https://metacpan.org/source/DCMERTENS/C-Blocks-0.01/examples/libobjmg.pl>
of XS::Object::Magic <https://metacpan.org/pod/XS::Object::Magic>, which
simply involved copying the top half of rafl's code from his Magic.xs
<https://metacpan.org/source/FLORA/XS-Object-Magic-0.04/Magic.xs> file into
a cshare block.

I plan to write more about it on blogs.perl.org, so I would encourage folks
to check there if interested.

David

--001a11c31528b159c0051c71b6c0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">A follow-up to this email:<br><div><div><div class=3D"gmai=
l_extra"><br><div class=3D"gmail_quote">On Fri, May 23, 2014 at 8:35 AM, Da=
vid Mertens <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]=
m" target=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><div>Hey everyon=
e,<br><br></div><div> C::Blocks is a new TinyCC-based module, presently onl=
y available on github. (1) It jit-compiles blocks of C code, building and i=
nserting OPs into the Perl OP tree, making invocation of C code essentially=
 free. (2) It will allow different blocks of C code to share function and s=
truct declarations, thus removing the need to always recompile perl.h, an o=
therwise major cost of jit-compiling C code that can interface with Perl an=
d Perl data structures.<br>
</div><div><br></div><div>I am currently seeking help and encouragement to =
squash the segfaults that currently prevent the completion of the second fe=
ature. :-)<br></div></div></div></div></div></blockquote></div><br></div><d=
iv class=3D"gmail_extra">It took a lot longer than I had expected, but I fi=
nally completed the second feature listed above and released=20
the first &quot;alpha&quot; release of <a href=3D"https://metacpan.org/pod/=
C::Blocks">C::Blocks</a> today.<br><br>It took a long time=20
because ultimately I had to create <a href=3D"https://github.com/run4flat/t=
inycc">my own fork of the Tiny C Compiler</a>=20
that supports extended symbol tables. I released an <a href=3D"https://meta=
cpan.org/pod/Alien::TinyCCx">Alien distribution</a> with (what I believe to=
 be a nearly complete implementation of)=20
extended symbol table support late last week, and it seems to be <a href=3D=
"http://matrix.cpantesters.org/?dist=3DAlien-TinyCCx+0.06">passing its test=
 suite decently well</a> on a fair number of platforms. Alien::TinyCCx is d=
oing particularly well on Linux and decent on Windows. I&#39;m a bit annoye=
d it&#39;s not passing on Macs because it works on my Mac. That&#39;ll get =
fixed soonish, I hope.<br><br></div><div class=3D"gmail_extra">It&#39;s sti=
ll rough around the edges, but it&#39;s surprisingly fast. I have <a href=
=3D"https://metacpan.org/source/DCMERTENS/C-Blocks-0.01/examples">a number =
of examples</a> that might give you an idea of how it works. I am particula=
rly fond of <a href=3D"https://metacpan.org/source/DCMERTENS/C-Blocks-0.01/=
examples/libobjmg.pl">my &quot;port&quot;</a> of <a href=3D"https://metacpa=
n.org/pod/XS::Object::Magic">XS::Object::Magic</a>, which simply involved c=
opying the top half of rafl&#39;s code from his <a href=3D"https://metacpan=
.org/source/FLORA/XS-Object-Magic-0.04/Magic.xs">Magic.xs</a> file into a c=
share block.<br><br>I plan to write more about it on <a href=3D"http://blog=
s.perl.org">blogs.perl.org</a>, so I would encourage folks to check there i=
f interested.<br><br></div><div class=3D"gmail_extra">David<br></div></div>=
</div></div>

--001a11c31528b159c0051c71b6c0--