hare::types+x86_64 +linux

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 = struct {
	storage: builtin,
	values: [](str, u64),
};
type _struct = struct {
	kind: struct_union,
	fields: []struct_field,
};
type _type = struct {
	flags: flag,
	repr: (alias | array | builtin | _enum | func | pointer | slice | _struct | tagged | tuple),
	id: u32,
	sz: size,
	_align: size,
};
type alias = struct {
	id: ast::ident,
	// null for forward referenced types
	secondary: const nullable *_type,
};
type arch = struct {
	_int: size,
	_pointer: size,
	_size: size,
	valist_size: size,
	valist_align: size,
};
type array = struct {
	// [[SIZE_UNDEFINED]] for [*]type
	length: size,
	member: const *_type,
};
type builtin = enum u8 {
	BOOL,
	DONE,
	F32,
	F64,
	FCONST,
	I16,
	I32,
	I64,
	I8,
	ICONST,
	INT,
	NEVER,
	NULL,
	OPAQUE,
	RCONST,
	RUNE,
	SIZE,
	STR,
	U16,
	U32,
	U64,
	U8,
	UINT,
	UINTPTR,
	VALIST,
	VOID,
};
type flag = enum u8 {
	NONE = 0,
	CONST = 1 << 0,
	ERROR = 1 << 1,
};
type func = struct {
	result: const *_type,
	variadism: variadism,
	params: []const *_type,
};
type pointer = struct {
	referent: const *_type,
	flags: pointer_flag,
};
type pointer_flag = enum u8 {
	NONE = 0,
	NULLABLE = 1 << 0,
};
type resolver = fn(rstate: nullable *opaque, store: *typestore, expr: const *ast::expr) (size | deferred | error);
type slice = const *_type;
type struct_field = struct {
	// "" for an anonymous field
	name: str,
	offs: size,
	_type: const *_type,
};
type struct_union = enum {
	STRUCT,
	UNION,
};
type tagged = []const *_type;
type tuple = []tuple_value;
type tuple_value = struct {
	offs: size,
	_type: const *_type,
};
type variadism = enum {
	NONE,
	C,
	HARE,
};

// Undocumented types:
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 *opaque,
};

Errors

type deferred = !void;
type error = !(noresolver | errors::opaque_);
type noresolver = !void;

Constants

def SIZE_UNDEFINED: size = -1: size;

// Undocumented constants:
def BUCKETS: size = 65535;

Globals

const aarch64: arch;
const builtin_bool: _type;
const builtin_done: _type;
const builtin_f32: _type;
const builtin_f64: _type;
const builtin_i16: _type;
const builtin_i32: _type;
const builtin_i64: _type;
const builtin_i8: _type;
const builtin_never: _type;
const builtin_opaque: _type;
const builtin_rune: _type;
const builtin_u16: _type;
const builtin_u32: _type;
const builtin_u64: _type;
const builtin_u8: _type;
const builtin_void: _type;
const riscv64: arch;
const x86_64: arch;

Functions

fn dealias(t: *_type) const *_type;
fn hash(t: *_type) u32;
fn is_float(ty: const *_type) bool;
fn is_integer(ty: const *_type) bool;
fn is_signed(ty: const *_type) bool;
fn lookup(store: *typestore, ty: *ast::_type) (const *_type | deferred | error);
fn lookup_builtin(store: *typestore, _type: ast::builtin_type) const *_type;
fn newalias(store: *typestore, ident: const ast::ident, of: const *_type) const *_type;
fn store(arch: arch, resolver: nullable *resolver, rstate: nullable *opaque) *typestore;
fn store_free(store: *typestore) void;
fn strerror(err: 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: flag,
	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,
	valist_size: size,
	valist_align: 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,
	DONE,
	F32,
	F64,
	FCONST,
	I16,
	I32,
	I64,
	I8,
	ICONST,
	INT,
	NEVER,
	NULL,
	OPAQUE,
	RCONST,
	RUNE,
	SIZE,
	STR,
	U16,
	U32,
	U64,
	U8,
	UINT,
	UINTPTR,
	VALIST,
	VOID,
};

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

type flag[link]

type flag = 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,
	params: []const *_type,
};

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

type pointer[link]

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

*int

type pointer_flag[link]

type pointer_flag = enum u8 {
	NONE = 0,
	NULLABLE = 1 << 0,
};

Flags which apply to a pointer type.

type resolver[link]

type resolver = fn(rstate: nullable *opaque, 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 *opaque,
};

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 = -1: 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 = 65535;

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_done[link]

const builtin_done: _type;

_type representation of done.

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_never[link]

const builtin_never: _type;

_type representation of never.

let builtin_opaque[link]

const builtin_opaque: _type;

_type representation of opaque.

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 *opaque) *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.