Parrot-GMP: Random Numbers, Distutils, Plumage, VTABLE overrides

This week many Parrot-teers and Perl hackers (and many of my co-workers) were at YAPC::NA. I originally planned on attending but my car broke down earlier this summer and I had to pay for repairs. While there dukeleto++ (my GSoC mentor) and colomon++ both asked how to install Parrot-GMP. I had been so focused on getting the guts and the test suite together that I had completely neglected my README and had no way of automating an install.

Well, that has been remedied. Distutils is a library that comes with Parrot and can handle the standard Makefile-like tasks. Distutils is also data-driven - I pass it a big hash of information (like what files to build and where) and it does the rest. Building, testing and installing is now a single command.

Plumage. is Parrot's package manager. It handles automating downloading, building, testing, and installing packages that run on top of Parrot. It also handles dependencies on other packages on Plumage. To grab a copy of Parrot-GMP you just need to do `plumage install parrot-gmp`.

With distutils and plumage I also have added some code to check that we meet minimum requirements - a version of Parrot that has a StructView, a somewhat recent version of GMP, and libffi installed. Libffi is only a temporary dependency as it speeds up development for me personally but eventually I'll include code so we don't need it.

While Parrot does detect the presence or absence of GMP, it does not actually store which version of GMP we have available on a system. So I have Distutils compile and run a small C script that prints out some of the #define'd values so we actually verify we have the right version. GMP also has some system-dependent values and types so in the same script I am printing out those as well although currently I am not doing anything with that information.

I've also finished off all of the random functions; plobsing++ helped point me in the right direction regarding how to handle some of the ugly structs inside GMP.

I have begun work on implementing VTABLE overrides for the GMP Integer class. VTABLE overrides will allow us to do things like x = y + z where x, y and z are GMP Integers. I currently have some in place such as get_string which allows us to directly print an Integer without jumping through any hoops. The VTABLE overrides are super convenient and provide transparent interoperability with other numeric types but are slow to use.

Finally, I found that I had actually missed five functions - in the docs they are described as "macros" so my script that parsed the documentation passed over them. Two of them I can actually use through NCI -mpz_cmp_ui and mpz_cmp_si - which compare a GMP Integer to an unsigned or signed integer respectively. The other three - mpz_sgn, mpz_odd_p and mpz_even_p - are not actual functions but inlined macros. This is great for C programmers as this is heavily optimized; this is bad for anyone else who because they can't use these macros. So I wrote these three functions in Winxed and updated the script to correctly pick up the other two.

For next week I think I'll round out my VTABLE overrides and their corresponding tests. I'll also start hacking on some more explanatory docs - how to create a new GMP integer, how to initialize the random state, and other things. Finally, if I have time I'll investigate getting some NQP examples in the repo.