aboutsummaryrefslogtreecommitdiff

Micro Programming Language

Micro is a small statically typed toy programming language.

Objectives:

  • Learn and have fun
  • Build an interpreter
  • (may be) Build a cross-compiler targeting 8-bit microcomputers (Z80 CPU)
  • Easy to interact with existing libraries written in other languages
  • Fast compilation (compiler) / start-up time (interpreter)
  • Micro should be statically typed, small but useful, and reasonably performant (including on the target CPU)

Current status

There is a tree-walk interpreter built in Go mostly following the most excellent Crafting Interpreters book. It isn't fast, but it can be useful to test code and play around.

A compiler targeting the Z80 CPU was planned, and that is influencing what is available on the interpreter. Unfortunately this has proven to be more than I can currently tackle, so I'm releasing the interpreter "as is".

There's a plugin to provide syntax highlighting in vim. The proposed extension for Micro source code is .micro or .cro.

How to build

Micro requires Go 1.18 (or later) can be built with:

$ git clone https://git.usebox.net/micro-lang
$ cd micro-lang
$ make

micro binary should be in ./bin directory ready to use.

You can also browse the code via web.

Running the interpreter

Run a script with micro file.micro, or start the REPL with micro:

Welcome to Micro <VERSION>
Type in expressions for evaluation, or :q to exit.

micro> println("Hello micro!");
Hello micro!
13
micro> :q

Also run micro -h for the CLI help.

An example of a program:

def fib(n number) number {
    if n < 2 {
        return n;
    } else {
        return fib(n - 1) + fib(n - 2);
    }
}

println(fib(20));
// output: 6765

Check the tour for features and details about the language.

You can also read the grammar.

Copying

This software is distributed under MIT license, unless stated otherwise. See COPYING file for further details.