OxL Reference

15.1 comptime

  • A comptime fn is executed only at compile time; comptime { … } is a block evaluated at compile time; const is its result.
  • comptime code is deterministic: the effects io, net, db, time, rand are forbidden. Exceptions are comptime.readFile(path), comptime.embedDir(path) and comptime.template(path) (a path inside the package; the file is tracked in the incremental build).
  • comptime.embedDir("dir") is a List<(str, str, str, bytes, i64)>: for every file of the directory (the path below the directory with the separator /, the content type by extension from a fixed table, the ETag — a quoted hash string of the content (FNV-1a 64), the gzip-compressed content, the size before compression). Files are sorted by path (reproducibility), hidden files and directories (.name) are skipped. The directory is looked up relative to the source file, then from the nearest directory with oxl.toml; a missing directory or an unreadable file is a comptime-error (D-8054; D-7883).

Implementation-defined. comptime file operations (D-8054; D-7883). Of the exceptions of this section this implementation contains only comptime.embedDir; comptime.readFile and comptime.template are not implemented (optional). Embedded files are not tracked in the incremental build: the driver has no build cache yet (changing a file requires rebuilding the package).

  • Types are comptime values of type type: comptime fn sizeOf(T: type) -> usize.
  • inline for x in comptimeIterable { … } is unrolled at compile time.

comptime-error, not-comptime

See also

Source: docs/spec/oxl-standard.en.md