scc

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

commit 99cb9c06c29a3c5280eed66de14a98f0a0e24503
parent a95148537302c8fe01bef6538943d4313068f988
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 17 Apr 2014 15:44:53 +0200

Add a print element to inline expressions

It is important emit a print element, because in other case
the user will not see the output of the expression.

Diffstat:
Mcc.h | 3++-
Mcode.c | 7+++++++
Mdecl.c | 7+++++--
3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/cc.h b/cc.h @@ -204,7 +204,8 @@ enum { extern void emitdcl(Symbol *), emitsframe(Symbol *), emiteframe(Symbol *), emitsym(Node *), emitunary(Node *), - emitbin(Node *), emitexp(Node *), emitconst(Node *np); + emitbin(Node *), emitexp(Node *), emitconst(Node *np), + emitprint(Node *); extern Node *node(Inst code, Type *tp, union unode u, uint8_t nchilds), diff --git a/code.c b/code.c @@ -165,6 +165,13 @@ emitexp(Node *np) } void +emitprint(Node *np) +{ + (*np->code)(np); + printf("\tk%c\n", np->type->letter); +} + +void emitfun(Symbol *sym) { printf("%c%d\tn%s\n", diff --git a/decl.c b/decl.c @@ -482,8 +482,8 @@ extdecl(void) break; case '@': next(); - emitexp(expr()); - return; + emitprint(expr()); + goto semicolon; default: goto dcl_expected; } @@ -515,10 +515,13 @@ extdecl(void) ; /* TODO: handle extern */ else if (accept('=')) initializer(tp); + emitdcl(sym); + } } while (accept(',')); } +semicolon: expect(';'); return;