More Related Content Similar to Pugs: A Perl 6 Implementation (20) More from Audrey Tang (20) Pugs: A Perl 6 Implementation5. Pugs...
≝ Perl 6 Compiler
≝ Perl 6 Runtime
6. Pugs...
≝ Perl 6 Compiler
≝ Perl 6 Runtime
≝ Perl 6 Test Suite
15. Perl 6 Code
✓ 130+ Modules
✓ 160+ Examples
✓ 18,000+ Unit Tests
18. “Official Perl 6”
✓ Defined by semantics,
not by accidents of history
✓ Compatibility test suite
(cf. JavaTest/TCK)
26. Perl, circa 1995
• use 5.000;
• require 'fastcwd.pl';
• require 'newgetopt.pl';
• require 'exceptions.pl';
31. Perl, circa 2005
• use v6-alpha;
• use perl5:DBI;
• use perl5:Encode <encode decode>;
• use perl5:Template;
32. Perl, circa 2005
• use v6-alpha;
• use perl5:DBI;
• use perl5:Encode <encode decode>;
• use perl5:Template;
• # Implementation of "crypt"
eval "crypt()" :lang<perl5>;
33. Hybrid Runcore
Pugs
GHC Perl 5
Runtime Runtime
Pugs.Eval Pugs::Runtime
Pugs.Prim Pugs::Compiler
Pugs.Types Pugs::Grammar
34. Hybrid Runcore
Pugs
⇚ Perl 5
GHC Perl 5
Runtime Runtime
Pugs.Eval Pugs::Runtime
Pugs.Prim Pugs::Compiler
Pugs.Types Pugs::Grammar
35. Hybrid Runcore
Pugs
⇚ Perl 5
GHC Perl 5
⇚ Haskell Runtime Runtime
Pugs.Eval Pugs::Runtime
Pugs.Prim Pugs::Compiler
Pugs.Types Pugs::Grammar
36. Hybrid Runcore
Pugs
⇚ Perl 5
GHC Perl 5
⇚ Haskell Runtime Runtime
⇚ C (.so/.dll) Pugs.Eval
Pugs.Prim
Pugs.Types
Pugs::Runtime
Pugs::Compiler
Pugs::Grammar
40. Backends
Pugs
Java
Haskell Perl 5
Script
41. Backends
JVM? YARV?
Pugs
CLR? PyPy?
Java
Haskell Perl 5
Script
42. Perl 5 Backend
Tool Support
CPAN, PAUSE
Perldoc, Perl::Tidy ...
Syntax
v6.pm
Pugs::Compiler::Perl6 ...
Perl 5 Sugar
Moose, Moose::Autobox ...
Semantics
Data::Bind, Class::MOP
Pugs::Runtime, Pugs::Compiler::Rule ...
Augmentation (XS) Infrastructure
PadWalker, Devel::Caller Parse::Yapp
autobox, re::override ... Module::Compile ...
Core
perl
43. Perl 5 Backend
⇛ Augment P5VM Tool Support
CPAN, PAUSE
Perldoc, Perl::Tidy ...
Syntax
v6.pm
Pugs::Compiler::Perl6 ...
Perl 5 Sugar
Moose, Moose::Autobox ...
Semantics
Data::Bind, Class::MOP
Pugs::Runtime, Pugs::Compiler::Rule ...
Augmentation (XS) Infrastructure
PadWalker, Devel::Caller Parse::Yapp
autobox, re::override ... Module::Compile ...
Core
perl
44. Perl 5 Backend
⇛ Augment P5VM Tool Support
CPAN, PAUSE
Perldoc, Perl::Tidy ...
Syntax
v6.pm
Pugs::Compiler::Perl6 ...
⇛ Deploy P6 as P5 Perl 5 Sugar
Moose, Moose::Autobox ...
Semantics
Data::Bind, Class::MOP
Pugs::Runtime, Pugs::Compiler::Rule ...
Augmentation (XS) Infrastructure
PadWalker, Devel::Caller Parse::Yapp
autobox, re::override ... Module::Compile ...
Core
perl
45. Perl 5 Backend
⇛ Augment P5VM Tool Support
CPAN, PAUSE
Perldoc, Perl::Tidy ...
Syntax
v6.pm
Pugs::Compiler::Perl6 ...
⇛ Deploy P6 as P5 Perl 5 Sugar
Moose, Moose::Autobox ...
Semantics
Data::Bind, Class::MOP
Pugs::Runtime, Pugs::Compiler::Rule ...
⇛ v6.pm on CPAN
Augmentation (XS) Infrastructure
PadWalker, Devel::Caller Parse::Yapp
autobox, re::override ... Module::Compile ...
Core
perl
103. Repositories
http://svn.pugscode.org/pugs/
http://darcs.pugscode.org/pugs/
104. Repositories
http://svn.pugscode.org/pugs/
http://darcs.pugscode.org/pugs/
SVK
118. Hackathons
Taipei Vienna2
Vienna Tokyo
Toronto Redmond
Amsterdam
Echt
Lismore
Mt. Arbel
119. Hackathons
Taipei Vienna2
Vienna Tokyo
Toronto Redmond
Amsterdam Chicago
Echt
Lismore
Mt. Arbel
120. Hackathons
Taipei Vienna2
Vienna Tokyo
Toronto Redmond
Amsterdam Chicago
Echt Boston
Lismore
Mt. Arbel
121. Hackathons
Taipei Vienna2
Vienna Tokyo
Toronto Redmond
Amsterdam Chicago
Echt Boston
Lismore Portland
Mt. Arbel
122. Hackathons
Taipei Vienna2
Vienna Tokyo
Toronto Redmond
Amsterdam Chicago
Echt Boston
Lismore Portland
Mt. Arbel Sao Paulo
123. Hackathons
Taipei Vienna2
Vienna Tokyo
Toronto Redmond
Amsterdam Chicago
Echt Boston
Lismore Portland
Mt. Arbel Sao Paulo
Mountain View?
138. Closures
sub make_counter {
my $start = shift;
return sub { ++$start };
}
my $from_ten = make_counter(10);
my $from_three = make_counter(3);
print $from_three->(); # 4
print $from_three->(); # 5
print $from_ten->(); # 11
139. Staged Evaluation
BEGIN {
print "Compile-time";
eval $generated_code;
print "Still in compiler";
}
print "Normal runtime";
eval $more_generated_code;
143. Contexts
# Scalar vs. List context
my $one = <STDIN>; # Read one line
my @all = <STDIN>; # Read all lines
# String vs. Numeric context
print "Lines: @all" if @all < 10;
144. Tied Variables
tie my %search => 'Tie::Google';
print $search{'Perl Pugs'}[0]{URL};
# http://www.pugscode.org/
145. Regular Expresisons
# DeCSS
s''$/=2048;while(<>){G=29;R=142;if((@a=unqT="C*",_)[20]&48){D=89;_=unqb24,qT,@
b=map{ord qB8,unqb8,qT,_^$a[--D]}@INC;s/...$/1$&/;Q=unqV,qb25,_;H=73;O=$b[4]<<9
|256|$b[3];Q=Q>>8^(P=(E=255)&(Q>>12^Q>>4^Q/8^Q))<<17,O=O>>8^(E&(F=(S=O>>14&7^O)
^S*8^S<<6))<<9,_=(map{U=_%16orE^=R^=110&(S=(unqT,"xbntdxbzx14d")[_/16%8]);E
^=(72,@z=(64,72,G^=12*(U-2?0:S&17)),H^=_%64?12:0,@z)[_%8]}(16..271))[_]^((D>>=8
)+=P+(~F&E))for@a[128..$#a]}print+qT,@a}';s/[D-HO-U_]/$$&/g;s/q/pack+/g;eval
166. • use v5;
• sub render {
167. • use v5;
• sub render {
• my $self = shift;
168. • use v5;
• sub render {
• my $self = shift;
• my %opts = (x => 1, y => 1, z => 0, %{$_[0]});
169. • use v5;
• sub render {
• my $self = shift;
• my %opts = (x => 1, y => 1, z => 0, %{$_[0]});
• for my $item ( $self->filter(@{ $self->{items} }) ) {
170. • use v5;
• sub render {
• my $self = shift;
• my %opts = (x => 1, y => 1, z => 0, %{$_[0]});
• for my $item ( $self->filter(@{ $self->{items} }) ) {
• print $item->draw({
x => $opts{x},
y => $opts{y},
z => $opts{z},
}), "n";
171. • use v5;
• sub render {
• my $self = shift;
• my %opts = (x => 1, y => 1, z => 0, %{$_[0]});
• for my $item ( $self->filter(@{ $self->{items} }) ) {
• print $item->draw({
x => $opts{x},
y => $opts{y},
z => $opts{z},
}), "n";
• }
}
175. • use v6-alpha;
• method render ($x = 1, $y = 1, $z = 0) {
• for @.filter(@.items) {
176. • use v6-alpha;
• method render ($x = 1, $y = 1, $z = 0) {
• for @.filter(@.items) {
• say .draw(:$x, :$y, :$z);
}
}
187. 2003
Ponie
(late, as in the late Arthur Dent)
200. Static Dynamic
(C++, OCaml...) (Python, Ruby, ...)
Efficient
Robust
201. Static Dynamic
(C++, OCaml...) (Python, Ruby, ...)
Efficient Productive
Robust
202. Static Dynamic
(C++, OCaml...) (Python, Ruby, ...)
Efficient Productive
Robust Flexible
204. • use v5;
• sub f {
• sqrt($_[0]**2 + $_[1]**2);
•}
• my $five = f( 3, 4 );
205. • use v6-alpha;
• sub f {
• sqrt(@_[0]**2 + @_[1]**2);
•}
• my $five = f( 3, 4 );
206. •sub f (Num $x, Num $y) {
• sqrt($x**2 + $y**2);
•}
•my Num $five = f( 3, 4 );
208. • subset Positive of Num where { $_ > 0 }
209. • subset Positive of Num where { $_ > 0 }
• sub f (
Positive $x, Positive $y
--> Positive where { $_ > ($x & $y) }
) {
210. • subset Positive of Num where { $_ > 0 }
• sub f (
Positive $x, Positive $y
--> Positive where { $_ > ($x & $y) }
) {
• sqrt($x ** 2 + $y ** 2);
}
211. • subset Positive of Num where { $_ > 0 }
• sub f (
Positive $x, Positive $y
--> Positive where { $_ > ($x & $y) }
) {
• sqrt($x ** 2 + $y ** 2);
}
•
my $five := f(3, 4); # inferred as Positive
216. DSL GPL
(SQL, Regex, ...) (Lisp, C, ...)
Concise
Expressive
217. DSL GPL
(SQL, Regex, ...) (Lisp, C, ...)
Concise Versatile
Expressive
218. DSL GPL
(SQL, Regex, ...) (Lisp, C, ...)
Concise Versatile
Expressive Reusable
225. • sub postfix:<!> ($x) {
• [*] 1..$x
•}
•
• say 10!; # 3628800
226. • macro GREETING () {
• # A late-bound macro
• q:code(:COMPILING){ "Hello, $s" };
•}
• my $s = "world";
• say GREETING; # Hello, world
231. Lazy Eager
(Haskell, Unix pipes) (everybody else)
Modular
Reasonable
232. Lazy Eager
(Haskell, Unix pipes) (everybody else)
Modular Direct
Reasonable
233. Lazy Eager
(Haskell, Unix pipes) (everybody else)
Modular Direct
Reasonable Predictable
237. •# "cat"
for =<> { .say }
•# "cat", together with line numbers
for each(1..*; =<>) {
say "Line $^num: $^text";
}
239. •# Lists are lazy by default
240. • # Lists are lazy by default
• my @fib := (
241. • # Lists are lazy by default
• my @fib := (
• 0, 1,
242. • # Lists are lazy by default
• my @fib := (
• 0, 1,
• each(@fib; @fib[1..*]).map(&infix:<+>)
);
243. • # Lists are lazy by default
• my @fib := (
• 0, 1,
• each(@fib; @fib[1..*]).map(&infix:<+>)
);
•
say "The first ten numbers are: @fib[^10]";
245. •# Items are eager values. However...
246. • # Items are eager values. However...
• my $ignored = lazy { 10 ** (10 * 10) };
247. • # Items are eager values. However...
• my $ignored = lazy { 10 ** (10 * 10) };
• my $unused = lazy { say 1..$ignored };
248. • # Items are eager values. However...
• my $ignored = lazy { 10 ** (10 * 10) };
• my $unused = lazy { say 1..$ignored };
• say "Hello, world!";
253. Classes Prototypes
(Java, Smalltalk, ...) (JavaScript, Lua, ...)
Typeful
Disciplined
254. Classes Prototypes
(Java, Smalltalk, ...) (JavaScript, Lua, ...)
Typeful Adaptive
Disciplined
255. Classes Prototypes
(Java, Smalltalk, ...) (JavaScript, Lua, ...)
Typeful Adaptive
Disciplined Convenient
258. • class Dog is Mammal does Companion {
259. • class Dog is Mammal does Companion {
•
my $.count where 0..100;
260. • class Dog is Mammal does Companion {
•
my $.count where 0..100;
•
has $!brain;
261. • class Dog is Mammal does Companion {
•
my $.count where 0..100;
•
has $!brain;
• has &.vocalize = &say;
has $.name is rw = "Fido";
262. • class Dog is Mammal does Companion {
•
my $.count where 0..100;
•
has $!brain;
• has &.vocalize = &say;
has $.name is rw = "Fido";
• has $.fur handles Groomable;
has $.tail handles <wag hang>;
263. • class Dog is Mammal does Companion {
•
my $.count where 0..100;
•
has $!brain;
• has &.vocalize = &say;
has $.name is rw = "Fido";
• has $.fur handles Groomable;
has $.tail handles <wag hang>;
•
method companion handles s/^owner_// { ... }
}
265. • my Dog $fido .= new;
266. • my Dog $fido .= new;
•
$fido.HOW; # the meta object for Dog
267. • my Dog $fido .= new;
•
$fido.HOW; # the meta object for Dog
• $fido.WHAT; # the Dog prototype object
268. • my Dog $fido .= new;
•
$fido.HOW; # the meta object for Dog
• $fido.WHAT; # the Dog prototype object
• $fido.WHICH; # $fido’s Object ID
269. • my Dog $fido .= new;
•
$fido.HOW; # the meta object for Dog
• $fido.WHAT; # the Dog prototype object
• $fido.WHICH; # $fido’s Object ID
• Dog.isa(Dog); $fido.isa(Dog);
277. Threads Processes
(Implicit sharing) (Explicit sharing)
Intuitive
Parallelizable
278. Threads Processes
(Implicit sharing) (Explicit sharing)
Intuitive Deterministic
Parallelizable
279. Threads Processes
(Implicit sharing) (Explicit sharing)
Intuitive Deterministic
Parallelizable Manageable
283. •
async {
$x.withdraw(3);
$y.deposit(3);
}
284. •
async {
$x.withdraw(3);
☣ Race Condition ☣
$y.deposit(3);
}
287. • async {
$x.lock;
$y.lock;
• $x.withdraw(3);
$y.deposit(3);
}
288. • async { • async {
$x.lock; $y.lock;
$y.lock; $x.lock;
• $x.withdraw(3); }
$y.deposit(3);
}
289. ☣ Deadlock ☣
• async { • async {
$x.lock; $y.lock;
$y.lock; $x.lock;
• $x.withdraw(3); }
$y.deposit(3);
}
292. • async {
• contend {
# begin transaction
• $x.withdraw(3);
$y.deposit(3);
• } # commit or rollback
• }
294. •# Retry with "defer"
method withdraw ($n) {
defer if $.balance < $n;
$.balance -= $n;
}
295. •# Retry with "defer"
method withdraw ($n) {
defer if $.balance < $n;
$.balance -= $n;
}
•
# Choice with "maybe"
sub transfer ($x1, $x2, $y) {
maybe { $x1.withdraw(3) }
maybe { $x2.withdraw(3) }
$y.deposit(3);
}
296. •# Retry with "defer"
method withdraw ($n) {
defer if $.balance < $n;
$.balance -= $n;
}
•
# Choice with "maybe"
sub transfer ($x1, $x2, $y) {
maybe { $x1.withdraw(3) }
maybe { $x2.withdraw(3) }
$y.deposit(3);
}
•
# Composable with nested "maybe"
contend {
maybe { transfer($x1, $x2, $y) }
maybe { transfer($x3, $x4, $y) }
}
301. SIMD MIMD
(APL, Fortran) (everybody else)
Simple
Scalable
302. SIMD MIMD
(APL, Fortran) (everybody else)
Simple Richer types
Scalable
303. SIMD MIMD
(APL, Fortran) (everybody else)
Simple Richer types
Scalable Familiar flow
306. • # Hyper Operator (SSE/GPU friendly)
[1, 1, 2, 3, 5] »+« [1, 2, 3, 5, 8];
• # === [2, 3, 5, 8, 13]
314. • % time pugs -e '(1..100000)>>.sqrt'
real 9.387s
user 9.219s
315. • % time pugs -e '(1..100000)>>.sqrt'
real 9.387s
user 9.219s
•
% time env GHCRTS=-N2 pugs -e '(1..100000)>>.sqrt'
real 5.807s
user 6.959s
318. •# Junctions
sub is_prime (Int $n --> Bool) {
$n % all(2 .. $n.sqrt+1);
}
•
sub has_twin_prime (Int $n --> Bool) {
is_prime($n & ($n ± 2));
}
319. •# Junctions
sub is_prime (Int $n --> Bool) {
$n % all(2 .. $n.sqrt+1);
}
•
sub has_twin_prime (Int $n --> Bool) {
is_prime($n & ($n ± 2));
}
•
sub infix:<±> ($x, $y) {
($x + $y) | ($x - $y);
}
320. •# Junctions
sub is_prime (Int $n --> Bool) {
$n % all(2 .. $n.sqrt+1);
}
•
sub has_twin_prime (Int $n --> Bool) {
is_prime($n & ($n ± 2));
}
•
sub infix:<±> ($x, $y) {
($x + $y) | ($x - $y);
}
•
325. Perl 6 Others
Better
Better
326. Perl 6 Others
Better Better
Better
327. Perl 6 Others
Better Better
Better Better
329. •use jsan:DOM;
•use perl5:DBI;
•use haskell:Numeric;
•use your_language:FavouriteModule;
330. JVM? YARV?
Pugs
CLR? PyPy?
Java
Haskell Perl 5
Script
334. When Perl 6 arrives,
every day will be like
Christmas!
❆