summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-10-10 17:19:27 -0700
committerOri Bernstein <ori@eigenstate.org>2015-10-10 17:19:27 -0700
commit776a9e4ed35369c9c8553e3035daa026e00495e9 (patch)
tree99beac4de9952263367f3a3511838b1beea8d356
parent954728ed5cc60e638cd858d232c5851f72ad7343 (diff)
downloadmc-776a9e4ed35369c9c8553e3035daa026e00495e9.tar.gz
Some API tweaks to make things match the docs.
-rw-r--r--lib/regex/types.myr2
-rw-r--r--lib/std/bitset.myr14
-rw-r--r--lib/std/optparse.myr4
-rw-r--r--lib/std/rand.myr13
-rw-r--r--lib/std/strbuf.myr2
-rw-r--r--lib/std/test/fmt.myr2
-rw-r--r--lib/std/units.myr6
7 files changed, 28 insertions, 15 deletions
diff --git a/lib/regex/types.myr b/lib/regex/types.myr
index 8de55ca..2af7d87 100644
--- a/lib/regex/types.myr
+++ b/lib/regex/types.myr
@@ -53,7 +53,7 @@ pkg regex =
strp : std.size
;;
- type rethread = struct
+ pkglocal type rethread = struct
next : rethread# /* run queue link */
tid : std.size /* just for debugging */
diff --git a/lib/std/bitset.myr b/lib/std/bitset.myr
index 3ce76ea..c323194 100644
--- a/lib/std/bitset.myr
+++ b/lib/std/bitset.myr
@@ -55,28 +55,28 @@ const bsmax = {bs
}
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
diff --git a/lib/std/optparse.myr b/lib/std/optparse.myr
index ae65b77..d3c72ee 100644
--- a/lib/std/optparse.myr
+++ b/lib/std/optparse.myr
@@ -30,6 +30,7 @@ pkg std =
type optparsed = struct
opts : (char, byte[:])[:]
args : byte[:][:]
+ prog : byte[:]
;;
const optparse : (optargs : byte[:][:], def : optdef# -> optparsed)
@@ -58,7 +59,8 @@ const optparse = {args, def
parsed = [
.opts=[][:],
- .args=[][:]
+ .args=[][:],
+ .prog=args[0]
]
optinit(&ctx, args, def)
while !optdone(&ctx)
diff --git a/lib/std/rand.myr b/lib/std/rand.myr
index 351bf8d..2e64fe7 100644
--- a/lib/std/rand.myr
+++ b/lib/std/rand.myr
@@ -54,6 +54,7 @@ pkg std =
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 @@ const freerng = {rng
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++
@@ -97,6 +94,14 @@ const init = {rng, seed
rng.i = 624
}
+generic rand = {lo, hi
+ -> rngrand(_rng, lo, hi)
+}
+
+generic randnum = {
+ -> rngrandnum(_rng)
+}
+
/*
Generates a random integer from `rng` in the range [lo, hi),
returning the value. The range [lo, hi) must be positive,
diff --git a/lib/std/strbuf.myr b/lib/std/strbuf.myr
index 3c4b51c..5638799 100644
--- a/lib/std/strbuf.myr
+++ b/lib/std/strbuf.myr
@@ -87,7 +87,7 @@ const sbputb = {sb, v
}
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
diff --git a/lib/std/test/fmt.myr b/lib/std/test/fmt.myr
index 5c600d3..fbae79a 100644
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -49,7 +49,7 @@ const builtins = {
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")
diff --git a/lib/std/units.myr b/lib/std/units.myr
index f1a99e9..4f1d24c 100644
--- 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 @@ pkg std =
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
;;