ref: 82eecd5a321aa3c619437a21997aa73c33c31d3c
parent: b5ddbc86346fddc60360a817ee62bc8ca938973e
author: S. Gilles <[email protected]>
date: Mon Sep 9 03:53:57 EDT 2019
Split out intfmt to a separate file. This prepares for intfmt being used within fltfmt for the exponent in scientific notation.
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -38,6 +38,7 @@
hasprefix.myr
hassuffix.myr
htab.myr
+ intfmt.myr
intparse.myr
introspect.myr
ipparse.myr
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -7,6 +7,7 @@
use "hashfuncs"
use "hasprefix"
use "htab"
+use "intfmt"
use "intparse"
use "introspect"
use "memops"
@@ -477,12 +478,6 @@
-> fp
}
-type intparams = struct
- base : size
- padto : size
- padfill : char
-;;
-
const intparams = {params
var ip : intparams
@@ -570,60 +565,6 @@
const isprint = {b
-> b >= (' ' : byte) && b < ('~' : byte)
-}
-
-const digitchars = "0123456789abcdef"
-const intfmt = {sb, opts, signed, bits : uint64, nbits
- var isneg
- var sval, val
- var b : byte[64]
- var i, j, npad
- var base
-
- base = (opts.base : uint64)
- if signed && bits >= 1 << (nbits - 1)
- sval = -(bits : int64)
- val = (sval : uint64)
- isneg = true
-
- /* if its negative after inverting, we have int64 min */
- if sval < 0
- std.sbputs(sb, "-9223372036854775808")
- -> void
- ;;
- else
- val = (bits : uint64)
- val &= ~0 >> nbits
- isneg = false
- ;;
-
- i = 0
- if val == 0
- b[0] = ('0' : byte)
- 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
- sbputb(sb, ('-' : byte))
- ;;
- for j = 0; j < npad; j++
- sbputc(sb, opts.padfill)
- ;;
- if opts.padfill != '0' && isneg
- sbputb(sb, ('-' : byte))
- ;;
- for j = i; j != 0; j--
- sbputb(sb, b[j - 1])
- ;;
}
/* would use std.get(), but that's a dependency loop */
--- /dev/null
+++ b/lib/std/intfmt.myr
@@ -1,0 +1,79 @@
+use "die"
+use "extremum"
+use "intparse"
+use "option"
+use "strbuf"
+use "striter"
+use "types"
+
+pkg std =
+ pkglocal type intparams = struct
+ base : size
+ padto : size
+ padfill : char
+ ;;
+
+ pkglocal const intfmt : (sb : strbuf#, opts : intparams, signed : bool, bits : uint64, nbits : uint64 -> void)
+;;
+
+const digitchars = "0123456789abcdef"
+const intfmt = {sb : strbuf#, opts : intparams, signed : bool, bits : uint64, nbits : uint64
+ var isneg
+ var sval, val
+ var b : byte[64]
+ var i, j, npad
+ var base
+
+ base = (opts.base : uint64)
+ if signed && bits >= 1 << (nbits - 1)
+ sval = -(bits : int64)
+ val = (sval : uint64)
+ isneg = true
+
+ /* if its negative after inverting, we have int64 min */
+ if sval < 0
+ std.sbputs(sb, "-9223372036854775808")
+ -> void
+ ;;
+ else
+ val = (bits : uint64)
+ val &= ~0 >> nbits
+ isneg = false
+ ;;
+
+ i = 0
+ if val == 0
+ b[0] = ('0' : byte)
+ 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
+ sbputb(sb, ('-' : byte))
+ ;;
+ for j = 0; j < npad; j++
+ sbputc(sb, opts.padfill)
+ ;;
+ if opts.padfill != '0' && isneg
+ sbputb(sb, ('-' : byte))
+ ;;
+ for j = i; j != 0; j--
+ sbputb(sb, b[j - 1])
+ ;;
+}
+
+/* would use std.get(), but that's a dependency loop */
+const getint = {s, msg
+ match std.intparse(s)
+ | `Some w: -> w;
+ | `None: die(msg)
+ ;;
+}
--- a/mk/bootstrap/bootstrap+Darwin-x86_64.sh
+++ b/mk/bootstrap/bootstrap+Darwin-x86_64.sh
@@ -90,6 +90,7 @@
$pwd/6/6m -O obj -I obj/lib/sys lib/std/intparse.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strsplit.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strbuf.myr
+ $pwd/6/6m -O obj -I obj/lib/sys lib/std/intfmt.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/sldup.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/bigint.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/fltparse.myr
--- a/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
@@ -90,6 +90,7 @@
$pwd/6/6m -O obj -I obj/lib/sys lib/std/intparse.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strsplit.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strbuf.myr
+ $pwd/6/6m -O obj -I obj/lib/sys lib/std/intfmt.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/sldup.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/bigint.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/fltparse.myr
--- a/mk/bootstrap/bootstrap+Linux-x86_64.sh
+++ b/mk/bootstrap/bootstrap+Linux-x86_64.sh
@@ -90,6 +90,7 @@
$pwd/6/6m -O obj -I obj/lib/sys lib/std/intparse.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strsplit.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strbuf.myr
+ $pwd/6/6m -O obj -I obj/lib/sys lib/std/intfmt.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/sldup.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/bigint.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/fltparse.myr
@@ -127,8 +128,8 @@
$pwd/6/6m -O obj -I obj/lib/sys lib/std/dial+posixy.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/listen+posixy.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/try.myr
- ar -rcs obj/lib/std/libstd.a obj/lib/std/resolve.o obj/lib/std/result.o obj/lib/std/try.o obj/lib/std/ipparse.o obj/lib/std/alloc.o obj/lib/std/sleq.o obj/lib/std/putint.o obj/lib/std/sljoin.o obj/lib/std/slpop.o obj/lib/std/syswrap.o obj/lib/std/getint.o obj/lib/std/strsplit.o obj/lib/std/slfill.o obj/lib/std/writeall.o obj/lib/std/fltfmt.o obj/lib/std/hasprefix.o obj/lib/std/swap.o obj/lib/std/fmt.o obj/lib/std/netaddr.o obj/lib/std/varargs.o obj/lib/std/diriter.o obj/lib/std/getcwd.o obj/lib/std/blat.o obj/lib/std/optparse.o obj/lib/std/pathjoin.o obj/lib/std/readall.o obj/lib/std/strjoin.o obj/lib/std/threadhooks.o obj/lib/std/sjlj.o obj/lib/std/extremum.o obj/lib/std/endian.o obj/lib/std/rand.o obj/lib/std/sldup.o obj/lib/std/sleep.o obj/lib/std/wait.o obj/lib/std/introspect.o obj/lib/std/fltparse.o obj/lib/std/fndup.o obj/lib/std/strbuf.o obj/lib/std/strreplace.o obj/lib/std/assert.o obj/lib/std/spork.o obj/lib/std/slpush.o obj/lib/std/strstrip.o obj/lib/std/htab.o obj/lib/std/hashfuncs.o obj/lib/std/slput.o obj/lib/std/sjlj-impl.o obj/lib/std/fltbits.o obj/lib/std/striter.o obj/lib/std/types.o obj/lib/std/cstrconv.o obj/lib/std/units.o obj/lib/std/backtrace.o obj/lib/std/syswrap-ss.o obj/lib/std/die.o obj/lib/std/mk.o obj/lib/std/hassuffix.o obj/lib/std/memops-impl.o obj/lib/std/pledge.o obj/lib/std/utf.o obj/lib/std/slurp.o obj/lib/std/dialparse.o obj/lib/std/bytealloc.o obj/lib/std/mktemp.o obj/lib/std/consts.o obj/lib/std/chomp.o obj/lib/std/dir.o obj/lib/std/search.o obj/lib/std/memops.o obj/lib/std/fmtfuncs.o obj/lib/std/strfind.o obj/lib/std/env.o obj/lib/std/dirname.o obj/lib/std/clear.o obj/lib/std/listen.o obj/lib/std/sort.o obj/lib/std/cmp.o obj/lib/std/now.o obj/lib/std/intparse.o obj/lib/std/traits.o obj/lib/std/mkpath.o obj/lib/std/option.o obj/lib/std/dial.o obj/lib/std/errno.o obj/lib/std/chartype.o obj/lib/std/bigint.o obj/lib/std/bitset.o obj/lib/std/getbp.o obj/lib/std/slcp.o obj/lib/std/execvp.o
- $pwd/muse/muse -o obj/lib/std/libstd.use -p std obj/lib/std/resolve.use obj/lib/std/result.use obj/lib/std/try.use obj/lib/std/ipparse.use obj/lib/std/alloc.use obj/lib/std/sleq.use obj/lib/std/putint.use obj/lib/std/sljoin.use obj/lib/std/slpop.use obj/lib/std/syswrap.use obj/lib/std/getint.use obj/lib/std/strsplit.use obj/lib/std/slfill.use obj/lib/std/writeall.use obj/lib/std/fltfmt.use obj/lib/std/hasprefix.use obj/lib/std/swap.use obj/lib/std/fmt.use obj/lib/std/netaddr.use obj/lib/std/varargs.use obj/lib/std/diriter.use obj/lib/std/getcwd.use obj/lib/std/blat.use obj/lib/std/optparse.use obj/lib/std/pathjoin.use obj/lib/std/readall.use obj/lib/std/strjoin.use obj/lib/std/threadhooks.use obj/lib/std/sjlj.use obj/lib/std/extremum.use obj/lib/std/endian.use obj/lib/std/rand.use obj/lib/std/sldup.use obj/lib/std/sleep.use obj/lib/std/wait.use obj/lib/std/introspect.use obj/lib/std/fltparse.use obj/lib/std/fndup.use obj/lib/std/strbuf.use obj/lib/std/strreplace.use obj/lib/std/assert.use obj/lib/std/spork.use obj/lib/std/slpush.use obj/lib/std/strstrip.use obj/lib/std/htab.use obj/lib/std/hashfuncs.use obj/lib/std/slput.use obj/lib/std/fltbits.use obj/lib/std/striter.use obj/lib/std/types.use obj/lib/std/cstrconv.use obj/lib/std/units.use obj/lib/std/backtrace.use obj/lib/std/syswrap-ss.use obj/lib/std/die.use obj/lib/std/mk.use obj/lib/std/hassuffix.use obj/lib/std/pledge.use obj/lib/std/utf.use obj/lib/std/slurp.use obj/lib/std/dialparse.use obj/lib/std/bytealloc.use obj/lib/std/mktemp.use obj/lib/std/consts.use obj/lib/std/chomp.use obj/lib/std/dir.use obj/lib/std/search.use obj/lib/std/memops.use obj/lib/std/fmtfuncs.use obj/lib/std/strfind.use obj/lib/std/env.use obj/lib/std/dirname.use obj/lib/std/clear.use obj/lib/std/listen.use obj/lib/std/sort.use obj/lib/std/cmp.use obj/lib/std/now.use obj/lib/std/intparse.use obj/lib/std/traits.use obj/lib/std/mkpath.use obj/lib/std/option.use obj/lib/std/dial.use obj/lib/std/errno.use obj/lib/std/chartype.use obj/lib/std/bigint.use obj/lib/std/bitset.use obj/lib/std/slcp.use obj/lib/std/execvp.use
+ ar -rcs obj/lib/std/libstd.a obj/lib/std/resolve.o obj/lib/std/intfmt.o obj/lib/std/result.o obj/lib/std/try.o obj/lib/std/ipparse.o obj/lib/std/alloc.o obj/lib/std/sleq.o obj/lib/std/putint.o obj/lib/std/sljoin.o obj/lib/std/slpop.o obj/lib/std/syswrap.o obj/lib/std/getint.o obj/lib/std/strsplit.o obj/lib/std/slfill.o obj/lib/std/writeall.o obj/lib/std/fltfmt.o obj/lib/std/hasprefix.o obj/lib/std/swap.o obj/lib/std/fmt.o obj/lib/std/netaddr.o obj/lib/std/varargs.o obj/lib/std/diriter.o obj/lib/std/getcwd.o obj/lib/std/blat.o obj/lib/std/optparse.o obj/lib/std/pathjoin.o obj/lib/std/readall.o obj/lib/std/strjoin.o obj/lib/std/threadhooks.o obj/lib/std/sjlj.o obj/lib/std/extremum.o obj/lib/std/endian.o obj/lib/std/rand.o obj/lib/std/sldup.o obj/lib/std/sleep.o obj/lib/std/wait.o obj/lib/std/introspect.o obj/lib/std/fltparse.o obj/lib/std/fndup.o obj/lib/std/strbuf.o obj/lib/std/strreplace.o obj/lib/std/assert.o obj/lib/std/spork.o obj/lib/std/slpush.o obj/lib/std/strstrip.o obj/lib/std/htab.o obj/lib/std/hashfuncs.o obj/lib/std/slput.o obj/lib/std/sjlj-impl.o obj/lib/std/fltbits.o obj/lib/std/striter.o obj/lib/std/types.o obj/lib/std/cstrconv.o obj/lib/std/units.o obj/lib/std/backtrace.o obj/lib/std/syswrap-ss.o obj/lib/std/die.o obj/lib/std/mk.o obj/lib/std/hassuffix.o obj/lib/std/memops-impl.o obj/lib/std/pledge.o obj/lib/std/utf.o obj/lib/std/slurp.o obj/lib/std/dialparse.o obj/lib/std/bytealloc.o obj/lib/std/mktemp.o obj/lib/std/consts.o obj/lib/std/chomp.o obj/lib/std/dir.o obj/lib/std/search.o obj/lib/std/memops.o obj/lib/std/fmtfuncs.o obj/lib/std/strfind.o obj/lib/std/env.o obj/lib/std/dirname.o obj/lib/std/clear.o obj/lib/std/listen.o obj/lib/std/sort.o obj/lib/std/cmp.o obj/lib/std/now.o obj/lib/std/intparse.o obj/lib/std/traits.o obj/lib/std/mkpath.o obj/lib/std/option.o obj/lib/std/dial.o obj/lib/std/errno.o obj/lib/std/chartype.o obj/lib/std/bigint.o obj/lib/std/bitset.o obj/lib/std/getbp.o obj/lib/std/slcp.o obj/lib/std/execvp.o
+ $pwd/muse/muse -o obj/lib/std/libstd.use -p std obj/lib/std/resolve.use obj/lib/std/intfmt.use obj/lib/std/result.use obj/lib/std/try.use obj/lib/std/ipparse.use obj/lib/std/alloc.use obj/lib/std/sleq.use obj/lib/std/putint.use obj/lib/std/sljoin.use obj/lib/std/slpop.use obj/lib/std/syswrap.use obj/lib/std/getint.use obj/lib/std/strsplit.use obj/lib/std/slfill.use obj/lib/std/writeall.use obj/lib/std/fltfmt.use obj/lib/std/hasprefix.use obj/lib/std/swap.use obj/lib/std/fmt.use obj/lib/std/netaddr.use obj/lib/std/varargs.use obj/lib/std/diriter.use obj/lib/std/getcwd.use obj/lib/std/blat.use obj/lib/std/optparse.use obj/lib/std/pathjoin.use obj/lib/std/readall.use obj/lib/std/strjoin.use obj/lib/std/threadhooks.use obj/lib/std/sjlj.use obj/lib/std/extremum.use obj/lib/std/endian.use obj/lib/std/rand.use obj/lib/std/sldup.use obj/lib/std/sleep.use obj/lib/std/wait.use obj/lib/std/introspect.use obj/lib/std/fltparse.use obj/lib/std/fndup.use obj/lib/std/strbuf.use obj/lib/std/strreplace.use obj/lib/std/assert.use obj/lib/std/spork.use obj/lib/std/slpush.use obj/lib/std/strstrip.use obj/lib/std/htab.use obj/lib/std/hashfuncs.use obj/lib/std/slput.use obj/lib/std/fltbits.use obj/lib/std/striter.use obj/lib/std/types.use obj/lib/std/cstrconv.use obj/lib/std/units.use obj/lib/std/backtrace.use obj/lib/std/syswrap-ss.use obj/lib/std/die.use obj/lib/std/mk.use obj/lib/std/hassuffix.use obj/lib/std/pledge.use obj/lib/std/utf.use obj/lib/std/slurp.use obj/lib/std/dialparse.use obj/lib/std/bytealloc.use obj/lib/std/mktemp.use obj/lib/std/consts.use obj/lib/std/chomp.use obj/lib/std/dir.use obj/lib/std/search.use obj/lib/std/memops.use obj/lib/std/fmtfuncs.use obj/lib/std/strfind.use obj/lib/std/env.use obj/lib/std/dirname.use obj/lib/std/clear.use obj/lib/std/listen.use obj/lib/std/sort.use obj/lib/std/cmp.use obj/lib/std/now.use obj/lib/std/intparse.use obj/lib/std/traits.use obj/lib/std/mkpath.use obj/lib/std/option.use obj/lib/std/dial.use obj/lib/std/errno.use obj/lib/std/chartype.use obj/lib/std/bigint.use obj/lib/std/bitset.use obj/lib/std/slcp.use obj/lib/std/execvp.use
$pwd/6/6m -O obj -I obj/lib/sys -I obj/lib/std -I obj/lib/bio -I obj/lib/regex -I obj/lib/thread mbld/types.myr
$pwd/6/6m -O obj -I obj/lib/sys -I obj/lib/std lib/regex/types.myr
$pwd/6/6m -O obj -I obj/lib/sys -I obj/lib/std lib/regex/interp.myr
--- a/mk/bootstrap/bootstrap+NetBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+NetBSD-amd64.sh
@@ -69,6 +69,7 @@
$pwd/6/6m -I lib/sys lib/std/slpush.myr
$pwd/6/6m -I lib/sys lib/std/strsplit.myr
$pwd/6/6m -I lib/sys lib/std/strbuf.myr
+ $pwd/6/6m -I lib/sys lib/std/intfmt.myr
$pwd/6/6m -I lib/sys lib/std/sldup.myr
$pwd/6/6m -I lib/sys lib/std/bigint.myr
$pwd/6/6m -I lib/sys lib/std/fltparse.myr
--- a/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
@@ -89,6 +89,7 @@
$pwd/6/6m -O obj -I obj/lib/sys lib/std/slpush.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/striter.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/intparse.myr
+ $pwd/6/6m -O obj -I obj/lib/sys lib/std/intfmt.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strsplit.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/strbuf.myr
$pwd/6/6m -O obj -I obj/lib/sys lib/std/sldup.myr
--- a/mk/bootstrap/bootstrap+Plan9-amd64.sh
+++ b/mk/bootstrap/bootstrap+Plan9-amd64.sh
@@ -85,6 +85,7 @@
$pwd/6/6.out -O obj -I obj/lib/sys lib/std/slpush.myr
$pwd/6/6.out -O obj -I obj/lib/sys lib/std/striter.myr
$pwd/6/6.out -O obj -I obj/lib/sys lib/std/intparse.myr
+ $pwd/6/6.out -O obj -I obj/lib/sys lib/std/intfmt.myr
$pwd/6/6.out -O obj -I obj/lib/sys lib/std/strsplit.myr
$pwd/6/6.out -O obj -I obj/lib/sys lib/std/strbuf.myr
$pwd/6/6.out -O obj -I obj/lib/sys lib/std/sldup.myr