From 65bc32b0333f60acc11ebb178777f331a8d0aa37 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 9 Sep 2019 01:04:46 -0700 Subject: [PATCH] Fixed many of the broken tests --- schala-lang/language/src/eval/test.rs | 2 +- schala-lang/language/src/reduced_ast.rs | 1 + schala-lang/language/src/scope_resolution.rs | 48 +++++++++++++++----- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/schala-lang/language/src/eval/test.rs b/schala-lang/language/src/eval/test.rs index b72f7fa..07053d8 100644 --- a/schala-lang/language/src/eval/test.rs +++ b/schala-lang/language/src/eval/test.rs @@ -92,7 +92,7 @@ fn full_if_matching() { let source = r#" type Option = Some(T) | None let a = None -if a { is None -> 4, is Some(x) -> x } +if a { is Option::None -> 4, is Option::Some(x) -> x } "#; test_in_fresh_env!(source, "4"); diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index d001902..d9c9d60 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -371,6 +371,7 @@ impl Pattern { Ignored => Subpattern { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![] }, Literal(lit) => lit.to_subpattern(symbol_table), VarOrName(Meta { n: QualifiedName(vec), .. }) => { + println!("Calling VarOrName reduction with : {:?}", vec); //TODO this name needs to be resolved from metadata with context let name = if vec.len() == 1 { vec[0].clone() diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index 1734b9b..1a3a4e0 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -9,7 +9,6 @@ impl ScopeResolver { ScopeResolver { } } pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> { - println!("Resolving scopes - nothing so far!"); for statement in ast.0.iter_mut() { match statement.mut_node() { Statement::Declaration(ref mut decl) => self.decl(decl), @@ -20,11 +19,22 @@ impl ScopeResolver { } fn decl(&mut self, decl: &mut Declaration) -> Result<(), String> { + use Declaration::*; match decl { - Declaration::Binding { expr, .. } => self.expr(expr), + Binding { expr, .. } => self.expr(expr), + FuncDecl(_, block) => self.block(block), _ => Ok(()), } } + fn block(&mut self, block: &mut Block) -> Result<(), String> { + for statement in block.iter_mut() { + match statement.mut_node() { + Statement::Declaration(ref mut decl) => self.decl(decl), + Statement::ExpressionStatement(ref mut expr) => self.expr(expr), + }?; + } + Ok(()) + } fn expr(&mut self, expr: &mut Meta) -> Result<(), String> { use ExpressionKind::*; @@ -56,18 +66,32 @@ impl ScopeResolver { self.invoc(arg)?; } }, - IfExpression { ref mut body, .. } => match &mut **body { - IfExpressionBody::SimplePatternMatch(ref mut pat, _, _) => { - self.pattern(pat)?; - }, - IfExpressionBody::GuardList(guardarms) => { - for arm in guardarms.iter_mut() { - if let Guard::Pat(ref mut pat) = arm.guard { - self.pattern(pat)?; - } + Lambda { params, body, .. } => { + self.block(body)?; + for param in params.iter_mut() { + if let Some(ref mut expr) = param.default { + self.expr(expr)?; } } - _ => () + }, + IfExpression { ref mut body, ref mut discriminator } => { + match &mut **discriminator { + Discriminator::Simple(expr) | Discriminator::BinOp(expr, _) => self.expr(expr)? + }; + + match &mut **body { + IfExpressionBody::SimplePatternMatch(ref mut pat, _, _) => { + self.pattern(pat)?; + }, + IfExpressionBody::GuardList(guardarms) => { + for arm in guardarms.iter_mut() { + if let Guard::Pat(ref mut pat) = arm.guard { + self.pattern(pat)?; + } + } + } + _ => () + } }, _ => () };