SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
”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”

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie Parrot -- "one bytecode to rule them all"

Ähnlich wie 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
 

Kürzlich hochgeladen

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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Kürzlich hochgeladen (20)

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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

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”