use crate::{
analysis::symbols::{FnSymbol, LiteralSymbol, ModuleSymbol, StructSymbol},
exports::Struct,
runtime::{ComponentHint, PackageMeta, ScriptType, TypeFamily, TypeHint, TypeMeta},
semantics::Tag,
};
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct Description {
pub type_hint: TypeHint,
pub impl_symbol: ModuleSymbol,
pub doc: Option<&'static str>,
}
impl Description {
#[inline(always)]
pub(super) fn dynamic() -> Self {
let type_hint = TypeHint::dynamic();
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Nil,
doc,
}
}
#[inline(always)]
pub(super) fn nil() -> Self {
let type_hint = TypeHint::nil();
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Nil,
doc,
}
}
#[inline(always)]
pub(super) fn number_family(symbol: LiteralSymbol) -> Self {
let type_hint = TypeHint::Family(TypeFamily::number());
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Literal(symbol),
doc,
}
}
#[inline(always)]
pub(super) fn bool_type(symbol: LiteralSymbol) -> Self {
let type_hint = TypeHint::Type(<bool>::type_meta());
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Literal(symbol),
doc,
}
}
#[inline(always)]
pub(super) fn string_family(symbol: LiteralSymbol) -> Self {
let type_hint = TypeHint::Family(<str>::type_meta().family());
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Literal(symbol),
doc,
}
}
#[inline(always)]
pub(super) fn fn_family(symbol: FnSymbol) -> Self {
let type_hint = TypeHint::Family(TypeFamily::fn_family());
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Fn(symbol),
doc,
}
}
#[inline(always)]
pub(super) fn fn_type(arity: usize, symbol: FnSymbol) -> Self {
let Some(ty) = TypeMeta::script_fn(arity) else {
return Self::fn_family(symbol);
};
let type_hint = TypeHint::Type(ty);
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Fn(symbol),
doc,
}
}
#[inline(always)]
pub(super) fn struct_family(symbol: StructSymbol) -> Self {
let type_hint = TypeHint::Family(<Struct>::type_meta().family());
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Struct(symbol),
doc,
}
}
#[inline(always)]
pub(super) fn from_tag(tag: Tag) -> Self {
let type_hint = tag.type_hint();
let doc = type_hint.doc();
let impl_symbol = ModuleSymbol::from(tag);
Self {
type_hint,
impl_symbol,
doc,
}
}
#[inline(always)]
pub(super) fn from_component(component: &ComponentHint) -> Self {
let type_hint = component.ty;
let doc = component.doc.or(component.ty.doc());
Self {
type_hint,
impl_symbol: ModuleSymbol::Nil,
doc,
}
}
#[inline(always)]
pub(super) fn from_package(package: &'static PackageMeta) -> Self {
let type_hint = TypeHint::Type(package.ty());
let doc = type_hint.doc();
Self {
type_hint,
impl_symbol: ModuleSymbol::Nil,
doc,
}
}
}