summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2017-12-01 15:05:54 -0800
committerOri Bernstein <ori@markovcorp.com>2017-12-01 15:08:10 -0800
commitf6ba58c5be0d9632a34ae6ad1a305445a71ebc89 (patch)
tree8cdaa545d5f22f97ad144a1f1c65602b3fb7c3b2 /6
parentc7e6d109bcd7e0d0b33c5e134c83e3efe9154ef9 (diff)
downloadmc-f6ba58c5be0d9632a34ae6ad1a305445a71ebc89.tar.gz
Allow function in blob initializers.
Diffstat (limited to '6')
-rw-r--r--6/blob.c13
-rw-r--r--6/simp.c1
2 files changed, 14 insertions, 0 deletions
diff --git a/6/blob.c b/6/blob.c
index 8e2671e..36ea671 100644
--- a/6/blob.c
+++ b/6/blob.c
@@ -272,6 +272,18 @@ blobucon(Blob *seq, Htab *globls, Htab *strtab, Node *n)
return sz;
}
+static size_t
+blobvar(Blob *seq, Htab *strtab, Node *var, Type *ty)
+{
+ Node *dcl;
+
+ dcl = decls[var->expr.did];
+ if (tybase(ty)->type != Tyfunc || !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));
+ return 16;
+}
static size_t
blobrec(Blob *b, Htab *globls, Htab *strtab, Node *n)
@@ -282,6 +294,7 @@ blobrec(Blob *b, Htab *globls, Htab *strtab, Node *n)
case Oucon: sz = blobucon(b, globls, strtab, n); break;
case Oslice: sz = blobslice(b, globls, strtab, n); break;
case Ostruct: sz = blobstruct(b, globls, strtab, n); break;
+ case Ovar: sz = blobvar(b, strtab, n, exprtype(n)); break;
case Olit: sz = bloblit(b, strtab, n->expr.args[0], exprtype(n)); break;
case Otup:
case Oarr:
diff --git a/6/simp.c b/6/simp.c
index aeab856..41fa010 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -1508,6 +1508,7 @@ simpconstinit(Simp *s, Node *dcl)
case Ostruct:
case Oslice:
case Oucon:
+ case Ovar:
extractsub(s, e);
lappend(&s->blobs, &s->nblobs, dcl);
break;