Symbol table handles functions better

This commit is contained in:
greg 2018-06-03 02:39:49 -07:00
parent 856a360aba
commit 0b0f6b6b50
2 changed files with 20 additions and 3 deletions

View File

@ -274,7 +274,7 @@ impl<'a> State<'a> {
return Err(format!("This data constructor thing not done")) return Err(format!("This data constructor thing not done"))
} }
}, },
SymbolSpec::Func => match self.values.lookup(&name) { SymbolSpec::Func(_) => match self.values.lookup(&name) {
Some(Binding { val: Expr::Func(UserDefined { name, params, body }), .. }) => { Some(Binding { val: Expr::Func(UserDefined { name, params, body }), .. }) => {
Expr::Func(UserDefined { name: name.clone(), params: params.clone(), body: body.clone() }) Expr::Func(UserDefined { name: name.clone(), params: params.clone(), body: body.clone() })
}, },

View File

@ -4,6 +4,7 @@ use std::fmt;
use std::fmt::Write; use std::fmt::Write;
use parsing; use parsing;
use typechecking::TypeName;
//cf. p. 150 or so of Language Implementation Patterns //cf. p. 150 or so of Language Implementation Patterns
pub struct SymbolTable { pub struct SymbolTable {
@ -24,7 +25,7 @@ pub struct Symbol {
#[derive(Debug)] #[derive(Debug)]
pub enum SymbolSpec { pub enum SymbolSpec {
Func, Func(Vec<TypeName>),
DataConstructor { DataConstructor {
type_name: Rc<String>, type_name: Rc<String>,
type_args: Vec<Rc<String>>, type_args: Vec<Rc<String>>,
@ -41,9 +42,25 @@ impl SymbolTable {
if let Statement::Declaration(decl) = statement { if let Statement::Declaration(decl) = statement {
match decl { match decl {
FuncSig(signature) | FuncDecl(signature, _) => { FuncSig(signature) | FuncDecl(signature, _) => {
let mut ch: char = 'a';
let mut types = vec![];
for param in signature.params.iter() {
match param {
(_, Some(ty)) => {
//TODO eventually handle this case different
types.push(Rc::new(format!("{}", ch)));
ch = ((ch as u8) + 1) as char;
},
(_, None) => {
types.push(Rc::new(format!("{}", ch)));
ch = ((ch as u8) + 1) as char;
}
}
}
let spec = SymbolSpec::Func(types);
self.values.insert( self.values.insert(
signature.name.clone(), signature.name.clone(),
Symbol { name: signature.name.clone(), spec: SymbolSpec::Func } Symbol { name: signature.name.clone(), spec }
); );
}, },
TypeDecl(TypeSingletonName { name, params}, TypeBody(variants)) => { TypeDecl(TypeSingletonName { name, params}, TypeBody(variants)) => {