Mercurial > projects > dang
changeset 46:90fb4fdfefdd new_gen
While is back
author | Anders Halager <halager@gmail.com> |
---|---|
date | Wed, 23 Apr 2008 17:01:24 +0200 |
parents | 9bc660cbdbec |
children | b0a691727a0c |
files | ast/Stmt.d gen/LLVMGen.d parser/Action.d parser/Parser.d sema/Visitor.d |
diffstat | 5 files changed, 26 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ast/Stmt.d Wed Apr 23 16:43:42 2008 +0200 +++ b/ast/Stmt.d Wed Apr 23 17:01:24 2008 +0200 @@ -92,15 +92,15 @@ class WhileStmt : Stmt { - this(Exp cond, Stmt[] stmts) + this(Exp cond, Stmt stmts) { super(StmtType.While); this.cond = cond; - this.stmts = stmts; + this.whileBody = stmts; } Exp cond; - Stmt[] stmts; + Stmt whileBody; } class SwitchStmt : Stmt
--- a/gen/LLVMGen.d Wed Apr 23 16:43:42 2008 +0200 +++ b/gen/LLVMGen.d Wed Apr 23 17:01:24 2008 +0200 @@ -382,8 +382,7 @@ b.buildCondBr(cond, bodyBB, doneBB); b.positionAtEnd(bodyBB); - foreach (s; wStmt.stmts) - genStmt(s); + genStmt(wStmt.whileBody); if (b.getInsertBlock().terminated() is false) b.buildBr(condBB);
--- a/parser/Action.d Wed Apr 23 16:43:42 2008 +0200 +++ b/parser/Action.d Wed Apr 23 17:01:24 2008 +0200 @@ -138,6 +138,13 @@ return null; } + /** + */ + StmtT actOnWhileStmt(ref Token whileTok, ExprT cond, StmtT whileBody) + { + return null; + } + StmtT actOnStartOfSwitchStmt() { return null; @@ -258,6 +265,13 @@ return new IfStmt(c, t, e); } + override StmtT actOnWhileStmt(ref Token tok, ExprT cond, StmtT whileBody) + { + Exp c = cast(Exp)cond; + Stmt b = cast(Stmt)whileBody; + return new WhileStmt(c, b); + } + // -- Expressions -- override ExprT actOnNumericConstant(Token c) {
--- a/parser/Parser.d Wed Apr 23 16:43:42 2008 +0200 +++ b/parser/Parser.d Wed Apr 23 17:01:24 2008 +0200 @@ -82,7 +82,9 @@ { case Tok.Return: Token ret = lexer.next; - Exp exp = parseExpression(); + Exp exp; + if (lexer.peek.type != Tok.Seperator) + exp = parseExpression(); require(Tok.Seperator); return action.actOnReturnStmt(ret, exp); @@ -114,7 +116,10 @@ return action.actOnIfStmt(_if, cond, thenB, _else, elseB); case Tok.While: - return null; + Token _while = lexer.next; + Exp cond = parseExpression(); + Stmt bodyStmt = parseSingleOrCompoundStatement(); + return action.actOnWhileStmt(_while, cond, bodyStmt); case Tok.Identifier: return null;