MacRuby: objective-c runtime is same as ruby runtime
I have no formal education in computer science but I have been programming in Java, Ruby, jQuery for a long time.
I was checking out macruby project. I keep running into stat开发者_高级运维ements which are similar to "In MacRuby objective-c runtime is same as ruby runtime".
I understand what MRI is. I understand what ruby 1.9 is bringing to the table. However I fail to understand how the VM for one language can support another language.
I know I am asking a question answer to which relies on years of formal education. Still any pointers and any discussion will help.
Also I like what I see in macruby.
Well,
The simplest explanation is that MacRuby is a ruby 1.9 VM. During earlier versions it was a modified version of the YARV (ruby 1.9's official VM) which instead of using custom types for things like ruby strings, hashes etc. made use of equivalents found within apples foundation classes such as NString. With the advent of version 0.5 a whole new VM has been developed based on the LLVM framework, again ruby 1.9 compatible, which is ground up based on apples foundation classes.
Therefore you can think of Macruby simply as a ruby 1.9 VM. However, due to the use of aforementioned foundation classes it has been possible to interface natively with much of apples own api's providing additional features only available to those running MacRuby (such as HotCocoa for example.)
Just a note on the
However I fail to understand how the VM for one language can support another language.
part.
A VM represents a middle layer between the machine and your programming language. E.g. the Java Virtual Machine (JVM) execute so called java bytecode. The javac
compiler takes the source code and compiles it into an intermediate language - that bytecode. When you run your application, you actually run bytecode inside the virtual machine:
The JVM runtime executes .class or .jar files, emulating the JVM instruction set by interpreting it, or using a just-in-time compiler (JIT) such as Sun's HotSpot. JIT compiling, not interpreting, is used in most JVMs today to achieve greater speed. Ahead-of-time compilers that enable the developer to precompile class files into native code for a particular platforms also exist.
It is therefore possible to code in any language (e.g. Clojure, Scala, Rhino, ...) for which a compiler to a certain VM has been written. The same princle applies to the architecture around Microsoft .NET's Common Intermediate Language (CIL).
As for macruby internals, there is a short overview on their site.
精彩评论