Skip to main content

nanvm_lib/vm/impls/
debug.rs

1use crate::vm::{
2    Any, Array, IVm, Object, Unpacked, container_fmt::ContainerFmt, impls::unpack,
3    numeric::Numeric, primitive::Primitive,
4};
5use core::fmt::{Debug, Formatter, Result};
6
7impl<A: IVm> Debug for Any<A> {
8    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
9        self.with_unpacked(|v| v.fmt(f))
10    }
11}
12
13impl<A: IVm> Debug for Array<A> {
14    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
15        self.container_fmt('[', ']', f)
16    }
17}
18
19impl<A: IVm> Debug for Object<A> {
20    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
21        self.container_fmt('{', '}', f)
22    }
23}
24
25impl<A: IVm> Debug for Unpacked<A> {
26    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
27        match self {
28            Self::Nullish(x) => x.fmt(f),
29            Self::Boolean(x) => x.fmt(f),
30            Self::Number(x) => x.fmt(f),
31            Self::String(x) => x.fmt(f),
32            Self::BigInt(x) => x.fmt(f),
33            Self::Object(x) => x.fmt(f),
34            Self::Array(x) => x.fmt(f),
35            Self::Function(x) => x.fmt(f),
36        }
37    }
38}
39
40impl<A: IVm> Debug for Primitive<A> {
41    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
42        unpack(self).fmt(f)
43    }
44}
45
46impl<A: IVm> Debug for Numeric<A> {
47    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
48        unpack(self).fmt(f)
49    }
50}