Types and values
Argon's types fall into scalars, collections, tuples, and layout types. Write types out in cell and function signatures: some can be inferred, but explicit signatures make call sites and error messages clearer.
Structs, enums, functions, and cells may take type parameters, written in angle brackets after the name: struct Pair<A, B>, fn last<T>(items: [T]) -> T. A type parameter stands for one type per use, which is inferred from the arguments, and a value of type T can only be stored, passed, and returned.
A struct groups values under named fields, written Size { w: 100., h: 50. } and read with . or taken apart with a pattern, as in let Size { w, h } = s; (see bindings). An enum is a fixed set of variants, each of which may carry a tuple payload or named fields of its own; see enums and match.
| Type | Example | Used for |
|---|---|---|
Float | 12., -0.5 | Coordinates, distances, and linear expressions |
Int | 12, -3 | Counts, indices, and discrete parameters |
Bool | true, false | Conditions and flags |
String | "met1" | Layer names and text |
Rect | rect("met1") | Rectangles, drawn or construction-only |
Polygon | polygon("met1", 3) | Polygons |
Path | path("met1", 2) | Paths with a width |
Point | shape.points[0] | A polygon or path vertex |
Inst | inst(child()) | A placed cell |
Signal | Signal() | A signal of a cell's schematic |
SchematicInst | std::schematic::inst(child()) | A cell placed in a schematic |
Device | device(DeviceKind::Res, signals(2), "", value=1.) | A device of a cell's schematic |
[T] | [Float] | A sequence of one type |
(A, B) | (3, 5) | A fixed-size tuple of mixed types |
Option<T> | Some(3), None | A value that may be absent |
Any | — | A value of any type |
() | () | The unit value and type |
The layout examples call rect, polygon, path, and inst from std::layout, imported with use std::layout::{inst, path, polygon, rect};. Signal is imported from std::schematic like any other item, with use std::schematic::Signal;, and is only a type name once imported.
Numeric literals
A decimal point or an exponent makes a literal a float:
let count = 50; // Int
let distance = 50.; // Float
let cap = 1e-12; // Float
let width = 2.5e3; // Float
An exponent is e or E, an optional sign, and digits, written with no spaces: 1e-12, 2.5e3, 1.0E+6. Write at least one digit after the decimal point before an exponent, since 1.e3 reads the field e3 of 1.
Geometry and constraints use Float. Counts and indices use Int.
Operators and casts
Arithmetic: +, -, *, /, and %. Comparison: ==, !=, <, <=, >, and >=.
Cast with as:
let offset = (index as Float) * pitch;
Sequences and tuples
Write a sequence as a bracketed list, index it with brackets, and walk it with head and tail.
let widths = [80., 120., 160.];
let first = widths[0];
let pair = (first, 3);
std::range makes an integer sequence for loops.