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

Contenu connexe

Tendances

Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and PythonAndreas Schreiber
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Languagezefhemel
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonRanjith kumar
 
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code LinterPerl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Lintermoznion
 
First python project
First python projectFirst python project
First python projectNeetu Jain
 
PyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fastPyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fastPyCon Italia
 
A Better Python for the JVM
A Better Python for the JVMA Better Python for the JVM
A Better Python for the JVMTobias Lindaaker
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data sciencebhavesh lande
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOLiran Zvibel
 
Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Ivan Chernoff
 
How to use Ruby code inside Elixir
How to use Ruby code inside ElixirHow to use Ruby code inside Elixir
How to use Ruby code inside ElixirWeverton Timoteo
 
The Ring programming language version 1.5.2 book - Part 180 of 181
The Ring programming language version 1.5.2 book - Part 180 of 181The Ring programming language version 1.5.2 book - Part 180 of 181
The Ring programming language version 1.5.2 book - Part 180 of 181Mahmoud Samir Fayed
 

Tendances (18)

Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and Python
 
Mixing Python and Java
Mixing Python and JavaMixing Python and Java
Mixing Python and Java
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Language
 
Python
PythonPython
Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code LinterPerl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Linter
 
Parrot Compiler Tools
Parrot Compiler ToolsParrot Compiler Tools
Parrot Compiler Tools
 
First python project
First python projectFirst python project
First python project
 
PyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fastPyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fast
 
Talk About Performance
Talk About PerformanceTalk About Performance
Talk About Performance
 
NooJ-2018-Palermo
NooJ-2018-PalermoNooJ-2018-Palermo
NooJ-2018-Palermo
 
A Better Python for the JVM
A Better Python for the JVMA Better Python for the JVM
A Better Python for the JVM
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
 
Python Flavors
Python FlavorsPython Flavors
Python Flavors
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
 
Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!
 
How to use Ruby code inside Elixir
How to use Ruby code inside ElixirHow to use Ruby code inside Elixir
How to use Ruby code inside Elixir
 
The Ring programming language version 1.5.2 book - Part 180 of 181
The Ring programming language version 1.5.2 book - Part 180 of 181The Ring programming language version 1.5.2 book - Part 180 of 181
The Ring programming language version 1.5.2 book - Part 180 of 181
 

En vedette

Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Workhorse Computing
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story ofAndrew Shitov
 
iPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.comiPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.comSeth dickens
 
Ontology Aware Applications
Ontology Aware ApplicationsOntology Aware Applications
Ontology Aware ApplicationsNuno Carvalho
 
Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012Nuno Carvalho
 

En vedette (6)

Introducing perl6
Introducing perl6Introducing perl6
Introducing perl6
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story of
 
iPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.comiPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.com
 
Ontology Aware Applications
Ontology Aware ApplicationsOntology Aware Applications
Ontology Aware Applications
 
Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012
 

Similaire à Parrot -- "one bytecode to rule them all"

Similaire à Parrot -- "one bytecode to rule them all" (20)

The Parrot VM
The Parrot VMThe Parrot VM
The Parrot VM
 
perl
perlperl
perl
 
perl
perlperl
perl
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?
 
Pi Is For Python
Pi Is For PythonPi Is For Python
Pi Is For Python
 
Le PERL est mort
Le PERL est mortLe PERL est mort
Le PERL est mort
 
Mastering Regex in Perl
Mastering Regex in PerlMastering Regex in Perl
Mastering Regex in Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Will iPython replace Bash?
Will iPython replace Bash?Will iPython replace Bash?
Will iPython replace Bash?
 
Will iPython replace bash?
Will iPython replace bash?Will iPython replace bash?
Will iPython replace bash?
 
Was können wir von Rebol lernen?
Was können wir von Rebol lernen?Was können wir von Rebol lernen?
Was können wir von Rebol lernen?
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Parrot tutorial
Parrot tutorialParrot tutorial
Parrot tutorial
 
Perl
PerlPerl
Perl
 
Perl family: 15 years of Perl 6 and Perl 5
Perl family: 15 years of Perl 6 and Perl 5Perl family: 15 years of Perl 6 and Perl 5
Perl family: 15 years of Perl 6 and Perl 5
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For Managers
 
Theperlreview
TheperlreviewTheperlreview
Theperlreview
 
effective_r27
effective_r27effective_r27
effective_r27
 
Using SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with PythonUsing SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with Python
 

Dernier

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Dernier (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Parrot -- "one bytecode to rule them all"

  • 1. ”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”
  • 2. 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”
  • 3. 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”
  • 4. 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”
  • 5. 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”
  • 6. 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”
  • 7. Parrot’s Architecture Interpretation Flow Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
  • 8. 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”
  • 9. 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”
  • 10. 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”
  • 11. 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”
  • 12. 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”
  • 13. 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”
  • 14. 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”
  • 15. 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”
  • 16. ’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”
  • 17. ’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”
  • 18. ’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”
  • 19. Simple Benchmark Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
  • 20. Parrot Compiler Toolkit Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”
  • 21. 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”
  • 22. 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”
  • 23. 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”
  • 24. 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”
  • 25. 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”
  • 26. 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”
  • 27. 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”
  • 28. 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”
  • 29. 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”
  • 30. 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”
  • 31. 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”
  • 32. 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”
  • 33. 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”
  • 34. 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”
  • 35. 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”
  • 36. 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”
  • 37. Questions http://www.parrotcode.org/ Portuguese Perl Workshop 2008 Parrot ”one bytecode to rule them all”