22. Episode VI - The Return
of The RubyMotion
Monday, October 14, 2013
23. What is RubyMotion?
• Use Ruby to build apps for iOS and OS X
• Native apps
• Interface directly with Obj-C libraries
• CLI-based build system
Monday, October 14, 2013
24. What is RubyMotion?
• RubyMotion: http://www.rubymotion.com/
• MotionCasts: http://motioncasts.tv/
• RubyMotion Wrappers:
!
http://rubymotion-wrappers.com/
• ...and lot’s more
Monday, October 14, 2013
25. What is MacRuby?
• Intended to be the implementation of Ruby
2.0 for OS X
• Target RubySpec compliance
• JIT or AOT Compiled
• Uses libauto for Garbage Collection
Monday, October 14, 2013
26. What is MacRuby?
Ruby Syntax
Parser
Compiler
VM (sans GVL)
LLVM (with JIT)
Objective-C Runtime
Monday, October 14, 2013
27. Running a “something.rb” file
Ruby Syntax
Parser
Compiler
VM (sans GVL)
LLVM (with JIT)
Objective-C Runtime
Monday, October 14, 2013
28. Running a “something.rb” file
Ruby Syntax
Parser
Compiler
VM (sans GVL)
LLVM (with JIT)
Objective-C Runtime
Monday, October 14, 2013
29. Running a “something.rb” file
Ruby Syntax
Parser
Compiler
VM (sans GVL)
LLVM (with JIT)
Objective-C Runtime
Monday, October 14, 2013
30. AOT compiling “something.rb”
Ruby Syntax
Parser
Compiler
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
LLVM
something.o
31. AOT compiling “something.rb”
Ruby Syntax
Parser
Compiler
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
LLVM
something.o
32. Running an AOT compiled
“something.rb”
Parser
Compiler
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
something.o
33. Running an AOT compiled
“something.rb”
Parser
Compiler
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
something.o
34. Running an AOT compiled
“something.rb”
Parser
Compiler
LLVM
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
something.o
35. Running an AOT compiled
“something.rb”
Parser
Compiler
LLVM
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
something.o
36. Running an AOT compiled
“something.rb”
Parser
Compiler
LLVM
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
something.o
37. What is RubyMotion?
• Descendent of MacRuby
• “Ruby, the Good Parts”
• Static Compiled
• Retain/release reference counting
Monday, October 14, 2013
40. Running a static compiled
“something.rb”
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
something.o
41. Running a static compiled
“something.rb”
VM (sans GVL)
Objective-C Runtime
Monday, October 14, 2013
something.o
42. Why must we statically
compile?
• On OS X
• Compile writes code to a memory
page
• Runtime runs the code from that
memory page
Monday, October 14, 2013
43. Why must we statically
compile?
•
On iOS
Memory pages must be writable or
executable, NOT BOTH!
•
•
•
Monday, October 14, 2013
•
OS prohibits runtime compilation
Apple prohibits interpreting arbitrary scripts
...but you wouldn’t want an interpreter
anyway
47. ARC vs “ARC”
• Objective-C’s ARC modifies your code
before compilation
• RubyMotion VM knows when retain and/or
release should be called...your code is not
touched
Monday, October 14, 2013
48. ARC vs “ARC”
Isn’t the distinction
rather academic?
Probably...
Monday, October 14, 2013
49. “ARC” Caveats
• Collection happens when the autorelease
pool drains
• Need to be careful with tight loops that
generate many objects
• Use “autorelease do...end”
• Detects almost all cycles
• Use WeakRefs if cycles become
problematic
Monday, October 14, 2013
50. Debugging RubyMotion
• Remember, RubyMotion objects are
Objective-C objects...
• All the usual tricks are valid!
Monday, October 14, 2013