summaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/alloc.myr24
-rw-r--r--lib/std/bigint.myr21
-rw-r--r--lib/std/bitset.myr20
-rw-r--r--lib/std/cmp.myr3
-rw-r--r--lib/std/cstrconv.myr12
-rw-r--r--lib/std/env+plan9.myr3
-rw-r--r--lib/std/fmtfuncs.myr4
-rw-r--r--lib/std/htab.myr6
-rw-r--r--lib/std/ipparse.myr8
-rw-r--r--lib/std/mkpath.myr3
-rw-r--r--lib/std/putint.myr8
-rw-r--r--lib/std/rand.myr14
-rw-r--r--lib/std/resolve+posixy.myr8
-rw-r--r--lib/std/search.myr4
-rw-r--r--lib/std/slcp.myr5
-rw-r--r--lib/std/slfill.myr4
-rw-r--r--lib/std/strfind.myr8
-rw-r--r--lib/std/strjoin.myr5
-rw-r--r--lib/std/strstrip.myr3
-rw-r--r--lib/std/utf.myr6
20 files changed, 61 insertions, 108 deletions
diff --git a/lib/std/alloc.myr b/lib/std/alloc.myr
index ed3b023..ef0037b 100644
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -80,9 +80,7 @@ type chunk = struct /* NB: must be smaller than sizeof(slab) */
;;
const __init__ = {
- var i
-
- for i = 0; i < buckets.len && (Align << i) <= Bktmax; i++
+ for var i = 0; i < buckets.len && (Align << i) <= Bktmax; i++
bktinit(&buckets[i], Align << i)
;;
}
@@ -162,7 +160,7 @@ generic slfree = {sl
/* Grows a slice */
generic slgrow = {sl : @a[:], len
- var i, n
+ var n
var new
/* if the slice doesn't need a bigger bucket, we don't need to realloc. */
@@ -172,7 +170,7 @@ generic slgrow = {sl : @a[:], len
new = slalloc(len)
n = min(len, sl.len)
- for i = 0; i < n; i++
+ for var i = 0; i < n; i++
new[i] = sl[i]
;;
if sl.len > 0
@@ -207,9 +205,7 @@ const zbytealloc = {sz
}
const zfill = {sl
- var i
-
- for i = 0; i < sl.len; i++
+ for var i = 0; i < sl.len; i++
sl[i] = 0
;;
}
@@ -258,7 +254,7 @@ const bktinit = {b, sz
/* Creates a slab for bucket 'bkt', and fills the chunk list */
const mkslab = {bkt
- var i, p, s
+ var p, s
var b, bnext
var off /* offset of chunk head */
@@ -287,7 +283,7 @@ const mkslab = {bkt
off = align(sizeof(slab), Align)
bnext = nextchunk(s castto(chunk#), off)
s.freehd = bnext
- for i = 0; i < bkt.nper; i++
+ for var i = 0; i < bkt.nper; i++
b = bnext
bnext = nextchunk(b, bkt.sz)
b.next = bnext
@@ -365,10 +361,10 @@ Finds the correct bucket index to allocate from
for allocations of size 'sz'
*/
const bktnum = {sz
- var i, bktsz
+ var bktsz
bktsz = Align
- for i = 0; bktsz <= Bktmax; i++
+ for var i = 0; bktsz <= Bktmax; i++
if bktsz >= sz
-> i
;;
@@ -382,11 +378,11 @@ returns the actual size we allocated for a given
size request
*/
const allocsz = {sz
- var i, bktsz
+ var bktsz
if sz <= Bktmax
bktsz = Align
- for i = 0; bktsz <= Bktmax; i++
+ for var i = 0; bktsz <= Bktmax; i++
if bktsz >= sz
-> bktsz
;;
diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr
index 719fd69..120663c 100644
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -229,12 +229,10 @@ const bigiszero = {v
}
const bigeq = {a, b
- var i
-
if a.sign != b.sign || a.dig.len != b.dig.len
-> false
;;
- for i = 0; i < a.dig.len; i++
+ for var i = 0; i < a.dig.len; i++
if a.dig[i] != b.dig[i]
-> false
;;
@@ -251,7 +249,6 @@ generic bigeqi = {a, b
}
const bigcmp = {a, b
- var i
var da, db, sa, sb
sa = a.sign castto(int64)
@@ -266,7 +263,7 @@ const bigcmp = {a, b
-> signedorder(sa)
else
/* otherwise, the one with the first larger digit is bigger */
- for i = a.dig.len; i > 0; i--
+ for var i = a.dig.len; i > 0; i--
da = a.dig[i - 1] castto(int64)
db = b.dig[i - 1] castto(int64)
-> signedorder(sa * (da - db))
@@ -647,7 +644,6 @@ generic bigdivi = {a, b
generic bigshli = {a, s : @a::(numeric,integral)
var off, shift
var t, carry
- var i
assert(s >= 0, "shift amount must be positive")
off = (s castto(uint64)) / 32
@@ -659,15 +655,15 @@ generic bigshli = {a, s : @a::(numeric,integral)
;;
a.dig = slzgrow(a.dig, 1 + a.dig.len + off castto(size))
/* blit over the base values */
- for i = a.dig.len; i > off; i--
+ for var i = a.dig.len; i > off; i--
a.dig[i - 1] = a.dig[i - 1 - off]
;;
- for i = 0; i < off; i++
+ for var i = 0; i < off; i++
a.dig[i] = 0
;;
/* and shift over by the remainder */
carry = 0
- for i = 0; i < a.dig.len; i++
+ for var i = 0; i < a.dig.len; i++
t = (a.dig[i] castto(uint64)) << shift
a.dig[i] = (t | carry) castto(uint32)
carry = t >> 32
@@ -679,22 +675,21 @@ generic bigshli = {a, s : @a::(numeric,integral)
generic bigshri = {a, s
var off, shift
var t, carry
- var i
assert(s >= 0, "shift amount must be positive")
off = (s castto(uint64)) / 32
shift = (s castto(uint64)) % 32
/* blit over the base values */
- for i = 0; i < a.dig.len - off; i++
+ for var i = 0; i < a.dig.len - off; i++
a.dig[i] = a.dig[i + off]
;;
- for i = a.dig.len - off; i < a.dig.len; i++
+ for var i = a.dig.len - off; i < a.dig.len; i++
a.dig[i] = 0
;;
/* and shift over by the remainder */
carry = 0
- for i = a.dig.len; i > 0; i--
+ for var i = a.dig.len; i > 0; i--
t = (a.dig[i - 1] castto(uint64))
a.dig[i - 1] = (carry | (t >> shift)) castto(uint32)
carry = t << (32 - shift)
diff --git a/lib/std/bitset.myr b/lib/std/bitset.myr
index 7843c7d..edf123e 100644
--- a/lib/std/bitset.myr
+++ b/lib/std/bitset.myr
@@ -89,37 +89,33 @@ generic bshas = {bs, v
}
const bsunion = {a, b
- var i
-
eqsz(a, b)
- for i = 0; i < b.bits.len; i++
+ for var i = 0; i < b.bits.len; i++
a.bits[i] |= b.bits[i]
;;
}
const bsintersect = {a, b
- var i, n
+ var n
n = min(a.bits.len, b.bits.len)
- for i = 0; i < n; i++
+ for var i = 0; i < n; i++
a.bits[i] &= b.bits[i]
;;
}
const bsdiff = {a, b
- var i, n
+ var n
n = min(b.bits.len, a.bits.len)
- for i = 0; i < n; i++
+ for var i = 0; i < n; i++
a.bits[i] &= ~b.bits[i]
;;
}
const bsissubset = {a, b
- var i
-
eqsz(a, b);
- for i = 0; i < a.bits.len; i++
+ for var i = 0; i < a.bits.len; i++
if (b.bits[i] & a.bits[i]) != b.bits[i]
-> false
;;
@@ -128,10 +124,8 @@ const bsissubset = {a, b
}
const bseq = {a, b
- var i
-
eqsz(a, b)
- for i = 0; i < a.bits.len; i++
+ for var i = 0; i < a.bits.len; i++
if a.bits[i] != b.bits[i]
-> false
;;
diff --git a/lib/std/cmp.myr b/lib/std/cmp.myr
index edc5fe3..8c01bfc 100644
--- a/lib/std/cmp.myr
+++ b/lib/std/cmp.myr
@@ -25,10 +25,9 @@ generic numcmp = {a, b
const strcmp = {a, b
var l
- var i
l = min(a.len, b.len)
- for i = 0; i < l; i++
+ for var i = 0; i < l; i++
if a[i] < b[i]
-> `Before
elif a[i] > b[i]
diff --git a/lib/std/cstrconv.myr b/lib/std/cstrconv.myr
index fa9e0bf..a517e19 100644
--- a/lib/std/cstrconv.myr
+++ b/lib/std/cstrconv.myr
@@ -7,9 +7,7 @@ pkg std =
;;
const cstrconv = {buf
- var i
-
- for i = 0; i < buf.len; i++
+ for var i = 0; i < buf.len; i++
if buf[i] == 0
-> buf[:i]
;;
@@ -29,12 +27,10 @@ const cstrconvp = {p
}
const cstrlen = {buf
- var i
-
- for i = 0; i < buf.len; i++
+ for var i = 0; i < buf.len; i++
if buf[i] == 0
- break
+ -> i
;;
;;
- -> i
+ -> 0
}
diff --git a/lib/std/env+plan9.myr b/lib/std/env+plan9.myr
index 4a95ed7..134aa75 100644
--- a/lib/std/env+plan9.myr
+++ b/lib/std/env+plan9.myr
@@ -21,8 +21,7 @@ var envkey : byte[:][:]
var envval : byte[:][:]
const envfind = {key
- var i
- for i = 0; i < envkey.len; i++
+ for var i = 0; i < envkey.len; i++
if std.sleq(envkey[i], key)
-> `Some envval[i]
;;
diff --git a/lib/std/fmtfuncs.myr b/lib/std/fmtfuncs.myr
index abe5e75..e20805e 100644
--- a/lib/std/fmtfuncs.myr
+++ b/lib/std/fmtfuncs.myr
@@ -38,12 +38,12 @@ const bigfmt = {sb, ap, opts
}
const bsfmt = {sb, ap, opts
- var i, bs, sep
+ var bs, sep
bs = vanext(ap)
sep = ""
sbputs(sb, "bitset{")
- for i = 0; i < bsmax(bs); i++
+ for var i = 0; i < bsmax(bs); i++
if bshas(bs, i)
sbfmt(sb, sep)
sbfmt(sb, "{}", i)
diff --git a/lib/std/htab.myr b/lib/std/htab.myr
index 500219d..0f7384d 100644
--- a/lib/std/htab.myr
+++ b/lib/std/htab.myr
@@ -45,7 +45,6 @@ generic resize = {ht, sz
var oldv
var oldh
var oldd
- var i
oldk = ht.keys
oldv = ht.vals
@@ -58,7 +57,7 @@ generic resize = {ht, sz
ht.nelt = 0
ht.ndead = 0
- for i = 0; i < oldk.len; i++
+ for var i = 0; i < oldk.len; i++
if oldh[i] != 0 && !oldd[i]
htput(ht, oldk[i], oldv[i])
;;
@@ -191,12 +190,11 @@ generic hthas = {ht, k
generic htkeys = {ht
var keys
- var i
var j
keys = slalloc(ht.nelt)
j = 0
- for i = 0; i < ht.keys.len; i++
+ for var i = 0; i < ht.keys.len; i++
if ht.hashes[i] != 0 && !ht.dead[i]
keys[j++] = ht.keys[i]
;;
diff --git a/lib/std/ipparse.myr b/lib/std/ipparse.myr
index 17bc6f0..8c6f7c7 100644
--- a/lib/std/ipparse.myr
+++ b/lib/std/ipparse.myr
@@ -35,14 +35,6 @@ const ipparse = {ip
const ip4parse = {ip
var a, b, c, d
var ok
- /*
- var addr
- var last : size
- var x : option(int32)
- var val : int32 /* need int32 to check for overflow */
- var i
- var j : size
- */
(a, ip, ok) = num(ip, 0, 255, 10, '.', true)
(ip, ok) = delim(ip, '.', ok)
diff --git a/lib/std/mkpath.myr b/lib/std/mkpath.myr
index b7e8e24..75c1b9c 100644
--- a/lib/std/mkpath.myr
+++ b/lib/std/mkpath.myr
@@ -7,9 +7,8 @@ pkg std =
const mkpath = {p
var st
- var i
- for i = 0; i < p.len; i++
+ for var i = 0; i < p.len; i++
if p[i] == '/' castto(byte) && i != 0
st = mkdir(p[:i], 0o777)
if st != 0 && (st castto(errno)) != Eexist
diff --git a/lib/std/putint.myr b/lib/std/putint.myr
index 711001d..9ff92dd 100644
--- a/lib/std/putint.myr
+++ b/lib/std/putint.myr
@@ -22,10 +22,10 @@ generic putle8 = {buf, v; -> putle(buf, v castto(uint64), 1)}
generic putbe8 = {buf, v; -> putbe(buf, v castto(uint64), 1)}
const putbe = {buf, val, n
- var i, k
+ var k
assert(buf.len >= n, "buffer too small")
- for i = 0; i < n; i++
+ for var i = 0; i < n; i++
k = val >> (8*(n-i-1))
buf[i] = (k & 0xff) castto(byte)
;;
@@ -33,10 +33,8 @@ const putbe = {buf, val, n
}
const putle = {buf, val, n
- var i
-
assert(buf.len >= n, "buffer too small")
- for i = 0; i < n; i++
+ for var i = 0; i < n; i++
buf[i] = (val & 0xff) castto(byte)
val >>= 8
;;
diff --git a/lib/std/rand.myr b/lib/std/rand.myr
index 2e8c73e..6ca23e6 100644
--- a/lib/std/rand.myr
+++ b/lib/std/rand.myr
@@ -75,13 +75,11 @@ const delrng = {rng
/* initializes a random number generator from the seed `seed`. */
const init = {rng, seed
- var i
-
- for i = 0; i < 624; i++
+ for var i = 0; i < 624; i++
rng.state[i] = seed
seed = 1812433253 * (seed ^ (seed >> 30)) + i + 1
;;
- rng.i = i
+ rng.i = 624
}
/*
@@ -117,10 +115,10 @@ generic rand = {rng, lo, hi -> @a::(integral,numeric)
may be negative, if the type is signed.
*/
generic randN = {rng -> @a::(integral,numeric)
- var i, val
+ var val
val = 0
- for i = 0; i < sizeof(@a)/4; i++
+ for var i = 0; i < sizeof(@a)/4; i++
val <<= 8*sizeof(@a)
val |= rand32(rng) castto(@a::(integral,numeric))
;;
@@ -147,10 +145,10 @@ const rand32 = {rng
}
const randbytes = {rng, buf
- var i, n, r
+ var n, r
n = 0
- for i = 0; i < buf.len/4; i++
+ for var i = 0; i < buf.len/4; i++
r = rand32(rng)
buf[n++] = (r >> 0 & 0xff) castto(byte)
buf[n++] = (r >> 8 & 0xff) castto(byte)
diff --git a/lib/std/resolve+posixy.myr b/lib/std/resolve+posixy.myr
index 185c9d7..f158eea 100644
--- a/lib/std/resolve+posixy.myr
+++ b/lib/std/resolve+posixy.myr
@@ -314,7 +314,6 @@ const rquery = {srv, id
const hosts = {pkt, id : uint16
var off
var v, q, a
- var i
var hinf : hostinfo[:]
off = 0
@@ -330,7 +329,7 @@ const hosts = {pkt, id : uint16
(v, off) = unpack16(pkt, off) /* arcount */
/* skip past query records */
- for i = 0; i < q; i++
+ for var i = 0; i < q; i++
off = skipname(pkt, off) /* name */
(v, off) = unpack16(pkt, off) /* type */
(v, off) = unpack16(pkt, off) /* class */
@@ -338,7 +337,7 @@ const hosts = {pkt, id : uint16
/* parse answer records */
hinf = slalloc(a castto(size))
- for i = 0; i < a; i++
+ for var i = 0; i < a; i++
off = skipname(pkt, off) /* name */
(v, off) = unpack16(pkt, off) /* type */
(v, off) = unpack16(pkt, off) /* class */
@@ -392,13 +391,12 @@ const unpack32 = {buf, off
}
const packname = {buf, off : size, host
- var i
var start
var last
start = off
last = 0
- for i = 0; i < host.len; i++
+ for var i = 0; i < host.len; i++
if host[i] == ('.' castto(byte))
off += addseg(buf, off, host[last:i])
last = i + 1
diff --git a/lib/std/search.myr b/lib/std/search.myr
index 725e419..fa2ae40 100644
--- a/lib/std/search.myr
+++ b/lib/std/search.myr
@@ -8,9 +8,7 @@ pkg std =
/* linear search over a list of values */
generic lsearch = {sl, val, cmp
- var i
-
- for i = 0; i < sl.len; i++
+ for var i = 0; i < sl.len; i++
match cmp(sl[i], val)
| `Equal:
-> `Some i
diff --git a/lib/std/slcp.myr b/lib/std/slcp.myr
index 1035a29..b2c9760 100644
--- a/lib/std/slcp.myr
+++ b/lib/std/slcp.myr
@@ -6,7 +6,6 @@ pkg std =
;;
generic slcp = {a : @a[:], b : @a[:]
- var i
var addr_a, addr_b
assert(a.len == b.len, "arguments to slcp() must be of equal length")
@@ -14,11 +13,11 @@ generic slcp = {a : @a[:], b : @a[:]
addr_a = a castto(@a#) castto(intptr)
addr_b = b castto(@a#) castto(intptr)
if addr_a <= addr_b
- for i = 0; i < a.len; i++
+ for var i = 0; i < a.len; i++
a[i] = b[i]
;;
else
- for i = a.len; i > 0; i--
+ for var i = a.len; i > 0; i--
a[i - 1] = b[i - 1]
;;
;;
diff --git a/lib/std/slfill.myr b/lib/std/slfill.myr
index d90e8f5..d09502f 100644
--- a/lib/std/slfill.myr
+++ b/lib/std/slfill.myr
@@ -3,9 +3,7 @@ pkg std =
;;
generic slfill = {sl, v
- var i
-
- for i = 0; i < sl.len; i++
+ for var i = 0; i < sl.len; i++
sl[i] = v
;;
-> sl
diff --git a/lib/std/strfind.myr b/lib/std/strfind.myr
index 0ec0e85..7336b8d 100644
--- a/lib/std/strfind.myr
+++ b/lib/std/strfind.myr
@@ -16,13 +16,13 @@ const strrfind = {haystack, needle
}
const strfindin = {haystack, needle, start, end
- var i, j, inc : size
+ var inc : size
inc = 1
if start > end
inc = -1
;;
- for i = start; i != end; i += inc
+ for var i = start; i != end; i += inc
/*
if we knew the direction we could terminate early,
but we allow the start and end to be passed in.
@@ -31,7 +31,7 @@ const strfindin = {haystack, needle, start, end
continue
;;
if haystack[i] == needle[0]
- for j = 0; j < needle.len; j++
+ for var j = 0; j < needle.len; j++
if haystack[i + j] != needle[j]
goto nextiter
;;
@@ -48,4 +48,4 @@ const strhas = {haystack, needle
| `Some _: -> true
| `None: -> false
;;
-} \ No newline at end of file
+}
diff --git a/lib/std/strjoin.myr b/lib/std/strjoin.myr
index 518a4dc..b8dc813 100644
--- a/lib/std/strjoin.myr
+++ b/lib/std/strjoin.myr
@@ -13,11 +13,10 @@ const strcat = {a, b
const strjoin = {strings, delim
var len, off
- var i
var s
len = 0
- for i = 0; i < strings.len; i++
+ for var i = 0; i < strings.len; i++
len += strings[i].len
;;
if strings.len > 0
@@ -26,7 +25,7 @@ const strjoin = {strings, delim
s = slalloc(len)
off = 0
- for i = 0; i < strings.len; i++
+ for var i = 0; i < strings.len; i++
slcp(s[off:off + strings[i].len], strings[i])
off += strings[i].len
/* we don't want to terminate the last string with delim */
diff --git a/lib/std/strstrip.myr b/lib/std/strstrip.myr
index a3d54fa..4f8a539 100644
--- a/lib/std/strstrip.myr
+++ b/lib/std/strstrip.myr
@@ -26,12 +26,11 @@ const strfstrip = {str
/* strip reverse on str */
const strrstrip = {str
- var i
var end
/* scan backwards for start of utf8 char */
end = str.len
- for i = str.len; i != 0; i--
+ for var i = str.len; i != 0; i--
if str[i - 1] & 0x80 == 0 || str[i-1] & 0xc0 != 0x80
if !isspace(decode(str[i-1:]))
break
diff --git a/lib/std/utf.myr b/lib/std/utf.myr
index 03cc8bb..a5ef05d 100644
--- a/lib/std/utf.myr
+++ b/lib/std/utf.myr
@@ -29,7 +29,6 @@ const charlen = {c
const encode = {buf, c
var len
var mark
- var i
len = charlen(c)
if len < 0 || buf.len < len
@@ -42,7 +41,7 @@ const encode = {buf, c
mark = (((1 << (8 - len)) - 1) ^ 0xff) castto(char)
;;
- for i = len - 1; i > 0; i--
+ for var i = len - 1; i > 0; i--
buf[i] = (c & 0x3f | 0x80) castto(byte)
c >>= 6
;;
@@ -63,7 +62,6 @@ const striter = {str
var len
var mask
var chr
- var i
var c
var tmp
@@ -94,7 +92,7 @@ const striter = {str
mask = (1 << (8 - len)) - 1
chr = (c castto(uint32)) & mask
- for i = 1; i < len; i++
+ for var i = 1; i < len; i++
tmp = str[i] castto(uint32)
chr = (chr << 6) | (tmp & 0x3f)
;;