作者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 的效能还是很差咧,真不晓得为什麽?
--
#!/usr/bin/env ruby [露比] /Programming (Kn|N)ight/ 看板《Ruby》
# if a
dog nailed
extra legs that
http://webptt.com/cn.aspx?n=bbs/Ruby/index.html
#
walks like an octopus, and Welcome ~
Ruby@ptt~
#
talks like an octopus, then
◢█◣ http://www.ruby-lang.org/
# we are happy to treat it as
█ http://www.ruby-doc.org/
# if it were
an octopus.
◥ ◤ http://www.rubyforge.org/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.160.129