Mirah (formerly Duby) has been a
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
based on
Ruby
Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
language syntax, local
type inference
Type inference, sometimes called type reconstruction, refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some bran ...
, hybrid static–dynamic
type system
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
, and a
pluggable compiler
toolchain
A toolchain is a set of software development tools used to build and otherwise develop software. Often, the tools are executed sequentially and form a pipeline such that the output of one tool is the input for the next. Sometimes the term is us ...
. Mirah was created by Charles Oliver Nutter to be "a 'Ruby-like' language, probably a subset of Ruby syntax, that
ouldcompile to solid, fast, idiomatic
JVM
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descri ...
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normal ...
." The word ' refers to the gemstone
ruby
Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
in the
Javanese language
Javanese ( , , ; , Aksara Jawa, Javanese script: , Pegon script, Pegon: , IPA: ) is an Austronesian languages, Austronesian language spoken primarily by the Javanese people from the central and eastern parts of the island of Java, Indones ...
, a play on the concept of Ruby in Java.
History
To foster more participation in the
JRuby project from Ruby community members, Nutter began to explore the possibility of presenting Ruby syntax, but with a
static type
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
model and direct-to-native compiling. In this context, "native" meant mainly the
Java virtual machine
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descr ...
(JVM), but Mirah has been designed around the possibility of having alternative
backends for other object-oriented runtimes like the
Common Language Runtime
The Common Language Runtime (CLR), the virtual machine component of Microsoft .NET Framework, manages the execution of .NET programs. Just-in-time compilation converts the managed code (compiled intermediate language code) into machine instr ...
(CLR) of the
.NET Framework. The language needed to look and feel like Ruby, and to introduce no new library dependencies into JRuby (which precludes most other
JVM languages) and to suffer no performance penalty (which precludes writing in Ruby).
Early versions of Mirah (then Duby) focused mostly on mathematical performance, where
dynamic programming language
A dynamic programming language is a type of programming language that allows various operations to be determined and executed at runtime. This is different from the compilation phase. Key decisions about variables, method calls, or data types are ...
s often pay the highest cost. Since then it has evolved into a full JVM language, with several users and real-world applications using it for core components.
Design
Mirah is mostly a pluggable compiler toolchain. The main elements of the chain are:
# A
parser
Parsing, syntax analysis, or syntactic analysis is a process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar by breaking it into parts. The term '' ...
, based on JRuby's parser, that emits a Ruby
abstract syntax tree
An abstract syntax tree (AST) is a data structure used in computer science to represent the structure of a program or code snippet. It is a tree representation of the abstract syntactic structure of text (often source code) written in a formal ...
(AST)
# A transformer that converts the Ruby AST into a Mirah AST
# A type inferrer that decorates the Mirah AST with appropriate typing information for the target backend
# A backend
code generator
Of these phases, only the last two need specific knowledge of the eventual target platform. This makes Mirah suitable for many backends, and also makes it possible to write language
plug-ins 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 emits nearly the same instructions as standard
javac compilers.
No runtime library
Because Mirah is just a compiler, it ships no
standard library
In computer programming, a standard library is the library (computing), library made available across Programming language implementation, implementations of a programming language. Often, a standard library is specified by its associated program ...
. 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 refer to JVM classes, primitives, and interfaces.
Mirah is primarily a statically-typed language, but support is in development to allow dynamic typing also. The mechanism is similar to that provided in
C# 4, with a special ''dynamic'' type indicating all dispatches against that
variable'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 is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
, 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
, Mirah is under development, but some developers are using Mirah for production
applications
Application may refer to:
Mathematics and computing
* Application software, computer software designed to help the user to perform specific tasks
** Application layer, an abstraction layer that specifies protocols and interface methods used in a ...
of limited scope.
Frameworks
Dubious
Dubious is a project for running Mirah on
Google App Engine
Google App Engine (also referred to as GAE or App Engine) is a cloud computing platform used as a service for developing and hosting web applications. Applications are sandboxed and run across multiple Google-managed servers. GAE supports aut ...
. It provides a way to build apps in Mirah, with conventions familiar to developers using
Ruby on Rails
Ruby on Rails (simplified as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web pa ...
and
Sinatra. Since everything is
compiled ahead-of-time, Mirah applications have none of the
initializing costs associated with JRuby. Dubious supports
ERuby (ERb) and has a simple datastore adapter that uses a syntax similar to
Datamapper.
See also
*
List of JVM languages
This list of JVM languages comprises notable computer programming languages that are used to produce computer software that runs on the Java virtual machine (JVM). Some of these languages are interpreted by a Java program, and some are compiled ...
References
External links
* {{Official website, www.mirah.org
Introduction to Mirah by Charles Nutter- Dr. Dobb's, March 25, 2011
Breaking the Rules - Making Java Fun with Mirah- Roja Buck, Mar 20, 2011
A Blend of Java and Ruby - The Mirah Language- InfoQ, July 27, 2010
Mirah brings Ruby niceties to Java- InfoWorld. July 23, 2010
- O'Reilly Media, July, 2010
Introducing Duby, Ryan BrownDubious frameworkVideo presentation: JRuby, Duby, and Surinx: Building a Better RubyVideo Lightning talk: Rails Underground 2009 - Charles Nutter on Charles Nutter - Duby and Juby LanguagesWhat does Mirah offer over JRuby, Groovy and Scala?
JVM programming languages
Scripting languages
Object-oriented programming languages
Java programming language family
Software using the Apache license
Programming languages created in 2008
Statically typed programming languages