nanvm_lib/vm/impls/
debug.rs1use 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 let u: Unpacked<_> = self.clone().into();
10 u.fmt(f)
11 }
12}
13
14impl<A: IVm> Debug for Array<A> {
15 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
16 self.container_fmt('[', ']', f)
17 }
18}
19
20impl<A: IVm> Debug for Object<A> {
21 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
22 self.container_fmt('{', '}', f)
23 }
24}
25
26impl<A: IVm> Debug for Unpacked<A> {
27 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
28 match self {
29 Self::Nullish(x) => x.fmt(f),
30 Self::Boolean(x) => x.fmt(f),
31 Self::Number(x) => x.fmt(f),
32 Self::String(x) => x.fmt(f),
33 Self::BigInt(x) => x.fmt(f),
34 Self::Object(x) => x.fmt(f),
35 Self::Array(x) => x.fmt(f),
36 Self::Function(x) => x.fmt(f),
37 }
38 }
39}
40
41impl<A: IVm> Debug for Primitive<A> {
42 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
43 unpack(self).fmt(f)
44 }
45}
46
47impl<A: IVm> Debug for Numeric<A> {
48 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
49 unpack(self).fmt(f)
50 }
51}