diff --git a/examples/wip.rs b/examples/wip.rs index 9f5ffa5ef612e36fb485f0e6a1419b2dac76a6c4..db7ffeddc7f84c3eccbcc5ca0bb07a5c942344e2 100644 --- a/examples/wip.rs +++ b/examples/wip.rs @@ -7,5 +7,5 @@ fn main() { } fn b(x: i32) -> i32 { - x; + x } diff --git a/src/ast.rs b/src/ast.rs index 8ee7334f8dffbdb45d8521cd3657b49a4f0ce53c..857e27218662247d41d4fae241e6b1a1387d7833 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -28,13 +28,11 @@ pub struct Stmts { #[derive(Debug, PartialEq, Clone)] pub enum Stmt { - // Id mut? (: Type)? (= Expr)? Let(Id, bool, Option<Type>, Option<Box<Expr>>), Assign(Box<Expr>, Box<Expr>), While(Box<Expr>, Stmts), If(Box<Expr>, Stmts, Option<Stmts>), Expr(Box<Expr>), - // perhaps block should be expression, hmm everything is expressions? Block(Stmts), Semi, } @@ -216,13 +214,13 @@ impl Stmts { fn ifmt(&self, fmt: &mut Formatter, indent: usize) -> Result<(), Error> { write!(fmt, "{{")?; let len = self.stmts.len(); - for (_i, s) in (&self.stmts).into_iter().enumerate() { + for (i, s) in (&self.stmts).into_iter().enumerate() { // set tab write!(fmt, "\n{}", " ".repeat(indent + 4))?; s.ifmt(fmt, indent + 4)?; - // if i < len - 1 || self.ret { - // write!(fmt, ";")?; - // } + if i < len - 1 || self.ret { + write!(fmt, ";")?; + } } write!(fmt, "\n{}}}", " ".repeat(indent)) } diff --git a/src/check.rs b/src/check.rs index 0941d757850275ba200740f3e0ff62e0957e0e5f..8870a42cd9d6f52b68f12e56172c1ccf6e43a5ff 100644 --- a/src/check.rs +++ b/src/check.rs @@ -441,7 +441,7 @@ pub fn check(p: &Program) -> Result<(), Error> { var_env.push_param_scope(arg_ty); let stmt_type = check_stmts(&fd.body, &fn_env, &type_env, &mut var_env); - trace!("result {}: {:?}", fd.id, &stmt_type); + trace!("result {}: {} {:?}", &fd.id, &fd.result, &stmt_type); let stmt_type = strip_mut(stmt_type?); diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index 3efe06252c9145d73d1825420f294f7517e61ca3..b978e1fd4b9dbff2f0628b8d3ffc499967e2f62f 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -15,13 +15,9 @@ match { // A comma separated sequence with optional trailing comma Comma<T>: Vec<T> = { - <v:(<T> ",")*> <e:T?> => match e { + <mut v:(<T> ",")*> <e:T?> => match e { None => v, - Some(e) => { - let mut v = v; - v.push(e); - v - } + Some(e) => { v.push(e); v }, } } @@ -32,16 +28,12 @@ CommaNoTrail<T>: Vec<T> = { // Parenthesized, comma delimeted ParCNT<T>: Vec<T> = { - "()" => Vec::new(), // seems like a hack? + "()" => Vec::new(), "(" <CommaNoTrail<T>> ")" => <>, } pub Path: Path = { - <h: (<Id> "::")+> <t: Id> => { - let mut h = h; - h.push(t); - Path(h) - } + <mut h: (<Id> "::")+> <t: Id> => { h.push(t); Path(h) } } // Type and FnDecl declarations may occur in any order. @@ -113,10 +105,7 @@ Params : Params = { Param : Param = { <is_mut: "mut"?> <id: Id> ":" <ty: Type> => Param { - is_mut: match is_mut { - Some(_) => true, - _ => false, - }, + is_mut: is_mut.is_some(), id, ty, }, @@ -134,14 +123,14 @@ Type : Type = { pub Block: Stmts = { "{" <mut stmts: StmtSeq*> <st: Stmt?> "}" => { match &st { - Some(st) => stmts.push(st.clone()), + Some(st) => stmts.push(st.clone()), _ =>(), }; Stmts { stmts, ret: match st { - Some(Stmt::Semi) => true, - _ => false + Some(_) => false, + _ => true, } } } diff --git a/tests/test_check.rs b/tests/test_check.rs index 57daf9c79866be54e774440e3ee2b485a8b0ad97..ce824c195dc247ff1c82929e4fb51f20635a3cac 100644 --- a/tests/test_check.rs +++ b/tests/test_check.rs @@ -177,5 +177,5 @@ fn check_let_if() { #[test] fn wip() { - let _ = check(&read_file::parse("examples/wip.rs")).is_ok(); + let _ = check(&read_file::parse("examples/wip.rs")).unwrap(); }