Language Tour
A single pass over every construct you will meet in real Vyne code.
This is the fast path through the language. Each section links to the full reference page.
Declarations and types
:= introduces a binding. = reassigns an existing one. Types are written after ::.
| Type | Example | Notes |
|---|---|---|
Int64 | 42, 0x7FFF_FFFF | 64-bit signed; hex and _ separators |
Float64 | 3.14, 1.0e3 | IEEE-754 double |
Float32 | 1.0f, 2f, float32(x) | first-class single precision |
String | "hello" | UTF-8, immutable |
Bool | true, false | |
Null | null | |
Array | [1, "two", 3.0] | heterogeneous, boxed |
Array<T> | Array<Float64> | typed, native ABI on the C backend |
Map | {"key": 42} | string keys |
Float32 is sticky: Float32 op Float32 stays Float32; mixing with Float64 or Int64 promotes to Float64. Typed arrays use 32-byte aligned payloads by default.
Operators
Ranges are inclusive. through is the canonical iteration construct:
The five modes are loop (side effects only), collect, filter, every, and unique. break and continue work in loop bodies.
Control flow
Loops and functions can carry executable contracts:
ruleset { contracts = "check" | "evidence" | "off" }; controls assertion lowering. A violation halts with VNE-111.
Functions and generics
Generic parameters are monomorphized: max_of<Int64>(3, 5) and max_of<Float64>(3.0, 5.0) produce two native C functions. Functions with primitive, typed-array, or registered-struct signatures also get an unboxed native variant.
Interfaces
An interface is both a struct declaration and its constructor. Methods close over the fields.
Struct-typed values participate in the native ABI: the caller and callee agree on a flat field layout, so a struct parameter expands to one C argument per field.
Groups and modules
group namespaces functions and constants without creating a type. module makes a built-in module available. use imports source files or external libraries.
use native selects a compiler-provided module. use external "path" resolves a library under vyne/modules/external/. Plain use "file.vy" imports a sibling source file.
Enums
Error handling
Exceptions are longjmp-based on the compiled backend and stack-unwound in the interpreter. The compiled runtime keeps a bounded frame stack (VYNE_MAX_EXC_FRAMES = 64).
Rulesets
A ruleset configures compile-time and runtime policy from the point it appears:
Regions
A region scopes arena lifetime lexically:
region carries at most one allocation, lifetime, or verification policy. Policies include @bounded<N>, @zeroed, @deterministic, @realtime<ms>, @pool<T, N>, @slab<T, MAX[, CAP]>, @ring<T, N, MAX>, @streamed<T, MAX>, @persistent, @speculative, and @device<backend>. Composition attributes include @layout<soa>, @backward, @recompute, and @mixed.
scratch lowers to a raw C array on the stack, not the arena. region.commit(x) deep-clones a value into the commit arena; region.move(x) relocates a large typed-array block in O(1); drop(x) releases an arena-tail payload early.
Automatic differentiation
grad(f, x) is the expression form. Scalar straight-line bodies and Array<Float64> reductions through the vstat/vlin kernels are supported; everything else is rejected with a stable VNE-12x diagnostic rather than being miscompiled. A custom adjoint can be registered as <fn>_vjp.
Devices
@device opens a device frame, runs the body, then releases device allocations before the host rewind. The CUDA driver backend JIT-compiles embedded PTX and falls back to CPU when CUDA is unavailable. device_alloc_f64 opts into double precision.
Arduino
The same region and scratch rules apply. On AVR the arena is 1 KB, checkpoints nest 16 deep, and out() is unavailable — use arduino.serial_print.