Bernhard Schmalhofer

All posts

Basic OO-features in Pipp

When starting on the ReflectionExtension class for Pipp, I got reminded that some very basic OO-features were not working yet. The good think is that I can all that stuff from Rakudo. So simple inheritance and reading member of class instances are working now.

I also simplified my Test.php. The current test number is now tracked in a global variable. Before that change, the test number had to be passed in from the test script.

Posted on 24 June 2009.

My first PHP extension

PHP Extensions are usually written C and they usually export at least one constant, function, class, resource type or stream to the PHP userspace. So they are pretty much the same as XS-Modules in Perl 5. Extensive information about PHP extension can be found in Sara Golemons book ‘Extending and Embedding PHP’.

The several hundred standard functions of PHP are implemented in terms of extensions. Pipp either needs to reimplement this massive count of functions, or support extensions natively. Being lazy, native support for extensions is the way to go. So let’s see how to create a dummy PHP extension. The following is for Linux and is based on the tutorial 1021-Extension-Writing-Part-I-Introduction-to-PHP-and-Zend. The first step is to build PHP 5.3 with development support. The source can be checked out from a CVS repository. See for details and the password for anonymous CVS access.

mkdir ~/first_php_extension
cd ~/first_php_extension
cvs -d login
cvs -d checkout -r PHP_5_3 php5
Posted on 07 June 2009.

Declaring lexicals within $sth-bind_columns()

Lately I have taken on the maintainance of a legacy Perl 5 script. The script heavily uses the DBI function bind_columns() for retrieving data from a relational database. After some refaktoring I ended up with something like this:

my $sth = $dbh->prepare(<<'END_SQL');
SELECT color, food, num_legs
    FROM pet
my ( $food, $something_else, $color, $num_legs);
$sth->bind_columns( \$color, \$food, $num_legs );
Posted on 05 March 2009.

Pipp has left the nest and moved to github

Pipp, that is PHP on Parrot, has moved to github,

I have not yet tested with an installed Parrot yet. So for now please check out Pipp in a Parrot source dir. See for details.

If you want to play with a cooler language than PHP, then take a look at

Posted on 15 February 2009.

Moved Unlambda and Lazy K to github

Unlambda and Lazy K are two pure functional esoteric programming languages. Leo Tötsch implemented them for Parrot. As language implementation are encouraged to leave the nest, I moved them over to Github.

See for the current list of languages for Parrot.

Posted on 25 January 2009.

Parrot m4 has left the nest

Parrot m4 is an incomplete implementation of GNU m4 on top of parrot. As language implementations are encouraged to leave Parrot’s svn, I have moved the code and the history over to The source can easily be fetched by typing ‘make co-m4’ in the ‘languages’ directory of a Parrot working copy.

I am no longer working on m4, so anybody is welcome to clone it. However I think that porting GNU m4 to Perl 6 would be the more interesting task these days.

The mostly up-to-date list of Parrot HLLs is at

Posted on 18 January 2009.

HQ9+ left the nest

HQ9+,, is a little language the makes a few things easy, and almost all other things impossible.

There is an implementation of HQ9+ for Parrot that is based on the Parrot Compiler Toolkit. For getting my feet wet with git, it moved the source code from Parrot’s svn repository to The migration went very smoothly and git made a good initial impression on me. The instructions on were very helpful. Details on the migration are on

In this migration I simply discarded the svn commit history. For moving other languages to git, it would be handy to have a complete and current git mirror of Parrot’s svn repository.

Posted on 12 January 2009.

Closures for Pipp

In the last days I have been working on supporting closures for Pipp. Yes, you’ve read correctly. The next version of PHP will support real closures. See for a nice writeup.

Closures are connected with lexical variables, so I had I had to rethink the way I handle variables in Pipp. Initially I had the variables outside functions as package variables. Since this doesn’t play well with closures, and as there are problems with included files, I changed those to lexical variables. This was the major part of the work. Thanks to Patrich Michaud for advising me where I should define the lexicals.

After switching to lexicals everywhere I followed my usual approach and tried to do the same as Rakudo does. This worked without hassle for a simple case.


  function gen_indentor ( ) {
      $indention = '+';
      $indentor = function ($line) use ($indention) {
          echo $indention . $line . "\n";

      return $indentor;

  $sub_1 = gen_indentor();

  $sub_1('one plus');


correctly gives:

+one plus

But when I create a second closure I run into problems.


  function gen_indentor ($indention) {
      $indentor = function ($line) use ($indention) {
          echo $indention . $line . "\n";

      return $indentor;

  $sub_1 = gen_indentor('+');
  $sub_4 = gen_indentor('++++');

  $sub_1('one plus');
  $sub_2('four plusses');


incorrectly gives:

++++one plus
++++four plusses

Looks like I need to fiddle some more.

Posted on 01 January 2009.

Pipp is now more boring

Comparing different parsing and tree transformation techniques was for me a major reason for starting work on Pipp. Therefore Pipp had until now support for different frontends:

* Antlr 3: Parsing and tree transformation with Java-based Antlr 3 * PHC: Take XML-output from phc and transform it with XSLT * PCT: Parrot Compiler Toolkit

Lately I found that I only worked on the PCT variant. So in order to keep it simple, especially for new contributors, I removed support for Antlr3 and PHC.

So, Pipp is now more boring, but other exciting things are coming.

Posted on 21 December 2008.

Rewriting Pipp tests in PHP

Pipp is Parrot’s PHP and it has small test suite that lives alongside the code in the Parrot repository. Most of the test scripts are written in Perl 5 using the Parrot::Test modules. So usually I tell Pipp to run some PHP code and check whether the expected result is printed. This works fine but is not very exiting.

More exciting, for some definition of exciting, is to run PHP scripts and emit TAP with a testing lib implemented in PHP. So Pipp this needs 1. user defined functions with param passing 2. global for keeping track of the running test count 3. module loading

Stealing from Rakudo I now got most of that. global is still missing, so currently I pass in the current test number and increment it outside the testing functions.

Over the next days I plan to port a selection of the easier scripts to PHP. Things like TODO, SKIP and regex matching have to wait for later. Takers welcome!

Posted on 27 November 2008.

Attended talk about Enterprise 2.0

Wednesday night I attended a talk entitled “Enterprise 2.0 – Die Kunst, loszulassen”. I didn’t expect much of the talk, as I primarily went there for meeting people. But I was pleasently surprised, as the speaker Wilms Buhse did an excellent talk. He really made his point, that the lessons learned from social networks can be applied to enterprises. His examples were the experiences at CoreMedia and with

The other thing I learned at the Forum is that Dresden is really a nice City. I just didn’t find the sweet spots when I went there.

Posted on 14 November 2008.

Parrot 0.6.4

On behalf of the Parrot team, I’m proud to announce Parrot 0.6.4 "St. Vincent Amazon.". Parrot is a virtual machine aimed at running dynamic languages.

Parrot 0.6.4 is available via CPAN (soon), or follow the download instructions. For those who would like to develop on Parrot, or help develop Parrot itself, we recommend using Subersion on our source code repository to get the latest and best Parrot code.

Parrot 0.6.4 News:

- Documentation
  + removed a lot of old information from the FAQ
  + improved function level documentation
- Configuration
  + removed the configuration item 'has_gnu_m4'
  + refactored ICU-detection
- Languages
  + ChitChat
    - improved the Smalltalk implementation
  + Pipp
    - renamed Plumhead to Pipp
    - support for a lot of builtin functions.
    - Pipp now uses PHP specific data types.
    - converted from PCT with TGE to PCT with NQP actions
    - improvements in the PCT variant by using optok parsing
    - start of object support
  + pir
    - simple assignments work
  + json
    - added a PCT-based implementation of JSON parsing
  + lolcode
    - improved handling of symbols
    - added support for block handling
    - added support for globals
  + Lua
    - more tests
  + Rakudo
    - updated Range implementation
    - added enums
    - added generic type declarations (::T)
    - added runtime mixing of roles with 'does' and 'but'
    - added generic type declarations
    - fixed handling of implicit lexicals ($_, $!, and $/)
    - fixed implicit method calls on $_
    - improved complex math builtins, added Complex
    - moved many builtins to class Any
    - declaration of lists of variables now work
    - improved test infrastructure
    - 910 additional passing spec tests since last release
    - more convergence with grammar
    - added named 0-ary parsing and ops
- Compilers
  + PCT:
    - allowed subroutine and method names to be a PAST tree that produces the name
    - Improved lexical handling
- Tools
  + pbc_disassemble renamed from disassemble
- Implementation
  + allowed<nobr> <wbr></nobr>.macro_const in PIR
  + added the flag<nobr> <wbr></nobr>:lexid(...) for subroutines
  + made multiple dispatch work for sub types
  + fixed garbage collection bug related to the metadata attached to a PMC_EXT structure
  + added a warning when using deprecated opcodes
  + simplified the stacks implementation
  + fixed C++ build
  + improved closure and lexical support
  + improved IMCC register allocator
  + added cache for all runtime-constant strings, reducing memory usage
- Miscellaneous
  + improved OpenGL/GLU/GLUT bindings
  + added a standard profile for Perl::Critic coding standard testing
  + added support for smoke testing with Smolder
  + enabled use of Test::Harness 3.0 if available, but don't require it for 'make test'
  + added the executable 'parrot_config' to query Parrot configuration
Posted on 15 July 2008.

Welcoming Pipp

The PHP on Parrot implementation used to be called Plumhead, after the Plum-Headed Parakeet. As this name is somewhat goofy, a new name was sought. Some more or less sane variants were discussed,

And the winner is Pipp.

Thanks to Christoph Otto for getting this rolling.

Posted on 02 July 2008.

Eclectus now emits Not Quite Perl6

Eclectus is a Scheme-compiler implemented in Scheme. The compilation target is a Parrot Abstract Syntax Tree, which is being run with the help of the Parrot Compiler Toolkit.

A sideline in Eclectus is the the problem how to tell PCT about the PAST generated in Scheme. Up to now I generated PIR that built up that data structure. This involved nasty dealings with unique ids for Parrot registers.

Generating NQP is much saner. The PAST is now set up with nested PAST::Node constructors.

Even nicer would be to create a YAML representation of PAST. But PCT doesn’t support this yet.

Posted on 01 May 2008.

HQ9+ reimplemented with PCT

Klaas Jan’s excellent “Parrot Compiler Tools” - Tutorial inspired me to go back and reimplement HQ9+ with PCT. The result is in

As HQ9+ is not really a hard language, it all went fairly smooth. ‘’ created me a stub in ‘languages/hq9plus’. Then I copied some reusable files from the old implementation in ‘languages/HQ9plus’. This was fine under Linux, but caused pain for folks on case-insensitive file systems. Sorry, next time I try to think before committing!

For looking up snippets of PAST I used the old trick: write a snippet of Perl 6 and look at the PAST that Rakudo generates.

The last problem was whitespace handling. For that I only needed a simple change in the grammar. Replace all ‘rule’s by ‘token’s and sprinkle some ‘\s*’s.

The next thing on my agenda is for Plumhead and Eclectus. I want to switch from ‘generate PIR that sets up PAST’ to ‘generate NQP that sets up PAST’.

Posted on 02 April 2008.

Parrot 0.6.0 "P&P" released

On behalf of the Parrot team, I’m proud to announce Parrot 0.6.0 "P&P." Parrot is a virtual machine aimed at running dynamic languages. This release is a milestone release featuring the revamping of Parrot Magic Cookies.</p>

Parrot 0.6.0 can be obtained via CPAN (soon), or follow the download instructions. For those who would like to develop on Parrot, or help develop Parrot itself, we recommend using Subversion or SVK on our source code repository to get the latest and best Parrot code.

Parrot 0.6.0 News:

- Specification
  + launched pdd18_security.pod
  + updated pdd17_pmc.pod
  + launching draft of pdd28_character_sets.pod
- Documentation
  + cleanup of IMCC documentation
- Configuration
  + add step auto::gettext
  + add step auto::crypto
- Compilers
  + PCT:
    . Fix '-e' option
    . Phase out P6Regex in favor of Perl6Regex
  + IMCC:
    '.local Array my_arr' is illegal now
- Languages
  + C99: reimplementation with PCT
  + lolcode:
    . various updates
    . add support for functions with params
    . add math functions
  + Rakudo:
    . support for 'say'
    . first cut at smart matching
    . indirect method calls
    . support for Pairs
    . added methods 'grep' and 'first'
    . implement auto{increment,decrement}
    . initial implementation of 'perl6doc'
  + Lua:
    . various updates
    . add base64 library
  + Cardinal: basic support for functions with parameters
  + Pheme: various updates
  + Ecmascript: various updates
  + Tcl: now targeting tcl 8.5.1, no more expected failures in test suite.
    (No, this doesn't mean everything's implemented. =-)
  + Eclectus: various updates
  + WMLScript: various updates
- Implementation
  + PDD17 (PMCs)
  + Add library YAML::Dumper
  + Add the MD2, MD4, MD5, RIPEMD160, SHA & SHA1 PMC, as a wrapper
     around libcrypto
- Miscellaneous
  + various bugfixes, code cleanups and coding standard fixes
  + consting
  + remove external Perl 5 modules from the Parrot distribution

Thanks to all our contributors for making this possible, and our sponsors for supporting this project.


Posted on 18 March 2008.

Techtip of the week

When being shocked that your notebook is kaputt, as it apparently gets no power, please make sure that you are using the correct power supply. There are plugs with a slightly wider inner diameter.

Posted on 25 February 2008.

Parrot Abstract Syntax Tree in Scheme-XML

As I’m hacking away at Eclectus, Scheme on Parrot in Scheme, I’m starting to pick some Scheme knowledge. So before implementing new features I employed my new wisdom and did some refactoring on my Scheme code.

The most nasty thing in compiler.scm was the generation of PIR while traversing the to-be-compiled s-expression. I decided to use XML Infoset as an intermediate representation, as I already have an XSLT sheet for generating a PIR representation of PAST from an XML representation of PAST. The nice thing is that the XML infoset can also be represented as a Scheme s-expression, that is SXML. The Scheme librarx SSAX-SXML can turn SXML into XML and perform XSLT operations.

For an example let’s look at the Scheme form: (fx+ (fx+ -10 11) (fx+ (fx+ 4 3) (fx+ 3 3)))

Posted on 06 January 2008.

Plumhead and Eclectus

I’m inching forward with Plumhead, PHP on Parrot, and Eclectus, Scheme on Parrot.

Both have been converted to use the shiny new Parrot Compiler Toolkit. I don’t use NQP yet, but being able to use Perl6 for compiler and library implementation is sooo sweet. Kudos to Patrick Michaud.

On the Plumhead side, Jeff Horwitz did some brave hacking and added Plumhead to mod_parrot. See

Posted on 09 December 2007.

Introducing Eclectus

When working on ‘languages/scheme’ in the Parrot repository I got estranged with using Perl5 for implementing Scheme on Parrot. It sure does the job, but I want to learn about Lisp, not about Arrays of Arrays in Perl 5.

I came across An Incremental Approach to Compiler Construction at This is a Scheme to x86 assembly compiler, implemented in Scheme. The cute thing is that the compiler construction is done in small steps. Every step constitutes a working compiler for a larger subset of Scheme. So I stared to work on Eclectus, a bootrapping Scheme to PBC compiler.

For pictures ses

Posted on 17 November 2007.

Teaching myself Scheme

In the last weeks I have been neglecting Plumhead, that is PHP on Parrot. Instead I have been concentrating on learning about Common Lisp and Scheme. Currently I’m working my way through a nice Scheme tutorial, Teach Yourself Scheme in Fixnum Days I try to make the tutorial examples work in ‘languages/scheme’, a Scheme on Parrot implementation from Jeff Goff.

I also got me a copy of Lisp in small pieces. But I found that it’s better to know a little bit of Scheme, before starting to delve into that.

Posted on 31 October 2007.

Seen on reddit: What large websites are running on

Seen on What nine of the world’s largest websites are running on Perl has a strong showing. However the selection of sites has been debated. “comments”)

The data for the table was scraped from

Posted on 02 October 2007.

Bitflip error

On Friday a colleague @work asked me about an error in a webapplication. There was a Perl syntax error in Sys::Hostname. As I saw no reason that anybody should mess with with Sys::Hostname, I checked the time was last changed. Confusingly the last change was in 2004, apparently this was the time the server was set up. A diff with another Perl 5.8.0 installation showed a single bit change. The first space, 0x20, of line 104 has turned into into a ‘(‘, 0x28. The only explanation I can imagine is that a bit has flipped in file cache.

Strange. Posted on 24 June 2007.

Choosing a license for Plumhead

I have been thinking on how to proceed with Plumhead, that is PHP on Parrot. The problem is that I have neither the ability nor the inclining to write a PHP grammar from scratch. So a template is needed. This brings up the question of licensing.

Johnlim’s blog got me jumpstarted on which PHP implementations are out there. I have put my finding into the Parrot Wiki, The projects that look most interesting to me are phc, PHP4Mono and Roadsend. The PHP4Mono and the Roadsend grammars seem to be written from scratch. Both projects are GPL licensed. The phc grammar is derived from the PHP 5.2 grammar.

PHP 5.2 is licensed under the PHP license, while parts are under the Zend license. Both licenses are BSD-like, which is quite acceptable to me.

So the plan of the day is to derive the Plumhead grammars from the PHP 5.2 grammar. I’m not sure whether that means that I need to put the whole of Plumhead under BSD license, or whether I can stick with Artistic+GPL.

Posted on 09 April 2007.


Tonight I was opening a sealed envolope in dim light. When opening the envelope I noticed blueish flashes of light where the adhesive was pulling apart. Subconciously I probably was looking out for that, as I already had noticed the phemenomen some years ago.

Googling told me that this effect in called Triboluminescence, which means ‘light from rubbing’. Apparently this is one of the messier phemenomens. At least three different mechanisms were suggested. Breaking of polymers, squashing of crystals and surface excitations. During my study of physics I never came accross it. The closest thing was the piezoelectric effect, which has a lot of technical applications.

If I don’t forget about it, I’ll get me some sugar cubes and crush them in the dark.

PS: Is there a something like a TinyMCE for use.perl ? Typing all that markup is tiring.

Posted on 15 February 2007.

More Plumheads

Lately I have expanded the scope of PlumHeaded Parakeet. The current plan is to have a side-by-side comparison of differend parsing and transformation techniques. These techniques are:

Take XML output of phc,, and transform it with XSLT.
Write parser and treegrammar in ANTLR3,, with Java backend
Use the Parrot compiler tools for parsing and transformation

The transformation target is in all three PAST-pm, an abstract syntax tree that can be trasformed into Parrot bytecode.

See also

Posted on 16 January 2007.


After starting on Plumhead, aka PlumHeaded Parakeet, I stumbled on base64 encoded strings embedded in the XML emitted by phc.

The plan is to create Parrot Intermediate Representation from XML. So I became sidetracked into making a MIME::Base64 module for PIR. As usual it took longer than expected, even though I found a nice German tutorial. So an incomplete implementation is now at

The tests I stole from the Perl5 module MIME::Base64. Thanks to Will Coleda for compilers/json, which helps in setting up the test cases.

Posted on 12 October 2006.

Plum-headed Parakeet

Mark Overmeer passed on one of the take home messages from YAPC::Europe in Birmingham. In a lightening talk about XML::Compile,, he said something like: Never mind the XML, it's just syntax. The day before, Allison Randall had talked about the Parrot compiler tools and mentioned how XSLT had influenced the design of TGE. So I wondered whether Never mind the XSLT, it's just syntax. applies as well.

The XSLT project I came up with, is to take the XML output of phc, and transform it to something Parrot can understand. phc parses PHP, so this should become an implementation of PHP on Parrot.

As a projectname,, I chose ‘Plumhead’, which is short for Plum-headed Parakeet, The description on Wikipedia is neat too: Plum-headed Parakeet is a gregarious and noisy species with range of raucous calls.

Posted on 09 September 2006.

May 2006 Munich Perl Monger meeting

Last night the Munich Perl Mongers celebrated the second installment of the bimonthly meeting. Harald Jörg, the MPM fearless leader, suggested a ‘Man Fat, a chinese restaurant in Schwabing as the stomping ground. The food was tasty and the wheatbeer was most welcome after the bike ride from $work at the other end of town.

Besides 7 regulars, two new faces showed up: another Jörg, of Perl golf fame, and Susanne Ruppel. Susanne got the rocks rolling by suggesting to bid for the German Perl Workshop 2007. As the enthusiasm is there, it was decided to go for it! In 2002, when we hosted the YAPC::EU, only Norbert Grüner really knew what we were getting into. This time we have no excuses.

Posted on 18 May 2006.

Munich Perl Monger meeting

In a radical breach of tradition, the Munich Perl Mongers decided to have regular bimonthly meetings. In order to limit the culture shock, the location will remain dynamic and will be chosen in feverish indecision.

So yesterday evening was the first regular meeting. Five Mongers showed, including a new face, Gertraud. Harald Jörg has a writeup in German, Topics ranged from using ‘ed’ on appliances to the job prospects of assembler programmers for BS2000.

The MPM schedule is the third wednesday of uneven months. When in doubt consult the perlgolf entries in

On the Parrot side, I hope to teach ANTLR 3 more about bc. And coming saturday I plan to attend the ‘Linux Info Tag’ in Augsburg, enjoying Ingo Blechschmidt’s talk ‘Perl6 genau jetzt’.

Posted on 16 March 2006.

Quine, wisdom teeth pulled

This month I didn’t get much done on the ANTLR3 front. Instead I did some directory renaming in the Parrot tree, did a quine in PIR and brought the long awaited HQ9+ to Parrot.

Doing a quine in PIR was fun. The first attempt ended up quite cheatingly with a dynamic op ‘q’ in myops.ops. Then, thanks to google, I found the standard recipe for quines and did ‘quine_ord.pir’. The ‘_ord’ comes from that I use the ‘ord’ opcode to encode part of the quine code in a data section.

This weekend I finally built up nerves for ANTLR3. There is now support for testing an ANTLR3 implementation in the ‘Parrot bc’ test suite. And I started on a dummy grammar for ‘bc’ with Java as a backend.

This afternoon I also had two of my wisdom teeth pulled. It went better than expected, and I feel almost up to par right now.

Posted on 31 January 2006.

First skiing holidays, then hacking on ANTLR v3

For tomorrow I’m planning a quiet day at $work and on Saturday me and Regina are heading for a week a skiing in the Wildschönau, in the Austrian Alps. I’m looking forward to that, as there has been ample snowfall in the Mountains. I won’t take my notebook, only my copy of ‘Language Programming Pragmatics’ for light reading.

After the holiday I really plan to get going on a Parrot backend of ANTLR v3. I’m not sure about the target language yet. I might start with PIR and then try to learn more about the ‘PIL2 minilanguage’.

WRT to ‘Parrot bc’ I’ll continue to piggyback on ‘punie’. So I try to generate ‘Allison’s PAST’ from bc, for whatever features are implemented for punie.

At $work I have been looking at This looks like exactly like the thing I want for web testing. It might also make the colleagues in quallity assurance happy! The only thing I’m really missing is support for frames. But some smart Ruby guys are already working on it.

Posted on 29 December 2005.

Prototype for less work and more fun

At $WORK I’m still doling away at my Mason-powered webapp, that keeps track of interesting biological sequences.

Lately I have been AJAXifying things with the help of Prototype, This works out quite nicely. For the user it makes the interaction more fluent. For the programming part, I experienced that it makes the seperation of content and actions more natural. I have to admit though, that I have no proper MVC setup yet.

For effects I use I’m quite fond of the autocompleter. I use it to let the user choose for the NCBI taxonomy database

The next think to look for is a consistent set of widgets, preferably based on Prototype. Perhaps Rico,

Posted on 30 November 2005.

Off to vacations in Istria

This afternoon I’m heading with Regina down South to Istria. We are staying in an appartment in lovely Rovinj.

Tonight we propably stay overnight in the Austrian Alps. If we are lucky, we will glimps some meteorites from Perseids meteorite shower.

I don’t know if I have Internet access in Rovinj. My notebook is packed. I’ve also downloaded the ‘bc’ and ‘m4’ specs and might work a little on their respective Parrot ports.

Posted on 12 August 2005.

No unary '+' in 'POSIX bc'

I’m still trying to learn about computer languages, by targeting ‘POSIX bc’ to Parrot. Currently I’m checking whether I got the precedences of ’+’, ‘-‘, ’*’, ’/’ and ’%’ right. The harder things are still to come: variables and subroutines.

There is a funny thing I noticed about POSIX bc. POSIX bc has no unary ’+’, thus ‘+1’ on a line by itself is a syntax error.

bernhard@ubuntu:~$ bc -s
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type 'warranty'.
(standard_in) 3: syntax error
Posted on 29 July 2005.

Meeting of the Munich Perl Mongers

Yesterday, the Munich Perl Mongers were guests of the Munich chapter of the System Administrators Guild Europe. This invitation was much to the relief of Harald Jörg. He got a break from the tedious task of determining the number of attendees, needed for restaurant reservations. An amazing number of about 20 SAGEs and 10 Mongers turned up.

The topic was ‘GUI in Perl’, and we even had presentations. Steffen Ulrich talked about his experiences with an homegrown competitor of SAP, written in Perl/Tk. He also did comparisons with other GUI toolkits. Tk seems to have the best impedance match with Perl, but is also the worst looking GUI toolkit.

Harald showed us a Perl/Tk project he had resurected after 8 years of banishment. He did a 3D-Designer for houses and furniture. It was jolly fun flying thru walls, all without VRML. No Doom monsters were to be seen anywhere.

Stephen Riem tooks us on tour of the darker sides of Programming, by showing a Java application for the planning of television commercials. The number of lines of code was truly frightening.

Posted on 12 July 2005.

Cool things at $work

My main project at $work is a Mason-based webapplication for keeping track of interesting biological sequences. As a new round of develoment is just starting, I finally took some time to do some refactoring and to beef up my test suite.

Almost all the application logic, interface to the database and connection to the world is wrapped in a set of Perl5 modules. Running the existing test suite with Devel::Cover was dead easy. It immediately showed me missing tests. Even better, it pointed me to some obsolete code. This is very good, as deleted code is guaranteed to be bugfree code.

The next toy was Test::TAP::HTMLMatrix. I think that there is no support from Module::Build yet, but I could avoid coding by fetching a script from There is still some red in the generated HTML, but I blame it on the world, that keeps on changing.

In the left frame of the webapplication there is a project tree, that can contain several hundred nodes. This used to be a homegrown tree, but I replaced it with a COOLjsTree, The COOLjsTree has a fairly complete API and certainly looks more professional than my old tree. My old tree only excelled in the speed of opening and closing subtrees, as it was simply a nested unordered list with some CSS and JavaScript.

I also switched to returning instances of Return::Value from some methods. It is nice to have a standardized returnvalue. However I feel somewhat uneasy about the overloaded get_bool() and get_string().

What are the next cool things? Catalyst with HTML::Mason views sound good for the next project. For web testing I’d like to use HTTP::Recorder and WWW::Mechanize, but I think that I can’t do without JavaScript support.

Posted on 09 July 2005.

Munich Perl Mongers meeting

Last Thursday we had our semi regular meeting of the Munich Perl Mongers. Eight brave souls tourned up at the Hirschgarten. Unexpectedly we had sunshine and thus could sit outside in the quite beautiful beergarden.

Topics ranged from mod_survey to Perl scripts for verifying orders in a large print shop.

Ralph Leonhard was interested in R on Parrot, but lacks time and funds. He mentioned that R is based on an internal scheme engine. So I started to look at languages/scheme in the Parrot SVN.

Posted on 02 May 2005.

First steps with ANTLR and Python

I’m still trying to find the ultimate tool for implementing languages on Parrot. Never having to take a compiler construction class, and not really needing it at work, I’m not familiar with any of common parsing tools.

For now I’m getting down with ANTLR, trying to bring ‘bc’ to Parrot. ‘bc’ is actually a neat little language, I like it much better than ‘m4’. The main purpose of ‘bc’ is of course the evaluation of arithmetic expressions. But there are also variables and subroutines. So ‘bc’ might be nice sandbox for playing with the PAST interface of Parrot.

ANTLR looks very good to me. Like with lex/yacc a syntax definition is transformed into code for lexers and parsers. The pros are * Mature, with lots of documentation and examples * Lexers and parsers in a variety of languages

The cons are: * No Perl5 backend * No Perl6 backend

The nice thing is that Abstract Syntax Trees are easily constructed. With a little syntactic sugar, on can specify which tokens are to be ignored and which tokens introduce subtrees. The generated AST can be processed with TreeParsers.

With ANTLR 2.7.5 Python code generation has been added. So I decided to do some baby talk in Python. The Python syntax is very regular and easy to learn, but I miss the human touch from Perl and Ruby. The whole indentation business makes me feel rather confined. I like hitting ’%’ in vim!

So ANTLR is thumbs up, and Python is thumbs down.

Posted on 06 April 2005.

*BooleanArray PMC for Parrot

My Easter project is to look into the FixedBooleanArray and ResizableBooleanArray PMC. As the name implies, a *BooleanArray is an array of boolean values. This functionality could be achieved with a *PMCArray of Boolean PMCs. However this wastes a lot of memory, as a bool really just needs a single bit.

Currently there is a minimal implemention from Matt Fowles. The downside of the current implementation is that a bool is stored in an INTVAL. This means that 31, or 63, bits are wasted per bool.

Making the current implementation to use 1 bit per bool should be straightforword. But as laziness if one of my virtues, it would be nice if somebody has already done the work. My first idea was to steal the code from Perl5's Bit::Vector. This module looks very nice and very complete, with a lot of tests. Bit::Vector is XS-based and the C-code can also be used without Perl. The downside is that the C-library is under GPL, which makes it hard to incorporate in Parrot.

The docs of Bit::Vector mentions that the module is also a big integer math library. Well, a bit vector is really the same as a big integer. Thus it would be economical, if the BigInt PMC and the *BooleanArray PMC have the same implementation in Parrot

The BigInt PMC is implemented by calling out to GMP, the GNU Multiple Precision Arithmetic Library. When there is no GMP, than a fallback implementation jumps in. Of course, all the methods needed for *BooleanArray are already implemented in GMP.

So that’s the plan: 1. Steal the test suit from Bit::Vector 2. Let *BooleanArray PMC call out to GMP 3. Make the fallback implementation use 1 bit per bool 4. Factor out common code of BigInt and *BooleanArray

Posted on 19 March 2005.

embedded databases for Parrot

In the last weeks, I have been looking into dynamic PMCs in Parrot. They are not very different from Parrot core PMCs.Users just have to look up the dynamic ID, before they can create a instance.

As an example I worked on the GDBMHash PMC. This is a binding the GNU dbm, a file dictionary. The basic implementation was straightforward. The configuration is somewhat akward. I need to check wether ‘’ exists. Currently I have added this check to the core Parrot configuration. It would be nicer to have a seperate configuration step for Parrot extensions. It would be cool to do that in PIR, as Parrot already exists when extensions are added.

Looking back, using ‘gdbm’ for the example was propably not the best choice. Berkely DB seems to be much more widely used. As far as I remember, Bio::Index::Fasta is based on Berkeley DB.

A more interesting dynamic PMC would be access to Piddles. Piddles are the basis data structure of the Perl Data languages, But before digging into that, I propably should tidy up the ‘Parrot YAML’ and rework ‘Parrot m4’.

Posted on 16 January 2005.

Parrot YAML ain't machine language

In the last weeks I have used some off-work hours for looking into Abstract Syntax Tree for Parrot. It looks like this is one of the less civilised areas of Parrot, as documentation is somewhat scarce.

Leo Tötsch added support for AST when coding for the infamous Piethon bet. So far one can take a Python program and turn it into PAST, Parrot abstract syntax tree As Simple Text.

bernhard@linux:~/devel/Parrot/parrot/languages/python&gt; cat
print 10;
bernhard@linux:~/devel/Parrot/parrot/languages/python&gt;<nobr> <wbr></nobr>./ &gt; hello_10.past
bernhard@linux:~/devel/Parrot/parrot/languages/python&gt; more hello_10.past

# generated by on Sun Nov 28 16:06:29 2004

&nbsp; version(Const('0.1'))
) # _options
&nbsp; _()
&nbsp; Stmts(
&nbsp; &nbsp;Py_Print(
&nbsp; &nbsp; Const(10)
&nbsp; &nbsp;) # Py_Print
&nbsp; &nbsp;Py_Print_nl()
&nbsp; &nbsp;Void(
&nbsp; &nbsp; Const(None)
&nbsp; &nbsp;) # Void
&nbsp; ) # Stmts
) # Py_Module
# end
) # Parrot_AST
bernhard@linux:~/devel/Parrot/parrot/languages/python&gt;<nobr> <wbr></nobr>../../parrot hello_10.past
Posted on 28 November 2004.

Back to YAML/Parser/Syck.imc

YAML is again on top of my ever changing Parrot project list. I’d like to get YAML working, before continuing with m4, PDL and ECMAScript.

Initially I had started with libsyck 0.42. However, libsyck is now at 0.45. In order to be on the bleeding edge, I checked out the CVS version. First I couldn’t built a shared from the CVS sources. This changed after I applied the complete patch of my changes. I had forgotten to set up the shared libs in

After a long session with ‘ddd’ I got libsyck to call the Parrot callback when there is a new node encountered. The next step is to set up the appropriate data structure in the Parrot interpreter. The idea is to use the Siva PMC for that.

The current state of YAML/Parser/Syck.imc can now be tracked on the YAML Kwiki.

Posted on 07 November 2004.

'make distclean' is not my friend

Over the weekend I have been looking into the Perl Data Language, PDL. Nice! There is ample support for visualisation and the Gnu Scientific Library is there too.

However for the next picture drawing, or number crunching task, I would like to finally get started on R. I think that with R it is much easier to do statistics. Also there seem to exist some bioinformatics packages for R.

Back to PDL: The basic data structure of PDL is a multidimensional array, usually called ‘piddle’. It would be a nice challenge to bring piddles to Parrot as PMCs. Loooking at the docs and the C header files, it shouldn’t be too hard. One should be able to load the shared libs that are already generated for Perl5.

For my work on bringing ‘libsyck’ to Parrot, there is good and bad news. The good news is that synchronous callbacks are now in Parrot. ‘libsyck’ really needs synchrounous callbacks, as it passes weak references back to the Parrot interpreter.

The other good news is, that Stéphane Payrard started to work on a multifacetted PMC, ‘siva’. The ‘siva’ PMC seems to be ideal for building up a parse tree of a YAML document.

The bad new is, that a couple of weeks ago I did a ‘make distclean’ on my working copy of the Parrot sources. This sent all my new libsyck files into Nirvana. Luckily I’m doing this for fun.

Posted on 26 October 2004.

Parrot and libsyck

During the last weeks I have been trying to bring libsyck to Parrot. libsyck is a C-library for parsing YAML. It has been designed to work closely together with scripting languages.

At first sight it looks fairly easy. The scripting language tells libsyck about the YAML string. Libsyck parses the YAML string into a parse tree and tells the scripting language whenever it encounters a node. The scripting language receives a node, store the information in a convenient location and tells libsyck where it has put the node. Usually the convenient location is the languages symbol table, and the location returned to libsyck is a symbol id.

The communication from libsyck to the scripting language is done via callback functions, aka handlers. So in order to marry Parrot and libsyck, one needs the Parrot Native Call Interface with callback functions.

Parrot NCI itself is pretty stable. It is easy to load a shared library and call functions in that library. The ops ‘loadlib’ and ‘dlfunc’ are your friends there. Arbitrary structs can be read and written to, by putting them into a UnMangagedStruct Parrot Magic Cookie.

For callback functions at least two different things are needed: * A function pointer that the external library can call * A Parrot subroutine that does the wanted work In Parrot there is a single callback function for each supported callback function signature. This is so, because it is hard to create new C-functions without resorting to a C-compiler. So how does the Parrot interpreter know which subroutine should be invoked? For that purpose, any PMC, e.g. ‘user_data’, can be used. The opcode ‘new_callback’ sticks the sub as a property onto ‘user_data’. The external library is given a pointer to ‘user_data’. When the external library is calling the callback function, it needs to pass ‘user_data’ back to the Parrot interpreter. In short, the actual callback function is dumb, all the interesting things are in ‘user_data’.

So far the external library can tell the Parrot interpreter to invoke a sub. The remaining questions are at what time the sub is invoked and how the sub passes information back to the external library. Parrot callback function have no return values. This should propably keep the number of function signatures small. However, the callback sub can receive an external data pointer from the external library and write data into the libraries memory.

The question of the timing is more crucial. Right now Parrot places all callback requests from external libraries into an event queue. This is so, because callbacks can in priciple be fired at any time. At least in a single threaded environment, this means that the actual work is done after the external library is finished with the callback call. The execution is asynchronous. This is OK for callbacks that should Parrot notify about something, for example key press events in a GUI. ‘libsyck’ however depends on synchronous execution. The memory that contains data about a YAML node seems to be reused. When libsyck is parsing, it gives Parrot a pointer to useful data. When Parrot is finally looking at the data, it has long been overwritten.

Presently, I see the lack of synchronous execution of callbacks as the biggest obstacle in bringing libsyck to Parrot. Unfortunately I have no idea how Perl5 and Ruby are handling this. The next thing I want to try, is to put a property ‘snchronous_is_ok’ on ‘user_data’ and call the sub synchronously.

Posted on 22 September 2004.

two tales on user support

During last week I had two experiences with user support.

Tale 1: broken telephone line

Sunday: I wanted to do some stuff for Parrot and found that my 56k-modem didn’t work. My phone didn’t have a dial tone, but emitted strange noise.

Monday: My upstairs neighbor, an elderly lady, told me that the whole block had problems and that it is supposed to be fixed today. Being lazy, I didn’t call the phone company. In the evening the phone emitted the same strange noise.

Tuesday: After more than 10 clicks on the WWW site of the phone company I found the relevant phone number for their technical customer support. When calling them the support guys made a remote measurement and couldn’t find anything wrong with the line. Same strange noises in the evening.

Wednesday: Called the phone company again and they filed it as a real problem. Fixed a date for Thursday 16:00, when a technician would check the line.

Thursday: At work I got a call from the phone company that my phone should be working again. In the evening the phone was really OK. Later my upstairs neighbor told me that she still had problems. I promised to call the phone company for her.

Friday: Called the phone company on behalf of my elderly neighbor, and was advised to try a different phone. At my neighbors I found that her phone was working well, but that her hearing aid went berserk, when using the phone. I advised her to have her hearing aid checked.

Saturday: Went to a birthday party of the nice of my girl friend.

Sunday: Called the elderly lady from the place of my girl friend. Everything is fine when she places the telephone receiver further away from the hearing aid.

Tale 2: DB::Introspector

Two months ago: At work I wrote a little migration script for a relational database. I used DB::Introspector for checking wether a MySQL database table had the needed indexes. Found a little problem with DB::Introspector, fixed it, and didn’t bother to send in a patch.

Friday: Needed the mentioned migration script for a software installation on a test machine. Installed DB::Introspector and ran into the old problem. I remembered my fix from two months ago and applied it. This time I filed the patch in

Saturday: Read on use.perl that a new revision of DB::Introspector is out. When checking on CPAN I found the it took masahji less than two hours to apply the patch and prepare a new revision.

I don’t know what can be learned from the two tales. For me, tale 1 was much more frustrating than tale 2. On the other side, problem 1 took one week to be resolved, while problem 2 lingered for two months because I didn’t take 5 minutes for a very simple problem report.

Posted on 29 August 2004.

Hello use Perl;

Since the last year I found myself checking use Perl; and clicking a couple of Recent Journal’s almost daily. Starting from that I’ll try writing in my journal. The plan is to do a regular entry every two weeks.

So that’s it for self motivation.

Now to my introduction.

I’m a 34 year old trained physicist, now doing software development and custumer support. Mostly I’m doing web application stuff for a Bioinformatics portal.

On the geeky side, I try to contribute to Parrot. I’m maintaining a halfway finished implementation of m4 in PIR. Currently I’m playing around with bringing YAML to Parrot. The long term vision is to do a implemention of JavaScript.

Yesterday a social meeting of the Munich Perl Mongers took place. Lively discussions were ranging from quantum dots to the state of documention of the Kwiki framework.

Posted on 20 August 2004.


Bernhard Schmalhofer from Munich in Germany.