ref: 5d8f48486d19ffea0833a336b2ca8d34af410057
parent: c9d57fb9d847b916d1c84f0ecd5c7d62676819a4
author: Ori Bernstein <ori@eigenstate.org>
date: Mon May 4 06:02:28 EDT 2015
Make fsel code more generic.
--- a/mbld/fsel.myr
+++ b/mbld/fsel.myr
@@ -3,15 +3,15 @@
use "opts.use"
pkg bld =
- type fsel = struct
- filematch : std.htab(byte[:], int)#
- filebest : std.htab(byte[:], byte[:])#
+ type syssel(@a) = struct
sysattrs : std.htab(byte[:], bool)#
+ _match : std.htab(byte[:], int)#
+ _best : std.htab(byte[:], @a)#
;;
- const mkfsel : (-> fsel#)
- const fseladd : (fsel : fsel#, file : byte[:] -> void)
- const fselfin : (fsel : fsel# -> byte[:][:])
+ const mkfsel : (-> syssel(byte[:])#)
+ const fseladd : (fsel : syssel(byte[:])#, file : byte[:] -> void)
+ const fselfin : (fsel : syssel(byte[:])# -> byte[:][:])
;;
const mkfsel = {
@@ -18,8 +18,8 @@
var fsel
fsel = std.alloc()
- fsel.filematch = std.mkht(std.strhash, std.streq)
- fsel.filebest = std.mkht(std.strhash, std.streq)
+ fsel._match = std.mkht(std.strhash, std.streq)
+ fsel._best = std.mkht(std.strhash, std.streq)
fsel.sysattrs = std.mkht(std.strhash, std.streq)
addsysattrs(fsel.sysattrs)
-> fsel
@@ -57,10 +57,10 @@
;;
;;
std.slfree(attrlist)
- curbest = std.htgetv(fsel.filematch, basename, -1)
+ curbest = std.htgetv(fsel._match, basename, -1)
if curbest < nmatch
- std.htput(fsel.filematch, basename, nmatch)
- std.htput(fsel.filebest, basename, f)
+ std.htput(fsel._match, basename, nmatch)
+ std.htput(fsel._best, basename, f)
;;
}
@@ -67,17 +67,17 @@
const fselfin = {fsel
var keys, nmatch, ret
- keys = std.htkeys(fsel.filematch)
+ keys = std.htkeys(fsel._match)
ret = [][:]
for k in keys
- nmatch = std.htgetv(fsel.filematch, k, -1)
+ nmatch = std.htgetv(fsel._match, k, -1)
if nmatch == -1
std.fatal(1, "no applicable file for '%s'\n", k)
;;
- ret = std.slpush(ret, std.htgetv(fsel.filebest, k, ""))
+ ret = std.slpush(ret, std.htgetv(fsel._best, k, ""))
;;
- std.htfree(fsel.filematch)
- std.htfree(fsel.filebest)
+ std.htfree(fsel._match)
+ std.htfree(fsel._best)
std.htfree(fsel.sysattrs)
-> ret
}
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -26,6 +26,9 @@
.argdesc = "[inputs...]",
.opts = [
[.opt='t', .desc="list all available targets"],
+ [.opt='S', .desc="generate assembly when building"],
+ [.opt='d', .desc="dump debugging information for mbld"],
+
[.opt='I', .arg="inc", .desc="add 'inc' to your include path"],
[.opt='R', .arg="root", .desc="install into 'root'"],
[.opt='b', .arg="bin", .desc="compile binary named 'bin' from inputs"],
@@ -33,8 +36,6 @@
[.opt='r', .arg="rt", .desc="link against runtime 'rt' instead of default"],
[.opt='C', .arg="mc", .desc="compile with 'mc' instead of the default compiler"],
[.opt='M', .arg="mu", .desc="merge uses with 'mu' instead of the default muse"],
- [.opt='S', .desc="generate assembly when building"],
- [.opt='d', .desc="dump debugging information for mbld"],
][:]
])
bld.initopts()
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -224,7 +224,7 @@
/* gentarget: wordlist {attrs} = wordlist ;; */
const cmdtarget = {b, p, cmd, iscmd
- var outlist, deplist, cmdlist
+ var outlist, deplist, cmdlist, systags
var durable
var attrs
var gt
@@ -268,9 +268,12 @@
for elt in attrs
match elt
| ("durable", ""): durable = true
- | ("durable", val): failparse(p, "durable attr does not take argument\n")
| ("dep", depname): deplist = std.slpush(deplist, depname)
- | (attrname, val): failparse(p, "attribute %s not valid on %s targets\n", attrname, cmd)
+ | ("sys", tags): systags = std.slpush(systags, tags)
+ | (attr, ""):
+ failparse(p, "attribute %s not valid on %s targets\n", attr, cmd)
+ | (attr, val):
+ failparse(p, "attribute %s=%s not valid on %s targets\n", attr, val, cmd)
;;
;;
@@ -279,7 +282,8 @@
.out=outlist,
.durable=durable,
.deps=deplist,
- .cmd=cmdlist
+ .cmd=cmdlist,
+ .systags=systags,
])
for o in outlist
if iscmd
@@ -296,7 +300,7 @@
| name attrlist = inputlist ';;'
*/
const myrtarget = {p, targ
- var ldscript, runtime, inst, incpath
+ var ldscript, runtime, inst, incpath, systags
var name, inputs, libdeps, attrs
var fsel
@@ -347,7 +351,7 @@
| ("runtime", rt): runtime = std.sldup(rt)
| ("inc", path): incpath = std.slpush(incpath, std.sldup(path))
| ("noinst", ""): inst = false
- | ("noinst", val): failparse(p, "noinst attr does not take argument\n")
+ | ("sys", tags): systags = std.slpush(systags, tags)
| (invalid, _):
std.fatal(1, "%s: got invalid attr '%s'\n", targ, invalid)
;;
@@ -363,6 +367,7 @@
.libdeps=libdeps,
.islib=false,
/* attrs */
+ .systags=systags,
.install=inst,
.ldscript=ldscript,
.runtime=runtime,
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -36,6 +36,7 @@
install : bool
runtime : byte[:]
incpath : byte[:][:]
+ systags : byte[:][:]
ldscript : byte[:]
;;
@@ -44,6 +45,7 @@
out : byte[:][:]
cmd : byte[:][:]
deps : byte[:][:]
+ systags : byte[:][:]
durable : bool
/* we can have multiple outputs, but we only want to run once for each */
done : bool
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -304,7 +304,6 @@
Tydefn *td;
Type *ty;
- assert(t != NULL);
if (st->name)
setns(n, st->name);
if (st->name && t && t->name)
@@ -312,7 +311,7 @@
ty = gettype(st, n);
if (!ty) {
- if (hastype(st, n)) {
+ if (t && hastype(st, n)) {
t->vis = Visexport;
updatetype(st, n, t);
} else {