scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 2891a62c9bcfcd4c3e9b396490245249d8e64bcb
parent a8acad8243a648e895baebf39b5672b8209a30c6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 28 Aug 2012 20:46:22 +0200

Added tree structure for return

Diffstat:
Mflow.c | 15++++++++++++++-
Msyntax.h | 3++-
Mtree.c | 1+
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/flow.c b/flow.c @@ -175,6 +175,19 @@ _continue(void) } static struct node * +_return(void) +{ + register struct node *np; + extern struct ctype *curfun; + + expect(RETURN); + /* TODO: Check the type of the function, can be void */ + np = expr(); + expect(';'); + return node1(ORETURN, np); +} + +static struct node * stmt(void) { register struct node *np; @@ -188,7 +201,7 @@ stmt(void) case WHILE: return _while(); case CONTINUE: return _continue(); case BREAK: return _break(); - case RETURN: + case RETURN: return _return(); case GOTO: return _goto(); case CASE: /* TODO */ case DEFAULT: /* TODO */ diff --git a/syntax.h b/syntax.h @@ -11,7 +11,8 @@ enum opcode { OBOR, OAND, OOR, OTERN, OASSIGN, OA_MUL, OA_DIV, OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND, OA_XOR, OA_OR, OSYM, OCOMP, OSWITCH, OIF, OFOR, - OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK, OCONT + OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK, OCONT, + ORETURN }; struct node; diff --git a/tree.c b/tree.c @@ -187,6 +187,7 @@ prtree_helper(register struct node *np) [OGOTO] = {1, "goto"}, [OBREAK] = {1, "break"}, [OCONT] = {1, "cont"}, + [ORETURN] = {1, "return"} }; if (!np) { fputs(" nil", stdout);