summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-12-30 19:23:12 -0800
committerOri Bernstein <ori@eigenstate.org>2017-12-30 19:23:12 -0800
commitf4a939a2cfdc00643b02c404b0acbed382964dd0 (patch)
tree107db984a46b56f0803960155dba25977df78aae /lib
parentb4252aeded2d15592fe940e20f533f113000c61d (diff)
downloadmc-f4a939a2cfdc00643b02c404b0acbed382964dd0.tar.gz
Start cleaning up libstd.
minor formatting, factoring out iterutil.
Diffstat (limited to 'lib')
-rw-r--r--lib/bld.sub1
-rw-r--r--lib/iter/bld.sub7
-rw-r--r--lib/iter/chunk.myr34
-rw-r--r--lib/iter/enum.myr30
-rw-r--r--lib/iter/ref.myr29
-rw-r--r--lib/iter/reverse.myr30
-rw-r--r--lib/iter/test/enum.myr12
-rw-r--r--lib/iter/test/reverse.myr14
-rw-r--r--lib/iter/test/zip.myr15
-rw-r--r--lib/iter/zip.myr30
-rw-r--r--lib/std/alloc.myr18
-rw-r--r--lib/std/bld.sub1
-rw-r--r--lib/std/bytealloc.myr14
-rw-r--r--lib/std/clear.myr1
-rw-r--r--lib/std/cmp.myr6
-rw-r--r--lib/std/dialparse+posixy.myr4
-rw-r--r--lib/std/fltfmt.myr2
-rw-r--r--lib/std/getcwd.myr2
-rw-r--r--lib/std/hasprefix.myr1
-rw-r--r--lib/std/hassuffix.myr1
-rw-r--r--lib/std/ipparse.myr1
-rw-r--r--lib/std/iterutil.myr140
-rw-r--r--lib/std/listen+posixy.myr1
-rw-r--r--lib/std/mktemp.myr8
-rw-r--r--lib/std/resolve+posixy.myr4
-rw-r--r--lib/std/slpush.myr12
-rw-r--r--lib/std/slput.myr4
-rw-r--r--lib/std/slurp.myr4
-rw-r--r--lib/std/test/iterutil.myr26
-rw-r--r--lib/std/try.myr8
-rw-r--r--lib/std/varargs.myr10
-rw-r--r--lib/std/writeall.myr6
32 files changed, 255 insertions, 221 deletions
diff --git a/lib/bld.sub b/lib/bld.sub
index da62ed6..97effae 100644
--- a/lib/bld.sub
+++ b/lib/bld.sub
@@ -6,6 +6,7 @@ sub =
fileutil
http
inifile
+ iter
json
regex
std
diff --git a/lib/iter/bld.sub b/lib/iter/bld.sub
new file mode 100644
index 0000000..f3ba696
--- /dev/null
+++ b/lib/iter/bld.sub
@@ -0,0 +1,7 @@
+lib iter =
+ chunk.myr
+ enum.myr
+ ref.myr
+ reverse.myr
+ zip.myr
+;;
diff --git a/lib/iter/chunk.myr b/lib/iter/chunk.myr
new file mode 100644
index 0000000..5d0d68c
--- /dev/null
+++ b/lib/iter/chunk.myr
@@ -0,0 +1,34 @@
+use std
+
+pkg iter =
+ type chunkiter(@a) = struct
+ idx : std.size
+ blksz : std.size
+ sl : @a[:]
+ ;;
+
+ impl iterable chunkiter(@a) -> @a[:]
+ generic bychunk : (a : @a[:], chunk : std.size -> chunkiter(@a))
+;;
+
+generic bychunk = {a, sz
+ -> [.sl = a, .idx = 0, .blksz = sz]
+}
+
+impl iterable chunkiter(@a) -> @a[:] =
+ __iternext__ = {itp, valp
+ var len
+
+ len = std.min(itp.blksz, itp.sl.len - itp.idx)
+ if itp.idx + len == itp.sl.len
+ -> false
+ ;;
+ valp# = itp.sl[itp.idx: itp.idx + len]
+ itp.idx += itp.blksz
+ -> true
+ }
+
+ __iterfin__ = {itp, valp
+ }
+;;
+
diff --git a/lib/iter/enum.myr b/lib/iter/enum.myr
new file mode 100644
index 0000000..e59a0ae
--- /dev/null
+++ b/lib/iter/enum.myr
@@ -0,0 +1,30 @@
+use std
+
+pkg iter =
+ type enumiter(@a) = struct
+ idx : std.size
+ sl : @a[:]
+ ;;
+
+ impl iterable enumiter(@a) -> (std.size, @a)
+ generic byenum : (a : @a[:] -> enumiter(@a))
+;;
+
+generic byenum = {a
+ -> [.sl = a, .idx = 0]
+}
+
+impl iterable enumiter(@a) -> (std.size, @a) =
+ __iternext__ = {itp, valp
+ if itp.idx == itp.sl.len
+ -> false
+ ;;
+ valp# = (itp.idx, itp.sl[itp.idx])
+ itp.idx++
+ -> true
+ }
+
+ __iterfin__ = {itp, valp
+ }
+;;
+
diff --git a/lib/iter/ref.myr b/lib/iter/ref.myr
new file mode 100644
index 0000000..45813c0
--- /dev/null
+++ b/lib/iter/ref.myr
@@ -0,0 +1,29 @@
+use std
+
+pkg iter =
+ type refiter(@a) = struct
+ idx : std.size
+ sl : @a[:]
+ ;;
+ impl iterable refiter(@a) -> @a#
+ generic byref : (sl : @a[:] -> refiter(@a))
+;;
+
+generic byref = {a
+ -> [.sl = a, .idx = 0]
+}
+
+impl iterable refiter(@a) -> @a# =
+ __iternext__ = {itp, valp
+ if itp.idx == itp.sl.len
+ -> false
+ ;;
+ valp# = &itp.sl[itp.idx]
+ itp.idx++
+ -> true
+ }
+
+ __iterfin__ = {itp, valp
+ }
+;;
+
diff --git a/lib/iter/reverse.myr b/lib/iter/reverse.myr
new file mode 100644
index 0000000..3647ba6
--- /dev/null
+++ b/lib/iter/reverse.myr
@@ -0,0 +1,30 @@
+use std
+
+pkg iter =
+ type reverseiter(@a) = struct
+ sl : @a[:]
+ idx : std.size
+ ;;
+ impl iterable reverseiter(@a) -> @a
+ generic byreverse : (sl : @a[:] -> reverseiter(@a))
+;;
+
+generic byreverse = {sl
+ -> [.sl = sl, .idx = sl.len]
+}
+
+impl iterable reverseiter(@a) -> @a =
+ __iternext__ = {itp, valp
+ if itp.idx > 0
+ valp# = itp.sl[itp.idx - 1]
+ itp.idx--
+ -> true
+ else
+ -> false
+ ;;
+ }
+
+ __iterfin__ = {itp, valp
+ }
+;;
+
diff --git a/lib/iter/test/enum.myr b/lib/iter/test/enum.myr
new file mode 100644
index 0000000..5c09734
--- /dev/null
+++ b/lib/iter/test/enum.myr
@@ -0,0 +1,12 @@
+use std
+
+const main = {
+ var n
+
+ n = 0
+ for (x, i) : std.byenum([1,3,5,7,9][:])
+ std.assert(x == n, "invalid enum idx {}", x)
+ std.assert(i == n*2 + 1, "invalid enum val {}", i)
+ n++
+ ;;
+}
diff --git a/lib/iter/test/reverse.myr b/lib/iter/test/reverse.myr
new file mode 100644
index 0000000..ed4ce1c
--- /dev/null
+++ b/lib/iter/test/reverse.myr
@@ -0,0 +1,14 @@
+use std
+use iter
+
+const main = {
+ var n, l : int[:]
+
+ n = 0
+ l = [3, 2, 1, 0][:]
+ for x : iter.byreverse(l)
+ std.assert(x == n, "invalid reversed value {}, expected {}", x, n)
+ n++
+ ;;
+
+}
diff --git a/lib/iter/test/zip.myr b/lib/iter/test/zip.myr
new file mode 100644
index 0000000..57f0563
--- /dev/null
+++ b/lib/iter/test/zip.myr
@@ -0,0 +1,15 @@
+use std
+use iter
+
+const main = {
+ var n, la : int[:], lb : int[:]
+
+ n = 0
+ la = [0,2,4,6,8][:]
+ lb = [2,4][:]
+ for (a, b) : iter.byzip(la, lb)
+ std.assert(a == n*2, "invalid val from a: {}", a)
+ std.assert(b == n*2 + 2, "invalid val from b: {}", b)
+ n++
+ ;;
+}
diff --git a/lib/iter/zip.myr b/lib/iter/zip.myr
new file mode 100644
index 0000000..6e2123c
--- /dev/null
+++ b/lib/iter/zip.myr
@@ -0,0 +1,30 @@
+pkg iter =
+ type zipiter(@a, @b) = struct
+ s1 : @a[:]
+ s2 : @b[:]
+ ;;
+
+ impl iterable zipiter(@a, @b) -> (@a, @b)
+ generic byzip : (a : @a[:], b : @b[:] -> zipiter(@a, @b))
+;;
+
+generic byzip = {a, b
+ -> [.s1 = a, .s2 = b]
+}
+
+impl iterable zipiter(@a, @b) -> (@a, @b) =
+ __iternext__ = {itp, valp
+ if itp.s1.len > 0 && itp.s2.len > 0
+ valp# = (itp.s1[0], itp.s2[0])
+ itp.s1 = itp.s1[1:]
+ itp.s2 = itp.s2[1:]
+ -> true
+ else
+ -> false
+ ;;
+ }
+
+ __iterfin__ = {itp, valp
+ }
+;;
+
diff --git a/lib/std/alloc.myr b/lib/std/alloc.myr
index cd0a6f9..576def4 100644
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -31,15 +31,15 @@ Large allocations are simply satisfied by mmap().
*/
pkg std =
- generic alloc : ( -> @a#)
- generic zalloc : ( -> @a#)
- generic free : (v:@a# -> void)
-
- generic slalloc : (len : size -> @a[:])
- generic slzalloc : (len : size -> @a[:])
- generic slgrow : (sl : @a[:]#, len : size -> @a[:])
- generic slzgrow : (sl : @a[:]#, len : size -> @a[:])
- generic slfree : (sl : @a[:] -> void)
+ generic alloc : ( -> @a#)
+ generic zalloc : ( -> @a#)
+ generic free : (v:@a# -> void)
+
+ generic slalloc : (len : size -> @a[:])
+ generic slzalloc : (len : size -> @a[:])
+ generic slgrow : (sl : @a[:]#, len : size -> @a[:])
+ generic slzgrow : (sl : @a[:]#, len : size -> @a[:])
+ generic slfree : (sl : @a[:] -> void)
;;
type slheader = struct
diff --git a/lib/std/bld.sub b/lib/std/bld.sub
index d79e512..88445c7 100644
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -38,7 +38,6 @@ lib std {inc=.} =
intparse.myr
introspect.myr
ipparse.myr
- iterutil.myr
mk.myr
mkpath.myr
mktemp.myr
diff --git a/lib/std/bytealloc.myr b/lib/std/bytealloc.myr
index 49636c8..63d18f1 100644
--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -1,4 +1,5 @@
use sys
+
use "die"
use "extremum"
use "memops"
@@ -14,17 +15,16 @@ pkg std =
const startalloctrace : (f : byte[:] -> void)
const endalloctrace : (-> void)
- /* public for testing */
- pkglocal const zbytealloc : (sz:size -> byte#)
- const bytealloc : (sz:size -> byte#)
- const bytefree : (m:byte#, sz:size -> void)
-
/* null pointers. only used internally. */
pkglocal const Zsliceptr = (0 : byte#)
pkglocal const Align = 16 /* minimum allocation alignment */
- pkglocal const align : (m : std.size, align : std.size -> std.size)
- pkglocal const allocsz : (sz : std.size -> std.size)
+ /* exported for testing */
+ const bytealloc : (sz:size -> byte#)
+ const bytefree : (m:byte#, sz:size -> void)
+ pkglocal const zbytealloc : (sz:size -> byte#)
+ pkglocal const align : (m : std.size, align : std.size -> std.size)
+ pkglocal const allocsz : (sz : std.size -> std.size)
;;
diff --git a/lib/std/clear.myr b/lib/std/clear.myr
index 6417eec..718131e 100644
--- a/lib/std/clear.myr
+++ b/lib/std/clear.myr
@@ -1,4 +1,5 @@
use "slfill"
+
pkg std =
generic clear : (p : @a# -> void)
;;
diff --git a/lib/std/cmp.myr b/lib/std/cmp.myr
index c022b2e..15d2f98 100644
--- a/lib/std/cmp.myr
+++ b/lib/std/cmp.myr
@@ -10,9 +10,9 @@ pkg std =
`After
;;
- generic numcmp : (a : @a, b : @a -> order)
- const strcmp : (a : byte[:], b : byte[:] -> order)
- const strncmp : (a : byte[:], b : byte[:], n : size -> order)
+ generic numcmp : (a : @a, b : @a -> order)
+ const strcmp : (a : byte[:], b : byte[:] -> order)
+ const strncmp : (a : byte[:], b : byte[:], n : size -> order)
const strcasecmp : (a : byte[:], b : byte[:] -> order)
;;
diff --git a/lib/std/dialparse+posixy.myr b/lib/std/dialparse+posixy.myr
index 2d0a695..76fc3ed 100644
--- a/lib/std/dialparse+posixy.myr
+++ b/lib/std/dialparse+posixy.myr
@@ -13,8 +13,8 @@ use "resolve"
pkg std =
pkglocal const parseport : (port : byte[:] -> option(uint16))
- pkglocal const getaddr : (addr : byte[:] -> result(netaddr, byte[:]))
- pkglocal const nameseg : (str : byte[:] -> option((byte[:], byte[:])))
+ pkglocal const getaddr : (addr : byte[:] -> result(netaddr, byte[:]))
+ pkglocal const nameseg : (str : byte[:] -> option((byte[:], byte[:])))
;;
const parseport = {port
diff --git a/lib/std/fltfmt.myr b/lib/std/fltfmt.myr
index 9b2e100..2a36daf 100644
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -10,7 +10,7 @@ use "utf"
use "memops"
pkg std =
- pkglocal const MNormal = 0
+ pkglocal const MNormal = 0
pkglocal const MAbsolute = 1
pkglocal const MRelative = 2
diff --git a/lib/std/getcwd.myr b/lib/std/getcwd.myr
index 9eed2ca..061a205 100644
--- a/lib/std/getcwd.myr
+++ b/lib/std/getcwd.myr
@@ -1,9 +1,9 @@
-
use "alloc"
use "errno"
use "extremum"
use "syswrap"
use "syswrap-ss"
+
pkg std =
const getcwd : (-> byte[:])
;;
diff --git a/lib/std/hasprefix.myr b/lib/std/hasprefix.myr
index 879118d..a652cd6 100644
--- a/lib/std/hasprefix.myr
+++ b/lib/std/hasprefix.myr
@@ -1,4 +1,5 @@
use "cmp"
+
pkg std =
const hasprefix : (s : byte[:], pre : byte[:] -> bool)
;;
diff --git a/lib/std/hassuffix.myr b/lib/std/hassuffix.myr
index 6f32d1d..4802da0 100644
--- a/lib/std/hassuffix.myr
+++ b/lib/std/hassuffix.myr
@@ -1,4 +1,5 @@
use "sleq"
+
pkg std =
const hassuffix : (s : byte[:], suff : byte[:] -> bool)
;;
diff --git a/lib/std/ipparse.myr b/lib/std/ipparse.myr
index 163d72e..78cb619 100644
--- a/lib/std/ipparse.myr
+++ b/lib/std/ipparse.myr
@@ -15,7 +15,6 @@ use "hasprefix"
use "utf"
pkg std =
-
type netaddr = union
`Ipv4 byte[4]
`Ipv6 byte[16]
diff --git a/lib/std/iterutil.myr b/lib/std/iterutil.myr
deleted file mode 100644
index 79b0e80..0000000
--- a/lib/std/iterutil.myr
+++ /dev/null
@@ -1,140 +0,0 @@
-use "types"
-use "fmt"
-use "extremum"
-
-pkg std =
- type zipiter(@a, @b) = struct
- s1 : @a[:]
- s2 : @b[:]
- ;;
-
- type reverseiter(@a) = struct
- sl : @a[:]
- idx : size
- ;;
-
- type enumiter(@a) = struct
- idx : size
- sl : @a[:]
- ;;
-
- type refiter(@a) = struct
- idx : size
- sl : @a[:]
- ;;
-
- type chunkiter(@a) = struct
- idx : size
- blksz : size
- sl : @a[:]
- ;;
-
- impl iterable zipiter(@a, @b) -> (@a, @b)
- impl iterable enumiter(@a) -> (size, @a)
- impl iterable reverseiter(@a) -> @a
- impl iterable refiter(@a) -> @a#
- impl iterable chunkiter(@a) -> @a[:]
-
- generic byzip : (a : @a[:], b : @b[:] -> zipiter(@a, @b))
- generic byenum : (a : @a[:] -> enumiter(@a))
- generic byreverse : (sl : @a[:] -> reverseiter(@a))
- generic byref : (sl : @a[:] -> refiter(@a))
- generic bychunk : (a : @a[:], chunk : size -> chunkiter(@a))
-;;
-
-generic byzip = {a, b
- -> [.s1 = a, .s2 = b]
-}
-
-impl iterable zipiter(@a, @b) -> (@a, @b) =
- __iternext__ = {itp, valp
- if itp.s1.len > 0 && itp.s2.len > 0
- valp# = (itp.s1[0], itp.s2[0])
- itp.s1 = itp.s1[1:]
- itp.s2 = itp.s2[1:]
- -> true
- else
- -> false
- ;;
- }
-
- __iterfin__ = {itp, valp
- }
-;;
-
-generic byreverse = {sl
- -> [.sl = sl, .idx = sl.len]
-}
-
-impl iterable reverseiter(@a) -> @a =
- __iternext__ = {itp, valp
- if itp.idx > 0
- valp# = itp.sl[itp.idx - 1]
- itp.idx--
- -> true
- else
- -> false
- ;;
- }
-
- __iterfin__ = {itp, valp
- }
-;;
-
-generic byenum = {a
- -> [.sl = a, .idx = 0]
-}
-
-impl iterable enumiter(@a) -> (size, @a) =
- __iternext__ = {itp, valp
- if itp.idx == itp.sl.len
- -> false
- ;;
- valp# = (itp.idx, itp.sl[itp.idx])
- itp.idx++
- -> true
- }
-
- __iterfin__ = {itp, valp
- }
-;;
-
-generic byref = {a
- -> [.sl = a, .idx = 0]
-}
-
-impl iterable refiter(@a) -> @a# =
- __iternext__ = {itp, valp
- if itp.idx == itp.sl.len
- -> false
- ;;
- valp# = &itp.sl[itp.idx]
- itp.idx++
- -> true
- }
-
- __iterfin__ = {itp, valp
- }
-;;
-
-generic bychunk = {a, sz
- -> [.sl = a, .idx = 0, .blksz = sz]
-}
-
-impl iterable chunkiter(@a) -> @a[:] =
- __iternext__ = {itp, valp
- var len
-
- len = min(itp.blksz, itp.sl.len - itp.idx)
- if itp.idx + len == itp.sl.len
- -> false
- ;;
- valp# = itp.sl[itp.idx: itp.idx + len]
- itp.idx += itp.blksz
- -> true
- }
-
- __iterfin__ = {itp, valp
- }
-;;
-
diff --git a/lib/std/listen+posixy.myr b/lib/std/listen+posixy.myr
index 49d1054..3cb0322 100644
--- a/lib/std/listen+posixy.myr
+++ b/lib/std/listen+posixy.myr
@@ -23,7 +23,6 @@ pkg std =
const announce : (ds : byte[:] -> result(announce#, byte[:]))
const aclose : (a : announce# -> void)
-
const accept : (a : announce# -> result(fd, byte[:]))
;;
diff --git a/lib/std/mktemp.myr b/lib/std/mktemp.myr
index bc1bf87..f5e8661 100644
--- a/lib/std/mktemp.myr
+++ b/lib/std/mktemp.myr
@@ -13,10 +13,10 @@ use "syswrap"
use "types"
pkg std =
- const mktemp : (base : byte[:], opt : fdopt, mode : int64 -> std.result((fd, byte[:]), errno))
- const mktempat : (dir : byte[:], base : byte[:], opt : fdopt, mode : int64 -> std.result((fd, byte[:]), errno))
- const mkdtemp : (base : byte[:], mode : int64 -> std.result(byte[:], errno))
- const mkdtempat : (dir : byte[:], base : byte[:], mode : int64 -> std.result(byte[:], errno))
+ const mktemp : (base : byte[:], opt : fdopt, mode : int64 -> std.result((fd, byte[:]), errno))
+ const mktempat : (dir : byte[:], base : byte[:], opt : fdopt, mode : int64 -> std.result((fd, byte[:]), errno))
+ const mkdtemp : (base : byte[:], mode : int64 -> std.result(byte[:], errno))
+ const mkdtempat : (dir : byte[:], base : byte[:], mode : int64 -> std.result(byte[:], errno))
const mktemppath : (base : byte[:] -> byte[:])
;;
diff --git a/lib/std/resolve+posixy.myr b/lib/std/resolve+posixy.myr
index bd053f5..042439f 100644
--- a/lib/std/resolve+posixy.myr
+++ b/lib/std/resolve+posixy.myr
@@ -58,8 +58,8 @@ pkg std =
rtype : rectype
;;
- const resolve : (host : byte[:] -> result(hostinfo[:], resolveerr))
- const resolvemx : (host : byte[:] -> result(hostinfo[:], resolveerr))
+ const resolve : (host : byte[:] -> result(hostinfo[:], resolveerr))
+ const resolvemx : (host : byte[:] -> result(hostinfo[:], resolveerr))
const resolverec : (host : byte[:], t : rectype[:] -> result(hostinfo[:], resolveerr))
;;
diff --git a/lib/std/slpush.myr b/lib/std/slpush.myr
index b09069c..de3585a 100644
--- a/lib/std/slpush.myr
+++ b/lib/std/slpush.myr
@@ -7,12 +7,12 @@ pkg std =
generic slpush = {sl, elt
/*
- slpush relies on implementation details
- of slgrow for efficiency. Because bucket
- sizes come in powers of two for all buckets
- <= 32k, and by powers of 1.5 for larger
- slices, this is effectively growing the
- slice by powers of two.
+ slpush relies on implementation details
+ of slgrow for efficiency. Because bucket
+ sizes come in powers of two for all buckets
+ <= 32k, and by powers of 1.5 for larger
+ slices, this is effectively growing the
+ slice by powers of two.
*/
slgrow(sl, sl#.len + 1)
sl#[sl#.len - 1] = elt
diff --git a/lib/std/slput.myr b/lib/std/slput.myr
index a5322a6..2f54099 100644
--- a/lib/std/slput.myr
+++ b/lib/std/slput.myr
@@ -3,8 +3,8 @@ use "alloc"
use "die"
pkg std =
- generic slput : (sl : @a[:]#, idx : size, elt : @a -> @a[:])
- generic sldel : (sl : @a[:]#, idx : size -> @a[:])
+ generic slput : (sl : @a[:]#, idx : size, elt : @a -> @a[:])
+ generic sldel : (sl : @a[:]#, idx : size -> @a[:])
;;
generic slput = {sl, idx, elt
diff --git a/lib/std/slurp.myr b/lib/std/slurp.myr
index 8e653f9..4df49b9 100644
--- a/lib/std/slurp.myr
+++ b/lib/std/slurp.myr
@@ -7,8 +7,8 @@ use "errno"
use "types"
pkg std =
- const slurp : (path : byte[:] -> result(byte[:], errno))
- const fslurp : (path : fd -> result(byte[:], errno))
+ const slurp : (path : byte[:] -> result(byte[:], errno))
+ const fslurp : (path : fd -> result(byte[:], errno))
;;
const Bufstart = 4096
diff --git a/lib/std/test/iterutil.myr b/lib/std/test/iterutil.myr
deleted file mode 100644
index 1d45a4d..0000000
--- a/lib/std/test/iterutil.myr
+++ /dev/null
@@ -1,26 +0,0 @@
-use std
-
-const main = {
- var n
-
- n = 0
- for (x, i) : std.byenum([1,3,5,7,9][:])
- std.assert(x == n, "invalid enum idx {}", x)
- std.assert(i == n*2 + 1, "invalid enum val {}", i)
- n++
- ;;
-
- n = 0
- for (a, b) : std.byzip([0,2,4,6,8][:], [2,4][:])
- std.assert(a == n*2, "invalid val from a: {}", a)
- std.assert(b == n*2 + 2, "invalid val from b: {}", b)
- n++
- ;;
-
- n = 0
- for x : std.byreverse([3, 2, 1, 0][:])
- std.assert(x == n, "invalid reversed value {}, expected {}", x, n)
- n++
- ;;
-
-}
diff --git a/lib/std/try.myr b/lib/std/try.myr
index c7a1c1f..86c2f74 100644
--- a/lib/std/try.myr
+++ b/lib/std/try.myr
@@ -3,10 +3,10 @@ use "option"
use "fmt"
pkg std =
- generic try : (v : result(@a, @b) -> @a)
- generic tryv : (v : result(@a, @b), d : @a -> @a)
- generic get : (v : option(@a) -> @a)
- generic getv : (v : option(@a), d : @a -> @a)
+ generic try : (v : result(@a, @b) -> @a)
+ generic tryv : (v : result(@a, @b), d : @a -> @a)
+ generic get : (v : option(@a) -> @a)
+ generic getv : (v : option(@a), d : @a -> @a)
generic canget : (o : option(@a) -> bool)
;;
diff --git a/lib/std/varargs.myr b/lib/std/varargs.myr
index 1710444..41ac903 100644
--- a/lib/std/varargs.myr
+++ b/lib/std/varargs.myr
@@ -6,12 +6,12 @@ use "die"
pkg std =
type valist
- const vastart : (args : ...# -> valist)
- const vatype : (ap : valist# -> byte[:])
- const vabytes : (ap : valist# -> byte[:])
- const vaenter : (ap : valist# -> valist)
+ const vastart : (args : ...# -> valist)
+ const vatype : (ap : valist# -> byte[:])
+ const vabytes : (ap : valist# -> byte[:])
+ const vaenter : (ap : valist# -> valist)
const vaenterunion : (ap : valist#, elt : int32 -> valist)
- generic vanext : (ap : valist# -> @a)
+ generic vanext : (ap : valist# -> @a)
;;
type valist = struct
diff --git a/lib/std/writeall.myr b/lib/std/writeall.myr
index 3559c96..6653741 100644
--- a/lib/std/writeall.myr
+++ b/lib/std/writeall.myr
@@ -14,10 +14,8 @@ const writeall = {fd, src
sz = src.len
while src.len != 0
match std.write(fd, src)
- | `Ok n:
- src = src[n:]
- | `Err e:
- -> (sz - src.len, `Some e)
+ | `Ok n: src = src[n:]
+ | `Err e: -> (sz - src.len, `Some e)
;;
;;
-> (sz, `None)