aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: b7bda3fd5292f4b885414f539331f3a3659b1885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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](https://craftinginterpreters.com/) 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 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](https://git.usebox.net/micro-lang.git/about/).

### 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:

```micro
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](docs/tour.md) for features and details about the language.

You can also read [the grammar](grammar.md).

## Copying

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