SlideShare a Scribd company logo
Building a Miserably
                Fun Compiler in
                     JRuby.
                                Chris Umbel

                                @chrisumbel

                         http://www.chrisumbel.com


Sunday, January 29, 12
Agenda


                         Ruby/JRuby introduction

                         Talk background

                         Building a compiler




Sunday, January 29, 12
Ruby
                         Dynamic, but strongly typed.

                         Object-oriented

                         metaprogrammable

                         Has multiple implementations (MRI,
                         IronRuby, Rubinius, JRuby)

                         Has functional features (Higher-order
                         functions, blocks)



Sunday, January 29, 12
Ruby Examples



                         OO

                         Data Structures




Sunday, January 29, 12
JRuby

                         Highly compatible Ruby implementation

                         Written in Java/runs on the JVM

                         Can consume arbitrary Java libraries

                         Favorable concurrency characteristics
                         to CRuby (no GIL)



Sunday, January 29, 12
JRuby Examples


                         Java types

                         Using .jars

                         conventions




Sunday, January 29, 12
Inspiration

                         Ian Dees @undees

                         JRubyConf 2011

                         JRuby, Not Just for Hard-Headed
                         Pragmatists Anymore

                         Author: Using JRuby: Bringing Ruby to
                         Java



Sunday, January 29, 12
JRubyConf


                         Practical problem solving

                         Customers, Customers, Customers!

                         ROI




Sunday, January 29, 12
Thnad
                         Just enough of a fictional
                         programming language to show how to
                         write a compiler

                         https://github.com/undees/thnad

                         Sort of JavaScript-ey

                         Allusion to the greatest of classical
                         literature


Sunday, January 29, 12
What We’ll Build


                         Lisp-style S-expressions

                         Pure JRuby

                         Compiles to Java bytecode




Sunday, January 29, 12
What We’ll Use
                         JRuby

                         Parslet

                           Kaspar Shiess

                           Parser in pure Ruby

                         Bitescript

                           Charles Nutter

                           JVM bytecode emitter for JRuby
Sunday, January 29, 12
What it wont’ do

                         Conditionals

                         Non-parametric locally scoped
                         variables

                         OO

                         Provide Java library support,
                         standard or otherwise.



Sunday, January 29, 12
What It’ll Do

                         Basic math

                         Functions

                         Standard output

                         Suck!!!




Sunday, January 29, 12
sucklang




Sunday, January 29, 12
Language Components


                         Simple Atoms (identifiers; literal
                         strings and integers)

                         Lists

                         Function calls




Sunday, January 29, 12
sucklang Code Sample




                (defun foo [x y]
                  (+ x y))
                (println "result is " (foo 6 9))




Sunday, January 29, 12
Parts


                         Parser

                         Transmogrifier

                         Compiler




Sunday, January 29, 12
Step 1

                         Parser

                           Numbers

                           Basic list

                           Whitespace handling




Sunday, January 29, 12
Step 2



                         Parser

                           Expressions




Sunday, January 29, 12
Step 3

                         Parser

                           Identifiers

                           Atoms

                           Lists in lists

                           Operators are Identifiers



Sunday, January 29, 12
Step 4



                         Parser

                           Strings




Sunday, January 29, 12
Step 5



                         Parser

                           Vectors




Sunday, January 29, 12
Step 6



                         Transmogrifier

                           AST




Sunday, January 29, 12
Step 7: STOP!



                         javap - Java disassembler




Sunday, January 29, 12
Step 8



                         bitescript example




Sunday, January 29, 12
Step 9


                         compiler

                           java requires/imports

                           emitting of simple types




Sunday, January 29, 12
Step 10

                         emitting of functions

                           +

                           println

                           defun

                           calls



Sunday, January 29, 12
What It Did


                         Parsed S-expressions into an AST

                         Compiled AST to JVM bytecode

                         Sucked (a lot of assumptions)




Sunday, January 29, 12
What We’ve Learned


                         Parslet

                         Bitescript

                         JVM innards




Sunday, January 29, 12
Thank you!




Sunday, January 29, 12

More Related Content

Similar to Building a compiler in JRuby

Function currying
Function curryingFunction currying
Function currying
Thomas Burleson
 
Reef - ESUG2011
Reef  - ESUG2011Reef  - ESUG2011
Reef - ESUG2011
Esteban Lorenzano
 
Test Driven Development - Caleb Tutty
Test Driven Development - Caleb TuttyTest Driven Development - Caleb Tutty
Test Driven Development - Caleb Tutty
Auckland Web Dev Nights
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
Jared Faris
 
D3 interactivity Linegraph basic example
D3 interactivity Linegraph basic exampleD3 interactivity Linegraph basic example
D3 interactivity Linegraph basic example
Adam Pah
 
Building Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and CascadingBuilding Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and Cascading
cwensel
 
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
cwensel
 

Similar to Building a compiler in JRuby (8)

JRuby at Square
JRuby at SquareJRuby at Square
JRuby at Square
 
Function currying
Function curryingFunction currying
Function currying
 
Reef - ESUG2011
Reef  - ESUG2011Reef  - ESUG2011
Reef - ESUG2011
 
Test Driven Development - Caleb Tutty
Test Driven Development - Caleb TuttyTest Driven Development - Caleb Tutty
Test Driven Development - Caleb Tutty
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
D3 interactivity Linegraph basic example
D3 interactivity Linegraph basic exampleD3 interactivity Linegraph basic example
D3 interactivity Linegraph basic example
 
Building Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and CascadingBuilding Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and Cascading
 
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
SAM SIG: Hadoop architecture, MapReduce patterns, and best practices with Cas...
 

Recently uploaded

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 

Building a compiler in JRuby

  • 1. Building a Miserably Fun Compiler in JRuby. Chris Umbel @chrisumbel http://www.chrisumbel.com Sunday, January 29, 12
  • 2. Agenda Ruby/JRuby introduction Talk background Building a compiler Sunday, January 29, 12
  • 3. Ruby Dynamic, but strongly typed. Object-oriented metaprogrammable Has multiple implementations (MRI, IronRuby, Rubinius, JRuby) Has functional features (Higher-order functions, blocks) Sunday, January 29, 12
  • 4. Ruby Examples OO Data Structures Sunday, January 29, 12
  • 5. JRuby Highly compatible Ruby implementation Written in Java/runs on the JVM Can consume arbitrary Java libraries Favorable concurrency characteristics to CRuby (no GIL) Sunday, January 29, 12
  • 6. JRuby Examples Java types Using .jars conventions Sunday, January 29, 12
  • 7. Inspiration Ian Dees @undees JRubyConf 2011 JRuby, Not Just for Hard-Headed Pragmatists Anymore Author: Using JRuby: Bringing Ruby to Java Sunday, January 29, 12
  • 8. JRubyConf Practical problem solving Customers, Customers, Customers! ROI Sunday, January 29, 12
  • 9. Thnad Just enough of a fictional programming language to show how to write a compiler https://github.com/undees/thnad Sort of JavaScript-ey Allusion to the greatest of classical literature Sunday, January 29, 12
  • 10. What We’ll Build Lisp-style S-expressions Pure JRuby Compiles to Java bytecode Sunday, January 29, 12
  • 11. What We’ll Use JRuby Parslet Kaspar Shiess Parser in pure Ruby Bitescript Charles Nutter JVM bytecode emitter for JRuby Sunday, January 29, 12
  • 12. What it wont’ do Conditionals Non-parametric locally scoped variables OO Provide Java library support, standard or otherwise. Sunday, January 29, 12
  • 13. What It’ll Do Basic math Functions Standard output Suck!!! Sunday, January 29, 12
  • 15. Language Components Simple Atoms (identifiers; literal strings and integers) Lists Function calls Sunday, January 29, 12
  • 16. sucklang Code Sample (defun foo [x y] (+ x y)) (println "result is " (foo 6 9)) Sunday, January 29, 12
  • 17. Parts Parser Transmogrifier Compiler Sunday, January 29, 12
  • 18. Step 1 Parser Numbers Basic list Whitespace handling Sunday, January 29, 12
  • 19. Step 2 Parser Expressions Sunday, January 29, 12
  • 20. Step 3 Parser Identifiers Atoms Lists in lists Operators are Identifiers Sunday, January 29, 12
  • 21. Step 4 Parser Strings Sunday, January 29, 12
  • 22. Step 5 Parser Vectors Sunday, January 29, 12
  • 23. Step 6 Transmogrifier AST Sunday, January 29, 12
  • 24. Step 7: STOP! javap - Java disassembler Sunday, January 29, 12
  • 25. Step 8 bitescript example Sunday, January 29, 12
  • 26. Step 9 compiler java requires/imports emitting of simple types Sunday, January 29, 12
  • 27. Step 10 emitting of functions + println defun calls Sunday, January 29, 12
  • 28. What It Did Parsed S-expressions into an AST Compiled AST to JVM bytecode Sucked (a lot of assumptions) Sunday, January 29, 12
  • 29. What We’ve Learned Parslet Bitescript JVM innards Sunday, January 29, 12