compiler – PullMonkey Blog http://pullmonkey.com Thu, 10 Nov 2011 06:23:18 +0000 en-US hourly 1 https://wordpress.org/?v=5.6 Playing with Mirah http://pullmonkey.com/2011/11/10/playing-with-mirah/ http://pullmonkey.com/2011/11/10/playing-with-mirah/#comments Thu, 10 Nov 2011 06:14:37 +0000 http://pullmonkey.com/?p=57622 Mirah (formally duby) is pretty freaking cool.   Plans are to scrap java and use mirah for future android development, we'll see.  Here's a rough example of some pretty basic mirah.

To get started, you'll need jruby and the mirah gem:

rvm install jruby
rvm use jruby (or put in your .rvmrc)
gem install mirah

Then create an example:

puts "hello world!!"
500.times do |x|
  puts x
end

Time in ruby:

time ruby test.mirah

...
=> .457s

Compile to Java and time:

mirahc test.mirah
time java Test

....
=> .081s

Less than 1/5 the time and it compiles to Java ... neat 🙂

mirahc -j test.mirah

// Generated from test.mirah
public class Test extends java.lang.Object {
  public static void main(java.lang.String[] argv) {
    int __xform_tmp_1 = 0;
    int __xform_tmp_2 = 0;
    int x = 0;
    java.io.PrintStream temp$1 = java.lang.System.out;
    temp$1.println("hello world");
    __xform_tmp_1 = 0;
    __xform_tmp_2 = 500;
    label2:
    while ((__xform_tmp_1 < __xform_tmp_2)) {
      x = __xform_tmp_1;
      label3:
       {
        java.io.PrintStream temp$4 = java.lang.System.out;
        temp$4.println(x);
      }
      __xform_tmp_1 = (__xform_tmp_1 + 1);
    }
  }
}
]]>
http://pullmonkey.com/2011/11/10/playing-with-mirah/feed/ 1