From 98cfcfc18dccd72e796a11f033750f81c72e8ada Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 15 May 2018 23:48:36 -0700 Subject: [PATCH] Eval shouldn't be aware of types --- schala-lang/src/eval.rs | 9 ++++----- schala-lang/src/typechecking.rs | 13 +++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 6581a1e..6643fc6 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -7,7 +7,7 @@ use itertools::Itertools; use util::StateStack; use ast_reducing::{ReducedAST, Stmt, Expr, Lit, Func}; -use typechecking::{TypeContext, Symbol, Type, TConst}; +use typechecking::{TypeContext, SymbolSpec, Symbol}; pub struct State<'a> { values: StateStack<'a, Rc, ValueEntry>, @@ -266,17 +266,16 @@ impl<'a> State<'a> { let type_context = self.type_context_handle.borrow(); Ok(match type_context.symbol_table.values.get(&name) { - Some(Symbol { name, ty }) => match ty { - Type::Const(TConst::Custom(_typename)) => { + Some(Symbol { name, spec }) => match spec { + SymbolSpec::Custom(_typename) => { Expr::Lit(Lit::Custom(name.clone())) }, - Type::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() }) }, _ => unreachable!(), }, - e => return Err(format!("Bad type in symbol table {:?}", e)) }, /* see if it's an ordinary variable TODO make variables go in symbol table */ None => match self.values.lookup(&name) { diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 3231d8b..e558e36 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -28,7 +28,12 @@ impl SymbolTable { #[derive(Debug)] pub struct Symbol { pub name: Rc, - pub ty: Type + pub spec: SymbolSpec, +} + +#[derive(Debug)] +pub enum SymbolSpec { + Func, Custom(String) } #[derive(Debug, PartialEq, Clone)] @@ -159,7 +164,7 @@ impl TypeContext { */ self.symbol_table.values.insert( signature.name.clone(), - Symbol { name: signature.name.clone(), ty: Func(Box::new(Void), Box::new(Void)) } + Symbol { name: signature.name.clone(), spec: SymbolSpec::Func } ); }, TypeDecl(TypeSingletonName { name, ..}, TypeBody(variants)) => { @@ -167,8 +172,8 @@ impl TypeContext { match var { Variant::UnitStruct(variant_name) => { //TODO will have to make this a function to this type eventually - let ty = Type::Const(TConst::Custom(format!("{}", name))); - self.symbol_table.values.insert(variant_name.clone(), Symbol { name: variant_name.clone(), ty }); + let spec = SymbolSpec::Custom(format!("{}", name)); + self.symbol_table.values.insert(variant_name.clone(), Symbol { name: variant_name.clone(), spec }); }, e => return Err(format!("{:?} not supported in typing yet", e)), }