shithub: mc

Download patch

ref: f5c244010143f1b7b90c66dd54d8b4d8d3c0a7df
parent: 062038c04a1cb9b7b161b670c5a3a948aaed42d1
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jul 13 20:26:13 EDT 2015

Forgot to commit the rename.

--- a/mbld/fsel.myr
+++ /dev/null
@@ -1,114 +1,0 @@
-use std
-
-use "opts.use"
-
-pkg bld =
-	type syssel(@a) = struct
-		file	: byte[:]
-		line	: int
-		targ	: byte[:]
-
-		_sysattrs	: std.htab(byte[:], bool)#
-		_match	: std.htab(byte[:], int)#
-		_best	: std.htab(byte[:], @a)#
-	;;
-
-	generic mksyssel	: (f : byte[:], line : int, targ : byte[:] -> syssel(byte[:])#)
-	generic sysseladd	: (fsel : syssel(byte[:])#, file : byte[:] -> void)
-	generic sysselfin	: (fsel : syssel(byte[:])# -> byte[:][:])
-;;
-
-generic mksyssel = {file, line, targ
-	var fsel
-
-	fsel = std.mk([
-		.file = file,
-		.line = line,
-		.targ = targ,
-
-		._match = std.mkht(std.strhash, std.streq),
-		._best = std.mkht(std.strhash, std.streq),
-		._sysattrs = std.mkht(std.strhash, std.streq),
-	])
-	addsysattrs(fsel._sysattrs)
-	-> fsel
-}
-
-generic sysseladd = {fsel, f
-	var basename, attrs
-	var nmatch, curbest
-	var attrlist, i
-
-	match std.strfind(f, "+")
-	| `std.Some idx:
-		basename = f[:idx]
-		match std.strrfind(f[idx+1:], ".")
-		| `std.Some j:	attrs = f[idx+1:][:j]
-		| `std.None:	std.fatal("unrecognized type for file {}\n", f)
-		;;
-	| `std.None:
-		match std.strrfind(f, ".")
-		| `std.None:	std.fatal("unrecognized type for file {}\n", f)
-		| `std.Some idx:
-			basename = f[:idx]
-			attrs = ""
-		;;
-	;;
-
-	nmatch = 0
-	attrlist = std.strsplit(attrs, "-")
-	for i = 0; i < attrlist.len; i++
-		if std.hthas(fsel._sysattrs, attrlist[i])
-			nmatch++
-		else
-			nmatch = -1
-			break
-		;;
-	;;
-	std.slfree(attrlist)
-	curbest = std.htgetv(fsel._match, basename, -1)
-	if curbest < nmatch
-		std.htput(fsel._match, basename, nmatch)
-		std.htput(fsel._best, basename, f)
-	;;
-}
-
-generic sysselfin = {fsel
-	var keys, nmatch, ret
-
-	keys = std.htkeys(fsel._match)
-	ret = [][:]
-	for k in keys
-		nmatch = std.htgetv(fsel._match, k, -1)
-		if nmatch == -1
-			std.fatal("{}:{}: target {}, no applicable file for '{}'\n", fsel.file, fsel.line, fsel.targ, k)
-		;;
-		ret = std.slpush(ret, std.htgetv(fsel._best, k, ""))
-	;;
-	std.htfree(fsel._match)
-	std.htfree(fsel._best)
-	std.htfree(fsel._sysattrs)
-	-> ret
-}
-
-const addsysattrs = {sa
-	var attrs
-	match opt_sys
-	| "freebsd":	attrs = ["freebsd", "posixy"][:]
-	| "osx":	attrs = ["osx", "posixy"][:]
-	| "linux":	attrs = ["linux", "posixy"][:]
-	| "plan9":	attrs = ["plan9"][:]
-	| unknown:	std.fatal("unknown systemx \"{}\"\n", unknown)
-	;;
-	for a in attrs
-		std.htput(sa, a, true)
-	;;
-
-	match opt_arch
-	| "x64":	attrs = ["x64"][:]
-	| unknown:	std.fatal("unknown architecture {}\n", unknown)
-	;;
-	for a in attrs
-		std.htput(sa, a, true)
-	;;
-}
--- /dev/null
+++ b/mbld/syssel.myr
@@ -1,0 +1,118 @@
+use std
+
+use "opts.use"
+
+pkg bld =
+	type syssel(@a) = struct
+		file	: byte[:]
+		line	: int
+		targ	: byte[:]
+		sysattrs	: std.htab(byte[:], bool)#
+		_match	: std.htab(byte[:], int)#
+		_best	: std.htab(byte[:], @a)#
+	;;
+
+	generic mksyssel	: (f : byte[:], line : int, targ : byte[:] -> syssel(@a)#)
+	generic sysseladd	: (syssel : syssel(byte[:])#, file : byte[:] -> void)
+	generic sysseladdlist	: (syssel : syssel(@a)#, base : byte[:], attrs : byte[:][:], val : @a -> void)
+	generic sysselfin	: (syssel : syssel(@a)# -> @a[:])
+;;
+
+generic mksyssel = {file, line, targ
+	var syssel
+
+	syssel = std.mk([
+		.file = file,
+		.line = line,
+		.targ = targ,
+		._match = std.mkht(std.strhash, std.streq),
+		._best = std.mkht(std.strhash, std.streq),
+		.sysattrs = std.mkht(std.strhash, std.streq),
+	])
+	addsysattrs(syssel.sysattrs)
+	-> syssel
+}
+
+generic sysseladd = {syssel, f
+	var basename, attrs
+	var attrlist
+
+	match std.strfind(f, "+")
+	| `std.Some i:
+		basename = f[:i]
+		match std.strrfind(f[i+1:], ".")
+		| `std.Some j:	attrs = f[i+1:][:j]
+		| `std.None:	std.fatal("unrecognized type for file {}\n", f)
+		;;
+	| `std.None:
+		match std.strrfind(f, ".")
+		| `std.None:	std.fatal("unrecognized type for file {}\n", f)
+		| `std.Some i:
+			basename = f[:i]
+			attrs = ""
+		;;
+	;;
+
+	attrlist = std.strsplit(attrs, "-")
+	sysseladdlist(syssel, basename, attrlist, f)
+	std.slfree(attrlist)
+}
+
+generic sysseladdlist = {syssel, base, attrs, val
+	var nmatch, curbest
+
+	nmatch = 0
+	for a in attrs
+		if std.hthas(syssel.sysattrs, a)
+			nmatch++
+		else
+			nmatch = -1
+			break
+		;;
+	;;
+	curbest = std.htgetv(syssel._match, base, -1)
+	if curbest < nmatch
+		std.htput(syssel._match, base, nmatch)
+		std.htput(syssel._best, base, val)
+	;;
+}
+
+generic sysselfin = {syssel
+	var keys, nmatch, ret
+
+	keys = std.htkeys(syssel._match)
+	ret = [][:]
+	for k in keys
+		nmatch = std.htgetv(syssel._match, k, -1)
+		if nmatch == -1
+			std.fatal("{}:{}: target {}, no applicable file for '{}'\n", syssel.file, syssel.line, syssel.targ, k)
+		;;
+		ret = std.slpush(ret, std.get(std.htget(syssel._best, k)))
+	;;
+	std.htfree(syssel._match)
+	std.htfree(syssel._best)
+	std.htfree(syssel.sysattrs)
+	-> ret
+}
+
+const addsysattrs = {sa
+	var attrs
+	match opt_sys
+	| "freebsd":	attrs = ["freebsd", "posixy"][:]
+	| "osx":	attrs = ["osx", "posixy"][:]
+	| "linux":	attrs = ["linux", "posixy"][:]
+	| "plan9":	attrs = ["plan9"][:]
+	| unknown:	std.fatal("unknown systemx \"{}\"\n", unknown)
+	;;
+	for a in attrs
+		std.htput(sa, a, true)
+	;;
+
+	match opt_arch
+	| "x64":	attrs = ["x64"][:]
+	| unknown:	std.fatal("unknown architecture {}\n", unknown)
+	;;
+	for a in attrs
+		std.htput(sa, a, true)
+	;;
+}