Builders and text

Rio never allocates memory while running, so builders have a fixed capacity, and a length that changes. [..N]T holds up to N:

Enemy :: struct
  x, hp: Int
end
enemies: [..64]Enemy
for i in 0..<3
  _ = enemies.push({x = i * 10, hp = 3})
end
for e in enemies
  e.hp -= 1
end
enemies.swapRemove(0)       # quick: the last one takes its place
log(enemies.len(), enemies[0].x, enemies.cap())
2 20 64

push gives false when the builder is full, and changes nothing. A proc that adds to a builder takes a builder view, [..]T, that pushes into the caller's builder:

spawn :: proc(out: [..]Int, n: Int)
  for i in 0..<n
    _ = out.push(i)
  end
end
xs: [..8]Int
spawn(xs, 3)
spawn(xs, 2)
log(xs.len(), xs[4])
5 1

Building text

A builder of bytes, Blob[..N], builds text. print appends values as log would show them, but without spaces:

line: Blob[..32]
hp := 7
_ = line.print("hp: ", hp, "/", 10)
_ = line.push('!')
log(line[])
hp: 7/10!

If it doesn't all fit, print changes nothing and gives false. format does the same, with settings for widths, digits and bases first (see format):

row: Blob[..32]
_ = row.format({width = 3}, 7, 42, 100)
log(row[])
  7 42100

Next: methods, enums, unions and maybes.