pub enum Type {
Show 28 variants
Any,
Void,
Bool,
U8,
I8,
U16,
I16,
U32,
I32,
U64,
I64,
F16,
F32,
F64,
Str,
Map,
List(Rc<Type>),
Iter,
Ident {
name: SmolStr,
params: Vec<Type>,
},
ConstInt(i64),
ConstBinary {
op: ConstIntOp,
left: Rc<Type>,
right: Rc<Type>,
},
Tuple(Vec<Type>),
Struct {
params: Vec<Type>,
fields: Vec<(SmolStr, Type)>,
},
Vec(Rc<Type>, u32),
Array(Rc<Type>, u32),
ArrayParam(Rc<Type>, Rc<Type>),
Fn {
tys: Vec<Type>,
ret: Rc<Type>,
},
Symbol {
id: u32,
params: Vec<Type>,
},
}Variants§
Any
Void
Bool
U8
I8
U16
I16
U32
I32
U64
I64
F16
F32
F64
Str
Map
List(Rc<Type>)
Iter
Ident
ConstInt(i64)
ConstBinary
Tuple(Vec<Type>)
Struct
Vec(Rc<Type>, u32)
Array(Rc<Type>, u32)
ArrayParam(Rc<Type>, Rc<Type>)
Fn
Symbol
Implementations§
Source§impl Type
impl Type
pub fn list_any() -> Self
pub fn align(&self) -> u32
pub fn storage_width(&self) -> u32
pub fn struct_layout(fields: &[(SmolStr, Type)]) -> (u32, Vec<u32>)
pub fn field_offset(&self, idx: usize) -> Option<u32>
pub fn len(&self) -> usize
pub fn compare_args(left: &[Type], right: &[Type]) -> Option<Vec<Type>>
pub fn force(&self, src: Dynamic) -> Result<Dynamic, DynamicErr>
pub fn width(&self) -> u32
pub fn is_void(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_str(&self) -> bool
pub fn is_native(&self) -> bool
pub fn is_any(&self) -> bool
pub fn is_ident(&self) -> bool
pub fn is_struct(&self) -> bool
pub fn get_field(&self, name: &str) -> Result<(usize, &Type)>
pub fn add_field(&mut self, name: SmolStr, ty: Type) -> Result<u32>
pub fn is_vec(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_uint(&self) -> bool
pub fn sign(self) -> Self
pub fn is_float(&self) -> bool
pub fn is_f64(&self) -> bool
pub fn is_f32(&self) -> bool
pub fn is_fn(&self) -> bool
pub fn from_args(args: Vec<(SmolStr, Type)>) -> (Self, Vec<SmolStr>)
Trait Implementations§
Source§impl Add for Type
两个类型相加得到的“公共类型“,也是 VM 里混合宽度算术结果类型的推断规则。
impl Add for Type
两个类型相加得到的“公共类型“,也是 VM 里混合宽度算术结果类型的推断规则。
优先级(从高到低):
- 完全相同的类型 → 自身;
- 任一为字符串 →
Str(支持任意 + 字符串拼接); - 任一为
Any→Any(动态值参与即退化为动态); - 任一为浮点 → 取较宽的浮点(有 f64 则 f64,否则 f32);
- 任一为有符号整数 → 取双方较大宽度的有符号整数(有符号优先于无符号);
- 任一为无符号整数 → 取双方较大宽度的无符号整数;
- 其它 →
Any。
注意:有符号在第 5 步先于无符号被处理,因此 i32 + u32 结果是 i32(按宽度,
不做无符号回绕检查)。宽度按 Type::width 计算。
impl Eq for Type
impl Send for Type
impl Sync for Type
Auto Trait Implementations§
impl Freeze for Type
impl RefUnwindSafe for Type
impl Unpin for Type
impl UnsafeUnpin for Type
impl UnwindSafe for Type
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.