Type#
- class rbc.typesystem.Type(*args, **params)#
Represents a type.
There are six kinds of a types:
Type
Description
Internal structure
void
a “no type”
Type()
atomic
e.g.
int32
Type(<str>,)
pointer
e.g.
int32*
Type(<Type instance>, ‘*’)
struct
e.g.
{int32, int32}
Type(<Type instances>, <Type instances>, …)
function
e.g.
int32(int32, int32)
Type(<Type instance>, …, name=’’)
custom
e.g.
MyClass<int32, int32>
Type((<object>,))
undefined
e.g.
fromcallable(foo)
Type(None)
Atomic types are types with names (Type contains a single string). All other types (except “no type”) are certain implementations of atomic types.
The name content of an atomic type is arbitrary but it cannot be empty. For instance, Type(‘a’) and Type(‘a long name’) are atomic types.
Parsing types from a string is not fixed to any type system, the names of types can be arbitrary. However, converting the Type instances to concrete types such as provided in numpy or numba, the following atomic types are defined (the first name corresponds to normalized name):
no type: void, none bool: bool, boolean, _Bool, b 1-bit bool: bool1, boolean1, b1 8-bit bool: bool8, boolean8, b8 8-bit char: char8, char 16-bit char: char16 32-bit char: char32, wchar 8-bit signed integer: int8, i8, byte, signed char 16-bit signed integer: int16, i16, int16_t 32-bit signed integer: int32, i32, int32_t 64-bit signed integer: int64, i64, int64_t 128-bit signed integer: int128, i128, int128_t 8-bit unsigned integer: uint8, u8, ubyte, unsigned char 16-bit unsigned integer: uint16, u16, uint16_t 32-bit unsigned integer: uint32, u32, uint32_t 64-bit unsigned integer: uint64, u64, uint64_t 128-bit unsigned integer: uint128, u128, uint64_t 16-bit float: float16, f16 32-bit float: float32, f32, float 64-bit float: float64, f64, double 128-bit float: float128, f128, long double 32-bit complex: complex32, c32, complex 64-bit complex: complex64, c64 128-bit complex: complex128, c128 256-bit complex: complex256, c256 string: string, str
with the following extensions:
N-bit signed integer: int<N>, i<N> for instance: int5, i31 N-bit unsigned integer: uint<N>, u<N> N-bit float: float<N> N-bit complex: complex<N>
Also
byte, short, int, long, long long, signed int, size_t, ssize_t
, etc are supported but their normalized names are system dependent.The typesystem supports processing custom types that are usually named structures or C++ template specifications, but not only.
Custom type can have arbitrary number of (hashable) parameters. A custom type is concrete when the parameters with type Type are concrete.
Custom types must implement tonumba method if needed. For that, one must derive MyClass from Type.
Internally, a custom type has two possible representations: if MyClass is derived from Type then MyClass<a, b> is represented as MyClass((‘a’, ‘b’)), otherwise, it is represented as Type((‘MyClass’, ‘a’, ‘b’)). If the parameters of a custom types need to be Type instances, use preprocess_args for required conversion of arguments.
Attributes
Return the list of consumed argument types.
Return the arity of the function type.
Return the argument types that the given type will consume.
Return the number of arguments that the given type consumes.
Return True when the Type instance does not contain unknown types.
Return True when the Type instance is concrete.
Return declarator name.
Methods
Type.annotation
(**annotations)Set and get annotations.
Type.apply_templates
(templates)Iterator of concrete types derived from applying templates mapping to self.
Type.copy
([cls])Return a copy of type.
Type.count
(value, /)Return number of occurrences of value.
Type.fromcallable
(func)Return new Type instance from a callable object.
Return new Type instance from ctypes type object.
Return new Type instance from numba type object.
Return new Type instance from numpy type object.
Type.fromobject
(obj)Return new Type instance from any object.
Return new Type instance from a string.
Type.fromvalue
(obj)Return Type instance that corresponds to given value.
Type.get_field_position
(name)Return the index of a structure member with name.
Type.index
(value[, start, stop])Return first index of value.
Type.inherit_annotations
(other)Return mangled type string.
Type.match
(other)Return match penalty when other can be converted to self.
Type.params
([other])In-place update of parameters from other or/and dictionary and return self.
Postprocess Type construction.
Type.preprocess_args
(args)Preprocess the arguments of Type constructor.
Type.set_mangling
(mangling)Set mangling string of the type.
Convert Type instance to ctypes type object.
Type.tollvmir
([bool_is_int8])Type.tonumba
([bool_is_int8])Convert Type instance to numba type object.
Type.tostring
([use_typename, ...])Return string representation of a type.