ref: 776a9e4ed35369c9c8553e3035daa026e00495e9
parent: 954728ed5cc60e638cd858d232c5851f72ad7343
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 10 13:19:27 EDT 2015
Some API tweaks to make things match the docs.
--- a/lib/regex/types.myr
+++ b/lib/regex/types.myr
@@ -53,7 +53,7 @@
strp : std.size
;;
- type rethread = struct
+ pkglocal type rethread = struct
next : rethread# /* run queue link */
tid : std.size /* just for debugging */
--- a/lib/std/bitset.myr
+++ b/lib/std/bitset.myr
@@ -55,28 +55,28 @@
}
generic bsput = {bs, v
- var idx, off, has
+ var idx, off, changed
idx = (v castto(size)) / (8*sizeof(size))
off = (v castto(size)) % (8*sizeof(size))
ensurelen(bs, idx)
- has = (bs.bits[idx] & (1 << off)) != 0
+ changed = (bs.bits[idx] & (1 << off)) == 0
bs.bits[idx] |= (1 << off)
- -> has
+ -> changed
}
generic bsdel = {bs, v
- var idx, off, had
+ var idx, off, changed
- had = false
+ changed = false
idx = (v castto(size)) / (8*sizeof(size))
off = (v castto(size)) % (8*sizeof(size))
if idx < bs.bits.len
- had = (bs.bits[idx] & (1 << off)) != 0
+ changed = (bs.bits[idx] & (1 << off)) != 0
bs.bits[idx] &= ~(1 << off)
;;
- -> had
+ -> changed
}
generic bshas = {bs, v
--- a/lib/std/optparse.myr
+++ b/lib/std/optparse.myr
@@ -30,6 +30,7 @@
type optparsed = struct
opts : (char, byte[:])[:]
args : byte[:][:]
+ prog : byte[:]
;;
const optparse : (optargs : byte[:][:], def : optdef# -> optparsed)
@@ -58,7 +59,8 @@
parsed = [
.opts=[][:],
- .args=[][:]
+ .args=[][:],
+ .prog=args[0]
]
optinit(&ctx, args, def)
while !optdone(&ctx)
--- a/lib/std/rand.myr
+++ b/lib/std/rand.myr
@@ -54,6 +54,7 @@
const freerng : (rng : rng# -> void)
generic rand : (lo : @a::(numeric,integral), hi : @a::(numeric,integral) -> @a::(numeric,integral))
+ generic randnum : (-> @a::(numeric,integral))
generic rngrand : (rng : rng#, lo : @a::(numeric,integral), hi : @a::(numeric,integral) -> @a::(numeric,integral))
generic rngrandnum : (rng : rng# -> @a::(numeric,integral))
@@ -84,10 +85,6 @@
free(rng)
}
-generic rand = {lo, hi
- -> rngrand(_rng, lo, hi)
-}
-
/* initializes a random number generator from the seed `seed`. */
const init = {rng, seed
for var i = 0; i < 624; i++
@@ -95,6 +92,14 @@
seed = 1812433253 * (seed ^ (seed >> 30)) + i + 1
;;
rng.i = 624
+}
+
+generic rand = {lo, hi
+ -> rngrand(_rng, lo, hi)
+}
+
+generic randnum = {
+ -> rngrandnum(_rng)
}
/*
--- a/lib/std/strbuf.myr
+++ b/lib/std/strbuf.myr
@@ -87,7 +87,7 @@
}
const sbtrim = {sb, len
- iassert(abs(len) <= sb.len, "trim out of range\n")
+ len = min(sb.len, len)
if len < 0
sb.len -= abs(len)
else
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -49,7 +49,7 @@
check("-000000001", "{p=0,w=10}", -1)
check("xxxxxxxx-1", "{p=x,w=10}", -1)
check(" -1", "{w=10}", -1)
- check("100000" , "{3}", 100000)
+ check("100000" , "{w=3}", 100000)
check("foobarbaz", "{}bar{}", "foo", "baz")
check("{}barbaz", "{{}}bar{}", "baz")
check("{barbaz}", "{{bar{}}}", "baz")
--- a/lib/std/units.myr
+++ b/lib/std/units.myr
@@ -1,3 +1,5 @@
+use "types.use"
+
pkg std =
/* JEDEC 100B.1 memory sizes */
generic KiB : @a::(integral,numeric) = 1024
@@ -8,4 +10,8 @@
generic EiB : @a::(integral,numeric) = PiB*1024
generic ZiB : @a::(integral,numeric) = EiB*1024
generic YiB : @a::(integral,numeric) = ZiB*1024
+
+ generic Sec : time = 1_000_000
+ generic Msec : time = 1_000
+ generic Usec : time = 1
;;