mica

Crates.iomica
lib.rsmica
version0.7.1
sourcesrc
created_at2022-03-13 11:40:03.021211
updated_at2023-01-29 14:18:27.52682
descriptionA simple, user-friendly, embeddable scripting language
homepage
repositoryhttps://github.com/liquidev/mica
max_upload_size
id549177
size597,377
(liquidev)

documentation

README

Mica

Language reference Rust API GitHub crates.io

A simple, human-friendly scripting language, developed one feature at a time. Its goals are:

  • Human-friendly syntax inspired by Ruby and Lua
  • Simple and familiar to Rust developers feature-wise
  • Easily embeddable into existing programs
  • Better performance than most existing Rust scripting languages
# Hello, Mica!

struct Counter impl
    func new(start, increment) constructor = do
        @value = start
        @increment = increment
    end

    func value() = @value

    func increment() = do
        @value = @value + @increment
    end
end

c = Counter.new(1, 1)
while c.value < 100 do
    print(c.value)
    if c.value.mod(2) == 0 do
        print("even!")
    end
    c.increment()
end

At its current stage, it can be embedded into existing programs, but bugs may arise and certain parts may be cumbersome to use. The performance is also not even close to where I'd like it to be. But I want you to try it out and share your thoughts!

Try it out

To compile Mica, use one of the following commands:

# To install the latest stable release:
$ cargo install mica-cli
# To compile the latest revision:
$ git clone https://github.com/mica-lang/mica
$ cd mica
$ cargo build -p mica-cli --release

Then you can try it out interactively, or run a file:

# To open the REPL:
$ mica
# To run a file:
$ mica filename.mi

Check out the language reference for a detailed look at the language!

Why?

The Rust ecosystem has plenty of existing scripting languages, but none of them quite cuts it for me.

  • Lua is awesome, but I found mlua and rlua quite annoying to use due to their inability to bind most functions out of the box. You have to create wrapper functions that take giant tuples as arguments, which confuses the heck out of rustfmt, and is just plain inconvenient.
  • Rhai is nice feature-wise, but the AST-walk interpreter is very slow. A real waste of computer resources.
  • Dyon… exists, but it seems more like an experimenting ground for implementing language features rather than a language designed for end users.
  • Rune is by far the most promising, but even the author admits that performance isn't the primary goal right now.
  • And there's plenty more languages, though these seem like the most prominent ones as far as I could tell. I also ruled out weird and wacky (including FP) languages, because due to current processor architectures they're doomed to remain merely research projects. Also, imperative languages are the most widely taught ones by far.

There's also a number of unfinished crates with bindings for more niche scripting languages that are written in C, but, well, they're unfinished.

I wanted a language that would take performance seriously. Be designed with specific goals in mind. Sugary, but not quite sweet enough to give you instant diabetes. And handmade by myself.

Designing and implementing a programming language has been one of my arch nemeses for the past few years with varying levels of success, but I feel like finally, this is it. This time I'm gonna do it.

Commit count: 391

cargo fmt