SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
MacRuby
      What is it?
and why should you care?


 Presented by: Joshua Ballanco
A bit about me...

• Using Ruby since 2004 (didn’t discover
  Rails until 2006)
• Worked for Apple 2006-2010 (Fifth Ave
  store & HQ in Cupertino)
• Now at Patch (just completed a migration
  to Ruby 1.9)
• MacRuby Core Team member
Overview
•   Practical MacRuby
    •   How is MacRuby different?

    •   Working with Cocoa

    •   Compiled Ruby!

    •   Make your millions on the App store

•   Nuts & Bolts
    •   GC

    •   Regular Expression Engine

    •   Hash method syntax

    •   LLVM & other Hacking

•   GCD
What is MacRuby?
What is MacRuby?
What is MacRuby?
What is MacRuby?
What is MacRuby?

• http://www.macruby.org
• http://www.macruby.org/files/
• http://www.macruby.org/files/nightlies/
• Available from RVM (but not recommended)
• Source now located at GitHub!
  https://github.com/MacRuby/MacRuby
What is MacRuby?
• Compiling MacRuby:
 •   Need LLVM (see the README; brew install llvm)

 •   rake ; sudo rake install

• Bugs – https://www.macruby.org/trac/report
• MacRuby-devel mailing list
• @macruby, #macruby
No Really, What is
   MacRuby?
No Really, What is
       MacRuby?
A language with:
•   Dynamic typing
•   Objects everywhere
•   Method calls via sending messages
•   Automatic generation of accessors
•   Methods can be added to classes at runtime
•   Garbage Collection
•   Closures
No Really, What is
       MacRuby?
A language with:
•   Dynamic typing
•   Objects everywhere
•   Method calls via sending messages
•   Automatic generation of accessors
•   Methods can be added to classes at runtime
•   Garbage Collection
•   Closures
               ...called Objective-C
Ruby Syntax
Ruby Syntax




 Parser
MRI’s parse.y
Ruby Syntax




     Parser
    MRI’s parse.y




     Compiler
RoxorCompiler <C++>
Ruby Syntax




                             Parser
                            MRI’s parse.y




                           Compiler
                      RoxorCompiler <C++>




     VM (sans GVL)
RoxorVM & RoxorCore <C++>
Ruby Syntax




                             Parser
                            MRI’s parse.y




                           Compiler
                      RoxorCompiler <C++>




     VM (sans GVL)
                                            LLVM (with JIT)
RoxorVM & RoxorCore <C++>
Ruby Syntax




                             Parser
                            MRI’s parse.y




                           Compiler
                      RoxorCompiler <C++>




     VM (sans GVL)
                                            LLVM (with JIT)
RoxorVM & RoxorCore <C++>
Ruby Syntax




                             Parser
                            MRI’s parse.y




                           Compiler
                      RoxorCompiler <C++>




     VM (sans GVL)
                                            LLVM (with JIT)
RoxorVM & RoxorCore <C++>




                     Objective-C Runtime
Integrating with Cocoa
• Bridge Support (please download preview 3
    from the “files” page)
•   gen_bridge_metadata   reads header files
    and generates XML descriptions of types
    and method signatures
• MacRuby uses BS files to construct calls
    and access constants and types
• framework     “Foundation”
Integrating with Cocoa
• String, Array, Hash, are members of the
  NSString, NSArray, and NSDictionary class
  clusters
• Caution: NSString, NSArray, and
  NSDictionary will lie to you!
• Time is implemented as a subclass of
  NSDate
Demo
A Ruby You Can
            Compile
• macrubyc
• Advantages:
 •   Faster startup, faster runtime (in most cases)

 •   Don’t distribute the source!

• Disadvantages:
 •   ?

 •   ...some bugs
A Ruby You Can
         Compile
• -c → Compile and assemble; good for
  multistage builds

• -C → Compile, assemble, and link creating
  an *.rbo
• Can also create stand-alone executables
  and entire “*.framework”s (experimental)
Demo
I wanna be an App
       store billionaire...
• Downloads contain Xcode templates
  (mostly work in Xcode 4)
• Integration with Interface Builder
• macruby_deploy
  •   Includes BS files

  •   Unpacks Gems

  •   Compiles source
I wanna be an App
 store billionaire...
I wanna be an App
 store billionaire...
  QuickAlarm

            Briquette

    Timey

            Zero2Nine
MacRuby Nuts & Bolts
Garbage Collector:
        libauto
• Yet another open source project from
  Apple
• The GC for Obj-C
• Based on write barriers
• scanning, conservative, generational, multi-
  threaded garbage collector...
• ...unfortunately...slow
Garbage Collector:
the Next Generation(?)
• Ruby does A LOT of allocations
• Nice to not have to stop the world, but...
• Write barriers are slow
• Maybe ref counting?
• Maybe MRI’s collector isn’t so bad after all...
RegExps:
               ICU
• Oniguruma is not (real thread) thread safe
• ICU is
 • thread safe
 • Unicode compatible
 • not as crazy feature-full as Oniguruma
• There are some bugs...but honestly, stop
  doing that with RegExps!!!
Hash method syntax
• Ruby 1.9’s hash syntax with Symbol keys:
  a = { foo: 1, bar: 2, baz: “Hello, world” }

  • ...looks a bit like:
     [@”Hello, world” rangeOfString:@”ello”
     options: NSCaseInsensitiveSearch]
• Let’s go with that!
Hash method syntax
• MacRuby turns method calls with hash
  arguments into SEL
• MacRuby turns method definitions with
  hash lists into SEL
• MacRuby can call Objective-C
• Objective-C can call MacRuby, but when
  possible you should use:
  [[MacRuby sharedRuntime]
      performRubySelector:@”foo”]
LLVM, JIT, and Hacking

• LLVM provides optimizations
• LLVM provides JIT utilities (kinda slow)
• MacRuby can emit LLVM...
  VM_DUMP_IR=1 macruby -e "def foo; puts
  'hello'; end; foo"

• Find other neat tricks in HACKING.rdoc
Demo
GCD & The Future
GCD
• MacRuby can tap directly into GCD
• Dispatch module:
 • Dispatch::Queue
 • Dispatch::Group
 • Dispatch::Source
• Dispatch Gem too!
GCD
• Dispatch is a powerful tool for concurrent
  programming
• Example: ControlTower
 • MacRuby Rack-based server
 • Uses GCD to handle requets
 • Accomplishes in 1 line what takes Thin/
    EventMachine > 6000 lines of C++ &
    Ruby
GCD
GCD

• Can we make GCD work in MRI?
• JRuby thinks they can make it work...
  https://github.com/headius/jcd
• GCD is Multithreaded Programming, Ruby
  Style
Who Is MacRuby?
•   Laurent Sansonetti   •   Watson

•   Vincent Isambart     •   Takao Kouji

•   Eloy Durán           •   Mark Rada

•   Matt Aimonetti       •   You?

•   Joshua Ballanco

•   Thibault Martin-
    Lagardette
Thank you!

http://ofps.oreilly.com/titles/9781449380373/

Weitere ähnliche Inhalte

Was ist angesagt?

JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
elliando dias
 
JRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform FurtherJRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform Further
Charles Nutter
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
elliando dias
 

Was ist angesagt? (20)

How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the world
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage library
 
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
 
MacRuby, an introduction
MacRuby, an introductionMacRuby, an introduction
MacRuby, an introduction
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovRuby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
 
TRICK2013 Results
TRICK2013 ResultsTRICK2013 Results
TRICK2013 Results
 
JRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform FurtherJRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform Further
 
Ruby Presentation - Beamer
Ruby Presentation - BeamerRuby Presentation - Beamer
Ruby Presentation - Beamer
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Emrubyconf
EmrubyconfEmrubyconf
Emrubyconf
 
Ruby3x3: How are we going to measure 3x
Ruby3x3: How are we going to measure 3xRuby3x3: How are we going to measure 3x
Ruby3x3: How are we going to measure 3x
 
Ruby programming
Ruby programmingRuby programming
Ruby programming
 
Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014
 

Ähnlich wie MacRuby

MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoa
Thilo Utke
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
elliando dias
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS development
toamitkumar
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門
Wen-Tien Chang
 
GUI Programming with MacRuby
GUI Programming with MacRubyGUI Programming with MacRuby
GUI Programming with MacRuby
Erik Berlin
 

Ähnlich wie MacRuby (20)

ruby-cocoa
ruby-cocoaruby-cocoa
ruby-cocoa
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoa
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS development
 
Intro to Crystal Programming Language
Intro to Crystal Programming LanguageIntro to Crystal Programming Language
Intro to Crystal Programming Language
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby Developers
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
 
Extending Ruby using C++
Extending Ruby using C++Extending Ruby using C++
Extending Ruby using C++
 
The story of language development
The story of language developmentThe story of language development
The story of language development
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門
 
GUI Programming with MacRuby
GUI Programming with MacRubyGUI Programming with MacRuby
GUI Programming with MacRuby
 

Mehr von bostonrb (6)

Measuring
MeasuringMeasuring
Measuring
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
 
Capybara-Webkit
Capybara-WebkitCapybara-Webkit
Capybara-Webkit
 
Copycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRBCopycopter Presentation by Joe Ferris at BostonRB
Copycopter Presentation by Joe Ferris at BostonRB
 
You're Doing It Wrong
You're Doing It WrongYou're Doing It Wrong
You're Doing It Wrong
 
You're Doing It Wrong
You're Doing It WrongYou're Doing It Wrong
You're Doing It Wrong
 

MacRuby

  • 1. MacRuby What is it? and why should you care? Presented by: Joshua Ballanco
  • 2. A bit about me... • Using Ruby since 2004 (didn’t discover Rails until 2006) • Worked for Apple 2006-2010 (Fifth Ave store & HQ in Cupertino) • Now at Patch (just completed a migration to Ruby 1.9) • MacRuby Core Team member
  • 3. Overview • Practical MacRuby • How is MacRuby different? • Working with Cocoa • Compiled Ruby! • Make your millions on the App store • Nuts & Bolts • GC • Regular Expression Engine • Hash method syntax • LLVM & other Hacking • GCD
  • 8. What is MacRuby? • http://www.macruby.org • http://www.macruby.org/files/ • http://www.macruby.org/files/nightlies/ • Available from RVM (but not recommended) • Source now located at GitHub! https://github.com/MacRuby/MacRuby
  • 9. What is MacRuby? • Compiling MacRuby: • Need LLVM (see the README; brew install llvm) • rake ; sudo rake install • Bugs – https://www.macruby.org/trac/report • MacRuby-devel mailing list • @macruby, #macruby
  • 10. No Really, What is MacRuby?
  • 11. No Really, What is MacRuby? A language with: • Dynamic typing • Objects everywhere • Method calls via sending messages • Automatic generation of accessors • Methods can be added to classes at runtime • Garbage Collection • Closures
  • 12. No Really, What is MacRuby? A language with: • Dynamic typing • Objects everywhere • Method calls via sending messages • Automatic generation of accessors • Methods can be added to classes at runtime • Garbage Collection • Closures ...called Objective-C
  • 15. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++>
  • 16. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) RoxorVM & RoxorCore <C++>
  • 17. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) LLVM (with JIT) RoxorVM & RoxorCore <C++>
  • 18. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) LLVM (with JIT) RoxorVM & RoxorCore <C++>
  • 19. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) LLVM (with JIT) RoxorVM & RoxorCore <C++> Objective-C Runtime
  • 20. Integrating with Cocoa • Bridge Support (please download preview 3 from the “files” page) • gen_bridge_metadata reads header files and generates XML descriptions of types and method signatures • MacRuby uses BS files to construct calls and access constants and types • framework “Foundation”
  • 21. Integrating with Cocoa • String, Array, Hash, are members of the NSString, NSArray, and NSDictionary class clusters • Caution: NSString, NSArray, and NSDictionary will lie to you! • Time is implemented as a subclass of NSDate
  • 22. Demo
  • 23. A Ruby You Can Compile • macrubyc • Advantages: • Faster startup, faster runtime (in most cases) • Don’t distribute the source! • Disadvantages: • ? • ...some bugs
  • 24. A Ruby You Can Compile • -c → Compile and assemble; good for multistage builds • -C → Compile, assemble, and link creating an *.rbo • Can also create stand-alone executables and entire “*.framework”s (experimental)
  • 25. Demo
  • 26. I wanna be an App store billionaire... • Downloads contain Xcode templates (mostly work in Xcode 4) • Integration with Interface Builder • macruby_deploy • Includes BS files • Unpacks Gems • Compiles source
  • 27. I wanna be an App store billionaire...
  • 28. I wanna be an App store billionaire... QuickAlarm Briquette Timey Zero2Nine
  • 29. MacRuby Nuts & Bolts
  • 30. Garbage Collector: libauto • Yet another open source project from Apple • The GC for Obj-C • Based on write barriers • scanning, conservative, generational, multi- threaded garbage collector... • ...unfortunately...slow
  • 31. Garbage Collector: the Next Generation(?) • Ruby does A LOT of allocations • Nice to not have to stop the world, but... • Write barriers are slow • Maybe ref counting? • Maybe MRI’s collector isn’t so bad after all...
  • 32. RegExps: ICU • Oniguruma is not (real thread) thread safe • ICU is • thread safe • Unicode compatible • not as crazy feature-full as Oniguruma • There are some bugs...but honestly, stop doing that with RegExps!!!
  • 33. Hash method syntax • Ruby 1.9’s hash syntax with Symbol keys: a = { foo: 1, bar: 2, baz: “Hello, world” } • ...looks a bit like: [@”Hello, world” rangeOfString:@”ello” options: NSCaseInsensitiveSearch] • Let’s go with that!
  • 34. Hash method syntax • MacRuby turns method calls with hash arguments into SEL • MacRuby turns method definitions with hash lists into SEL • MacRuby can call Objective-C • Objective-C can call MacRuby, but when possible you should use: [[MacRuby sharedRuntime] performRubySelector:@”foo”]
  • 35. LLVM, JIT, and Hacking • LLVM provides optimizations • LLVM provides JIT utilities (kinda slow) • MacRuby can emit LLVM... VM_DUMP_IR=1 macruby -e "def foo; puts 'hello'; end; foo" • Find other neat tricks in HACKING.rdoc
  • 36. Demo
  • 37. GCD & The Future
  • 38. GCD • MacRuby can tap directly into GCD • Dispatch module: • Dispatch::Queue • Dispatch::Group • Dispatch::Source • Dispatch Gem too!
  • 39. GCD • Dispatch is a powerful tool for concurrent programming • Example: ControlTower • MacRuby Rack-based server • Uses GCD to handle requets • Accomplishes in 1 line what takes Thin/ EventMachine > 6000 lines of C++ & Ruby
  • 40. GCD
  • 41. GCD • Can we make GCD work in MRI? • JRuby thinks they can make it work... https://github.com/headius/jcd • GCD is Multithreaded Programming, Ruby Style
  • 42. Who Is MacRuby? • Laurent Sansonetti • Watson • Vincent Isambart • Takao Kouji • Eloy Durán • Mark Rada • Matt Aimonetti • You? • Joshua Ballanco • Thibault Martin- Lagardette