From: Rick DeNatale Date: 2007-05-15T21:20:32+09:00 Subject: Re: Algorithm books for Ruby (was Re: Object-oriented solution to Tower of Hanoi) On 5/15/07, Florian Frank wrote: > Rick DeNatale schrieb: > > Well, to be fair he actually does describe the VM as working on an > > AST. VM is a general term which actually could be used to describe > > the Ruby 1.x implementation even if x < 9. In fact doesn't YARV stand > > for Yet Another Ruby Vm? > > But where's the "machine" in an AST walker? If the term should make any > sense the higher language code has to be compiled into an intermediary > language. The virtual machine instructions will then be executed on a > simulated processor like the P-Code machine > (http://en.wikipedia.org/wiki/P-code_machine). If these compile and > execution steps don't happen, I would call the resulting program only a > Ruby interpreter - not a Ruby virtual machine. I think that this is too strict a definition. To my mind, a Virtual Machine simply provides some form of virtual execution environments. There seem to be two main branches of VMs, language VMs and VMs for hosting multiple operating systems, or instances of operating systems on one set of hardware. A language VM in general, provides an execution environment which is higher-level than the hardware. There is more to this than just program representation, it also includes, for example GC where the language requires it. The implementation of GC and execution are co-dependent. In most language VM implementations program execution is implemented by some form of interpretation. The difference between bytecode and AST representation of the "object code" is really just an implementation choice. Other VMs use threaded code representations, and there are probably others. And if we are talking about VMs in the operating system sense, virtualization is the isolation of process groups into virtual hardware machines, the program execution is done by the hardware itself, which is the other end of the spectrum. While bytecode/p-code interpretation is a common feature of many virtual machines, I don't consider it to be the sine-qua-non of VMness. > > At least rewriting them isn't as hard as writing them. > > Maybe the author deliberately confused AST interpreters and VMs in order > to cut down on the transliteration work? Well he does actually make the distinction. Compare this page from the Ruby version: http://www.brpreiss.com/books/opus8/html/page36.html which actually shows the AST interpreter (called parse tree interpreter) as part of the Ruby VM, with the equivalent page from the python version: http://www.brpreiss.com/books/opus7/html/page37.html which shows byte code interpretation. Not that this makes the rest of the books valuable as resources for the different languages it's been adapted to. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/