• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Parrot -- "one bytecode to rule them all"
 

Parrot -- "one bytecode to rule them all"

on

  • 4,204 views

http://workshop.perl.pt/ptpw2008/

http://workshop.perl.pt/ptpw2008/

Statistics

Views

Total Views
4,204
Views on SlideShare
4,203
Embed Views
1

Actions

Likes
1
Downloads
22
Comments
0

1 Embed 1

http://www.slideshare.net 1

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 -- "one bytecode to rule them all" Parrot -- "one bytecode to rule them all" Presentation Transcript

    • ”one bytecode to rule them all” Nuno Carvalho <smash@cpan.org> Portuguese Perl Workshop 2008 Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Overview Definition Parrot is a virtual machine designed to compile and execute bytecode for dynamic languages. Parrot is a register-based, bytecode-driven, object-oriented, dynamically typed, self-modifying, asynchronous interpreter. initially created to run Perl6 Core Design Principles speed stability abstraction Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Overview Definition Parrot is a virtual machine designed to compile and execute bytecode for dynamic languages. Parrot is a register-based, bytecode-driven, object-oriented, dynamically typed, self-modifying, asynchronous interpreter. initially created to run Perl6 Core Design Principles speed stability abstraction Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Insight Software CPU register based (four type of registers) also uses stacks no operands limit to opcodes Core Data Types integers strings floating-point PMCs (Parrot Magic Cookie) Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Insight Software CPU register based (four type of registers) also uses stacks no operands limit to opcodes Core Data Types integers strings floating-point PMCs (Parrot Magic Cookie) Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Insight Some Interesting Features complex object and class model system exception handling events (signals) garbage collection MMD (Multi Method Dispatching) multiple concurrency models unicode support Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Parrot’s Architecture Interpretation Flow Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • PASM, PIR And PBC PASM Parrot Assembly traditional low-level features also has advanced features lexical, global variables, objects, etc PIR Parrot Intermediate Representation high level features named variables, etc it still isn’t a HLL PBC Parrot Bytecode sequence of instructions in a binary format Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • PASM, PIR And PBC PASM Parrot Assembly traditional low-level features also has advanced features lexical, global variables, objects, etc PIR Parrot Intermediate Representation high level features named variables, etc it still isn’t a HLL PBC Parrot Bytecode sequence of instructions in a binary format Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • PASM, PIR And PBC PASM Parrot Assembly traditional low-level features also has advanced features lexical, global variables, objects, etc PIR Parrot Intermediate Representation high level features named variables, etc it still isn’t a HLL PBC Parrot Bytecode sequence of instructions in a binary format Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Code Samples PASM lt P0,10,branch set I2,P0 dec P0 PIR cost = minimum(a,b,c) matrix[i;j] = cost j += 1 if j <= n goto inner_cycle Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Code Samples PASM lt P0,10,branch set I2,P0 dec P0 PIR cost = minimum(a,b,c) matrix[i;j] = cost j += 1 if j <= n goto inner_cycle Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Get Your Feet Wet Checking Out ~$ svn co https://svn.perl.org/parrot/trunk parrot Building ~/parrot$ perl Configure.pl ~/parrot$ make Testing ~/parrot$ make test Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Get Your Feet Wet Checking Out ~$ svn co https://svn.perl.org/parrot/trunk parrot Building ~/parrot$ perl Configure.pl ~/parrot$ make Testing ~/parrot$ make test Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Get Your Feet Wet Checking Out ~$ svn co https://svn.perl.org/parrot/trunk parrot Building ~/parrot$ perl Configure.pl ~/parrot$ make Testing ~/parrot$ make test Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • ’Hello world!’ hello.pir .sub hello :main say ’Hello world!’ .end linux x86 $ ./parrot hello.pir Hello world! hello.pbc $ ./parrot --output-pbc --output=hello.pbc hello.pir $ ./parrot hello.pbc Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • ’Hello world!’ hello.pir .sub hello :main say ’Hello world!’ .end linux x86 $ ./parrot hello.pir Hello world! hello.pbc $ ./parrot --output-pbc --output=hello.pbc hello.pir $ ./parrot hello.pbc Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • ’Hello world!’ hello.pir .sub hello :main say ’Hello world!’ .end linux x86 $ ./parrot hello.pir Hello world! hello.pbc $ ./parrot --output-pbc --output=hello.pbc hello.pir $ ./parrot hello.pbc Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Simple Benchmark Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Parrot Compiler Toolkit Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Parrot Compiler Toolkit What? Set of powerfull tools and engines that are used to quickly and easily craft compilers for Parrot. Why? ”There’s an odd misconception in the computing world that writing compilers is hard. This view is fueled by the fact that we don’t write compilers very often. People used to think writing CGI code was hard. Well, it is hard, if you do it in C without any tools.” by Allison Randall Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Parrot Compiler Toolkit What? Set of powerfull tools and engines that are used to quickly and easily craft compilers for Parrot. Why? ”There’s an odd misconception in the computing world that writing compilers is hard. This view is fueled by the fact that we don’t write compilers very often. People used to think writing CGI code was hard. Well, it is hard, if you do it in C without any tools.” by Allison Randall Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Interpretation Flow Four stages of PCT based compilers source to parse tree 1 parse tree to PAST 2 PAST to POST 3 POST to PIR 4 PAST Parrot Abstract Syntax Tree abstract syntax tree nodes that represent common language constructs POST Parrot Opcode Syntax Tree lower abstraction level each node represents a instruction or label Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Interpretation Flow Four stages of PCT based compilers source to parse tree 1 parse tree to PAST 2 PAST to POST 3 POST to PIR 4 PAST Parrot Abstract Syntax Tree abstract syntax tree nodes that represent common language constructs POST Parrot Opcode Syntax Tree lower abstraction level each node represents a instruction or label Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Interpretation Flow Four stages of PCT based compilers source to parse tree 1 parse tree to PAST 2 PAST to POST 3 POST to PIR 4 PAST Parrot Abstract Syntax Tree abstract syntax tree nodes that represent common language constructs POST Parrot Opcode Syntax Tree lower abstraction level each node represents a instruction or label Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Create A New Language Create Files $ perl tools/dev/mk_language_shell.pl msp creating languages/msp/config/makefiles/ creating languages/msp/config/makefiles/root.in creating languages/msp/msp.pir (...) $ ls languages/msp/ config Makefile msp.pir src t Build $ cd languages/msp $ make $ make test (...) All tests successful. Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Create A New Language Create Files $ perl tools/dev/mk_language_shell.pl msp creating languages/msp/config/makefiles/ creating languages/msp/config/makefiles/root.in creating languages/msp/msp.pir (...) $ ls languages/msp/ config Makefile msp.pir src t Build $ cd languages/msp $ make $ make test (...) All tests successful. Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Running Your Compiler Execute a script $ ../../parrot msp.pbc script.msp Run in interactive mode $ ../../parrot msp.pbc msp version 0.1 msp> Default compilation trees $ ../../parrot msp.pbc --target=parse script.msp $ ../../parrot msp.pbc --target=past script.msp $ ../../parrot msp.pbc --target=post script.msp $ ../../parrot msp.pbc --target=pir script.msp Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Running Your Compiler Execute a script $ ../../parrot msp.pbc script.msp Run in interactive mode $ ../../parrot msp.pbc msp version 0.1 msp> Default compilation trees $ ../../parrot msp.pbc --target=parse script.msp $ ../../parrot msp.pbc --target=past script.msp $ ../../parrot msp.pbc --target=post script.msp $ ../../parrot msp.pbc --target=pir script.msp Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Running Your Compiler Execute a script $ ../../parrot msp.pbc script.msp Run in interactive mode $ ../../parrot msp.pbc msp version 0.1 msp> Default compilation trees $ ../../parrot msp.pbc --target=parse script.msp $ ../../parrot msp.pbc --target=past script.msp $ ../../parrot msp.pbc --target=post script.msp $ ../../parrot msp.pbc --target=pir script.msp Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Extending Your Language grammar.pg rule say_statement { ’say’ <value> [ ’,’ <value> ]* ’;’ {*} } actions.pm method say_statement($/) { my $past := PAST::Op.new( :name(’say’), :pasttype(’call’), :node( $/ ) ); for $<value> { $past.push( $( $_ ) ); } make $past; } Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Extending Your Language grammar.pg rule say_statement { ’say’ <value> [ ’,’ <value> ]* ’;’ {*} } actions.pm method say_statement($/) { my $past := PAST::Op.new( :name(’say’), :pasttype(’call’), :node( $/ ) ); for $<value> { $past.push( $( $_ ) ); } make $past; } Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Extending Your Language grammar.pg rule if_statement { ’if’ <expression> ’then’ <block> ’;’ {*} } actions.pm method if_statement($/) { my $cond := $( $<expression> ); my $then := $( $<block> ); my $past := PAST::Op.new( $cond, $then, :pasttype(’if’), :node($/) ); make $past; } Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Extending Your Language grammar.pg rule if_statement { ’if’ <expression> ’then’ <block> ’;’ {*} } actions.pm method if_statement($/) { my $cond := $( $<expression> ); my $then := $( $<block> ); my $past := PAST::Op.new( $cond, $then, :pasttype(’if’), :node($/) ); make $past; } Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Final Notes Conclusion Parrot is a virtual machine Parrot Compiler Toolkit target multiple languages (or brand new) implement Perl6 (rakudo) It’s a work in progress. Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Final Notes Conclusion Parrot is a virtual machine Parrot Compiler Toolkit target multiple languages (or brand new) implement Perl6 (rakudo) It’s a work in progress. Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
    • Questions http://www.parrotcode.org/ Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”