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
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
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. $ 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. $ 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
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
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
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. 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. Bonne année! (fr)
Happy new year! (en)
¡Feliz año nuevo! (es)
Felice anno nuovo! (it)
(ar) ﺳﻌﻴﺪة أﻋﻴﺎد
明けましておめでとうございます。 (ja)
Friday, November 12, 2010