summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-06-12 12:46:50 -0400
committerOri Bernstein <ori@eigenstate.org>2015-06-12 14:01:54 -0400
commit21b91ad9fa7ae830272dc67fbe3150dc30921702 (patch)
treea674ea3e28f90ba8fa2f4521069a010b4742961e
parent96c8217e913d8d6de22bbb1aa3624c26e66838fc (diff)
downloadmc-21b91ad9fa7ae830272dc67fbe3150dc30921702.tar.gz
Move fmt to fmt2.
Shit seems to work.
-rw-r--r--libbio/bio.myr4
-rw-r--r--libregex/compile.myr72
-rw-r--r--libregex/interp.myr2
-rw-r--r--libregex/redump.myr10
-rw-r--r--libstd/blat.myr1
-rw-r--r--libstd/bld.sub3
-rw-r--r--libstd/dial+plan9.myr10
-rw-r--r--libstd/dial+posixy.myr1
-rw-r--r--libstd/execvp.myr4
-rw-r--r--libstd/fmt.myr554
-rw-r--r--libstd/fmt2.myr412
-rw-r--r--libstd/htab.myr1
-rw-r--r--libstd/intparse.myr1
-rw-r--r--libstd/optparse.myr20
-rw-r--r--libstd/pathjoin.myr2
-rw-r--r--libstd/rand.myr1
-rw-r--r--libstd/resolve+posixy.myr1
-rw-r--r--libstd/search.myr1
-rw-r--r--libstd/slput.myr1
-rw-r--r--libstd/slurp.myr1
-rw-r--r--libstd/spork.myr2
-rw-r--r--libstd/strsplit.myr1
-rw-r--r--mbld/build.myr38
-rw-r--r--mbld/clean.myr6
-rw-r--r--mbld/deps.myr34
-rw-r--r--mbld/fsel.myr10
-rw-r--r--mbld/install.myr18
-rw-r--r--mbld/main.myr4
-rw-r--r--mbld/opts.myr10
-rw-r--r--mbld/parse.myr22
-rw-r--r--mbld/test.myr12
-rw-r--r--mbld/util.myr30
-rw-r--r--test/align.myr22
-rw-r--r--test/bigcondarg.myr4
-rw-r--r--test/bigliteral.myr2
-rw-r--r--test/catfile.myr2
-rw-r--r--test/constslice.myr6
-rw-r--r--test/doublecall.myr2
-rw-r--r--test/foldidx.myr2
-rw-r--r--test/genericmake.myr2
-rw-r--r--test/loop.myr6
-rw-r--r--test/matchunion_sl.myr2
-rw-r--r--test/nestucon.myr2
-rw-r--r--test/patiter.myr4
-rw-r--r--test/strfind.myr2
-rw-r--r--test/strjoin.myr6
-rw-r--r--test/strsplit.myr6
-rw-r--r--test/strstrip.myr30
-rw-r--r--test/strtab.myr2
-rw-r--r--test/subrangefor.myr2
-rw-r--r--test/traitimpl.myr2
-rw-r--r--test/uconinit.myr2
52 files changed, 534 insertions, 863 deletions
diff --git a/libbio/bio.myr b/libbio/bio.myr
index 84344b1..ecac49f 100644
--- a/libbio/bio.myr
+++ b/libbio/bio.myr
@@ -109,7 +109,7 @@ const sysmode = {mode
| Rd: -> std.Ordonly
| Wr: -> std.Owronly
| Rw: -> std.Ordwr
- | _: std.f2fatal("bio: bad file mode")
+ | _: std.fatal("bio: bad file mode")
;;
-> 0
}
@@ -407,7 +407,7 @@ const put = {f, fmt, args
ap = std.vastart(&args)
sb = std.mksb()
- sl = std.f2fmt(fmt, &ap)
+ sl = std.fmt(fmt, &ap)
n = write(f, sl)
std.slfree(sl)
-> n
diff --git a/libregex/compile.myr b/libregex/compile.myr
index ed69432..172844d 100644
--- a/libregex/compile.myr
+++ b/libregex/compile.myr
@@ -168,21 +168,21 @@ const rtdump = {rt, ind
var l, h
indent(ind)
- std.f2put("Range (end = {}) {{\n", rt.end)
+ std.put("Range (end = {}) {{\n", rt.end)
for i = 0; i < rt.ranges.len; i++
indent(ind + 1)
(l, h) = rt.ranges[i]
- std.f2put("0x{x}-0x{x}: \n", l, h)
+ std.put("0x{x}-0x{x}: \n", l, h)
rtdump(rt.link[i], ind + 1)
;;
indent(ind)
- std.f2put("}\n")
+ std.put("}\n")
}
const indent = {ind
var i
for i = 0; i < ind; i++
- std.f2put("\t")
+ std.put("\t")
;;
}
@@ -373,28 +373,28 @@ const idump = {re
->
;;
for i = 0; i < re.proglen; i++
- std.f2put("{}:\t", i)
+ std.put("{}:\t", i)
match re.prog[i]
/* Char matching. Consume exactly one byte from the string. */
- | `Ibyte b: std.f2put("`Ibyte {} ({})\n", b, b castto(char))
+ | `Ibyte b: std.put("`Ibyte {} ({})\n", b, b castto(char))
| `Irange (start, end):
- std.f2put("`Irange ({},{})", start, end)
+ std.put("`Irange ({},{})", start, end)
if std.isalnum(start castto(char)) && std.isalnum(end castto(char))
- std.f2put("\t/* {}-{} */", start castto(char), end castto(char))
+ std.put("\t/* {}-{} */", start castto(char), end castto(char))
;;
- std.f2put("\n")
+ std.put("\n")
/* capture groups */
- | `Ilbra m: std.f2put("`Ilbra {}\n", m)
- | `Irbra m: std.f2put("`Irbra {}\n", m)
+ | `Ilbra m: std.put("`Ilbra {}\n", m)
+ | `Irbra m: std.put("`Irbra {}\n", m)
/* anchors */
- | `Ibol: std.f2put("`Ibol\n")
- | `Ieol: std.f2put("`Ieol\n")
- | `Ibow: std.f2put("`Ibow\n")
- | `Ieow: std.f2put("`Ieow\n")
+ | `Ibol: std.put("`Ibol\n")
+ | `Ieol: std.put("`Ieol\n")
+ | `Ibow: std.put("`Ibow\n")
+ | `Ieow: std.put("`Ieow\n")
/* control flow */
- | `Ifork (lip, rip): std.f2put("`Ifork ({},{})\n", lip, rip)
- | `Ijmp ip: std.f2put("`Ijmp {}\n", ip)
- | `Imatch id: std.f2put("`Imatch {}\n", id)
+ | `Ifork (lip, rip): std.put("`Ifork ({},{})\n", lip, rip)
+ | `Ijmp ip: std.put("`Ijmp {}\n", ip)
+ | `Imatch id: std.put("`Imatch {}\n", id)
;;
;;
}
@@ -407,58 +407,58 @@ const dump = {re, t, indent
->
;;
for i = 0; i < indent; i++
- std.f2put(" ")
+ std.put(" ")
;;
match t#
| `Alt (a, b):
- std.f2put("Alt\n")
+ std.put("Alt\n")
dump(re, a, indent + 1)
dump(re, b, indent + 1)
| `Cat (a, b):
- std.f2put("Cat\n")
+ std.put("Cat\n")
dump(re, a, indent + 1)
dump(re, b, indent + 1)
/* repetition */
| `Star a:
- std.f2put("Star\n")
+ std.put("Star\n")
dump(re, a, indent + 1)
| `Rstar a:
- std.f2put("Rstar\n")
+ std.put("Rstar\n")
dump(re, a, indent + 1)
| `Plus a:
- std.f2put("Plus\n")
+ std.put("Plus\n")
dump(re, a, indent + 1)
| `Rplus a:
- std.f2put("Rplus\n")
+ std.put("Rplus\n")
dump(re, a, indent + 1)
| `Quest a:
- std.f2put("Quest\n")
+ std.put("Quest\n")
dump(re, a, indent + 1)
| `Bol:
- std.f2put("Bol\n")
+ std.put("Bol\n")
| `Eol:
- std.f2put("Eol\n")
+ std.put("Eol\n")
| `Bow:
- std.f2put("Bow\n")
+ std.put("Bow\n")
| `Eow:
- std.f2put("Eow\n")
+ std.put("Eow\n")
/* end matches */
| `Byte b:
- std.f2put("Byte {}\n", b)
+ std.put("Byte {}\n", b)
| `Chr c:
- std.f2put("Char {}\n", c)
+ std.put("Char {}\n", c)
| `Ranges rl:
- std.f2put("Ranges")
+ std.put("Ranges")
for r in rl
for i = 0; i < indent + 1; i++
- std.f2put(" ")
+ std.put(" ")
;;
- std.f2put("\t({}-{})\n", r[0], r[1])
+ std.put("\t({}-{})\n", r[0], r[1])
;;
/* meta */
| `Cap (m, a):
- std.f2put("Cap {}\n", m)
+ std.put("Cap {}\n", m)
dump(re, a, indent + 1)
;;
}
diff --git a/libregex/interp.myr b/libregex/interp.myr
index efd7cf8..fc179c0 100644
--- a/libregex/interp.myr
+++ b/libregex/interp.myr
@@ -289,7 +289,7 @@ const trace : (re : regex#, thr : rethread#, msg : byte[:], args : ... -> void)
if re.debug
ap = std.vastart(&args)
- std.f2putv(msg, &ap)
+ std.putv(msg, &ap)
;;
}
diff --git a/libregex/redump.myr b/libregex/redump.myr
index 416d8a9..7f7ed40 100644
--- a/libregex/redump.myr
+++ b/libregex/redump.myr
@@ -13,7 +13,7 @@ const main = {args
cmd = std.optparse(args, &opts)
match regex.dbgcompile(cmd.args[0])
| `std.Fail m:
- std.f2fatal("unable to compile regex: {}\n", regex.failmsg(m))
+ std.fatal("unable to compile regex: {}\n", regex.failmsg(m))
| `std.Ok re:
if cmd.args.len > 1
runall(re, cmd.args)
@@ -33,7 +33,7 @@ const runall = {re, files
dump(re, fd)
bio.close(fd)
| `std.None:
- std.f2fatal("failed to open {}\n", f)
+ std.fatal("failed to open {}\n", f)
;;
;;
}
@@ -55,11 +55,11 @@ const show = {mg
match mg
| `std.Some rl:
- std.f2put("Matched: {}\n", rl[0])
+ std.put("Matched: {}\n", rl[0])
for i = 1; i < rl.len; i++
- std.f2put("group {}: {}\n", i, rl[i])
+ std.put("group {}: {}\n", i, rl[i])
;;
| `std.None:
- std.f2put("Match failed\n")
+ std.put("Match failed\n")
;;
}
diff --git a/libstd/blat.myr b/libstd/blat.myr
index 724bc90..90c0f94 100644
--- a/libstd/blat.myr
+++ b/libstd/blat.myr
@@ -1,5 +1,4 @@
use "syswrap.use"
-use "fmt.use"
pkg std =
const blat : (path : byte[:], buf : byte[:], perm : int64 -> bool)
diff --git a/libstd/bld.sub b/libstd/bld.sub
index c8cf73c..8158ce3 100644
--- a/libstd/bld.sub
+++ b/libstd/bld.sub
@@ -39,8 +39,7 @@ lib std {inc=.} =
extremum.myr
fltbits.myr
fltfmt.myr
- fmt.myr
- fmt2.myr
+ fmt.myr
getcwd.myr
getint.myr
hashfuncs.myr
diff --git a/libstd/dial+plan9.myr b/libstd/dial+plan9.myr
index 4d95f28..35d97e9 100644
--- a/libstd/dial+plan9.myr
+++ b/libstd/dial+plan9.myr
@@ -40,10 +40,10 @@ const csdial = {netdir, proto, rem
var buf : byte[Maxpath]
/* Try using the connection server */
- dir = fmt("%s/cs", netdir)
+ dir = fmt("{}/cs", netdir)
csfd = open(dir, Ordwr)
if csfd < 0
- clone = fmt("%s/%s/clone", netdir, proto)
+ clone = fmt("{}/{}/clone", netdir, proto)
ret = call(clone, rem, netdir)
slfree(clone)
if ret == -1
@@ -54,7 +54,7 @@ const csdial = {netdir, proto, rem
;;
slfree(dir)
- csaddr = fmt("%s!%s", proto, rem)
+ csaddr = fmt("{}!{}", proto, rem)
if write(csfd, csaddr) < 0
close(csfd)
-> `Fail "couldn't blah cs"
@@ -106,13 +106,13 @@ const call = {clone, addr, netdir
if n < 0
goto cleanup
;;
- fput(cfd, "connect %s", addr)
+ fput(cfd, "connect {}", addr)
name = strstrip(namebuf[:n])
match strrfind(c, "/")
| `None: die("there should be a '/' here\n")
| `Some i: base = c[:i]
;;
- dpath = bfmt(databuf[:], "%s/%s/data", base, name)
+ dpath = bfmt(databuf[:], "{}/{}/data", base, name)
datafd = open(dpath, Ordwr)
:cleanup
close(cfd)
diff --git a/libstd/dial+posixy.myr b/libstd/dial+posixy.myr
index 77920b6..e63df76 100644
--- a/libstd/dial+posixy.myr
+++ b/libstd/dial+posixy.myr
@@ -4,7 +4,6 @@ use "alloc.use"
use "chartype.use"
use "die.use"
use "endian.use"
-use "fmt.use"
use "hasprefix.use"
use "intparse.use"
use "ipparse.use"
diff --git a/libstd/execvp.myr b/libstd/execvp.myr
index 4f70e63..38d9fc5 100644
--- a/libstd/execvp.myr
+++ b/libstd/execvp.myr
@@ -21,7 +21,7 @@ const execvp = {cmd, args
| `None:
paths = getpaths()
for p in paths
- binpath = bfmt(buf[:], "%s/%s", p, cmd)
+ binpath = bfmt(buf[:], "{}/{}", p, cmd)
execv(binpath, args)
;;
slfree(paths)
@@ -39,7 +39,7 @@ const execvpe = {cmd, args, env
| `None:
paths = getpaths()
for p in paths
- binpath = bfmt(buf[:], "%s/%s", p, cmd)
+ binpath = bfmt(buf[:], "{}/{}", p, cmd)
execve(binpath, args, env)
;;
slfree(paths)
diff --git a/libstd/fmt.myr b/libstd/fmt.myr
index f78023d..1df1253 100644
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -1,10 +1,12 @@
-use sys
use "alloc.use"
use "chartype.use"
use "die.use"
use "extremum.use"
use "fltfmt.use"
+use "htab.use"
+use "hashfuncs.use"
use "introspect.use"
+use "option.use"
use "strbuf.use"
use "syswrap-ss.use"
use "syswrap.use"
@@ -12,100 +14,348 @@ use "types.use"
use "utf.use"
use "varargs.use"
-/*
- printf-like functions. These use a different syntax from the C printf,
- as described below:
-
- %s - A string, ie, a utf8 encoded byte slice.
- %t - A boolean
- %b - A byte.
- %w - A 16 bit integer
- %i - A 32 bit integer
- %l - A 64 bit integer
- %z - A size
- %p - A pointer
- %c - A char
-*/
-
pkg std =
+ /* write to fd */
const put : (fmt : byte[:], args : ... -> size)
const fput : (fd : fd, fmt : byte[:], args : ... -> size)
- const putv : (fmt : byte[:], ap : valist -> size)
- const fputv : (fd : fd, fmt : byte[:], ap : valist -> size)
+ const putv : (fmt : byte[:], ap : valist# -> size)
+ const fputv : (fd : fd, fmt : byte[:], ap : valist# -> size)
+ /* write to buffer */
const fmt : (fmt : byte[:], args : ... -> byte[:])
- const fmtv : (fmt : byte[:], ap : valist -> byte[:])
+ const fmtv : (fmt : byte[:], ap : valist# -> byte[:])
const bfmt : (buf : byte[:], fmt : byte[:], args : ... -> byte[:])
- const bfmtv : (buf : byte[:], fmt : byte[:], ap : valist -> byte[:])
+ const bfmtv : (buf : byte[:], fmt : byte[:], ap : valist# -> byte[:])
+
+ /* write to strbuf */
+ const sbfmt : (buf : strbuf#, fmt : byte[:], args : ... -> size)
+ const sbfmtv : (buf : strbuf#, fmt : byte[:], ap : valist# -> size)
+
+ /* add a formatter function */
+ const fmtinstall : (ty : byte[:], \
+ fn : (sb : strbuf#, ap : valist#, opts : byte[:] -> void) \
+ -> void)
$noret const fatal : (fmt : byte[:], args : ... -> void)
- $noret const fatalv : (fmt : byte[:], ap : valist -> void)
+ $noret const fatalv : (fmt : byte[:], ap : valist# -> void)
;;
-/* Writes a string of text up to 2 kb in size to stdout */
-const put = {fmt, args
- -> fputv(1, fmt, vastart(&args))
+/* same as 'put', but exits the program after printing */
+const fatal = {fmt, args
+ var ap
+
+ ap = vastart(&args)
+ putv(fmt, &ap)
+ exit(1)
}
-const fput = {fd, fmt, args
- -> fputv(fd, fmt, vastart(&args))
+/* same as 'putv', but exits the program after printing */
+const fatalv = {fmt, ap
+ putv(fmt, ap)
+ exit(1)
+}
+
+var fmtmapinited : bool = false
+var fmtmap : htab(byte[:], (sb : strbuf#, ap : valist#, opts : byte[:] -> void))#
+
+const fmtinstall = {ty, fn
+ if !fmtmapinited
+ fmtmapinited = true
+ fmtmap = mkht(strhash, streq)
+ ;;
+ htput(fmtmap, ty, fn)
+}
+
+const put = {fmt, args
+ var ap
+
+ ap = vastart(&args)
+ -> fputv(1, fmt, &ap)
}
const putv = {fmt, ap
-> fputv(1, fmt, ap)
}
-/* Writes a string of text up to 2kb long to stdout, using a valist
- as the source of the arguments */
-const fputv = {fd, fmt, ap
- var buf : byte[2048]
-
- -> write(fd, bfmtv(buf[:], fmt, ap))
-}
+const fput = {fd, fmt, args
+ var ap
-/* same as 'put', but exits the program after printing */
-const fatal = {fmt, args
- putv(fmt, vastart(&args))
- exit(1)
+ ap = vastart(&args)
+ -> fputv(fd, fmt, &ap)
}
-/* same as 'putv', but exits the program after printing */
-const fatalv = {fmt, ap
- putv(fmt, ap)
- exit(1)
+const fputv = {fd, fmt, ap
+ var sb, s
+
+ sb = mksb()
+ sbfmtv(sb, fmt, ap)
+ s = sbfin(sb)
+ -> writeall(fd, s)
}
-/* formats a string, allocating the slice. FIXME: calculate the
- size needed. */
const fmt = {fmt, args
- -> fmtv(fmt, vastart(&args))
+ var ap
+
+ ap = vastart(&args)
+ -> fmtv(fmt, &ap)
}
-/* formats a string, allocating the slice. FIXME: calculate the
- size needed. Takes a valist as it's last argument. */
const fmtv = {fmt, ap
- var buf
+ var sb
- buf = slalloc(2048)
- -> bfmtv(buf, fmt, ap)
+ sb = mksb()
+ sbfmtv(sb, fmt, ap)
+ -> sbfin(sb)
}
-/* formats a string of text as specified by 'fmt' into 'buf' */
const bfmt = {buf, fmt, args
- -> bfmtv(buf, fmt, vastart(&args))
+ var ap
+
+ ap = vastart(&args)
+ -> bfmtv(buf, fmt, &ap)
+}
+
+const bfmtv = {buf, fmt, ap
+ var sb
+
+ sb = mkbufsb(buf)
+ sbfmtv(sb, fmt, ap)
+ -> sbfin(sb)
+}
+
+const sbfmt = {sb, fmt, args
+ var ap
+
+ ap = vastart(&args)
+ -> sbfmtv(sb, fmt, &ap)
+}
+
+const sbfmtv = {sb, fmt, ap -> size
+ var c, params, ty
+ var nfmt, nparams
+
+ nparams = ap.tc.nelt
+ nfmt = 0
+ if !fmtmapinited
+ fmtmapinited = true
+ fmtmap = mkht(strhash, streq)
+ ;;
+ while fmt.len != 0
+ (c, fmt) = striter(fmt)
+ match c
+ | '{':
+ if decode(fmt) == '{'
+ (c, fmt) = striter(fmt)
+ sbputc(sb, '{')
+ else
+ (params, fmt) = getparams(fmt)
+ nfmt++
+ if nfmt > nparams
+ die("too few params for fmt\n")
+ ;;
+
+ ty = vatype(ap)
+ match htget(fmtmap, ty)
+ | `Some func:
+ func(sb, ap, params)
+ | `None:
+ fallbackfmt(sb, params, ty, ap)
+ ;;
+ ;;
+ | '}':
+ if decode(fmt) == '}'
+ sbputc(sb, '}')
+ ;;
+ | chr:
+ sbputc(sb, chr)
+ ;;
+:fmtdone
+ ;;
+ if nfmt != nparams
+ die("too many params for fmt\n")
+ ;;
+ -> sb.len
+}
+
+const fallbackfmt = {sb, params, tyenc, ap : valist# -> void
+ /* value types */
+ var t_val : bool
+ var b_val : int8, ub_val : uint8
+ var w_val : int16, uw_val : uint16
+ var i_val : int32, ui_val : uint32
+ var l_val : int64, ul_val : uint64
+ var z_val : size
+ var p_val : byte#
+ var c_val : char
+ var s_val : byte[:]
+ var f32_val : flt32, f64_val : flt64
+ var i8 : int8, i16: int16, i32 : int32
+ var by : byte
+ var i : int, i64 : int64, l : long
+ var ui8 : int8, ui16: int16, ui32 : int32
+ var ui : int, ui64 : int64, ul : long
+
+ match typedesc(tyenc)
+ | `Tynone: /* nothing */
+ /* atomic types */
+ | `Tyvoid:
+ sbputs(sb, "void")
+ | `Tybool:
+ t_val = vanext(ap)
+ if t_val
+ sbputs(sb ,"true")
+ else
+ sbputs(sb, "false")
+ ;;
+ | `Tychar:
+ c_val = vanext(ap)
+ sbputc(sb, c_val)
+ | `Tyint8:
+ b_val = vanext(ap)
+ intfmt(sb, intparams(params), true, b_val)
+ | `Tyint16:
+ w_val = vanext(ap)
+ intfmt(sb, intparams(params), true, w_val)
+ | `Tyint:
+ i_val = vanext(ap)
+ intfmt(sb, intparams(params), true, i_val)
+ | `Tyint32:
+ i_val = vanext(ap)
+ intfmt(sb, intparams(params), true, i_val)
+ | `Tyint64:
+ l_val = vanext(ap)
+ intfmt(sb, intparams(params), true, l_val)
+ | `Tylong:
+ l_val = vanext(ap)
+ intfmt(sb, intparams(params), true, l_val)
+
+ | `Tybyte:
+ ub_val = vanext(ap)
+ intfmt(sb, intparams(params), false, ub_val)
+ | `Tyuint8:
+ ub_val = vanext(ap)
+ intfmt(sb, intparams(params), false, ub_val)
+ | `Tyuint16:
+ w_val = vanext(ap)
+ intfmt(sb, intparams(params), false, uw_val)
+ | `Tyuint:
+ i_val = vanext(ap)
+ intfmt(sb, intparams(params), false, ui_val)
+ | `Tyuint32:
+ i_val = vanext(ap)
+ intfmt(sb, intparams(params), false, ui_val)
+ | `Tyuint64:
+ l_val = vanext(ap)
+ intfmt(sb, intparams(params), false, ul_val)
+ | `Tyulong:
+ l_val = vanext(ap)
+ intfmt(sb, intparams(params), false, ul_val)
+ | `Tyflt32:
+ f32_val = vanext(ap)
+ flt32bfmt(sb, f32_val, MNormal, 0)
+ | `Tyflt64:
+ f64_val = vanext(ap)
+ flt64bfmt(sb, f64_val, MNormal, 0)
+ | `Tyvalist:
+ sbputs(sb, "...")
+
+ /* compound types */
+ | `Typtr desc:
+ p_val = vanext(ap)
+ sbputs(sb, "0x")
+ intfmt(sb, \
+ [.base=16, .padto=2*sizeof(void#), .padfill='0'], \
+ false, p_val castto(intptr))
+ | `Tyslice desc:
+ match typedesc(desc)
+ | `Tybyte:
+ s_val = vanext(ap)
+ sbputs(sb, s_val)
+ | _:
+ sbputs(sb, "slice[:]")
+ ;;
+ | `Tyfunc tc:
+ p_val = vanext(ap)
+ sbputs(sb, "func{")
+ intfmt(sb, \
+ [.base=16, .padto=2*sizeof(void#), .padfill='0'], \
+ false, p_val castto(intptr))
+ sbputs(sb, "}")
+ | `Tyarray (sz, data):
+ sbputs(sb, "array")
+ /* aggregate types */
+ | `Tytuple typecursor:
+ vabytes(ap)
+ sbputs(sb, "tuple")
+ | `Tystruct namecursor:
+ vabytes(ap)
+ sbputs(sb, "struct")
+ | `Tyunion namecursor:
+ vabytes(ap)
+ sbputs(sb, "union")
+ | `Tyname (name, desc):
+ fallbackfmt(sb, params, desc, ap)
+ ;;
+}
+
+type intparams = struct
+ base : size
+ padto : size
+ padfill : char
+;;
+
+const getparams = {fmt
+ var i
+
+ for i = 0; i < fmt.len; i++
+ if fmt[i] == '}' castto(byte)
+ goto foundparams
+ ;;
+ ;;
+ die("invalid format string")
+:foundparams
+ -> (fmt[:i], fmt[i+1:])
+}
+
+const intparams = {params
+ var ip : intparams
+ var c
+
+ ip = [
+ .base = 10,
+ .padfill = ' ',
+ .padto = 0
+ ]
+
+ while params.len > 0
+ (c, params) = striter(params)
+ match c
+ | 'x': ip.base = 16
+ | '0': ip.padfill = '0'
+ | chr:
+ while isdigit(c)
+ ip.padto = ip.padto*10 + charval(c, 10)
+ (c, params) = striter(params)
+ ;;
+ ;;
+ ;;
+ -> ip
+
}
const digitchars = [
- '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
+ '0','1','2','3','4',
+ '5','6','7','8','9',
+ 'a','b','c','d','e','f'
]
-generic intfmt = {buf : byte[:], bits : @a::(integral,numeric), base, signed, padto, padfill
+generic intfmt = {sb, opts, signed, bits : @a::(integral,numeric)
var isneg
var val
var b : char[32]
- var i, j, n, npad
+ var i, j, npad
+ var base
- n = 0
- i = 0
+ base = opts.base castto(uint64)
if signed && bits < 0
val = -bits castto(uint64)
isneg = true
@@ -115,6 +365,7 @@ generic intfmt = {buf : byte[:], bits : @a::(integral,numeric), base, signed, pa
isneg = false
;;
+ i = 0
if val == 0
b[0] = '0'
i++
@@ -125,192 +376,35 @@ generic intfmt = {buf : byte[:], bits : @a::(integral,numeric), base, signed, pa
i++
;;
- npad = clamp(padto - i, 0, padto)
- n = 0
+ npad = clamp(opts.padto - i, 0, opts.padto)
if isneg
npad--
;;
- if padfill == '0' && isneg && n < buf.len
- n += encode(buf[n:], '-')
+ if opts.padfill == '0' && isneg
+ sbputc(sb, '-')
;;
- for j = 0; j < min(npad, buf.len); j++
- if n >= buf.len
- break
- ;;
- n += encode(buf[n:], padfill)
+ for j = 0; j < npad; j++
+ sbputc(sb, opts.padfill)
;;
- if padfill != '0' && isneg && n < buf.len
- n += encode(buf[n:], '-')
+ if opts.padfill != '0' && isneg
+ sbputc(sb, '-')
;;
for j = i; j != 0; j--
- if n >= buf.len
- break
- ;;
- n += encode(buf[n:], b[j - 1])
+ sbputc(sb, b[j - 1])
;;
- -> n
}
-/* formats a string of text as specified by 'fmt' into 'buf',
- using a valist for the arguments */
-const bfmtv = {buf, fmt, ap
- var b
- var c
- var n
- var padto
- var base
- var signed, padfill
- var s_val : byte[:]
- var t_val : bool
- var b_val : int8, ub_val : uint8
- var w_val : int16, uw_val : uint16
- var i_val : int32, ui_val : uint32
- var l_val : int64, ul_val : uint64
- var z_val : size
- var p_val : byte#
- var c_val : char
- var f_val : flt64, F_val : flt32
- var sb
+const writeall = {fd, buf
+ var n, len
- n = 0
- while fmt.len != 0
- (c, fmt) = striter(fmt)
- if c == '%'
- base = 10
- padto = 0
- signed = true
- padfill = ' '
- (c, fmt) = striter(fmt)
- /* modifiers */
- while fmt.len > 0
- match c
- | 'x':
- (c, fmt) = striter(fmt)
- base = 16
- signed = false
-
- | 'u':
- (c, fmt) = striter(fmt)
- signed = false
- | '0':
- (c, fmt) = striter(fmt)
- padfill = '0'
- | _: /* nothing */
- ;;
- if isdigit(c) && padto == 0
- /*
- We can't get a 0 on the first iteration, since
- that was matched above. So, no special checks
- for nonzero on the first iteration.
- */
- padto = 0
- while isdigit(c)
- padto = padto*10 + charval(c, 10)
- (c, fmt) = striter(fmt)
- ;;
- else
- break
- ;;
- ;;
- /* format specifiers */
- match c
- | 's':
- s_val = vanext(&ap)
- n += strfmt(buf[n:], s_val, padto, padfill)
- | 't':
- t_val = vanext(&ap)
- n += boolfmt(buf[n:], t_val, padto, padfill)
- | 'f':
- f_val = vanext(&ap)
- b = buf[n:]
- sb = mkbufsb(b)
- flt64bfmt(sb, f_val, 0, b.len)
- n += sb.len
- strfmt(buf[n:], sbfin(sb), 0, ' ')
- | 'F':
- F_val = vanext(&ap)
- b = buf[n:]
- sb = mkbufsb(b)
- flt64bfmt(sb, F_val castto(flt64), 0, b.len)
- n += sb.len
- strfmt(buf[n:], sbfin(sb), 0, ' ')
- /* format integers */
- | 'b':
- if signed
- b_val = vanext(&ap)
- n += intfmt(buf[n:], b_val, base, signed, padto, padfill)
- else
- ub_val = vanext(&ap)
- n += intfmt(buf[n:], ub_val, base, signed, padto, padfill)
- ;;
- | 'w':
- if signed
- w_val = vanext(&ap)
- n += intfmt(buf[n:], w_val, base, signed, padto, padfill)
- else
- uw_val = vanext(&ap)
- n += intfmt(buf[n:], uw_val, base, signed, padto, padfill)
- ;;
- | 'i':
- if signed
- i_val = vanext(&ap)
- n += intfmt(buf[n:], i_val, base, signed, padto, padfill)
- else
- ui_val = vanext(&ap)
- n += intfmt(buf[n:], ui_val, base, signed, padto, padfill)
- ;;
- | 'l':
- if signed
- l_val = vanext(&ap)
- n += intfmt(buf[n:], l_val, base, signed, padto, padfill)
- else
- ul_val = vanext(&ap)
- n += intfmt(buf[n:], ul_val, base, signed, padto, padfill)
- ;;
-
- | 'z':
- z_val = vanext(&ap)
- n += intfmt(buf[n:], z_val castto(int64), base, signed, padto, padfill)
- | 'p':
- p_val = vanext(&ap)
- n += intfmt(buf[n:], p_val castto(int64), 16, false, padto, padfill)
- | 'c':
- c_val = vanext(&ap)
- n += encode(buf[n:], c_val)
- | '%':
- n += encode(buf[n:], '%')
- | _:
- die("Unknown format specifier\n")
- ;;
- else
- n += encode(buf[n:], c)
+ len = 0
+ while true
+ n = write(fd, buf)
+ if n <= 0 || n >= len
+ break
;;
+ len += n
;;
- -> buf[:n]
-}
-
-const strfmt = {buf, str, padto, padfill
- var i, n, npad
-
- n = 0
- npad = clamp(padto - str.len, 0, padto)
- for i = 0; i < padto - str.len; i++
- n += encode(buf[n:], padfill)
- ;;
- for i = 0; i < min(str.len, buf.len); i++
- buf[n++] = str[i]
- ;;
- -> n
-}
-
-const boolfmt = {buf, val, padto, padfill
- var s
-
- if val
- s = "true"
- else
- s = "false"
- ;;
- -> strfmt(buf, s, padto, padfill)
+ -> len
}
diff --git a/libstd/fmt2.myr b/libstd/fmt2.myr
deleted file mode 100644
index bc1de45..0000000
--- a/libstd/fmt2.myr
+++ /dev/null
@@ -1,412 +0,0 @@
-use "alloc.use"
-use "chartype.use"
-use "die.use"
-use "extremum.use"
-use "fltfmt.use"
-use "htab.use"
-use "hashfuncs.use"
-use "introspect.use"
-use "option.use"
-use "strbuf.use"
-use "syswrap-ss.use"
-use "syswrap.use"
-use "types.use"
-use "utf.use"
-use "varargs.use"
-
-use "fmt.use" /* FOR DEBUGGING */
-
-pkg std =
- /* write to fd */
- const f2put : (fmt : byte[:], args : ... -> size)
- const f2fput : (fd : fd, fmt : byte[:], args : ... -> size)
- const f2putv : (fmt : byte[:], ap : valist# -> size)
- const f2fputv : (fd : fd, fmt : byte[:], ap : valist# -> size)
-
- /* write to buffer */
- const f2fmt : (fmt : byte[:], args : ... -> byte[:])
- const f2fmtv : (fmt : byte[:], ap : valist# -> byte[:])
- const f2bfmt : (buf : byte[:], fmt : byte[:], args : ... -> byte[:])
- const f2bfmtv : (buf : byte[:], fmt : byte[:], ap : valist# -> byte[:])
-
- /* write to strbuf */
- const f2sbfmt : (buf : strbuf#, fmt : byte[:], args : ... -> size)
- const f2sbfmtv : (buf : strbuf#, fmt : byte[:], ap : valist# -> size)
-
- /* add a formatter function */
- const f2fmtinstall : (ty : byte[:], \
- fn : (sb : strbuf#, ap : valist#, opts : byte[:] -> void) \
- -> void)
-
- $noret const f2fatal : (fmt : byte[:], args : ... -> void)
- $noret const f2fatalv : (fmt : byte[:], ap : valist# -> void)
-;;
-
-/* same as 'put', but exits the program after printing */
-const f2fatal = {fmt, args
- var ap
-
- ap = vastart(&args)
- f2putv(fmt, &ap)
- exit(1)
-}
-
-/* same as 'putv', but exits the program after printing */
-const f2fatalv = {fmt, ap
- f2putv(fmt, ap)
- exit(1)
-}
-
-var fmtmapinited : bool = false
-var fmtmap : htab(byte[:], (sb : strbuf#, ap : valist#, opts : byte[:] -> void))#
-
-const f2fmtinstall = {ty, fn
- if !fmtmapinited
- fmtmapinited = true
- fmtmap = mkht(strhash, streq)
- ;;
- htput(fmtmap, ty, fn)
-}
-
-const f2put = {fmt, args
- var ap
-
- ap = vastart(&args)
- -> f2fputv(1, fmt, &ap)
-}
-
-const f2putv = {fmt, ap
- -> f2fputv(1, fmt, ap)
-}
-
-const f2fput = {fd, fmt, args
- var ap
-
- ap = vastart(&args)
- -> f2fputv(fd, fmt, &ap)
-}
-
-const f2fputv = {fd, fmt, ap
- var sb, s
-
- sb = mksb()
- f2sbfmtv(sb, fmt, ap)
- s = sbfin(sb)
- -> writeall(fd, s)
-}
-
-const f2fmt = {fmt, args
- var ap
-
- ap = vastart(&args)
- -> f2fmtv(fmt, &ap)
-}
-
-const f2fmtv = {fmt, ap
- var sb
-
- sb = mksb()
- f2sbfmtv(sb, fmt, ap)
- -> sbfin(sb)
-}
-
-const f2bfmt = {buf, fmt, args
- var ap
-
- ap = vastart(&args)
- -> f2bfmtv(buf, fmt, &ap)
-}
-
-const f2bfmtv = {buf, fmt, ap
- var sb
-
- sb = mkbufsb(buf)
- f2sbfmtv(sb, fmt, ap)
- -> sbfin(sb)
-}
-
-const f2sbfmt = {sb, fmt, args
- var ap
-
- ap = vastart(&args)
- -> f2sbfmtv(sb, fmt, &ap)
-}
-
-const f2sbfmtv = {sb, fmt, ap -> size
- var c, params, ty
- var nfmt, nparams
-
- nparams = ap.tc.nelt
- nfmt = 0
- if !fmtmapinited
- fmtmapinited = true
- fmtmap = mkht(strhash, streq)
- ;;
- while fmt.len != 0
- (c, fmt) = striter(fmt)
- match c
- | '{':
- if decode(fmt) == '{'
- (c, fmt) = striter(fmt)
- sbputc(sb, '{')
- else
- (params, fmt) = f2getparams(fmt)
- nfmt++
- if nfmt > nparams
- die("too few params for fmt\n")
- ;;
-
- ty = vatype(ap)
- match htget(fmtmap, ty)
- | `Some func:
- func(sb, ap, params)
- | `None:
- fallbackfmt(sb, params, ty, ap)
- ;;
- ;;
- | '}':
- if decode(fmt) == '}'
- sbputc(sb, '}')
- ;;
- | chr:
- sbputc(sb, chr)
- ;;
-:fmtdone
- ;;
- if nfmt != nparams
- die("too many params for fmt\n")
- ;;
- -> sb.len
-}
-
-const fallbackfmt = {sb, params, tyenc, ap : valist# -> void
- /* value types */
- var t_val : bool
- var b_val : int8, ub_val : uint8
- var w_val : int16, uw_val : uint16
- var i_val : int32, ui_val : uint32
- var l_val : int64, ul_val : uint64
- var z_val : size
- var p_val : byte#
- var c_val : char
- var s_val : byte[:]
- var f32_val : flt32, f64_val : flt64
- var i8 : int8, i16: int16, i32 : int32
- var by : byte
- var i : int, i64 : int64, l : long
- var ui8 : int8, ui16: int16, ui32 : int32
- var ui : int, ui64 : int64, ul : long
-
- match typedesc(tyenc)
- | `Tynone: /* nothing */
- /* atomic types */
- | `Tyvoid:
- sbputs(sb, "void")
- | `Tybool:
- t_val = vanext(ap)
- if t_val
- sbputs(sb ,"true")
- else
- sbputs(sb, "false")
- ;;
- | `Tychar:
- c_val = vanext(ap)
- sbputc(sb, c_val)
- | `Tyint8:
- b_val = vanext(ap)
- intfmt(sb, intparams(params), true, b_val)
- | `Tyint16:
- w_val = vanext(ap)
- intfmt(sb, intparams(params), true, w_val)
- | `Tyint:
- i_val = vanext(ap)
- intfmt(sb, intparams(params), true, i_val)
- | `Tyint32:
- i_val = vanext(ap)
- intfmt(sb, intparams(params), true, i_val)
- | `Tyint64:
- l_val = vanext(ap)
- intfmt(sb, intparams(params), true, l_val)
- | `Tylong:
- l_val = vanext(ap)
- intfmt(sb, intparams(params), true, l_val)
-
- | `Tybyte:
- ub_val = vanext(ap)
- intfmt(sb, intparams(params), false, ub_val)
- | `Tyuint8:
- ub_val = vanext(ap)
- intfmt(sb, intparams(params), false, ub_val)
- | `Tyuint16:
- w_val = vanext(ap)
- intfmt(sb, intparams(params), false, uw_val)
- | `Tyuint:
- i_val = vanext(ap)
- intfmt(sb, intparams(params), false, ui_val)
- | `Tyuint32:
- i_val = vanext(ap)
- intfmt(sb, intparams(params), false, ui_val)
- | `Tyuint64:
- l_val = vanext(ap)
- intfmt(sb, intparams(params), false, ul_val)
- | `Tyulong:
- l_val = vanext(ap)
- intfmt(sb, intparams(params), false, ul_val)
- | `Tyflt32:
- f32_val = vanext(ap)
- flt32bfmt(sb, f32_val, MNormal, 0)
- | `Tyflt64:
- f64_val = vanext(ap)
- flt64bfmt(sb, f64_val, MNormal, 0)
- | `Tyvalist:
- sbputs(sb, "...")
-
- /* compound types */
- | `Typtr desc:
- p_val = vanext(ap)
- sbputs(sb, "0x")
- intfmt(sb, \
- [.base=16, .padto=2*sizeof(void#), .padfill='0'], \
- false, p_val castto(intptr))
- | `Tyslice desc:
- match typedesc(desc)
- | `Tybyte:
- s_val = vanext(ap)
- sbputs(sb, s_val)
- | _:
- sbputs(sb, "slice[:]")
- ;;
- | `Tyfunc tc:
- p_val = vanext(ap)
- sbputs(sb, "func{")
- intfmt(sb, \
- [.base=16, .padto=2*sizeof(void#), .padfill='0'], \
- false, p_val castto(intptr))
- sbputs(sb, "}")
- | `Tyarray (sz, data):
- sbputs(sb, "array")
- /* aggregate types */
- | `Tytuple typecursor:
- vabytes(ap)
- sbputs(sb, "tuple")
- | `Tystruct namecursor:
- vabytes(ap)
- sbputs(sb, "struct")
- | `Tyunion namecursor:
- vabytes(ap)
- sbputs(sb, "union")
- | `Tyname (name, desc):
- fallbackfmt(sb, params, desc, ap)
- ;;
-}
-
-type intparams = struct
- base : size
- padto : size
- padfill : char
-;;
-
-const f2getparams = {fmt
- var i
-
- for i = 0; i < fmt.len; i++
- if fmt[i] == '}' castto(byte)
- goto foundparams
- ;;
- ;;
- die("invalid format string")
-:foundparams
- -> (fmt[:i], fmt[i+1:])
-}
-
-const intparams = {params
- var ip : intparams
- var c
-
- ip = [
- .base = 10,
- .padfill = ' ',
- .padto = 0
- ]
-
- while params.len > 0
- (c, params) = striter(params)
- match c
- | 'x': ip.base = 16
- | '0': ip.padfill = '0'
- | chr:
- while isdigit(c)
- ip.padto = ip.padto*10 + charval(c, 10)
- (c, params) = striter(params)
- ;;
- ;;
- ;;
- -> ip
-
-}
-
-const digitchars = [
- '0','1','2','3','4',
- '5','6','7','8','9',
- 'a','b','c','d','e','f'
-]
-generic intfmt = {sb, opts, signed, bits : @a::(integral,numeric)
- var isneg
- var val
- var b : char[32]
- var i, j, npad
- var base
-
- base = opts.base castto(uint64)
- if signed && bits < 0
- val = -bits castto(uint64)
- isneg = true
- else
- val = bits castto(uint64)
- val &= ~0 >> (8*(sizeof(uint64)-sizeof(@a)))
- isneg = false
- ;;
-
- i = 0
- if val == 0
- b[0] = '0'
- i++
- ;;
- while val != 0
- b[i] = digitchars[val % base]
- val /= base
- i++
- ;;
-
- npad = clamp(opts.padto - i, 0, opts.padto)
- if isneg
- npad--
- ;;
- if opts.padfill == '0' && isneg
- sbputc(sb, '-')
- ;;
- for j = 0; j < npad; j++
- sbputc(sb, opts.padfill)
- ;;
- if opts.padfill != '0' && isneg
- sbputc(sb, '-')
- ;;
- for j = i; j != 0; j--
- sbputc(sb, b[j - 1])
- ;;
-}
-
-const writeall = {fd, buf
- var n, len
-
- len = 0
- while true
- n = write(fd, buf)
- if n <= 0 || n >= len
- break
- ;;
- len += n
- ;;
- -> len
-}
-
diff --git a/libstd/htab.myr b/libstd/htab.myr
index c8cb694..e9880b9 100644
--- a/libstd/htab.myr
+++ b/libstd/htab.myr
@@ -1,7 +1,6 @@
use "alloc.use"
use "die.use"
use "extremum.use"
-use "fmt.use"
use "option.use"
use "types.use"
diff --git a/libstd/intparse.myr b/libstd/intparse.myr
index 685c6cd..4180f8c 100644
--- a/libstd/intparse.myr
+++ b/libstd/intparse.myr
@@ -1,6 +1,5 @@
use "chartype.use"
use "die.use"
-use "fmt.use"
use "hasprefix.use"
use "option.use"
use "types.use"
diff --git a/libstd/optparse.myr b/libstd/optparse.myr
index 888b72f..cd22801 100644
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -1,7 +1,7 @@
use "alloc.use"
use "die.use"
use "extremum.use"
-use "fmt2.use"
+use "fmt.use"
use "option.use"
use "sleq.use"
use "slpush.use"
@@ -62,7 +62,7 @@ const optparse = {args, def
parsed.opts = slpush(parsed.opts, optnext(&ctx))
;;
if ctx.args.len < def.minargs
- f2put("error: expected at least {} args, got {}\n", def.minargs, ctx.args.len)
+ put("error: expected at least {} args, got {}\n", def.minargs, ctx.args.len)
optusage(ctx.optargs[0], ctx.optdef)
exit(1)
;;
@@ -97,7 +97,7 @@ const optnext = {ctx
optusage(ctx.optargs[0], ctx.optdef)
exit(0)
else
- f2fatal("unexpected argument '{}'\n", c)
+ fatal("unexpected argument '{}'\n", c)
;;
| `Some (true, needed):
/* -arg => '-a' 'rg' */
@@ -111,7 +111,7 @@ const optnext = {ctx
ctx.argidx++
next(ctx)
elif needed
- f2put("Expected argument for {}\n", c)
+ put("Expected argument for {}\n", c)
exit(1)
;;
| `Some (false, _):
@@ -162,15 +162,15 @@ const next = {ctx
}
const optusage = {prog, def
- std.f2put("usage: {} [-h?] ", prog)
+ std.put("usage: {} [-h?] ", prog)
for o in def.opts
- std.f2put("[-{}{}{}] ", o.opt, sep(o.arg), o.arg)
+ std.put("[-{}{}{}] ", o.opt, sep(o.arg), o.arg)
;;
- std.f2put("{}\n", def.argdesc)
- std.f2put("\t-h\tprint this help message\n")
- std.f2put("\t-?\tprint this help message\n")
+ std.put("{}\n", def.argdesc)
+ std.put("\t-h\tprint this help message\n")
+ std.put("\t-?\tprint this help message\n")
for o in def.opts
- std.f2put("\t-{}{}{}\t{}\n", o.opt, sep(o.arg), o.arg, o.desc)
+ std.put("\t-{}{}{}\t{}\n", o.opt, sep(o.arg), o.arg, o.desc)
;;
}
diff --git a/libstd/pathjoin.myr b/libstd/pathjoin.myr
index 3e05905..f9df8aa 100644
--- a/libstd/pathjoin.myr
+++ b/libstd/pathjoin.myr
@@ -92,7 +92,7 @@ const pathnorm = {p
;;
;;
s = strjoin(comps[i:], "/")
- ret = fmt("/%s", s)
+ ret = fmt("/{}", s)
slfree(s)
elif comps.len == 0
ret = sldup(".")
diff --git a/libstd/rand.myr b/libstd/rand.myr
index 06599d6..2e8c73e 100644
--- a/libstd/rand.myr
+++ b/libstd/rand.myr
@@ -1,5 +1,4 @@
use "die.use"
-use "fmt.use"
use "types.use"
use "alloc.use"
/*
diff --git a/libstd/resolve+posixy.myr b/libstd/resolve+posixy.myr
index 3a4fc42..e4cf555 100644
--- a/libstd/resolve+posixy.myr
+++ b/libstd/resolve+posixy.myr
@@ -5,7 +5,6 @@ use "die.use"
use "endian.use"
use "result.use"
use "extremum.use"
-use "fmt.use"
use "hashfuncs.use"
use "htab.use"
use "ipparse.use"
diff --git a/libstd/search.myr b/libstd/search.myr
index 26b9870..725e419 100644
--- a/libstd/search.myr
+++ b/libstd/search.myr
@@ -1,6 +1,5 @@
use "cmp.use"
use "option.use"
-use "fmt.use"
pkg std =
generic lsearch : (sl : @t[:], val : @t, cmp : (a : @t, b : @t -> order) -> option(@idx::(integral,numeric)))
diff --git a/libstd/slput.myr b/libstd/slput.myr
index c1a7d33..88dc875 100644
--- a/libstd/slput.myr
+++ b/libstd/slput.myr
@@ -1,7 +1,6 @@
use "types.use"
use "alloc.use"
use "die.use"
-use "fmt.use"
pkg std =
generic slput : (sl : @a[:], idx : size, elt : @a -> @a[:])
diff --git a/libstd/slurp.myr b/libstd/slurp.myr
index c4ebb2c..8636f40 100644
--- a/libstd/slurp.myr
+++ b/libstd/slurp.myr
@@ -2,7 +2,6 @@ use "alloc.use"
use "die.use"
use "result.use"
use "extremum.use"
-use "fmt.use"
use "syswrap.use"
use "types.use"
diff --git a/libstd/spork.myr b/libstd/spork.myr
index f728768..64e8fce 100644
--- a/libstd/spork.myr
+++ b/libstd/spork.myr
@@ -53,7 +53,7 @@ const sporkfd = {cmd, infd, outfd
close(infd)
close(outfd)
execvp(cmd[0], cmd) < 0
- fatal("failed to exec %s\n")
+ fatal("failed to exec {}\n", cmd[0])
/* parent */
else
-> `Ok pid
diff --git a/libstd/strsplit.myr b/libstd/strsplit.myr
index b09e8c8..e64d907 100644
--- a/libstd/strsplit.myr
+++ b/libstd/strsplit.myr
@@ -1,7 +1,6 @@
use "alloc.use"
use "die.use"
use "extremum.use"
-use "fmt.use"
use "option.use"
use "slpush.use"
use "strfind.use"
diff --git a/mbld/build.myr b/mbld/build.myr
index 1a508ba..295e4e8 100644
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -52,7 +52,7 @@ const build = {b, targ
| `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.f2fatal("invalid target {}\n", targ)
+ | `std.None: std.fatal("invalid target {}\n", targ)
;;
-> true
}
@@ -67,10 +67,10 @@ const buildbin = {b, targ, addsrc
setdir(b, targ.dir)
addincludes(b, targ)
- std.f2put("{}...\n", targ.name)
+ std.put("{}...\n", targ.name)
dg = myrdeps(b, targ, false, addsrc)
if !std.hthas(dg.deps, targ.name)
- std.f2fatal("no input files for {}\n", targ.name)
+ std.fatal("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 @@ const buildlib = {b, targ
setdir(b, targ.dir)
addincludes(b, targ)
lib = targ.name
- std.f2put("lib{}.a...\n", lib)
- archive = std.f2fmt("lib{}.a", lib)
+ std.put("lib{}.a...\n", lib)
+ archive = std.fmt("lib{}.a", lib)
dg = myrdeps(b, targ, false, false)
if !std.hthas(dg.deps, lib)
- std.f2fatal("no target declared for {}\n", lib)
+ std.fatal("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 @@ const builddep = {b, dg, out, incs
;;
| `std.None:
if !std.fexists(d)
- std.f2fatal("no input file {}\n", d)
+ std.fatal("no input file {}\n", d)
;;
;;
if !isfresh(d, out)
@@ -204,7 +204,7 @@ const compile = {src, incs
run(cmd)
std.slfree(o)
else
- std.f2fatal("Unknown file type for {}\n", src)
+ std.fatal("Unknown file type for {}\n", src)
;;
}
@@ -257,7 +257,7 @@ const archivelib = {dg, lib, files, incs
for c in config.Arcmd
cmd = std.slpush(cmd, std.sldup(c))
;;
- cmd = std.slpush(cmd, std.f2fmt("lib{}.a", lib))
+ cmd = std.slpush(cmd, std.fmt("lib{}.a", lib))
for f in files
obj = srcswapsuffix(f, config.Objsuffix)
cmd = std.slpush(cmd, obj)
@@ -277,7 +277,7 @@ const mergeuse = {dg, lib, files, incs
if std.hassuffix(f, ".myr")
cmd = std.slpush(cmd, srcswapsuffix(f, ".use"))
elif !std.hassuffix(f, ".s")
- std.f2fatal("unknown file type for {}\n", f)
+ std.fatal("unknown file type for {}\n", f)
;;
;;
run(cmd)
@@ -293,7 +293,7 @@ const addlibs = {cmd, libgraph, incs
/* -L incpath... */
if !config.Directlib
for inc in incs
- cmd = std.slpush(cmd, std.f2fmt("-L{}", inc))
+ cmd = std.slpush(cmd, std.fmt("-L{}", inc))
;;
;;
@@ -311,7 +311,7 @@ const addlibs = {cmd, libgraph, incs
const visit = {cmd, head, g, lib, looped, marked, incs
if std.hthas(looped, lib)
- std.f2fatal("cycle in library graph involving \"{}\"\n", lib)
+ std.fatal("cycle in library graph involving \"{}\"\n", lib)
elif std.hthas(marked, lib)
-> cmd
;;
@@ -327,11 +327,11 @@ const visit = {cmd, head, g, lib, looped, marked, incs
const putlib = {cmd, head, lib, incs
if !config.Directlib
- -> std.slput(cmd, head, std.f2fmt("-l", lib))
+ -> std.slput(cmd, head, std.fmt("-l{}", lib))
else
match findlib(lib, incs)
| `std.None:
- std.f2fatal("could not find library lib{}.a\n", lib)
+ std.fatal("could not find library lib{}.a\n", lib)
| `std.Some p:
-> std.slput(cmd, head, p)
;;
@@ -342,7 +342,7 @@ const findlib = {lib, incs
var buf : byte[512]
var sl, p
- sl = std.bfmt(buf[:], "lib%s.a", lib)
+ sl = std.bfmt(buf[:], "lib{}.a", lib)
for i in incs
p = std.pathcat(i, sl)
if std.fexists(p)
@@ -366,10 +366,10 @@ const freshlibs = {targ, libgraph
;;
std.slfree(lib)
| `std.None:
- std.f2fput(1, "{}: could not find library lib{}.a\n", targ.name, l)
- std.f2fput(1, "searched:\n")
+ std.fput(1, "{}: could not find library lib{}.a\n", targ.name, l)
+ std.fput(1, "searched:\n")
for inc in targ.incpath
- std.f2fput(1, "\t{}\n", inc)
+ std.fput(1, "\t{}\n", inc)
;;
std.exit(1)
;;
@@ -401,7 +401,7 @@ const isfresh = {src, dst
*/
match std.fmtime(src)
| `std.Some mt: srcmt = mt
- | `std.None: std.f2fatal("could not stat {}\n", src)
+ | `std.None: std.fatal("could not stat {}\n", src)
;;
match std.fmtime(dst)
| `std.Some mt: dstmt = mt
diff --git a/mbld/clean.myr b/mbld/clean.myr
index 6f4fb2f..02d9a8f 100644
--- a/mbld/clean.myr
+++ b/mbld/clean.myr
@@ -24,7 +24,7 @@ const cleanall = {b
| `Gen gt:
for f in gt.out
if !gt.durable && std.remove(f)
- std.f2put("\tclean {}\n", f)
+ std.put("\tclean {}\n", f)
;;
;;
| `Cmd ct: /* nothing to do */
@@ -52,7 +52,7 @@ const clean = {b, targ
| `Gen gt:
for f in gt.out
if !gt.durable && std.remove(f)
- std.f2put("\tclean {}\n", f)
+ std.put("\tclean {}\n", f)
;;
;;
| `Cmd ct:
@@ -80,7 +80,7 @@ const cleanup = {b, targ, leaves
keys = std.htkeys(dg.deps)
for k in keys
if !std.htgetv(mchammer_files, k, false) && std.remove(k)
- std.f2put("\tclean {}\n", k)
+ std.put("\tclean {}\n", k)
;;
;;
}
diff --git a/mbld/deps.myr b/mbld/deps.myr
index 2a99612..b79447c 100644
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -48,7 +48,7 @@ const myrdeps = {b, mt, doclean, addsrc
])
/* direct dependencies of binary */
if mt.islib
- out = std.f2fmt("lib{}.a", mt.name)
+ out = std.fmt("lib{}.a", mt.name)
useout = std.sldup(mt.name)
else
out = std.sldup(mt.name)
@@ -106,13 +106,13 @@ const dumpgraph = {dg
->
;;
keys = std.htkeys(dg.deps)
- std.f2put("digraph dg {{\n")
+ std.put("digraph dg {{\n")
for k in keys
for v in std.htgetv(dg.deps, k, ["WTFUNKNOWN!"][:])
- std.f2put("\t\"{}\" -> \"{}\";\n", k, v)
+ std.put("\t\"{}\" -> \"{}\";\n", k, v)
;;
;;
- std.f2put("}\n")
+ std.put("}\n")
}
const srcdeps = {b, ds, g, path, obj, usefile
@@ -124,7 +124,7 @@ const srcdeps = {b, ds, g, path, obj, usefile
ds.depstk = std.slpush(ds.depstk, path)
if std.htgetv(g.seen, path, false)
- std.f2fput(1, "dependency loop involving {}:\n", path)
+ std.fput(1, "dependency loop involving {}:\n", path)
for d in ds.depstk
std.fput(1, "\t{}\n", d)
;;
@@ -144,7 +144,7 @@ const srcdeps = {b, ds, g, path, obj, usefile
;;
| `Local (l, lnum):
if !std.hassuffix(l, ".use")
- std.f2fatal("{}:{}: local dependency \"{}\" should end with .use\n", path, lnum, l)
+ std.fatal("{}:{}: local dependency \"{}\" should end with .use\n", path, lnum, l)
;;
if obj.len != 0
pushdep(g, l, obj)
@@ -165,7 +165,7 @@ const addusedep = {b, ds, g, f, usefile, line
if std.hthas(g.done, usefile)
if opt_debug
- std.f2put("already loaded deps for {}\n", usefile)
+ std.put("already loaded deps for {}\n", usefile)
;;
->
;;
@@ -177,7 +177,7 @@ const addusedep = {b, ds, g, f, usefile, line
if ds.addsrc
std.htput(g.sources, src, true)
elif !std.hthas(g.input, usefile)
- std.f2fatal("{}:{}: source file {} not listed in bldfile\n", f, line, src)
+ std.fatal("{}:{}: source file {} not listed in bldfile\n", f, line, src)
;;
;;
pushdep(g, src, usefile)
@@ -194,12 +194,12 @@ const getdeps = {b, ds, path
if !std.fexists(path)
match std.htget(b.gensrc, path)
| `std.Some gt: run(gt.cmd)
- | `std.None: std.f2fatal("no input file {}\n", path)
+ | `std.None: std.fatal("no input file {}\n", path)
;;
;;
match bio.open(path, bio.Rd)
| `std.Some fd: f = fd
- | `std.None: std.f2fatal("could not open {}\n", path)
+ | `std.None: std.fatal("could not open {}\n", path)
;;
lnum = 0
@@ -230,14 +230,14 @@ const scrapelibs = {dg, lib, incs
f = openlib(lib, incs)
match bio.getc(f)
| `std.Some 'U': /* nothing */
- | `std.Some _: std.f2fatal("library {}: corrupt or invalid usefile\n", lib)
- | `std.None: std.f2fatal("library {}: could not read usefile\n", lib)
+ | `std.Some _: std.fatal("library {}: corrupt or invalid usefile\n", lib)
+ | `std.None: std.fatal("library {}: could not read usefile\n", lib)
;;
match bio.getbe32(f)
| `std.Some 1: /* nothing: version matches. */
- | `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.Some 0: std.fput(1, "library {}: warning: old usefile version\n", lib)
+ | `std.Some _: std.fatal("library {}: usefile version unknown\n", lib)
+ | `std.None: std.fatal("library {}: corrutpt or invalid usefile\n", lib)
;;
std.slfree(rdstr(f))
done = false
@@ -276,7 +276,7 @@ const openlib = {lib, incs
| `std.None:
/* nothing */
;;
- std.f2fatal("could not find library {}.\n", lib)
+ std.fatal("could not find library {}.\n", lib)
}
const depname = {deps, ln, lnum
@@ -304,7 +304,7 @@ const pushdep = {dg, src, dst
var sl
if opt_debug
- std.f2put("{} <= {}\n", dst, src)
+ std.put("{} <= {}\n", dst, src)
;;
std.assert(dst.len < 200, "BUG!")
sl = std.htgetv(dg.deps, dst, [][:])
diff --git a/mbld/fsel.myr b/mbld/fsel.myr
index e40d16c..7b4423d 100644
--- a/mbld/fsel.myr
+++ b/mbld/fsel.myr
@@ -35,11 +35,11 @@ const fseladd = {fsel, f
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 %s\n", f)
+ | `std.None: std.fatal("unrecognized type for file {}\n", f)
;;
| `std.None:
match std.strrfind(f, ".")
- | `std.None: std.fatal("unrecognized type for file %s\n", f)
+ | `std.None: std.fatal("unrecognized type for file {}\n", f)
| `std.Some i:
basename = f[:i]
attrs = ""
@@ -72,7 +72,7 @@ const fselfin = {fsel
for k in keys
nmatch = std.htgetv(fsel._match, k, -1)
if nmatch == -1
- std.fatal("no applicable file for '%s'\n", k)
+ std.fatal("no applicable file for '{}'\n", k)
;;
ret = std.slpush(ret, std.htgetv(fsel._best, k, ""))
;;
@@ -89,7 +89,7 @@ const addsysattrs = {sa
| "osx": attrs = ["osx", "posixy"][:]
| "linux": attrs = ["linux", "posixy"][:]
| "plan9": attrs = ["plan9"][:]
- | unknown: std.fatal("unknown system \"%s\"\n", unknown)
+ | unknown: std.fatal("unknown system \"{}\"\n", unknown)
;;
for a in attrs
std.htput(sa, a, true)
@@ -97,7 +97,7 @@ const addsysattrs = {sa
match opt_arch
| "x64": attrs = ["x64"][:]
- | unknown: std.fatal("unknown arch %s\n", unknown)
+ | unknown: std.fatal("unknown arch {}\n", unknown)
;;
for a in attrs
std.htput(sa, a, true)
diff --git a/mbld/install.myr b/mbld/install.myr
index e88a43a..a36eee2 100644
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -34,7 +34,7 @@ const movetargs = {b, rm
| `Lib lt:
if lt.install
movefile(b, rm, lt.dir, lt.name, config.Libpath, 0o644)
- libarchive = std.f2fmt("lib{}.a", lt.name)
+ libarchive = std.fmt("lib{}.a", lt.name)
movefile(b, rm, lt.dir, libarchive, config.Libpath, 0o644)
std.slfree(libarchive)
;;
@@ -60,18 +60,18 @@ const movefile = {b, rm, dir, file, prefix, perm
setdir(b, dir)
path = std.pathjoin([opt_destdir, opt_instroot, prefix, file][:])
if rm
- std.f2put("\trm {}\n", path)
+ std.put("\trm {}\n", path)
if !std.remove(path)
- std.f2put("\t\tno such file {}\n", file)
+ std.put("\t\tno such file {}\n", file)
;;
else
- std.f2put("\t{} => {}\n", file, path)
+ std.put("\t{} => {}\n", file, path)
std.remove(path)
match std.slurp(file)
- | `std.Fail m: std.f2fatal("Could not open {} for reading\n", file)
+ | `std.Fail m: std.fatal("Could not open {} for reading\n", file)
| `std.Ok buf:
if !std.blat(path, buf, perm)
- std.f2put("Could not write {}\n", file)
+ std.put("Could not write {}\n", file)
;;
std.slfree(buf)
;;
@@ -84,15 +84,15 @@ const moveman = {b, rm, dir, man
match std.strrfind(man, ".")
| `std.None:
- std.f2fatal("manpage {} has no section\n", man)
+ std.fatal("manpage {} has no section\n", man)
| `std.Some s:
sect = s + 1
if s + 1 == man.len
- std.f2fatal("manpage {} missing suffix\n", man)
+ std.fatal("manpage {} missing suffix\n", man)
;;
;;
- manrel = std.f2fmt("{}{}", opt_manpath, man[sect:])
+ manrel = std.fmt("{}{}", opt_manpath, man[sect:])
movefile(b, rm, dir, man, manrel, 0o644)
std.slfree(manrel)
}
diff --git a/mbld/main.myr b/mbld/main.myr
index f6d2dcb..a78db6f 100644
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -96,7 +96,7 @@ const main = {args : byte[:][:]
findproj(b, "bld.proj")
bld.load(b)
for t in b.all
- std.f2put("{}\n", t)
+ std.put("{}\n", t)
;;
else
findproj(b, "bld.proj")
@@ -133,7 +133,7 @@ const mkbuild = {
const findproj = {b, bldfile
if !findbase(b, bldfile) || !std.chdir(b.basedir)
- std.f2fatal("could not find {}\n", bldfile)
+ std.fatal("could not find {}\n", bldfile)
;;
bld.setdir(b, "")
}
diff --git a/mbld/opts.myr b/mbld/opts.myr
index 7c4f0f2..0fd4465 100644
--- a/mbld/opts.myr
+++ b/mbld/opts.myr
@@ -56,13 +56,13 @@ const initopts = {
| "Darwin": opt_sys = "osx"
| "FreeBSD": opt_sys = "freebsd"
| "Plan9": opt_sys = "plan9"
- | unknown: std.fatal("unknown system \"%s\"\n", unknown)
+ | unknown: std.fatal("unknown system \"{}\"\n", unknown)
;;
match si.arch
| "x86_64": opt_arch = "x64"
| "amd64": opt_arch = "x64"
- | unknown: std.fatal("unknown architecture \"%s\"\n", unknown)
+ | unknown: std.fatal("unknown architecture \"{}\"\n", unknown)
;;
opt_incpaths = [][:]
@@ -76,8 +76,8 @@ const initopts = {
opt_runtime = std.pathjoin([opt_instroot, config.Libpath, config.Runtime][:])
;;
- sysarchstr = std.fmt("+%s-%s", opt_sys, opt_arch)
- sysstr = std.fmt("+%s", opt_sys)
- archstr = std.fmt("+%s", opt_arch)
+ sysarchstr = std.fmt("+{}-{}", opt_sys, opt_arch)
+ sysstr = std.fmt("+{}", opt_sys)
+ archstr = std.fmt("+{}", opt_arch)
}
diff --git a/mbld/parse.myr b/mbld/parse.myr
index 88043dc..5f7f9fe 100644
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -59,7 +59,7 @@ const loadall = {b, path, dir
loadall(b, subproj, subpath)
b.basedir = curbase
else
- std.f2fatal("could not open {} or {} \n", subbld, subproj)
+ std.fatal("could not open {} or {} \n", subbld, subproj)
;;
std.slfree(subbld)
std.slfree(subproj)
@@ -91,7 +91,7 @@ const sortdeps = {b
const visit = {all, b, targ, looped, marked
if std.hthas(looped, targ)
- std.f2fatal("cycle in build depgraph involving {}\n", targ)
+ std.fatal("cycle in build depgraph involving {}\n", targ)
elif std.hthas(marked, targ)
-> all
;;
@@ -109,7 +109,7 @@ const getdeps = {targ
match targ
| `Bin t: -> t.libdeps
| `Lib t: -> t.libdeps
- | _: std.f2fatal("depending on non-library target")
+ | _: std.fatal("depending on non-library target")
;;
}
@@ -123,7 +123,7 @@ const mkparser = {path, dir, basedir
p.basedir = std.sldup(basedir)
match std.slurp(path)
| `std.Ok d: p.data = d
- | `std.Fail _: std.f2fatal("could not open '{}'\n", path)
+ | `std.Fail _: std.fatal("could not open '{}'\n", path)
;;
p.rest = p.data
-> p
@@ -144,8 +144,8 @@ const failparse = {p, msg, args : ...
var sl
ap = std.vastart(&args)
- sl = std.bfmtv(buf[:], msg, ap)
- std.f2fput(1, "{}:{}: {}", p.fname, p.line, sl)
+ sl = std.bfmtv(buf[:], msg, &ap)
+ std.fput(1, "{}:{}: {}", p.fname, p.line, sl)
std.exit(1)
}
@@ -353,7 +353,7 @@ const myrtarget = {p, targ
| ("noinst", ""): inst = false
| ("sys", tags): systags = std.slpush(systags, tags)
| (invalid, _):
- std.f2fatal("{}: got invalid attr '{}'\n", targ, invalid)
+ std.fatal("{}: got invalid attr '{}'\n", targ, invalid)
;;
;;
for inc in bld.opt_incpaths
@@ -596,7 +596,7 @@ const getc = {p
const addtarg = {p, b, name, targ
var tn
- tn = std.f2fmt("{}:{}", p.fdir, name)
+ tn = std.fmt("{}:{}", p.fdir, name)
if std.hthas(b.targs, tn)
failparse(p, "duplicate target {}\n", tn)
;;
@@ -611,10 +611,10 @@ const libpath = {p, libpath
| `std.None:
dir = std.sldup(".")
lib = std.sldup(libpath)
- targ = std.f2fmt("{}:{}", p.fdir, lib)
+ targ = std.fmt("{}:{}", p.fdir, lib)
| `std.Some idx:
if idx == libpath.len
- std.f2fatal("libdep {} missing library after ':'\n")
+ std.fatal("libdep {} missing library after ':'\n")
;;
/* absolute path */
if std.hasprefix(libpath, "@/") || std.hasprefix(libpath, "@:")
@@ -627,7 +627,7 @@ const libpath = {p, libpath
lib = std.sldup(libpath[idx+1:])
targ = std.pathcat(p.fdir, libpath)
if std.hasprefix(targ, "../")
- std.f2fatal("library {} outside of project\n", libpath)
+ std.fatal("library {} outside of project\n", libpath)
;;
;;
;;
diff --git a/mbld/test.myr b/mbld/test.myr
index 4f253ae..19c2dce 100644
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -55,9 +55,9 @@ const test = {b
;;
if hastest
if ok
- std.f2put("TESTS PASSED\n")
+ std.put("TESTS PASSED\n")
else
- std.f2put("TESTS FAILED\n")
+ std.put("TESTS FAILED\n")
std.exit(1)
;;
;;
@@ -121,11 +121,11 @@ const cleantest = {b, src
const runtest = {bin
var r, log
- std.f2put("run {}:\t", bin)
+ std.put("run {}:\t", bin)
log = std.strcat(bin, ".log")
match std.spork([bin][:])
| `std.Fail m:
- std.f2fatal("unable to run test: {}\n", m)
+ std.fatal("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 @@ const runtest = {bin
r = false
match std.wait(pid)
- | `std.Wfailure: std.f2put("FAIL\n")
- | `std.Wsignalled: std.f2put("CRASH\n")
+ | `std.Wfailure: std.put("FAIL\n")
+ | `std.Wsignalled: std.put("CRASH\n")
| `std.Wsuccess:
std.put("PASS\n")
r = true
diff --git a/mbld/util.myr b/mbld/util.myr
index 3325e66..6bb9de3 100644
--- a/mbld/util.myr
+++ b/mbld/util.myr
@@ -20,30 +20,30 @@ const run = {cmd
printcmd(cmd)
pid = std.fork()
if pid == -1
- std.f2fatal("could not fork command\n")
+ std.fatal("could not fork command\n")
elif pid == 0
if std.execvp(cmd[0], cmd) < 0
- std.f2fatal("failed to exec {}\n", cmd[0])
+ std.fatal("failed to exec {}\n", cmd[0])
;;
else
match std.wait(pid)
| `std.Wsuccess: /* nothing */
- | `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, " "))
+ | `std.Wfailure: std.fatal("FAIL: \"{}\"\n", std.strjoin(cmd, " "))
+ | `std.Wsignalled: std.fatal("CRASH: \"{}\"\n", std.strjoin(cmd, " "))
+ | `std.Waiterror: std.fatal("WAT: \"{}\"\n", std.strjoin(cmd, " "))
;;
;;
}
const printcmd = {lst
if lst.len > 0
- std.f2put("\t")
- std.f2put("{}\t", lst[0])
+ std.put("\t")
+ std.put("{}\t", lst[0])
for l in lst[1:]
- std.f2put("{} ", l)
+ std.put("{} ", l)
;;
;;
- std.f2put("\n")
+ std.put("\n")
}
const srcsplit = {src
@@ -73,7 +73,7 @@ const swapsuffix = {f, suff, newsuff
if std.hassuffix(f, suff)
f = f[:f.len - suff.len]
;;
- -> std.f2fmt("{}{}", f, newsuff)
+ -> std.fmt("{}{}", f, newsuff)
}
const srcswapsuffix = {src, new
@@ -85,7 +85,7 @@ const srcswapsuffix = {src, new
elif std.sleq(suff, ".s")
-> std.strcat(base, new)
else
- std.f2fatal("unrecognized source {}\n", src)
+ std.fatal("unrecognized source {}\n", src)
;;
}
@@ -98,7 +98,7 @@ const strlistfree = {sl
const gettarg = {tab, n
match std.htget(tab, n)
- | `std.None: std.f2fatal("internal: nonexistent {}\n", n)
+ | `std.None: std.fatal("internal: nonexistent {}\n", n)
| `std.Some t: -> t
;;
}
@@ -109,12 +109,12 @@ const setdir = {b, dir
if !std.sleq(b.curdir, dir)
p = std.pathcat(b.basedir, dir)
if b.curdir.len != 0
- std.f2put("Leaving directory '{}'\n", b.curdir)
+ std.put("Leaving directory '{}'\n", b.curdir)
;;
- std.f2put("Entering directory '{}'\n", dir)
+ std.put("Entering directory '{}'\n", dir)
if !std.chdir(p)
- std.f2fatal("could not cd into {}\n", p)
+ std.fatal("could not cd into {}\n", p)
;;
b.curdir = dir
std.slfree(p)
diff --git a/test/align.myr b/test/align.myr
index 06555df..a103817 100644
--- a/test/align.myr
+++ b/test/align.myr
@@ -53,18 +53,18 @@ type alignstruct7 = struct
;;
const main = {
- std.put("size = %i\n", sizeof(alignstruct0))
- std.put("size = %i\n", sizeof(alignstruct1))
- std.put("size = %i\n", sizeof(alignstruct2))
- std.put("size = %i\n", sizeof(alignstruct3))
- std.put("size = %i\n", sizeof(alignstruct4))
- std.put("size = %i\n", sizeof(alignstruct5))
- std.put("size = %i\n", sizeof(alignstruct6))
- std.put("size = %i\n", sizeof(alignstruct7))
+ std.put("size = {}\n", sizeof(alignstruct0))
+ std.put("size = {}\n", sizeof(alignstruct1))
+ std.put("size = {}\n", sizeof(alignstruct2))
+ std.put("size = {}\n", sizeof(alignstruct3))
+ std.put("size = {}\n", sizeof(alignstruct4))
+ std.put("size = {}\n", sizeof(alignstruct5))
+ std.put("size = {}\n", sizeof(alignstruct6))
+ std.put("size = {}\n", sizeof(alignstruct7))
/* size should be 8 */
- std.put("size = %i\n", sizeof((int, byte, byte)))
+ std.put("size = {}\n", sizeof((int, byte, byte)))
/* size should be 16 */
- std.put("size = %i\n", sizeof((int, byte, int, byte)))
+ std.put("size = {}\n", sizeof((int, byte, int, byte)))
/* size should be 12 */
- std.put("size = %i\n", sizeof((int, int, byte, byte)))
+ std.put("size = {}\n", sizeof((int, int, byte, byte)))
}
diff --git a/test/bigcondarg.myr b/test/bigcondarg.myr
index 2615749..6af216e 100644
--- a/test/bigcondarg.myr
+++ b/test/bigcondarg.myr
@@ -21,9 +21,9 @@ generic expect = {a : @a, b : @a, expected : bool
actual = false
;;
if actual == expected
- std.put("a == b: expected: %t, got, %t: pass\n", expected, actual)
+ std.put("a == b: expected: {}, got, {}: pass\n", expected, actual)
else
- std.put("a == b: expected: %t, got, %t: fail\n", expected, actual)
+ std.put("a == b: expected: {}, got, {}: fail\n", expected, actual)
;;
}
diff --git a/test/bigliteral.myr b/test/bigliteral.myr
index bd310d6..5a04ffa 100644
--- a/test/bigliteral.myr
+++ b/test/bigliteral.myr
@@ -1,5 +1,5 @@
use std
const main = {
- std.put("%l\n", 34359738368 castto(int64))
+ std.put("{}\n", 34359738368 castto(int64))
}
diff --git a/test/catfile.myr b/test/catfile.myr
index b766209..f41e23f 100644
--- a/test/catfile.myr
+++ b/test/catfile.myr
@@ -7,7 +7,7 @@ const main = {args : byte[:][:]
r = std.slurp("data/catfile-in")
match r
| `std.Ok dat: std.write(1, dat)
- | `std.Fail msg: std.put("Failed to read file: %s\n", msg)
+ | `std.Fail msg: std.put("Failed to read file: {}\n", msg)
;;
-> 0
}
diff --git a/test/constslice.myr b/test/constslice.myr
index 2065220..588f3ca 100644
--- a/test/constslice.myr
+++ b/test/constslice.myr
@@ -8,15 +8,15 @@ const array = [1,2,3,4,5]
const main = {
/* expected output 23 */
for x in slpart
- std.put("%i", x)
+ std.put("{}", x)
;;
/* expected output 12345 */
for x in slfull
- std.put("%i", x)
+ std.put("{}", x)
;;
/* expected output 678 */
for x in slinline
- std.put("%i", x)
+ std.put("{}", x)
;;
std.put("\n")
}
diff --git a/test/doublecall.myr b/test/doublecall.myr
index efaa921..2248ee7 100644
--- a/test/doublecall.myr
+++ b/test/doublecall.myr
@@ -1,7 +1,7 @@
use std
const main = {
- std.put("%i,%w\n", a(), b())
+ std.put("{},{}\n", a(), b())
}
const a = {
diff --git a/test/foldidx.myr b/test/foldidx.myr
index 60489fa..d6916b6 100644
--- a/test/foldidx.myr
+++ b/test/foldidx.myr
@@ -11,6 +11,6 @@ const z : xy[1] = [
]
const main = {
- std.put("%i,%i\n", z[0].x, z[0].y)
+ std.put("{},{}\n", z[0].x, z[0].y)
}
diff --git a/test/genericmake.myr b/test/genericmake.myr
index 819dc82..8b6768b 100644
--- a/test/genericmake.myr
+++ b/test/genericmake.myr
@@ -14,7 +14,7 @@ const main = {
x = make(123)
match x
- | `std.Some v: std.put("val = %i\n", v)
+ | `std.Some v: std.put("val = {}\n", v)
| `std.None: std.die("Unreachable\n")
;;
}
diff --git a/test/loop.myr b/test/loop.myr
index 6bf93cf..02260fa 100644
--- a/test/loop.myr
+++ b/test/loop.myr
@@ -6,19 +6,19 @@ const main = {
n = 0
for i = 0; i < 5; ++i
- std.put("%i", i)
+ std.put("{}", i)
;;
for i = 0; i < 5; ++i
if i > 3
break
;;
- std.put("%i", i)
+ std.put("{}", i)
;;
for i = 0; i < 10; ++i
if i < 6
continue
;;
- std.put("%i", i)
+ std.put("{}", i)
;;
std.put("\n")
}
diff --git a/test/matchunion_sl.myr b/test/matchunion_sl.myr
index e8f9dd7..34f17f5 100644
--- a/test/matchunion_sl.myr
+++ b/test/matchunion_sl.myr
@@ -13,7 +13,7 @@ const main = {
v = `Str "foo"
match v
| `Int 127: std.exit(42)
- | `Str s: std.put("%s\n", s)
+ | `Str s: std.put("{}\n", s)
| `Nil:
| _: std.die("Impossible match failure\n")
;;
diff --git a/test/nestucon.myr b/test/nestucon.myr
index deee01e..747ca59 100644
--- a/test/nestucon.myr
+++ b/test/nestucon.myr
@@ -12,7 +12,7 @@ const main = {
a = [.x = `Str "asdf"]
match a
- | [.x=`Str s]: std.put("%s\n", s)
+ | [.x=`Str s]: std.put("{}\n", s)
| _: std.die("Impossible match failure\n")
;;
}
diff --git a/test/patiter.myr b/test/patiter.myr
index 4016a36..aee5883 100644
--- a/test/patiter.myr
+++ b/test/patiter.myr
@@ -3,11 +3,11 @@ use std
const main = {
/* should print 1,3,5, skipping 4 */
for (1,x) in [(1,2),(1,3),(2,4),(1,5)]
- std.put("%i", x)
+ std.put("{}", x)
;;
/* should print 1, 2 skipping `None */
for `std.Some v in [`std.None, `std.Some 1, `std.Some 2]
- std.put("%i", v)
+ std.put("{}", v)
;;
std.put("\n")
}
diff --git a/test/strfind.myr b/test/strfind.myr
index be33714..aa55619 100644
--- a/test/strfind.myr
+++ b/test/strfind.myr
@@ -15,7 +15,7 @@ const main = {
const printloc = {l
match l
- | `std.Some loc: std.put("Found %z\n", loc)
+ | `std.Some loc: std.put("Found {}\n", loc)
| `std.None: std.put("No match\n")
;;
}
diff --git a/test/strjoin.myr b/test/strjoin.myr
index cde44c6..8b291e7 100644
--- a/test/strjoin.myr
+++ b/test/strjoin.myr
@@ -7,7 +7,7 @@ const main = {
"z",
"w"
]
- std.put("%s\n", std.strcat("foo;", "bar"))
- std.put("%s\n", std.strjoin(strings[:], ""))
- std.put("%s\n", std.strjoin(strings[:], ":"))
+ std.put("{}\n", std.strcat("foo;", "bar"))
+ std.put("{}\n", std.strjoin(strings[:], ""))
+ std.put("{}\n", std.strjoin(strings[:], ":"))
}
diff --git a/test/strsplit.myr b/test/strsplit.myr
index cf46549..ea46734 100644
--- a/test/strsplit.myr
+++ b/test/strsplit.myr
@@ -6,19 +6,19 @@ const main = {
sp = std.strsplit("a,b,c,d", ",")
for i = 0; i < sp.len; i++
- std.put("\"%s\"\n", sp[i])
+ std.put("\"{}\"\n", sp[i])
;;
std.slfree(sp)
sp = std.strsplit("a,,b,c,,d", ",")
for i = 0; i < sp.len; i++
- std.put("\"%s\"\n", sp[i])
+ std.put("\"{}\"\n", sp[i])
;;
std.slfree(sp)
sp = std.strsplit("a--b---b--c---c-d--d", "---")
for i = 0; i < sp.len; i++
- std.put("\"%s\"\n", sp[i])
+ std.put("\"{}\"\n", sp[i])
;;
std.slfree(sp)
}
diff --git a/test/strstrip.myr b/test/strstrip.myr
index 733e68e..32dc475 100644
--- a/test/strstrip.myr
+++ b/test/strstrip.myr
@@ -1,27 +1,27 @@
use std
const main = {
- std.put("\"%s\"\n", std.strstrip("cccc"))
- std.put("\"%s\"\n", std.strfstrip("cccc"))
- std.put("\"%s\"\n", std.strrstrip("cccc"))
+ std.put("\"{}\"\n", std.strstrip("cccc"))
+ std.put("\"{}\"\n", std.strfstrip("cccc"))
+ std.put("\"{}\"\n", std.strrstrip("cccc"))
std.put("--\n")
- std.put("\"%s\"\n", std.strstrip(" abc "))
- std.put("\"%s\"\n", std.strfstrip(" abc "))
- std.put("\"%s\"\n", std.strrstrip(" abc "))
+ std.put("\"{}\"\n", std.strstrip(" abc "))
+ std.put("\"{}\"\n", std.strfstrip(" abc "))
+ std.put("\"{}\"\n", std.strrstrip(" abc "))
std.put("--\n")
- std.put("\"%s\"\n", std.strstrip(" 世界 "))
- std.put("\"%s\"\n", std.strfstrip(" 世界 "))
- std.put("\"%s\"\n", std.strrstrip(" 世界 "))
+ std.put("\"{}\"\n", std.strstrip(" 世界 "))
+ std.put("\"{}\"\n", std.strfstrip(" 世界 "))
+ std.put("\"{}\"\n", std.strrstrip(" 世界 "))
std.put("--\n")
- std.put("\"%s\"\n", std.strstrip(" "))
- std.put("\"%s\"\n", std.strfstrip(" "))
- std.put("\"%s\"\n", std.strrstrip(" "))
+ std.put("\"{}\"\n", std.strstrip(" "))
+ std.put("\"{}\"\n", std.strfstrip(" "))
+ std.put("\"{}\"\n", std.strrstrip(" "))
std.put("--\n")
- std.put("\"%s\"\n", std.strstrip(""))
- std.put("\"%s\"\n", std.strfstrip(""))
- std.put("\"%s\"\n", std.strrstrip(""))
+ std.put("\"{}\"\n", std.strstrip(""))
+ std.put("\"{}\"\n", std.strfstrip(""))
+ std.put("\"{}\"\n", std.strrstrip(""))
}
diff --git a/test/strtab.myr b/test/strtab.myr
index 115efca..309df6f 100644
--- a/test/strtab.myr
+++ b/test/strtab.myr
@@ -10,7 +10,7 @@ const strtab = [
const main = {
var i
for i = 0; i < strtab.len; i++
- std.put("%i: %s\n", i, strtab[i])
+ std.put("{}: {}\n", i, strtab[i])
;;
std.exit(0)
}
diff --git a/test/subrangefor.myr b/test/subrangefor.myr
index 0a3acc4..7d397dd 100644
--- a/test/subrangefor.myr
+++ b/test/subrangefor.myr
@@ -2,7 +2,7 @@ use std
const main = {
for i in [1,2,3,4][:2]
- std.put("%i", i)
+ std.put("{}", i)
;;
std.put("\n")
}
diff --git a/test/traitimpl.myr b/test/traitimpl.myr
index 172478f..6299b43 100644
--- a/test/traitimpl.myr
+++ b/test/traitimpl.myr
@@ -31,6 +31,6 @@ const main = {
a = foo(123)
b = foo(11 castto(int16))
c = frob("meeeeeeh")
- std.put("%i,%w,%s\n", a, b, c)
+ std.put("{},{},{}\n", a, b, c)
}
diff --git a/test/uconinit.myr b/test/uconinit.myr
index 824879b..768df31 100644
--- a/test/uconinit.myr
+++ b/test/uconinit.myr
@@ -13,7 +13,7 @@ const main = {
match v
| `A: std.put("A ")
| `B: std.put("B ")
- | `C x: std.put("C %i\n", x)
+ | `C x: std.put("C {}\n", x)
;;
;;
std.put("\n")