Symbol table handles functions better
This commit is contained in:
parent
856a360aba
commit
0b0f6b6b50
@ -274,7 +274,7 @@ impl<'a> State<'a> {
|
||||
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 }), .. }) => {
|
||||
Expr::Func(UserDefined { name: name.clone(), params: params.clone(), body: body.clone() })
|
||||
},
|
||||
|
@ -4,6 +4,7 @@ use std::fmt;
|
||||
use std::fmt::Write;
|
||||
|
||||
use parsing;
|
||||
use typechecking::TypeName;
|
||||
|
||||
//cf. p. 150 or so of Language Implementation Patterns
|
||||
pub struct SymbolTable {
|
||||
@ -24,7 +25,7 @@ pub struct Symbol {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SymbolSpec {
|
||||
Func,
|
||||
Func(Vec<TypeName>),
|
||||
DataConstructor {
|
||||
type_name: Rc<String>,
|
||||
type_args: Vec<Rc<String>>,
|
||||
@ -41,9 +42,25 @@ impl SymbolTable {
|
||||
if let Statement::Declaration(decl) = statement {
|
||||
match decl {
|
||||
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(
|
||||
signature.name.clone(),
|
||||
Symbol { name: signature.name.clone(), spec: SymbolSpec::Func }
|
||||
Symbol { name: signature.name.clone(), spec }
|
||||
);
|
||||
},
|
||||
TypeDecl(TypeSingletonName { name, params}, TypeBody(variants)) => {
|
||||
|
Loading…
Reference in New Issue
Block a user