SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à Parrot Compiler Tools

Perl 5.10 in 2010
Perl 5.10 in 2010Perl 5.10 in 2010
Perl 5.10 in 2010guest7899f0
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklChristoph Pickl
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?acme
 
Massimiliano Pala
Massimiliano PalaMassimiliano Pala
Massimiliano Palaprensacespi
 
Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Criticolegmmiller
 
Developing Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and JavascriptDeveloping Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and JavascriptJeff Haynie
 
From Pylama to Pylava - Susam Pal - PyCon UK 2018
From Pylama to Pylava - Susam Pal - PyCon UK 2018From Pylama to Pylava - Susam Pal - PyCon UK 2018
From Pylama to Pylava - Susam Pal - PyCon UK 2018Susam Pal
 
Server Independent Programming
Server Independent ProgrammingServer Independent Programming
Server Independent ProgrammingZendCon
 
Overloading Perl OPs using XS
Overloading Perl OPs using XSOverloading Perl OPs using XS
Overloading Perl OPs using XSℕicolas ℝ.
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会Ippei Ogiwara
 
Piece Framework 2.0 Background
Piece Framework 2.0 BackgroundPiece Framework 2.0 Background
Piece Framework 2.0 BackgroundAtsuhiro Kubo
 
2013 Tevreden.nl, our Love and Hate of Perl
2013 Tevreden.nl, our Love and Hate of Perl2013 Tevreden.nl, our Love and Hate of Perl
2013 Tevreden.nl, our Love and Hate of PerlPascal Vree
 
20130202 fosdem love n hateperl latest
20130202 fosdem love n hateperl latest20130202 fosdem love n hateperl latest
20130202 fosdem love n hateperl latestBas Bloemsaat
 
Things we love and hate about Perl @ Tevreden.nl
Things we love and hate about Perl @ Tevreden.nlThings we love and hate about Perl @ Tevreden.nl
Things we love and hate about Perl @ Tevreden.nlTevreden
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perldaoswald
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
 

Similaire à Parrot Compiler Tools (20)

Perl 5.10 in 2010
Perl 5.10 in 2010Perl 5.10 in 2010
Perl 5.10 in 2010
 
PHP 5.3/6
PHP 5.3/6PHP 5.3/6
PHP 5.3/6
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph Pickl
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?
 
Test Fest 2009
Test Fest 2009Test Fest 2009
Test Fest 2009
 
僕とPerlとYAPC Asia
僕とPerlとYAPC Asia僕とPerlとYAPC Asia
僕とPerlとYAPC Asia
 
Massimiliano Pala
Massimiliano PalaMassimiliano Pala
Massimiliano Pala
 
Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Critic
 
Developing Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and JavascriptDeveloping Desktop Applications using HTML and Javascript
Developing Desktop Applications using HTML and Javascript
 
From Pylama to Pylava - Susam Pal - PyCon UK 2018
From Pylama to Pylava - Susam Pal - PyCon UK 2018From Pylama to Pylava - Susam Pal - PyCon UK 2018
From Pylama to Pylava - Susam Pal - PyCon UK 2018
 
WordPress APIs
WordPress APIsWordPress APIs
WordPress APIs
 
Server Independent Programming
Server Independent ProgrammingServer Independent Programming
Server Independent Programming
 
Overloading Perl OPs using XS
Overloading Perl OPs using XSOverloading Perl OPs using XS
Overloading Perl OPs using XS
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
 
Piece Framework 2.0 Background
Piece Framework 2.0 BackgroundPiece Framework 2.0 Background
Piece Framework 2.0 Background
 
2013 Tevreden.nl, our Love and Hate of Perl
2013 Tevreden.nl, our Love and Hate of Perl2013 Tevreden.nl, our Love and Hate of Perl
2013 Tevreden.nl, our Love and Hate of Perl
 
20130202 fosdem love n hateperl latest
20130202 fosdem love n hateperl latest20130202 fosdem love n hateperl latest
20130202 fosdem love n hateperl latest
 
Things we love and hate about Perl @ Tevreden.nl
Things we love and hate about Perl @ Tevreden.nlThings we love and hate about Perl @ Tevreden.nl
Things we love and hate about Perl @ Tevreden.nl
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 

Plus de Kazutake Hiramatsu (6)

八王子
八王子八王子
八王子
 
八王子
八王子八王子
八王子
 
STD_P6
STD_P6STD_P6
STD_P6
 
PerlMotion
PerlMotionPerlMotion
PerlMotion
 
Perl motion
Perl motionPerl motion
Perl motion
 
同人誌を支える技術
同人誌を支える技術同人誌を支える技術
同人誌を支える技術
 

Dernier

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Dernier (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Parrot Compiler Tools

  • 1. Parrot Compiler Tools Kazutake Hiramatsu kazutakehiramatsu@gmail.com 2008/05/15 YAPC::Asia 2008
  • 2. Introduction  2001  2005 Pugs  2006 Perl6  2008 Parrot version 0.6.1  Parrot is Dead ? 2008/05/15 YAPC::Asia 2008
  • 3. What is Parrot Compiler Tools (PCT) ?  Parrot VM  Rakudo PCT  Parrot PCT  2008/05/15 YAPC::Asia 2008
  • 4. All Dynamic language is compiled into Parrot bytecode Perl6 Perl5 Ruby Python Parrot VM 2008/05/15 YAPC::Asia 2008
  • 5. All Dynamic language is compiled into Parrot bytecode Perl6 Perl5 Ruby Python Parrot VM 2008/05/15 YAPC::Asia 2008
  • 6. 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
  • 7. Parrot Registers  Integers (I)  Numbers (N)  Strings (S)  PMCs (P) – Parrot Magic Cookies – String,Array, Hash, Object 2008/05/15 YAPC::Asia 2008
  • 8. 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
  • 9. Parrot Assembly language (PASM)  Parrot  Parrot 2008/05/15 YAPC::Asia 2008
  • 10. 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
  • 11. Parrot Intermediate Representation (PIR)  PASM  PASM 2008/05/15 YAPC::Asia 2008
  • 12. 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
  • 13. 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
  • 14. Compilation Phase   PAST  PAST POST  POST PIR 2008/05/15 YAPC::Asia 2008
  • 15. Parrot Grammar Engine(PGE)  Perl6 Rule  Rule  Rule  “{*}“ Rule  Parse Actions 2008/05/15 YAPC::Asia 2008
  • 16. 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
  • 17. 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
  • 18. Not Quite Perl(6) (NQP)  Perl6  Parse Actions 2008/05/15 YAPC::Asia 2008
  • 19. Parrot Abstract Syntax Tree (PAST)  AST  Parse Actions PAST  PAST  PAST::Node, PAST::Val, PAST::Var… 2008/05/15 YAPC::Asia 2008
  • 20. 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
  • 21. 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
  • 22. Generate a Language Stub config/gen/languages.pm $ laguages $languages = qq{ : : WMLScript Zcode Foo # add } unless defined $languages; 2008/05/15 YAPC::Asia 2008
  • 23. Generate a Language Stub $ perl Configure.pl $ cd language/foo $ make $ make test 2008/05/15 YAPC::Asia 2008
  • 24. 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
  • 25. Writing Code say “Hello, Foo!”; 2008/05/15 YAPC::Asia 2008
  • 26. Executes $ ../../parrot foo.pbc test.foo Hello, Foo! 2008/05/15 YAPC::Asia 2008
  • 27. Next Step  – foo/src/parser/grammar.pg – foo/src/parser/actions.pm  – foo/src/builtins/xxx.pir 2008/05/15 YAPC::Asia 2008
  • 28. 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
  • 29. Open the actions.pm  NQP  Actions  grammar.pg “{*}” Rule  ($/) Rule Match Object 2008/05/15 YAPC::Asia 2008
  • 30. 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
  • 31. 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
  • 32. NQP Syntax  $/ Match  $<expression> $/ Match  $( $x ) $x  make Match PAST  my $past := PAST::Op.new( :node($/) ); 2008/05/15 YAPC::Asia 2008
  • 33. PAST Nodes  PAST::Node  PAST::Block  PAST::Stmts  PAST::Var  PAST::Val  PAST::VarList  PAST::Op 2008/05/15 YAPC::Asia 2008
  • 34. Advanced Topics  Scope Management  Operator precedence  Calling Conventions 2008/05/15 YAPC::Asia 2008
  • 35. References  docs/pct/*.pdd  http://planet.parrotcode.org/  http://www.parrotblog.org/  http://www.parrotcode.org/ 2008/05/15 YAPC::Asia 2008
  • 36. Thank you ! 2008/05/15 YAPC::Asia 2008