From 821f3212616a18a40aa966a6c8d3f6b888ced829 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 5 Jan 2019 18:11:51 -0800 Subject: [PATCH] More Node-wrapping of Expression --- schala-lang/language/src/ast.rs | 2 +- schala-lang/language/src/parsing.rs | 7 ++++--- schala-lang/language/src/reduced_ast.rs | 2 +- schala-lang/language/src/typechecking.rs | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index aa6c322..9563387 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -120,7 +120,7 @@ pub enum ExpressionType { }, Call { f: Box, - arguments: Vec, + arguments: Vec>, }, Index { indexee: Box, diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index f30b39f..50613b4 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -607,6 +607,7 @@ impl Parser { let mut expr = self.index_expr()?; while let LParen = self.peek() { let arguments = delimited!(self, LParen, expression, Comma, RParen); + let arguments = arguments.into_iter().map(|s| Node::new(s)).collect(); expr = Expression(ExpressionType::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect } @@ -1296,7 +1297,7 @@ mod parse_tests { parse_test!("oi()", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] })])); parse_test!("oi(a, 2 + 2)", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), - arguments: vec![ex!(val!("a")), ex!(binexp!("+", NatLiteral(2), NatLiteral(2)))] + arguments: vec![ex!(val!("a")).into(), ex!(binexp!("+", NatLiteral(2), NatLiteral(2))).into()] })])); parse_error!("a(b,,c)"); @@ -1543,7 +1544,7 @@ fn a(x) { type_anno: None, body: vec![exst!(s "y")] } )), - arguments: vec![ex!(NatLiteral(1))] })])); + arguments: vec![ex!(NatLiteral(1)).into()] })])); parse_test_wrap_ast! { r#"\(x: Int): String { "q" }"#, @@ -1585,7 +1586,7 @@ fn a(x) { exst! { Call { f: bx!(ex!(Call { f: bx!(ex!(val!("wahoo"))), arguments: vec![] })), - arguments: vec![ex!(s "3")], + arguments: vec![ex!(s "3").into()], } } ]) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index ffa327e..854b353 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -140,7 +140,7 @@ impl Expression { }, Call { f, arguments } => Expr::Call { f: Box::new(f.reduce(symbol_table)), - args: arguments.iter().map(|arg| arg.reduce(symbol_table)).collect(), + args: arguments.iter().map(|arg| arg.node().reduce(symbol_table)).collect(), }, TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()), IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table), diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index a6925c9..c493735 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -166,7 +166,7 @@ impl<'a> TypeContext<'a> { IfExpression { discriminator, body } => self.infer_if_expr(discriminator, body)?, Call { f, arguments } => { let tf = self.infer_expr(f)?; //has to be an Arrow Type - let targ = self.infer_expr(&arguments[0])?; // TODO make this work with functions with more than one arg + let targ = self.infer_expr(&arguments[0].node())?; // TODO make this work with functions with more than one arg match tf { Type::Arrow(t1, t2) => { self.unify(&t1.to_tvar(), &targ.to_tvar())?;