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...
Overview•   Practical MacRuby    •   How is MacRuby different?    •   Working with Cocoa    •   Compiled Ruby!    •   Make...
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 ...
What is MacRuby?• Compiling MacRuby: •   Need LLVM (see the README; brew install llvm) •   rake ; sudo rake install• Bugs ...
No Really, What is   MacRuby?
No Really, What is       MacRuby?A language with:•   Dynamic typing•   Objects everywhere•   Method calls via sending mess...
No Really, What is       MacRuby?A language with:•   Dynamic typing•   Objects everywhere•   Method calls via sending mess...
Ruby Syntax
Ruby Syntax ParserMRI’s parse.y
Ruby Syntax     Parser    MRI’s parse.y     CompilerRoxorCompiler <C++>
Ruby Syntax                             Parser                            MRI’s parse.y                           Compiler...
Ruby Syntax                             Parser                            MRI’s parse.y                           Compiler...
Ruby Syntax                             Parser                            MRI’s parse.y                           Compiler...
Ruby Syntax                             Parser                            MRI’s parse.y                           Compiler...
Integrating with Cocoa• Bridge Support (please download preview 3    from the “files” page)•   gen_bridge_metadata   reads ...
Integrating with Cocoa• String, Array, Hash, are members of the  NSString, NSArray, and NSDictionary class  clusters• Caut...
Demo
A Ruby You Can            Compile• macrubyc• Advantages: •   Faster startup, faster runtime (in most cases) •   Don’t dist...
A Ruby You Can         Compile• -c → Compile and assemble; good for  multistage builds• -C → Compile, assemble, and link c...
Demo
I wanna be an App       store billionaire...• Downloads contain Xcode templates  (mostly work in Xcode 4)• Integration wit...
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•...
Garbage Collector:the Next Generation(?)• Ruby does A LOT of allocations• Nice to not have to stop the world, but...• Writ...
RegExps:               ICU• Oniguruma is not (real thread) thread safe• ICU is • thread safe • Unicode compatible • not as...
Hash method syntax• Ruby 1.9’s hash syntax with Symbol keys:  a = { foo: 1, bar: 2, baz: “Hello, world” }  • ...looks a bi...
Hash method syntax• MacRuby turns method calls with hash  arguments into SEL• MacRuby turns method definitions with  hash l...
LLVM, JIT, and Hacking• LLVM provides optimizations• LLVM provides JIT utilities (kinda slow)• MacRuby can emit LLVM...  V...
Demo
GCD & The Future
GCD• MacRuby can tap directly into GCD• Dispatch module: • Dispatch::Queue • Dispatch::Group • Dispatch::Source• Dispatch ...
GCD• Dispatch is a powerful tool for concurrent  programming• Example: ControlTower • MacRuby Rack-based server • Uses GCD...
GCD
GCD• Can we make GCD work in MRI?• JRuby thinks they can make it work...  https://github.com/headius/jcd• GCD is Multithre...
Who Is MacRuby?•   Laurent Sansonetti   •   Watson•   Vincent Isambart     •   Takao Kouji•   Eloy Durán           •   Mar...
Thank you!http://ofps.oreilly.com/titles/9781449380373/
Upcoming SlideShare
Loading in...5
×

MacRuby

1,417

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,417
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MacRuby

  1. 1. MacRuby What is it?and why should you care? Presented by: Joshua Ballanco
  2. 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. 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
  4. 4. What is MacRuby?
  5. 5. What is MacRuby?
  6. 6. What is MacRuby?
  7. 7. What is MacRuby?
  8. 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. 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. 10. No Really, What is MacRuby?
  11. 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. 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
  13. 13. Ruby Syntax
  14. 14. Ruby Syntax ParserMRI’s parse.y
  15. 15. Ruby Syntax Parser MRI’s parse.y CompilerRoxorCompiler <C++>
  16. 16. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL)RoxorVM & RoxorCore <C++>
  17. 17. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) LLVM (with JIT)RoxorVM & RoxorCore <C++>
  18. 18. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) LLVM (with JIT)RoxorVM & RoxorCore <C++>
  19. 19. Ruby Syntax Parser MRI’s parse.y Compiler RoxorCompiler <C++> VM (sans GVL) LLVM (with JIT)RoxorVM & RoxorCore <C++> Objective-C Runtime
  20. 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. 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. 22. Demo
  23. 23. A Ruby You Can Compile• macrubyc• Advantages: • Faster startup, faster runtime (in most cases) • Don’t distribute the source!• Disadvantages: • ? • ...some bugs
  24. 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. 25. Demo
  26. 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. 27. I wanna be an App store billionaire...
  28. 28. I wanna be an App store billionaire... QuickAlarm Briquette Timey Zero2Nine
  29. 29. MacRuby Nuts & Bolts
  30. 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. 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. 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. 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. 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. 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. 36. Demo
  37. 37. GCD & The Future
  38. 38. GCD• MacRuby can tap directly into GCD• Dispatch module: • Dispatch::Queue • Dispatch::Group • Dispatch::Source• Dispatch Gem too!
  39. 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. 40. GCD
  41. 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. 42. Who Is MacRuby?• Laurent Sansonetti • Watson• Vincent Isambart • Takao Kouji• Eloy Durán • Mark Rada• Matt Aimonetti • You?• Joshua Ballanco• Thibault Martin- Lagardette
  43. 43. Thank you!http://ofps.oreilly.com/titles/9781449380373/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×