1. Programs
A program is a root file plus the files it imports (section 16). A file
holds, in any order, functions, type declarations (const Name = struct /
enum / union(enum) { ... }), type aliases (const Name = T), imports (const m = @import("m.egg")) and
uses lines naming the capabilities it needs (section 17). Every function
can call every other function of its file, including itself.
The root file must have a function main returning void, i64 or
!void, whose parameters are only capability values, each type at most
once: fn main(), fn main(io: Io), fn main(io: Io, a: Allocator)
(E109). The runtime creates them; they are the only source of
capabilities. When main returns i64, the value becomes the process exit
status (the operating system keeps only the low bits, usually 8). When it
returns an error, the program prints error: Name to standard error and
exits with status 1.
Most examples below print, so they start with uses io and take
io: Io.
// expect: 3
uses io
fn main(io: Io) void {
io.print(add(1, 2)) // add is declared below; order does not matter
}
fn add(a: i64, b: i64) i64 {
return a + b
}