SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler offline
”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”

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a Parrot -- "one bytecode to rule them all"

Semelhante a 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
 

Último

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Último (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

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”