From 1f6e6d9b3133925425777a111e0200ac13fd8b41 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 12 May 2018 12:56:39 -0700 Subject: [PATCH] Tuples --- schala-lang/src/ast_reducing.rs | 4 +++- schala-lang/src/eval.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/schala-lang/src/ast_reducing.rs b/schala-lang/src/ast_reducing.rs index f57d130..3fda49c 100644 --- a/schala-lang/src/ast_reducing.rs +++ b/schala-lang/src/ast_reducing.rs @@ -20,6 +20,7 @@ pub enum Stmt { pub enum Expr { Unit, Lit(Lit), + Tuple(Vec), Func(Func), Val(Rc), Call { @@ -88,7 +89,8 @@ impl Expression { f: Box::new(f.reduce()), args: arguments.iter().map(|arg| arg.reduce()).collect(), }, - e => Expr::UnimplementedSigilValue, + TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.reduce()).collect()), + _ => Expr::UnimplementedSigilValue, } } } diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 158f950..08e7177 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -298,6 +298,18 @@ impl Expr { UserDefined { name: None, .. } => format!(""), UserDefined { name: Some(name), .. } => format!("", name), }, + Expr::Tuple(exprs) => { + let mut buf = String::new(); + write!(buf, "(").unwrap(); + for term in exprs.iter().map(|e| Some(e)).intersperse(None) { + match term { + Some(e) => write!(buf, "{}", e.to_repl()).unwrap(), + None => write!(buf, ", ").unwrap(), + }; + } + write!(buf, ")").unwrap(); + buf + }, _ => format!("{:?}", self), } } @@ -343,6 +355,7 @@ impl<'a> State<'a> { }, Val(v) => self.value(v), func @ Func(_) => Ok(func), + Tuple(exprs) => Ok(Tuple(exprs.into_iter().map(|expr| self.expression(expr)).collect::,_>>()?)), Assign { box val, box expr } => { let name = match val { Expr::Val(name) => name,