patshaughnessy / ruby-under-a-microscope

Code Samples for Ruby Under A Microscope - Learning Ruby Internals Through Experiment
56 stars 6 forks source link

[PDF] Inconsistent YARV Definition #3

Open ghost opened 11 years ago

ghost commented 11 years ago

page 10

Jared-Prime commented 11 years ago

I agree, the definitions seem inconsistent. I was also confused by the comparison to the JVM.

There’s one final step on your code’s journey through Ruby: compilation. With Ruby 1.9, the Ruby core team introduced something called “Yet Another Ruby Virtual Machine” (or YARV), which actually executes your Ruby code. (Kindle Locations 617-619).

It was not immediately clear to me that YARV does not actually compile bytecode (or does it)? Being unknowledgeable about such things, a more precise definition would help greatly.

PS. Overall, I'm enjoying the book and learning a ton!

patshaughnessy commented 11 years ago

Hi - glad you're enjoying the book!

I'm going through the text this weekend fixing all the typos and issues, and will update the download kit tomorrow.

So I rewrote this paragraph to be a bit more clear about this - does this sound better?

However if you have upgraded to Ruby 1.9 or Ruby 2.0, then Ruby is still not quite ready to run your code. There’s one final step on your code’s journey through Ruby: compilation. With Ruby 1.9, the Ruby core team introduced something called “Yet Another Ruby Virtual Machine” (or YARV), which actually executes your Ruby code. At a high level, this is the same idea behind the much more famous Java Virtual Machine (or JVM) used by Java and many other languages. To use the JVM, you first compile your Java code into “byte code,” a series of low level instructions that the JVM understands. Starting with version 1.9, Ruby works the same way! The only differences are that:

• Ruby doesn’t expose the compiler to you as a separate tool; instead it automatically compiles your Ruby code into byte code instructions internally without you ever realizing it.

• MRI Ruby also never compiles your Ruby code all the way to machine language. As you can see in the next diagram, Ruby interprets the byte code instructions. The JVM, however, can compile some of the byte code instructions all the way into machine language using its “hotspot” or JIT compiler.

cheers - pat

Jared-Prime commented 11 years ago

that's a bit clearer now that I've been able to process YARV (no pun intended)