← all projects

RustyIC10

in progress

A small Rust-like language that compiles to Stationeers' IC10 assembly.

Stationeers is a space base-building game. You automate your base by programming chips in IC10, a small assembly language with 16 registers and at most 128 lines per chip. It works, but a thermostat written by hand looks like this:

l r1 d0 Temperature
ble r1 294.65 6

RustyIC10 is a language with Rust-like syntax; its compiler, icr, turns it into IC10. Types are checked before the code runs. You get functions, structs, enums and typed devices, and the output is compact enough to fit in 128 lines.

const sensor: GasSensor = d0;
const heater: WallHeater = d1;

fn main() {
    let mut t = Thermostat { target: 293.15, heating: false };
    loop {
        update(&mut t, sensor.Temperature);
        heater.On = t.heating;
        yield();
    }
}

The whole program above compiles to 13 lines of IC10.

The playground

The playground above runs the real compiler in your browser, as WebAssembly. It has:

  • compilation as you type, with errors underlined and listed;
  • completion that knows your types: typing sensor. lists that device's values, marked read-only or writable;
  • go to definition (F12), including into the device libraries;
  • projects with several files: chips can share modules with use, and if you change a shared module you see right away which programs it breaks.

Your projects are saved in the browser's local storage.

Why typed devices?

In IC10, a device is just a numbered port. If you write to a read-only value or misspell a value's name, you only find out in the game. In RustyIC10, the device libraries describe every device in the game (about 800 items, generated from the game's data), so the compiler catches these mistakes:

const sensor: GasSensor = d0;
sensor.Temperature = 5;   // compile error: Temperature is read-only

For more, see the language tour or how the compiler works.