← RustyIC10

RustyIC10

in progress

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

Language tour

Types

type notes
num 64-bit float (the only numeric type IC10 has)
bool true/false; convert with b as num, never automatically
Device a device port with no type: d0..d5, db
device types declared with device (e.g. GasSensor); every read and write is checked
structs struct S { a: num, mut b: bool }
enums enum VentMode { Outward, Inward = 1 }
arrays [num; 4], exist only at compile time

Nothing is converted automatically: if 1 {} and 1 + true are type errors.

Mutability

let x can't be changed after it's set; let mut x can. Struct fields are read-only unless declared mut. Parameters can be x: T, mut x: T (a local copy) or x: &mut T (changes are written back to the caller).

Devices

A device type lists the values you can read from a device (its "logic values"). mut marks the ones you can write:

device GasSensor("StructureGasSensor") {
    Pressure: num,
    Temperature: num,
    Combustion: bool,
    mut On: bool,
}

The compiler checks every access. With --aliases, device constants become alias lines, like in hand-written scripts:

alias sensor d0
alias heater d1
l r1 sensor Temperature
s heater On r0

Arrays

Arrays exist only at compile time. A for over an array is unrolled: the body is repeated once per element, and in each copy the element is a constant.

const TEMPS: [num; 4] = [273.15, 300, 320, 350];
for dev in [d0, d1, d2] { dev.On = true; }
db.Setting = TEMPS[1] + TEMPS.len;   // 300 + 4, folded

Slots and networks

Item slots, cable-network channels and a device's stack memory are typed too. So are batch reads, which reach every device of one type on the network at once: GasSensor::named("West").Temperature.avg.

The full reference is in the playground docs.