Adam Parrott edited this page Jan 4, 2014 · 2 revisions

Design principles

Mirah's design is centered around a few simple principles:

  • Platform-agnostic implementation
  • Arbitrary typing system
  • Dynamic code generation

This means roughly similar scripts could conceivably compile to any number of type systems and runtimes. In this sense, Mirah is more of a rough coupling of Ruby-like syntax with a pluggable type-inference and compilation pipeline.

The following sections explain these principles in greater detail.

Platform-agnostic implementation

Mirah code has no inherent runtime dependency other than the libraries explicitly called from Mirah code. Currently, no other JVM language duplicates the aesthetic goals of Mirah without also introducing a runtime library (such as Mono or JRuby), often with a prohibitive file size.

Since Mirah contains no specific requirements on how code is to be executed, most Ruby syntax can be implemented on any platform using the execution primitives standard to that platform.

Type system

When compared to traditional strongly-typed languages such as Java, Mirah type declarations are often minimal in comparison, but not necessarily eliminated. To support this goal, Mirah provides local type inference by the typer, which provides most of the benefit of dynamic type inference without the much-higher complexity of full-system (e.g. Hindley-Milner) type inference.

(give brief type inference example)

Dynamic code generation

Every phase of the compilation pipeline should be pluggable, to the point that language enhancement becomes a simple matter of loading compiler plugins, rather than introducing unwanted syntax and libraries to support it (and in turn, the accompanying complexity and dependency hassle).

Because Ruby has a very flexible syntax already, syntax enhancements come in the form of special-casing method names, constant access, and similar improvements that compile to keyword-like behaviors. As a result, the Mirah parser is already considered complete — only AST (Abstract Syntax Tree) transformations are necessary to expand the language's capabilities.

(give brief macro example)

More information about this pluggable expansion system can be seen on our Macros page.


With these rough principles in mind, the project seeks to implement the following goals:

  • The compiler chain and all plugins should be written in Ruby, although there's no reason why they could not be (re)written in Mirah at some future date.

  • The syntax is largely Ruby-inspired, but only to the extent that the initial implementation based it's AST transformation on JRuby.

  • The type system is purely symbolic, with the compiler responsible for mapping symbolic types to a platform-appropriate representation.

While Mirah could be seen as a "Ruby with static types", Mirah is not Ruby: it does not share Ruby's type system, core classes, standard library, or even execution model, since none of these things are imposed upon Mirah programs by the Mirah language itself. Mirah is more a repurposing of Ruby's syntax into a flexible toolchain suitable for compiling to any number of type systems and runtimes with maximum performance.

For more information on real-world Mirah usage, including examples and tutorials, see our Getting Started page.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.