diff --git a/src/ast.rs b/src/ast.rs index d64d66e..4de0da3 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -66,6 +66,7 @@ pub enum Expr { Record(Option>, Vec<(Spanned, Box)>, Span), RefGet(Spanned>), RefSet(Spanned>, Box), + Seq(Box, Box), Typed(Box, TypeExpr), Variable(Spanned), } diff --git a/src/codegen.rs b/src/codegen.rs index cab75e2..0de5947 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -238,6 +238,11 @@ fn compile(ctx: &mut ModuleBuilder, expr: &ast::Expr) -> js::Expr { let rhs = compile(ctx, rhs_expr); js::assign(js::field(lhs, "$p".to_string()), rhs) } + ast::Expr::Seq(lhs_expr, rhs_expr) => { + let lhs = compile(ctx, lhs_expr); + let rhs = compile(ctx, rhs_expr); + js::comma_pair(lhs, rhs) + } ast::Expr::Typed(expr, _) => compile(ctx, expr), ast::Expr::Variable((name, _)) => ctx.bindings.get(name).unwrap().clone(), } diff --git a/src/grammar.lalr b/src/grammar.lalr index 5d5dcf2..293437a 100644 --- a/src/grammar.lalr +++ b/src/grammar.lalr @@ -222,9 +222,9 @@ NewRef: ast::Expr = { CallExpr = { RefExpr, - Call, - Case, - NewRef, + //Call, + //Case, + //NewRef, } ////////////////////////////////////////////////////////////////////// @@ -275,15 +275,15 @@ CmpOp: ast::Expr = { MultExpr = { CallExpr, - MultOp, + //MultOp, } AddExpr = { MultExpr, - AddOp, + //AddOp, } CompareExpr = { AddExpr, - CmpOp, + //CmpOp, } ////////////////////////////////////////////////////////////////////// @@ -296,22 +296,22 @@ LetPattern: ast::LetPattern = { => ast::LetPattern::Var(<>), "{" > "}" => ast::LetPattern::Record(<>), } -FuncSub = "fun" "->" >; +FuncSub = "fun" "->" >; FuncDef: ast::Expr = { Spanned => ast::Expr::FuncDef(<>), } If: ast::Expr = { - "if" >> "then" > "else" > => ast::Expr::If(<>), + "if" >> "then" > "else" > => ast::Expr::If(<>), } LetLHS = { - "let" "=" >, + "let" "=" >, } LetRHS = { - "in" >, + "in" >, } Let: ast::Expr = { => ast::Expr::Let(<>), @@ -346,12 +346,12 @@ Match: ast::Expr = { RefSet: ast::Expr = { - >> ":=" > => ast::Expr::RefSet(<>) + >> ":=" > => ast::Expr::RefSet(<>) } -Expr = { +NoSemiExpr = { CompareExpr, FuncDef, If, @@ -360,6 +360,10 @@ Expr = { Match, RefSet, } +Expr = { + > ";" > => ast::Expr::Seq(<>), + , +} ////////////////////////////////////////////////////////////////////// @@ -367,7 +371,7 @@ Expr = { TopLevelItem: ast::TopLevel = { => ast::TopLevel::LetDef(<>), => ast::TopLevel::LetRecDef(<>), - => ast::TopLevel::Expr(<>), + => ast::TopLevel::Expr(<>), } pub Script = { diff --git a/src/typeck.rs b/src/typeck.rs index 8af6f9e..bd4da51 100644 --- a/src/typeck.rs +++ b/src/typeck.rs @@ -532,6 +532,11 @@ fn check_expr(engine: &mut TypeCheckerCore, bindings: &mut Bindings, expr: &ast: engine.flow(lhs_type, bound)?; Ok(rhs_type) } + Seq(lhs_expr, rhs_expr) => { + let _lhs_type = check_expr(engine, bindings, lhs_expr)?; + let rhs_type = check_expr(engine, bindings, rhs_expr)?; + Ok(rhs_type) + } Typed(expr, sig) => { let expr_type = check_expr(engine, bindings, expr)?; let sig_type = parse_type_signature(engine, sig)?;