Skip to content

Finch 2.4.0: macOS, ARM64, methods, maps, errors as values

Choose a tag to compare

@Nexoniarz Nexoniarz released this 08 Oct 23:14
· 53 commits to main since this release

Finch now runs on macOS and ARM64, and gets three things real programs need: methods, maps and errors as values.

Platforms

  • macOS (Apple Silicon): finch-macos-arm64.tar.gz below (needs brew install llvm@21). Apple frameworks: import "OpenGL/gl.h", link "Cocoa.framework".
  • Linux ARM64 (Raspberry Pi 4/5, Graviton, …): finch-linux-arm64.tar.gz; also finch-linux-x64.tar.gz. Both need LLVM 21's libraries (libllvm21 libclang1-21 from apt.llvm.org).
  • C structs by value follow AAPCS64 on ARM64 (float aggregates in vector registers, Apple's variants included).
  • Cross-building: --target arm64 (runs with QEMU), --target macos, --target windows.
  • CI builds and tests everything natively on Linux x86-64, Linux ARM64, macOS ARM64 and Windows: 74 tests each.

Language

struct Counter {
    map[str]int counts
}

fn Counter.add(str word) {          // a method: self is the caller's Counter, not a copy
    self.counts[word] += 1          // a missing key starts at 0
}

fn parse_port(str s) -> int! {      // ! = can fail
    n := int(s) or { return error("not a number: " + s) }
    return n
}

fn main() -> ! {
    port := parse_port("80") or 8080
    text := try read_file("words.txt")
    ...
}
  • Methods: fn Point.move(int dx) { self.x += dx }, p.move(3); also on structs from C headers.
  • Maps: map[K]V, ["a": 1], m[k], has, get(k, default), remove, keys, values, for k, v in m; insertion order is kept.
  • Errors as values: -> T! / -> !, return error("..."), then or <value>, or { ... err ... } or try. Forgetting to handle a failure is a compile error. int(s), float(s), read_file, write_file, delete_file work with or / try too. fn main() -> ! prints the error and exits with 1.
  • for i, x in list; str(x) works for arrays, maps and structs (the same text print shows).
  • New example: examples/wordcount.fch.

Editors

  • Kate (and KWrite/KDevelop): highlighting and language server setup in editors/kate (install.sh).
  • The language server completes struct methods and map methods and shows method signatures.
  • VS Code extension 2.4.0 (finch-lang-2.4.0.vsix below): new highlighting and snippets.

Docs

All three guides (beginners, technicians, engineers) and the cheat sheets, in English and Polish, cover the new features and platforms.