ref: 3a076cf836169c7483321ce396bf61ea6fd08db6
parent: 76052f85cadd41162d999b7fa402d7d1e7488b0d
author: Ori Bernstein <[email protected]>
date: Fri Jun 15 09:05:45 EDT 2012
Acutally store initializers.
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -539,7 +539,7 @@
static Node *simp(Simp *s, Node *n)
{
- Node *r;
+ Node *r, *v;
size_t i;
if (!n)
@@ -568,7 +568,14 @@
r = n;
break;
case Ndecl:
- declarelocal(s, n);
+ /* Should already have happened */
+ declarelocal(s, n);
+ if (n->decl.init) {
+ v = rval(s, n->decl.init);
+ r = mkexpr(n->line, Ovar, n, NULL);
+ r->expr.did = n->decl.sym->id;
+ append(s, store(r, v));
+ }
break;
case Nlbl:
append(s, n);
@@ -626,12 +633,16 @@
for (i = 0; i < s.nstmts; i++) {
if (s.stmts[i]->type != Nexpr)
continue;
- printf("FOLD FROM ----------\n");
- dump(s.stmts[i], stdout);
+ if (debug) {
+ printf("FOLD FROM ----------\n");
+ dump(s.stmts[i], stdout);
+ }
s.stmts[i] = fold(s.stmts[i]);
- printf("FOLD TO ------------\n");
- dump(s.stmts[i], stdout);
- printf("END ----------------\n");
+ if (debug) {
+ printf("FOLD TO ------------\n");
+ dump(s.stmts[i], stdout);
+ printf("END ----------------\n");
+ }
}
cfg = mkcfg(s.stmts, s.nstmts);
if (debug)
@@ -677,7 +688,7 @@
nn = file->file.nstmts;
globls = mkht(ptrhash, ptreq);
- /* We need to declare all variables before use */
+ /* We need to define all global variables before use */
for (i = 0; i < nn; i++)
if (n[i]->type == Ndecl)
htput(globls, (void*)n[i]->decl.sym->id, asmname(n[i]->decl.sym->name));
--- a/test/mul.myr
+++ b/test/mul.myr
@@ -1,3 +1,6 @@
const main = {
- -> 7 * 2 * 3
+ var a = 7
+ var b = 2
+ var c = 3
+ -> a * b * c
}