| 1 | = Pugs Apocryphon 1 -- Overview of the Pugs project |
|---|
| 2 | |
|---|
| 3 | == What is this document about? |
|---|
| 4 | |
|---|
| 5 | The [Pugs Apocrypha|http://svn.perl.org/perl6/pugs/trunk/docs/] are a series of |
|---|
| 6 | documents, written in question/answer format, to explain the design and |
|---|
| 7 | implementation of Pugs. This document (PA01) is a higher-level overview of the |
|---|
| 8 | project. |
|---|
| 9 | |
|---|
| 10 | == What is Pugs? |
|---|
| 11 | |
|---|
| 12 | Started in February 2005, [Pugs|http://pugscode.org/] is an |
|---|
| 13 | implementation of the Perl 6 language. [Autrijus |
|---|
| 14 | Tang|http://use.perl.org/%7Eautrijus/journal/] is responsible for the |
|---|
| 15 | design and development of Pugs with help from a group of committers and |
|---|
| 16 | contributors. |
|---|
| 17 | |
|---|
| 18 | == What is Perl 6? |
|---|
| 19 | |
|---|
| 20 | [Perl 6|http://dev.perl.org/perl6/] is the next major revision of Perl, |
|---|
| 21 | a context-sensitive, multi-paradigmatic, /practical/ programming |
|---|
| 22 | language, designed by a team led by Larry Wall. The Pugs project was |
|---|
| 23 | [enthusiastically |
|---|
| 24 | welcomed|http://www.nntp.perl.org/group/perl.perl6.language/19263] by the Perl 6 |
|---|
| 25 | team. |
|---|
| 26 | |
|---|
| 27 | == Is Pugs the official Perl 6? |
|---|
| 28 | |
|---|
| 29 | Official Perl 6 is now defined as any implementation which passes the |
|---|
| 30 | Perl 6 testsuite. So Pugs is expected to be an official Perl 6, but |
|---|
| 31 | not necessarily the only one. |
|---|
| 32 | |
|---|
| 33 | == Has Perl 6 been specified? |
|---|
| 34 | |
|---|
| 35 | By December 2004, most of Perl 6 had been specified as a series of |
|---|
| 36 | [Synopses|http://dev.perl.org/perl6/synopsis/]. Although not considered |
|---|
| 37 | final, it is now stable enough to be implemented. Many of the Synopses |
|---|
| 38 | are based on Larry's [Apocalypses|http://dev.perl.org/perl6/apocalypse/]. |
|---|
| 39 | Sometimes the design team releases |
|---|
| 40 | [Exegeses|http://dev.perl.org/perl6/exegesis/], which explain the Apocalypses. |
|---|
| 41 | Pugs adheres to the Synopses, referring to the Apocalypses or Exegeses when a |
|---|
| 42 | Synopsis is unclear or imprecise. |
|---|
| 43 | |
|---|
| 44 | == What does "Apocrypha" mean? |
|---|
| 45 | |
|---|
| 46 | The word [Apocrypha|http://en.wikipedia.org/wiki/Apocrypha], from the |
|---|
| 47 | Greek word απκρυφος or "hidden", |
|---|
| 48 | refers to religious works that are not considered canonical, or part of |
|---|
| 49 | officially accepted scripture. The proper singular form in Greek is |
|---|
| 50 | "Apocryphon". |
|---|
| 51 | |
|---|
| 52 | == What is the relationship between the Apocrypha and the Perl 6 design |
|---|
| 53 | documents? |
|---|
| 54 | |
|---|
| 55 | Apocalypses and Synopses cover the Perl 6 language in general; Apocrypha |
|---|
| 56 | are specific to the Pugs implementation. Like the [Parrot Design |
|---|
| 57 | Documents|http://www.parrotcode.org/docs/pdd/], the Apocrypha will be |
|---|
| 58 | constantly updated according to the status of Pugs. |
|---|
| 59 | |
|---|
| 60 | == Will Pugs implement the full Perl 6 specification? |
|---|
| 61 | |
|---|
| 62 | Yes. Pugs always targets the latest revision of Perl 6 Synopses. As soon |
|---|
| 63 | as a new revision or a new Synopsis is published, incompatibilities |
|---|
| 64 | between Pugs and the new version will be considered bugs in Pugs. |
|---|
| 65 | |
|---|
| 66 | == Is Pugs free software? |
|---|
| 67 | |
|---|
| 68 | Yes. It is available under the |
|---|
| 69 | [Artistic License version 2.0|http://svn.pugscode.org/pugs/LICENSE/Artistic-2]. |
|---|
| 70 | |
|---|
| 71 | == Is Pugs funded by the Perl Foundation? |
|---|
| 72 | |
|---|
| 73 | No. After receiving three [Perl Foundation |
|---|
| 74 | grants|http://www.perlfoundation.org/gc/grants/2003_autrijus.html] on |
|---|
| 75 | various projects, Autrijus decides it would be more helpful to donate |
|---|
| 76 | time to the Perl 6 project by hacking Pugs, rather than asking TPF for |
|---|
| 77 | money to do the same thing. |
|---|
| 78 | |
|---|
| 79 | == Where can I download Pugs? |
|---|
| 80 | |
|---|
| 81 | For the very latest version of Pugs, check out the source from the |
|---|
| 82 | [Subversion|http://svn.pugscode.org/pugs/] or |
|---|
| 83 | [darcs|http://wagner.elixus.org/~autrijus/darcs/pugs] repositories. Periodic |
|---|
| 84 | releases are available on CPAN under the |
|---|
| 85 | `[Perl6-Pugs|http://search.cpan.org/dist/Perl6-Pugs/]` distribution. |
|---|
| 86 | (By the way, if you'd like to work offline with the Subversion |
|---|
| 87 | repository, [the `svk` client|http://svk.elixus.org/] may be of interest. |
|---|
| 88 | Using vanilla `svn` is fine, though.) |
|---|
| 89 | |
|---|
| 90 | == How do I build Pugs? |
|---|
| 91 | |
|---|
| 92 | Pugs uses the standard Makefile.PL build system, as detailed in the |
|---|
| 93 | `[README|http://svn.pugscode.org/pugs/README]` file. Since Pugs is |
|---|
| 94 | written in Haskell, you will need [the Glasgow Haskell |
|---|
| 95 | Compiler (GHC)|http://haskell.org/ghc/] 6.4 or above. Please [download a |
|---|
| 96 | binary build|http://haskell.org/ghc/download_ghc_64.html] for your platform; |
|---|
| 97 | compiling GHC from source is a long, tedious process. |
|---|
| 98 | |
|---|
| 99 | == What is Haskell? |
|---|
| 100 | |
|---|
| 101 | [Haskell|http://haskell.org/] is a standardized, purely functional programming |
|---|
| 102 | language with builtin [lazy |
|---|
| 103 | evaluation|http://en.wikipedia.org/wiki/Lazy_evaluation] capabilities. While |
|---|
| 104 | there are several different implementations available, Pugs currently needs to |
|---|
| 105 | be built with GHC, as it uses several GHC-specific features. |
|---|
| 106 | |
|---|
| 107 | == What is GHC? |
|---|
| 108 | |
|---|
| 109 | GHC is a state-of-the-art compiler and interactive environment, available under |
|---|
| 110 | [a BSD-style license|http://haskell.org/ghc/license.html]. Written in Haskell |
|---|
| 111 | itself, GHC can compile Haskell to bytecode, C code, and machine code (on some |
|---|
| 112 | platforms). GHC has an extensive library, numerous language extensions, and a |
|---|
| 113 | very capable optimizer (with some help from [a Perl 5 |
|---|
| 114 | program|http://www.cse.unsw.edu.au/%7Echak/haskell/ghc/comm/the-beast/mangler.html]). |
|---|
| 115 | As such, it provides an excellent platform to solve Perl 6's /bootstrapping |
|---|
| 116 | problem/. |
|---|
| 117 | |
|---|
| 118 | == What is the Perl 6 bootstrapping problem? |
|---|
| 119 | |
|---|
| 120 | The goal of the Perl 6 project is to be /self-hosting/: the Perl 6 |
|---|
| 121 | compiler needs to be written in Perl 6 itself, and must parse Perl 6 |
|---|
| 122 | source code with Perl 6 Rules, the next-generation pattern matching syntax for |
|---|
| 123 | Perl 6. The generated code must also contain an evaluator that can execute Perl |
|---|
| 124 | 6 code on the fly. The only way to break this cycle of dependency is by |
|---|
| 125 | first implementing some parts in other languages, then rewriting those |
|---|
| 126 | parts in Perl 6. |
|---|
| 127 | |
|---|
| 128 | == What was the initial bootstrapping plan? |
|---|
| 129 | |
|---|
| 130 | According to the |
|---|
| 131 | [Parrot FAQ|http://search.cpan.org/dist/parrot/docs/faq.pod#Isn't_there_a_bootstrapping_problem?], |
|---|
| 132 | the initial plan was to bootstrap via Perl 5: first extend Perl 5 to run on the |
|---|
| 133 | Parrot virtual machine (via `B::Parrot` or [Ponie|http://www.poniecode.org/]), |
|---|
| 134 | then implement the Perl 6 compiler in Perl 5, which will be translated to Perl 6 |
|---|
| 135 | via a p5-to-p6 translator. However, although part of the Rules system was |
|---|
| 136 | prototyped in Perl 5 as |
|---|
| 137 | `[Perl6::Rules|http://search.cpan.org/dist/Perl6-Rules/]`, it was not mature |
|---|
| 138 | enough to build a compiler on. As such, the plan was revised to bootstrap via C |
|---|
| 139 | instead. |
|---|
| 140 | |
|---|
| 141 | == What is the revised bootstrapping plan? |
|---|
| 142 | |
|---|
| 143 | According to an early 2005 |
|---|
| 144 | [proposal|http://www.perlfoundation.org/gc/grants/2005-p6-proposal.html], the |
|---|
| 145 | plan is to first implement the Rule engine in C (i.e. [the Perl Grammar Engine |
|---|
| 146 | (PGE)|http://cvs.perl.org/viewcvs/cvs-public/parrot/compilers/pge/]), use it to |
|---|
| 147 | parse Perl 6 into Parrot as an [abstract syntax |
|---|
| 148 | tree|http://en.wikipedia.org/wiki/Abstract_syntax_tree] (AST), and then |
|---|
| 149 | implement an AST evaluator as part of Parrot. Ponie and p5-to-p6 are still being |
|---|
| 150 | worked on, but they are no longer critical dependencies in the bootstrapping |
|---|
| 151 | process. |
|---|
| 152 | |
|---|
| 153 | == How can Pugs help Perl 6 to bootstrap? |
|---|
| 154 | |
|---|
| 155 | In a bootstrapping process, there are often many bottlenecks, which prevent |
|---|
| 156 | people from working on things that depend on them. For example, one cannot |
|---|
| 157 | easily write unit tests and standard libraries for Perl 6 without a working |
|---|
| 158 | Perl 6 implementation, or work on an AST evaluator without an AST interface. |
|---|
| 159 | Pugs solves such deadlocks by providing ready substitutes at various levels of |
|---|
| 160 | the process. |
|---|
| 161 | |
|---|
| 162 | == How can Pugs help the Perl 6 language design? |
|---|
| 163 | |
|---|
| 164 | Without a working implementation, it is very hard to spot |
|---|
| 165 | inconsistencies and corner cases in the specification. However, if a |
|---|
| 166 | design problem is found late in the implementation phase, it may require the |
|---|
| 167 | costly rearchitecture of everything else. By providing a working Perl 6 |
|---|
| 168 | implementation, Pugs can serve as a proving ground, finding and resolving |
|---|
| 169 | problems as early as possible, as well as encourage more people to exercise Perl |
|---|
| 170 | 6's features. |
|---|
| 171 | |
|---|
| 172 | == Why did you choose Haskell? |
|---|
| 173 | |
|---|
| 174 | Many Perl 6 features have very similar Haskell counterparts: Perl 6 Rules |
|---|
| 175 | correspond closely to |
|---|
| 176 | [Parsec|http://www.cs.uu.nl/%7Edaan/download/parsec/parsec.html]; lazy |
|---|
| 177 | list evaluation is common in both languages; continuation support can be |
|---|
| 178 | modeled with the [ContT|http://www.nomaware.com/monads/html/contmonad.html] |
|---|
| 179 | monad transformer; and so on. This greatly simplified the prototyping |
|---|
| 180 | effort: the first working interpreter was released [within the first |
|---|
| 181 | week|http://use.perl.org/~autrijus/journal/23051], and by the [third |
|---|
| 182 | week|http://use.perl.org/~autrijus/journal/23335] a fully-fledged |
|---|
| 183 | `[Test.pm|http://svn.pugscode.org/pugs/lib/Perl6/lib/Test.pm]` |
|---|
| 184 | module was available for unit testing. |
|---|
| 185 | |
|---|
| 186 | == What is the relationship between Pugs and Parrot? |
|---|
| 187 | |
|---|
| 188 | The plan is for Pugs to target Parrot PIR. This is |
|---|
| 189 | already possible; Pugs can target Parrot PIR using an experimental Parrot |
|---|
| 190 | backend, which is being improved steadily. |
|---|
| 191 | |
|---|
| 192 | == Is Pugs a compiler or an interpreter? |
|---|
| 193 | |
|---|
| 194 | Similar to Perl 5, Pugs first compiles Perl 6 program to an AST, then |
|---|
| 195 | executes it using the built-in evaluator. However, in the future Pugs |
|---|
| 196 | may also provide a compiler interface that supports different compiler |
|---|
| 197 | backends. |
|---|
| 198 | |
|---|
| 199 | == Which compiler backends are available? Will more be added? |
|---|
| 200 | |
|---|
| 201 | Currently, there are three compiler backends available: Pugs, Parrot |
|---|
| 202 | (experimental) and Haskell. More backends may be added if people can work on |
|---|
| 203 | them (e.g. Perl 5 bytecode). |
|---|
| 204 | |
|---|
| 205 | == Do you have a roadmap for Pugs development? |
|---|
| 206 | |
|---|
| 207 | The major/minor version numbers of Pugs converge to 2*π; each |
|---|
| 208 | significant digit in the minor version represents a milestone. The |
|---|
| 209 | third digit is incremented for each release. The current milestones |
|---|
| 210 | are: |
|---|
| 211 | |
|---|
| 212 | * 6.0: Initial release. |
|---|
| 213 | * 6.2: Basic IO and control flow elements; mutable variables; assignment. |
|---|
| 214 | * 6.28: Classes and traits. |
|---|
| 215 | * 6.283: Rules and Grammars. |
|---|
| 216 | * 6.2831: Type system and linking. |
|---|
| 217 | * 6.28318: Macros. |
|---|
| 218 | * 6.283185: Port Pugs to Perl 6, if needed. |
|---|
| 219 | |
|---|
| 220 | == How portable is Pugs? |
|---|
| 221 | |
|---|
| 222 | Pugs runs on Win32, Linux and many flavors of Unix systems. See GHC's |
|---|
| 223 | [porters list|http://haskell.org/ghc/contributors.html] and [download |
|---|
| 224 | page|http://haskell.org/ghc/download_ghc_622.html] for details. |
|---|
| 225 | Binaries for Windows 2000/XP are available as part of [the PXPerl |
|---|
| 226 | distribution|http://pixigreg.com/?pxperl]. There are plans to provide binaries |
|---|
| 227 | for other platforms as well eventually. |
|---|
| 228 | |
|---|
| 229 | == How fast is Pugs? |
|---|
| 230 | |
|---|
| 231 | The parser part of Pugs is very fast, due to its robust underpinning in |
|---|
| 232 | Parsec. However, the Pugs evaluator is currently not optimized at all: |
|---|
| 233 | dispatching is around 1000 operators per second on a typical PC, which |
|---|
| 234 | is nearly 100 times slower than Perl 5. Still, it is fast enough for |
|---|
| 235 | prototyping language features; if you need fast operations in Pugs, |
|---|
| 236 | please consider helping out by working on the Compiler backend. |
|---|
| 237 | |
|---|
| 238 | == Is there a CPAN for Perl 6 modules? |
|---|
| 239 | |
|---|
| 240 | No. The current preferred method for submitting Perl 6/Pugs modules is |
|---|
| 241 | to ask for a committer bit at commitbit.pugscode.org and add your module to |
|---|
| 242 | the Pugs source tree under the modules/ directory. It is also helpful to |
|---|
| 243 | include test suites with your modules as well, so we can know when they |
|---|
| 244 | work. |
|---|
| 245 | |
|---|
| 246 | However, all is not lost. If you are patient you can wait for |
|---|
| 247 | `Pugs::MakeMaker` and `Module::Install::Pugs` to come out on CPAN. Once |
|---|
| 248 | they are available individually on CPAN, you can begin submitting things |
|---|
| 249 | to CPAN, because that means we've figured out the distribution problem. |
|---|
| 250 | Of course, suggestions are always welcome. |
|---|
| 251 | |
|---|
| 252 | == Can Pugs work with Perl 5 libraries? |
|---|
| 253 | |
|---|
| 254 | Yes, Pugs can work with Perl 5 libraries. This requires that Pugs be compiled |
|---|
| 255 | with Perl 5 embedding. Pugs understands Perl 5 objects, classes and functions. |
|---|
| 256 | Pugs objects, classes and functions are also understood by Perl 5. |
|---|
| 257 | As such, these types can be used in round-trip callbacks. |
|---|
| 258 | |
|---|
| 259 | Examples of working with Perl 5 may be found in [the source |
|---|
| 260 | tree|http://svn.pugscode.org/pugs/t/unspecced/p5/]. |
|---|
| 261 | |
|---|
| 262 | == Can Pugs work with Haskell libraries? |
|---|
| 263 | |
|---|
| 264 | Yes. Pugs can be compiled with |
|---|
| 265 | `[hs-plugins|http://www.cse.unsw.edu.au/%7Edons/hs-plugins/]` support, which |
|---|
| 266 | allows it to use Haskell libraries. It is also capable of dynamically loading |
|---|
| 267 | Haskell modules. Aside from this, inline Haskell can be evaluated using |
|---|
| 268 | `eval('...', :lang<haskell>)`. |
|---|
| 269 | |
|---|
| 270 | In addition, at the basic level, you can statically link Haskell libraries into |
|---|
| 271 | Pugs primitives, by modifying a few lines in `Prim.hs`. |
|---|
| 272 | |
|---|
| 273 | == Can Pugs work with C libraries? |
|---|
| 274 | |
|---|
| 275 | Not yet. However, [HaskellDirect|http://www.haskell.org/hdirect/] seems to |
|---|
| 276 | provide an easy way to interface with C, CORBA and COM libraries, especially |
|---|
| 277 | when combined with `hs-plugins` (described above). |
|---|
| 278 | |
|---|
| 279 | == I know Perl 5, but not Haskell. Can I help develop Pugs? |
|---|
| 280 | |
|---|
| 281 | Sure! The standard libraries and unit tests that come with Pugs are |
|---|
| 282 | coded in Perl 6, and there is always a need for more tests and |
|---|
| 283 | libraries. All you need is basic familiarity with Perl 5, and a few |
|---|
| 284 | minutes to acquaint yourself with some small syntax changes. A ["Porting |
|---|
| 285 | HOWTO"|http://svn.pugscode.org/pugs/docs/other/porting_howto] is also |
|---|
| 286 | available, which should help ease the transition. You'll |
|---|
| 287 | likely pick up some Haskell knowledge along the way, too. |
|---|
| 288 | |
|---|
| 289 | == I know Haskell, but not Perl 5. Can I help develop Pugs? |
|---|
| 290 | |
|---|
| 291 | Sure! Perl 6 and Haskell have many things in common, such as type-based |
|---|
| 292 | function dispatch, first-class functions, and currying, so picking up the |
|---|
| 293 | syntax is relatively easy. Since there are always some TODO tests for |
|---|
| 294 | features in need of implementation, it is never hard to find something |
|---|
| 295 | to do. |
|---|
| 296 | |
|---|
| 297 | == I have learned some Perl 6. What can I do with Pugs? |
|---|
| 298 | |
|---|
| 299 | Look at the `examples/` directory to see some sample programs. Some people |
|---|
| 300 | are already writing web applications and report systems with Pugs. If |
|---|
| 301 | you run into a missing feature in Pugs, you are encouraged to write TODO tests |
|---|
| 302 | for it (if there aren't any already) so that someone can implement it. |
|---|
| 303 | |
|---|
| 304 | == Where can I learn more about Haskell? |
|---|
| 305 | |
|---|
| 306 | [The Haskell homepage|http://www.haskell.org/] and |
|---|
| 307 | [the Wiki|http://haskell.org/hawiki/] are good entry points. Of the |
|---|
| 308 | many online tutorials, [Yet Another Haskell |
|---|
| 309 | Tutorial|http://www.isi.edu/%7Ehdaume/htut/] is perhaps the most accessible. |
|---|
| 310 | Due to the ubiquitous use of Monad transformers in Pugs, [All About |
|---|
| 311 | Monads|http://www.nomaware.com/monads/html/] is also recommended. For books, |
|---|
| 312 | [Algorithms: A Functional Programming |
|---|
| 313 | Approach|http://www.iro.umontreal.ca/%7Elapalme/Algorithms-functional.html], |
|---|
| 314 | [Haskell: The Craft of Functional Programming|http://www.cs.kent.ac.uk/people/staff/sjt/craft2e/] |
|---|
| 315 | and [The Haskell School of Expression|http://haskell.org/soe/] are fine |
|---|
| 316 | introductory materials. Finally, |
|---|
| 317 | [the `#haskell` channel|irc://irc.freenode.net/haskell] on |
|---|
| 318 | [freenode|http://freenode.net] is always full of helpful and interesting people. |
|---|
| 319 | |
|---|
| 320 | == Where can I learn more about Perl 6? |
|---|
| 321 | |
|---|
| 322 | [The Perl 6 homepage|http://dev.perl.org/perl6/] provides |
|---|
| 323 | many online documents. Every week or two, a new Perl 6 list summary appears on |
|---|
| 324 | [Perl.com|http://www.perl.com/]; it is a must-read for people who wish to |
|---|
| 325 | follow Perl 6's progress. For books, [Perl 6 and Parrot |
|---|
| 326 | Essentials|http://www.oreilly.com/catalog/059600737X/] and [Perl 6 |
|---|
| 327 | Now|http://www.apress.com/book/bookDisplay.html?bID=355] are both helpful. |
|---|
| 328 | |
|---|
| 329 | == Where can I learn more about implementing programming languages? |
|---|
| 330 | |
|---|
| 331 | [Types and Programming Languages|http://www.cis.upenn.edu/%7Ebcpierce/tapl/] is |
|---|
| 332 | an essential read; Pugs started out as a self-initiated study of the text, and |
|---|
| 333 | it continues to be an important guide during the implementation. Its sequel, |
|---|
| 334 | [Advanced Topics in Types and Programming |
|---|
| 335 | Languages|http://www.cis.upenn.edu/%7Ebcpierce/attapl/], is also invaluable. It |
|---|
| 336 | may also help to get acquainted with other multi-paradigmatic languages, such as |
|---|
| 337 | [Mozart/Oz|http://www.mozart-oz.org/], |
|---|
| 338 | [Curry|http://www.informatik.unikiel.de/%7Emh/curry/] and |
|---|
| 339 | [O'Caml|http://www.ocaml.org/]. Finally, the detailed [GHC |
|---|
| 340 | commentary|http://www.cse.unsw.edu.au/%7Echak/haskell/ghc/comm/] describes how |
|---|
| 341 | GHC itself was implemented. |
|---|
| 342 | |
|---|
| 343 | == I'd like to help. What should I do? |
|---|
| 344 | |
|---|
| 345 | First, subscribe to the |
|---|
| 346 | [perl6-compiler|http://nntp.perl.org/group/perl.perl6.compiler] |
|---|
| 347 | mailing list by sending an empty mail to |
|---|
| 348 | [perl6-compiler-subscribe@perl.org|mailto:perl6-compiler-subscribe@perl.org]. |
|---|
| 349 | Next, join [the `#perl6` IRC channel|irc://irc.freenode.net/perl6] on |
|---|
| 350 | [freenode|http://freenode.net/] to find out what needs to be done. |
|---|
| 351 | Commit access is handed out liberally; contact the Pugs team on `#perl6` for |
|---|
| 352 | details. See you on IRC! |
|---|