shithub: mc

Download patch

ref: 80f3197039716af937a80f3f3516c3c8af1a4b58
parent: 30c662571c4f64f72171cca0efc7bedc59bd53fa
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 28 19:28:25 EST 2018

Allow generating function vars.

--- a/6/blob.c
+++ b/6/blob.c
@@ -173,7 +173,9 @@
 		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 @@
 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));
--- a/6/simp.c
+++ b/6/simp.c
@@ -388,6 +388,8 @@
 	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 @@
 	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) {