Built with Calx: Calcite
Calcite is a Minecraft Java Edition server, and the largest program written in Calx so far. It's still in development. The official client can log in, walk around a flat world and chat.
A memory-safe compiled language whose programs give the same results on every machine.
Calx is pre-release, and you build it from source. It runs on Windows and Linux.
parallel for runs a loop's iterations on a pool of threads. The compiler rejects a loop in which one iteration changes data that another one uses, so the output doesn't depend on the number of threads.
main.calx:6:9: error: `total` is shared by every iteration of the `parallel for`, so it can't be changed here; an iteration can change only its own elements, indexed with `k` itself total += xs[k] ^~~~~ 1 error
struct Region { blocks: List<i32>, total: i64,}
fn tick(r: mut Region, scale: i32) { for i in 0usize..r.blocks.len() { r.blocks[i] = r.blocks[i] * scale + 1 r.total += i64(r.blocks[i]) }}
fn main() { var regions = List<Region>() for k in 0..16 { regions.push(Region { blocks: [k, k + 1, k + 2], total: 0 }) } let scale = 3 parallel for k in 0usize..regions.len() { tick(mut regions[k], scale) } println("{regions[0].total} {regions[15].total}")}struct cx_par_game__main_3_c { cx_list_game__Region* regions; cx_i32 scale; cx_u64 cx__lo; };static void cx_par_game__main_3(void* cx__v, cx_u64 cx__begin, cx_u64 cx__end) { struct cx_par_game__main_3_c* cx__c = (struct cx_par_game__main_3_c*)cx__v; cx_list_game__Region* restrict regions = cx__c->regions; CX_VIEW(regions); const cx_i32 scale = cx__c->scale; for (cx_u64 cx__i = cx__begin; cx__i < cx__end; cx__i++) { cx_usize k = (cx_usize)(cx__c->cx__lo + cx__i); game__tick(&(*regions).ptr[cx_index(k, (*regions).len, "game.calx:20:26")], scale); cx_cont3:; }}
// and in main, where the loop was:struct cx_par_game__main_3_c cx_t10 = {®ions, scale, (cx_u64)cx_t8};cx_parallel((cx_u64)cx_t9 - (cx_u64)cx_t8, cx_par_game__main_3, &cx_t10);12 147
Integer and float arithmetic gives the same bits on every platform, and floats print the same way too. The rules are Java's.
fn main() { let zero = 0.0 println("{0.1 + 0.2} {100.0} {1.0e7} {0.001} {1.0e-4}") println("{-zero} {1.0 / zero} {zero / zero}") println("{1.0f32 / 3.0f32} {f64(0.1f32)}")}0.30000000000000004 100.0 1.0E7 0.001 1.0E-4 -0.0 Infinity NaN 0.33333334 0.10000000149011612
Every value has one owner, and the compiler frees it where the owner ends. Using a value after it has moved is an error.
fn main() { let a = String("x") let b = a println("{a} {b}")}There are no warnings. Unused values, shadowing and silent conversions are errors, and no flag turns one off.
fn three() -> i32 { return 3}
fn main() { three() _ = three()}CI times the compiler on every push, on the same machine as the benchmark below.
| Windows | Linux | |
|---|---|---|
calx check, 64 modules (9,900 lines) | 32 ms | 24 ms |
| Debug build of those 64 modules, empty cache | 520 ms | 278 ms |
| Debug rebuild after changing one module | 123 ms | 78 ms |
calx run of a small program, empty cache | 274 ms | 302 ms |
calx run of it again, nothing changed | 16 ms | 21 ms |
We wrote the same simulation in Calx and in Rust, with the same algorithms. Both must produce the same checksum, and CI runs them on every push.
| Platform | Calx, 1 worker | Rust, 1 worker | Calx, 24 workers | Rust, 24 workers |
|---|---|---|---|---|
| Windows 11 | 18.06 | 25.75 | 2.25 | 3.41 |
| Linux (WSL2) | 18.01 | 26.04 | 2.46 | 3.52 |
The guide builds stash, a small program that keeps an inventory. Each page adds to it.
add stone 64 add stone 66 take stone 5 take dirt 20 show
line 4: there's no dirt stone: 1 stack and 61
Calcite is a Minecraft Java Edition server, and the largest program written in Calx so far. It's still in development. The official client can log in, walk around a flat world and chat.