shithub: mc

Download patch

ref: f6ba58c5be0d9632a34ae6ad1a305445a71ebc89
parent: c7e6d109bcd7e0d0b33c5e134c83e3efe9154ef9
author: Ori Bernstein <ori@markovcorp.com>
date: Fri Dec 1 10:05:54 EST 2017

Allow function in blob initializers.

--- a/6/blob.c
+++ b/6/blob.c
@@ -272,7 +272,19 @@
 	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 @@
 	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:
--- a/6/simp.c
+++ b/6/simp.c
@@ -1508,6 +1508,7 @@
 		case Ostruct:
 		case Oslice:
 		case Oucon:
+		case Ovar:
 			extractsub(s, e);
 			lappend(&s->blobs, &s->nblobs, dcl);
 			break;