パール2 で ポーション
p2 on potion
.ooo 'OOOo ~ p ooOOOo 2 ~ .OOO oO %% a fast perl5 Oo 'O ` (o) ___/ / /` \ /v^ ` , (...v/v^/ \../::/ \/::/
p2 is a she. She will be a perl5 frontend and possible perl6/nqp backend, based on why the luck stiff’s potion compiler and vm technology and a new extensible parser. Optionally perl6 might be parsed natively. (use v6;)
See the potion README why potion is exciting.
parrot example/fib.pir 28 0m1.746s perl example/fib.pl 28 0m0.439s potion example/fib.pn 28 0m0.013s p2 -B example/fib.p2 28 0m0.177s p2 example/fib.p2 28 <todo: 0.013s> parrot example/fib.pir 40 3m36.447s perl example/fib.pl 40 2m19.752s potion example/fib.pn 40 0m3.512s p2 -B example/fib.p2 40 0m54.560s p2 example/fib.p2 40 <todo: 0m3.512s>
So function calls are ~30x faster than perl5, real-world programs between 2-5x. gperl is about 3x faster than p2, because it uses the llvm backend and less dynamic types. There are no optimizer passes in the p2 compiler yet, esp. constant folding and type hinting are missing.
java/jvm is somewhere between perl and potion. java has slow startup, fast calls, faster math, but limited OO and dynamic type support.
p2's exciting points for perl folks are:- Radically simplified and functional core.
- Should parse most of perl5, just some XS and B tricks not.
Maybe perl6 also.
Since the original perl5 testsuite is not usable for other
implementations and compilers it needs to be adjusted. The perl6
testsuite is in a better shape.
- signatures (done), mop (done), mixins (done), types, traits, fast native threads,
coroutines (done), perl6-like grammars (static peg parser), macros for perl5.
- Using most of Damian Conway’s p5i recommendations:
i.e. classes are immutable and final by default.
See www.yetanother.org/damian/Perl5+i/
- Native and fast calling convention, no XS stack args on the heap.
XS is replaced by dlcall (dynamic ffi), and/or shared libraries with
normal function calls into the vm.
- int, str, num are objects, you can optionally type all args and lexical variables.
In fact everything is an object as in parrot, even the compiler, the parser, the vm.
- Sized arrays are non-autovivifying and initialized with undef, resp. if typed 0, 0.0, "".
my $a[3]; print $a[3]; => compile-time error: array out of bounds my int $i[3]; print $a[2] => 0 my num $n[3]; print $n[2] => 0.0 my str $s[3]; print $a[2] => ""
- A new pragma “no magic” applies to all visible objects in scope.
{ no magic; use Config; print $Config{’ccflags’}; } => compile-time error: Invalid use of tie with no magicuse
{ no magic; use Config; print $Config::Config{’ccflags’}; }instead.
- p6-like dynamic, but fast meta object model:
roles, :multi, type-optimizer.
Like Moose, just better and much faster. (~800x as first rough estimation)
- smartmatch works because all data are typed objects.
links
See p2-extensions for an overview on the planned perl5 language extensions, activated via the use p2; pragma.
See glossary for an overview on the potion/lua derived terminology.
See design-decisions why the code looks like asis, and what we want.
development
- github.com/perl11/p2.git, branch p2
- no mailing list yet. fork, pull requests, comment, wiki, commit and create issues. irc://irc.perl.org/#perl11
- the plan is to have ~50% of perl5 parsed by summer 2013, add some basic libraries, and finish it by summer 2014.
- Travis
documentation
- p2 data structures (by doxygen)
- p2 reference (by global htags)
- glossary
- p2-extensions over perl5 (use p2;)
- design-decisions
- p2 YAPC NA 2013 talk slides [PDF]
- p2 YAPC Asia 2013 talk slides (with japanese translations) [PDF]
- INTERNALS
- Just-in-time compilation for x86, x86-64 and ppc done, missing is callcc for ppc and the arm jit.
- Intermediate bytecode format and VM. Load and dump code. Decent
speed and cross-architecture. Heavily based on Lua’s VM.
- Planned is the switch to a multi-threaded concurrent generational GC, based on Stefan Seifert's
work on hybrid parrot threads with proxies to safely update foreign
variables via coroutines.
The compiler will add hooks for objects leaving scope and add
DESTROY method calls if they are visible at compile-time.
Run-time created DESTROY methods will not be automatically called. - The current potion generational GC is based on Basile Starynkevitch’s
work on Qish.
- Bootstrapped “id” object model, based on Ian Piumarta’s soda
languages. This means almost everything in the language, including
object allocation and interpreter state are part of the object
model. (See COPYING for citations.) The parser not yet, but this is planned.
- Interpreter is thread-safe and reentrant. This will
facilitate coroutines, parallel interpreters and sandboxing.
- Lean, small, fast. Under 10kloc. Right now we’re like 6,000 or
something. Install sloccount and run: make sloc.
No configure, just make.
- Reified AST and bytecode structures. This is very important to
me. By giving access to the parser and compiler, it allows people
to target other platforms, write code analysis tools and even
fully bootstrapped VMs. I’m not as concerned about the Potion VM
being fully bootstrapped, especially as it is tied into the JIT
so closely.
- Memory-efficient classes. Stored like C structs. Although the
method lookup table can be used like a hash for storing arbitrary
data.
- The JIT is also used to speed up some other bottlenecks. For
example, instance variable and method lookup tables are compiled
into machine code.
- Strings are immutable (like Lua and parrot) and byte arrays are used for I/O
buffers. Strings are utf-8 only, de/encoding done in library functions.
- No arbitrary precision for numbers yet. Limited int range, no automatic int boxing nor promotion to bigint, bignum.
- Only preliminary error handling yet.
- No signal handling yet. (longjmp based)
thankyous
why the lucky stiff left the ruby community. potion was his last public project. It’s a work of art and mastership. I could not think of anything better. I think it is better than go, if potion would have had dlcall, autothreads and channels, arbitrary precision numbers and exception handling.
Rob Pike for go, and the parrot community for parrot.
cPanel for letting me do what I consider important. Not just 10% of my time as with Google.
Larry Wall for perl5. We miss his leadership and technical excellence. Without him nothing got done, and *if* something was done it was wrong. Besides defined-or, which left Tom Christiansen behind.
why the lucky stiff thanks:
I am gravely indebted to Basile Starynkevitch, who fielded my questions about his garbage collector. I favor French hackers to an extreme (Xavier Leroy, Nicolas Cannasse, Guy Decoux, Mathieu Bochard to name only a portion of those I admire) and am very glad to represent their influence in Potion’s garbage collector.
Matz, for answering my questions about conservative GC and for encouraging me so much. Potion’s stack scanning code and some of the object model come from Ruby.
Steve Dekorte for the Io language, libgarbagecollector and libcoroutine — I referred frequently to all of them in sorting out what I wanted.
Of course, Mauricio Fernandez for his inspiring programming journal housed at eigenclass.org/R2/ and for works derived throughout the course of it — extprot most of all. Many of my thoughts about language internals (object repr, GC, etc.) are informed by him.
Ian Piumarta for peg/leg and id-objmodel. I use a re-entrant custom version of peg, but the original library is sheer minimalist parsing amazement.
Final appreciations to Jonathan Wright and William Morgan who pitched in, back in the wee hours of Potion’s history. Thanks.
license
See COPYING for legal information.potion is an MIT license, which lets you do anything you want with this.
perl5 code is ARTISTIC and GPL dual licensed,
p2, parrot and perl6 code is ARTISTIC 2 licensed.