Pretty-print Symbol Table

This commit is contained in:
greg 2018-06-03 23:04:07 -07:00
parent 3beabf4678
commit 889610f0b0
2 changed files with 18 additions and 3 deletions

View File

@ -19,7 +19,6 @@ pub enum TConstOld {
Float,
StringT,
Bool,
Custom(String),
}
impl fmt::Display for Type {

View File

@ -23,6 +23,12 @@ pub struct Symbol {
pub spec: SymbolSpec,
}
impl fmt::Display for Symbol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "<Name: {}, Spec: {}>", self.name, self.spec)
}
}
#[derive(Debug)]
pub enum SymbolSpec {
Func(Vec<TypeName>),
@ -32,6 +38,16 @@ pub enum SymbolSpec {
},
}
impl fmt::Display for SymbolSpec {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::SymbolSpec::*;
match self {
Func(type_names) => write!(f, "Func({:?})", type_names),
DataConstructor { type_name, type_args } => write!(f, "DataConstructor({:?} -> {})", type_args, type_name),
}
}
}
impl SymbolTable {
/* note: this adds names for *forward reference* but doesn't actually create any types. solve that problem
* later */
@ -97,8 +113,8 @@ impl SymbolTable {
}
pub fn debug_symbol_table(&self) -> String {
let mut output = format!("Symbol table\n");
for (sym, ty) in &self.values {
write!(output, "{} -> {:?}\n", sym, ty).unwrap();
for (name, sym) in &self.values {
write!(output, "{} -> {}\n", name, sym).unwrap();
}
output
}