RubyMotion: Under the Hood
-
Upload
joshua-ballanco -
Category
Technology
-
view
995 -
download
3
description
Transcript of RubyMotion: Under the Hood
RubyMotion:Under the Hood
Inspired by Click and Clack
Monday, October 14, 2013
A brief introduction
Monday, October 14, 2013
Name:
About Me
Joshua BallancoMonday, October 14, 2013
Employer: Burnside Digital
About Me
Monday, October 14, 2013
Ankara, Turkey
About Me
Location:Monday, October 14, 2013
A slightly longer introduction
Monday, October 14, 2013
Before...
Monday, October 14, 2013
Employer: Patch
About Me
Monday, October 14, 2013
New York City
About Me
Location:Monday, October 14, 2013
Before that...
Monday, October 14, 2013
Employer: Apple
About Me
Monday, October 14, 2013
Cupertino
About Me
Location:Monday, October 14, 2013
Before that...
Monday, October 14, 2013
School: University of Miami
About Me
Monday, October 14, 2013
Miami
About Me
Location:Monday, October 14, 2013
A bit of history
Monday, October 14, 2013
In graduate school
Monday, October 14, 2013
In graduate school
Monday, October 14, 2013
At Apple... Retail
Monday, October 14, 2013
At Apple
Laurent Sansonetti
Monday, October 14, 2013
After Apple...
Monday, October 14, 2013
Episode VI - The Return of The RubyMotion
Monday, October 14, 2013
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
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
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
What is MacRuby?Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM (with JIT)
Objective-C Runtime
Monday, October 14, 2013
Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM (with JIT)
Objective-C Runtime
Running a “something.rb” file
Monday, October 14, 2013
Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM (with JIT)
Objective-C Runtime
Running a “something.rb” file
Monday, October 14, 2013
Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM (with JIT)
Objective-C Runtime
Running a “something.rb” file
Monday, October 14, 2013
Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM
Objective-C Runtime
AOT compiling “something.rb”
something.o
Monday, October 14, 2013
Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM
Objective-C Runtime
AOT compiling “something.rb”
something.o
Monday, October 14, 2013
Parser
Compiler
something.oVM (sans GVL)
Objective-C Runtime
Running an AOT compiled “something.rb”
Monday, October 14, 2013
Parser
Compiler
something.oVM (sans GVL)
Objective-C Runtime
Running an AOT compiled “something.rb”
Monday, October 14, 2013
Parser
Compiler
LLVM
something.oVM (sans GVL)
Objective-C Runtime
Running an AOT compiled “something.rb”
Monday, October 14, 2013
Parser
Compiler
LLVM
something.oVM (sans GVL)
Objective-C Runtime
Running an AOT compiled “something.rb”
Monday, October 14, 2013
Parser
Compiler
LLVM
something.oVM (sans GVL)
Objective-C Runtime
Running an AOT compiled “something.rb”
Monday, October 14, 2013
What is RubyMotion?
• Descendent of MacRuby
• “Ruby, the Good Parts”
• Static Compiled
• Retain/release reference counting
Monday, October 14, 2013
Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM
Objective-C Runtime
Static compiling “something.rb”
something.o
Monday, October 14, 2013
Ruby Syntax
Parser
Compiler
VM (sans GVL) LLVM
Objective-C Runtime
Static compiling “something.rb”
something.o
Monday, October 14, 2013
VM (sans GVL)
Objective-C Runtime
Running a static compiled “something.rb”
something.o
Monday, October 14, 2013
VM (sans GVL)
Objective-C Runtime
Running a static compiled “something.rb”
something.o
Monday, October 14, 2013
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
Why must we statically compile?
• On iOS
• Memory pages must be writable or executable, NOT BOTH!
• OS prohibits runtime compilation
• Apple prohibits interpreting arbitrary scripts
• ...but you wouldn’t want an interpreter anyway
Monday, October 14, 2013
Garbage Collection
Monday, October 14, 2013
What happened to the Garbage Collector?
It required extra threads, so we had to kill it...
Monday, October 14, 2013
So RubyMotion Uses ARC?
Yes...
Uh...no
...sorta?
Monday, October 14, 2013
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
ARC vs “ARC”
Isn’t the distinction rather academic?
Probably...
Monday, October 14, 2013
“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
Debugging RubyMotion
• Remember, RubyMotion objects are Objective-C objects...
• All the usual tricks are valid!
Monday, October 14, 2013
Let’s Play!
Monday, October 14, 2013
The Victimapp/app_delegate.rb
Monday, October 14, 2013
The Victimapp/app_delegate.rb
Monday, October 14, 2013
REPL Magic
Monday, October 14, 2013
REPL Magic
Monday, October 14, 2013
REPL Magic
Monday, October 14, 2013
REPL Magic
Monday, October 14, 2013
That’s cool...but can you do it in a debugger???
Monday, October 14, 2013
Debugger Wizardry
Monday, October 14, 2013
Debugger Wizardry
Monday, October 14, 2013
Debugger Wizardry
Monday, October 14, 2013
Debugger Wizardry
Monday, October 14, 2013
That’s CRAZY!
I know...but it’s fun!
Monday, October 14, 2013
Debugging RubyMotion
• Helper methods “pro” and “pri”
• http://www.rubymotion.com/developer-center/articles/debugging/
• Watch for more/better tooling to come...
Monday, October 14, 2013
Questions?
@manhattanmetric
Joshua Ballanco
https://github.com/jballanc
Monday, October 14, 2013