Pointers & Slices

Pointer types

TypeMeaning
*TMutable pointer to T (nullable)
*!TNon-null mutable pointer to T
*const TImmutable pointer to T

Taking an address

tape
var x: i64 = 42;
let ptr: *i64 = &x;

Dereferencing

tape
let val: i64 = *ptr;
*ptr = 100;

Dereference uses prefix * (same as C).

Arrays

Fixed-size, stack-allocated:

tape
let nums: [4]i64 = [1, 2, 3, 4];
let first = nums[0];
let count = nums.len;  // compile-time constant: 4

Slices

Bounded view into contiguous memory (pointer + length):

tape
var slice: []i64 = nums[1..3];  // elements at index 1, 2
let len = slice.len;
let full: []i64 = nums[..];    // full array as slice
TypeMeaning
[]TMutable slice
[]const TRead-only slice

Pointer arithmetic (t0/t1)

tape
var p: *u8 = &buffer;
let next: *u8 = (p as i64 + 1) as *u8;  // byte-level offset

Pointer arithmetic is done via casting to i64, adding the byte offset, and casting back. There is no automatic sizeof scaling.

Null checking

tape
let p: *i64 = get_maybe_null();
if (p != null) {
    io.print_i64(*p);
}

Non-null pointers

Not yet implemented*!T and *const T are recognized in type declarations but not yet enforced — the typechecker does not reject null assignments to *!T or writes through *const T.
tape
fn process(data: *!u8) {
    // guaranteed non-null — no check needed
}

Last modified: