From c65907388d7d5d6928ef7908a45d5361ef6614ec Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 30 May 2018 23:54:24 -0700 Subject: [PATCH] Some ADT work --- schala-lang/src/eval.rs | 8 ++++++-- schala-lang/src/symbol_table.rs | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 76c41b5..24c27bd 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -267,8 +267,12 @@ impl<'a> State<'a> { let symbol_table = self.symbol_table_handle.borrow(); Ok(match symbol_table.values.get(&name) { Some(Symbol { name, spec }) => match spec { - SymbolSpec::Custom(_typename) => { - Expr::Lit(Lit::Custom(name.clone())) + SymbolSpec::DataConstructor { type_name, type_args } => { + if type_args.len() == 0 { + Expr::Lit(Lit::Custom(name.clone())) + } else { + return Err(format!("This data constructor thing not done")) + } }, SymbolSpec::Func => match self.values.lookup(&name) { Some(Binding { val: Expr::Func(UserDefined { name, params, body }), .. }) => { diff --git a/schala-lang/src/symbol_table.rs b/schala-lang/src/symbol_table.rs index 4aa9672..2af74e2 100644 --- a/schala-lang/src/symbol_table.rs +++ b/schala-lang/src/symbol_table.rs @@ -24,7 +24,11 @@ pub struct Symbol { #[derive(Debug)] pub enum SymbolSpec { - Func, Custom(String) + Func, + DataConstructor { + type_name: Rc, + type_args: Vec>, + }, } impl SymbolTable { @@ -42,14 +46,28 @@ impl SymbolTable { Symbol { name: signature.name.clone(), spec: SymbolSpec::Func } ); }, - TypeDecl(TypeSingletonName { name, ..}, TypeBody(variants)) => { + TypeDecl(TypeSingletonName { name, params}, TypeBody(variants)) => { for var in variants { match var { Variant::UnitStruct(variant_name) => { //TODO will have to make this a function to this type eventually - let spec = SymbolSpec::Custom(format!("{}", name)); + let spec = SymbolSpec::DataConstructor { + type_name: name.clone(), + type_args: vec![], + }; self.values.insert(variant_name.clone(), Symbol { name: variant_name.clone(), spec }); }, + Variant::TupleStruct(variant_name, tuple_members) => { + let type_args = vec![ + + ]; + let spec = SymbolSpec::DataConstructor { + type_name: name.clone(), + type_args + }; + let symbol = Symbol { name: variant_name.clone(), spec }; + self.values.insert(variant_name.clone(), symbol); + }, e => return Err(format!("{:?} not supported in typing yet", e)), } }