Limits and memory

The compiler rejects code it cannot handle safely instead of crashing:

  • blocks and expressions may nest at most 200 levels deep, counting each if, loop body, parenthesis, and unary operator;
  • one expression may hold at most 1000 nested operations, such as the terms of a long + chain;
  • integer literals must fit in an i64, so the largest is 9223372036854775807.

Every array index and string position is checked, every field access checks for null, and values are always initialized, so a Cuarzo program cannot read or write outside of its data. Unbounded recursion is stopped with a runtime error before the native stack overflows, rather than crashing. A program's stack is 8 MB on every system (on Linux and macOS, as the system sets it; on Windows, as cuarzo build links it).

A runtime error prints its message, then where the program was: the line in each function that was running, innermost first, ending with the line of the program body. A function that keeps calling itself is shown once, and a long chain shows its first twelve calls and the program body:

Cuarzo runtime error: division by zero
    at stats.cz:5 in ratio
    at stats.cz:17 in a function written with =>
    at stats.cz:11 in each
    at stats.cz:21

The program then exits with status 1.

Strings, arrays, maps, structs, enum values that carry values, and function values are reclaimed automatically by a garbage collector once nothing refers to them, so the memory a program uses tracks the data it is actually holding, not the total it has ever created. Building large text still allocates less with join than with repeated +=, but neither leaks. The collector can be turned off or bounded with command-line options; see the architecture guide and cuarzo help. It runs when the program has allocated as much again as it held after the last collection; collect_garbage() runs it at once, as a program may while it is idle, so a collection is less likely to fall in the middle of work that should be quick.