DEV Community

Javier Leandro Arancibia
Javier Leandro Arancibia

Posted on

machin: make([]T, n) and make([]T, len, cap) for slices

A new machin release shipped, headlined by proper support for make([]T, n) and make([]T, len, cap). The slice implementation, AST, and codegen all learned the two- and three-argument forms, so you can preallocate a slice with an explicit length and an optional capacity the way you would in Go.

Alongside that, the router got a semantics pass and the coverage tooling got some rough edges filed off. The Windows target also picked up two C libraries that had been missing.

What changed

  • make([]T, n) and make([]T, len, cap) now work end to end (#584, #617). Touched SPEC.md, alias.go, ast.go, codegen.go, and docs/LANGUAGE.md.
  • Router semantics: unknown paths are now distinguishable. navigate returns -1 for unknown paths and the route table resets on init (#606, shipped as v0.130.0).
  • The upper bound of navigate is now guarded as well, and the new semantics are documented (#609).
  • machin test --cover is now advertised in the usage output and header (#615).
  • --cover JSON emits empty uncovered arrays instead of null (#616), so consumers don't have to special-case missing keys.
  • v0.129.0: SQLite on the Windows target, verified by running it (#605).
  • v0.131.0: zlib on the Windows target, verified by running it (#613).

A concrete example of the new slice allocation:

buf := make([]byte, 0, 4096)
rows := make([]string, n)
Enter fullscreen mode Exit fullscreen mode

The first form gives you a zero-length, 4096-capacity buffer for appending; the second gives you a length-n slice ready to index and assign. Both now go through the same codegen path as the rest of the slice machinery.

Nine files changed in this release (+292/-2), mostly in the language core and docs.

Repo: https://github.com/javimosch/machin

Top comments (0)