shithub: mc

Download patch

ref: bc05485833aa6d18041678cdc2510cc827957f41
parent: ae222f2157fa57dd27ff23bcb13c78adc08627b2
author: Ori Bernstein <[email protected]>
date: Wed Apr 22 17:29:40 EDT 2015

Clean up insane argument lists.

--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -61,15 +61,13 @@
 	setdir(b, targ.dir)
 	addincludes(b, targ)
 	std.put("%s...\n", targ.name)
-	if !myrdeps(b, targ, false, false, addsrc, &dg)
-		std.fatal(1, "Could not load dependencies for %s\n", targ.name)
-	;;
+	dg = myrdeps(b, targ, false, addsrc)
 	if !std.hthas(dg.deps, targ.name)
 		std.fatal(1, "no input files for %s\n", targ.name)
 	;;
-	if builddep(b, &dg, targ.name, targ.incpath) || !freshlibs(targ, dg.libs)
+	if builddep(b, dg, targ.name, targ.incpath) || !freshlibs(targ, dg.libs)
 		src = std.htkeys(dg.sources)
-		linkbin(&dg, targ.name, src, targ.ldscript, targ.runtime, targ.incpath, targ.libdeps)
+		linkbin(dg, targ.name, src, targ.ldscript, targ.runtime, targ.incpath, targ.libdeps)
 		std.slfree(src)
 	;;
 }
@@ -85,18 +83,16 @@
 	lib = targ.name
 	std.put("lib%s.a...\n", lib)
 	archive = std.fmt("lib%s.a", lib)
-	if !myrdeps(b, targ, true, false, false, &dg)
-		std.fatal(1, "Could not load dependencies for %s\n", lib)
-	;;
+	dg = myrdeps(b, targ, false, false)
 	if !std.hthas(dg.deps, lib)
 		std.fatal(1, "no target declared for %s\n", lib)
 	;;
-	u = builddep(b, &dg, targ.name, targ.incpath)
-	l = builddep(b, &dg, archive, targ.incpath)
+	u = builddep(b, dg, targ.name, targ.incpath)
+	l = builddep(b, dg, archive, targ.incpath)
 	if  u || l || !freshlibs(targ, dg.libs)
 		src = std.htkeys(dg.sources)
-		mergeuse(&dg, lib, src, targ.incpath)
-		archivelib(&dg, lib, src, targ.incpath)
+		mergeuse(dg, lib, src, targ.incpath)
+		archivelib(dg, lib, src, targ.incpath)
 		std.slfree(src)
 	;;
 	std.slfree(archive)
--- a/mbld/clean.myr
+++ b/mbld/clean.myr
@@ -16,11 +16,11 @@
 	for tn in b.all
 		match gettarg(b.targs, tn)
 		| `Bin bt:
-			cleanup(b, bt, bt.inputs, true)
+			cleanup(b, bt, bt.inputs)
 		| `Lib lt:
-			cleanup(b, lt, lt.inputs, true)
+			cleanup(b, lt, lt.inputs)
 		| `Test tt:
-			cleanup(b, tt, tt.inputs, true)
+			cleanup(b, tt, tt.inputs)
 		| `Gen gt:
 			for f in gt.out
 				if !gt.durable && std.remove(f)
@@ -38,15 +38,15 @@
 		match gettarg(b.targs, tn)
 		| `Bin bt:
 			if std.sleq(bt.name, targ)
-				cleanup(b, bt, bt.inputs, true)
+				cleanup(b, bt, bt.inputs)
 			;;
 		| `Lib lt:
 			if std.sleq(lt.name, targ)
-				cleanup(b, lt, lt.inputs, true)
+				cleanup(b, lt, lt.inputs)
 			;;
 		| `Test tt:
 			if std.sleq(tt.name, targ)
-				cleanup(b, tt, tt.inputs, true)
+				cleanup(b, tt, tt.inputs)
 			;;
 		| `Gen gt:
 			for f in gt.out
@@ -60,10 +60,9 @@
 	-> true
 }
 
-const cleanup = {b, targ, leaves, islib
+const cleanup = {b, targ, leaves
 	var mchammer_files /* cant touch this */
-	var keys
-	var dg
+	var keys, dg
 
 	/*
 	we want to automatically add 'clean' sources since otherwise,
@@ -70,9 +69,7 @@
 	mbld won't be able to clean code after changing a build file.
 	*/
 	setdir(b, targ.dir)
-	if !myrdeps(b, targ, islib, true, true, &dg)
-		std.fatal(1, "Could not load dependencies for %s\n", targ.name)
-	;;
+	dg = myrdeps(b, targ, true, true)
 	mchammer_files = std.mkht(std.strhash, std.streq)
 	for l in leaves
 		std.htput(mchammer_files, l, true)
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -8,7 +8,7 @@
 use "util.use"
 
 pkg bld =
-	const myrdeps	: (b : build#, mt : myrtarg#, islib : bool, isclean : bool, addsrc : bool, dg : depgraph#	-> bool)
+	const myrdeps	: (b : build#, mt : myrtarg#, doclean : bool, addsrc : bool -> depgraph#)
 
 	/* a bit ugly: initialized from main() */
 	var usepat	: regex.regex#
@@ -21,21 +21,33 @@
 	`Lib byte[:]
 ;;
 
-const myrdeps = {b, mt, islib, isclean, addsrc, dg
-	var objs, uses, srcs, incs
-	var out, useout, depstk
+type depscan = struct
+	doclean	: bool
+	addsrc	: bool
+	tagsel	: std.htab(byte[:], byte[:])#
+	targ	: myrtarg#
+	depstk	: byte[:][:]
+	incs	: byte[:][:]
+;;
+
+const myrdeps = {b, mt, doclean, addsrc
+	var objs, uses, srcs
+	var out, useout
+	var dg : depgraph#
+	var ds : depscan
 	var i
 
-	dg.deps = std.mkht(std.strhash, std.streq)
-	dg.libs = std.mkht(std.strhash, std.streq)
-	dg.input = std.mkht(std.strhash, std.streq)
-	dg.sources = std.mkht(std.strhash, std.streq)
-	dg.updated = std.mkht(std.strhash, std.streq)
-	dg.seen = std.mkht(std.strhash, std.streq)
-	dg.done = std.mkht(std.strhash, std.streq)
-
+	dg = std.mk([
+		.deps = std.mkht(std.strhash, std.streq),
+		.libs = std.mkht(std.strhash, std.streq),
+		.input = std.mkht(std.strhash, std.streq),
+		.sources = std.mkht(std.strhash, std.streq),
+		.updated = std.mkht(std.strhash, std.streq),
+		.seen = std.mkht(std.strhash, std.streq),
+		.done = std.mkht(std.strhash, std.streq),
+	])
 	/* direct dependencies of binary */
-	if islib
+	if mt.islib
 		out = std.fmt("lib%s.a", mt.name)
 		useout = std.sldup(mt.name)
 	else
@@ -43,8 +55,14 @@
 		useout = ""
 	;;
 
+	ds = [
+		.doclean = doclean,
+		.addsrc = addsrc,
+		.incs = mt.incpath,
+		.targ = mt,
+		.depstk = [][:],
+	]
 	srcs = mt.inputs
-	incs = mt.incpath
 	objs = swapall(srcs, config.Objsuffix)
 	uses = swapall(srcs, ".use")
 	for i = 0; i < srcs.len; i++
@@ -59,18 +77,16 @@
 
 	for i = 0; i < srcs.len; i++
 		pushdep(dg, objs[i], out)
-		if islib && std.hassuffix(srcs[i], ".myr")
+		if mt.islib && std.hassuffix(srcs[i], ".myr")
 			pushdep(dg, uses[i], useout)
 		;;
 	;;
 
 	for i = 0; i < srcs.len; i++
-		depstk = [][:]
-		srcdeps(b, dg, srcs[i], objs[i], uses[i], incs, &depstk, isclean, addsrc)
-		std.slfree(depstk)
+		srcdeps(b, dg, srcs[i], objs[i], uses[i], &ds)
 	;;
 	dumpgraph(dg)
-	-> true
+	-> dg
 }
 
 const swapall = {srcs, suff
@@ -99,7 +115,7 @@
 	std.put("}\n")
 }
 
-const srcdeps = {b, g, path, obj, usefile, incs, depstk, isclean, addsrc
+const srcdeps = {b, g, path, obj, usefile, ds
 	var deps
 
 	if std.hthas(g.done, path)
@@ -106,10 +122,10 @@
 		->
 	;;
 
-	depstk# = std.slpush(depstk#, path)
+	ds.depstk = std.slpush(ds.depstk, path)
 	if std.htgetv(g.seen, path, false)
 		std.fput(1, "dependency loop involving %s:\n", path)
-		for d in depstk#
+		for d in ds.depstk
 			std.fput(1, "\t%s\n", d)
 		;;
 		std.exit(1)
@@ -123,8 +139,8 @@
 			If we're cleaning, we don't care about libraries; at best, this does nothing. At
 			worst, this will cause failure if the library is a local library that gets cleand.
 			*/
-			if !isclean
-				scrapelibs(g, lib, incs)
+			if !ds.doclean
+				scrapelibs(g, lib, ds.incs)
 			;;
 		| `Local l:
 			if !std.hassuffix(l, ".use")
@@ -136,15 +152,15 @@
 			if usefile.len != 0
 				pushdep(g, l, usefile)
 			;;
-			addusedep(b, g, path, l, incs, depstk, isclean, addsrc)
+			addusedep(b, g, path, l, ds)
 		;;
 	;;
-	depstk# = std.slgrow(depstk#, depstk#.len - 1)
+	ds.depstk = std.slgrow(ds.depstk, ds.depstk.len - 1)
 	std.htput(g.seen, path, false)
 	std.htput(g.done, path, true)
 }
 
-const addusedep = {b, g, f, usefile, incs, depstk, isclean, addsrc
+const addusedep = {b, g, f, usefile, ds
 	var src
 
 	if std.hthas(g.done, usefile)
@@ -158,7 +174,7 @@
 		src = std.sldup(path)
 	| `std.None:
 		src = swapsuffix(usefile, ".use", ".myr")
-		if addsrc
+		if ds.addsrc
 			std.htput(g.sources, src, true)
 		elif !std.hthas(g.input, usefile)
 			std.fatal(1, "%s: source file %s not listed in bldfile\n", f, src)
@@ -166,7 +182,7 @@
 	;;
 	pushdep(g, src, usefile)
 	std.htput(g.input, usefile, src)
-	srcdeps(b, g, src, "", usefile, incs, depstk, isclean, addsrc)
+	srcdeps(b, g, src, "", usefile, ds)
 	std.htput(g.done, usefile, true)
 }
 
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -189,6 +189,7 @@
 const libtarget = {b, p
 	var t
 	t = myrtarget(p, "lib")
+	t.islib = true
 	addtarg(p, b, t.name, `Lib t)
 }
 
@@ -353,6 +354,7 @@
 		.name=name,
 		.inputs=inputs,
 		.libdeps=libdeps,
+		.islib=false,
 		/* attrs */
 		.install=inst,
 		.ldscript=ldscript,
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -27,6 +27,7 @@
 	;;
 
 	type myrtarg = struct
+		islib	: bool
 		dir	: byte[:]
 		name	: byte[:]
 		inputs	: byte[:][:]