MicroRuby
Run Ruby code on an embedded microcontroller!

The MicroRuby framework allows Ruby bytecode to execute on limited resource systems, to include low-cost microcontrollers.

Creating an embedded application is as simple as writing Ruby, and the binaries can be deployed to almost any platform.

How it Works

The MicroRuby framework is composed of two components – a Ruby Bytecode Compiler that builds the application, and a Virtual Machine that executes the application.

The compiler makes use of Ruby's internal bytecode compiler (YARV), which was introduced in Ruby 1.9. The bytecode is filtered to remove overhead and encoded in a compact binary format. The MicroRuby binary may be installed on the device or deployed at runtime.

The MicroRuby VM is implemented in C as a stack machine. The VM executes the simple bytecode instructions without actually "knowing" Ruby.

The VM is configurable to accommodate different target platforms and applications of widely varying complexity. This makes MicroRuby equally suitable for 8-bit micros with 256 bytes of RAM and enterprise web servers.

Installation

The MicroRuby framework is available as a gem for easy installation:

> gem install microruby

MicroRuby Development

MicroRuby applications start with Ruby source; developed, debugged, and tested however you like. Depending on the deployment strategy, the application may be compiled manually or automatically.

 

 

A really simple bit of Ruby code:

myapp.rb

a = 123
b = 456
c = 7.89
a * b + c

To compile manually, run:

> microruby compile myapp.rb

This generates a bytecode file named myapp.mrbc, which looks something like this:

2B 01 11 04 7B 02 05 2B 01 11 05 01 C8 02 04 2B

01 11 08 40 1F 8F 5C 28 F5 C2 8F 02 03 2B 01 01

05 01 04 3D 02 01 03 3B 03 1F 02 02 30         

Limitations

The current MicroRuby gem (version 0.0.2) is based on an early proof of concept which has limited opcode support. This limits the compiler to "hello world" applications. Complete opcode support is forthcoming.