summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-30 22:18:21 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-30 22:18:21 -0700
commit8672ce0c95bf5d6e6b721694bd0e5944d4af556b (patch)
treead54ebc4603c410cd9eb0b2f07cf133a701ff185 /lib
parent7cc7912b2834f9f5dde95412e5302f13fb82042c (diff)
downloadmc-8672ce0c95bf5d6e6b721694bd0e5944d4af556b.tar.gz
Replace bio.status(@t) with std.result(@t, bio.err)
It's more consistent.
Diffstat (limited to 'lib')
-rw-r--r--lib/bio/bio.myr187
-rw-r--r--lib/bio/geti.myr36
-rw-r--r--lib/bio/iter.myr10
-rw-r--r--lib/bio/puti.myr28
-rw-r--r--lib/bio/test/bio-delim.myr12
-rw-r--r--lib/bio/test/bio-endianrd.myr29
-rw-r--r--lib/bio/test/bio-peek.myr12
-rw-r--r--lib/bio/test/bio-read.myr6
-rw-r--r--lib/bio/test/mem.myr6
-rw-r--r--lib/http/client.myr17
-rw-r--r--lib/http/parse.myr29
-rw-r--r--lib/http/session.myr10
-rw-r--r--lib/inifile/parse.myr6
-rw-r--r--lib/inifile/write.myr2
-rw-r--r--lib/regex/redump.myr6
15 files changed, 175 insertions, 221 deletions
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr
index 0a611f3..437cde6 100644
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -33,17 +33,10 @@ pkg bio =
close : (-> bool)
;;
- type status(@a) = union
+ type err = union
`Eof
- `Ok @a
- `Err ioerr
- ;;
-
- type ioerr = union
- `Ebadfile
- `Ebadbuf
- `Ebadfd
- `Eioerr
+ `Eio
+ `Ebadf
;;
/* creation */
@@ -56,36 +49,36 @@ pkg bio =
const free : (f : file# -> void)
/* basic i/o. Returns sub-buffer when applicable. */
- const write : (f : file#, src : byte[:] -> status(std.size))
- const read : (f : file#, dst : byte[:] -> status(byte[:]))
+ const write : (f : file#, src : byte[:] -> std.result(std.size, err))
+ const read : (f : file#, dst : byte[:] -> std.result(byte[:], err))
const flush : (f : file# -> bool)
/* seeking */
- const seek : (f : file#, off : std.off -> std.result(std.off, ioerr))
+ const seek : (f : file#, off : std.off -> std.result(std.off, err))
/* single unit operations */
- const putb : (f : file#, b : byte -> status(std.size))
- const putc : (f : file#, c : char -> status(std.size))
- const getb : (f : file# -> status(byte))
- const getc : (f : file# -> status(char))
+ const putb : (f : file#, b : byte -> std.result(std.size, err))
+ const putc : (f : file#, c : char -> std.result(std.size, err))
+ const getb : (f : file# -> std.result(byte, err))
+ const getc : (f : file# -> std.result(char, err))
/* peeking */
- const peekb : (f : file# -> status(byte))
- const peekc : (f : file# -> status(char))
+ const peekb : (f : file# -> std.result(byte, err))
+ const peekc : (f : file# -> std.result(char, err))
/* delimited read; returns freshly allocated buffer. */
- const readln : (f : file# -> status(byte[:]))
- const readto : (f : file#, delim : byte[:] -> status(byte[:]))
+ const readln : (f : file# -> std.result(byte[:], err))
+ const readto : (f : file#, delim : byte[:] -> std.result(byte[:], err))
const skipto : (f : file#, delim : byte[:] -> bool)
const skipspace : (f : file# -> bool)
/* formatted i/o */
- const put : (f : file#, fmt : byte[:], args : ... -> status(std.size))
- const putv : (f : file#, fmt : byte[:], ap : std.valist# -> status(std.size))
+ const put : (f : file#, fmt : byte[:], args : ... -> std.result(std.size, err))
+ const putv : (f : file#, fmt : byte[:], ap : std.valist# -> std.result(std.size, err))
/* pkg funcs */
- pkglocal const ensureread : (f : file#, n : std.size -> status(std.size))
- pkglocal const ensurewrite : (f : file#, n : std.size -> status(std.size))
+ pkglocal const ensureread : (f : file#, n : std.size -> std.result(std.size, err))
+ pkglocal const ensurewrite : (f : file#, n : std.size -> std.result(std.size, err))
;;
const Bufsz = 16*std.KiB
@@ -208,7 +201,7 @@ const write = {f, src
if src.len <= (f.wbuf.len - f.wend)
std.slcp(f.wbuf[f.wend:f.wend+src.len], src)
f.wend += src.len
- -> `Ok src.len
+ -> `std.Ok src.len
else
flush(f)
-> writebuf(f, src)
@@ -225,7 +218,7 @@ const read = {f, dst
/* Clear the error state so we can retry */
if f.lasterr != 0
- -> `Err geterr(f)
+ -> `std.Err geterr(f)
;;
/*
@@ -235,7 +228,7 @@ const read = {f, dst
an EOF condition.
*/
if dst.len == 0
- -> `Ok dst
+ -> `std.Ok dst
;;
std.assert(f.mode & Rd != 0, "File is not in read mode")
/*
@@ -268,7 +261,7 @@ const read = {f, dst
d = d[n:]
| `std.Err err:
if count == 0
- -> `Err errtype(err)
+ -> `std.Err errtype(err)
else
f.lasterr = err
;;
@@ -276,9 +269,9 @@ const read = {f, dst
;;
;;
if count == 0
- -> `Eof
+ -> `std.Err `Eof
else
- -> `Ok dst[:count]
+ -> `std.Ok dst[:count]
;;
}
@@ -289,7 +282,7 @@ const flush = {f
ret = true
if f.mode & Wr != 0
match writebuf(f, f.wbuf[:f.wend])
- | `Ok n: ret = (n == f.wend)
+ | `std.Ok n: ret = (n == f.wend)
| _: ret = false
;;
;;
@@ -309,11 +302,10 @@ const seek = {f, off
/* writes a single byte to the output stream */
const putb = {f, b
match ensurewrite(f, 1)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok n:
+ | `std.Err e: -> `std.Err e
+ | `std.Ok n:
f.wbuf[f.wend++] = b
- -> `Ok 1
+ -> `std.Ok 1
;;
}
@@ -323,22 +315,20 @@ const putc = {f, c
sz = std.charlen(c)
match ensurewrite(f, sz)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok n:
+ | `std.Err e: -> `std.Err e
+ | `std.Ok n:
std.encode(f.wbuf[f.wend:], c)
f.wend += sz
- -> `Ok sz
+ -> `std.Ok sz
;;
}
/* reads a single byte from the input stream */
const getb = {f
match ensureread(f, 1)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok n:
- -> `Ok f.rbuf[f.rstart++]
+ | `std.Err e: -> `std.Err e
+ | `std.Ok n:
+ -> `std.Ok f.rbuf[f.rstart++]
;;
}
@@ -347,12 +337,11 @@ const getc = {f
var c
match ensurecodepoint(f)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok n:
+ | `std.Err e: -> `std.Err e
+ | `std.Ok n:
c = std.decode(f.rbuf[f.rstart:f.rend])
f.rstart += std.charlen(c)
- -> `Ok c
+ -> `std.Ok c
;;
}
@@ -362,9 +351,8 @@ const ensurecodepoint = {f
var len
match ensureread(f, 1)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok n:
+ | `std.Err e: -> `std.Err e
+ | `std.Ok n:
b = f.rbuf[f.rstart]
if b & 0x80 == 0 /* 0b0xxx_xxxx */
len = 1
@@ -408,20 +396,18 @@ generic putbe = {f, v : @a::(numeric,integral)
/* peeks a single byte from an input stream */
const peekb = {f
match ensureread(f, 1)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok n:
- -> `Ok f.rbuf[f.rstart]
+ | `std.Err e: -> `std.Err e
+ | `std.Ok n:
+ -> `std.Ok f.rbuf[f.rstart]
;;
}
/* peeks a single character from a utf8 encoded input stream */
const peekc = {f
match ensurecodepoint(f)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok n:
- -> `Ok std.decode(f.rbuf[f.rstart:f.rend])
+ | `std.Err e: -> `std.Err e
+ | `std.Ok n:
+ -> `std.Ok std.decode(f.rbuf[f.rstart:f.rend])
;;
}
@@ -441,23 +427,20 @@ const readto = {f, delim
/* same as readto, but drops the read data. */
const skipto = {f, delim
match readdelim(f, delim, true)
- | `Ok ign: -> true
- | `Eof: -> false
- | `Err _: -> false
+ | `std.Ok ign: -> true
+ | `std.Err _: -> false
;;
}
const skipspace = {f
while true
match bio.peekc(f)
- | `Ok c:
+ | `std.Ok c:
if !std.isspace(c)
break
;;
bio.getc(f)
- | `Err e: -> false
- | `Eof: break
-
+ | `std.Err e: -> false
;;
;;
-> true
@@ -471,15 +454,15 @@ const readln = {f
while true
/* get at least delimiter count of characters */
match ensureread(f, 1)
- | `Ok _:
- | `Err e: -> `Err e
- | `Eof:
+ | `std.Err `Eof:
ret = readinto(f, ret, f.rend - f.rstart)
if ret.len > 0
- -> `Ok ret
+ -> `std.Ok ret
else
- -> `Eof
+ -> `std.Err `Eof
;;
+ | `std.Err e: -> `std.Err e
+ | `std.Ok _:
;;
/* scan for delimiter */
for var i = f.rstart; i < f.rend; i++
@@ -491,7 +474,7 @@ const readln = {f
if c == '\r' && unwrapc(peekc(f), -1) == '\n'
f.rstart++
;;
- -> `Ok ret
+ -> `std.Ok ret
;;
:nextitergetln
;;
@@ -502,7 +485,7 @@ const readln = {f
const unwrapc = {cc, v
match cc
- | `Ok c: -> c
+ | `std.Ok c: -> c
| _: -> v
;;
}
@@ -514,17 +497,17 @@ const readdelim = {f, delim, drop
while true
/* get at least delimiter count of characters */
match ensureread(f, 1)
- | `Ok _:
- | `Err e: -> `Err e
- | `Eof:
+ | `std.Err `Eof:
if !drop
ret = readinto(f, ret, f.rend - f.rstart)
;;
if ret.len > 0
- -> `Ok ret
+ -> `std.Ok ret
else
- -> `Eof
+ -> `std.Err `Eof
;;
+ | `std.Err e: -> `std.Err e
+ | `std.Ok _:
;;
for var i = f.rstart; i < f.rend; i++
if f.rbuf[i] == delim[0]
@@ -537,7 +520,7 @@ const readdelim = {f, delim, drop
ret = readinto(f, ret, i - f.rstart)
;;
f.rstart += delim.len
- -> `Ok ret
+ -> `std.Ok ret
;;
:nextiterread
;;
@@ -591,14 +574,13 @@ const ensurewrite = {f, n
std.assert(n < f.wbuf.len, "ensured write capacity > buffer size")
if n > f.wbuf.len - f.wend
match writebuf(f, f.wbuf[:f.wend])
- | `Ok len:
+ | `std.Ok len:
f.wend = 0
- -> `Ok len
- | `Err e: -> `Err e
- | `Eof: -> `Eof
+ -> `std.Ok len
+ | `std.Err e: -> `std.Err e
;;
;;
- -> `Ok n
+ -> `std.Ok n
}
/*
@@ -612,17 +594,16 @@ const ensureread = {f, n
held = f.rend - f.rstart
if n > held
match fill(f, n)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok len:
+ | `std.Err e: -> `std.Err e
+ | `std.Ok len:
if len >= n
- -> `Ok len
+ -> `std.Ok len
else
- -> `Eof
+ -> `std.Err `Eof
;;
;;
else
- -> `Ok n
+ -> `std.Ok n
;;
}
@@ -634,16 +615,16 @@ const writebuf = {f, src
while src.len != 0
match f.write(src)
| `std.Ok 0:
- -> `Eof
+ -> `std.Err `Eof
| `std.Ok n:
count += n
src = src[n:]
| `std.Err e:
- -> `Err errtype(e)
+ -> `std.Err errtype(e)
;;
;;
:writedone
- -> `Ok count
+ -> `std.Ok count
}
@@ -658,7 +639,7 @@ const fill = {f, min
count = 0
/* Clear the error state so we can retry */
if f.lasterr != 0
- -> `Err geterr(f)
+ -> `std.Err geterr(f)
;;
/* if we need to shift the slice down to the start, do it */
@@ -684,16 +665,16 @@ const fill = {f, min
if count > 0
f.lasterr = e
else
- -> `Err errtype(e)
+ -> `std.Err errtype(e)
;;
break
;;
;;
if count == 0
- -> `Eof
+ -> `std.Err `Eof
else
- -> `Ok count
+ -> `std.Ok count
;;
}
@@ -705,20 +686,18 @@ const geterr = {f
-> errtype(e)
}
-const errtype = {e : std.errno -> ioerr
+const errtype = {e : std.errno -> err
var errno
errno = (e : std.errno)
if errno == std.Ebadf
- -> `Ebadfile
+ -> `Ebadf
elif errno == std.Einval
- -> `Ebadfile
+ -> `Ebadf
elif errno == std.Efault
- -> `Ebadbuf
- elif errno == std.Eio
- -> `Eioerr
+ -> `Eio
else
- -> `Eioerr
+ -> `Eio
;;
}
diff --git a/lib/bio/geti.myr b/lib/bio/geti.myr
index 70186b2..3b6eb3e 100644
--- a/lib/bio/geti.myr
+++ b/lib/bio/geti.myr
@@ -4,34 +4,34 @@ use "bio"
pkg bio =
/* unsigned big endian */
- generic getbe8 : (f : file# -> status(@a::(numeric,integral)))
- generic getbe16 : (f : file# -> status(@a::(numeric,integral)))
- generic getbe32 : (f : file# -> status(@a::(numeric,integral)))
- generic getbe64 : (f : file# -> status(@a::(numeric,integral)))
+ generic getbe8 : (f : file# -> std.result(@a::(numeric,integral), err))
+ generic getbe16 : (f : file# -> std.result(@a::(numeric,integral), err))
+ generic getbe32 : (f : file# -> std.result(@a::(numeric,integral), err))
+ generic getbe64 : (f : file# -> std.result(@a::(numeric,integral), err))
/* signed big endian */
- generic getle8 : (f : file# -> status(@a::(numeric,integral)))
- generic getle16 : (f : file# -> status(@a::(numeric,integral)))
- generic getle32 : (f : file# -> status(@a::(numeric,integral)))
- generic getle64 : (f : file# -> status(@a::(numeric,integral)))
+ generic getle8 : (f : file# -> std.result(@a::(numeric,integral), err))
+ generic getle16 : (f : file# -> std.result(@a::(numeric,integral), err))
+ generic getle32 : (f : file# -> std.result(@a::(numeric,integral), err))
+ generic getle64 : (f : file# -> std.result(@a::(numeric,integral), err))
;;
/*
reads a single integer-like value to the output stream, in
little endian format
*/
-generic getle = {f, n -> status(@a::(numeric,integral))
+generic getle = {f, n -> std.result(@a::(numeric,integral), err)
var v, i
v = 0
match ensureread(f, n)
- | `Eof: -> `Eof
- | `Err e : -> `Err e
- | `Ok _:
+ | `std.Err e:
+ -> `std.Err e
+ | `std.Ok _:
for i = 0; i < n; i++
v |= (f.rbuf[f.rstart++] : uint64) << (8*(i : uint64))
;;
- -> `Ok (v : @a::(numeric,integral))
+ -> `std.Ok (v : @a::(numeric,integral))
;;
}
@@ -39,19 +39,19 @@ generic getle = {f, n -> status(@a::(numeric,integral))
reads a single integer-like value to the output stream, in
big endian format
*/
-generic getbe = {f, n -> status(@a::(numeric,integral))
+generic getbe = {f, n -> std.result(@a::(numeric,integral), err)
var v, i
v = 0
match ensureread(f, n)
- | `Eof: -> `Eof
- | `Err e : -> `Err e
- | `Ok _:
+ | `std.Err e:
+ -> `std.Err e
+ | `std.Ok _:
for i = 0; i < n; i++
v <<= 8
v |= (f.rbuf[f.rstart++] : uint64)
;;
- -> `Ok (v : @a::(numeric,integral))
+ -> `std.Ok (v : @a::(numeric,integral))
;;
}
diff --git a/lib/bio/iter.myr b/lib/bio/iter.myr
index dbdd025..55379ed 100644
--- a/lib/bio/iter.myr
+++ b/lib/bio/iter.myr
@@ -18,9 +18,8 @@ const byline = {f
impl iterable lineiter -> byte[:] =
__iternext__ = {itp, outp
match bio.readln((itp# : file#))
- | `Ok ln: outp# = ln
- | `Err _: -> false
- | `Eof: -> false
+ | `std.Ok ln: outp# = ln
+ | `std.Err _: -> false
;;
-> true
}
@@ -37,9 +36,8 @@ const bychar = {f
impl iterable chariter -> char =
__iternext__ = {itp, outp : char#
match bio.getc((itp# : file#))
- | `Ok c: outp# = c
- | `Err _: -> false
- | `Eof: -> false
+ | `std.Ok c: outp# = c
+ | `std.Err _: -> false
;;
-> true
}
diff --git a/lib/bio/puti.myr b/lib/bio/puti.myr
index d4d7a3f..056f6a4 100644
--- a/lib/bio/puti.myr
+++ b/lib/bio/puti.myr
@@ -4,16 +4,16 @@ use "bio"
pkg bio =
/* unsigned big endian */
- generic putbe8 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
- generic putbe16 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
- generic putbe32 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
- generic putbe64 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
+ generic putbe8 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
+ generic putbe16 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
+ generic putbe32 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
+ generic putbe64 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
/* unsigned little endian */
- generic putle8 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
- generic putle16 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
- generic putle32 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
- generic putle64 : (f : file#, v : @a::(numeric,integral) -> status(std.size))
+ generic putle8 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
+ generic putle16 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
+ generic putle32 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
+ generic putle64 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err))
;;
generic putbe8 = {f, v; -> putbe(f, (v : uint64), 1)}
@@ -30,9 +30,9 @@ const putle = {f, v, n
var buf : byte[8]
match ensurewrite(f, n)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok _:
+ | `std.Err e:
+ -> `std.Err e
+ | `std.Ok _:
buf[0] = ((v >> 0) & 0xff : byte)
buf[1] = ((v >> 8) & 0xff : byte)
buf[2] = ((v >> 16) & 0xff : byte)
@@ -49,9 +49,9 @@ const putbe = {f, v, n
var buf : byte[8]
match ensurewrite(f, n)
- | `Eof: -> `Eof
- | `Err e: -> `Err e
- | `Ok _:
+ | `std.Err e:
+ -> `std.Err e
+ | `std.Ok _:
buf[0] = ((v >> 56) & 0xff : byte)
buf[1] = ((v >> 48) & 0xff : byte)
buf[2] = ((v >> 40) & 0xff : byte)
diff --git a/lib/bio/test/bio-delim.myr b/lib/bio/test/bio-delim.myr
index 354dc50..dbc2f65 100644
--- a/lib/bio/test/bio-delim.myr
+++ b/lib/bio/test/bio-delim.myr
@@ -67,11 +67,11 @@ const main = {
const readln = {f
match bio.readln(f)
- | `bio.Ok d: -> d
- | `bio.Eof:
+ | `std.Ok d: -> d
+ | `std.Err `bio.Eof:
std.put("eof\n")
-> [][:]
- | `bio.Err e:
+ | `std.Err e:
std.put("err\n")
-> [][:]
;;
@@ -79,11 +79,11 @@ const readln = {f
const readto = {f, delim
match bio.readto(f, delim)
- | `bio.Ok d: -> d
- | `bio.Eof:
+ | `std.Ok d: -> d
+ | `std.Err `bio.Eof:
std.put("eof\n")
-> [][:]
- | `bio.Err e:
+ | `std.Err e:
std.put("err\n")
-> [][:]
;;
diff --git a/lib/bio/test/bio-endianrd.myr b/lib/bio/test/bio-endianrd.myr
index e445459..8296c75 100644
--- a/lib/bio/test/bio-endianrd.myr
+++ b/lib/bio/test/bio-endianrd.myr
@@ -1,13 +1,6 @@
use std
use bio
-generic try = {opt : bio.status(@a::(integral,numeric))-> @a::(integral,numeric)
- match opt
- | `bio.Ok val: -> val
- | _: std.fatal("read failed")
- ;;
-}
-
const main = {
var b : byte
var w : uint16
@@ -23,31 +16,31 @@ const main = {
/* byte */
b = 0xaa
- var r = try(bio.getle8(f))
+ var r = std.try(bio.getle8(f))
std.assert(r == b, "le byte broken: {x}\n", r)
- std.assert(try(bio.getbe8(f)) == b, "be byte broken\n")
+ std.assert(std.try(bio.getbe8(f)) == b, "be byte broken\n")
/* word */
w = 0xaabb
- std.assert(try(bio.getle16(f)) == w, "le word broken\n")
- std.assert(try(bio.getbe16(f)) == w, "be word broken\n")
+ std.assert(std.try(bio.getle16(f)) == w, "le word broken\n")
+ std.assert(std.try(bio.getbe16(f)) == w, "be word broken\n")
/* long */
l = 0xaabbccdd
- std.assert(try(bio.getle32(f)) == l, "le long broken\n")
- std.assert(try(bio.getbe32(f)) == l, "be long broken\n")
+ std.assert(std.try(bio.getle32(f)) == l, "le long broken\n")
+ std.assert(std.try(bio.getbe32(f)) == l, "be long broken\n")
/* quad */
q = (0x11223344aabbccdd : uint64)
- std.assert(try(bio.getle64(f)) == q, "le quad broken\n")
- std.assert(try(bio.getbe64(f)) == q, "be quad broken\n")
+ std.assert(std.try(bio.getle64(f)) == q, "le quad broken\n")
+ std.assert(std.try(bio.getbe64(f)) == q, "be quad broken\n")
/* end of file */
match bio.getle64(f)
- | `bio.Eof:
- | `bio.Err _:
+ | `std.Err `bio.Eof:
+ | `std.Err _:
std.die("error on reading file\n")
- | `bio.Ok v:
+ | `std.Ok v:
std.die("read past end of file\n")
v = q /* shut up type inference */
;;
diff --git a/lib/bio/test/bio-peek.myr b/lib/bio/test/bio-peek.myr
index 506dea0..a0f4752 100644
--- a/lib/bio/test/bio-peek.myr
+++ b/lib/bio/test/bio-peek.myr
@@ -28,11 +28,11 @@ const main = {
const peekc = {f
match bio.peekc(f)
- | `bio.Ok c: -> c
- | `bio.Eof:
+ | `std.Ok c: -> c
+ | `std.Err `bio.Eof:
std.put("eof\n")
-> -1
- | `bio.Err e:
+ | `std.Err e:
std.fatal("error reading\n")
-> -1
;;
@@ -40,11 +40,11 @@ const peekc = {f
const peekb = {f
match bio.peekb(f)
- | `bio.Ok b: -> b
- | `bio.Eof:
+ | `std.Ok b: -> b
+ | `std.Err `bio.Eof:
std.put("eof\n")
-> -1
- | `bio.Err e:
+ | `std.Err e:
std.fatal("error reading\n")
-> -1
;;
diff --git a/lib/bio/test/bio-read.myr b/lib/bio/test/bio-read.myr
index 829b442..3e477c2 100644
--- a/lib/bio/test/bio-read.myr
+++ b/lib/bio/test/bio-read.myr
@@ -40,12 +40,12 @@ const main = {
const r = {f, buf
match bio.read(f, buf)
- | `bio.Ok b:
+ | `std.Ok b:
-> b
- | `bio.Eof:
+ | `std.Err `bio.Eof:
std.put("eof\n")
-> ""
- | `bio.Err e:
+ | `std.Err e:
std.put("err\n")
-> ""
;;
diff --git a/lib/bio/test/mem.myr b/lib/bio/test/mem.myr
index f3135d2..a7cb613 100644
--- a/lib/bio/test/mem.myr
+++ b/lib/bio/test/mem.myr
@@ -7,21 +7,21 @@ const main = {
f = bio.mkmem("hello world")
match bio.read(f, buf[:3])
- | `bio.Ok "hel":
+ | `std.Ok "hel":
/* ok */
| _:
std.fatal("invalid read from memfile")
;;
match bio.read(f, buf[:])
- | `bio.Ok "lo world":
+ | `std.Ok "lo world":
/* ok */
| _:
std.fatal("invalid read from memfile")
;;
match bio.read(f, buf[:])
- | `bio.Eof:
+ | `std.Err `bio.Eof:
/* ok */
| _:
std.fatal("expected eof in memfile")
diff --git a/lib/http/client.myr b/lib/http/client.myr
index 4fdf481..770c233 100644
--- a/lib/http/client.myr
+++ b/lib/http/client.myr
@@ -180,9 +180,8 @@ const readlenbody = {s, r
buf = std.slalloc(r.len)
match bio.read(s.f, buf)
- | `bio.Err e: goto shortread
- | `bio.Eof: goto shortread
- | `bio.Ok rd:
+ | `std.Err e: goto shortread
+ | `std.Ok rd:
if rd.len != r.len
goto shortread
;;
@@ -215,13 +214,10 @@ const readchunkedbody = {s, r
| `std.Ok sz:
std.slgrow(&buf, buf.len + sz)
match bio.read(s.f, buf[len:len + sz])
- | `bio.Eof:
- std.slfree(buf)
- -> `std.Err `Eshort
- | `bio.Err e:
+ | `std.Err e:
std.slfree(buf)
-> `std.Err `Econn
- | `bio.Ok str:
+ | `std.Ok str:
if str.len != sz
std.slfree(buf)
-> `std.Err `Eshort
@@ -243,9 +239,8 @@ const checkendln = {s
var r
match bio.readln(s.f)
- | `bio.Err e: r = `std.Err `Econn
- | `bio.Eof: r = `std.Err `Econn
- | `bio.Ok crlf:
+ | `std.Err e: r = `std.Err `Econn
+ | `std.Ok crlf:
if std.strstrip(crlf).len == 0
r = `std.Ok void
else
diff --git a/lib/http/parse.myr b/lib/http/parse.myr
index d9f8b34..fabf7a2 100644
--- a/lib/http/parse.myr
+++ b/lib/http/parse.myr
@@ -23,13 +23,10 @@ const parsereq = {s
])
match bio.readln(s.f)
- | `bio.Err e:
- err = `Econn
- goto error
- | `bio.Eof:
+ | `std.Err e:
err = `Econn
goto error
- | `bio.Ok ln:
+ | `std.Ok ln:
match parsereqstatus(s, r, ln)
| `std.Ok void:
| `std.Err e:
@@ -42,13 +39,10 @@ const parsereq = {s
while true
match bio.readln(s.f)
- | `bio.Err e:
- err = `Econn
- goto error
- | `bio.Eof:
+ | `std.Err e:
err = `Econn
goto error
- | `bio.Ok ln:
+ | `std.Ok ln:
if std.strstrip(ln).len == 0
std.slfree(ln)
break
@@ -70,9 +64,8 @@ const parsereq = {s
const parseresp = {s, r : resp#
match bio.readln(s.f)
- | `bio.Err e: r.err = `std.Some `Econn
- | `bio.Eof: r.err = `std.Some `Econn
- | `bio.Ok ln:
+ | `std.Err _: r.err = `std.Some `Econn
+ | `std.Ok ln:
if !parserespstatus(s, r, ln)
std.slfree(ln)
-> false
@@ -82,9 +75,8 @@ const parseresp = {s, r : resp#
while true
match bio.readln(s.f)
- | `bio.Err e: r.err = `std.Some `Econn
- | `bio.Eof: r.err = `std.Some `Econn
- | `bio.Ok ln:
+ | `std.Err e: r.err = `std.Some `Econn
+ | `std.Ok ln:
if std.strstrip(ln).len == 0
std.slfree(ln)
break
@@ -203,9 +195,8 @@ const parsechunksz = {s
var ret, str
match bio.readln(s.f)
- | `bio.Eof: ret = `std.Err `Econn
- | `bio.Err e: ret = `std.Err `Econn
- | `bio.Ok ln:
+ | `std.Err e: ret = `std.Err `Econn
+ | `std.Ok ln:
str = ln
match parsenumber(&str, 16)
| `std.Some n: ret = `std.Ok (n : std.size)
diff --git a/lib/http/session.myr b/lib/http/session.myr
index 2b6f65a..4091165 100644
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -58,9 +58,8 @@ const ioput = {s, fmt, args
;;
ap = std.vastart(&args)
match bio.putv(s.f, fmt, &ap)
- | `bio.Ok _: /* nothing */
- | `bio.Err _: s.err = true
- | `bio.Eof: s.err = true
+ | `std.Ok _: /* nothing */
+ | `std.Err _: s.err = true
;;
-> s.err
}
@@ -70,9 +69,8 @@ const iowrite = {s, buf
-> false
;;
match bio.write(s.f, buf)
- | `bio.Ok _: /* nothing */
- | `bio.Err _: s.err = true
- | `bio.Eof: s.err = true
+ | `std.Ok _: /* nothing */
+ | `std.Err _: s.err = true
;;
-> s.err
}
diff --git a/lib/inifile/parse.myr b/lib/inifile/parse.myr
index cd78813..6b9be91 100644
--- a/lib/inifile/parse.myr
+++ b/lib/inifile/parse.myr
@@ -54,13 +54,13 @@ const loadf = {fd
f = bio.mkfile(fd, bio.Rd)
while true
match bio.readln(f)
- | `bio.Eof:
+ | `std.Err `bio.Eof:
break
- | `bio.Ok ln:
+ | `std.Ok ln:
if !parseline(p, ini, ln)
break
;;
- | `bio.Err e:
+ | `std.Err e:
p.err = `std.Some `Fileerr
break
;;
diff --git a/lib/inifile/write.myr b/lib/inifile/write.myr
index 1c7071d..ab4042c 100644
--- a/lib/inifile/write.myr
+++ b/lib/inifile/write.myr
@@ -53,7 +53,7 @@ const writeini = {f, ini
val = std.htgetv(ini.elts, (sect, key), "")
match bio.put(f, "\t{} = {}\n", key, val)
- | `bio.Err e: -> false
+ | `std.Err e: -> false
| _:
;;
;;
diff --git a/lib/regex/redump.myr b/lib/regex/redump.myr
index e47b824..2cbb4ad 100644
--- a/lib/regex/redump.myr
+++ b/lib/regex/redump.myr
@@ -57,12 +57,12 @@ const runall = {re, files
const dump = {re, fd
while true
match bio.readln(fd)
- | `bio.Ok ln:
+ | `std.Ok ln:
show(re, ln, regex.exec(re, ln))
std.slfree(ln)
- | `bio.Eof:
+ | `std.Err `bio.Eof:
break
- | `bio.Err e:
+ | `std.Err e:
std.put("error reading from input: {}", e)
break
;;