Primitive Types and Values
Grammar
literal ::= intnumber | floatnumber | "true" | "false"
int_type ::= "i8" | "i16" | "i32" | "i64" | "u8" | "u16" | "u32" | "u64"
float_type ::= "f16" | "f32" | "f64"
intnumber ::= (decimal | hexadecimal | binary) [int_type]
decimal ::= decdigit (decdigit |"_")*
hexadecimal ::= 0 ("x" | "X") hexdigit (hexdigit |"_")*
binary ::= 0 ("b" | "B") bindigit (bindigit | "_")*
floatnumber ::= (pointfloat | exponentfloat) [float_type]
pointfloat ::= [intpart] fraction
exponentfloat ::= (intpart | pointfloat) exponent
intpart ::= decdigit (decdigit |"_")*
fraction ::= "." decdigit (decdigit |"_")*
exponent ::= ("e" | "E") ["+" | "-"] decdigit+
decdigit ::= "0"..."9"
hexdigit ::= decdigit | "a"..."f" | "A"..."F"
bindigit ::= "0" | "1"
Description
Boolean literals are written true and false. The primitive types in Wyn are:
- Signed integer types:
i8,i16,i32,i64 - Unsigned integer types:
u8,u16,u32,u64 - Floating-point types:
f16,f32,f64 - Boolean type:
bool
Each primitive type name doubles as a polymorphic conversion
builtin: applied as T(value) it dispatches on value’s inferred
type to the corresponding per-type catalog entry. The vec shorthand
names (vec2i32, vec3f32, vec4u32, …) extend the same scheme to
vectors — vecNT(v) is componentwise. See Type Conversions below
for the full dispatch table and the dot-form T.source(value) compatibility syntax.
Numeric Literals
Numeric literals can be suffixed with their intended type. For example
42i8 is of type i8, and 1337e2f64 is of type f64. If no suffix
is given, the type of the literal will be inferred based on its use.
If the use is not constrained, integral literals will be assigned type
i32, and decimal literals type f32.
Integer formats:
- Decimal:
42,1000,42i8 - Hexadecimal:
0xFF,0x1A2B(prefixed with0x) - Binary:
0b1010,0b11110000(prefixed with0b)
Float formats:
- Decimal:
3.14,1.5e-10,2.0f32
Underscores may be used as digit separators in numeric literals for
readability (e.g., 1_000_000, 0xFF_FF_FF).
String Literals
Wyn has no first-class string type. A string literal ("...") is a
lexical token accepted only in two non-expression positions: the path
in import "..." and the linkage name in #[linked("...")]. Writing
a string where a value is expected is a syntax error.