hare::types
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;
type typestore;
Errors
type deferred;
type error;
type noresolver;
Constants
const SIZE_UNDEFINED: size;
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
type _enum = struct {
storage: builtin,
values: [](str, u64),
};
An enum type, e.g. enum { FOO = 0 }
type _struct
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
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
type alias = struct {
id: ast::ident,
secondary: const nullable *_type,
};
A type alias.
type arch
type arch = struct {
_int: size,
_pointer: size,
_size: size,
};
Configuration for a specific architecture.
type array
type array = struct {
length: size,
member: const *_type,
};
An array type, e.g. [10]int
type builtin
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
type flags = enum u8 {
NONE = 0,
CONST = 1 << 0,
ERROR = 1 << 1,
};
Flags for a Hare type.
type func
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
type func_flags = enum uint {
NONE = 0,
NORETURN = 1 << 0,
};
Indicats if a func has the @noreturn attribute
type pointer
type pointer = struct {
referent: const *_type,
flags: pointer_flags,
};
*int
type pointer_flags
type pointer_flags = enum u8 {
NONE = 0,
NULLABLE = 1 << 0,
};
Flags which apply to a pointer type.
type resolver
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
type slice = const *_type;
[]int
type struct_field
type struct_field = struct {
name: str,
offs: size,
_type: const *_type,
};
A single struct field.
type struct_union
type struct_union = enum {
STRUCT,
UNION,
};
Indicates if a _struct was declared as a struct or union type.
type tagged
type tagged = []const *_type;
A tagged union type, e.g. (int | uint | void).
type tuple
type tuple = []tuple_value;
A tuple type, e.g. (a, b, c)
type tuple_value
type tuple_value = struct {
offs: size,
_type: const *_type,
};
A single value of a tuple type.
type variadism
type variadism = enum {
NONE,
C,
HARE,
};
Indicates the variadism of a func
type typestore
Show undocumented member
type typestore = struct {
map: [BUCKETS][]_type,
arch: arch,
resolve: nullable *resolver,
rstate: nullable *void,
};
Errors
type deferred
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
type error = !(noresolver | errors::opaque);
All possible errors for lookup.
type noresolver
type noresolver = !void;
A resolver function was not provided to store, but was required to look
up this type.
Constants
def SIZE_UNDEFINED
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
Show undocumented member
def BUCKETS: size;
Globals
let aarch64
const aarch64: arch;
arch configuration for aarch64.
let builtin_bool
const builtin_bool: _type;
_type representation of bool.
let builtin_char
const builtin_char: _type;
_type representation of char.
let builtin_f32
const builtin_f32: _type;
_type representation of f32.
let builtin_f64
const builtin_f64: _type;
_type representation of f64.
let builtin_i16
const builtin_i16: _type;
_type representation of i16.
let builtin_i32
const builtin_i32: _type;
_type representation of i32.
let builtin_i64
const builtin_i64: _type;
_type representation of i64.
let builtin_i8
const builtin_i8: _type;
_type representation of i8.
let builtin_null
const builtin_null: _type;
_type representation of null.
let builtin_rune
const builtin_rune: _type;
_type representation of rune.
let builtin_u16
const builtin_u16: _type;
_type representation of u16.
let builtin_u32
const builtin_u32: _type;
_type representation of u32.
let builtin_u64
const builtin_u64: _type;
_type representation of u64.
let builtin_u8
const builtin_u8: _type;
_type representation of u8.
let builtin_void
const builtin_void: _type;
_type representation of void.
let riscv64
const riscv64: arch;
arch configuration for riscv64.
let x86_64
const x86_64: arch;
arch configuration for x86_64.
Functions
fn dealias
fn dealias(t: *_type) const *_type;
Unwraps a type which may be aliased and returns the underlying type.
fn hash
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
fn is_float(ty: const *_type) bool;
Returns true if the given type is a floating-point type.
fn is_integer
fn is_integer(ty: const *_type) bool;
Returns true if the given type is an integer type.
fn is_signed
fn is_signed(ty: const *_type) bool;
Returns true if the given type is a signed type.
fn lookup
fn lookup(store: *typestore, ty: *ast::_type) (const *_type | deferred | error);
Retrieves a _type for a given hare::ast::_type.
fn lookup_builtin
fn lookup_builtin(store: *typestore, _type: ast::builtin_type) const *_type;
Looks up a built-in type.
fn newalias
fn newalias(
store: *typestore,
ident: const ast::ident,
of: const *_type,
) const *_type;
Creates a new type alias.
fn store
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
fn store_free(store: *typestore) void;
Frees state associated with a typestore.
fn strerror
fn strerror(err: error) const str;
Convert an error into a human-friendly string.