ref: 1eca6494d70ec51a950891697093525be826cef5
parent: 99517584674b6040c9c72393d160b9b60d6f3321
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jun 12 08:30:21 EDT 2015
Move movement to f2fmt and friends.
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -52,7 +52,7 @@
| `std.Some (`Gen gt): runin(b, gt.cmd, gt.dir)
| `std.Some (`Cmd ct): runin(b, ct.cmd, ct.dir)
| `std.Some (`Man mt): /* nothing needed */
- | `std.None: std.fatal("invalid target %s\n", targ)+ | `std.None: std.f2fatal("invalid target {}\n", targ);;
-> true
}
@@ -67,10 +67,10 @@
setdir(b, targ.dir)
addincludes(b, targ)
- std.put("%s...\n", targ.name)+ std.f2put("{}...\n", targ.name)dg = myrdeps(b, targ, false, addsrc)
if !std.hthas(dg.deps, targ.name)
- std.fatal("no input files for %s\n", targ.name)+ std.f2fatal("no input files for {}\n", targ.name);;
if builddep(b, dg, targ.name, targ.incpath) || !freshlibs(targ, dg.libs)
src = std.htkeys(dg.sources)
@@ -88,11 +88,11 @@
setdir(b, targ.dir)
addincludes(b, targ)
lib = targ.name
- std.put("lib%s.a...\n", lib)- archive = std.fmt("lib%s.a", lib)+ std.f2put("lib{}.a...\n", lib)+ archive = std.f2fmt("lib{}.a", lib)dg = myrdeps(b, targ, false, false)
if !std.hthas(dg.deps, lib)
- std.fatal("no target declared for %s\n", lib)+ std.f2fatal("no target declared for {}\n", lib);;
u = builddep(b, dg, targ.name, targ.incpath)
l = builddep(b, dg, archive, targ.incpath)
@@ -155,7 +155,7 @@
;;
| `std.None:
if !std.fexists(d)
- std.fatal("no input file %s\n", d)+ std.f2fatal("no input file {}\n", d);;
;;
if !isfresh(d, out)
@@ -204,7 +204,7 @@
run(cmd)
std.slfree(o)
else
- std.fatal("Unknown file type for %s\n", src)+ std.f2fatal("Unknown file type for {}\n", src);;
}
@@ -257,7 +257,7 @@
for c in config.Arcmd
cmd = std.slpush(cmd, std.sldup(c))
;;
- cmd = std.slpush(cmd, std.fmt("lib%s.a", lib))+ cmd = std.slpush(cmd, std.f2fmt("lib{}.a", lib))for f in files
obj = srcswapsuffix(f, config.Objsuffix)
cmd = std.slpush(cmd, obj)
@@ -277,7 +277,7 @@
if std.hassuffix(f, ".myr")
cmd = std.slpush(cmd, srcswapsuffix(f, ".use"))
elif !std.hassuffix(f, ".s")
- std.fatal("unknown file type for %s\n", f)+ std.f2fatal("unknown file type for {}\n", f);;
;;
run(cmd)
@@ -293,7 +293,7 @@
/* -L incpath... */
if !config.Directlib
for inc in incs
- cmd = std.slpush(cmd, std.fmt("-L%s", inc))+ cmd = std.slpush(cmd, std.f2fmt("-L{}", inc));;
;;
@@ -311,7 +311,7 @@
const visit = {cmd, head, g, lib, looped, marked, incsif std.hthas(looped, lib)
- std.fatal("cycle in library graph involving \"%s\"\n", lib)+ std.f2fatal("cycle in library graph involving \"{}\"\n", lib)elif std.hthas(marked, lib)
-> cmd
;;
@@ -327,11 +327,11 @@
const putlib = {cmd, head, lib, incsif !config.Directlib
- -> std.slput(cmd, head, std.fmt("-l%s", lib))+ -> std.slput(cmd, head, std.f2fmt("-l", lib))else
match findlib(lib, incs)
| `std.None:
- std.fatal("could not find library lib%s.a\n", lib)+ std.f2fatal("could not find library lib{}.a\n", lib)| `std.Some p:
-> std.slput(cmd, head, p)
;;
@@ -366,10 +366,10 @@
;;
std.slfree(lib)
| `std.None:
- std.fput(1, "%s: could not find library lib%s.a\n", targ.name, l)
- std.fput(1, "searched:\n")
+ std.f2fput(1, "{}: could not find library lib{}.a\n", targ.name, l)+ std.f2fput(1, "searched:\n")
for inc in targ.incpath
- std.fput(1, "\t%s\n", inc)
+ std.f2fput(1, "\t{}\n", inc);;
std.exit(1)
;;
@@ -401,7 +401,7 @@
*/
match std.fmtime(src)
| `std.Some mt: srcmt = mt
- | `std.None: std.fatal("could not stat %s\n", src)+ | `std.None: std.f2fatal("could not stat {}\n", src);;
match std.fmtime(dst)
| `std.Some mt: dstmt = mt
--- a/mbld/clean.myr
+++ b/mbld/clean.myr
@@ -24,7 +24,7 @@
| `Gen gt:
for f in gt.out
if !gt.durable && std.remove(f)
- std.put("\tclean %s\n", f)+ std.f2put("\tclean {}\n", f);;
;;
| `Cmd ct: /* nothing to do */
@@ -52,7 +52,7 @@
| `Gen gt:
for f in gt.out
if !gt.durable && std.remove(f)
- std.put("\tclean %s\n", f)+ std.f2put("\tclean {}\n", f);;
;;
| `Cmd ct:
@@ -80,7 +80,7 @@
keys = std.htkeys(dg.deps)
for k in keys
if !std.htgetv(mchammer_files, k, false) && std.remove(k)
- std.put("\tclean %s\n", k)+ std.f2put("\tclean {}\n", k);;
;;
}
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -48,7 +48,7 @@
])
/* direct dependencies of binary */
if mt.islib
- out = std.fmt("lib%s.a", mt.name)+ out = std.f2fmt("lib{}.a", mt.name)useout = std.sldup(mt.name)
else
out = std.sldup(mt.name)
@@ -106,13 +106,13 @@
->
;;
keys = std.htkeys(dg.deps)
- std.put("digraph dg {\n")+ std.f2put("digraph dg {{\n")for k in keys
for v in std.htgetv(dg.deps, k, ["WTFUNKNOWN!"][:])
- std.put("\t\"%s\" -> \"%s\";\n", k, v)+ std.f2put("\t\"{}\" -> \"{}\";\n", k, v);;
;;
- std.put("}\n")+ std.f2put("}\n")}
const srcdeps = {b, ds, g, path, obj, usefile@@ -124,9 +124,9 @@
ds.depstk = std.slpush(ds.depstk, path)
if std.htgetv(g.seen, path, false)
- std.fput(1, "dependency loop involving %s:\n", path)
+ std.f2fput(1, "dependency loop involving {}:\n", path)for d in ds.depstk
- std.fput(1, "\t%s\n", d)
+ std.fput(1, "\t{}\n", d);;
std.exit(1)
;;
@@ -165,7 +165,7 @@
if std.hthas(g.done, usefile)
if opt_debug
- std.put("already loaded deps for %s\n", usefile)+ std.f2put("already loaded deps for {}\n", usefile);;
->
;;
@@ -177,7 +177,7 @@
if ds.addsrc
std.htput(g.sources, src, true)
elif !std.hthas(g.input, usefile)
- std.fatal("%s:%i: source file %s not listed in bldfile\n", f, line, src)+ std.f2fatal("{}:{}: source file {} not listed in bldfile\n", f, line, src);;
;;
pushdep(g, src, usefile)
@@ -194,12 +194,12 @@
if !std.fexists(path)
match std.htget(b.gensrc, path)
| `std.Some gt: run(gt.cmd)
- | `std.None: std.fatal("no input file %s\n", path)+ | `std.None: std.f2fatal("no input file {}\n", path);;
;;
match bio.open(path, bio.Rd)
| `std.Some fd: f = fd
- | `std.None: std.fatal("could not open %s\n", path)+ | `std.None: std.f2fatal("could not open {}\n", path);;
lnum = 0
@@ -230,14 +230,14 @@
f = openlib(lib, incs)
match bio.getc(f)
| `std.Some 'U': /* nothing */
- | `std.Some _: std.fatal("library %s: corrupt or invalid usefile\n", lib)- | `std.None: std.fatal("library %s: could not read usefile\n", lib)+ | `std.Some _: std.f2fatal("library {}: corrupt or invalid usefile\n", lib)+ | `std.None: std.f2fatal("library {}: could not read usefile\n", lib);;
match bio.getbe32(f)
| `std.Some 1: /* nothing: version matches. */
- | `std.Some 0: std.fput(1, "library %s: warning: old usefile version\n", lib)
- | `std.Some _: std.fatal("library %s: usefile version unknown\n", lib)- | `std.None: std.fatal("library %s: corrutpt or invalid usefile\n", lib)+ | `std.Some 0: std.f2fput(1, "library {}: warning: old usefile version\n", lib)+ | `std.Some _: std.f2fatal("library {}: usefile version unknown\n", lib)+ | `std.None: std.f2fatal("library {}: corrutpt or invalid usefile\n", lib);;
std.slfree(rdstr(f))
done = false
@@ -276,7 +276,7 @@
| `std.None:
/* nothing */
;;
- std.fatal("could not find library %s.\n", lib)+ std.f2fatal("could not find library {}.\n", lib)}
const depname = {deps, ln, lnum@@ -304,7 +304,7 @@
var sl
if opt_debug
- std.put("%s <= %s\n", dst, src)+ std.f2put("{} <= {}\n", dst, src);;
std.assert(dst.len < 200, "BUG!")
sl = std.htgetv(dg.deps, dst, [][:])
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -34,7 +34,7 @@
| `Lib lt:
if lt.install
movefile(b, rm, lt.dir, lt.name, config.Libpath, 0o644)
- libarchive = std.fmt("lib%s.a", lt.name)+ libarchive = std.f2fmt("lib{}.a", lt.name)movefile(b, rm, lt.dir, libarchive, config.Libpath, 0o644)
std.slfree(libarchive)
;;
@@ -60,18 +60,18 @@
setdir(b, dir)
path = std.pathjoin([opt_destdir, opt_instroot, prefix, file][:])
if rm
- std.put("\trm %s\n", path)+ std.f2put("\trm {}\n", path)if !std.remove(path)
- std.put("\t\tno such file %s\n", file)+ std.f2put("\t\tno such file {}\n", file);;
else
- std.put("\t%s => %s\n", file, path)+ std.f2put("\t{} => {}\n", file, path)std.remove(path)
match std.slurp(file)
- | `std.Fail m: std.fatal("Could not open %s for reading\n", file)+ | `std.Fail m: std.f2fatal("Could not open {} for reading\n", file)| `std.Ok buf:
if !std.blat(path, buf, perm)
- std.put("Could not write %s\n", file)+ std.f2put("Could not write {}\n", file);;
std.slfree(buf)
;;
@@ -84,15 +84,15 @@
match std.strrfind(man, ".")
| `std.None:
- std.fatal("manpage %s has no section\n", man)+ std.f2fatal("manpage {} has no section\n", man)| `std.Some s:
sect = s + 1
if s + 1 == man.len
- std.fatal("manpage %s missing suffix\n", man)+ std.f2fatal("manpage {} missing suffix\n", man);;
;;
- manrel = std.fmt("%s%s", opt_manpath, man[sect:])+ manrel = std.f2fmt("{}{}", opt_manpath, man[sect:])movefile(b, rm, dir, man, manrel, 0o644)
std.slfree(manrel)
}
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -96,7 +96,7 @@
findproj(b, "bld.proj")
bld.load(b)
for t in b.all
- std.put("%s\n", t)+ std.f2put("{}\n", t);;
else
findproj(b, "bld.proj")
@@ -133,7 +133,7 @@
const findproj = {b, bldfileif !findbase(b, bldfile) || !std.chdir(b.basedir)
- std.fatal("could not find %s\n", bldfile)+ std.f2fatal("could not find {}\n", bldfile);;
bld.setdir(b, "")
}
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -59,7 +59,7 @@
loadall(b, subproj, subpath)
b.basedir = curbase
else
- std.fatal("could not open %s or %s \n", subbld, subproj)+ std.f2fatal("could not open {} or {} \n", subbld, subproj);;
std.slfree(subbld)
std.slfree(subproj)
@@ -91,7 +91,7 @@
const visit = {all, b, targ, looped, markedif std.hthas(looped, targ)
- std.fatal("cycle in build depgraph involving %s\n", targ)+ std.f2fatal("cycle in build depgraph involving {}\n", targ)elif std.hthas(marked, targ)
-> all
;;
@@ -109,7 +109,7 @@
match targ
| `Bin t: -> t.libdeps
| `Lib t: -> t.libdeps
- | _: std.fatal("depending on non-library target")+ | _: std.f2fatal("depending on non-library target");;
}
@@ -123,7 +123,7 @@
p.basedir = std.sldup(basedir)
match std.slurp(path)
| `std.Ok d: p.data = d
- | `std.Fail _: std.fatal("could not open '%s'\n", path)+ | `std.Fail _: std.f2fatal("could not open '{}'\n", path);;
p.rest = p.data
-> p
@@ -145,7 +145,7 @@
ap = std.vastart(&args)
sl = std.bfmtv(buf[:], msg, ap)
- std.fput(1, "%s:%i: %s", p.fname, p.line, sl)
+ std.f2fput(1, "{}:{}: {}", p.fname, p.line, sl)std.exit(1)
}
@@ -158,7 +158,7 @@
;;
skipspace(p)
if p.rest.len > 0
- failparse(p, "junk in file near %s\n", p.rest[:std.min(p.rest.len, 10)])
+ failparse(p, "junk in file near {}\n", p.rest[:std.min(p.rest.len, 10)])-> false
;;
-> true
@@ -173,7 +173,7 @@
| `std.Some "cmd": cmdtarget(b, p, "cmd", true)
| `std.Some "man": mantarget(b, p)
| `std.Some "sub": subtarget(b, p)
- | `std.Some targtype: failparse(p, "unknown targtype type %s\n", targtype)
+ | `std.Some targtype: failparse(p, "unknown targtype type {}\n", targtype)| `std.None: -> false
;;
-> true
@@ -230,10 +230,10 @@
var gt
match wordlist(p)
- | `std.None: failparse(p, "%s target missing output files\n", cmd)
+ | `std.None: failparse(p, "{} target missing output files\n", cmd)| `std.Some out:
if iscmd && out.len != 1
- failparse(p, "%s target takes one name\n", cmd)
+ failparse(p, "{} target takes one name\n", cmd);;
outlist = out
;;
@@ -242,7 +242,7 @@
if !iscmd && matchc(p, '{')match attrlist(p)
| `std.Some al: attrs = al
- | `std.None: failparse(p, "invalid attr list for %s\n", outlist[0])
+ | `std.None: failparse(p, "invalid attr list for {}\n", outlist[0]);;
else
attrs = [][:]
@@ -250,17 +250,17 @@
skipspace(p)
if !matchc(p, '=')
- failparse(p, "expected '=' after '%s %s'\n", cmdlist, outlist[outlist.len-1])
+ failparse(p, "expected '=' after '{} {}'\n", cmdlist, outlist[outlist.len-1]);;
match wordlist(p)
- | `std.None: failparse(p, "%s target missing command\n", cmd)
+ | `std.None: failparse(p, "{} target missing command\n", cmd)| `std.Some cl:
cmdlist = cl
;;
if !matchc(p, ';') || !matchc(p, ';')
- failparse(p, "expected ';;' terminating genfile command, got %c\n", peekc(p))
+ failparse(p, "expected ';;' terminating genfile command, got {}\n", peekc(p));;
durable = false
@@ -271,9 +271,9 @@
| ("dep", depname): deplist = std.slpush(deplist, depname) | ("sys", tags): systags = std.slpush(systags, tags)| (attr, ""):
- failparse(p, "attribute %s not valid on %s targets\n", attr, cmd)
+ failparse(p, "attribute {} not valid on {} targets\n", attr, cmd)| (attr, val):
- failparse(p, "attribute %s=%s not valid on %s targets\n", attr, val, cmd)
+ failparse(p, "attribute {}={} not valid on {} targets\n", attr, val, cmd);;
;;
@@ -306,7 +306,7 @@
match word(p)
| `std.Some n: name = n
- | `std.None: failparse(p, "expected target name after '%s'\n", targ)
+ | `std.None: failparse(p, "expected target name after '{}'\n", targ);;
skipspace(p)
@@ -313,7 +313,7 @@
if matchc(p, '{')match attrlist(p)
| `std.Some al: attrs = al
- | `std.None: failparse(p, "invalid attr list for %s %s\n", targ, name)
+ | `std.None: failparse(p, "invalid attr list for {} {}\n", targ, name);;
else
attrs = [][:]
@@ -321,7 +321,7 @@
skipspace(p)
if !matchc(p, '=')
- failparse(p, "expected '=' after '%s %s'\n", targ, name)
+ failparse(p, "expected '=' after '{} {}'\n", targ, name);;
match inputlist(p)
@@ -333,12 +333,12 @@
;;
inputs = fselfin(fsel)
std.slfree(wl)
- | `std.None: failparse(p, "expected list of file names after '%s %s'\n", targ, name)
+ | `std.None: failparse(p, "expected list of file names after '{} {}'\n", targ, name);;
skipspace(p)
if !matchc(p, ';') || !matchc(p, ';')
- failparse(p, "expected ';;' terminating input list, got %c\n", peekc(p))
+ failparse(p, "expected ';;' terminating input list, got {}\n", peekc(p));;
inst = true
@@ -353,7 +353,7 @@
| ("noinst", ""): inst = false | ("sys", tags): systags = std.slpush(systags, tags)| (invalid, _):
- std.fatal("%s: got invalid attr '%s'\n", targ, invalid)+ std.f2fatal("{}: got invalid attr '{}'\n", targ, invalid);;
;;
for inc in bld.opt_incpaths
@@ -382,11 +382,11 @@
inputs = [][:]
skipspace(p)
if !matchc(p, '=')
- failparse(p, "expected '=' after '%s' target\n", targ)
+ failparse(p, "expected '=' after '{}' target\n", targ);;
match wordlist(p)
- | `std.None: failparse(p, "expected list of file names after '%s' target\n", targ)
+ | `std.None: failparse(p, "expected list of file names after '{}' target\n", targ)| `std.Some wl: inputs = wl
;;
skipspace(p)
@@ -430,7 +430,7 @@
;;
;;
if !matchc(p, '}')
- failparse(p, "expected '}' at end of attr list, got '%c'\n", peekc(p))
+ failparse(p, "expected '}' at end of attr list, got '{}'\n", peekc(p));;
if al.len == 0
-> `std.None
@@ -596,9 +596,9 @@
const addtarg = {p, b, name, targvar tn
- tn = std.fmt("%s:%s", p.fdir, name)+ tn = std.f2fmt("{}:{}", p.fdir, name)if std.hthas(b.targs, tn)
- failparse(p, "duplicate target %s\n", tn)
+ failparse(p, "duplicate target {}\n", tn);;
b.all = std.slpush(b.all, tn)
std.htput(b.targs, tn, targ)
@@ -611,10 +611,10 @@
| `std.None:
dir = std.sldup(".")lib = std.sldup(libpath)
- targ = std.fmt("%s:%s", p.fdir, lib)+ targ = std.f2fmt("{}:{}", p.fdir, lib)| `std.Some idx:
if idx == libpath.len
- std.fatal("libdep %s missing library after ':'\n")+ std.f2fatal("libdep {} missing library after ':'\n");;
/* absolute path */
if std.hasprefix(libpath, "@/") || std.hasprefix(libpath, "@:")
@@ -627,7 +627,7 @@
lib = std.sldup(libpath[idx+1:])
targ = std.pathcat(p.fdir, libpath)
if std.hasprefix(targ, "../")
- std.fatal("library %s outside of project\n", libpath)+ std.f2fatal("library {} outside of project\n", libpath);;
;;
;;
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -55,9 +55,9 @@
;;
if hastest
if ok
- std.put("TESTS PASSED\n")+ std.f2put("TESTS PASSED\n")else
- std.put("TESTS FAILED\n")+ std.f2put("TESTS FAILED\n")std.exit(1)
;;
;;
@@ -121,11 +121,11 @@
const runtest = {binvar r, log
- std.put("run %s:\t", bin)+ std.f2put("run {}:\t", bin)log = std.strcat(bin, ".log")
match std.spork([bin][:])
| `std.Fail m:
- std.fatal("unable to run test: %s\n", m)+ std.f2fatal("unable to run test: {}\n", m)| `std.Ok (pid, infd, outfd):
match std.fslurp(outfd)
| `std.Ok "": /* empty output; nothing to log */
@@ -137,8 +137,8 @@
r = false
match std.wait(pid)
- | `std.Wfailure: std.put("FAIL\n")- | `std.Wsignalled: std.put("CRASH\n")+ | `std.Wfailure: std.f2put("FAIL\n")+ | `std.Wsignalled: std.f2put("CRASH\n")| `std.Wsuccess:
std.put("PASS\n")r = true
--- a/mbld/util.myr
+++ b/mbld/util.myr
@@ -20,17 +20,17 @@
printcmd(cmd)
pid = std.fork()
if pid == -1
- std.fatal("could not fork command\n")+ std.f2fatal("could not fork command\n")elif pid == 0
if std.execvp(cmd[0], cmd) < 0
- std.fatal("failed to exec %s\n", cmd[0])+ std.f2fatal("failed to exec {}\n", cmd[0]);;
else
match std.wait(pid)
| `std.Wsuccess: /* nothing */
- | `std.Wfailure: std.fatal("FAIL: \"%s\"\n", std.strjoin(cmd, " "))- | `std.Wsignalled: std.fatal("CRASH: \"%s\"\n", std.strjoin(cmd, " "))- | `std.Waiterror: std.fatal("WAT: \"%s\"\n", std.strjoin(cmd, " "))+ | `std.Wfailure: std.f2fatal("FAIL: \"{}\"\n", std.strjoin(cmd, " "))+ | `std.Wsignalled: std.f2fatal("CRASH: \"{}\"\n", std.strjoin(cmd, " "))+ | `std.Waiterror: std.f2fatal("WAT: \"{}\"\n", std.strjoin(cmd, " "));;
;;
}
@@ -37,13 +37,13 @@
const printcmd = {lstif lst.len > 0
- std.put("\t")- std.put("%s\t", lst[0])+ std.f2put("\t")+ std.f2put("{}\t", lst[0])for l in lst[1:]
- std.put("%s ", l)+ std.f2put("{} ", l);;
;;
- std.put("\n")+ std.f2put("\n")}
const srcsplit = {src@@ -73,7 +73,7 @@
if std.hassuffix(f, suff)
f = f[:f.len - suff.len]
;;
- -> std.fmt("%s%s", f, newsuff)+ -> std.f2fmt("{}{}", f, newsuff)}
const srcswapsuffix = {src, new@@ -85,7 +85,7 @@
elif std.sleq(suff, ".s")
-> std.strcat(base, new)
else
- std.fatal("unrecognized source %s\n", src)+ std.f2fatal("unrecognized source {}\n", src);;
}
@@ -98,7 +98,7 @@
const gettarg = {tab, nmatch std.htget(tab, n)
- | `std.None: std.fatal("internal: nonexistent %s\n", n)+ | `std.None: std.f2fatal("internal: nonexistent {}\n", n)| `std.Some t: -> t
;;
}
@@ -109,12 +109,12 @@
if !std.sleq(b.curdir, dir)
p = std.pathcat(b.basedir, dir)
if b.curdir.len != 0
- std.put("Leaving directory '%s'\n", b.curdir)+ std.f2put("Leaving directory '{}'\n", b.curdir);;
- std.put("Entering directory '%s'\n", dir)+ std.f2put("Entering directory '{}'\n", dir)if !std.chdir(p)
- std.fatal("could not cd into %s\n", p)+ std.f2fatal("could not cd into {}\n", p);;
b.curdir = dir
std.slfree(p)
--
⑨