MACRUBYA p p l e ’ s R u b y
M a t t A i m o n e t t i - R u b y C o n f X - N o v 2 0 1 0
Friday, November 12, 2010
ABOUT ME
Friday, November 12, 2010
Friday, November 12, 2010
Hacker
Friday, November 12, 2010
MacRuby
Friday, November 12, 2010
http://macruby.labs.oreilly.com/
Friday, November 12, 2010
MACRUBYA p p l e ’ s R u b y
Friday, November 12, 2010
MacRuby
YARV
Parser
GC
Runtime
Stdlib
Builtin classes
Ruby 1.9
Friday, November 12, 2010
MacRuby
LLVM/Roxor
Parser Stdlib
AOT JIT
Obj-C Runtime
libobjc
libauto
Builtin Classes
CoreFoundation
MacRuby
Friday, Nove...
MacRuby
LLVM/Roxor
Parser Stdlib
AOT JIT
Obj-C Runtime
libobjc
libauto
Builtin Classes
CoreFoundation
YARV
Parser
GC
Runti...
MacRuby
LLVM
Friday, November 12, 2010
JIT Compilation
MacRuby
Friday, November 12, 2010
JIT CompilationMacRuby
Ruby AST
LLVM IR
Machine
Code
CPU
Transforms the AST into LLVM
intermediate representation
... opti...
AOT Compilation
MacRuby
Friday, November 12, 2010
AOT CompilationMacRuby
Ruby AST
LLVM IR
Machine
Code
Mach-O
Object File
CLI tool or Xcode
... applies more optimizations
....
NO GIL
No Global Interpreter Lock
Friday, November 12, 2010
GC Thread Thread
VM VM VM
Core
Friday, November 12, 2010
MULTI-THREADED
GENERATIONAL
GC
Friday, November 12, 2010
NATIVE ACCESS
TO COCOA
Friday, November 12, 2010
WHEN .
TO USE
MACRUBY?
NOT
Friday, November 12, 2010
YOU DON’T HAVE A MAC
Friday, November 12, 2010
LINUX HOSTING
Friday, November 12, 2010
YOU DON’T WANTTO LEARN
Friday, November 12, 2010
WHAT’S NEW?
Friday, November 12, 2010
COCOA DEV
IS STABLE
Friday, November 12, 2010
DNA Sequencing
by Hampton Catlin
Friday, November 12, 2010
AOT
COMPILATION
Friday, November 12, 2010
MacRuby: Definitive Guide
Hello World Example
Friday, November 12, 2010
framework 'AppKit'
class AppDelegate
def applicationDidFinishLaunching(notification)
voice_type = "com.apple.speech.synthe...
$ macrubyc hello_world.rb -o demo
$ file demo
demo:
Mach-O 64-bit executable x86_64
$ ./demo
Compile to machine code
Frida...
w00t!!
Friday, November 12, 2010
Create compiled/
dynamic libraries
$ macrubyc file1.rb file2.rb
-o shared.dylib --dylib
$ macrubyc other_project_source.rb...
DEBUGGER
Friday, November 12, 2010
characters = %w{Adama Apollo Baltar Roslin
StarBuck Six}
def cylon?(character)
false # buggy detector
end
characters.each ...
$ macruby cylon_detector.rb
Adama is not a cylon.
Apollo is not a cylon.
Baltar is not a cylon.
Roslin is not a cylon.
Sta...
$ macrubyd cylon_detector.rb
Starting program.
1!characters = %w{Adama Apollo
Baltar Roslin StarBuck Six}
cylon_detector.r...
cylon_detector.rb:1>
b cylon_detector.rb:8
if character == 'Six'
Added breakpoint 1.
Added a breakpoint on a
specific file...
cylon_detector.rb:1> c
Adama is not a cylon.
Apollo is not a cylon.
Baltar is not a cylon.
Roslin is not a cylon.
StarBuck...
cylon_detector.rb:8>
p character
=> "Six"
cylon_detector.rb:8>
p cylon?(character)
=> false
Bug confirmed :(
Friday, Novem...
cylon_detector.rb:8>
p def cylon?(character)
character == 'Six'
end
ZOMG live bug fixing!
Friday, November 12, 2010
cylon_detector.rb:8> c
Six is a Cylon!
Program exited.
w00t!!
Friday, November 12, 2010
GCD API
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
Friday, November 12, 2010
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
Threads can becomplicated to program:(
Friday, November 12, 20...
Global Interpreter Lock
VM
Friday, November 12, 2010
Slow :(
Friday, November 12, 2010
Full concurrency via
multiple processes :(
Friday, November 12, 2010
Safe data :)
Friday, November 12, 2010
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
MacRuby doesn’t have
a global VM lock
Friday, November 12, 2010
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
MacRuby
VM
Core
VM
VM
Friday, November 12, 2010
Good but not good
enough, threads are still
a pain in the butt!
Friday, November 12, 2010
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
libdispatch
Friday, November 12, 2010
Let GCD figure out how
many threads to use!
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
require 'dispatch'...
Asynchronous API
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
require 'dispatch'
job = Dispatch::Job.new { ...
Elegant wrapper API
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
require 'dispatch'
job = Dispatch::Job.new...
Dispatch Enumerable
Parallel Iterations
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
require 'dispatch'
gee...
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
Remember: MacRuby
doesn’t have a global
VM lock!
Friday, Novem...
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
Serial queues:
lock free synchronization
Friday, November 12, ...
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
require 'dispatch'
job = Dispatch::Job.new
@scores = job.synch...
https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/
require 'dispatch'
job = Dispatch::Job.new
@scores = job.synch...
CONTROLTOWER
http://github.com/MacRuby/ControlTower
Friday, November 12, 2010
http://github.com/MacRuby/ControlTower
Web server for
Rack apps
Friday, November 12, 2010
NEW DISPATCHER
Friday, November 12, 2010
ONIGURUMA
TO ICU
Friday, November 12, 2010
MORE SOLID
FOUNDATIONS
Friday, November 12, 2010
SUPPORT FOR C
BLOCKS
Friday, November 12, 2010
SANDBOX
Friday, November 12, 2010
$ macirb --simple-prompt
>> require 'open-uri'
=> true
>> begin
>> Sandbox.no_internet.apply!
>> open('http://www.macruby....
•Sandbox.pure_computation
•Sandbox.no_internet
•Sandbox.no_network
•Sandbox.temporary_writes
•Sandbox.no_writes
5 default ...
APP STORE
Friday, November 12, 2010
Great exposure!
Friday, November 12, 2010
Better user
experience
Friday, November 12, 2010
Reinvent
desktop apps
Friday, November 12, 2010
/Developer/Examples/Ruby/MacRuby/
What can you do
with MacRuby?!
Friday, November 12, 2010
Speech
Recognizer
Friday, November 12, 2010
Friday, November 12, 2010
CoreLocation
Friday, November 12, 2010
Friday, November 12, 2010
Friday, November 12, 2010
Address
Book.app
Friday, November 12, 2010
Friday, November 12, 2010
String Tokenizer
Friday, November 12, 2010
framework 'Foundation'
class String
def language
CFStringTokenizerCopyBestStringLanguage(self,
CFRangeMake(0, self.size))
...
framework 'Foundation'
class String
def language
CFStringTokenizerCopyBestStringLanguage(self,
CFRangeMake(0, self.size))
...
Bonne année! (fr)
Happy new year! (en)
¡Feliz año nuevo! (es)
Felice anno nuovo! (it)
(ar) ‫ﺳﻌﻴﺪة‬ ‫أﻋﻴﺎد‬
明けましておめでとうございます...
BluetoothHardware
WebKit
JS Bridge
Friday, November 12, 2010
Friday, November 12, 2010
http://macruby.org
download & dble click
No conflict with your Rubies
Friday, November 12, 2010
@merbist
http://merbist.com
http://macruby.labs.oreilly.com
http://github.com/mattetti
Friday, November 12, 2010
Upcoming SlideShare
Loading in …5
×

Macruby - RubyConf Presentation 2010

6,533 views

Published on

Presentation of what's new with MacRuby since RubyConf 2009

Published in: Technology
0 Comments
18 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,533
On SlideShare
0
From Embeds
0
Number of Embeds
1,310
Actions
Shares
0
Downloads
174
Comments
0
Likes
18
Embeds 0
No embeds

No notes for slide

Macruby - RubyConf Presentation 2010

  1. 1. MACRUBYA p p l e ’ s R u b y M a t t A i m o n e t t i - R u b y C o n f X - N o v 2 0 1 0 Friday, November 12, 2010
  2. 2. ABOUT ME Friday, November 12, 2010
  3. 3. Friday, November 12, 2010
  4. 4. Hacker Friday, November 12, 2010
  5. 5. MacRuby Friday, November 12, 2010
  6. 6. http://macruby.labs.oreilly.com/ Friday, November 12, 2010
  7. 7. MACRUBYA p p l e ’ s R u b y Friday, November 12, 2010
  8. 8. MacRuby YARV Parser GC Runtime Stdlib Builtin classes Ruby 1.9 Friday, November 12, 2010
  9. 9. MacRuby LLVM/Roxor Parser Stdlib AOT JIT Obj-C Runtime libobjc libauto Builtin Classes CoreFoundation MacRuby Friday, November 12, 2010
  10. 10. MacRuby LLVM/Roxor Parser Stdlib AOT JIT Obj-C Runtime libobjc libauto Builtin Classes CoreFoundation YARV Parser GC Runtime Stdlib Builtin classes Ruby1.9 Friday, November 12, 2010
  11. 11. MacRuby LLVM Friday, November 12, 2010
  12. 12. JIT Compilation MacRuby Friday, November 12, 2010
  13. 13. JIT CompilationMacRuby Ruby AST LLVM IR Machine Code CPU Transforms the AST into LLVM intermediate representation ... optimizes it ... compiles it to machine code ... and executes it! Very good performance for algorithmic operations Friday, November 12, 2010
  14. 14. AOT Compilation MacRuby Friday, November 12, 2010
  15. 15. AOT CompilationMacRuby Ruby AST LLVM IR Machine Code Mach-O Object File CLI tool or Xcode ... applies more optimizations ... and saves the machine code to disk ... faster bootstrap time Can be used to obfuscate the source code Friday, November 12, 2010
  16. 16. NO GIL No Global Interpreter Lock Friday, November 12, 2010
  17. 17. GC Thread Thread VM VM VM Core Friday, November 12, 2010
  18. 18. MULTI-THREADED GENERATIONAL GC Friday, November 12, 2010
  19. 19. NATIVE ACCESS TO COCOA Friday, November 12, 2010
  20. 20. WHEN . TO USE MACRUBY? NOT Friday, November 12, 2010
  21. 21. YOU DON’T HAVE A MAC Friday, November 12, 2010
  22. 22. LINUX HOSTING Friday, November 12, 2010
  23. 23. YOU DON’T WANTTO LEARN Friday, November 12, 2010
  24. 24. WHAT’S NEW? Friday, November 12, 2010
  25. 25. COCOA DEV IS STABLE Friday, November 12, 2010
  26. 26. DNA Sequencing by Hampton Catlin Friday, November 12, 2010
  27. 27. AOT COMPILATION Friday, November 12, 2010
  28. 28. MacRuby: Definitive Guide Hello World Example Friday, November 12, 2010
  29. 29. framework 'AppKit' class AppDelegate def applicationDidFinishLaunching(notification) voice_type = "com.apple.speech.synthesis.voice.GoodNews" @voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type) end def windowWillClose(notification) puts "Bye!" exit end def say_hello(sender) @voice.startSpeakingString("Hello World!") puts "Hello World!" end end app = NSApplication.sharedApplication app.delegate = AppDelegate.new window = NSWindow.alloc.initWithContentRect([200, 300, 300, 100], styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask, backing:NSBackingStoreBuffered, defer:false) window.title = 'MacRuby: The Definitive Guide' window.level = 3 window.delegate = app.delegate button = NSButton.alloc.initWithFrame([80, 10, 120, 80]) button.bezelStyle = 4 button.title = 'Hello World!' button.target = app.delegate button.action = 'say_hello:' window.contentView.addSubview(button) window.display window.orderFrontRegardless app.run hello_world.rb Friday, November 12, 2010
  30. 30. $ macrubyc hello_world.rb -o demo $ file demo demo: Mach-O 64-bit executable x86_64 $ ./demo Compile to machine code Friday, November 12, 2010
  31. 31. w00t!! Friday, November 12, 2010
  32. 32. Create compiled/ dynamic libraries $ macrubyc file1.rb file2.rb -o shared.dylib --dylib $ macrubyc other_project_source.rb shared.dylib -o example $ ./example Friday, November 12, 2010
  33. 33. DEBUGGER Friday, November 12, 2010
  34. 34. characters = %w{Adama Apollo Baltar Roslin StarBuck Six} def cylon?(character) false # buggy detector end characters.each do |character| if cylon?(character) puts "#{character} is a Cylon!" else puts "#{character} is not a cylon." end end Friday, November 12, 2010
  35. 35. $ macruby cylon_detector.rb Adama is not a cylon. Apollo is not a cylon. Baltar is not a cylon. Roslin is not a cylon. StarBuck is not a cylon. Six is not a cylon. Buggy code :( Friday, November 12, 2010
  36. 36. $ macrubyd cylon_detector.rb Starting program. 1!characters = %w{Adama Apollo Baltar Roslin StarBuck Six} cylon_detector.rb:1> Debug the detector live Friday, November 12, 2010
  37. 37. cylon_detector.rb:1> b cylon_detector.rb:8 if character == 'Six' Added breakpoint 1. Added a breakpoint on a specific file/line based on a condition Friday, November 12, 2010
  38. 38. cylon_detector.rb:1> c Adama is not a cylon. Apollo is not a cylon. Baltar is not a cylon. Roslin is not a cylon. StarBuck is not a cylon. 8! if cylon?(character) cylon_detector.rb:8> Breaks on condition Friday, November 12, 2010
  39. 39. cylon_detector.rb:8> p character => "Six" cylon_detector.rb:8> p cylon?(character) => false Bug confirmed :( Friday, November 12, 2010
  40. 40. cylon_detector.rb:8> p def cylon?(character) character == 'Six' end ZOMG live bug fixing! Friday, November 12, 2010
  41. 41. cylon_detector.rb:8> c Six is a Cylon! Program exited. w00t!! Friday, November 12, 2010
  42. 42. GCD API https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ Friday, November 12, 2010
  43. 43. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ Threads can becomplicated to program:( Friday, November 12, 2010
  44. 44. Global Interpreter Lock VM Friday, November 12, 2010
  45. 45. Slow :( Friday, November 12, 2010
  46. 46. Full concurrency via multiple processes :( Friday, November 12, 2010
  47. 47. Safe data :) Friday, November 12, 2010
  48. 48. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ MacRuby doesn’t have a global VM lock Friday, November 12, 2010
  49. 49. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ MacRuby VM Core VM VM Friday, November 12, 2010
  50. 50. Good but not good enough, threads are still a pain in the butt! Friday, November 12, 2010
  51. 51. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ libdispatch Friday, November 12, 2010
  52. 52. Let GCD figure out how many threads to use! https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ require 'dispatch' job = Dispatch::Job.new { slow_operation } job.value # => “wait for the result” Friday, November 12, 2010
  53. 53. Asynchronous API https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ require 'dispatch' job = Dispatch::Job.new { slow_operation } job.value do |v| "asynchronous dispatch when done!" end Friday, November 12, 2010
  54. 54. Elegant wrapper API https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ require 'dispatch' job = Dispatch::Job.new job.add { slow_operation(a) } job.add { slow_operation(b) } job.add { slow_operation(c) } job.join job.values # =>[result_a, result_b, result_c] Friday, November 12, 2010
  55. 55. Dispatch Enumerable Parallel Iterations https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ require 'dispatch' geeks.p_each do |user| print find_pair(user) end Friday, November 12, 2010
  56. 56. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ Remember: MacRuby doesn’t have a global VM lock! Friday, November 12, 2010
  57. 57. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ Serial queues: lock free synchronization Friday, November 12, 2010
  58. 58. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ require 'dispatch' job = Dispatch::Job.new @scores = job.synchronize Hash.new [user1, user2, user3].each do |user| job.add { @scores[user.name] = calculate(user) } end job.join @scores[user1.name] # => 1042 @scores[user2.name] # => 673 @scores[user3.name] # => 845 Friday, November 12, 2010
  59. 59. https://github.com/MacRuby/MacRuby/tree/trunk/lib/dispatch/ require 'dispatch' job = Dispatch::Job.new @scores = job.synchronize Hash.new [user1, user2, user3].each do |user| job.add { @scores[user.name] = calculate(user) } end job.join @scores[user1.name] # => 1042 @scores[user2.name] # => 673 @scores[user3.name] # => 845 safe proxy object Friday, November 12, 2010
  60. 60. CONTROLTOWER http://github.com/MacRuby/ControlTower Friday, November 12, 2010
  61. 61. http://github.com/MacRuby/ControlTower Web server for Rack apps Friday, November 12, 2010
  62. 62. NEW DISPATCHER Friday, November 12, 2010
  63. 63. ONIGURUMA TO ICU Friday, November 12, 2010
  64. 64. MORE SOLID FOUNDATIONS Friday, November 12, 2010
  65. 65. SUPPORT FOR C BLOCKS Friday, November 12, 2010
  66. 66. SANDBOX Friday, November 12, 2010
  67. 67. $ macirb --simple-prompt >> require 'open-uri' => true >> begin >> Sandbox.no_internet.apply! >> open('http://www.macruby.org') >> rescue SystemCallError => exception >> puts exception >> end Operation not permitted - connect(2) => nil Friday, November 12, 2010
  68. 68. •Sandbox.pure_computation •Sandbox.no_internet •Sandbox.no_network •Sandbox.temporary_writes •Sandbox.no_writes 5 default profiles Friday, November 12, 2010
  69. 69. APP STORE Friday, November 12, 2010
  70. 70. Great exposure! Friday, November 12, 2010
  71. 71. Better user experience Friday, November 12, 2010
  72. 72. Reinvent desktop apps Friday, November 12, 2010
  73. 73. /Developer/Examples/Ruby/MacRuby/ What can you do with MacRuby?! Friday, November 12, 2010
  74. 74. Speech Recognizer Friday, November 12, 2010
  75. 75. Friday, November 12, 2010
  76. 76. CoreLocation Friday, November 12, 2010
  77. 77. Friday, November 12, 2010
  78. 78. Friday, November 12, 2010
  79. 79. Address Book.app Friday, November 12, 2010
  80. 80. Friday, November 12, 2010
  81. 81. String Tokenizer Friday, November 12, 2010
  82. 82. framework 'Foundation' class String def language CFStringTokenizerCopyBestStringLanguage(self, CFRangeMake(0, self.size)) end end Call a C function directly Friday, November 12, 2010
  83. 83. framework 'Foundation' class String def language CFStringTokenizerCopyBestStringLanguage(self, CFRangeMake(0, self.size)) end end ["Bonne année!", "Happy new year!", "¡Feliz año nuevo!", "Felice anno nuovo!", "‫ﺳﻌﻴﺪة‬ ‫,"أﻋﻴﺎد‬ "明けましておめでとうございます。"].each do |msg| puts "#{msg} (#{msg.language})" end Friday, November 12, 2010
  84. 84. Bonne année! (fr) Happy new year! (en) ¡Feliz año nuevo! (es) Felice anno nuovo! (it) (ar) ‫ﺳﻌﻴﺪة‬ ‫أﻋﻴﺎد‬ 明けましておめでとうございます。 (ja) Friday, November 12, 2010
  85. 85. BluetoothHardware WebKit JS Bridge Friday, November 12, 2010
  86. 86. Friday, November 12, 2010
  87. 87. http://macruby.org download & dble click No conflict with your Rubies Friday, November 12, 2010
  88. 88. @merbist http://merbist.com http://macruby.labs.oreilly.com http://github.com/mattetti Friday, November 12, 2010

×