//! returns: 0
//! An `Arena` initializer creates storage for growth, objects and the allocator view.

/// The allocation error, which the compiler knows.
@language union AllocError: Copy { OutOfMemory }

/// An arena, which holds elements of any type.
@language record Arena {}

/// Allocate the backing storage of a static heap.
@intrinsic constant fn new(size: u32) -> Arena;


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

/// A region of memory for growable slices.
static POOL: Arena = new(256);

/// Append through the allocator view.
fn push(xs: *mut [u32], v: u32, a: &Allocator) -> *mut [u32] throws (AllocError) {
    let mut ys = xs;
    try ys.append(v, a);
    return ys;
}

@default fn main() -> i32 {
    let mut xs: *mut [u32] = &mut [];
    try! xs.append(7, &POOL);
    try! xs.append(8, &POOL);
    assert xs.len == 2 and xs[0] == 7 and xs[1] == 8;
    let p = try! POOL.new(5 as u32);
    assert *p == 5;
    let ys = try! push(&mut [], 3, &POOL);
    assert ys.len == 1 and ys[0] == 3;
    return 0;
}
