From 0b0f6b6b50addf791e41c262cb8b37bc83816a89 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 3 Jun 2018 02:39:49 -0700 Subject: [PATCH] Symbol table handles functions better --- schala-lang/src/eval.rs | 2 +- schala-lang/src/symbol_table.rs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 24c27bd..83a322f 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -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() }) }, diff --git a/schala-lang/src/symbol_table.rs b/schala-lang/src/symbol_table.rs index 2af74e2..9d65b77 100644 --- a/schala-lang/src/symbol_table.rs +++ b/schala-lang/src/symbol_table.rs @@ -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), DataConstructor { type_name: Rc, type_args: Vec>, @@ -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)) => {