Upgrade to Pro — share decks privately, control downloads, hide ads and more …

最速で最速のRuby擴張を作る

 最速で最速のRuby擴張を作る

さっちゃん

March 23, 2017
Tweet

More Decks by さっちゃん

Other Decks in Programming

Transcript

  1. ne-sachirou/sample_ruby_extension_in_crystal ruby Fib, module Fib def self.fib_cr(n : Int32) :

    Int32 (1..n-1).reduce([1,1]){|ns|[ns[1],ns[0]+ns[1]]}[1] end end p Fib.fib_cr
  2. ne-sachirou/sample_ruby_extension_in_crystal macro ruby(name, code) {{ code }} {% if code.class_name

    == "Def" %} Ruby.ruby_def {{ name }}, {{ code }} {% elsif code.class_name == "ModuleDef" %} Ruby.ruby_module_def {{ name }}, {{ code }} {% end %} end LLVMで速いbinaryを作る ⾃動でRubyにmodule/methodを登録する `rake compile`