Struct TypeRegistry

Source
pub struct TypeRegistry {
    types: HashMap<TypeId, TypeInfo>,
    function_type_cache: HashMap<FunctionType, TypeId>,
}
Expand description

Registry that stores all available types in the language

Fields§

§types: HashMap<TypeId, TypeInfo>

Map from TypeId to TypeInfo

§function_type_cache: HashMap<FunctionType, TypeId>

Map from function signatures to TypeIds for fast function type deduplication

Implementations§

Source§

impl TypeRegistry

Source

pub fn new_instance() -> Self

Creates a new TypeRegistry with built-in types registered.

Source

fn register_built_in_types(&mut self)

Registers all built-in types in the type registry

Source

pub fn register_type(&mut self, name: &str, kind: TypeKind) -> TypeId

Registers a new type in the registry

§Arguments
  • name - The name of the type
  • kind - The kind of the type (e.g., Integer, Float, etc.)
§Returns

A TypeId representing the newly registered type

Source

fn register_primitive_type(&mut self, name: &str, kind: TypeKind, id: TypeId)

Registers a primitive type in the registry

§Arguments
  • name - The name of the primitive type
  • kind - The kind of the primitive type (e.g., Integer, Float, etc.)
  • id - The TypeId for the primitive type
Source

pub fn get_type_info(&self, id: &TypeId) -> Option<&TypeInfo>

Gets type information for a given TypeId

§Arguments
  • id - The TypeId to look up
§Returns

An Option containing the TypeInfo if found, or None if not found

Source

pub fn get_primitive_type(&self, id: &TypeId) -> Option<PrimitiveType>

Try to get the primitive type for a given TypeId

§Arguments
  • id - The TypeId to look up
§Returns

An Option containing the PrimitiveType if found, or None if not found

Source

pub fn is_primitive_type(&self, id: &TypeId) -> bool

Check if a type is a primitive type

§Arguments
  • id - The TypeId to check
§Returns

A boolean indicating whether the type is a primitive type

Source

pub fn check_value_in_range(&self, value: &i64, type_id: &TypeId) -> bool

Checks if a value is within the valid range for a given type

§Arguments
  • value - The value to check
  • type_id - The TypeId of the type to check against
§Returns

A boolean indicating whether the value is within the valid range

Source

pub fn check_float_value_in_range(&self, value: &f64, type_id: &TypeId) -> bool

Checks if a float value is within the valid range for a given type

§Arguments
  • value - The float value to check
  • type_id - The TypeId of the type to check against
§Returns

A boolean indicating whether the float value is within the valid range

Source

pub fn register_function_type( &mut self, param_types: Vec<TypeId>, return_type: TypeId, ) -> TypeId

Registers a function type in the registry

§Arguments
  • param_types - The parameter types of the function
  • return_type - The return type of the function
§Returns

A TypeId representing the function type (either existing or newly registered)

Source

pub fn is_function_type(&self, id: &TypeId) -> bool

Checks if a type is a function type

§Arguments
  • id - The TypeId to check
§Returns

A boolean indicating whether the type is a function type

Source

pub fn get_function_type(&self, id: &TypeId) -> Option<&FunctionType>

Gets the function type information for a given TypeId

§Arguments
  • id - The TypeId to look up
§Returns

An Option containing the FunctionType if found, or None if not found or not a function

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.