Polyconf
09/06/2015
Edit: So polyconf happened and it was great. You can see a video of my talk here. Enjoy!
In December last year Cello recieved another round of publicity when it got posted to Reddit and Hacker News. Response was great and it got me thinking again about a whole load of things I wanted to do with Cello. Since then I've been quietly working on a completely new version of Cello which personally I think is a huge improvement. I was also invited to speak at Polyconf which I was really chuffed about, and providing I get it all done in time I should be speaking about some of the new things there, so if you want to talk to me in person, or hear any of the other awesome talks, please attend!
Providing I get everything I want done in time you can expect a big Cello update in the next few weeks. I've completely revamped the website and written a few more articles about some of the new features. Everything should be much easier to use and navigate. But before any of that gets uploaded here is a little preview of the things I've been working on:
Fat Pointers
I've completely restructured how Cello worked internally. I've borrowed some ideas from Walter Bright's Fat Pointers and the C sds strings library, and Cello now stores all of its meta-data about an object in the memory before the pointer to the object. The really neat thing about this is that it means Cello pointers are completely compatible with standard C pointers - and you can mix normal C and Cello seamlessly. Before you needed to do everything in a Cello way and it felt like a totally new language - now Cello feels much more like C, just with a bunch of sweet additional features.
Performance
When I finally got around to benchmarking the previous version of Cello it was insanely slow. There was a huge amount of overhead for calling a Cello function and the data structures sucked as well. With the current version I've benchmarked Cello pretty extensively and now the performance is really impressive (even if I say so myself). The overhead of calling a Cello function is roughly the same as a C++ virtual call and all of the data structures have been revamped to be state-of-the-art. The performance now sits somewhere between C++ and Java. But even more importantly, because Cello now interacts so well with standard C, if you ever do need that final bit of performance you can just drop to standard C and get it.
Garbage Collection
One of the things I really wanted to try to add to Cello was optional Garbage Collection. Previously I had sworn that it would be impossible, but I started to get a few inklings about how it might be done (in some form or other) and after following on from those I managed to find a compromise that adds a kind of Garbage Collection for Cello objects and is both simple, and portable. To my suprise the performance wasn't too terrible either. So now Cello has a pretty nice kind of optional Garbage Collection. Probably my poudest addition!
Type Definition
In the previous version of Cello writing type definitions was insanely labourious. You had to implement about 20 functions just to make your object in the slightest way useful, and use 5 different macros in weird complicated ways. In the current version you can define a Cello type in a single line of code, with a single macro, and instantly get lots of useful default implementations for most of the library type classes. Combined with C compatibility now you there is really nothing to lose by making your C structures Cello compatible. One line and you're ready to go.
Portability
One of the main issues people had with the previous version of Cello was that it used some C extensions for some of the advanced featuers. This included things like GNU nested functions and Clang blocks which are definitely not part of normal C. The current version only uses two extremely common C extensions (dollars in identifiers and variadic macro pasting) and is therefore compilable with all of the major C compilers including gcc
, clang
, tcc
(on the dev branch), and even cl.exe
(Visual Studio). This does mean closures are dropped from the feature list - but it was probably for the best.
Documentation
Cello Documentation is now built into the language. In fact - the website documentation is just generated using a simple Cello script. Having the documentation avaliable from the library is nice (you can just call help
on some type), but more importantly because the code and documentation is in the same place there is less chance of it getting out of sync - all pull requests go to the main repo.
Iterables
The new version of Cello has python3 style iterables. Although the syntax isn't as nice as python this does mean you can do neat things like use slices, filters, and maps on any iterable type. Special care has also been taken to ensure these types can be constructed on the stack so the overhead should be as small as possible.
Debugging
Having a runtime layer provides an easy way to insert all of the runtime checks that are missing from standard C programming. In the new version of Cello these are everywhere. It performs out of bounds checks, out of memory checks, IO checks, etc, etc. And if there is a runtime error an exception will be thrown and you get a nice error message and a stack trace. Once you're program is running correctly all of these checks can be disabled using -DCELLO_NDEBUG
to get C style "don't pay for what you don't use" performance. Before when Cello was used incorrectly all I could do was shrug and point at C, but now it should really be able to give a helping hand, and ideally, no more segfaults!