ref: 610852e18629b8a9a4c4f4ed6e6fc7a336152511
parent: ae9a74441cba3160943ad18bf500781143bff096
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Sep 12 05:01:39 EDT 2015
Move to use 'for var i = ...' construct.
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -291,9 +291,7 @@
little endian format
*/
generic putle = {f, v : @a::(numeric,integral)
- var i
-
- for i = 0; i < sizeof(@a); i++
+ for var i = 0; i < sizeof(@a); i++
putb(f, (v & 0xff) castto(byte))
v >>= 8
;;
@@ -305,9 +303,7 @@
big endian format
*/
generic putbe = {f, v : @a::(numeric,integral)
- var i
-
- for i = sizeof(@a); i != 0; i--
+ for var i = sizeof(@a); i != 0; i--
putb(f, ((v >> ((i-1)*8)) & 0xff) castto(byte))
;;
-> sizeof(@a)
@@ -360,7 +356,6 @@
const readdelim = {f, delim, drop
var ret
- var i, j
ret = [][:]
while true
@@ -374,9 +369,9 @@
-> `std.None
;;
;;
- for i = f.rstart; i < f.rend; i++
+ for var i = f.rstart; i < f.rend; i++
if f.rbuf[i] == delim[0]
- for j = 0; j < delim.len; j++
+ for var j = 0; j < delim.len; j++
if f.rbuf[i + j] != delim[j]
goto nextiterread
;;
--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -142,7 +142,7 @@
}
const bound = {buf, len, fill
- var i, s
+ var s
if len == 1
buf[0] = 0x7f
@@ -149,7 +149,7 @@
else
s = len castto(byte)
buf[0] = (0xff << (8 - s)) | (fill >> (s + 1))
- for i = 1; i < len; i++
+ for var i = 1; i < len; i++
buf[i] = 0x80 | (fill >> 2)
;;
;;
@@ -163,12 +163,11 @@
;;
const rtdump = {rt, ind
- var i
var l, h
indent(ind)
std.put("Range (end = {}) {{\n", rt.end)
- for i = 0; i < rt.ranges.len; i++
+ for var i = 0; i < rt.ranges.len; i++
indent(ind + 1)
(l, h) = rt.ranges[i]
std.put("0x{x}-0x{x}: \n", l, h)
@@ -179,8 +178,7 @@
}
const indent = {ind
- var i
- for i = 0; i < ind; i++
+ for var i = 0; i < ind; i++
std.put("\t")
;;
}
@@ -273,10 +271,9 @@
/* calculates the forward jump distance for a utf8 character range */
const jmpdist = {n
var d
- var i
d = n - 1
- for i = n - 1; i > 0; i--
+ for var i = n - 1; i > 0; i--
d += i
;;
-> d
@@ -344,11 +341,10 @@
const genchar = {re, c
var b : byte[4]
var n
- var i
n = std.encode(b[:], c)
std.assert(n > 0 && n < 4, "non-utf character in regex\n")
- for i = 0; i < n; i++
+ for var i = 0; i < n; i++
append(re, `Ibyte b[i])
;;
-> re.proglen
@@ -366,12 +362,10 @@
/* instruction dump */
const idump = {re
- var i
-
if !re.debug
->
;;
- for i = 0; i < re.proglen; i++
+ for var i = 0; i < re.proglen; i++
std.put("{}:\t", i)
match re.prog[i]
/* Char matching. Consume exactly one byte from the string. */
@@ -400,12 +394,10 @@
/* AST dump */
const dump = {re, t, indent
- var i
-
if !re.debug
->
;;
- for i = 0; i < indent; i++
+ for var i = 0; i < indent; i++
std.put(" ")
;;
match t#
@@ -447,7 +439,7 @@
| `Ranges rl:
std.put("Ranges")
for r in rl
- for i = 0; i < indent + 1; i++
+ for var i = 0; i < indent + 1; i++
std.put(" ")
;;
std.put("\t({}-{})\n", r[0], r[1])
--- a/lib/regex/interp.myr
+++ b/lib/regex/interp.myr
@@ -46,10 +46,9 @@
const getmatches = {re, thr
var ret
- var i
ret = std.slalloc(re.nmatch)
- for i = 0; i < re.nmatch; i++
+ for var i = 0; i < re.nmatch; i++
if thr.mstart[i] != -1 && thr.mend[i] != -1
ret[i] = re.str[thr.mstart[i]:thr.mend[i]]
else
@@ -62,7 +61,7 @@
/* returns a matching thread, or Zthr if no threads matched */
const run = {re
- var i, ip
+ var ip
var consumed
var thr
var states
@@ -71,7 +70,7 @@
re.runq = mkthread(re, 0)
re.runq.mstart = std.slalloc(re.nmatch)
re.runq.mend = std.slalloc(re.nmatch)
- for i = 0; i < re.nmatch; i++
+ for var i = 0; i < re.nmatch; i++
re.runq.mstart[i] = -1
re.runq.mend[i] = -1
;;
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -80,9 +80,7 @@
;;
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 @@
/* 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 @@
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 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 @@
/* 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 @@
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 @@
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 @@
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
;;
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -229,12 +229,10 @@
}
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 @@
}
const bigcmp = {a, b
- var i
var da, db, sa, sb
sa = a.sign castto(int64)
@@ -266,7 +263,7 @@
-> 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 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 @@
;;
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,7 +675,6 @@
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
@@ -686,15 +681,15 @@
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)
--- a/lib/std/bitset.myr
+++ b/lib/std/bitset.myr
@@ -89,37 +89,33 @@
}
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 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
;;
--- a/lib/std/cmp.myr
+++ b/lib/std/cmp.myr
@@ -25,10 +25,9 @@
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]
--- a/lib/std/cstrconv.myr
+++ b/lib/std/cstrconv.myr
@@ -7,9 +7,7 @@
;;
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 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
}
--- a/lib/std/env+plan9.myr
+++ b/lib/std/env+plan9.myr
@@ -21,8 +21,7 @@
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]
;;
--- a/lib/std/fmtfuncs.myr
+++ b/lib/std/fmtfuncs.myr
@@ -38,12 +38,12 @@
}
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)
--- a/lib/std/htab.myr
+++ b/lib/std/htab.myr
@@ -45,7 +45,6 @@
var oldv
var oldh
var oldd
- var i
oldk = ht.keys
oldv = ht.vals
@@ -58,7 +57,7 @@
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 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]
;;
--- a/lib/std/ipparse.myr
+++ b/lib/std/ipparse.myr
@@ -35,14 +35,6 @@
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)
--- a/lib/std/mkpath.myr
+++ b/lib/std/mkpath.myr
@@ -7,9 +7,8 @@
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
--- a/lib/std/putint.myr
+++ b/lib/std/putint.myr
@@ -22,10 +22,10 @@
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 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
;;
--- a/lib/std/rand.myr
+++ b/lib/std/rand.myr
@@ -75,13 +75,11 @@
/* 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 @@
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 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)
--- a/lib/std/resolve+posixy.myr
+++ b/lib/std/resolve+posixy.myr
@@ -314,7 +314,6 @@
const hosts = {pkt, id : uint16
var off
var v, q, a
- var i
var hinf : hostinfo[:]
off = 0
@@ -330,7 +329,7 @@
(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 @@
/* 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 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
--- a/lib/std/search.myr
+++ b/lib/std/search.myr
@@ -8,9 +8,7 @@
/* 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
--- a/lib/std/slcp.myr
+++ b/lib/std/slcp.myr
@@ -6,7 +6,6 @@
;;
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 @@
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]
;;
;;
--- a/lib/std/slfill.myr
+++ b/lib/std/slfill.myr
@@ -3,9 +3,7 @@
;;
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
--- a/lib/std/strfind.myr
+++ b/lib/std/strfind.myr
@@ -16,13 +16,13 @@
}
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 @@
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 @@
| `Some _: -> true
| `None: -> false
;;
-}
\ No newline at end of file
+}
--- a/lib/std/strjoin.myr
+++ b/lib/std/strjoin.myr
@@ -13,11 +13,10 @@
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 @@
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 */
--- a/lib/std/strstrip.myr
+++ b/lib/std/strstrip.myr
@@ -26,12 +26,11 @@
/* 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
--- a/lib/std/utf.myr
+++ b/lib/std/utf.myr
@@ -29,7 +29,6 @@
const encode = {buf, c
var len
var mark
- var i
len = charlen(c)
if len < 0 || buf.len < len
@@ -42,7 +41,7 @@
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 @@
var len
var mask
var chr
- var i
var c
var tmp
@@ -94,7 +92,7 @@
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)
;;