Upload
-
View
2.450
Download
0
Embed Size (px)
DESCRIPTION
MacRuby is an implementation of Ruby 1.9 that is directly on top of Mac OS X core technologies. Recently, MacRuby has become viable as a tool for developing useful desktop applications for Mac OS X. However, as of March 2011, MacRuby is still missing some functionality that is present in cRuby. Therefore, MacRuby is not able to run Ruby on Rails. In my presentation, I will explain how I modified MacRuby to make it a suitable foundation for running Rails. I would also like to explain some of technical intricacies that I discovered along the way. (Japanese) 2011年3月時点でのMacRubyはRuby処理系としての完成度は低く、Ruby on Railsが到底動作するようには思えない。しかしながら、MacRubyに対して改良 に改良を重ねることできっとRailsを動作させることができる(はずである)。 本発表ではMacRubyでRailsを動作させるために必要だった修正内容とともに、 その過程であらためて知ることになったcRubyのすばらしさを説明します。
Citation preview
MacRuby on Rails~MacRubyから見たcRuby~
概要
2011年3月時点でのMacRubyはRuby処理系としての完成度は低く、Ruby on Railsが到底動作するようには思えない。しかしながら、MacRubyに対して改良 に改良を重ねることできっとRailsを動作させることができる(はずである)。 本発表ではMacRubyでRailsを動作させるために必要だった修正内容とともに、 その過程であらためて知ることになったcRubyのすばらしさを説明します。
Abstract
MacRuby is an implementation of Ruby 1.9 that is directly on top of Mac OS X core technologies. Recently, MacRuby has become viable as a tool for developing useful desktop applications for Mac OS X. However, as of March 2011, MacRuby is still missing some functionality that is present in cRuby. Therefore, MacRuby is not able to run Ruby on Rails. In my presentation, I will explain how I modified MacRuby to make it a suitable foundation for running Rails. I would also like to explain some of technical intricacies that I discovered along the way.
Ruby会議2011 - 2011年7月17日ネットワーク応用通信研究所高尾宏治<kou j i@ne t l ab . jp>
12011年7月19日火曜日
高尾宏治• 株式会社ネットワーク応用通信研究所
• cRubyのコミッタ(Readlineモジュール)
• MacRubyのコミッタ
• @takaokouji(@takaokouji_en)
• http://facebook.com/takaokouji
22011年7月19日火曜日
提供
32011年7月19日火曜日
提供• ネットワーク応用通信研究所
32011年7月19日火曜日
提供• ネットワーク応用通信研究所
Network Applied Communicaiton Laboratory Co,.Ltd.
32011年7月19日火曜日
提供• ネットワーク応用通信研究所
Network Applied Communicaiton Laboratory Co,.Ltd.
• 自分を幸せにしてください。
32011年7月19日火曜日
提供• ネットワーク応用通信研究所
Network Applied Communicaiton Laboratory Co,.Ltd.
• 自分を幸せにしてください。家族を幸せにしてください。
32011年7月19日火曜日
提供
会社
家族
自分
• ネットワーク応用通信研究所Network Applied Communicaiton Laboratory Co,.Ltd.
• 自分を幸せにしてください。家族を幸せにしてください。
余った分で会社を幸せにしてください。
32011年7月19日火曜日
MacRuby on Rails~MacRubyから見たcRuby~
Ruby会議2011 - 2011年7月17日ネットワーク応用通信研究所高尾宏治<kou j i@ne t l ab . jp>
42011年7月19日火曜日
MacRuby on Rails~MacRubyから見たcRuby~
MacRuby非公式イメージキャラクターR u b y 忍 者 @ l r z
Ruby会議2011 - 2011年7月17日ネットワーク応用通信研究所高尾宏治<kou j i@ne t l ab . jp>
42011年7月19日火曜日
MacRubyMac OS Xに特化したRuby
52011年7月19日火曜日
MacRuby
62011年7月19日火曜日
MacRubyMacRuby is a unique blend of Ruby 1.9 and Objective-C.
➡ Ruby 1.9とObjective-Cを融合させたもの
62011年7月19日火曜日
MacRubyMacRuby is a unique blend of Ruby 1.9 and Objective-C.
➡ Ruby 1.9とObjective-Cを融合させたもの
The goal of the MacRuby project is to be 100% compatible syntactically and behaviorally with Ruby 1.9.
➡ Ruby 1.9との100%互換を目指す
62011年7月19日火曜日
Ruby 1.9
OS(Linux,Windows,Mac OS X,etc...)
ライブラリ
Ruby 1.9
アプリケーション
組み込みGC
Ruby VM
組み込みライブラリ
添付ライブラリ
72011年7月19日火曜日
MacRuby
Mac OS X
ライブラリ
MacRuby
アプリケーション
組み込みGC
Ruby VM
組み込みライブラリ
添付ライブラリ
82011年7月19日火曜日
MacRuby
Mac OS X
ライブラリ
MacRuby
アプリケーション
組み込みGC
Ruby VM
組み込みライブラリ
添付ライブラリ
82011年7月19日火曜日
MacRuby
Mac OS X
ライブラリ
MacRuby
アプリケーション
組み込みGC
Ruby VM
組み込みライブラリ
添付ライブラリ
AutoZone
82011年7月19日火曜日
MacRuby
Mac OS X
ライブラリ
MacRuby
アプリケーション
組み込みGC
Ruby VM
組み込みライブラリ
添付ライブラリ
AutoZone
Foundation
82011年7月19日火曜日
MacRuby
Mac OS X
ライブラリ
MacRuby
アプリケーション
世代別・スレッドGC
LLVM
組み込みライブラリ
添付ライブラリ
AutoZone
Foundation
92011年7月19日火曜日
MacRuby×Cocoa
framework “cocoa”
def playSound(name) sound = NSSound.soundNamed(name) sound.playend
102011年7月19日火曜日
HelloMacRuby
112011年7月19日火曜日
HelloMacRuby
(1)クリック
112011年7月19日火曜日
HelloMacRuby
(1)クリック
(2)Hello,MacRuby!
Hello,MacRuby!
112011年7月19日火曜日
class AppController attr_accessor :textField def hello(sender) @textField.stringValue = "Hello,MacRuby!" endend
HelloMacRuby
ビュー
Rubyスクリプト:コントローラ
122011年7月19日火曜日
class AppController attr_accessor :textField def hello(sender) @textField.stringValue = "Hello,MacRuby!" endend
HelloMacRuby
ビュー
Rubyスクリプト:コントローラ
122011年7月19日火曜日
class AppController attr_accessor :textField def hello(sender) @textField.stringValue = "Hello,MacRuby!" endend
HelloMacRuby
ビュー
Rubyスクリプト:コントローラ
122011年7月19日火曜日
MacRuby on RailsMacRubyでRuby on Railsを動作させる
132011年7月19日火曜日
MacRuby on Rails
142011年7月19日火曜日
MacRuby on Rails$ rails new demo
142011年7月19日火曜日
MacRuby on Rails$ rails new demo
$ rails generate scaffold ...
142011年7月19日火曜日
MacRuby on Rails
$ rails server
$ rails new demo
$ rails generate scaffold ...
142011年7月19日火曜日
MacRuby on Rails
$ rails server
$ rails new demo
$ rails generate scaffold ...
142011年7月19日火曜日
4ヶ月前...
152011年7月19日火曜日
2011年3月中旬
4ヶ月前...
152011年7月19日火曜日
2011年3月中旬
• MacRubyでRailsは動くの?
4ヶ月前...
152011年7月19日火曜日
2011年3月中旬
• MacRubyでRailsは動くの?
• Railsのインストールはできる
4ヶ月前...
$ sudo macgem install --verbose rails --no-ri --no-rdoc7 gems installed
$ sudo macgem install --verbose sqlite3-ruby --no-ri --no-rdoc2 gems installed
152011年7月19日火曜日
もしかして...
162011年7月19日火曜日
• すでにRailsって動作する!?
もしかして...
162011年7月19日火曜日
• すでにRailsって動作する!?
• プロジェクトが作成できた!
もしかして...
$ macruby -S rails new demo create create README create Rakefile ... create vendor/plugins create vendor/plugins/.gitkeep
162011年7月19日火曜日
まさか!?
172011年7月19日火曜日
• scaffoldは...
まさか!?
172011年7月19日火曜日
• scaffoldは...
• abort!?やっぱりだめじゃん
まさか!?
$ macruby -S rails generate scaffold Bookmark title:string description:text url:string...Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3434.zsh: abort macruby -S rails generate scaffold Bookmark title:string description:text
172011年7月19日火曜日
• scaffoldは...
• abort!?やっぱりだめじゃん
まさか!?
$ macruby -S rails generate scaffold Bookmark title:string description:text url:string...Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3434.zsh: abort macruby -S rails generate scaffold Bookmark title:string description:text
$ macruby -S rails server...Assertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3434.zsh: abort macruby -S rails server
172011年7月19日火曜日
Railsの実行
RubySpec
コーディング
原因調査
イテレーション
SEGV・abort
Railsの実行
182011年7月19日火曜日
Railsの実行
RubySpec
コーディング
原因調査
イテレーション
SEGV・abort
Railsの実行必要な知識や技術
• cRuby
• Objective-C
• C++
• LLVM
182011年7月19日火曜日
#860 catch/throwAssertion fails in pop_current_exception when catch/throw used in rescue
➡ rescue節の中でcatchとthrowを行うとabortしてしまう
192011年7月19日火曜日
#860 catch/throwAssertion fails in pop_current_exception when catch/throw used in rescue
➡ rescue節の中でcatchとthrowを行うとabortしてしまう
begin raiserescue catch(:ambiguous) { throw :ambiguous } p :okend
192011年7月19日火曜日
#860 catch/throwAssertion fails in pop_current_exception when catch/throw used in rescue
➡ rescue節の中でcatchとthrowを行うとabortしてしまう
begin raiserescue catch(:ambiguous) { throw :ambiguous } p :okend
:okAssertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3448.
192011年7月19日火曜日
#860 catch/throwAssertion fails in pop_current_exception when catch/throw used in rescue
➡ rescue節の中でcatchとthrowを行うとabortしてしまう
begin raiserescue catch(:ambiguous) { throw :ambiguous } p :okend
throwで例外をスタックから取り除いてしまっていた
:okAssertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3448.
192011年7月19日火曜日
#860 catch/throwAssertion fails in pop_current_exception when catch/throw used in rescue
➡ rescue節の中でcatchとthrowを行うとabortしてしまう
begin raiserescue catch(:ambiguous) { throw :ambiguous } p :okend
throwで例外をスタックから取り除いてしまっていた
:okAssertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3448.
ここでも例外をスタックから取り除こうとしてabort
192011年7月19日火曜日
#860 catch/throw修正前(60723bf~)だとthrow時に例外があれば必ずスタックから取り除いてしまう
202011年7月19日火曜日
#860 catch/throw修正前(60723bf~)だとthrow時に例外があれば必ずスタックから取り除いてしまうcatch(:ambiguous) { begin raise rescue throw :ambiguou end}
202011年7月19日火曜日
#860 catch/throw修正前(60723bf~)だとthrow時に例外があれば必ずスタックから取り除いてしまうcatch(:ambiguous) { begin raise rescue throw :ambiguou end} ここには到達しないためendで例
外を取り除くだけではダメ
202011年7月19日火曜日
#860 catch/throw修正前(60723bf~)だとthrow時に例外があれば必ずスタックから取り除いてしまうcatch(:ambiguous) { begin raise rescue throw :ambiguou end}
throwで例外をスタックから取り除かないといけない
ここには到達しないためendで例外を取り除くだけではダメ
202011年7月19日火曜日
#860 catch/throw修正前(60723bf~)だとthrow時に例外があれば必ずスタックから取り除いてしまうcatch(:ambiguous) { begin raise rescue throw :ambiguou end}
throwで例外をスタックから取り除かないといけない
ここには到達しないためendで例外を取り除くだけではダメ
vm.cpp:4321:VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... // We must pop the current VM exception in case we are in a rescue handler, // since we are going to unwind the stack. if (current_exception() != Qnil) { pop_current_exception(); }...
202011年7月19日火曜日
#860 catch/throw➡必要なときだけ例外を取り除くように修正(60723bf)
212011年7月19日火曜日
vm.cpp:4318:VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... rb_vm_catch_t *catch_ptr = iter->second; while (catch_ptr->current_exception != current_exception()) { pop_current_exception(); }...
#860 catch/throw➡必要なときだけ例外を取り除くように修正(60723bf)
212011年7月19日火曜日
vm.cpp:4318:VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... rb_vm_catch_t *catch_ptr = iter->second; while (catch_ptr->current_exception != current_exception()) { pop_current_exception(); }...
#860 catch/throw➡必要なときだけ例外を取り除くように修正(60723bf)
catchを処理したときの例外(catch_ptr->current_exception)
と現在の例外(current_exception())が等しくなければ例外をスタックから取り除く
212011年7月19日火曜日
begin raiserescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :okend
#860 catch/throw
222011年7月19日火曜日
begin raiserescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :okend
#860 catch/throw例外Aが発生
222011年7月19日火曜日
begin raiserescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :okend
#860 catch/throw例外Aが発生 例外Aを記録
catch_ptr->current_exception = current_exception();
222011年7月19日火曜日
begin raiserescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :okend
#860 catch/throw例外Aが発生 例外Aを記録
catch_ptr->current_exception = current_exception();
例外Bが発生
222011年7月19日火曜日
begin raiserescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :okend
#860 catch/throw例外Aが発生 例外Aを記録
catch_ptr->current_exception = current_exception();
例外Bが発生
例外Cが発生
222011年7月19日火曜日
begin raiserescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :okend
#860 catch/throw
例外C、B、Aの順に記録しておいた例外A
と比較して、例外CとBをスタックから取り除く
例外Aが発生 例外Aを記録catch_ptr->current_exception = current_exception();
例外Bが発生
例外Cが発生
222011年7月19日火曜日
begin raiserescue catch(:ambiguous) { begin raise rescue begin raise rescue throw :ambiguous end end } p :okend
#860 catch/throw
例外C、B、Aの順に記録しておいた例外A
と比較して、例外CとBをスタックから取り除く
例外Aが発生 例外Aを記録catch_ptr->current_exception = current_exception();
例外Bが発生
例外Cが発生
例外Aをスタックから取り除く
222011年7月19日火曜日
#1192 定数探索Did not find nested constants.
➡ネストした定数の探索に失敗する
232011年7月19日火曜日
#1192 定数探索Did not find nested constants.
➡ネストした定数の探索に失敗する
module A B = 10 Object.class_eval { B }end
232011年7月19日火曜日
#1192 定数探索Did not find nested constants.
➡ネストした定数の探索に失敗する
module A B = 10 Object.class_eval { B }end
reduction.rb:3:in `block': uninitialized constant B (NameError) from reduction.rb:1:in `<main>'
232011年7月19日火曜日
#1192 定数探索Did not find nested constants.
➡ネストした定数の探索に失敗する
module A B = 10 Object.class_eval { B }end
Objectから定数Bを探索しているため失敗する
reduction.rb:3:in `block': uninitialized constant B (NameError) from reduction.rb:1:in `<main>'
232011年7月19日火曜日
#1192 定数探索修正前(6b101bd~)だとレキシカルな定数探索が実装されていなかった。
242011年7月19日火曜日
#1192 定数探索修正前(6b101bd~)だとレキシカルな定数探索が実装されていなかった。module A module B CONST = “B’s Const” module ::A p CONST end endend
242011年7月19日火曜日
#1192 定数探索修正前(6b101bd~)だとレキシカルな定数探索が実装されていなかった。module A module B CONST = “B’s Const” module ::A p CONST end endend
-e:5:in `block': uninitialized constant A::CONST (NameError)
242011年7月19日火曜日
#1192 定数探索修正前(6b101bd~)だとレキシカルな定数探索が実装されていなかった。module A module B CONST = “B’s Const” module ::A p CONST end endend
::A、A::B、Aの順に定数を探索する必要があるが、::Aしか探索していない。
-e:5:in `block': uninitialized constant A::CONST (NameError)
242011年7月19日火曜日
定数探索むずい
module A CONST = "A's CONST" def f class_eval <<-EOS p CONST EOS endend
class K CONST = "K's CONST" extend A fend
module A CONST = "A's CONST" def f class_eval { p CONST } endend
class K CONST = "K's CONST" extend A fend
module_eval(文字列) module_eval ブロック
252011年7月19日火曜日
定数探索むずい
module A CONST = "A's CONST" def f class_eval <<-EOS p CONST EOS endend
class K CONST = "K's CONST" extend A fend
module A CONST = "A's CONST" def f class_eval { p CONST } endend
class K CONST = "K's CONST" extend A fend
module_eval(文字列) module_eval ブロック
#=> "K's CONST"
252011年7月19日火曜日
定数探索むずい
module A CONST = "A's CONST" def f class_eval <<-EOS p CONST EOS endend
class K CONST = "K's CONST" extend A fend
module A CONST = "A's CONST" def f class_eval { p CONST } endend
class K CONST = "K's CONST" extend A fend
module_eval(文字列) module_eval ブロック
#=> "K's CONST" #=> "A's CONST"
252011年7月19日火曜日
定数探索むずい
module A CONST = "A's CONST" def f class_eval <<-EOS p CONST EOS endend
class K CONST = "K's CONST" extend A fend
module A CONST = "A's CONST" def f class_eval { p CONST } endend
class K CONST = "K's CONST" extend A fend
K、A、Objectの順に定数CONSTを探索する。
module_eval(文字列) module_eval ブロック
#=> "K's CONST" #=> "A's CONST"
252011年7月19日火曜日
定数探索むずい
module A CONST = "A's CONST" def f class_eval <<-EOS p CONST EOS endend
class K CONST = "K's CONST" extend A fend
module A CONST = "A's CONST" def f class_eval { p CONST } endend
class K CONST = "K's CONST" extend A fend
K、A、Objectの順に定数CONSTを探索する。
A、Objectの順に定数CONSTを探索する。Kからは探索しない。
module_eval(文字列) module_eval ブロック
#=> "K's CONST" #=> "A's CONST"
252011年7月19日火曜日
困難かなり実装が難しい振る舞いを発見
262011年7月19日火曜日
困難かなり実装が難しい振る舞いを発見module A B = 42end
A.class_eval do def self.f p B endend
A.f
262011年7月19日火曜日
困難かなり実装が難しい振る舞いを発見module A B = 42end
A.class_eval do def self.f p B endend
A.f
Ruby 1.942
262011年7月19日火曜日
困難かなり実装が難しい振る舞いを発見module A B = 42end
A.class_eval do def self.f p B endend
A.f
Ruby 1.942
Ruby 1.8.7-e:8:in `f': uninitialized constant B (NameError)
262011年7月19日火曜日
困難かなり実装が難しい振る舞いを発見module A B = 42end
A.class_eval do def self.f p B endend
A.f
Ruby 1.942
Ruby 1.8.7-e:8:in `f': uninitialized constant B (NameError)cRubyのバ
グ
262011年7月19日火曜日
#?abort when I pressed “About your application’s environment” in welcome page.
➡ Welcome aboardのページにあるリンクをクリックするとabortする
272011年7月19日火曜日
#?abort when I pressed “About your application’s environment” in welcome page.
➡ Welcome aboardのページにあるリンクをクリックするとabortする
272011年7月19日火曜日
#?abort when I pressed “About your application’s environment” in welcome page.
➡ Welcome aboardのページにあるリンクをクリックするとabortする
ここをクリックするだけ
272011年7月19日火曜日
#?abort when I pressed “About your application’s environment” in welcome page.
➡ Welcome aboardのページにあるリンクをクリックするとabortする
ここをクリックするだけ
Assertion failed: ((b->flags & flags) == flags), function rb_vm_prepare_block, file dispatcher.cpp, line 1406.zsh: abort env VM_DISABLE_RBO=1 macruby -S rails server
272011年7月19日火曜日
それって...
282011年7月19日火曜日
それって...MacRubyでRailsが動いていないのでは...
282011年7月19日火曜日
それって...MacRubyでRailsが動いていないのでは...
➡すみません。実はまだ動いていませんでした。
282011年7月19日火曜日
それって...MacRubyでRailsが動いていないのでは...
➡すみません。実はまだ動いていませんでした。
➡ @lrz「Railsが動作すればMacRuby 1.0をリリースする」
282011年7月19日火曜日