开发者

How is ruby code executed

开发者 https://www.devze.com 2023-02-12 23:54 出处:网络
I have recently started to learn Ruby. I know that Ruby is a interpreted language(even though \"every\" language is since it is interpreted by the CPU as machine code). But how does the ruby interpret

I have recently started to learn Ruby. I know that Ruby is a interpreted language(even though "every" language is since it is interpreted by the CPU as machine code). But how does the ruby interpreter convert the code written in Ruby to machine code? I have read that the interpreter do not read the source code, but byte code, however I do never have to compile as I do in Java. So, is this yet another thing that Ruby does for you? And if it does, does it generate the byte code at runtime? Because you never get a .cla开发者_高级运维ss file as you do in Java. And on top of it all I read about Just-In-Time compilators that obviously does something to the byte code so it runs faster.

If the above is the case does the interpreter first scan through all of the source code, convert it into byte code and then compiles it another time with JIT at runtime?

And last I AM NOT looking for an answer with the performance aspect of this, I just want to know how it is processed, which stages it goes through and in what time it does so.

Thanks for your time.

I am using this interpeter http://www.ruby-lang.org/en/


But how does the ruby interpreter convert the code written in Ruby to machine code?

It doesn't, at least not all the implementations.

Afaik only Rubinius is trying to do what you describe, that's compiling to machine code.

I have read that the interpreter do not read the source code, but byte code, however I do never have to compile as I do in Java. So, is this yet another thing that Ruby does for you?

Yes

And if it does, does it generate the byte code at runtime?

Yeap, pretty much. And keeps it in memory. The tradeof is the next time it has to read->translate->execute all over again.

If the above is the case does the interpreter first scan through all of the source code, convert it into byte code and then compiles it another time with JIT at runtime?

Not all the source code, just what it needs. Then yes, create a bytecode representation keeps it in memory, and not necessarily that is compiled to machine code.


The standard implementation of Ruby1.8 uses an interpreter called MRI (Matz's Ruby Interpreter). This is a program that is compiled to machine code that:

  1. Reads the text files into a data structure.
  2. Follows the instructions in the data structure to decide what to do
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号