Current Version 0.5

Check out the tutorial, resources     and examples that are available for MacRuby.

MacRuby Events

19-21 Nov 2009 » RubyConf
San Francisco, CA
Laurent Sansonetti presents MacRuby

19-21 Nov 2009 » RubyConf
San Francisco, CA
Matt Aimonetti talks about writing 2D video games with MacRuby

Blog Overview

The MacRuby Blog

By Laurent Sansonetti

As you might have noticed, MacRuby 0.4 has just been released a few days ago. It’s now time to focus on the next release, 0.5, which will be principally dedicated to performance.

New Virtual Machine

A new virtual machine based on the LLVM compiler infrastructure has been developed and integrated as a replacement for YARV.

The new VM transforms the abstract source tree (AST) directly from the parser into LLVM’s intermediate representation (IR), which is then compiled into optimized machine code. A number of other key optimizations have also been completed, such as fast fixnum arithmetic, cached method dispatch, zero-cost IA64 exceptions, fast instance variable access, constants caching, fast break/next, cheap local variables, tail call optimization and much more.

While the amount of work remaining is significant, the compiler is already able to compile most of the Ruby syntax and the new runtime is mostly complete. Early performance measurements are also very promising, with substantial room for improvement remaining.

New IO Subsystem

A new IO implementation based on CoreFoundation streams is under active development. The objective of this work is to provide a cleaner and faster implementation of the various IO operations; additionally, we will be able to perform asynchronous operations through the principal run loop.

A ByteString class which silently inherits from String has been introduced and is now used as the return value of all IO operations. Its backing store is a CFMutableDataRef, which integrates better with the new IO subsystem and offers substantially better performance.

RubySpec Integration

Performance without compatibility is, of course, meaningless. We have therefore integrated the RubySpec project and are aiming to pass all the specifications.

The current experimental branch is already able to pass most of the language specifications and will be a standard part of our regression test suite. We are also actively working on upgrading the specifications to match the Ruby 1.9 behaviors.

Want to Help?

If you want to help or simply give the new changes a try, everything is on the experimental SVN branch.

$ svn co http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental macruby-experimental

Please make sure to read the README file for information regarding requirements, dependencies and build instructions. Do not hesitate to contact us if you need more info!

2009-03-09
By Laurent Sansonetti

After several months of development and some slight delays, MacRuby 0.4 is now available. Get it here while it’s still hot!

This is quite an important release that brings new features and fixes several problems. The changes are too numerous to be all mentioned, so here is a selection of the most interesting ones.

Threaded GC

The MacRuby garbage collector is now running in multi-threaded mode by default. That means that MacRuby will always do garbage collections on a separate thread and therefore not interrupt the program’s flow.

Full 64-bit Support

MacRuby is now fully working in both Intel 32-bit and 64-bit modes. If you are running a recent Mac chances are that it is 64-bit and MacRuby will run faster on it. This is mainly due to the fact that the underlying infrastructure has been significantly improved for 64-bit processors.

DTrace Probes

DTrace probes have been added to the core of the interpreter. You can now trace various things such as method calls or exceptions. All of that can be done on any MacRuby processes in the system.

provider macruby {
    probe insn__entry(char *insnname, char *sourcefile, int sourceline);
    probe insn__return(char *insnname, char *sourcefile, int sourceline);
    probe method__entry(char *classname, char *methodname, char *sourcefile, int sourceline);
    probe method__return(char *classname, char *methodname, char *sourcefile, int sourceline);
    probe raise(char *classname, char *sourcefile, int sourceline);
    probe rescue(char *sourcefile, int sourceline);
};

DTrace is a very powerful tool that has proven to be extremely useful when debugging live applications. MacRuby ships with several DTrace scripts in /Developer/Examples/Ruby/MacRuby/DTrace to profile various things such as method count, duration or even objects collected by the GC.

Runtime Objective-C API

MacRuby now exposes an Objective-C API that can be used to control the runtime from a pure Cocoa environment.

$ cat hello_macruby.m 
#import <Foundation/Foundation.h>
#import <MacRuby/MacRuby.h>

int main(void) {
    id proc = [[MacRuby sharedRuntime] evaluateString:@"proc { |x| puts \"hello #{x}\"}"];
    [proc performRubySelector:@selector(call:) withArguments:@"MacRuby"];
    return 0;
}
$ gcc hello_macruby.m -o hello_macruby -framework Foundation -framework MacRuby -fobjc-gc
$ ./hello_macruby 
hello MacRuby

It should be helpful if you are working on an Objective-C Cocoa application and are considering using MacRuby to either implement new functionalities or to provide a scripting interface to your native objects.

New Xcode Templates

A “MacRuby Core Data Application” template is now available, as well as an “Embed MacRuby” target. The latter can be used to embed MacRuby.framework inside your application bundle. Embedding the framework allows you to distribute your application to users and not require them to install MacRuby.

A Better HotCocoa

HotCocoa is a thin, idiomatic Ruby layer that sits above Cocoa and other frameworks. It was introduced in MacRuby 0.3 and it has been significantly improved in 0.4.

New mappings for XML parser, KVO array/set accessors, property lists and more AppKit components were added as well as lots of bug fixes and improvements.

A “deploy” task was added to the project’s Rakefile. This new task prepares an application for deployment by embedding the MacRuby runtime inside its bundle (similar to what the Xcode’s Embed MacRuby target does). Once the “macrake deploy” task is complete, you can share your .app with friends who do not have MacRuby installed on their machine.

But the most interesting change is probably the new graphics layer, called HotCocoa::Graphics. It provides a simple object-oriented interface into the power of Mac OS X’s Core Graphics and Core Image drawing libraries.

Misc Changes

Over the list of minor changes, Set has been reimplemented on top of NSSet and NSNumber implements the Numeric methods. Finally, the standard library was updated to Ruby 1.9.1’s version.

Caveat Lector

While MacRuby 0.4 turns out to be pretty stable when it comes to Cocoa development, there are still a few problems with C extensions, RubyGems and Ruby IOs. We recommend to use the corresponding Cocoa APIs (when they exist) in the meantime we work on these issues.

We hope that you will enjoy this release. Please let us know if you find any problems.

Stay tuned for more details about the next release: 0.5, which will be focusing on performance.

By Laurent Sansonetti

The Apple Developer Connection (ADC) website is now featuring an article about MacRuby, titled Developing Cocoa Applications Using MacRuby. This article will introduce you to MacRuby and guide you through the process of writing a Cocoa application with it.

Enjoy, and do not hesitate to contact us if you have any question!


« newer | Page 2 of 4 | older »