summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/regex/compile.myr6
-rw-r--r--lib/std/bigint.myr5
-rw-r--r--lib/std/cmp.myr4
-rw-r--r--lib/std/fmt.myr4
-rw-r--r--lib/std/hashfuncs.myr9
-rw-r--r--lib/std/intparse.myr4
-rw-r--r--lib/std/optparse.myr2
-rw-r--r--lib/std/utf.myr31
-rw-r--r--mbld/parse.myr4
-rwxr-xr-xmbldwrap.sh3
-rw-r--r--test/encodechar.myr4
11 files changed, 48 insertions, 28 deletions
diff --git a/lib/regex/compile.myr b/lib/regex/compile.myr
index 3cee04b..d62d006 100644
--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -773,7 +773,7 @@ const matchc = {re, c
var str
var chr
- (chr, str) = std.striter(re.pat)
+ (chr, str) = std.strstep(re.pat)
if chr != c
-> false
;;
@@ -784,14 +784,14 @@ const matchc = {re, c
const getc = {re
var c
- (c, re.pat) = std.striter(re.pat)
+ (c, re.pat) = std.strstep(re.pat)
-> c
}
const peekc = {re
var c
- (c, _) = std.striter(re.pat)
+ (c, _) = std.strstep(re.pat)
-> c
}
diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr
index a3f342a..0a56004 100644
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -175,7 +175,7 @@ const bigbfmt = {buf, x, base
}
const bigparse = {str
- var c, val : int, base
+ var val : int, base
var v, b
var a
@@ -200,8 +200,7 @@ const bigparse = {str
fit in one digit.
*/
v = mkbigint(1)
- while str.len != 0
- (c, str) = striter(str)
+ for c in std.chariter(str)
if c == '_'
continue
;;
diff --git a/lib/std/cmp.myr b/lib/std/cmp.myr
index b599166..021f5bc 100644
--- a/lib/std/cmp.myr
+++ b/lib/std/cmp.myr
@@ -60,8 +60,8 @@ const strcasecmp = {a, b
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
diff --git a/lib/std/fmt.myr b/lib/std/fmt.myr
index 816b157..590541a 100644
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -151,11 +151,11 @@ const sbfmtv = {sb, fmt, ap -> size
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)
diff --git a/lib/std/hashfuncs.myr b/lib/std/hashfuncs.myr
index 4f32604..9386f56 100644
--- 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 @@ const strcaseeq = {a, b
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 @@ const strcasehash = {s
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)
diff --git a/lib/std/intparse.myr b/lib/std/intparse.myr
index 4180f8c..f05ddf7 100644
--- a/lib/std/intparse.myr
+++ b/lib/std/intparse.myr
@@ -43,13 +43,11 @@ generic intparsebase = {s, base
}
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
;;
diff --git a/lib/std/optparse.myr b/lib/std/optparse.myr
index d3c72ee..81b0d98 100644
--- a/lib/std/optparse.myr
+++ b/lib/std/optparse.myr
@@ -104,7 +104,7 @@ const optnext = {ctx
var c
var arg
- (c, ctx.curarg) = striter(ctx.curarg)
+ (c, ctx.curarg) = strstep(ctx.curarg)
match optinfo(ctx, c)
| `None:
diff --git a/lib/std/utf.myr b/lib/std/utf.myr
index a5ef05d..b3acb40 100644
--- a/lib/std/utf.myr
+++ b/lib/std/utf.myr
@@ -6,12 +6,37 @@ pkg std =
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 @@ const decode = {buf
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
diff --git a/mbld/parse.myr b/mbld/parse.myr
index 425e225..8c02775 100644
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -650,7 +650,7 @@ const matchc = {p, c
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 peekc = {p
const getc = {p
var c, s
- (c, s) = std.striter(p.rest)
+ (c, s) = std.strstep(p.rest)
p.rest = s
-> c
}
diff --git a/mbldwrap.sh b/mbldwrap.sh
index b074c8a..e4aacc6 100755
--- 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 @@ if [ -f mbld/mbld ]; then
./mbld/mbld $@ || mbld $@ || \
(echo "Unable to run mbld $@; have you build successfully"; false)
else
- ./mbld/mbld || mbld || $BOOT
+ ./mbld/mbld || mbld
fi
diff --git a/test/encodechar.myr b/test/encodechar.myr
index ca2ff76..ed1fda7 100644
--- a/test/encodechar.myr
+++ b/test/encodechar.myr
@@ -7,13 +7,11 @@ const main = {args : byte[:][:]
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")