Day 50: pugscc --runparrot -e "'Hello, Parrot'.say"

autrijus on 2005-03-22T20:35:09

The title is worth repeating:

% pugscc --runparrot -e "'Hello, Parrot'.say"

Yes, it works now, as of revision 1024. And yes, it does what you think it does. Pugs takes that Perl 6 source code, produce an AST, triggers the Compiler backend, generates some PIR code, saves it into a.pir, and runs it with the parrot executable in path. The compilation and execution speed are both very fast, and will get faster with embedded Parrot and/or Ponie support in the future.

This also works:

% pugscc --runhaskell -e "'Hello, Haskell'.say"
Instead of PIR, it generates raw Haskell code using Template Haskell, compiles it with GHC, and runs the resulting executable. Template Haskell is really good for prototyping and verifying a compiler; the code it produces is also quite fast, within 20% of Perl 5 speed.

The old, undecorated form of pugscc also works. It can also be written thus:

% pugscc --runpugs -e "'Hello, Pugs'.say"
The --pugs backend is the only one that guarantees to run identically to the pugs interpreter. Unsurprisingly, it merely bundles the evaluator with the Pugs AST, and makes an executable out from that.

On a somewhat more interesting note, if you can build Pugs with the PUGS_EMBED environment variable set to perl5 (that works on FreeBSD for me, but apparently not on many other platforms), then you can do this:

% pugscc --runpugs -e "eval_perl5('print q[Hello, Perl5!]')"

The eval_perl5($str) form is but a temporary kluge; it will likely become eval($str, :language<perl5>), or whatever form preferred by the perl6 design folks. Suggestions welcome!

Aside from perl5, I plan to add embedding support for Haskell and C via hs-plugins, and Parrot support via the embedding API. Of course, once Ponie gets up to speed, I can replace Perl5 and Parrot embeds with it, which will save a lot of value casting works.

Tomorrow I'll hack some more to get mandel.p6 working correctly on the two new compiler backends. Thanks to Dan Sugalski's help on #parrot, I have figured out the PIR-level supports to get this done. Parrot is really much, much saner than I had hoped; it eeriely supports lots of things needed by a Perl 6 implementation. I wonder why that is the case. :-)

There are many developmenets today. nothingmuch checked in a working .assuming() implementation; GHC 6.2.2 now works again Win32; scw fixed the behaviour of $! after eval; gaal started working on a YAML-based harness; and more things that I can't quite summarize. I'll try to catch up again tomorrow...


Astounding!

knobunc on 2005-03-22T21:27:21

This project is absolutely amazing.

In the time it has taken me to wrestle a new ID3v2 (.3 and .4) parser into some rough shape you have made a mostly working perl 6 compiler that is fast and targets multiple backends.

Thank you all for your amazing work. I was beginning to worry about ever seeing a P6, but this project really has pumped life back into the community.

-ben