Mirah (programming language)
Encyclopedia
Mirah is a programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 based on Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

 syntax, local type inference
Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....

, hybrid static/dynamic type system
Type system
A type system associates a type with each computed value. By examining the flow of these values, a type system attempts to ensure or prove that no type errors can occur...

, and a pluggable compiler toolchain. Mirah is an effort by Charles Oliver Nutter to create "a 'Ruby-like' language, probably a subset of Ruby syntax, that [could] compile to solid, fast, idiomatic JVM bytecode
Java bytecode
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. 51 are reserved for future use...

." The word refers to the gemstone ruby
Ruby
A ruby is a pink to blood-red colored gemstone, a variety of the mineral corundum . The red color is caused mainly by the presence of the element chromium. Its name comes from ruber, Latin for red. Other varieties of gem-quality corundum are called sapphires...

 in the Javanese language
Javanese language
Javanese language is the language of the Javanese people from the central and eastern parts of the island of Java, in Indonesia. In addition, there are also some pockets of Javanese speakers in the northern coast of western Java...

, a play on the concept of Ruby in Java.

History

In order to foster more participation in the JRuby
JRuby
JRuby is a Java implementation of the Ruby programming language, being developed by the JRuby team. It is free software released under a three-way CPL/GPL/LGPL license...

 project from Ruby community members, Nutter began to explore the possibility of presenting Ruby syntax, but with a static type model and direct-to-native compilation. In this context, "native" meant primarily the JVM
Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...

, but Mirah has been designed around the possibility of having alternative backends for other object-oriented runtimes like the CLR
Common Language Runtime
The Common Language Runtime is the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...

. The language needed to look and feel like Ruby, but without introducing any new library dependencies into JRuby (which ruled out most other JVM languages) and without suffering a performance penalty (which meant writing in Ruby itself was out).

Early versions of Mirah (then Duby) focused mostly on mathematical performance, where dynamic languages
Dynamic programming language
Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all...

 often pay the highest cost. Since then it has evolved into a full-fledged JVM language, with several users and real-world applications using it for core components.

Design

Mirah is largely just a pluggable compiler toolchain. The primary elements of this toolchain are:
  1. A parser
    Parsing
    In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a text, made of a sequence of tokens , to determine its grammatical structure with respect to a given formal grammar...

    , based on JRuby's parser, that produces a Ruby AST
    Abstract syntax tree
    In computer science, an abstract syntax tree , or just syntax tree, is a tree representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code. The syntax is 'abstract' in the sense that it...

  2. A transformer that converts the Ruby AST into a Mirah AST
  3. A type inferrer that decorates the Mirah AST with appropriate typing information for the target backend
  4. A backend code generator


Of these phases, only the last two require specific knowledge of the eventual target platform. This makes Mirah suitable for many backends, and also makes it possible to write language plugins for Mirah's transformation phase that will apply to all supported backends equally.

For simple pieces of code and the JVM bytecode backend, the Mirah compiler will produce nearly the same instructions as standard javac compilers.

No runtime library

Because Mirah is just a compiler, it ships no standard library
Standard library
A standard library for a programming language is the library that is conventionally made available in every implementation of that language. In some cases, the library is described directly in the programming language specification; in other cases, the contents of the standard library are...

. The intent is that Mirah users will choose what libraries they want to use, perhaps write plugins for the Mirah compiler to support them, and the compiler will do the rest. This is an explicit design goal, avoid introducing a requirement on any new external library. The standard library for Mirah, then, is whatever the standard library for the current backend is, and emphasis is placed on writing compiler plugins rather than libraries to extend and enhance the language.

Type system

Mirah does not impose a specific type system on users, instead relying on whatever the target backend provides. On the JVM, the type system is largely Java's type system, and type declarations
Declaration (computer science)
In programming languages, a declaration specifies the identifier, type, and other aspects of language elements such as variables and functions. It is used to announce the existence of the element to the compiler; this is important in many strongly-typed languages that require variables and their...

 refer to JVM classes, primitives, and interfaces.

Mirah is primarily a statically-typed language, but support is in development to allow dynamic typing as well. The mechanism is similar to that provided in C# 4, with a special "dynamic" type indicating all dispatches against that variable
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

's value should be done dynamically. Dynamic type support is currently planned only for Java 7 and higher, using the new invokedynamic bytecode.

Syntax

The syntax of Mirah is largely the same as the syntax of Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

, but with a few modifications to support static typing:
  • Method parameters usually need to have their types declared:


def foo(a:String, b:int)
  • Because several transformations occur in the Mirah compiler toolchain, some strings that are valid identifiers in Ruby are treated as keywords in Mirah, such as the word "interface" used to specify a JVM-style interface.


Outside of these differences, Mirah code generally looks like Ruby code:

def fib(a:int)
if a < 2
a
else
fib(a - 1) + fib(a - 2)
end
end

Status

Currently Mirah is under development, but there are developers using Mirah for production applications on a limited scope.

Dubious

Dubious is a project for running Mirah on Google App Engine
Google App Engine
Google App Engine is a platform as a service cloud computing platform for developing and hosting web applications in Google-managed data centers. It virtualizes applications across multiple servers,...

. Dubious provide a way to build apps in Mirah, with conventions familiar to Rails and Sinatra developers. Since everything is compiled ahead-of-time Mirah apps have none of the initialization costs associated with JRuby. Dubious supports ERb
ERuby
eRuby is a templating system that embeds Ruby into a text document. It is often used to embed Ruby code in an HTML document, similar to ASP, JSP and PHP.-Usage:eRuby allows Ruby code to be embedded within a pair of delimiters...

and has a simple datastore adapter that uses a syntax similar to DataMapper.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK