From: n/a Date: 2007-04-01T03:25:04+09:00 Subject: Re: compiler for ruby On Sat, 31 Mar 2007 23:42:31 +0900, Rick DeNatale wrote: > On 3/30/07, n/a wrote: > >> >> I meant under windows and/or Linux environments. >> >> And source code to machine code. >> >> I had done a search of this group but I guess didn't download enough >> headers to see the previous threads. >> >> I see there are various forms of compilers that work at different levels of >> code, e.g. XRuby to Java Bytecode, etc. > > Yes there are a variety of approaches to compiling Ruby to either Java > bytecodes (e.g. XRuby) or bytecodes more specifically tuned to Ruby > semantics (e.g. YARV which is now in Ruby 1.9). I think most people > these days think that bytecode == Java bytecode, but the idea preceded > Java. > > As of today YARV seems to be the best performing, at least according > to the benchmarks I've seen. > > As for compiling directly to machine code, it could be done I suppose, > but it's not clear that it would be the best approach. Why? > > * The dynamic nature of Ruby means that methods can be dynamically > created at run-time and would therefore need to be compiled at > run-time. Additional bookkeeping would be required to make all the > semantic effects on the compiled code would be properly implemented. > > * Previous experience with compiling dynamic OO languages has shown > that the much smaller code representation of byte codes compared to > machine code can actually lead to better performance on machines with > virtual memory (almost all machines these days) due to the smaller > working set. Digitalk tried direct compilation of Smalltalk to > machine code, because they were sick of getting blasted for being > 'interpreted' and found that the byte coded stuff ran significantly > faster. The practice these days is to do two-stage compilation, first > to byte-codes, and then to machine code for selected code when the > run-time detects that that code is frequently executed. > Rick, Thanks for the informative reply. Very helpful.