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

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
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
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Kürzlich hochgeladen (20)

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
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
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

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”