ref: 99cb9c06c29a3c5280eed66de14a98f0a0e24503
parent: a95148537302c8fe01bef6538943d4313068f988
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Apr 17 11:44:53 EDT 2014
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.
--- a/cc.h
+++ b/cc.h
@@ -204,7 +204,8 @@
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),
--- a/code.c
+++ b/code.c
@@ -165,6 +165,13 @@
}
void
+emitprint(Node *np)
+{
+ (*np->code)(np);
+ printf("\tk%c\n", np->type->letter);
+}
+
+void
emitfun(Symbol *sym)
{
printf("%c%d\tn%s\n",
--- a/decl.c
+++ b/decl.c
@@ -482,8 +482,8 @@
break;
case '@':
next();
- emitexp(expr());
- return;
+ emitprint(expr());
+ goto semicolon;
default:
goto dcl_expected;
}
@@ -515,10 +515,13 @@
; /* TODO: handle extern */
else if (accept('='))
initializer(tp);
+ emitdcl(sym);
+
}
} while (accept(','));
}
+semicolon:
expect(';');
return;
--
⑨