macruby on rails

204
MacRuby on Rails Abstract MacRuby is an implementation of Ruby 1.9 that is built 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 the technical intricacies that I discovered along the way. RubyConf2011 - 2011/09/30 Network Applied Communication Laboratory Ltd. Kouji Takao< [email protected] > @takaokouji_en/[email protected] Illustrator: Yuki Morohoshi< [email protected] > This presentation was made possible by

Upload: -

Post on 15-May-2015

3.993 views

Category:

Technology


0 download

DESCRIPTION

This is my presentation in RubyConf 2011, 30th Octobar 2011,New Orleans in the U.S.Abstract:MacRuby is an implementation of Ruby 1.9 that is built 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 the technical intricacies that I discovered along the way.RubyConf 2011:http://rubyconf.org/

TRANSCRIPT

Page 1: MacRuby on Rails

MacRuby on RailsAbstractMacRuby is an implementation of Ruby 1.9 that is built 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 the technical intricacies that I discovered along the way.

R u b y C o n f 2 0 1 1 - 2 0 1 1 / 0 9 / 3 0Network Applied Communication Laboratory Ltd.K o u j i T a k a o < k o u j i @ n e t l a b . j p >@takaokouji_en/[email protected]: Yuki Morohoshi<[email protected]>

This presentation was made possible by

Page 2: MacRuby on Rails

Kouji Takao宏治 高尾

Page 3: MacRuby on Rails

Work

• Network Applied Communication Laboratory Ltd.

• System design, programming, planning and meeting

Page 4: MacRuby on Rails

Spare Time

• MacRuby committer

➡Core

• cRuby committer

➡Readline module

Page 5: MacRuby on Rails

ContactInformation

[email protected]

• @takaokouji_en

• http://facebook.com/takaokouji (mainly in Japanese)

Page 6: MacRuby on Rails

My Company

Page 7: MacRuby on Rails

• Network Applied Communication Laboratory Ltd.

My Company

Page 8: MacRuby on Rails

• Network Applied Communication Laboratory Ltd.

• a.k.a NaCl

My Company

Page 9: MacRuby on Rails

• Network Applied Communication Laboratory Ltd.

• a.k.a NaCl➡ means salt

My Company

Page 10: MacRuby on Rails

My Company

Page 11: MacRuby on Rails

• http://www.netlab.jp/

My Company

Page 12: MacRuby on Rails

• http://www.netlab.jp/• Shimane, Japan

My Company

Page 13: MacRuby on Rails

• http://www.netlab.jp/• Shimane, Japan• Since 2001

My Company

Page 14: MacRuby on Rails

• http://www.netlab.jp/• Shimane, Japan• Since 2001➡ 10th Anniversary!

My Company

Page 15: MacRuby on Rails

• http://www.netlab.jp/• Shimane, Japan• Since 2001➡ 10th Anniversary!

• 57 people

My Company

Page 16: MacRuby on Rails

• http://www.netlab.jp/• Shimane, Japan• Since 2001➡ 10th Anniversary!

• 57 people ➡ 6 people are cRuby committers

My Company

Page 17: MacRuby on Rails

• http://www.netlab.jp/• Shimane, Japan• Since 2001➡ 10th Anniversary!

• 57 people ➡ 6 people are cRuby committers

• SI, Training, etc...

My Company

Page 18: MacRuby on Rails

The NaCl Way

Page 19: MacRuby on Rails

The NaCl Way

NaCl's President

Page 20: MacRuby on Rails

The NaCl Way

Page 21: MacRuby on Rails

The NaCl WayFirst, I want You to be happy.

Page 22: MacRuby on Rails

The NaCl WayFirst, I want You to be happy.

Next, I want you to make Your

Family happy.

Page 23: MacRuby on Rails

The NaCl WayFirst, I want You to be happy.

Next, I want you to make Your

Family happy.

Finally, if you have more happiness

left, then please share it with Our

Company :)

Page 24: MacRuby on Rails

The NaCl Way(as I see it)

Page 25: MacRuby on Rails

The NaCl Way(as I see it)

• First: Employee

Employee

Page 26: MacRuby on Rails

The NaCl Way(as I see it)

• First: Employee• Next: Employee's Family

Employee Employee'sFamily>

Page 27: MacRuby on Rails

The NaCl Way(as I see it)

• First: Employee• Next: Employee's Family• Finally: Company

Employee Employee'sFamily

Company> >>

Page 28: MacRuby on Rails

The NaCl Way(as I see it)

• First: Employee• Next: Employee Family• Finally: Company

Employee Employee'sFamily

Company> >>

Page 29: MacRuby on Rails

The NaCl Way(as I see it)

• First: Employee• Next: Employee Family• Finally: Company

Employee Employee'sFamily

Company> >>

I love my

company!!

Page 30: MacRuby on Rails

R u b y C o n f 2 0 1 1 - 2 0 1 1 / 0 9 / 3 0Network Applied Communication Laboratory Ltd.K o u j i T a k a o < k o u j i @ n e t l a b . j p >@takaokouji_en/[email protected]: Yuki Morohoshi<[email protected]>

MacRuby on Rails

Page 31: MacRuby on Rails

R u b y C o n f 2 0 1 1 - 2 0 1 1 / 0 9 / 3 0Network Applied Communication Laboratory Ltd.K o u j i T a k a o < k o u j i @ n e t l a b . j p >@takaokouji_en/[email protected]: Yuki Morohoshi<[email protected]>

MacRuby on Rails

Ma c R u b y U n o f f i c i a l C h a r a c t e rR u b y N i n j a @ l r z

Page 32: MacRuby on Rails

R u b y C o n f 2 0 1 1 - 2 0 1 1 / 0 9 / 3 0Network Applied Communication Laboratory Ltd.K o u j i T a k a o < k o u j i @ n e t l a b . j p >@takaokouji_en/[email protected]: Yuki Morohoshi<[email protected]>

MacRuby on Rails

Ma c R u b y U n o f f i c i a l C h a r a c t e rR u b y N i n j a @ l r z

Page 33: MacRuby on Rails

R u b y C o n f 2 0 1 1 - 2 0 1 1 / 0 9 / 3 0Network Applied Communication Laboratory Ltd.K o u j i T a k a o < k o u j i @ n e t l a b . j p >@takaokouji_en/[email protected]: Yuki Morohoshi<[email protected]>

MacRuby on Rails

Ma c R u b y U n o f f i c i a l C h a r a c t e rR u b y N i n j a @ l r z

MacRuby 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 the technical internals that I discovered along the way.

Page 34: MacRuby on Rails

R u b y C o n f 2 0 1 1 - 2 0 1 1 / 0 9 / 3 0Network Applied Communication Laboratory Ltd.K o u j i T a k a o < k o u j i @ n e t l a b . j p >@takaokouji_en/[email protected]: Yuki Morohoshi<[email protected]>

MacRuby on Rails

Ma c R u b y U n o f f i c i a l C h a r a c t e rR u b y N i n j a @ l r z

Page 35: MacRuby on Rails

MacRubyRuby customized for Mac OS X

Page 36: MacRuby on Rails

MacRuby

Page 37: MacRuby on Rails

MacRuby

• MacRuby is a unique blend of Ruby 1.9 and Objective-C.

Page 38: MacRuby on Rails

MacRuby

• MacRuby is a unique blend of Ruby 1.9 and Objective-C.

• The goal of the MacRuby project is to be 100% compatible syntactically and behaviorally with Ruby 1.9.

Page 39: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 40: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 41: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 42: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 43: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 44: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 45: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 46: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 47: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 48: MacRuby on Rails

Ruby 1.9

OS(Linux,Windows,Mac OS X,etc...)

System libraries

Ruby 1.9

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 49: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 50: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 51: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 52: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

Page 53: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibrary

AutoZone

Page 54: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibraryFoundation

AutoZone

Page 55: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibraryFoundation

AutoZone

"kouji".transform("latin-hiragana")#=> こうじ

Page 56: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibraryFoundation

AutoZone

Page 57: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibraryFoundation

AutoZone

Page 58: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibraryFoundation

AutoZone

Page 59: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

Built-inGC

Ruby VM

Built-inLibrary

StandardLibraryFoundation

AutoZone

Page 60: MacRuby on Rails

MacRuby

Mac OS X

System libraries

MacRuby

Application

GenerationalThreaded GC

LLVM

Built-inLibrary

StandardLibrary

AutoZone

Foundation

Page 61: MacRuby on Rails

MacRuby on RailsMaking Ruby on Rails work on MacRuby

Page 62: MacRuby on Rails

Current Status

Page 63: MacRuby on Rails

Current Status$ rails new demo

Page 64: MacRuby on Rails

Current Status$ rails new demo

$ rails generate scaffold ...

Page 65: MacRuby on Rails

Current Status

$ rails server

$ rails new demo

$ rails generate scaffold ...

Page 66: MacRuby on Rails

Current Status

$ rails server

$ rails new demo

$ rails generate scaffold ...

Page 67: MacRuby on Rails

7 months ago...

Page 68: MacRuby on Rails

March 2011 in Japan

7 months ago...

Page 69: MacRuby on Rails

March 2011 in Japan

• I thought, "Does Rails work on MacRuby?".

7 months ago...

Page 70: MacRuby on Rails

March 2011 in Japan

• I thought, "Does Rails work on MacRuby?".

• I managed to install Rails.

7 months ago...

$ sudo macgem install rails7 gems installed

$ sudo macgem install sqlite3-ruby2 gems installed

Page 71: MacRuby on Rails

Perhaps...

Page 72: MacRuby on Rails

• I thought, "OK, it's installed, but surely the Rails generators won't work...".

Perhaps...

Page 73: MacRuby on Rails

• I thought, "OK, it's installed, but surely the Rails generators won't work...".

• However, I managed to create a Rails project!?

Perhaps...

$ macruby -S rails new demo create create README ... create vendor/plugins create vendor/plugins/.gitkeep

Page 74: MacRuby on Rails

Are you kidding me?

Page 75: MacRuby on Rails

• I tried to generate a scaffold...

Are you kidding me?

Page 76: MacRuby on Rails

• I tried to generate a scaffold...

• It failed. After all Rails didn't work on MacRuby.

Are you kidding me?

$ 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

Page 77: MacRuby on Rails

• I tried to generate a scaffold...

• It failed. After all Rails didn't work on MacRuby.

Are you kidding me?

$ 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

Page 78: MacRuby on Rails

My approach

Run Rails

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Page 79: MacRuby on Rails

My approach

Run Rails

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Page 80: MacRuby on Rails

My approach

Run Rails

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Page 81: MacRuby on Rails

My approach

Run Rails

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Page 82: MacRuby on Rails

My approach

Run Rails

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Page 83: MacRuby on Rails

My approach

Run Rails

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Page 84: MacRuby on Rails

My approach

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Run RubySpec

Coding

Research

Page 85: MacRuby on Rails

My approach

Run RubySpec

Coding

Research

SEGV or abort

Run Rails

Run RubySpec

Coding

Research

Required knowledge and technology

• cRuby

• Objective-C

• C++

• LLVM

Page 86: MacRuby on Rails

A couple of examples ofwhat I have fixed so far

Page 87: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

➡ MacRuby aborts if you use catch and throw inside a rescue clause.

Page 88: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

➡ MacRuby aborts if you use catch and throw inside a rescue clause.

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

Page 89: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

➡ MacRuby aborts if you use catch and throw inside a rescue clause.

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

:okAssertion failed: ((size_t)pos < current_exceptions.size()), function pop_current_exception, file vm.cpp, line 3448.

Page 90: MacRuby on Rails

Exception Handling(in MacRuby)

Page 91: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Page 92: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Page 93: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Exception Stack

Page 94: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Exception Stack"A"

push

Page 95: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Exception Stack"A"

push

Page 96: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Exception Stack"A"

"B"

push

push

Page 97: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Exception Stack"A"

"B"

push

push

Page 98: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Exception Stack"A"

push

push

pop

Page 99: MacRuby on Rails

01: begin02: raise "A"03: rescue04: begin05: raise "B"06: rescue07: end08: end

Exception Handling(in MacRuby)

Exception Stack

push

push

pop

pop

Page 100: MacRuby on Rails

Exception Handling and catch / throw(in MacRuby)

Exception Stack

Page 101: MacRuby on Rails

01: catch(:foo) {02: begin03: raise "A"04: rescue05: throw :foo06: end07: }

Exception Handling and catch / throw(in MacRuby)

Exception Stack

Page 102: MacRuby on Rails

01: catch(:foo) {02: begin03: raise "A"04: rescue05: throw :foo06: end07: }

Exception Handling and catch / throw(in MacRuby)

Exception Stack

Page 103: MacRuby on Rails

01: catch(:foo) {02: begin03: raise "A"04: rescue05: throw :foo06: end07: }

Exception Handling and catch / throw(in MacRuby)

Exception Stack"A"

push

Page 104: MacRuby on Rails

01: catch(:foo) {02: begin03: raise "A"04: rescue05: throw :foo06: end07: }

Exception Handling and catch / throw(in MacRuby)

Exception Stack"A"

push

Page 105: MacRuby on Rails

01: catch(:foo) {02: begin03: raise "A"04: rescue05: throw :foo06: end07: }

Exception Handling and catch / throw(in MacRuby)

Exception Stack"A"

push

Page 106: MacRuby on Rails

01: catch(:foo) {02: begin03: raise "A"04: rescue05: throw :foo06: end07: }

Exception Handling and catch / throw(in MacRuby)

Exception Stack

push

pop

Page 107: MacRuby on Rails

Before being fixed(60723bf~), 'throw' always popped the current Exception.

throw(in "old " MacRuby)

VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... if (current_exception() != Qnil) { pop_current_exception(); }...

vm.cpp:4321:

Page 108: MacRuby on Rails

Before being fixed(60723bf~), 'throw' always popped the current Exception.

throw(in "old " MacRuby)

VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... if (current_exception() != Qnil) { pop_current_exception(); }...

vm.cpp:4321:

Page 109: MacRuby on Rails

Before being fixed(60723bf~), 'throw' always popped the current Exception.

throw(in "old " MacRuby)

VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... if (current_exception() != Qnil) { pop_current_exception(); }...

vm.cpp:4321:

Page 110: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

Exception Stack

Page 111: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

Exception Stack"A"

push

Page 112: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

Exception Stack"A"

push

Page 113: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

Exception Stack

push

pop

Page 114: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

Exception Stack

push

pop

pop

Page 115: MacRuby on Rails

#860 catch/throw(in "old" MacRuby)

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

Exception Stack

push

pop

pop

A b o r t ! !

Page 116: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

How to fix(in "new" MacRuby)

Exception Stack

Page 117: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

How to fix(in "new" MacRuby)

Exception Stack"A"

push

Page 118: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

How to fix(in "new" MacRuby)

Exception Stack"A"

push

store

Page 119: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

How to fix(in "new" MacRuby)

Exception Stack"A"

push

store

Page 120: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) { throw :foo }05: end

How to fix(in "new" MacRuby)

Exception Stack

push

pop store

Page 121: MacRuby on Rails

VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... while (catch_ptr->current_exception != current_exception()) { pop_current_exception(); }...

How to fix(in "new" MacRuby)

vm.cpp:4318:

In the new implementation, MacRuby only pops exceptions when necessary (60723bf)

Page 122: MacRuby on Rails

VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... while (catch_ptr->current_exception != current_exception()) { pop_current_exception(); }...

How to fix(in "new" MacRuby)

vm.cpp:4318:

In the new implementation, MacRuby only pops exceptions when necessary (60723bf)

Page 123: MacRuby on Rails

VALUERoxorVM::ruby_throw(VALUE tag, VALUE value){... while (catch_ptr->current_exception != current_exception()) { pop_current_exception(); }...

How to fix(in "new" MacRuby)

vm.cpp:4318:

In the new implementation, MacRuby only pops exceptions when necessary (60723bf)

Page 124: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) {05: begin06: raise "B"07: rescue08: throw :foo09: end10: }11: end

#860 Fixed(in "new" MacRuby)

Exception Stack

Page 125: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) {05: begin06: raise "B"07: rescue08: throw :foo09: end10: }11: end

#860 Fixed(in "new" MacRuby)

Exception Stack"A"

push

store

Page 126: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) {05: begin06: raise "B"07: rescue08: throw :foo09: end10: }11: end

#860 Fixed(in "new" MacRuby)

Exception Stack"A"

push

push

store

"B"

Page 127: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) {05: begin06: raise "B"07: rescue08: throw :foo09: end10: }11: end

#860 Fixed(in "new" MacRuby)

Exception Stack"A"

push

push

store

"B"

Page 128: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) {05: begin06: raise "B"07: rescue08: throw :foo09: end10: }11: end

#860 Fixed(in "new" MacRuby)

Exception Stack"A"

push

pop

push

store

Page 129: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) {05: begin06: raise "B"07: rescue08: throw :foo09: end10: }11: end

#860 Fixed(in "new" MacRuby)

Exception Stack"A"

push

pop

push

store

Page 130: MacRuby on Rails

01: begin02: raise "A"03: rescue04: catch(:foo) {05: begin06: raise "B"07: rescue08: throw :foo09: end10: }11: end

#860 Fixed(in "new" MacRuby)

Exception Stack

push

pop

push

pop

store

Page 131: MacRuby on Rails

#1192 Constant Lookup➡MacRuby failed to correctly look up

constants in a number of situations when you used module_eval and class_eval.

Page 132: MacRuby on Rails

#1192 Constant Lookup➡MacRuby failed to correctly look up

constants in a number of situations when you used module_eval and class_eval.

module A B = 10 Object.class_eval { B }end

Page 133: MacRuby on Rails

#1192 Constant Lookup➡MacRuby failed to correctly look up

constants in a number of situations when you used module_eval and class_eval.

module A B = 10 Object.class_eval { B }end

reduction.rb:3:in `block': uninitialized constant B (NameError)

Page 134: MacRuby on Rails

#1192 Constant Lookup➡MacRuby failed to correctly look up

constants in a number of situations when you used module_eval and class_eval.

module A B = 10 Object.class_eval { B }end

reduction.rb:3:in `block': uninitialized constant B (NameError)

cRuby

Page 135: MacRuby on Rails

#1192 Constant Lookup➡MacRuby failed to correctly look up

constants in a number of situations when you used module_eval and class_eval.

module A B = 10 Object.class_eval { B }end

reduction.rb:3:in `block': uninitialized constant B (NameError)

MacRuby

Page 136: MacRuby on Rails

Constant Lookup(in cRuby)

Page 137: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Page 138: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Page 139: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Page 140: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Page 141: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Page 142: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Page 143: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Lexical Scope

Page 144: MacRuby on Rails

Constant Lookup(in cRuby)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Lexical Scope

Lexical Constant Lookup

Page 145: MacRuby on Rails

Constant Lookup(in "old" MacRuby)

MacRuby had not implemented Lexical Constant Lookup.1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

Page 146: MacRuby on Rails

Constant Lookup(in "old" MacRuby)

MacRuby had not implemented Lexical Constant Lookup.1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

MacRuby

Page 147: MacRuby on Rails

Constant Lookup(in "old" MacRuby)

MacRuby had not implemented Lexical Constant Lookup.

-e:5:in `block': uninitialized constant A::CONST (NameError)

1: module A2: module B3: CONST = "B’s Const"4: module ::A5: p CONST6: end7: end8: end

MacRuby

Page 148: MacRuby on Rails

Constant Lookup is complex(in cRuby)

Page 149: MacRuby on Rails

Constant Lookup is complex(in cRuby)

class_eval(String)class_eval(&Block)01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

Page 150: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 151: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 152: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 153: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 154: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 155: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 156: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 157: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 158: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 159: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 160: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)

Page 161: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)Lexical Scope

Page 162: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(&Block)Lexical Scope

"A's CONST"

Page 163: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(String)

Page 164: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(String)

Page 165: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(String)

Page 166: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(String)

Page 167: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(String)

Page 168: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(String)

Dynamic Scope

Page 169: MacRuby on Rails

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

class_eval(String)

Dynamic Scope

"K's CONST"

Page 170: MacRuby on Rails

Constant Lookup is complex(in cRuby)

class_eval(String)class_eval(&Block)01: module A02: CONST = "A's CONST"03: def f()04: class_eval {05: p CONST06: }07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

01: module A02: CONST = "A's CONST"03: def f()04: class_eval <<-EOS05: p CONST06: EOS07: end08: end09:10: class K11: CONST = "K's CONST"12: extend A13: f()14: end

Lexical Scope

"A's CONST"

Dynamic Scope

"K's CONST"

Page 171: MacRuby on Rails

I somehow managed to fix this(in MacRuby)

Page 172: MacRuby on Rails

I somehow managed to fix this(in MacRuby)

• Three attempts to get it right.

Page 173: MacRuby on Rails

I somehow managed to fix this(in MacRuby)

• Three attempts to get it right.

• More than 3000 lines of code changed.

Page 174: MacRuby on Rails

I somehow managed to fix this(in MacRuby)

• Three attempts to get it right.

• More than 3000 lines of code changed.

21 Apr 2011 15:24 Laurent S.

it's official,kouji is the hero of the day/week/month/...?

his patch seems to fix remaining lexical

const lookup bugs :)

Page 175: MacRuby on Rails

A very complex bug(in "new" MacRuby)

Page 176: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Page 177: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Page 178: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Page 179: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Page 180: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Page 181: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Page 182: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Page 183: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Lexical

Page 184: MacRuby on Rails

A very complex bug(in "new" MacRuby)

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

Lexical

CAUTION'class_eval' does not add it's own receiver(A) to the constant lookup scope.

Page 185: MacRuby on Rails

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

A very complex bug(in cRuby)

Page 186: MacRuby on Rails

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

A very complex bug(in cRuby)

Ruby 1.9

➡42

Page 187: MacRuby on Rails

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

A very complex bug(in cRuby)

Ruby 1.9

➡42

Ruby 1.8.7

➡-e:8:in `f': uninitialized constant B (NameError)

Page 188: MacRuby on Rails

01: module A02: B = 4203: end04:05: A.class_eval do06: def self.f07: p B08: end09: end10:11: A.f

A very complex bug(in cRuby)

Ruby 1.9

➡42

Ruby 1.8.7

➡-e:8:in `f': uninitialized constant B (NameError)

A cRuby's Bug

Page 189: MacRuby on Rails

Demo

$ rails server

$ rails new demo

$ rails generate scaffold ...

Page 190: MacRuby on Rails

#1390 rb_vm_prepare_block

➡ Abort if the "About your application’s environment" is link is clicked.

CLICK!

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

Page 191: MacRuby on Rails

The MacRuby train trip continues...

Page 192: MacRuby on Rails

The MacRuby train trip continues...

http://www.macruby.org/

Page 193: MacRuby on Rails

The MacRuby train trip continues...

http://www.macruby.org/

@macruby

Page 194: MacRuby on Rails

The MacRuby train trip continues...

http://www.macruby.org/

@macruby

GitHub:MacRuby/MacRuby

Page 196: MacRuby on Rails

Conclusion

Page 197: MacRuby on Rails

Conclusion

• MacRuby

➡MacRuby is a unique blend of Ruby 1.9 and Objective-C.

➡The goal is to be 100% compatible with Ruby 1.9.

Page 198: MacRuby on Rails

Conclusion

• MacRuby

➡MacRuby is a unique blend of Ruby 1.9 and Objective-C.

➡The goal is to be 100% compatible with Ruby 1.9.

• MacRuby on Rails

➡We're now able to show the default Rails welcome page.

➡But there is still a lot to do.

Page 199: MacRuby on Rails

Acknowledgment

Page 200: MacRuby on Rails

Acknowledgment

• The RubyConf hosts and organizers

Page 201: MacRuby on Rails

Acknowledgment

• The RubyConf hosts and organizers

• Tor Yamamoto-Sorensen (@shakaijin)

Page 202: MacRuby on Rails

Acknowledgment

• The RubyConf hosts and organizers

• Tor Yamamoto-Sorensen (@shakaijin)

• Everyone present today

Page 203: MacRuby on Rails

Thank you

Page 204: MacRuby on Rails

Q & A

• If you have a question, please ask me, but if possible please speak slowly.

• or contact @takaokouji_en by Twitter

• or send e-mail to MacRuby ML