Jump to content

Pugs (compiler)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Autrijus (talk | contribs) at 00:52, 22 December 2005 (Nicholas is handing out Ponie pumpkingship; I had a name change; pugs can compile to JavaScript and perl5.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

This article is about the Perl 6 computer programing language implementation. For other meanings of Pug, see Pug (disambiguation).

Pugs is a compiler and interpreter for the Perl 6 programming language, started on February 1st 2005 by Audrey Tang.

Overview

The Pugs project aims to bootstrap Perl 6 by implementing the full Perl 6 specification, as detailed in the Synopsis. It is written in Haskell, specifically targeting the Glasgow Haskell Compiler.

Pugs includes two main executables:

  • pugs is the interpreter with an interactive shell.
  • pugscc can compile Perl 6 programs into Haskell code, Perl 5, JavaScript, or Parrot virtual machine's PIR assembly.

Version numbering

The major/minor version numbers of Pugs converges to 2 × π (being reminiscent of TeX and METAFONT, which use similar scheme); each significant digit in the minor version represents a successfully completed milestone. The third digit is incremented for each release. The current milestones are:

  • 6.0: Initial release.
  • 6.2: Basic IO and control flow elements; mutable variables; assignment.
  • 6.28: Classes and traits.
  • 6.283: Rules and Grammars.
  • 6.2831: Type system and linking.
  • 6.28318: Macros.
  • 6.283185: Port Pugs to Perl 6, if needed.

Perl 5 compatibility

As of version 6.2.6, Pugs also has the ability to embed Perl 5 and use CPAN modules installed on the system. The example below show a use of the popular Perl DBI module to manage a SQLite database:

#!/usr/bin/pugs
use v6;
use perl5:DBI;

my $dbh = DBI.connect('dbi:SQLite:dbname=test.db');
$dbh.do("CREATE TABLE Test (Project, Pumpking)");

my $sth = $dbh.prepare("INSERT INTO Test VALUES (?, ?)");
$sth.execute(<PGE Patrick>);
$sth.execute(<Pugs Audrey>);
$sth.execute(<Parrot Leo>);

my $res = $dbh.selectall_hashref('SELECT * FROM Test', 'Pumpking');
# Just another Pugs hacker
say "Just another $res<Audrey><Project> hacker";

Development model

Pugs has been praised as a particularly successful open-source project. Started at the beginning of 2005, progress has been rapid. Several factors have been suggested as reasons:

  • Pugs's use of Haskell. Haskell's static typing means that a wider range of bugs are detected by the compiler at compile-time. In the tradition of functional languages, it appears that a few lines of Haskell can do a lot, especially in the basics of language parsing and execution. Things get marginally trickier around the edges, where the functional code has to interact with the real (time-oriented) world. To achieve this, Pugs makes extensive use of monads, which are containers for side-effects in a language without side-effects (purely functional).
  • Test-driven methodology. A feature of Extreme Programming, the aim is to ensure that absolutely everything has test code, probably long before the real code is written. It's then apparent what the state of the project is, simply from how many tests are passing or failing. It also makes it much easier to detect regressions. Originally there was hope that the huge Pugs test suite would form the basis of the actual Perl 6 test suite, but now it looks more like Pugs itself will form the basis of the actual Perl 6, so the point is a bit moot.
  • Audrey's liberal sprinkling of the commit bit. Pugs development is currently based around a Subversion repository, and access is given out quite freely - especially to people wishing to write tests. Because of this, a huge library of tests has accumulated.
  • Audrey's enthusiastic and frequent communications. Her journal (linked below) attracted many people to the project, mainly due to the astonishing pace of development. There's also usually a community on the #perl6 Freenode IRC channel.