//! A single object allocated through an allocator trait object passes the verifier.

/// The allocation error, which the compiler knows.
@language union AllocError: Copy {
    /// The heap is out of memory.
    OutOfMemory,
}

/// A heap, which holds elements of any type.
@language record Heap {}

/// The allocator view of a heap, which provides plain elements.
@language record Allocator {}

/// A plain record.
record Point: Copy {
    /// Horizontal coordinate.
    x: i32,
    /// Vertical coordinate.
    y: i32,
}

/// A record without bytes.
record Unit: Copy {}

/// Allocate a record.
fn makePoint(a: &Heap) -> *mut Point throws (AllocError) {
    return try a.new(Point { x: 1, y: 2 });
}

/// Allocate and write through the result.
fn makeNumber(a: &Heap, value: u64) -> *mut u64 throws (AllocError) {
    let mut number = try a.new(value);
    set *number = value + 1;
    return number;
}

/// Allocate an object without bytes.
fn makeUnit(a: &Heap) -> *mut Unit throws (AllocError) {
    return try a.new(Unit {});
}
