Better debugging for types
This commit is contained in:
parent
1a74e16af5
commit
73206d345e
@ -1,6 +1,8 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::char;
|
use std::char;
|
||||||
|
use std::fmt;
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
use schala_lang::parsing;
|
use schala_lang::parsing;
|
||||||
|
|
||||||
@ -18,6 +20,19 @@ pub enum Type {
|
|||||||
Void
|
Void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Type {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use self::Type::*;
|
||||||
|
match self {
|
||||||
|
&Const(ref c) => write!(f, "{:?}", c),
|
||||||
|
&Func(ref a, ref b) => write!(f, "{} -> {}", a, b),
|
||||||
|
&UVar(ref s) => write!(f, "{}_u", s),
|
||||||
|
&EVar(ref n) => write!(f, "{}_e", n),
|
||||||
|
&Void => write!(f, "Void")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct UVarGenerator {
|
struct UVarGenerator {
|
||||||
n: u32,
|
n: u32,
|
||||||
@ -101,7 +116,11 @@ impl TypeContext {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn debug_symbol_table(&self) -> String {
|
pub fn debug_symbol_table(&self) -> String {
|
||||||
format!("Symbols: {:?}", self.bindings)
|
let mut output = format!("Symbols\n");
|
||||||
|
for (sym, ty) in &self.bindings {
|
||||||
|
write!(output, "{} : {}\n", sym, ty);
|
||||||
|
}
|
||||||
|
output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user