ref: 14fd8b9e92ffe32275aba6f30dd8edf4531c6a19
parent: 77a5bd52ac777a95a22395227f29084e49569370
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Dec 24 17:01:12 EST 2015
Land char iterators.
--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -773,7 +773,7 @@
var str
var chr
- (chr, str) = std.striter(re.pat)
+ (chr, str) = std.strstep(re.pat)
if chr != c
-> false
;;
@@ -784,7 +784,7 @@
const getc = {re
var c
- (c, re.pat) = std.striter(re.pat)
+ (c, re.pat) = std.strstep(re.pat)
-> c
}
@@ -791,7 +791,7 @@
const peekc = {re
var c
- (c, _) = std.striter(re.pat)
+ (c, _) = std.strstep(re.pat)
-> c
}
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -175,7 +175,7 @@
}
const bigparse = {str
- var c, val : int, base
+ var val : int, base
var v, b
var a
@@ -200,8 +200,7 @@
fit in one digit.
*/
v = mkbigint(1)
- while str.len != 0
- (c, str) = striter(str)
+ for c in std.chariter(str)
if c == '_'
continue
;;
--- a/lib/std/cmp.myr
+++ b/lib/std/cmp.myr
@@ -60,8 +60,8 @@
var ca, cb
while a.len > 0 && b.len > 0
- (ca, a) = std.striter(a)
- (cb, b) = std.striter(b)
+ (ca, a) = std.strstep(a)
+ (cb, b) = std.strstep(b)
ca = toupper(ca)
cb = toupper(cb)
if ca < cb
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -151,11 +151,11 @@
nparams = ap.tc.nelt
nfmt = 0
while fmt.len != 0
- (c, fmt) = striter(fmt)
+ (c, fmt) = strstep(fmt)
match c
| '{':
if decode(fmt) == '{'
- (c, fmt) = striter(fmt)
+ (c, fmt) = strstep(fmt)
sbputc(sb, '{')
else
(params, fmt) = getparams(fmt)
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -1,4 +1,5 @@
use "alloc.use"
+use "chartype.use"
use "die.use"
use "sleq.use"
use "slpush.use"
@@ -48,9 +49,9 @@
if a.len == 0 || b.len == 0
break
;;
- (ca, a) = std.striter(a)
- (cb, b) = std.striter(b)
- if ca != cb
+ (ca, a) = std.strstep(a)
+ (cb, b) = std.strstep(b)
+ if std.tolower(ca) != std.tolower(cb)
-> false
;;
;;
@@ -63,7 +64,7 @@
chars = [][:]
while s.len != 0
- (c, s) = std.striter(s)
+ (c, s) = std.strstep(s)
chars = std.slpush(chars, c)
;;
h = murmurhash2(slbytes(chars), Seed)
--- a/lib/std/intparse.myr
+++ b/lib/std/intparse.myr
@@ -43,13 +43,11 @@
}
generic doparse = {s, isneg, base
- var c
var v
var cv : int32
v = 0
- while s.len != 0
- (c, s) = striter(s)
+ for c in std.chariter(s)
if c == '_'
continue
;;
--- a/lib/std/optparse.myr
+++ b/lib/std/optparse.myr
@@ -104,7 +104,7 @@
var c
var arg
- (c, ctx.curarg) = striter(ctx.curarg)
+ (c, ctx.curarg) = strstep(ctx.curarg)
match optinfo(ctx, c)
| `None:
--- a/lib/std/utf.myr
+++ b/lib/std/utf.myr
@@ -6,12 +6,37 @@
const Maxcharlen : size = 4
const Maxcharval : char = 0x10FFFF
+ type chariter = struct
+ rest : byte[:]
+ ;;
+
+ impl iterable chariter -> char
+
+ const chariter : (str : byte[:] -> chariter)
const charlen : (chr : char -> size)
const encode : (buf : byte[:], chr : char -> size)
const decode : (buf : byte[:] -> char)
- const striter : (str : byte[:] -> (char, byte[:]))
+ const strstep : (str : byte[:] -> (char, byte[:]))
+
;;
+impl iterable chariter -> char =
+ __iternext__ = {ci, c
+ if ci.rest.len == 0
+ -> false
+ ;;
+ (c#, ci.rest) = strstep(ci.rest)
+ -> true
+ }
+
+ __iterfin__ = {ci, c
+ }
+;;
+
+const chariter = {str
+ -> [.rest = str]
+}
+
const charlen = {c
if c < 0x80
-> 1
@@ -54,11 +79,11 @@
var c
var b
- (c, b) = striter(buf)
+ (c, b) = strstep(buf)
-> c
}
-const striter = {str
+const strstep = {str
var len
var mask
var chr
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -650,7 +650,7 @@
if p.rest.len == 0
-> false
;;
- (chr, s) = std.striter(p.rest)
+ (chr, s) = std.strstep(p.rest)
if c == chr
p.rest = s
-> true
@@ -666,7 +666,7 @@
const getc = {p
var c, s
- (c, s) = std.striter(p.rest)
+ (c, s) = std.strstep(p.rest)
p.rest = s
-> c
}
--- a/mbldwrap.sh
+++ b/mbldwrap.sh
@@ -4,7 +4,6 @@
export PATH=`pwd`:`pwd`/6:`pwd`/muse:$PATH
if test `uname` = Plan9; then
O=6
- echo $PATH/6/6.out
export MYR_MUSE=`pwd`/muse/$O.out
export MYR_MC=`pwd`/6/$O.out
export MYR_RT=`pwd`/rt/_myrrt.$O
@@ -20,5 +19,5 @@
./mbld/mbld $@ || mbld $@ || \
(echo "Unable to run mbld $@; have you build successfully"; false)
else
- ./mbld/mbld || mbld || $BOOT
+ ./mbld/mbld || mbld
fi
--- a/test/encodechar.myr
+++ b/test/encodechar.myr
@@ -7,13 +7,11 @@
const chartypes = {
var s
- var c
var foo
var buf : byte[32]
s = "1世界äa\n"
- while s.len != 0
- (c, s) = std.striter(s)
+ for c in std.chariter(s)
foo = c
if std.encode(buf[:std.charlen(c)], c) == 0
std.write(1, "couldn't encode\n")