shithub: mc

Download patch

ref: ec311388a2880c4f836bd1108245cd4c2ab5630e
parent: 80e1f20064f435fba7b4c7be70fd6b19c5218cc3
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Jul 19 18:20:53 EDT 2017

Only use the filename itself for __init__

	This sucks, but it's *extremely* unlikely that a file
	will share a namespace, filename, and __init__.

	This makes builds directory-independent, so that linking
	the same file compiled with a different compiler cwd will
	work.

--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -58,6 +58,7 @@
 		.extlibs = [][:],
 		.dynamic = false,
 	])
+
 	/* direct dependencies of binary */
 	if mt.islib
 		out = std.fmt("lib{}.a", mt.name)
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -1053,10 +1053,15 @@
 static void setupinit(Node *n)
 {
 	char name[1024];
-	char *p;
+	char *p, *s;
 
 	bprintf(name, sizeof name, "%s$__init__", file->file.files[0]);
-	p = name;
+	s = strrchr(name, '/');
+	if (s)
+		s++;
+	else
+		s = name;
+	p = s;
 	while (*p) {
 		if (!isalnum(*p) && *p != '_')
 			*p = '$';
@@ -1064,7 +1069,7 @@
 	}
 	n->decl.isinit = 1;
 	n->decl.vis = Vishidden;
-	n->decl.name->name.name = strdup(name);
+	n->decl.name->name.name = strdup(s);
 }
 
 static void addtrait(Type *t, char *str)