hare::types +linux +x86_64

hare::types provides an implementation of the Hare type system. See store to initialize a type store and lookup for looking up Hare types from their hare::ast representation.

Index

Types

type _enum;
type _struct;
type _type;
type alias;
type arch;
type array;
type builtin;
type flags;
type func;
type func_flags;
type pointer;
type pointer_flags;
type resolver;
type slice;
type struct_field;
type struct_union;
type tagged;
type tuple;
type tuple_value;
type variadism;

// Undocumented types:
type typestore;

Errors

type deferred;
type error;
type noresolver;

Constants

const SIZE_UNDEFINED: size;

// Undocumented constants:
const BUCKETS: size;

Globals

let aarch64: arch;
let builtin_bool: _type;
let builtin_char: _type;
let builtin_f32: _type;
let builtin_f64: _type;
let builtin_i16: _type;
let builtin_i32: _type;
let builtin_i64: _type;
let builtin_i8: _type;
let builtin_null: _type;
let builtin_rune: _type;
let builtin_u16: _type;
let builtin_u32: _type;
let builtin_u64: _type;
let builtin_u8: _type;
let builtin_void: _type;
let riscv64: arch;
let x86_64: arch;

Functions

fn dealias(*_type) const *_type;
fn hash(*_type) u32;
fn is_float(const *_type) bool;
fn is_integer(const *_type) bool;
fn is_signed(const *_type) bool;
fn lookup(*typestore, *ast::_type) (const *_type | deferred | error);
fn lookup_builtin(*typestore, ast::builtin_type) const *_type;
fn newalias(*typestore, const ast::ident, const *_type) const *_type;
fn store(arch, nullable *resolver, nullable *void) *typestore;
fn store_free(*typestore) void;
fn strerror(error) const str;

Types

type _enum[link]

type _enum = struct {
	storage: builtin,
	values: [](str, u64),
};

An enum type, e.g. enum { FOO = 0 }

type _struct[link]

type _struct = struct {
	kind: struct_union,
	fields: []struct_field,
};

struct { ... } or union { ... }

Note that embedded anonymous structs will have been merged into their parent type.

type _type[link]

type _type = struct {
	flags: flags,
	repr: (alias | array | builtin | _enum | func | pointer | slice |
	_struct | tagged | tuple),
	id: u32,
	sz: size,
	align: size,
};

A Hare type.

type alias[link]

type alias = struct {
	id: ast::ident,
	// null for forward referenced types
secondary: const nullable *_type, };

A type alias.

type arch[link]

type arch = struct {
	_int: size,
	_pointer: size,
	_size: size,
};

Configuration for a specific architecture.

type array[link]

type array = struct {
	// [[SIZE_UNDEFINED]] for [*]type
length: size, member: const *_type, };

An array type, e.g. [10]int

type builtin[link]

type builtin = enum u8 {
	BOOL,
	CHAR,
	F32,
	F64,
	FCONST,
	I16,
	I32,
	I64,
	I8,
	ICONST,
	INT,
	NULL,
	RUNE,
	SIZE,
	STR,
	U16,
	U32,
	U64,
	U8,
	UINT,
	UINTPTR,
	VALIST,
	VOID,

};

A built-in primitive type (int, bool, str, etc).

type flags[link]

type flags = enum u8 {
	NONE = 0,
	CONST = 1 << 0,
	ERROR = 1 << 1,

};

Flags for a Hare type.

type func[link]

type func = struct {
	result: const *_type,
	variadism: variadism,
	flags: func_flags,
	params: []const *_type,
};

A function type, e.g. fn(x: int, y: int) int

type func_flags[link]

type func_flags = enum uint {
	NONE = 0,
	NORETURN = 1 << 0,

};

Indicats if a func has the @noreturn attribute

type pointer[link]

type pointer = struct {
	referent: const *_type,
	flags: pointer_flags,
};

*int

type pointer_flags[link]

type pointer_flags = enum u8 {
	NONE = 0,
	NULLABLE = 1 << 0,

};

Flags which apply to a pointer type.

type resolver[link]

type resolver = fn(rstate: nullable *void, store: *typestore, expr: const *ast::expr) (size | deferred | error);

A function which evaluates a hare::ast::expr, providing either a size result or an error.

type slice[link]

type slice = const *_type;

[]int

type struct_field[link]

type struct_field = struct {
	// "" for an anonymous field
name: str, offs: size, _type: const *_type, };

A single struct field.

type struct_union[link]

type struct_union = enum {
	STRUCT,
	UNION,

};

Indicates if a _struct was declared as a struct or union type.

type tagged[link]

type tagged = []const *_type;

A tagged union type, e.g. (int | uint | void).

type tuple[link]

type tuple = []tuple_value;

A tuple type, e.g. (a, b, c)

type tuple_value[link]

type tuple_value = struct {
	offs: size,
	_type: const *_type,
};

A single value of a tuple type.

type variadism[link]

type variadism = enum {
	NONE,
	C,
	HARE,

};

Indicates the variadism of a func

type typestore[link]

Show undocumented member
type typestore = struct {
	// This hash map provides the canonical address for all types owned by
// this type store. Any type which has a reference to another type has
// borrowed it from this map.
map: [BUCKETS][]_type, arch: arch, resolve: nullable *resolver, rstate: nullable *void, };

Errors

type deferred[link]

type deferred = !void;

Returned from lookup when we are unable to resolve this type, but it does not necessarily have an error. This occurs when a type includes an unknown forward reference.

type error[link]

type error = !(noresolver | errors::opaque);

All possible errors for lookup.

type noresolver[link]

type noresolver = !void;

A resolver function was not provided to store, but was required to look up this type.

Constants

def SIZE_UNDEFINED[link]

def SIZE_UNDEFINED: size;

The sz field of _type is set to this value to indicate that the size of the type is undefined.

def BUCKETS[link]

Show undocumented member
def BUCKETS: size;

Globals

let aarch64[link]

const aarch64: arch;

arch configuration for aarch64.

let builtin_bool[link]

const builtin_bool: _type;

_type representation of bool.

let builtin_char[link]

const builtin_char: _type;

_type representation of char.

let builtin_f32[link]

const builtin_f32: _type;

_type representation of f32.

let builtin_f64[link]

const builtin_f64: _type;

_type representation of f64.

let builtin_i16[link]

const builtin_i16: _type;

_type representation of i16.

let builtin_i32[link]

const builtin_i32: _type;

_type representation of i32.

let builtin_i64[link]

const builtin_i64: _type;

_type representation of i64.

let builtin_i8[link]

const builtin_i8: _type;

_type representation of i8.

let builtin_null[link]

const builtin_null: _type;

_type representation of null.

let builtin_rune[link]

const builtin_rune: _type;

_type representation of rune.

let builtin_u16[link]

const builtin_u16: _type;

_type representation of u16.

let builtin_u32[link]

const builtin_u32: _type;

_type representation of u32.

let builtin_u64[link]

const builtin_u64: _type;

_type representation of u64.

let builtin_u8[link]

const builtin_u8: _type;

_type representation of u8.

let builtin_void[link]

const builtin_void: _type;

_type representation of void.

let riscv64[link]

const riscv64: arch;

arch configuration for riscv64.

let x86_64[link]

const x86_64: arch;

arch configuration for x86_64.

Functions

fn dealias[link]

fn dealias(t: *_type) const *_type;

Unwraps a type which may be aliased and returns the underlying type.

fn hash[link]

fn hash(t: *_type) u32;

Returns the hash of a type. These hashes are deterministic and universally unique: different computers will generate the same hash for the same type.

fn is_float[link]

fn is_float(ty: const *_type) bool;

Returns true if the given type is a floating-point type.

fn is_integer[link]

fn is_integer(ty: const *_type) bool;

Returns true if the given type is an integer type.

fn is_signed[link]

fn is_signed(ty: const *_type) bool;

Returns true if the given type is a signed type.

fn lookup[link]

fn lookup(store: *typestore, ty: *ast::_type) (const *_type | deferred | error);

Retrieves a _type for a given hare::ast::_type.

fn lookup_builtin[link]

fn lookup_builtin(store: *typestore, _type: ast::builtin_type) const *_type;

Looks up a built-in type.

fn newalias[link]

fn newalias(
	store: *typestore,
	ident: const ast::ident,
	of: const *_type,
) const *_type;

Creates a new type alias.

fn store[link]

fn store(
	arch: arch,
	resolver: nullable *resolver,
	rstate: nullable *void,
) *typestore;

Initializes a new type store. Optionally, provide a function which type-checks and evaluates an hare::ast::expr. If a resolver is not provided, looking up types with an expression component (e.g. [2 + 2]int) will return noresolver.

fn store_free[link]

fn store_free(store: *typestore) void;

Frees state associated with a typestore.

fn strerror[link]

fn strerror(err: error) const str;

Convert an error into a human-friendly string.