The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

INTRODUCTION

v6.pm hacking how-to

Links

  • The development repository is: http://svn.pugscode.org/pugs/perl5/

  • The CPAN distribution is: http://search.cpan.org/dist/v6-alpha/

  • The irc channel for development is: #perl6 on freenode

#perl6 jargon

  • PCR -- the Pugs::Compiler::Rule module - implements Perl 6 parser tools: rule, token, regex, P5 regex, and precedence parser.

  • PCP6 or v6.pm or v6 or v6-alpha -- the perl6-on-perl6 implementation

  • lrep -- an older version of v6.pm -- lrep is still used to compile the Rule grammar in the Pugs::Compiler::Rule module.

v6 Environment variables

  •   V6DUMPAST=1  - tells the code emitter to dump the syntax tree to STDOUT before processing
  •   PERL6LIB=dir;dir  - same usage as PERL5LIB

v6 Compilation cycle

  Source file ->
  Parser -> 
  Emitter ->
  Execute

There is currently no intermediate AST processing phase - the match capture is sent directly to the emitter.

Implementing new syntax

  1. set the V6DUMPAST environment variable

  2. try a simple test with the new syntax:

      perl -Ilib lib/v6.pm --compile-only ' say 42 '
  3. if the syntax tree looks ok, the new syntax can be implemented in the emitter file - see the Emitter section below.

  4. in order to implement of fix syntax tree nodes, see the Parsing section for choosing which file to edit.

Source file processors

  • lib/v6.pm

  • provides compatibility with other perl 6 implementations, by implementing "use v6-alpha;"

  • provides pre-compilation through Module::Compile

  • the compiled code is post-processed with Perl::Tidy, if it is available.

  • lib/Pugs/Compiler/Perl6

    subclasses Pugs::Compiler::Rule to implement the "perl 6 compiler"

Parsing

The syntax is mostly implemented using perl 6 rules, which are provided by the Pugs::Compiler::Rule module.

A few "terms" are implemented using perl 5 modules, such as Pugs::Grammar::Precedence (called from Expression.pm), and Text::Balanced (called from Term.pm)

lib/Pugs/Grammar/*

  • Perl6.pm

    • statements

  • Term.pm

    • number, string, :a<b>

  • Expression.pm

    • detects end-of-expresion

    • parses some terms, like method calls

  • Operator, BaseCategory.pm

    • Infrastructure for operator tables

  • Infix, Prefix, Postfix, Postcircumfix, Circumfix, Ternary

    • operator tables; most of the work is done by Pugs::Grammar::Precedence

  • P6Rule.pm

  • parser for rules (almost a duplicate of the one in Pugs::Runtime::Rule)

  • StatementControl.pm and Pod.pm are currently not used

Code Emitter

lib/Pugs/Emitter/Perl6/Perl5.pm

  • gets a syntax tree and generates Perl5 code

Execute (Runtime)

lib/Pugs/Runtime/Perl6.pm

  • provides routines and objects that help emulate perl 6 semantics.

lib/Pugs/Runtime/Perl6Prelude.pm

  • provides runtime routines that can be written in Perl 6

Writing new tests

For consistency, we share tests with the Haskell implementation. Instead of duplicating the tests in our tree, we copy the tests over when "perl Makefile.PL" is run. This is done by analyzing the MANIFEST to decide which files to copy.

The exceptions are when we need to modify a test script to be different, perhaps because the feature needs to be marked TODO in this implementation but not the other.

As of 07/09/06, this test suite is still in transition to this model.

COPYRIGHT

Copyright 2006 by Flavio Soibelmann Glock and others.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html