What have you found for these years?

2009-12-31

MacRuby with LLVM

作者 godfat (godfat 真常) 看板 Ruby
標題 Re: [閒聊] MacRuby 0.5
時間 Thu Dec 31 01:23:21 2009
───────────────────────────────────────

※ 引述《godfat (godfat 真常)》之銘言:
: 真要說革命的話應該是 LLVM :p
: Rubinius 有沒有用 LLVM, 效能差異很驚人... 就我自己憑感覺說,五倍可能有。
: 沒用 LLVM 的速度是「完全」不能接受的,有用的話就還算可以。
: LLVM 的 clang 還在快速開發中,慢慢等...
: 之前也看過有人說 Ruby 1.9 快要可以在 clang 上 compile 了。

因為對 LLVM 感興趣,剛剛看了一下他怎麼 compile ruby 程式的:
(只看了幾分鐘,有講錯麻煩指正,感謝 :D)

他的作法也滿單純的,就是用這隻 Ruby 程式產生一個 C++ 程式,
內嵌 C 程式(因為 Ruby 本身是 C),用這隻 C 程式啟動 Ruby VM,
然後呼叫一個外部(後面再 link)的 C function.
這邊看後面的 compile_executable.

而那個 C function 是由 LLVM compile 出來的,compile 法看後面的
compile_object 那段。就是很標準地先 compile 成 LLVM bitcode,
然後再 compile 成 assembly, 最後再 compile 成 object (machine) code.

http://svn.macosforge.org/repository/ruby/MacRuby/trunk/bin/rubyc
我節錄出兩段比較重要的:https://gist.github.com/548caf0d63f647c0fbe2
分別是 compile_object 和 compile_executable 那兩段。

簡單地說就是完全是用 LLVM 做的。
不過 Rubinius 的效能還是很差咧,真不曉得為什麼?

--

--
※ 發信站: 批踢踢實業坊(ptt.cc)

0 retries:

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0