Parrot Compiler Tools
Upcoming SlideShare
Loading in...5
×
 

Parrot Compiler Tools

on

  • 3,743 views

 

Statistics

Views

Total Views
3,743
Views on SlideShare
3,740
Embed Views
3

Actions

Likes
0
Downloads
18
Comments
0

1 Embed 3

http://www.slideshare.net 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Parrot Compiler Tools Parrot Compiler Tools Presentation Transcript

  • Parrot Compiler Tools Kazutake Hiramatsu kazutakehiramatsu@gmail.com 2008/05/15 YAPC::Asia 2008
  • Introduction  2001  2005 Pugs  2006 Perl6  2008 Parrot version 0.6.1  Parrot is Dead ? 2008/05/15 YAPC::Asia 2008
  • What is Parrot Compiler Tools (PCT) ?  Parrot VM  Rakudo PCT  Parrot PCT  2008/05/15 YAPC::Asia 2008
  • All Dynamic language is compiled into Parrot bytecode Perl6 Perl5 Ruby Python Parrot VM 2008/05/15 YAPC::Asia 2008
  • All Dynamic language is compiled into Parrot bytecode Perl6 Perl5 Ruby Python Parrot VM 2008/05/15 YAPC::Asia 2008
  • What is Parrot ?  Register-based VM  (Perl, Ruby etc)  4 (In, Nn, Sn, Pn)  Parrot Intermediate Representation (PIR)  Parrot Assembly language (PASM) 2008/05/15 YAPC::Asia 2008
  • Parrot Registers  Integers (I)  Numbers (N)  Strings (S)  PMCs (P) – Parrot Magic Cookies – String,Array, Hash, Object 2008/05/15 YAPC::Asia 2008
  • Parrot Registers I0 integer register #0 N1 number of floating point register #1 S2 string register #2 P3 PMC register #3 2008/05/15 YAPC::Asia 2008
  • Parrot Assembly language (PASM)  Parrot  Parrot 2008/05/15 YAPC::Asia 2008
  • Parrot Assembly language (PASM) set I0, 1 set S0, quot;Fooquot; set S1, S0 set S0, quot;Barquot; print S1 # Foo print S0 # Bar new P0, 'String' set P0, quot;Bazquot; print P0 # Baz end 2008/05/15 YAPC::Asia 2008
  • Parrot Intermediate Representation (PIR)  PASM  PASM 2008/05/15 YAPC::Asia 2008
  • Parrot Intermediate Representation (PIR) .sub 'main' :main .param pmc args $P0 = compreg 'C99' $P1 = $P0.'command_line'(args) .end 2008/05/15 YAPC::Asia 2008
  • Parrot Compiler Tools  Parrot Grammar Engine (PGE)  Parrot Abstract Syntax Tree (PAST)  Parrot Opcode Syntax Tree (POST)  Not Quite Perl(6) (NQP) 2008/05/15 YAPC::Asia 2008
  • Compilation Phase   PAST  PAST POST  POST PIR 2008/05/15 YAPC::Asia 2008
  • Parrot Grammar Engine(PGE)  Perl6 Rule  Rule  Rule  “{*}“ Rule  Parse Actions 2008/05/15 YAPC::Asia 2008
  • Perl6 Rule grammar C99::Grammar is PCT::Grammar; token TOP { ^ <external_declaration>+ [ $ || <.panic: Syntax error> ] {*} } rule external_declaration { | <declaration> {*} #= declaration | <function_definition> {*} #= function_definition } 2008/05/15 YAPC::Asia 2008
  • Parse Actions class C99::Grammar::Actions; method TOP($/) { for $<external_declaration> { my $fun := $( $_ ); if $fun.name() eq 'main' { make $fun; } } } method external_declaration($/, $key) { make $( $/{$key} ); } 2008/05/15 YAPC::Asia 2008
  • Not Quite Perl(6) (NQP)  Perl6  Parse Actions 2008/05/15 YAPC::Asia 2008
  • Parrot Abstract Syntax Tree (PAST)  AST  Parse Actions PAST  PAST  PAST::Node, PAST::Val, PAST::Var… 2008/05/15 YAPC::Asia 2008
  • Let’s Getting Started! $ svn co https://svn.perl.org/parrot/trunk parrot $ cd parrot $ perl Configure.pl $ make $ make test 2008/05/15 YAPC::Asia 2008
  • Generate a Language Stub $ perl tools/dev/mk_language_shell.pl <language> <location> Foo language $ perl tools/dev/mk_language_shell.pl Foo language/foo 2008/05/15 YAPC::Asia 2008
  • Generate a Language Stub config/gen/languages.pm $ laguages $languages = qq{ : : WMLScript Zcode Foo # add } unless defined $languages; 2008/05/15 YAPC::Asia 2008
  • Generate a Language Stub $ perl Configure.pl $ cd language/foo $ make $ make test 2008/05/15 YAPC::Asia 2008
  • Source Tree foo/ /config/makefiles/root.in /src/ /parser/ /actions.pm # Parse Actions NQP /grammar.pg # Perl6 Rule /builtins/ /say.pir # PIR /t/ /00-sanity.t # /harness /foo.pir # 2008/05/15 YAPC::Asia 2008
  • Writing Code say “Hello, Foo!”; 2008/05/15 YAPC::Asia 2008
  • Executes $ ../../parrot foo.pbc test.foo Hello, Foo! 2008/05/15 YAPC::Asia 2008
  • Next Step  – foo/src/parser/grammar.pg – foo/src/parser/actions.pm  – foo/src/builtins/xxx.pir 2008/05/15 YAPC::Asia 2008
  • Open the grammar.pg  Perl6 Rule – http://dev.perl.org/perl6/doc/design/syn/S05.html  grammar  Rule Token  Top level Rule “TOP” token  Rule “{*}” 2008/05/15 YAPC::Asia 2008
  • Open the actions.pm  NQP  Actions  grammar.pg “{*}” Rule  ($/) Rule Match Object 2008/05/15 YAPC::Asia 2008
  • grammar.pg grammar C99::Grammar is PCT::Grammar; token TOP { ^ <external_declaration>+ [ $ || <.panic: Syntax error> ] {*} } rule external_declaration { | <declaration> {*} #= declaration | <function_definition> {*} #= function_definition } 2008/05/15 YAPC::Asia 2008
  • actions.pm class C99::Grammar::Actions; method TOP($/) { for $<external_declaration> { my $fun := $( $_ ); if $fun.name() eq 'main' { make $fun; } } } method external_declaration($/, $key) { make $( $/{$key} ); } 2008/05/15 YAPC::Asia 2008
  • NQP Syntax  $/ Match  $<expression> $/ Match  $( $x ) $x  make Match PAST  my $past := PAST::Op.new( :node($/) ); 2008/05/15 YAPC::Asia 2008
  • PAST Nodes  PAST::Node  PAST::Block  PAST::Stmts  PAST::Var  PAST::Val  PAST::VarList  PAST::Op 2008/05/15 YAPC::Asia 2008
  • Advanced Topics  Scope Management  Operator precedence  Calling Conventions 2008/05/15 YAPC::Asia 2008
  • References  docs/pct/*.pdd  http://planet.parrotcode.org/  http://www.parrotblog.org/  http://www.parrotcode.org/ 2008/05/15 YAPC::Asia 2008
  • Thank you ! 2008/05/15 YAPC::Asia 2008