better debug impls for types, fix for simpletype key
This commit is contained in:
parent
5c38969ef8
commit
4432cf198e
|
@ -23,7 +23,7 @@ pub mod intern {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum SimpleType {
|
pub enum SimpleType {
|
||||||
F32,
|
F32 = 0,
|
||||||
F64,
|
F64,
|
||||||
Bool,
|
Bool,
|
||||||
Void,
|
Void,
|
||||||
|
@ -32,6 +32,21 @@ pub mod intern {
|
||||||
ComptimeInt,
|
ComptimeInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<u8> for SimpleType {
|
||||||
|
fn from(value: u8) -> Self {
|
||||||
|
match value {
|
||||||
|
0 => Self::F32,
|
||||||
|
1 => Self::F64,
|
||||||
|
2 => Self::Bool,
|
||||||
|
3 => Self::Void,
|
||||||
|
4 => Self::USize,
|
||||||
|
5 => Self::ISize,
|
||||||
|
6 => Self::ComptimeInt,
|
||||||
|
_ => panic!("{value} is not a simple type"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum Tag {
|
pub enum Tag {
|
||||||
String,
|
String,
|
||||||
|
@ -271,7 +286,6 @@ pub mod intern {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct InternPool {
|
pub struct InternPool {
|
||||||
tags: Vec<Tag>,
|
tags: Vec<Tag>,
|
||||||
indices: Vec<u32>,
|
indices: Vec<u32>,
|
||||||
|
@ -281,6 +295,32 @@ pub mod intern {
|
||||||
hashed: BTreeMap<u64, Index>,
|
hashed: BTreeMap<u64, Index>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for InternPool {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("InternPool")
|
||||||
|
.field_with("keys", |f| {
|
||||||
|
let mut list = f.debug_list();
|
||||||
|
|
||||||
|
let keys = (0..self.indices.len())
|
||||||
|
.map(|i| Index(i as u32))
|
||||||
|
.map(|idx| (idx, self.get_key(idx)));
|
||||||
|
for (idx, key) in keys {
|
||||||
|
list.entry_with(|f| write!(f, "{}: {key:?}", idx.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
list.finish()
|
||||||
|
})
|
||||||
|
.field_with("hashed", |f| {
|
||||||
|
let mut list = f.debug_list();
|
||||||
|
for (hash, idx) in self.hashed.iter() {
|
||||||
|
list.entry_with(|f| write!(f, "{hash}: {}", idx.0));
|
||||||
|
}
|
||||||
|
list.finish()
|
||||||
|
})
|
||||||
|
.finish_non_exhaustive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const STATIC_KEYS: [Key; 19] = [
|
const STATIC_KEYS: [Key; 19] = [
|
||||||
Key::SimpleType {
|
Key::SimpleType {
|
||||||
ty: SimpleType::Bool,
|
ty: SimpleType::Bool,
|
||||||
|
@ -694,7 +734,7 @@ pub mod intern {
|
||||||
Key::SIntType { bits }
|
Key::SIntType { bits }
|
||||||
}
|
}
|
||||||
Tag::SimpleType => {
|
Tag::SimpleType => {
|
||||||
let ty = self.words[item.idx()] as u8;
|
let ty = item.idx() as u8;
|
||||||
|
|
||||||
Key::SimpleType {
|
Key::SimpleType {
|
||||||
ty: unsafe { core::mem::transmute::<u8, SimpleType>(ty) },
|
ty: unsafe { core::mem::transmute::<u8, SimpleType>(ty) },
|
||||||
|
|
Loading…
Reference in a new issue