summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-01-29 00:28:25 -0800
committerOri Bernstein <ori@eigenstate.org>2018-01-29 00:28:25 -0800
commit80f3197039716af937a80f3f3516c3c8af1a4b58 (patch)
treef96382adbd0a8aabc32e7bbbeebab43ffda67402 /6
parent30c662571c4f64f72171cca0efc7bedc59bd53fa (diff)
downloadmc-80f3197039716af937a80f3f3516c3c8af1a4b58.tar.gz
Allow generating function vars.
Diffstat (limited to '6')
-rw-r--r--6/blob.c8
-rw-r--r--6/simp.c7
2 files changed, 10 insertions, 5 deletions
diff --git a/6/blob.c b/6/blob.c
index 36ea671..4c1fa0b 100644
--- a/6/blob.c
+++ b/6/blob.c
@@ -173,7 +173,9 @@ bloblit(Blob *seq, Htab *strtab, Node *v, Type *ty)
b(seq, mkblobi(Bti64, v->lit.strval.len));
break;
case Lfunc:
- die("Generating this shit ain't ready yet ");
+ lbl = asmname(v);
+ b(seq, mkblobi(Bti64, 0));
+ b(seq, mkblobref(lbl, 0, 0));
break;
case Llbl:
die("Can't generate literal labels, ffs. They're not data.");
@@ -276,9 +278,11 @@ static size_t
blobvar(Blob *seq, Htab *strtab, Node *var, Type *ty)
{
Node *dcl;
+ Ty tt;
dcl = decls[var->expr.did];
- if (tybase(ty)->type != Tyfunc || !dcl->decl.isglobl)
+ tt = tybase(ty)->type;
+ if ((tt != Tyfunc && tt != Tycode)|| !dcl->decl.isglobl)
fatal(var, "non-constant initializer %s", namestr(var->expr.args[0]));
b(seq, mkblobi(Bti64, 0));
b(seq, mkblobref(asmname(dcl), 0, 1));
diff --git a/6/simp.c b/6/simp.c
index 730dda5..d2a9d18 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -388,6 +388,8 @@ simpcode(Simp *s, Node *fn)
Node *r, *d;
r = geninitdecl(fn, codetype(exprtype(fn)), &d);
+ r->decl.isconst = 1;
+ r->decl.isglobl = 1;
htput(s->globls, d, asmname(d));
lappend(&file->file.stmts, &file->file.nstmts, d);
return r;
@@ -1500,9 +1502,8 @@ simpconstinit(Simp *s, Node *dcl)
e = dcl->decl.init;
if (e && exprop(e) == Olit) {
if (e->expr.args[0]->lit.littype == Lfunc)
- simpcode(s, e);
- else
- lappend(&s->blobs, &s->nblobs, dcl);
+ dcl->decl.init = simpcode(s, e);
+ lappend(&s->blobs, &s->nblobs, dcl);
} else if (!dcl->decl.isconst && !e) {
lappend(&s->blobs, &s->nblobs, dcl);
} else if (e->expr.isconst) {