Types
Cera’s type system is built around a single type keyword that defines a type — its fields, methods, and behavior. Where instances are stored — on the stack, the GC heap, or via raw pointers — is determined by how the type is used at the declaration site, not by the type definition itself.
Primitive Types
| Type | Size | Description |
|---|---|---|
int | 64-bit | Signed integer (default) |
int8, int16, int32, int64 | 8—64 bit | Sized signed integers |
uint8, uint16, uint32, uint64 | 8—64 bit | Unsigned integers |
float | 64-bit | Floating point (default) |
float32, float64 | 32—64 bit | Sized floats |
string | — | Immutable text |
char | 8-bit | Single byte character |
bool | — | true / false |
hash | 64-bit | Hash value (via (hash)value cast) |
User-Defined Types
The type keyword defines the field layout, methods, and behavior of a type:
type Point(int x, int y) { }
type Circle{ float radius; float Area() Math.PI * this.radius * this.radius;}See Type Definitions for constructors, destructors, inheritance, virtual methods, and full details.
Type Categories
The same type definition can be used in three ways at the declaration site:
| Declaration | Category | Storage | Lifetime |
|---|---|---|---|
Point p; | Value | Stack | Scope-based |
Point? p; / Point! p; | GC reference | Heap | Garbage collected |
Point* p; / Point& p; | Raw pointer | Heap (manual) | Manual delete* |
Point a; // value on the stackPoint! b = new Point(1, 2); // non-null GC reference on the heap
unsafe { Point* c = new* Point(3, 4); // raw pointer, manual lifetime delete* c;}Vtable pointers are added depending on the category and whether the type uses virtual dispatch:
- Values and raw pointers — a vtable pointer (8 bytes at offset 0) is only present when the type has
virtualorabstractmethods, or inherits from a type that does. Types without virtual methods have no vtable overhead. - GC references — always include a vtable pointer, even without virtual methods. The GC and reflection system use it for type identification.
See Type Definitions — Using Types for full memory layout details.
Arrays
| Syntax | Description |
|---|---|
T[] | Fixed-size array (value type) |
T[*] | Growable dynamic array |
See Arrays for full details.
Callable Types
Function signatures as types, used for callbacks and higher-order functions:
int(int, int) operation = Math.Add;See Callable Types for details.
Special Types
| Type | Description |
|---|---|
object | Universal GC reference — auto-boxes value types |
dyn | Dynamic dispatch — resolves fields and methods at runtime |
void | No value |
See Object and Dyn for details.
Type Checks and Casts
if (value is int) { /* ... */ }
int n = value as int;
switch type (value){ case int i: Console.WriteLine($"{i}"); break; case string s: Console.WriteLine(s); break;}See Pattern Matching for more patterns.
Related Pages
- Type Definitions — defining types, inheritance, vtables, memory layout
- Interfaces — interface contracts and implementation
- Templates — generic type and value parameters
- Immutability —
constandimmut - Raw Pointers — unsafe manual memory
- Safe Navigation —
?.and??operators