hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 9df4493ae0107fa49d1d646172f328fb93ad8f46
parent e9f718c9c0bc02472489810302ec5b6cc86cc82f
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Tue,  7 Dec 2021 11:12:09 +0000

hare::parse::expr: update match binding syntax

And update the rest of the stdlib for the new syntax

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Mascii/strcmp.ha | 8++++----
Mbufio/buffered.ha | 6+++---
Mbufio/memstream.ha | 2+-
Mbufio/scanner.ha | 12++++++------
Mbytes/contains.ha | 4++--
Mbytes/index.ha | 8++++----
Mbytes/tokenize.ha | 26+++++++++++++-------------
Mcmd/hare/plan.ha | 14+++++++-------
Mcmd/hare/release.ha | 26+++++++++++++-------------
Mcmd/hare/schedule.ha | 10+++++-----
Mcmd/hare/subcmds.ha | 54+++++++++++++++++++++++++++---------------------------
Mcmd/harec/errors.ha | 4++--
Mcmd/harec/gen.ha | 30+++++++++++++++---------------
Mcmd/harec/main.ha | 14+++++++-------
Mcmd/harec/qbe.ha | 32++++++++++++++++----------------
Mcmd/harec/qtype.ha | 6+++---
Mcmd/haredoc/docstr.ha | 22+++++++++++-----------
Mcmd/haredoc/errors.ha | 6+++---
Mcmd/haredoc/hare.ha | 14+++++++-------
Mcmd/haredoc/html.ha | 68++++++++++++++++++++++++++++++++++----------------------------------
Mcmd/haredoc/main.ha | 46+++++++++++++++++++++++-----------------------
Mcmd/haredoc/resolver.ha | 4++--
Mcmd/haredoc/sort.ha | 16++++++++--------
Mcmd/haredoc/tty.ha | 48++++++++++++++++++++++++------------------------
Mcmd/iobus/main.ha | 2+-
Mcompress/flate/inflate.ha | 8++++----
Mcompress/zlib/reader.ha | 12++++++------
Mcrypto/random/+freebsd.ha | 8++++----
Mcrypto/random/+linux.ha | 8++++----
Mcrypto/random/random.ha | 2+-
Mdirs/xdg.ha | 6+++---
Mencoding/base64/base64.ha | 24++++++++++++------------
Mencoding/hex/hex.ha | 2+-
Mencoding/utf8/decode.ha | 8++++----
Merrors/string.ha | 2+-
Mfmt/fmt.ha | 48++++++++++++++++++++++++------------------------
Mfnmatch/fnmatch.ha | 24++++++++++++------------
Mformat/ini/scan.ha | 6+++---
Mformat/ini/types.ha | 4++--
Mformat/xml/+test.ha | 10+++++-----
Mformat/xml/parser.ha | 60++++++++++++++++++++++++++++++------------------------------
Mformat/xml/types.ha | 2+-
Mfs/fs.ha | 42+++++++++++++++++++++---------------------
Mfs/mem/+test.ha | 4++--
Mfs/mem/mem.ha | 12++++++------
Mfs/mem/util.ha | 12++++++------
Mfs/util.ha | 4++--
Mgetopt/getopts.ha | 10+++++-----
Mhare/ast/decl.ha | 8++++----
Mhare/ast/expr.ha | 88++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mhare/ast/import.ha | 6+++---
Mhare/ast/type.ha | 38+++++++++++++++++++-------------------
Mhare/lex/+test.ha | 14+++++++-------
Mhare/lex/lex.ha | 92++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mhare/module/context.ha | 4++--
Mhare/module/manifest.ha | 42+++++++++++++++++++++---------------------
Mhare/module/scan.ha | 22+++++++++++-----------
Mhare/module/types.ha | 8++++----
Mhare/module/walk.ha | 8++++----
Mhare/parse/+test/expr.ha | 6+++---
Mhare/parse/+test/loc.ha | 12++++++------
Mhare/parse/+test/roundtrip.ha | 4++--
Mhare/parse/+test/unit.ha | 4++--
Mhare/parse/decl.ha | 8++++----
Mhare/parse/expr.ha | 54+++++++++++++++++++++++++++++++-----------------------
Mhare/parse/ident.ha | 2+-
Mhare/parse/type.ha | 4++--
Mhare/types/class.ha | 14+++++++-------
Mhare/types/hash.ha | 22+++++++++++-----------
Mhare/types/lookup.ha | 2+-
Mhare/types/store.ha | 56++++++++++++++++++++++++++++----------------------------
Mhare/unit/process.ha | 50+++++++++++++++++++++++++-------------------------
Mhare/unit/scan.ha | 12++++++------
Mhare/unit/scope.ha | 2+-
Mhare/unparse/decl.ha | 12++++++------
Mhare/unparse/expr.ha | 130++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Mhare/unparse/import.ha | 6+++---
Mhare/unparse/type.ha | 32++++++++++++++++----------------
Mio/+freebsd/file.ha | 12++++++------
Mio/+freebsd/mmap.ha | 6+++---
Mio/+linux/file.ha | 16++++++++--------
Mio/+linux/mmap.ha | 6+++---
Mio/+test/copy.ha | 8++++----
Mio/+test/limit.ha | 8++++----
Mio/copy.ha | 12++++++------
Mio/drain.ha | 2+-
Mio/handle.ha | 18++++++++++--------
Mio/stream.ha | 8++++----
Mio/tee.ha | 2+-
Mio/types.ha | 2+-
Mio/util.ha | 2+-
Miobus/io_uring/bus.ha | 12++++++------
Miobus/io_uring/handle.ha | 2+-
Miobus/io_uring/ops.ha | 34+++++++++++++++++-----------------
Miobus/io_uring/types.ha | 6+++---
Mlinux/io_uring/cqe.ha | 8++++----
Mlinux/io_uring/queue.ha | 6+++---
Mlinux/io_uring/register.ha | 24++++++++++++------------
Mlinux/io_uring/setup.ha | 16++++++++--------
Mlinux/io_uring/uring.ha | 2+-
Mlinux/signalfd/signalfd.ha | 8++++----
Mlinux/vdso/vdso.ha | 8++++----
Mmath/floats.ha | 32++++++++++++++++----------------
Mmath/ints.ha | 16++++++++--------
Mmath/math.ha | 8++++----
Mnet/+freebsd.ha | 4++--
Mnet/+linux.ha | 4++--
Mnet/dial/ip.ha | 8++++----
Mnet/dial/registry.ha | 4++--
Mnet/dial/resolve.ha | 14+++++++-------
Mnet/dns/error.ha | 4++--
Mnet/dns/types.ha | 4++--
Mnet/errors.ha | 2+-
Mnet/ip/+freebsd.ha | 4++--
Mnet/ip/+linux.ha | 4++--
Mnet/ip/+test.ha | 2+-
Mnet/ip/ip.ha | 28++++++++++++++--------------
Mnet/listener.ha | 4++--
Mnet/tcp/+freebsd.ha | 24++++++++++++------------
Mnet/tcp/+linux.ha | 24++++++++++++------------
Mnet/udp/+freebsd.ha | 30+++++++++++++++---------------
Mnet/udp/+linux.ha | 30+++++++++++++++---------------
Mnet/unix/+freebsd.ha | 20++++++++++----------
Mnet/unix/+linux.ha | 20++++++++++----------
Mnet/unix/dial.ha | 4++--
Mnet/unix/socketpair.ha | 2+-
Mos/+freebsd/dirfdfs.ha | 36++++++++++++++++++------------------
Mos/+freebsd/environ.ha | 4++--
Mos/+freebsd/fs.ha | 10+++++-----
Mos/+linux/dirfdfs.ha | 36++++++++++++++++++------------------
Mos/+linux/environ.ha | 4++--
Mos/+linux/fs.ha | 16++++++++--------
Mos/exec/cmd.ha | 18+++++++++---------
Mos/exec/exec+freebsd.ha | 32++++++++++++++++----------------
Mos/exec/exec+linux.ha | 32++++++++++++++++----------------
Mos/exec/process+freebsd.ha | 14+++++++-------
Mos/exec/process+linux.ha | 14+++++++-------
Mos/exec/types.ha | 2+-
Mpath/iter.ha | 2+-
Mpath/names.ha | 6+++---
Mrt/+aarch64/backtrace.ha | 2+-
Mrt/+freebsd/segmalloc.ha | 6+++---
Mrt/+freebsd/syscalls.ha | 18+++++++++---------
Mrt/+linux/+aarch64.ha | 4++--
Mrt/+linux/+riscv64.ha | 4++--
Mrt/+linux/+x86_64.ha | 4++--
Mrt/+linux/segmalloc.ha | 6+++---
Mrt/+linux/syscalls.ha | 32++++++++++++++++----------------
Mrt/+riscv64/backtrace.ha | 2+-
Mrt/+x86_64/backtrace.ha | 2+-
Mshlex/split.ha | 10+++++-----
Msort/+test.ha | 2+-
Mstrconv/numeric.ha | 34+++++++++++++++++-----------------
Mstrconv/stou.ha | 12++++++------
Mstrings/contains.ha | 4++--
Mstrings/cstrings.ha | 4++--
Mstrings/dup.ha | 6+++---
Mstrings/index.ha | 6+++---
Mstrings/iter.ha | 14+++++++-------
Mstrings/replace.ha | 2+-
Mstrings/sub.ha | 6+++---
Mstrings/suffix.ha | 8++++----
Mstrings/tokenize.ha | 14+++++++-------
Mstrings/trim.ha | 4++--
Mstrio/dynamic.ha | 2+-
Mstrio/fixed.ha | 2+-
Mtemp/+freebsd.ha | 6+++---
Mtemp/+linux.ha | 10+++++-----
Mtime/+freebsd/functions.ha | 4++--
Mtime/+linux/functions.ha | 8++++----
Munix/+freebsd/nice.ha | 2+-
Munix/+freebsd/pipe.ha | 2+-
Munix/+linux/nice.ha | 2+-
Munix/+linux/pipe.ha | 2+-
Munix/hosts/lookup.ha | 6+++---
Munix/passwd/group.ha | 10+++++-----
Munix/passwd/passwd.ha | 12++++++------
Munix/poll/+freebsd.ha | 4++--
Munix/poll/+linux.ha | 4++--
Munix/resolvconf/load.ha | 6+++---
Munix/tty/+freebsd/isatty.ha | 4++--
Munix/tty/+freebsd/open.ha | 2+-
Munix/tty/+freebsd/termios.ha | 4++--
Munix/tty/+freebsd/winsize.ha | 2+-
Munix/tty/+linux/isatty.ha | 4++--
Munix/tty/+linux/open.ha | 2+-
Munix/tty/+linux/termios.ha | 4++--
Munix/tty/+linux/winsize.ha | 2+-
Muuid/uuid.ha | 12++++++------
189 files changed, 1327 insertions(+), 1309 deletions(-)

diff --git a/ascii/strcmp.ha b/ascii/strcmp.ha @@ -15,13 +15,13 @@ export fn strcmp(a: str, b: str) (int | void) = { case rune => return -1; }; - case r: rune => + case let r: rune => yield r; }; let rb = match (strings::next(&b)) { case void => return 1; - case r: rune => + case let r: rune => yield r; }; if (!isascii(ra) || !isascii(rb)) { @@ -46,13 +46,13 @@ export fn strcasecmp(a: str, b: str) (int | void) = { case rune => return -1; }; - case r: rune => + case let r: rune => yield r; }; let rb = match (strings::next(&b)) { case void => return 1; - case r: rune => + case let r: rune => yield r; }; if (!isascii(ra) || !isascii(rb)) { diff --git a/bufio/buffered.ha b/bufio/buffered.ha @@ -115,7 +115,7 @@ export fn isbuffered(in: io::handle) bool = { match (in) { case io::file => return false; - case st: *io::stream => + case let st: *io::stream => return st.reader == &buffered_read || st.writer == &buffered_write; }; }; @@ -148,14 +148,14 @@ fn buffered_read(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { let n = if (len(buf) < len(s.rbuffer)) len(buf) else len(s.rbuffer); if (n > s.ravail) { let z = match (io::read(s.source, s.rbuffer[s.ravail..])) { - case err: io::error => + case let err: io::error => return err; case io::EOF => if (s.ravail == 0) { return io::EOF; }; yield 0z; - case z: size => + case let z: size => yield z; }; s.ravail += z; diff --git a/bufio/memstream.ha b/bufio/memstream.ha @@ -84,7 +84,7 @@ fn getmemstream(in: io::handle) *memstream = { match (in) { case io::file => abort("Invalid use of bufio with unbuffered file"); - case st: *io::stream => + case let st: *io::stream => assert(st.closer == &dynamic_close); return st: *memstream; }; diff --git a/bufio/scanner.ha b/bufio/scanner.ha @@ -9,7 +9,7 @@ export fn scanbyte(file: io::handle) (u8 | io::EOF | io::error) = { let buf: [1]u8 = [0...]; match (io::read(file, buf)?) { - case read: size => + case let read: size => if (read > 0) { return buf[0]; } else { @@ -27,7 +27,7 @@ export fn scantok(file: io::handle, delim: u8...) ([]u8 | io::EOF | io::error) = for (true) { match (scanbyte(file)?) { - case res: u8 => + case let res: u8 => if (bytes::contains(delim, res)) { break; }; @@ -54,7 +54,7 @@ export fn scanrune( ) (rune | utf8::invalid | io::EOF | io::error) = { let b: [4]u8 = [0...]; match (io::read(file, b[..1])?) { - case n: size => + case let n: size => assert(n == 1); case io::EOF => return io::EOF; @@ -70,7 +70,7 @@ export fn scanrune( }; match (io::read(file, b[1..sz])?) { - case n: size => + case let n: size => assert(n == sz - 1); case io::EOF => return io::EOF; @@ -78,7 +78,7 @@ export fn scanrune( let dec = utf8::decode(b[..sz]); match (utf8::next(&dec)?) { - case r: rune => + case let r: rune => return r; case (void | utf8::more) => return io::EOF; @@ -141,7 +141,7 @@ export fn scanrune( let want = expected[i]; match (scanrune(in)) { - case r: rune => + case let r: rune => assert(want is rune && want as rune == r); case io::EOF => assert(want is io::EOF); diff --git a/bytes/contains.ha b/bytes/contains.ha @@ -1,8 +1,8 @@ // Returns true if a byte slice contains a byte or a sequence of bytes. export fn contains(haystack: []u8, needle: (u8 | []u8)) bool = match (needle) { -case b: u8 => +case let b: u8 => yield !(index_byte(haystack, b) is void); -case b: []u8 => +case let b: []u8 => yield !(index_slice(haystack, b) is void); }; diff --git a/bytes/index.ha b/bytes/index.ha @@ -2,9 +2,9 @@ // bytes, or void if it is not found. export fn index(haystack: []u8, needle: (u8 | []u8)) (size | void) = { return match (needle) { - case b: u8 => + case let b: u8 => yield index_byte(haystack, b); - case b: []u8 => + case let b: []u8 => yield index_slice(haystack, b); }; }; @@ -31,9 +31,9 @@ case => // bytes, or void if it is not found. export fn rindex(haystack: []u8, needle: (u8 | []u8)) (size | void) = { match (needle) { - case b: u8 => + case let b: u8 => return rindex_byte(haystack, b); - case b: []u8 => + case let b: []u8 => return rindex_slice(haystack, b); }; }; diff --git a/bytes/tokenize.ha b/bytes/tokenize.ha @@ -21,7 +21,7 @@ export fn tokenize(s: []u8, delim: []u8) tokenizer = { // string starts with, or ends with, a token, an empty slice is returned at the // beginning or end of the sequence, respectively. export fn next_token(s: *tokenizer) ([]u8 | void) = match (peek_token(s)) { -case b: []u8 => +case let b: []u8 => if (s.p == len(s.s)) { s.d = s.d[..0]; s.s = s.s[..0]; @@ -40,7 +40,7 @@ export fn peek_token(s: *tokenizer) ([]u8 | void) = { }; if (s.p > len(s.s)) { s.p = match (index(s.s, s.d)) { - case i: size => + case let i: size => yield i; case void => yield len(s.s); @@ -72,7 +72,7 @@ export fn remaining_tokens(s: *tokenizer) []u8 = { assert(equal(peek_token(&t) as []u8, peek_token(&t) as []u8)); match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([4, 5], b)); case void => abort(); @@ -86,7 +86,7 @@ export fn remaining_tokens(s: *tokenizer) []u8 = { assert(equal(peek_token(&t) as []u8, peek_token(&t) as []u8)); match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([], b)); case void => abort(); @@ -94,7 +94,7 @@ export fn remaining_tokens(s: *tokenizer) []u8 = { assert(equal(peek_token(&t) as []u8, peek_token(&t) as []u8)); match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([1], b)); case void => abort(); @@ -102,7 +102,7 @@ export fn remaining_tokens(s: *tokenizer) []u8 = { assert(equal(peek_token(&t) as []u8, peek_token(&t) as []u8)); match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([], b)); case void => abort(); @@ -115,21 +115,21 @@ export fn remaining_tokens(s: *tokenizer) []u8 = { t = tokenize(input3, [1, 2]); match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([1, 1], b)); case void => abort(); }; match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([1], b)); case void => abort(); }; match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([2], b)); case void => abort(); @@ -141,14 +141,14 @@ export fn remaining_tokens(s: *tokenizer) []u8 = { t = tokenize(input4, [1, 2]); match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([], b)); case void => abort(); }; match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([], b)); case void => abort(); @@ -161,14 +161,14 @@ export fn remaining_tokens(s: *tokenizer) []u8 = { t = tokenize(input5, [24, 42]); match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([], b)); case void => abort(); }; match (next_token(&t)) { - case b: []u8 => + case let b: []u8 => assert(equal([1], b)); case void => abort(); diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha @@ -49,9 +49,9 @@ type plan = struct { fn mkplan(ctx: *module::context, libs: []str) plan = { const rtdir = match (module::lookup(ctx, ["rt"])) { - case err: module::error => + case let err: module::error => fmt::fatal("Error resolving rt: {}", module::strerror(err)); - case ver: module::version => + case let ver: module::version => yield ver.basedir; }; @@ -59,7 +59,7 @@ fn mkplan(ctx: *module::context, libs: []str) plan = { const iter = os::iter(rtdir)!; for (true) match (fs::next(iter)) { - case d: fs::dirent => + case let d: fs::dirent => const p = module::parse_name(d.name); defer module::tags_free(p.2); @@ -148,15 +148,15 @@ fn plan_execute(plan: *plan, verbose: bool) (void | !exec::exit_status) = { let task = match (next) { case null => abort(); - case t: *task => + case let t: *task => yield t; }; match (execute(plan, task, verbose)) { - case err: exec::error => + case let err: exec::error => fmt::fatal("Error: {}: {}", task.cmd[0], exec::strerror(err)); - case err: !exec::exit_status => + case let err: !exec::exit_status => fmt::errorfln("Error: {}: {}", task.cmd[0], exec::exitstr(err))!; return err; @@ -179,7 +179,7 @@ fn update_cache(plan: *plan, mod: modcache) void = { versions = [mod.version], }; match (module::manifest_write(plan.context, &manifest)) { - case err: module::error => + case let err: module::error => fmt::fatal("Error updating module cache: {}", module::strerror(err)); case void => void; diff --git a/cmd/hare/release.ha b/cmd/hare/release.ha @@ -55,7 +55,7 @@ fn parseversion(in: str) (modversion | badversion) = { const ptrs = [&major, &minor, &patch]; for (let i = 0z; i < len(items); i += 1) { *ptrs[i] = match (strconv::stou(items[i])) { - case u: uint => + case let u: uint => yield u; case => return badversion; @@ -83,9 +83,9 @@ fn do_release( const lasttag = match (git_readcmd("describe", "--abbrev=0")) { case git_error => return do_initial_release(next); - case err: release_error => + case let err: release_error => return err; - case s: str => + case let s: str => yield strings::rtrim(s); }; defer free(lasttag); @@ -118,7 +118,7 @@ fn do_release( fn do_initial_release(ver: (modversion | increment)) (void | release_error) = { const ver = match (ver) { - case ver: modversion => + case let ver: modversion => yield ver; case increment => fmt::errorln("Error: cannot increment version number without a previous version to reference.")!; @@ -151,9 +151,9 @@ fn nextversion( next: (increment | modversion), ) modversion = { const next = match (next) { - case incr: increment => + case let incr: increment => yield incr; - case ver: modversion => + case let ver: modversion => return ver; }; switch (next) { @@ -192,9 +192,9 @@ fn checkbehind() (void | release_error) = { // Fails if there is no upstream, in which case we don't need to // bother checking. return; - case err: release_error => + case let err: release_error => return err; - case s: str => + case let s: str => yield s; }; defer free(upstream); @@ -206,7 +206,7 @@ fn checkbehind() (void | release_error) = { match (git_runcmd("merge-base", "--is-ancestor", "HEAD@{upstream}", "HEAD")) { case git_error => fmt::errorln("Warning! Your local branch is behind the upstream branch.")!; - case err: release_error => + case let err: release_error => return err; case => void; }; @@ -223,7 +223,7 @@ fn shortlog(out: io::file, what: str) (void | release_error) = { fn choosekey() (str | release_error) = { match (os::getenv("HAREKEY")) { case void => void; - case name: str => + case let name: str => return name; }; const paths = [ @@ -247,7 +247,7 @@ fn choosekey() (str | release_error) = { const line = match (bufio::scanline(os::stdin)?) { case io::EOF => fmt::fatal("No suitable key available. Terminating."); - case line: []u8 => + case let line: []u8 => yield strings::fromutf8(line); }; defer free(line); @@ -261,9 +261,9 @@ fn choosekey() (str | release_error) = { const path = path::join(home, ".ssh", "id_ed25519"); const cmd = match (exec::cmd("ssh-keygen", "-t", "ed25519", "-f", path)) { - case cmd: exec::command => + case let cmd: exec::command => yield cmd; - case err: exec::error => + case let err: exec::error => fmt::fatal("ssh-keygen: command not found. Is openssh installed?"); }; const proc = exec::start(&cmd)?; diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha @@ -30,11 +30,11 @@ fn sched_module(plan: *plan, ident: ast::ident, link: *[]*task) *task = { }; let ver = match (module::lookup(plan.context, ident)) { - case err: module::error => + case let err: module::error => let ident = unparse::identstr(ident); fmt::fatal("Error resolving {}: {}", ident, module::strerror(err)); - case ver: module::version => + case let ver: module::version => yield ver; }; @@ -197,10 +197,10 @@ fn sched_hare_object( // overwriting with just the latest let manifest = match (module::manifest_load( plan.context, namespace)) { - case err: module::error => + case let err: module::error => fmt::fatal("Error reading cache entry for {}: {}", ns, module::strerror(err)); - case m: module::manifest => + case let m: module::manifest => yield m; }; defer module::manifest_finish(&manifest); @@ -219,7 +219,7 @@ fn sched_hare_object( }; match (os::mkdirs(path)) { case void => void; - case err: fs::error => + case let err: fs::error => fmt::fatal("Error: mkdirs {}: {}", path, fs::strerror(err)); }; diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -28,7 +28,7 @@ fn addtags(tags: []module::tag, in: str) ([]module::tag | void) = { let in = match (module::parsetags(in)) { case void => return void; - case t: []module::tag => + case let t: []module::tag => yield t; }; defer free(in); @@ -44,7 +44,7 @@ fn deltags(tags: []module::tag, in: str) ([]module::tag | void) = { let in = match (module::parsetags(in)) { case void => return void; - case t: []module::tag => + case let t: []module::tag => yield t; }; defer free(in); @@ -111,14 +111,14 @@ fn build(args: []str) void = { tags = match (addtags(tags, opt.1)) { case void => fmt::fatal("Error parsing tags"); - case t: []module::tag => + case let t: []module::tag => yield t; }; case 'X' => tags = match (deltags(tags, opt.1)) { case void => fmt::fatal("Error parsing tags"); - case t: []module::tag => + case let t: []module::tag => yield t; }; case => @@ -150,9 +150,9 @@ fn build(args: []str) void = { defer plan_finish(&plan); const ver = match (module::scan(&ctx, input)) { - case ver: module::version => + case let ver: module::version => yield ver; - case err: module::error => + case let err: module::error => fmt::fatal("Error scanning input module: {}", module::strerror(err)); }; @@ -240,22 +240,22 @@ fn release(args: []str) void = { case badversion => getopt::printusage(os::stderr, "release", help); os::exit(1); - case ver: modversion => + case let ver: modversion => yield ver; }; }; match (do_release(next, dryrun)) { case void => void; - case err: exec::error => + case let err: exec::error => fmt::fatal(exec::strerror(err)); - case err: errors::error => + case let err: errors::error => fmt::fatal(errors::strerror(err)); - case err: io::error => + case let err: io::error => fmt::fatal(io::strerror(err)); - case err: fs::error => + case let err: fs::error => fmt::fatal(fs::strerror(err)); - case err: git_error => + case let err: git_error => fmt::fatal("git: {}", exec::exitstr(err)); case badversion => fmt::fatal("Error: invalid format string. Hare uses semantic versioning, in the form major.minor.patch."); @@ -299,14 +299,14 @@ fn run(args: []str) void = { tags = match (addtags(tags, opt.1)) { case void => fmt::fatal("Error parsing tags"); - case t: []module::tag => + case let t: []module::tag => yield t; }; case 'X' => tags = match (deltags(tags, opt.1)) { case void => fmt::fatal("Error parsing tags"); - case t: []module::tag => + case let t: []module::tag => yield t; }; case => @@ -337,9 +337,9 @@ fn run(args: []str) void = { defer plan_finish(&plan); const ver = match (module::scan(&ctx, input)) { - case ver: module::version => + case let ver: module::version => yield ver; - case err: module::error => + case let err: module::error => fmt::fatal("Error scanning input module: {}", module::strerror(err)); }; @@ -360,9 +360,9 @@ fn run(args: []str) void = { fmt::fatal("{} {}: build failed", os::args[0], os::args[1]); }; const cmd = match (exec::cmd(output, runargs...)) { - case err: exec::error => + case let err: exec::error => fmt::fatal("exec: {}", exec::strerror(err)); - case cmd: exec::command => + case let cmd: exec::command => yield cmd; }; exec::setname(&cmd, input); @@ -414,14 +414,14 @@ fn test(args: []str) void = { tags = match (addtags(tags, opt.1)) { case void => fmt::fatal("Error parsing tags"); - case t: []module::tag => + case let t: []module::tag => yield t; }; case 'X' => tags = match (deltags(tags, opt.1)) { case void => fmt::fatal("Error parsing tags"); - case t: []module::tag => + case let t: []module::tag => yield t; }; case => @@ -455,9 +455,9 @@ fn test(args: []str) void = { sched_module(&plan, ["rt"], &depends); let items = match (module::walk(&ctx, input)) { - case items: []ast::ident => + case let items: []ast::ident => yield items; - case err: module::error => + case let err: module::error => fmt::fatal("Error scanning source root: {}", module::strerror(err)); }; @@ -468,7 +468,7 @@ fn test(args: []str) void = { continue; }; match (module::lookup(plan.context, items[i])) { - case ver: module::version => + case let ver: module::version => if (len(ver.inputs) == 0) continue; case module::error => continue; @@ -492,9 +492,9 @@ fn test(args: []str) void = { }; const cmd = match (exec::cmd(output, runargs...)) { - case err: exec::error => + case let err: exec::error => fmt::fatal("exec: {}", exec::strerror(err)); - case cmd: exec::command => + case let cmd: exec::command => yield cmd; }; exec::setname(&cmd, input); @@ -537,7 +537,7 @@ fn version(args: []str) void = { const items = strings::join("\n\t\t", items...); defer free(items); fmt::printfln("HAREPATH\t{}", items)!; - case env: str => + case let env: str => fmt::printf("HAREPATH\t")!; bufio::flush(os::stdout)!; fmt::errorf("(from environment)")!; @@ -552,7 +552,7 @@ fn version(args: []str) void = { const val = match (os::getenv("HAREPATH")) { case void => yield HAREPATH; - case env: str => + case let env: str => yield env; }; fmt::printfln("HAREPATH\t{}", val)!; diff --git a/cmd/harec/errors.ha b/cmd/harec/errors.ha @@ -9,9 +9,9 @@ use strings; // TODO: Expand to more kinds of errors fn printerr(err: parse::error) void = { match (err) { - case err: lex::syntax => + case let err: lex::syntax => printerr_syntax(err); - case err: io::error => + case let err: io::error => fmt::errorln(io::strerror(err))!; }; }; diff --git a/cmd/harec/gen.ha b/cmd/harec/gen.ha @@ -28,7 +28,7 @@ fn gen(out: io::handle, store: *types::typestore, unit: *unit::unit) void = { defer io::close(ctx.buf); for (let i = 0z; i < len(unit.decls); i += 1) { match (unit.decls[i].decl) { - case func: unit::decl_func => + case let func: unit::decl_func => gen_func(&ctx, &unit.decls[i]); case => abort(); // TODO }; @@ -39,7 +39,7 @@ fn gen_func(ctx: *context, decl: *unit::decl) void = { // TODO: const fndecl = &decl.decl as *unit::decl_func; const fndecl = decl.decl as unit::decl_func; const body = match (fndecl.body) { - case expr: *unit::expr => + case let expr: *unit::expr => yield expr; case null => return; // Prototype @@ -55,7 +55,7 @@ fn gen_func(ctx: *context, decl: *unit::decl) void = { const rtype = fntype.result; const has_rval = match (types::dealias(rtype).repr) { - case bi: types::builtin => + case let bi: types::builtin => yield bi != types::builtin::VOID; case => yield true; @@ -92,7 +92,7 @@ fn gen_func(ctx: *context, decl: *unit::decl) void = { fn gen_store(ctx: *context, object: value, value: value) void = { match (types::dealias(object._type).repr) { - case bi: types::builtin => + case let bi: types::builtin => switch (bi) { case builtin::STR => abort(); // TODO case => void; @@ -108,7 +108,7 @@ fn gen_store(ctx: *context, object: value, value: value) void = { fn gen_load(ctx: *context, object: value) value = { match (types::dealias(object._type).repr) { - case bi: types::builtin => + case let bi: types::builtin => switch (bi) { case builtin::STR => abort(); // TODO case => void; @@ -166,11 +166,11 @@ fn gen_access_object(ctx: *context, object: *unit::object) value = { fn gen_access_addr(ctx: *context, expr: *unit::expr) value = { match (expr.expr as unit::access) { - case ao: unit::access_object => + case let ao: unit::access_object => return gen_access_object(ctx, ao); - case ai: unit::access_index => abort(); // TODO - case af: unit::access_field => abort(); // TODO - case at: unit::access_tuple => abort(); // TODO + case let ai: unit::access_index => abort(); // TODO + case let af: unit::access_field => abort(); // TODO + case let at: unit::access_tuple => abort(); // TODO }; }; @@ -215,17 +215,17 @@ fn gen_const(ctx: *context, expr: *unit::expr) value = { const val: qval = match (constexpr) { case void => return vvoid; - case b: bool => + case let b: bool => yield (if (b) 1u32 else 0u32): constant; case ast::_null => yield 0u64; // XXX: Arch - case r: rune => + case let r: rune => yield r: u32; - case v: (u64 | f64) => + case let v: (u64 | f64) => yield v; - case i: i64 => + case let i: i64 => yield i: u64; - case s: str => abort(); // TODO + case let s: str => abort(); // TODO // TODO: Aggregate types }; return value { @@ -239,7 +239,7 @@ fn gen_return(ctx: *context, expr: *unit::expr) value = { match (rexpr) { case null => emit(ctx.buf, void, qinstr::RET); - case expr: *unit::expr => + case let expr: *unit::expr => emit(ctx.buf, void, qinstr::RET, gen_expr(ctx, expr)); }; return vvoid; diff --git a/cmd/harec/main.ha b/cmd/harec/main.ha @@ -34,9 +34,9 @@ export fn main() void = { case 'T' => abort(); // TODO case 'o' => out = match (os::create(opt.1, 0o644)) { - case f: io::file => + case let f: io::file => yield f; - case e: fs::error => + case let e: fs::error => fmt::fatal(fs::strerror(e)); }; case 't' => abort(); // TODO @@ -60,9 +60,9 @@ export fn main() void = { for (let i = 0z; i < len(cmd.args); i += 1) { let input = match (os::open(cmd.args[i])) { - case f: io::file => + case let f: io::file => yield f; - case err: fs::error => + case let err: fs::error => fmt::fatal("Error opening {}: {}", cmd.args[i], fs::strerror(err)); }; @@ -73,10 +73,10 @@ export fn main() void = { let lexer = lex::init(bufin, cmd.args[i]); let su = match (parse::subunit(&lexer)) { - case err: parse::error => + case let err: parse::error => printerr(err); os::exit(1); - case u: ast::subunit => + case let u: ast::subunit => yield u; }; append(subunits, su); @@ -84,7 +84,7 @@ export fn main() void = { let unit = match (unit::check(store, [], subunits)) { case unit::error => abort(); // TODO - case u: unit::unit => + case let u: unit::unit => yield u; }; defer unit::unit_free(unit); diff --git a/cmd/harec/qbe.ha b/cmd/harec/qbe.ha @@ -29,7 +29,7 @@ fn emit( ) void = { fmt::fprintf(to, "\t")!; match (out) { - case val: qtypeval => + case let val: qtypeval => const ty = val.0, val = val.1; qval_emit(to, val); fmt::fprintf(to, " ={} ", qtype_repr(ty))!; @@ -211,16 +211,16 @@ fn emit( })!; for (let i = 0z; i < len(args); i += 1) { const arg = match (args[i]) { - case v: value => + case let v: value => yield v.value; case => yield args[i]; }; match (arg) { - case v: value => abort(); // Invariant - case qv: qval => + case let v: value => abort(); // Invariant + case let qv: qval => yield qval_emit(to, qv); - case qt: qtype => + case let qt: qtype => abort(); // TODO }; if (i + 1 < len(args)) { @@ -232,16 +232,16 @@ fn emit( fn qval_emit(to: io::handle, qv: qval) void = { match (qv) { - case g: global => + case let g: global => fmt::fprintf(to, " ${}", g)!; - case t: temporary => + case let t: temporary => fmt::fprintf(to, " %{}", t)!; - case l: label => + case let l: label => fmt::fprintf(to, " @{}", l)!; - case c: constant => + case let c: constant => match (c) { case qvoid => abort(); - case v: (u32 | u64 | f32 | f64 | str) => + case let v: (u32 | u64 | f32 | f64 | str) => fmt::fprintf(to, " {}", v)!; }; }; @@ -264,9 +264,9 @@ fn qinstr_store( ty: *types::_type, ) qinstr = { match (ty.repr) { - case al: types::alias => + case let al: types::alias => return qinstr_store(ctx, al.secondary: *types::_type); - case bi: types::builtin => + case let bi: types::builtin => switch (bi) { case builtin::STR, builtin::VOID => abort(); case builtin::F32 => @@ -292,7 +292,7 @@ fn qinstr_store( } else if (ctx.arch.ptr == &qword) { return qinstr::STOREW; } else abort(); - case en: types::_enum => abort(); // TODO + case let en: types::_enum => abort(); // TODO case => abort(); }; }; @@ -302,9 +302,9 @@ fn qinstr_load( ty: *types::_type, ) qinstr = { match (ty.repr) { - case al: types::alias => + case let al: types::alias => return qinstr_load(ctx, al.secondary: *types::_type); - case bi: types::builtin => + case let bi: types::builtin => switch (bi) { case builtin::STR, builtin::VOID => abort(); case builtin::F32 => @@ -342,7 +342,7 @@ fn qinstr_load( } else if (ctx.arch.ptr == &qword) { return qinstr::LOADUW; } else abort(); - case en: types::_enum => abort(); // TODO + case let en: types::_enum => abort(); // TODO case => abort(); }; }; diff --git a/cmd/harec/qtype.ha b/cmd/harec/qtype.ha @@ -38,7 +38,7 @@ fn qtype_lookup( extype: bool, ) const *qtype = { match (_type.repr) { - case bi: builtin => + case let bi: builtin => switch (bi) { case builtin::CHAR => return if (extype) &qbyte else &qword; @@ -81,10 +81,10 @@ fn qtype_repr(qtype: const *qtype) const str = { // XXX: This dereference should not be necessary after the match // overhaul match (*qtype) { - case st: stype => + case let st: stype => static let buf: [1]u8 = [0...]; return fmt::bsprintf(buf, "{}", st: rune); - case qc: qcompound => abort(); // TODO + case let qc: qcompound => abort(); // TODO case void => return ""; }; diff --git a/cmd/haredoc/docstr.ha b/cmd/haredoc/docstr.ha @@ -35,7 +35,7 @@ fn parsedoc(in: io::handle) parser = { fn scandoc(par: *parser) (token | void) = { const rn = match (bufio::scanrune(par.src)!) { - case rn: rune => + case let rn: rune => yield rn; case io::EOF => return; @@ -74,7 +74,7 @@ fn scantext(par: *parser) (token | void) = { for (true) { const rn = match (bufio::scanrune(par.src)!) { case io::EOF => break; - case rn: rune => + case let rn: rune => yield rn; }; switch (rn) { @@ -85,7 +85,7 @@ fn scantext(par: *parser) (token | void) = { strio::appendrune(buf, rn)!; const rn = match (bufio::scanrune(par.src)!) { case io::EOF => break; - case rn: rune => + case let rn: rune => yield rn; }; if (rn == '\n') { @@ -108,7 +108,7 @@ fn scanref(par: *parser) (token | void) = { match (bufio::scanrune(par.src)!) { case io::EOF => return; - case rn: rune => + case let rn: rune => if (rn != '[') { abort(); }; @@ -116,7 +116,7 @@ fn scanref(par: *parser) (token | void) = { match (bufio::scanrune(par.src)!) { case io::EOF => return; - case rn: rune => + case let rn: rune => if (rn != '[') { bufio::unreadrune(par.src, rn); return strings::dup("["): text; @@ -128,7 +128,7 @@ fn scanref(par: *parser) (token | void) = { // TODO: Handle invalid syntax here for (true) { match (bufio::scanrune(par.src)!) { - case rn: rune => + case let rn: rune => switch (rn) { case ']' => bufio::scanrune(par.src) as rune; // ] @@ -149,7 +149,7 @@ fn scansample(par: *parser) (token | void) = { match (bufio::scanrune(par.src)!) { case io::EOF => return; - case rn: rune => + case let rn: rune => switch (rn) { case ' ' => nws += 1; @@ -170,7 +170,7 @@ fn scansample(par: *parser) (token | void) = { for (cont) { const rn = match (bufio::scanrune(par.src)!) { case io::EOF => break; - case rn: rune => + case let rn: rune => yield rn; }; switch (rn) { @@ -185,7 +185,7 @@ fn scansample(par: *parser) (token | void) = { for (let i = 0z; i < nws) { match (bufio::scanrune(par.src)!) { case io::EOF => break; - case rn: rune => + case let rn: rune => switch (rn) { case ' ' => i += 1; @@ -218,7 +218,7 @@ fn scanlist(par: *parser) (token | void) = { for (true) { match (bufio::scanrune(par.src)!) { case io::EOF => break; - case rn: rune => + case let rn: rune => if (rn != '-') { break; }; @@ -226,7 +226,7 @@ fn scanlist(par: *parser) (token | void) = { // XXX: multi-line list items append(items, match (bufio::scanline(par.src)!) { case io::EOF => break; - case u: []u8 => + case let u: []u8 => yield strings::fromutf8(u); }); }; diff --git a/cmd/haredoc/errors.ha b/cmd/haredoc/errors.ha @@ -8,11 +8,11 @@ type error = !(lex::error | parse::error | io::error | syntaxerr | eof); fn strerror(err: error) str = { match (err) { - case err: lex::error => + case let err: lex::error => return lex::strerror(err); - case err: parse::error => + case let err: parse::error => return parse::strerror(err); - case err: io::error => + case let err: io::error => return io::strerror(err); case eof => return "Unexpected EOF"; diff --git a/cmd/haredoc/hare.ha b/cmd/haredoc/hare.ha @@ -14,12 +14,12 @@ fn emit_hare(ctx: *context) (void | error) = { let first = true; match (ctx.readme) { - case readme: io::file => + case let readme: io::file => first = false; for (true) { match (bufio::scanline(readme)?) { case io::EOF => break; - case b: []u8 => + case let b: []u8 => fmt::fprintfln(ctx.out, "// {}", strings::fromutf8(b))?; free(b); @@ -75,7 +75,7 @@ fn details_hare(ctx: *context, decl: ast::decl) (void | error) = { for (true) { match (strings::next_token(&iter)) { case void => break; - case s: str => + case let s: str => if (len(s) != 0) { fmt::fprintfln(ctx.out, "//{}", s)?; }; @@ -91,7 +91,7 @@ fn details_hare(ctx: *context, decl: ast::decl) (void | error) = { fn unparse_hare(out: io::handle, d: ast::decl) (size | io::error) = { let n = 0z; match (d.decl) { - case g: []ast::decl_global => + case let g: []ast::decl_global => n += fmt::fprint(out, if (g[0].is_const) "const " else "let ")?; for (let i = 0z; i < len(g); i += 1) { @@ -106,7 +106,7 @@ fn unparse_hare(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case t: []ast::decl_type => + case let t: []ast::decl_type => n += fmt::fprint(out, "type ")?; for (let i = 0z; i < len(t); i += 1) { n += unparse::ident(out, t[i].ident)?; @@ -116,7 +116,7 @@ fn unparse_hare(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case c: []ast::decl_const => + case let c: []ast::decl_const => n += fmt::fprint(out, "def ")?; for (let i = 0z; i < len(c); i += 1) { n += unparse::ident(out, c[i].ident)?; @@ -126,7 +126,7 @@ fn unparse_hare(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case f: ast::decl_func => + case let f: ast::decl_func => n += fmt::fprint(out, switch (f.attrs) { case ast::fndecl_attrs::NONE => yield ""; diff --git a/cmd/haredoc/html.ha b/cmd/haredoc/html.ha @@ -20,7 +20,7 @@ fn html_escape(out: io::handle, in: str) (size | io::error) = { for (true) { match (strings::next(&iter)) { case void => break; - case rn: rune => + case let rn: rune => z += io::write(out, switch (rn) { case '&' => yield strings::toutf8("&amp;"); @@ -87,7 +87,7 @@ fn emit_html(ctx: *context) (void | error) = { match (ctx.readme) { case void => void; - case f: io::file => + case let f: io::file => fmt::fprintln(ctx.out, "<div class='readme'>")?; markup_html(ctx, f)?; fmt::fprintln(ctx.out, "</div>")?; @@ -218,16 +218,16 @@ fn tocentry(out: io::handle, decl: ast::decl) (void | error) = { fmt::fprint(out, "</a>")?; match (decl.decl) { - case t: []ast::decl_type => void; - case g: []ast::decl_global => + case let t: []ast::decl_type => void; + case let g: []ast::decl_global => let g = g[0]; fmt::fprint(out, ": ")?; type_html(out, 0, g._type, true)?; - case c: []ast::decl_const => + case let c: []ast::decl_const => let c = c[0]; fmt::fprint(out, ": ")?; type_html(out, 0, c._type, true)?; - case f: ast::decl_func => + case let f: ast::decl_func => prototype_html(out, 0, f.prototype.repr as ast::func_type, true)?; @@ -282,7 +282,7 @@ fn details(ctx: *context, decl: ast::decl) (void | error) = { fn htmlref(ctx: *context, ref: ast::ident) (void | io::error) = { const ik = match (resolve(ctx, ref)) { - case ik: (ast::ident, symkind) => + case let ik: (ast::ident, symkind) => yield ik; case void => const ident = unparse::identstr(ref); @@ -320,14 +320,14 @@ fn markup_html(ctx: *context, in: io::handle) (void | io::error) = { for (true) { const tok = match (scandoc(&parser)) { case void => break; - case tok: token => + case let tok: token => yield tok; }; match (tok) { case paragraph => fmt::fprintln(ctx.out)?; fmt::fprint(ctx.out, "<p>")?; - case tx: text => + case let tx: text => if (strings::hasprefix(tx, "https://")) { // Temporary hack fmt::fprint(ctx.out, "<a rel='nofollow noopener' href='")?; @@ -340,14 +340,14 @@ fn markup_html(ctx: *context, in: io::handle) (void | io::error) = { html_escape(ctx.out, tx)?; free(tx); }; - case re: reference => + case let re: reference => htmlref(ctx, re)?; - case sa: sample => + case let sa: sample => fmt::fprint(ctx.out, "<pre class='sample'>")?; html_escape(ctx.out, sa)?; fmt::fprint(ctx.out, "</pre>")?; free(sa); - case li: list => + case let li: list => fmt::fprintln(ctx.out, "<ul>")?; for (let i = 0z; i < len(li); i += 1) { fmt::fprintln(ctx.out, "<li>")?; @@ -365,7 +365,7 @@ fn markup_html(ctx: *context, in: io::handle) (void | io::error) = { fn unparse_html(out: io::handle, d: ast::decl) (size | io::error) = { let n = 0z; match (d.decl) { - case c: []ast::decl_const => + case let c: []ast::decl_const => n += fmt::fprintf(out, "<span class='keyword'>def</span> ")?; for (let i = 0z; i < len(c); i += 1) { n += unparse::ident(out, c[i].ident)?; @@ -375,7 +375,7 @@ fn unparse_html(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case g: []ast::decl_global => + case let g: []ast::decl_global => n += fmt::fprintf(out, "<span class='keyword'>{}</span>", if (g[0].is_const) "const " else "let ")?; for (let i = 0z; i < len(g); i += 1) { @@ -386,7 +386,7 @@ fn unparse_html(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case t: []ast::decl_type => + case let t: []ast::decl_type => n += fmt::fprint(out, "<span class='keyword'>type</span> ")?; for (let i = 0z; i < len(t); i += 1) { n += unparse::ident(out, t[i].ident)?; @@ -396,7 +396,7 @@ fn unparse_html(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case f: ast::decl_func => + case let f: ast::decl_func => n += fmt::fprint(out, switch (f.attrs) { case ast::fndecl_attrs::NONE => yield ""; @@ -500,7 +500,7 @@ fn enum_html( match (val.value) { case null => void; - case expr: *ast::expr => + case let expr: *ast::expr => z += fmt::fprint(out, " = ")?; z += unparse::expr(out, indent, *expr)?; }; @@ -520,10 +520,10 @@ fn struct_union_html( ) (size | io::error) = { let z = 0z; let members = match (t.repr) { - case t: ast::struct_type => + case let t: ast::struct_type => z += fmt::fprint(out, "<span class='keyword'>struct</span> {")?; yield t: []ast::struct_member; - case t: ast::union_type => + case let t: ast::union_type => z += fmt::fprint(out, "<span class='keyword'>union</span> {")?; yield t: []ast::struct_member; }; @@ -535,19 +535,19 @@ fn struct_union_html( z += newline(out, indent)?; match (member._offset) { case null => void; - case expr: *ast::expr => + case let expr: *ast::expr => z += fmt::fprint(out, "@offset(")?; z += unparse::expr(out, indent, *expr)?; z += fmt::fprint(out, ") ")?; }; match (member.member) { - case f: ast::struct_field => + case let f: ast::struct_field => z += fmt::fprintf(out, "{}: ", f.name)?; z += type_html(out, indent, *f._type, brief)?; - case embed: ast::struct_embedded => + case let embed: ast::struct_embedded => z += type_html(out, indent, *embed, brief)?; - case indent: ast::struct_alias => + case let indent: ast::struct_alias => z += unparse::ident(out, indent)?; }; z += fmt::fprint(out, ",")?; @@ -591,15 +591,15 @@ fn type_html( }; match (_type.repr) { - case a: ast::alias_type => + case let a: ast::alias_type => if (a.unwrap) { z += fmt::fprint(out, "...")?; }; z += unparse::ident(out, a.ident)?; - case t: ast::builtin_type => + case let t: ast::builtin_type => z += fmt::fprintf(out, "<span class='type'>{}</span>", builtin_type(t))?; - case t: ast::tagged_type => + case let t: ast::tagged_type => z += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { z += type_html(out, indent, *t[i], brief)?; @@ -608,7 +608,7 @@ fn type_html( }; }; z += fmt::fprint(out, ")")?; - case t: ast::tuple_type => + case let t: ast::tuple_type => z += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { z += type_html(out, indent, *t[i], brief)?; @@ -617,13 +617,13 @@ fn type_html( }; }; z += fmt::fprint(out, ")")?; - case t: ast::pointer_type => + case let t: ast::pointer_type => if (t.flags & ast::pointer_flags::NULLABLE != 0) { z += fmt::fprint(out, "<span class='type'>nullable</span> ")?; }; z += fmt::fprint(out, "*")?; z += type_html(out, indent, *t.referent, brief)?; - case t: ast::func_type => + case let t: ast::func_type => if (t.attrs & ast::func_attrs::NORETURN == ast::func_attrs::NORETURN) { z += fmt::fprint(out, "@noreturn ")?; }; @@ -649,12 +649,12 @@ fn type_html( }; z += fmt::fprint(out, ") ")?; z += type_html(out, indent, *t.result, brief)?; - case t: ast::enum_type => + case let t: ast::enum_type => z += enum_html(out, indent, t)?; - case t: ast::list_type => + case let t: ast::list_type => z += fmt::fprint(out, "[")?; match (t.length) { - case expr: *ast::expr => + case let expr: *ast::expr => z += unparse::expr(out, indent, *expr)?; case ast::len_slice => z += 0; @@ -666,9 +666,9 @@ fn type_html( z += fmt::fprint(out, "]")?; z += type_html(out, indent, *t.members, brief)?; - case t: ast::struct_type => + case let t: ast::struct_type => z += struct_union_html(out, indent, _type, brief)?; - case t: ast::union_type => + case let t: ast::union_type => z += struct_union_html(out, indent, _type, brief)?; }; diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -94,24 +94,24 @@ export fn main() void = { const id: ast::ident = if (len(cmd.args) < 1) [] else match (parse::identstr(cmd.args[0])) { - case err: parse::error => + case let err: parse::error => fmt::fatal(parse::strerror(err)); - case id: ast::ident => + case let id: ast::ident => yield id; }; let decl = ""; let dirname = if (len(id) < 2) id else id[..len(id) - 1]; const version = match (module::lookup(&ctx, id)) { - case ver: module::version => + case let ver: module::version => yield ver; - case err: module::error => + case let err: module::error => yield match (module::lookup(&ctx, dirname)) { - case ver: module::version => + case let ver: module::version => assert(len(id) >= 2); decl = id[len(id) - 1]; yield ver; - case err: module::error => + case let err: module::error => fmt::fatal( "Error scanning input module: {}", module::strerror(err)); @@ -125,9 +125,9 @@ export fn main() void = { continue; }; match (scan(in.path)) { - case u: ast::subunit => + case let u: ast::subunit => append(decls, u.decls...); - case err: error => + case let err: error => fmt::fatal("Error: {}", strerror(err)); }; }; @@ -136,16 +136,16 @@ export fn main() void = { defer free(rpath); const readme: (io::file | void) = if (decl == "") { yield match (os::open(rpath)) { - case err: fs::error => + case let err: fs::error => yield void; - case f: io::file => + case let f: io::file => yield f; }; } else void; defer match (readme) { case void => void; - case f: io::file => + case let f: io::file => io::close(f); }; @@ -188,34 +188,34 @@ export fn main() void = { match (emit(&ctx)) { case void => void; - case err: error => + case let err: error => fmt::fatal("Error: {}", strerror(err)); }; io::close(ctx.out); match (ctx.pager) { case void => void; - case proc: exec::process => + case let proc: exec::process => exec::wait(&proc)!; }; }; fn init_tty(ctx: *context) io::handle = { const pager = match (os::getenv("PAGER")) { - case name: str => + case let name: str => yield match (exec::cmd(name)) { - case cmd: exec::command => + case let cmd: exec::command => yield cmd; case exec::error => return os::stdout; }; case void => yield match (exec::cmd("less")) { - case cmd: exec::command => + case let cmd: exec::command => yield cmd; case exec::error => yield match (exec::cmd("more")) { - case cmd: exec::command => + case let cmd: exec::command => yield cmd; case exec::error => return os::stdout; @@ -236,21 +236,21 @@ fn has_decl(decl: ast::decl, name: str) bool = { }; match (decl.decl) { - case d: []ast::decl_const => + case let d: []ast::decl_const => for (let i = 0z; i < len(d); i += 1) { if (len(d[i].ident) == 1 && d[i].ident[0] == name) { return true; }; }; - case d: ast::decl_func => + case let d: ast::decl_func => return len(d.ident) == 1 && d.ident[0] == name; - case d: []ast::decl_global => + case let d: []ast::decl_global => for (let i = 0z; i < len(d); i += 1) { if (len(d[i].ident) == 1 && d[i].ident[0] == name) { return true; }; }; - case d: []ast::decl_type => + case let d: []ast::decl_type => for (let i = 0z; i < len(d); i += 1) { if (len(d[i].ident) == 1 && d[i].ident[0] == name) { return true; @@ -262,9 +262,9 @@ fn has_decl(decl: ast::decl, name: str) bool = { fn scan(path: str) (ast::subunit | error) = { const input = match (os::open(path)) { - case f: io::file => + case let f: io::file => yield f; - case err: fs::error => + case let err: fs::error => fmt::fatal("Error reading {}: {}", path, fs::strerror(err)); }; defer io::close(input); diff --git a/cmd/haredoc/resolver.ha b/cmd/haredoc/resolver.ha @@ -20,14 +20,14 @@ fn resolve(ctx: *context, what: ast::ident) ((ast::ident, symkind) | void) = { let partial = what[..len(what) - 1]; match (module::lookup(ctx.mctx, partial)) { - case ver: module::version => + case let ver: module::version => return (what, symkind::SYMBOL); case module::error => void; }; }; match (module::lookup(ctx.mctx, what)) { - case ver: module::version => + case let ver: module::version => return (what, symkind::MODULE); case module::error => void; }; diff --git a/cmd/haredoc/sort.ha b/cmd/haredoc/sort.ha @@ -24,9 +24,9 @@ fn sort_decls(decls: []ast::decl) summary = { }; match (decl.decl) { - case f: ast::decl_func => + case let f: ast::decl_func => append(sorted.funcs, decl); - case t: []ast::decl_type => + case let t: []ast::decl_type => for (let j = 0z; j < len(t); j += 1) { let bucket = &sorted.types; if (t[j]._type.flags & ast::type_flags::ERROR == ast::type_flags::ERROR) { @@ -44,7 +44,7 @@ fn sort_decls(decls: []ast::decl) summary = { docs = decl.docs, }); }; - case c: []ast::decl_const => + case let c: []ast::decl_const => for (let j = 0z; j < len(c); j += 1) { append(sorted.constants, ast::decl { exported = true, @@ -58,7 +58,7 @@ fn sort_decls(decls: []ast::decl) summary = { docs = decl.docs, }); }; - case g: []ast::decl_global => + case let g: []ast::decl_global => for (let j = 0z; j < len(g); j += 1) { append(sorted.globals, ast::decl { exported = true, @@ -97,15 +97,15 @@ fn decl_cmp(a: const *void, b: const *void) int = { fn decl_ident(decl: ast::decl) ast::ident = { match (decl.decl) { - case f: ast::decl_func => + case let f: ast::decl_func => return f.ident; - case t: []ast::decl_type => + case let t: []ast::decl_type => assert(len(t) == 1); return t[0].ident; - case c: []ast::decl_const => + case let c: []ast::decl_const => assert(len(c) == 1); return c[0].ident; - case g: []ast::decl_global => + case let g: []ast::decl_global => assert(len(g) == 1); return g[0].ident; }; diff --git a/cmd/haredoc/tty.ha b/cmd/haredoc/tty.ha @@ -16,10 +16,10 @@ fn emit_tty(ctx: *context) (void | error) = { const summary = ctx.summary; match (ctx.readme) { - case readme: io::file => + case let readme: io::file => for (true) match (bufio::scanline(readme)?) { case io::EOF => break; - case b: []u8 => + case let b: []u8 => firstline = false; fmt::fprintfln(ctx.out, "\x1b[1m" "// {}" "\x1b[0m", @@ -51,7 +51,7 @@ fn isws(s: str) bool = { const iter = strings::iter(s); for (true) { match (strings::next(&iter)) { - case r: rune => + case let r: rune => if (!ascii::isspace(r)) { return false; }; @@ -74,7 +74,7 @@ fn details_tty(ctx: *context, decl: ast::decl) (void | error) = { const iter = strings::tokenize(decl.docs, "\n"); for (true) { match (strings::next_token(&iter)) { - case s: str => + case let s: str => if (!(strings::peek_token(&iter) is void)) { fmt::fprintfln(ctx.out, "\x1b[1m" "//{}" "\x1b[0m", s)?; @@ -92,7 +92,7 @@ fn details_tty(ctx: *context, decl: ast::decl) (void | error) = { fn unparse_tty(out: io::handle, d: ast::decl) (size | io::error) = { let n = 0z; match (d.decl) { - case g: []ast::decl_global => + case let g: []ast::decl_global => n += fmt::fprint(out, "\x1b[34m")?; n += fmt::fprint(out, if (g[0].is_const) "const " else "let ")?; @@ -110,7 +110,7 @@ fn unparse_tty(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case c: []ast::decl_const => + case let c: []ast::decl_const => n += fmt::fprintf(out, "\x1b[34m" "def " "\x1b[0m")?; for (let i = 0z; i < len(c); i += 1) { n += unparse::ident(out, c[i].ident)?; @@ -120,7 +120,7 @@ fn unparse_tty(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case t: []ast::decl_type => + case let t: []ast::decl_type => n += fmt::fprint(out, "\x1b[34m" "type " "\x1b[0m")?; for (let i = 0z; i < len(t); i += 1) { n += unparse::ident(out, t[i].ident)?; @@ -130,7 +130,7 @@ fn unparse_tty(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case f: ast::decl_func => + case let f: ast::decl_func => n += fmt::fprint(out, "\x1b[33m")?; n += fmt::fprint(out, switch (f.attrs) { case ast::fndecl_attrs::NONE => @@ -201,11 +201,11 @@ fn struct_union_type_tty( ) (size | io::error) = { let z = 0z; let membs = match (t.repr) { - case st: ast::struct_type => + case let st: ast::struct_type => z += fmt::fprint(out, "\x1b[36m" "struct" "\x1b[0m" " {")?; yield st: []ast::struct_member; - case ut: ast::union_type => + case let ut: ast::union_type => z += fmt::fprint(out, "\x1b[36m" "union" "\x1b[0m" " {")?; yield ut: []ast::struct_member; @@ -217,18 +217,18 @@ fn struct_union_type_tty( match (membs[i]._offset) { case null => void; - case ex: *ast::expr => + case let ex: *ast::expr => z += fmt::fprint(out, "\x1b[33m" "@offset(")?; z += unparse::expr(out, indent, *ex)?; z += fmt::fprint(out, ") \x1b[0m")?; }; match (membs[i].member) { - case se: ast::struct_embedded => + case let se: ast::struct_embedded => z += type_tty(out, indent, *se)?; - case sa: ast::struct_alias => + case let sa: ast::struct_alias => z += unparse::ident(out, sa)?; - case sf: ast::struct_field => + case let sf: ast::struct_field => z += fmt::fprintf(out, "{}: ", sf.name)?; z += type_tty(out, indent, *sf._type)?; }; @@ -262,15 +262,15 @@ fn type_tty( }; match (t.repr) { - case a: ast::alias_type => + case let a: ast::alias_type => if (a.unwrap) { n += fmt::fprint(out, "...")?; }; n += unparse::ident(out, a.ident)?; - case b: ast::builtin_type => + case let b: ast::builtin_type => n += fmt::fprintf(out, "\x1b[36m" "{}" "\x1b[0m", builtin_type(b))?; - case e: ast::enum_type => + case let e: ast::enum_type => n += fmt::fprint(out, "\x1b[36m" "enum " "\x1b[0m")?; if (e.storage != ast::builtin_type::INT) { n += fmt::fprintf(out, @@ -285,7 +285,7 @@ fn type_tty( n += fmt::fprint(out, value.name)?; match (value.value) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => n += fmt::fprint(out, " = ")?; n += unparse::expr(out, indent, *e)?; }; @@ -294,14 +294,14 @@ fn type_tty( indent -= 1; n += newline(out, indent)?; n += fmt::fprint(out, "}")?; - case f: ast::func_type => + case let f: ast::func_type => if (f.attrs & ast::func_attrs::NORETURN != 0) { n += fmt::fprint(out, "\x1b[33m" "@noreturn " "\x1b[0m")?; }; n += fmt::fprint(out, "\x1b[34m" "fn" "\x1b[0m")?; n += prototype_tty(out, indent, f)?; - case l: ast::list_type => + case let l: ast::list_type => n += fmt::fprint(out, "[")?; match (l.length) { case ast::len_slice => void; @@ -309,12 +309,12 @@ fn type_tty( n += fmt::fprint(out, "*")?; case ast::len_contextual => n += fmt::fprint(out, "_")?; - case e: *ast::expr => + case let e: *ast::expr => n += unparse::expr(out, indent, *e)?; }; n += fmt::fprint(out, "]")?; n += type_tty(out, indent, *l.members)?; - case p: ast::pointer_type => + case let p: ast::pointer_type => if (p.flags & ast::pointer_flags::NULLABLE != 0) { n += fmt::fprint(out, "\x1b[36m" "nullable " "\x1b[0m")?; @@ -325,7 +325,7 @@ fn type_tty( n += struct_union_type_tty(out, indent, t)?; case ast::union_type => n += struct_union_type_tty(out, indent, t)?; - case t: ast::tagged_type => + case let t: ast::tagged_type => n += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { n += type_tty(out, indent, *t[i])?; @@ -334,7 +334,7 @@ fn type_tty( }; }; n += fmt::fprint(out, ")")?; - case t: ast::tuple_type => + case let t: ast::tuple_type => n += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { n += type_tty(out, indent, *t[i])?; diff --git a/cmd/iobus/main.ha b/cmd/iobus/main.ha @@ -69,7 +69,7 @@ export fn main() void = { fn readcmd(state: *state) bool = { const line = match (bufio::scanline(os::stdin)!) { - case line: []u8 => + case let line: []u8 => yield strings::fromutf8(line); case io::EOF => return false; diff --git a/compress/flate/inflate.ha b/compress/flate/inflate.ha @@ -104,7 +104,7 @@ fn bits(d: *decompressor, want: u32) (u32 | io::error) = { match (io::read(d.in, buf)?) { case io::EOF => return wraperror(inflate_err::EOF); - case z: size => + case let z: size => if (z < 1) { continue; // Short read, retry }; @@ -231,7 +231,7 @@ fn uncompressed_read(d: *decompressor) (void | io::EOF | io::error) = { static let _buf: [1024]u8 = [0...]; let buf = if (len(_buf) > d.left: size) _buf[..d.left] else _buf[..]; let z = match (io::read(d.in, buf)?) { - case z: size => + case let z: size => d.left -= z; yield z; case io::EOF => @@ -339,7 +339,7 @@ fn next(d: *decompressor) (void | io::EOF | io::error) = { match (io::read(d.in, buf[n..])?) { case io::EOF => return wraperror(inflate_err::EOF); - case z: size => + case let z: size => n += z; }; }; @@ -428,7 +428,7 @@ fn close(s: *io::stream) void = { defer io::close(&s); match (io::copy(outs, &s)) { case size => void; - case e: io::error => + case let e: io::error => fmt::errorln(io::strerror(e))!; abort(); }; diff --git a/compress/zlib/reader.ha b/compress/zlib/reader.ha @@ -59,7 +59,7 @@ fn verifysum(s: *reader) (io::EOF | io::error) = { match (io::read(s.source, hash[n..])?) { case io::EOF => return wraperror(decompress_err::EOF); - case z: size => + case let z: size => n += z; }; }; @@ -73,7 +73,7 @@ fn read(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { match (io::read(&s.flate, buf)?) { case io::EOF => return verifysum(s); - case z: size => + case let z: size => buf = buf[..z]; }; return hash::write(&s.hash, buf); @@ -91,7 +91,7 @@ export fn decompress(src: io::handle) (reader | io::error) = { match (io::read(src, buf[n..])?) { case io::EOF => return wraperror(decompress_err::EOF); - case z: size => + case let z: size => n += z; }; }; @@ -127,15 +127,15 @@ export fn decompress(src: io::handle) (reader | io::error) = { let in = bufio::fixed(*vectors[i].1, io::mode::READ); let out = bufio::dynamic(io::mode::WRITE); let d = match (decompress(in)) { - case s: reader => + case let s: reader => yield s; - case e: io::error => + case let e: io::error => fmt::errorln(io::strerror(e))!; abort(); }; match (io::copy(out, &d)) { case size => void; - case e: io::error => + case let e: io::error => fmt::errorfln("vector {}: {}", i, io::strerror(e))!; abort(); }; diff --git a/crypto/random/+freebsd.ha b/crypto/random/+freebsd.ha @@ -10,13 +10,13 @@ export fn buffer(buf: []u8) void = { let n = 0z; for (n < len(buf)) { match (rt::getrandom(buf[n..]: *[*]u8, len(buf), 0)) { - case err: rt::errno => + case let err: rt::errno => switch (err) { case rt::EINTR => void; case => abort(); }; - case z: size => + case let z: size => n += z; }; }; @@ -25,9 +25,9 @@ export fn buffer(buf: []u8) void = { fn rand_reader(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { assert(s == stream); match (rt::getrandom(buf: *[*]u8, len(buf), 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => return n; }; }; diff --git a/crypto/random/+linux.ha b/crypto/random/+linux.ha @@ -10,13 +10,13 @@ export fn buffer(buf: []u8) void = { let n = 0z; for (n < len(buf)) { match (rt::getrandom(buf[n..]: *[*]u8, len(buf), 0)) { - case err: rt::errno => + case let err: rt::errno => switch (err) { case rt::EINTR => void; case => abort(); }; - case z: size => + case let z: size => n += z; }; }; @@ -25,9 +25,9 @@ export fn buffer(buf: []u8) void = { fn rand_reader(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { assert(s == stream); match (rt::getrandom(buf: *[*]u8, len(buf), 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => return n; }; }; diff --git a/crypto/random/random.ha b/crypto/random/random.ha @@ -28,7 +28,7 @@ export let stream: *io::stream = &_stream; match (io::read(stream, buf[..])) { case (io::error | io::EOF) => abort(); - case n: size => + case let n: size => test = buf[..n]; }; diff --git a/dirs/xdg.ha b/dirs/xdg.ha @@ -5,13 +5,13 @@ use io; fn lookup(prog: str, var: str, default: str) str = { match (os::getenv(var)) { - case s: str => + case let s: str => const path = path::join(s, prog); match (os::stat(path)) { - case err: fs::error => + case let err: fs::error => os::mkdirs(path)!; return path; - case st: fs::filestat => + case let st: fs::filestat => if (fs::isdir(st.mode)) { return path; }; diff --git a/encoding/base64/base64.ha b/encoding/base64/base64.ha @@ -104,14 +104,14 @@ export fn decode( ) (size | errors::invalid | io::error) = { let dec = decoder(alphabet, in); match (io::copy(out, &dec)) { - case err: io::error => + case let err: io::error => match (err) { case errors::invalid => return errors::invalid; case => return err; }; - case s: size => + case let s: size => return s; }; }; @@ -127,14 +127,14 @@ export fn decode_static( defer io::close(buf); let dec = decoder(alphabet, in); match (io::copy(buf, &dec)) { - case err: io::error => + case let err: io::error => match (err) { case errors::invalid => return errors::invalid; case => return err; }; - case s: size => + case let s: size => return s; }; }; @@ -183,7 +183,7 @@ export fn decodeslice_static( let in = bufio::fixed(in, io::mode::READ); defer io::close(in); // bufio::finish? match (decode_static(alphabet, out, in)) { - case s: size => + case let s: size => return s; case errors::invalid => return errors::invalid; @@ -312,7 +312,7 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) = s.avail = 0; }; break; - case err: io::error => + case let err: io::error => return err; }; } else { @@ -341,7 +341,7 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) = s.waseof = true; z += n; break; - case err: io::error => + case let err: io::error => return err; }; } else { @@ -371,7 +371,7 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) = return io::EOF; }; break; - case err: io::error => + case let err: io::error => return err; }; return z; @@ -400,12 +400,12 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) = defer free(out); for (true) match (io::read(&dec, buf)) { - case z: size => + case let z: size => append(out, buf[0]); assert(z == 1); case io::EOF => break; - case err: io::error => + case let err: io::error => abort(); }; @@ -428,11 +428,11 @@ fn decodestream_reader(s: *io::stream, out: []u8) (size | io::EOF | io::error) = defer free(out); for (true) match (io::read(&dec, buf)) { - case z: size => + case let z: size => append(out, buf[..z]...); case io::EOF => break; - case err: io::error => + case let err: io::error => abort(); }; diff --git a/encoding/hex/hex.ha b/encoding/hex/hex.ha @@ -51,7 +51,7 @@ export fn decode(s: str) ([]u8 | invalid) = { let u = match (strconv::stou8b(oct, 16)) { case (strconv::invalid | strconv::overflow) => return invalid; - case u: u8 => + case let u: u8 => yield u; }; append(buf, u); diff --git a/encoding/utf8/decode.ha b/encoding/utf8/decode.ha @@ -9,9 +9,9 @@ export type decoder = struct { // Initializes a new UTF-8 decoder. export fn decode(src: (str | []u8)) decoder = match (src) { -case s: str => +case let s: str => yield decoder { src = toutf8(s), ... }; -case b: []u8 => +case let b: []u8 => yield decoder { src = b, ... }; }; @@ -97,7 +97,7 @@ export fn prev(d: *decoder) (rune | void | more | invalid) = { match (next(&decoder)) { case (invalid | more | void) => abort(); - case r: rune => + case let r: rune => assert(r == expected[i]); }; }; @@ -107,7 +107,7 @@ export fn prev(d: *decoder) (rune | void | more | invalid) = { match (prev(&decoder)) { case (invalid | more | void) => abort(); - case r: rune => + case let r: rune => assert(r == expected[len(expected) - i - 1]); }; }; diff --git a/errors/string.ha b/errors/string.ha @@ -31,6 +31,6 @@ case refused => yield "A connection attempt was refused"; case nomem => yield "Unable to allocate sufficient memory for the requested operation"; -case op: opaque => +case let op: opaque => yield op.strerror(&op.data); }; diff --git a/fmt/fmt.ha b/fmt/fmt.ha @@ -174,7 +174,7 @@ export fn fprintf( let r: rune = match (strings::next(&iter)) { case void => break; - case r: rune => + case let r: rune => yield r; }; @@ -182,7 +182,7 @@ export fn fprintf( r = match (strings::next(&iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -199,7 +199,7 @@ export fn fprintf( }; const arg = match (arg) { - case arg: formattable => + case let arg: formattable => yield arg; case => abort("Invalid formattable"); @@ -208,7 +208,7 @@ export fn fprintf( r = match (strings::next(&iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -225,9 +225,9 @@ export fn fprintf( }; match (pi) { - case pi: uint => + case let pi: uint => match (args[pi]) { - case pmod: *modifiers => + case let pmod: *modifiers => mod = pmod; case => abort("Explicit parameter is not *fmt::modifier"); @@ -235,7 +235,7 @@ export fn fprintf( case nextparam => i += 1; match (args[i - 1]) { - case pmod: *modifiers => + case let pmod: *modifiers => mod = pmod; case => abort("Implicit parameter is not *fmt::modifier"); @@ -252,7 +252,7 @@ export fn fprintf( match (strings::next(&iter)) { case void => abort("Invalid format string (hanging '}')"); - case r: rune => + case let r: rune => assert(r == '}', "Invalid format string (hanging '}')"); }; @@ -303,22 +303,22 @@ fn format_raw( mod: *modifiers, ) (size | io::error) = { match (arg) { - case s: str => + case let s: str => return io::write(out, strings::toutf8(s)); - case r: rune => + case let r: rune => return io::write(out, utf8::encoderune(r)); - case b: bool => + case let b: bool => return io::write(out, strings::toutf8(if (b) "true" else "false")); - case n: types::numeric => + case let n: types::numeric => const s = strconv::numerictosb(n, mod.base); return io::write(out, strings::toutf8(s)); - case p: uintptr => + case let p: uintptr => const s = strconv::uptrtosb(p, mod.base); return io::write(out, strings::toutf8(s)); - case v: nullable *void => + case let v: nullable *void => match (v) { - case v: *void => + case let v: *void => let n = io::write(out, strings::toutf8("0x"))?; const s = strconv::uptrtosb(v: uintptr, strconv::base::HEX_LOWER); @@ -339,7 +339,7 @@ fn scan_uint(iter: *strings::iterator) uint = { let r = match (strings::next(iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -350,7 +350,7 @@ fn scan_uint(iter: *strings::iterator) uint = { match (strconv::stou(strings::fromutf8(num))) { case (strconv::invalid | strconv::overflow) => abort("Invalid format string (invalid index)"); - case u: uint => + case let u: uint => return u; }; }; @@ -365,7 +365,7 @@ fn scan_modifier_flags(iter: *strings::iterator, mod: *modifiers) void = { let r = match (strings::next(iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -403,7 +403,7 @@ fn scan_modifier_width(iter: *strings::iterator, mod: *modifiers) void = { let r = match (strings::next(iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -419,7 +419,7 @@ fn scan_modifier_precision(iter: *strings::iterator, mod: *modifiers) void = { let r = match (strings::next(iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -434,7 +434,7 @@ fn scan_modifier_base(iter: *strings::iterator, mod: *modifiers) void = { let r = match (strings::next(iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -462,7 +462,7 @@ fn scan_inline_modifiers(iter: *strings::iterator, mod: *modifiers) void = { let terminated = match (strings::next(iter)) { case void => yield false; - case r: rune => + case let r: rune => yield r == '}'; }; assert(terminated, "Invalid format string (unterminated '{')"); @@ -472,7 +472,7 @@ fn scan_parameter_index(iter: *strings::iterator, pi: *paramindex) void = { let r = match (strings::next(iter)) { case void => abort("Invalid format string (unterminated '{')"); - case r: rune => + case let r: rune => yield r; }; @@ -492,7 +492,7 @@ fn scan_parametric_modifiers(iter: *strings::iterator, pi: *paramindex) void = { let terminated = match (strings::next(iter)) { case void => yield false; - case r: rune => + case let r: rune => yield r == '}'; }; assert(terminated, "Invalid format string (unterminated '{')"); diff --git a/fnmatch/fnmatch.ha b/fnmatch/fnmatch.ha @@ -45,14 +45,14 @@ export fn fnmatch(pattern: str, string: str, flag: flags...) bool = { }; if (fl & flags::PATHNAME != 0) { match (fnmatch_pathname(pattern, string, fl)) { - case b: bool => + case let b: bool => return b; case => return false; }; } else { match (fnmatch_internal(pattern, string, fl)) { - case b: bool => + case let b: bool => return b; case => return false; @@ -75,7 +75,7 @@ fn fnmatch_pathname( for (true) match (pat_next(&p_iter, fl)?) { case end => break :outer; - case r: rune => + case let r: rune => if (r == '/') break; case bracket => match_bracket(&p_iter, '\0')?; @@ -84,7 +84,7 @@ fn fnmatch_pathname( let s = match (strings::next_token(&tok)) { case void => return false; - case s: str => + case let s: str => yield s; }; strings::prev(&p_iter); @@ -97,7 +97,7 @@ fn fnmatch_pathname( let s = match(strings::next_token(&tok)) { case void => return false; - case s: str => + case let s: str => yield s; }; let p = strings::iter_str(&start); @@ -137,7 +137,7 @@ fn fnmatch_internal( yield rn is rune; case bracket => yield rn is rune && match_bracket(&p, rn: rune)?; - case r: rune => + case let r: rune => yield rn is rune && rn: rune == r; }; if (!t) { @@ -183,7 +183,7 @@ fn fnmatch_internal( yield rn is rune; case bracket => yield rn is rune && match_bracket(&p, rn: rune)?; - case r: rune => + case let r: rune => yield rn is rune && rn: rune == r; case star => abort(); @@ -212,7 +212,7 @@ fn fnmatch_internal( yield rn is rune; case bracket => yield rn is rune && match_bracket(&p, rn: rune)?; - case r: rune => + case let r: rune => yield rn is rune && r == rn: rune; case star => p_copy = p; @@ -317,7 +317,7 @@ fn match_ctype(it: *strings::iterator, c: rune) (bool | errors::invalid) = { match (ctype_name_to_func(name)) { case null => return errors::invalid; - case f: *fn(c: rune) bool => + case let f: *fn(c: rune) bool => return f(c); }; }; @@ -340,7 +340,7 @@ fn ctype_name_to_func(name: str) nullable *fn(c: rune) bool = { match (sort::search(map, size(funcmap), &name, &cmp)) { case null => return null: nullable *fn(c: rune) bool; - case p: *void => + case let p: *void => return (p: *funcmap).1; }; }; @@ -349,7 +349,7 @@ fn pat_next(pat: *strings::iterator, fl: flags) (token | errors::invalid) = { let r = match (strings::next(pat)) { case void => return end; - case r: rune => + case let r: rune => yield r; }; switch (r) { @@ -370,7 +370,7 @@ fn pat_next(pat: *strings::iterator, fl: flags) (token | errors::invalid) = { fn advance_or_err(it: *strings::iterator) (rune | errors::invalid) = { match (strings::next(it)) { - case r: rune => + case let r: rune => return r; case void => return errors::invalid; diff --git a/format/ini/scan.ha b/format/ini/scan.ha @@ -48,7 +48,7 @@ export fn entry_finish(ent: entry) void = { export fn next(sc: *scanner) (entry | io::EOF | error) = { for (true) { const line = match (bufio::scanline(sc.in)?) { - case b: []u8 => + case let b: []u8 => yield strings::try_fromutf8(b)?; case io::EOF => return io::EOF; @@ -66,7 +66,7 @@ export fn next(sc: *scanner) (entry | io::EOF | error) = { if (strings::hasprefix(line, "[")) { const end = match (strings::index(line, ']')) { - case idx: size => + case let idx: size => yield idx; case void => return sc.lineno: syntaxerr; @@ -77,7 +77,7 @@ export fn next(sc: *scanner) (entry | io::EOF | error) = { }; const eq = match (strings::index(line, '=')) { - case idx: size => + case let idx: size => yield idx; case void => return sc.lineno: syntaxerr; diff --git a/format/ini/types.ha b/format/ini/types.ha @@ -10,11 +10,11 @@ export type error = !(io::error | utf8::invalid | syntaxerr); // Returns a user-friendly representation of [[error]]. export fn strerror(err: error) const str = match (err) { -case err: io::error => +case let err: io::error => return io::strerror(err); case utf8::invalid => return "File is invalid UTF-8"; -case s: syntaxerr => +case let s: syntaxerr => static let buf: [1024]u8 = [0...]; yield fmt::bsprintf(buf, "{}: Invalid syntax", s: size); }; diff --git a/format/xml/+test.ha b/format/xml/+test.ha @@ -87,7 +87,7 @@ fn xmltest(input: str, expected: []token, error: bool) void = { let parser = parse(in) as *parser; for (let i = 0z; i < len(expected); i += 1) { let tok = match (scan(parser)) { - case tok: token => + case let tok: token => yield tok; case void => abort("Expected token, got void"); @@ -95,16 +95,16 @@ fn xmltest(input: str, expected: []token, error: bool) void = { abort("Expected token, got syntax error"); }; match (tok) { - case el: elementstart => + case let el: elementstart => let ex = expected[i] as elementstart; assert(el == ex); - case at: attribute => + case let at: attribute => let ex = expected[i] as attribute; assert(at.0 == ex.0 && at.1 == ex.1); - case tx: text => + case let tx: text => let ex = expected[i] as text; assert(tx == ex); - case el: elementend => + case let el: elementend => let ex = expected[i] as elementend; assert(el == ex); }; diff --git a/format/xml/parser.ha b/format/xml/parser.ha @@ -68,7 +68,7 @@ export fn scan(par: *parser) (token | void | error) = { } else { return; }; - case rn: rune => + case let rn: rune => yield rn; }; switch (par.state) { @@ -78,7 +78,7 @@ export fn scan(par: *parser) (token | void | error) = { const next = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => bufio::unreadrune(par.in, rn); yield rn; }; @@ -139,7 +139,7 @@ fn scan_attr(par: *parser) (token | error) = { for (true) match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => rn = switch (rn) { case '<' => return syntaxerr; @@ -160,7 +160,7 @@ fn scan_comment(par: *parser) (token | void | error) = { match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => switch (rn) { case '-' => // Comments want(par, '-')?; @@ -178,21 +178,21 @@ fn scan_comment(par: *parser) (token | void | error) = { const rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (rn != '-') continue; const rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (rn != '-') continue; const rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (rn == '>') break; @@ -206,7 +206,7 @@ fn scan_cdata(par: *parser) (text | error) = { const rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (rn != ']') { @@ -216,7 +216,7 @@ fn scan_cdata(par: *parser) (text | error) = { const rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (rn != ']') { @@ -226,7 +226,7 @@ fn scan_cdata(par: *parser) (text | error) = { const rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (rn == '>') break; @@ -240,7 +240,7 @@ fn scan_content(par: *parser) (text | error) = { for (true) match (bufio::scanrune(par.in)?) { case io::EOF => break; - case rn: rune => + case let rn: rune => rn = switch (rn) { case '<' => bufio::unreadrune(par.in, rn); @@ -262,7 +262,7 @@ fn scan_element(par: *parser) (token | error) = { match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => switch (rn) { case '/' => close = true; @@ -285,7 +285,7 @@ fn scan_entity(par: *parser) (rune | error) = { let rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; switch (rn) { @@ -304,7 +304,7 @@ fn scan_charref(par: *parser) (rune | error) = { match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => if (rn == 'x') { base = strconv::base::HEX; } else { @@ -317,7 +317,7 @@ fn scan_charref(par: *parser) (rune | error) = { let rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (ascii::isdigit(rn)) { @@ -332,7 +332,7 @@ fn scan_charref(par: *parser) (rune | error) = { return syntaxerr; }; match (strconv::stou32b(strio::string(par.entbuf), base)) { - case u: u32 => + case let u: u32 => return u: rune; case (strconv::invalid | strconv::overflow) => return syntaxerr; @@ -365,7 +365,7 @@ fn scan_name(par: *parser, buf: io::handle) (str | error) = { const rn = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (!isnamestart(rn)) { @@ -376,7 +376,7 @@ fn scan_name(par: *parser, buf: io::handle) (str | error) = { for (true) match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => if (isname(rn)) { strio::appendrune(buf, rn)!; } else { @@ -404,7 +404,7 @@ fn prolog(par: *parser) (void | error) = { for (true) match (bufio::scanrune(par.in)?) { case io::EOF => break; - case rn: rune => + case let rn: rune => if (!ascii::isdigit(rn)) { bufio::unreadrune(par.in, rn); break; @@ -416,7 +416,7 @@ fn prolog(par: *parser) (void | error) = { let encoding = match (bufio::scanrune(par.in)) { case io::EOF => yield false; - case rn: rune => + case let rn: rune => bufio::unreadrune(par.in, rn); yield hadws && rn == 'e'; }; @@ -429,7 +429,7 @@ fn prolog(par: *parser) (void | error) = { match (ascii::strcasecmp(attr.1, "utf-8")) { case void => return utf8::invalid; - case n: int => + case let n: int => if (n != 0) { return utf8::invalid; }; @@ -440,7 +440,7 @@ fn prolog(par: *parser) (void | error) = { let standalone = match (bufio::scanrune(par.in)) { case io::EOF => yield false; - case rn: rune => + case let rn: rune => bufio::unreadrune(par.in, rn); yield hadws && rn == 's'; }; @@ -453,7 +453,7 @@ fn prolog(par: *parser) (void | error) = { match (ascii::strcasecmp(attr.1, "yes")) { case void => return syntaxerr; - case n: int => + case let n: int => if (n != 0) { return syntaxerr; }; @@ -472,7 +472,7 @@ def OPTWS: whitespace = false; fn quote(par: *parser) (rune | error) = { match (bufio::scanrune(par.in)?) { - case rn: rune => + case let rn: rune => switch (rn) { case '"', '\'' => return rn; @@ -487,30 +487,30 @@ fn quote(par: *parser) (rune | error) = { fn want(par: *parser, tok: (rune | str | whitespace)...) (bool | error) = { let hadws = false; for (let i = 0z; i < len(tok); i += 1) match (tok[i]) { - case x: rune => + case let x: rune => let have = match (bufio::scanrune(par.in)?) { case io::EOF => return syntaxerr; - case rn: rune => + case let rn: rune => yield rn; }; if (have != x) { return syntaxerr; }; - case x: str => + case let x: str => let iter = strings::iter(x); for (true) match (strings::next(&iter)) { - case rn: rune => + case let rn: rune => want(par, rn)?; case void => break; }; - case ws: whitespace => + case let ws: whitespace => let n = 0; for (true; n += 1) match (bufio::scanrune(par.in)?) { case io::EOF => break; - case rn: rune => + case let rn: rune => if (!ascii::isspace(rn)) { bufio::unreadrune(par.in, rn); break; diff --git a/format/xml/types.ha b/format/xml/types.ha @@ -48,6 +48,6 @@ case syntaxerr => yield "Syntax error"; case utf8::invalid => yield "Document is not valid UTF-8"; -case err: io::error => +case let err: io::error => yield io::strerror(err); }; diff --git a/fs/fs.ha b/fs/fs.ha @@ -6,7 +6,7 @@ use path; export fn close(fs: *fs) void = { match (fs.close) { case null => void; - case f: *closefunc => + case let f: *closefunc => f(fs); }; }; @@ -17,7 +17,7 @@ export fn open(fs: *fs, path: str, flags: flags...) (io::handle | error) = { match (fs.open) { case null => return errors::unsupported; - case f: *openfunc => + case let f: *openfunc => return f(fs, path, flags...); }; }; @@ -31,7 +31,7 @@ export fn open_file(fs: *fs, path: str, flags: flags...) (io::file | error) = { match (fs.openfile) { case null => return errors::unsupported; - case f: *openfilefunc => + case let f: *openfilefunc => return f(fs, path, flags...); }; }; @@ -47,7 +47,7 @@ export fn create( match (fs.create) { case null => return errors::unsupported; - case f: *createfunc => + case let f: *createfunc => return f(fs, path, mode, flags...); }; }; @@ -67,7 +67,7 @@ export fn create_file( match (fs.createfile) { case null => return errors::unsupported; - case f: *createfilefunc => + case let f: *createfilefunc => return f(fs, path, mode, flags...); }; }; @@ -77,7 +77,7 @@ export fn remove(fs: *fs, path: str) (void | error) = { match (fs.remove) { case null => return errors::unsupported; - case f: *removefunc => + case let f: *removefunc => return f(fs, path); }; }; @@ -89,7 +89,7 @@ export fn rename(fs: *fs, oldpath: str, newpath: str) (void | error) = { match (fs.rename) { case null => return errors::unsupported; - case f: *renamefunc => + case let f: *renamefunc => return f(fs, oldpath, newpath); }; }; @@ -99,7 +99,7 @@ export fn rename(fs: *fs, oldpath: str, newpath: str) (void | error) = { export fn move(fs: *fs, oldpath: str, newpath: str) (void | error) = { match (rename(fs, oldpath, newpath)) { case (cannotrename | errors::unsupported) => void; // Fallback - case err: error => + case let err: error => return err; case void => return; // Success @@ -124,7 +124,7 @@ export fn iter(fs: *fs, path: str) (*iterator | error) = { match (fs.iter) { case null => return errors::unsupported; - case f: *iterfunc => + case let f: *iterfunc => return f(fs, path); }; }; @@ -135,7 +135,7 @@ export fn stat(fs: *fs, path: str) (filestat | error) = { match (fs.stat) { case null => return errors::unsupported; - case f: *statfunc => + case let f: *statfunc => return f(fs, path); }; }; @@ -160,7 +160,7 @@ export fn readlink(fs: *fs, path: str) (str | error) = { match (fs.readlink) { case null => return errors::unsupported; - case f: *readlinkfunc => + case let f: *readlinkfunc => return f(fs, path); }; }; @@ -172,7 +172,7 @@ export fn subdir(fs: *fs, path: str) (*fs | error) = { match (fs.subdir) { case null => return errors::unsupported; - case f: *subdirfunc => + case let f: *subdirfunc => return f(fs, path); }; }; @@ -182,7 +182,7 @@ export fn mkdir(fs: *fs, path: str) (void | error) = { match (fs.mkdir) { case null => return errors::unsupported; - case f: *mkdirfunc => + case let f: *mkdirfunc => return f(fs, path); }; }; @@ -194,14 +194,14 @@ export fn mkdirs(fs: *fs, path: str) (void | error) = { match (mkdirs(fs, parent)) { case errors::exists => void; case void => void; - case err: error => + case let err: error => return err; }; }; match (mkdir(fs, path)) { case errors::exists => void; case void => void; - case err: error => + case let err: error => return err; }; }; @@ -215,7 +215,7 @@ export fn rmdir(fs: *fs, path: str) (void | error) = { match (fs.rmdir) { case null => return errors::unsupported; - case f: *rmdirfunc => + case let f: *rmdirfunc => return f(fs, path); }; }; @@ -225,7 +225,7 @@ export fn rmdirall(fs: *fs, path: str) (void | error) = { let it = iter(fs, path)?; for (true) { match (next(it)) { - case ent: dirent => + case let ent: dirent => if (ent.name == "." || ent.name == "..") { continue; }; @@ -254,7 +254,7 @@ export fn mksubdir(fs: *fs, path: str) (*fs | error) = { case null => mkdir(fs, path)?; return subdir(fs, path); - case f: *mksubdirfunc => + case let f: *mksubdirfunc => return f(fs, path); }; }; @@ -264,7 +264,7 @@ export fn chmod(fs: *fs, path: str, mode: mode) (void | error) = { match (fs.chmod) { case null => return errors::unsupported; - case f: *chmodfunc => + case let f: *chmodfunc => return f(fs, path, mode); }; }; @@ -274,7 +274,7 @@ export fn chown(fs: *fs, path: str, uid: uint, gid: uint) (void | error) = { match (fs.chown) { case null => return errors::unsupported; - case f: *chownfunc => + case let f: *chownfunc => return f(fs, path, uid, gid); }; }; @@ -285,7 +285,7 @@ export fn chown(fs: *fs, path: str, uid: uint, gid: uint) (void | error) = { export fn resolve(fs: *fs, path: str) str = { match (fs.resolve) { case null => void; - case f: *resolvefunc => + case let f: *resolvefunc => return f(fs, path); }; abort(); // TODO diff --git a/fs/mem/+test.ha b/fs/mem/+test.ha @@ -57,7 +57,7 @@ use strconv; for (true) match (it.next(it)) { case void => break; - case d: fs::dirent => + case let d: fs::dirent => count += 1; }; assert(count == 6); @@ -144,7 +144,7 @@ use strconv; for (true) match (it.next(it)) { case void => break; - case d: fs::dirent => + case let d: fs::dirent => count += 1; }; assert(count == limit); diff --git a/fs/mem/mem.ha b/fs/mem/mem.ha @@ -132,7 +132,7 @@ fn stat(fs: *fs::fs, path: str) (fs::filestat | fs::error) = { match (inode_find(fs: *inode, path)?.data) { case directory => return fs::filestat { mode = fs::mode::DIR | 0o777, ... }; - case f: file => + case let f: file => return fs::filestat { mode = fs::mode::REG | 0o777, mask = fs::stat_mask::SIZE, @@ -193,7 +193,7 @@ fn subdir(fs: *fs::fs, path: str) (*fs::fs | fs::error) = { fn iter(fs: *fs::fs, path: str) (*fs::iterator | fs::error) = { let ino = inode_find(fs: *inode, path)?; match (ino.data) { - case d: directory => + case let d: directory => return alloc(iterator { next = &next, parent = ino, @@ -208,7 +208,7 @@ fn iter(fs: *fs::fs, path: str) (*fs::iterator | fs::error) = { fn next(iter: *fs::iterator) (fs::dirent | void) = { match (_next(iter)) { case null => void; - case ino: *inode => + case let ino: *inode => return fs::dirent { name = ino.name, ftype = match (ino.data) { @@ -231,7 +231,7 @@ fn _next(it: *fs::iterator) nullable *inode = { for (iter.idx < len(p.ents)) match (p.ents[iter.idx]) { case null => iter.idx += 1; - case ino: *inode => + case let ino: *inode => iter.curr = ino.next; return ino; }; @@ -244,7 +244,7 @@ fn rmdir(fs: *fs::fs, path: str) (void | fs::error) = { return errors::invalid; }; match (ino.data) { - case d: directory => + case let d: directory => if (ino.opencount != 0 || d.sz != 0) { return errors::busy; }; @@ -283,7 +283,7 @@ fn close_rec(ino: *inode) void = { for (true) match (_next(&it)) { case null => break; - case ino: *inode => + case let ino: *inode => ino.parent = null; match (ino.data) { case file => diff --git a/fs/mem/util.ha b/fs/mem/util.ha @@ -34,7 +34,7 @@ fn ensure(parent: *inode) void = { for (true) match (old[i]) { case null => break; - case ino: *inode => + case let ino: *inode => old[i] = ino.next; _inode_insert(parent, ino); }; @@ -64,7 +64,7 @@ fn unlink(parent: *inode, ino: *inode) void = { for (true) match (it) { case null => break; - case ii: *inode => + case let ii: *inode => if (ii.hash == ino.hash && ii.name == ino.name) { *prev = ii.next; break; @@ -79,9 +79,9 @@ fn unlink(parent: *inode, ino: *inode) void = { fn inode_free(ino: *inode) void = { match (ino.data) { - case d: directory => + case let d: directory => free(d.ents); - case f: file => + case let f: file => free(f); }; free(ino.name); @@ -102,12 +102,12 @@ fn find_rec(dir: *inode, name: str, it: *path::iterator) (*inode | fs::error) = for (true) match (bucket) { case null => break; - case ino: *inode => + case let ino: *inode => if (name == ino.name) { match (path::next(it)) { case void => return ino; - case name: str => + case let name: str => return find_rec(ino, name, it); }; }; diff --git a/fs/util.ha b/fs/util.ha @@ -17,7 +17,7 @@ case errors::exists => yield "File or directory exists"; case errors::invalid => yield "Invalid argument"; -case err: io::error => +case let err: io::error => yield io::strerror(err); }; @@ -95,7 +95,7 @@ export fn readdir(fs: *fs, path: str) ([]dirent | error) = { let ents: []dirent = []; for (true) { match (next(i)) { - case d: dirent => + case let d: dirent => append(ents, dirent_dup(&d)); case void => break; diff --git a/getopt/getopts.ha b/getopt/getopts.ha @@ -132,14 +132,14 @@ export fn parse(args: []str, help: help...) command = { let p: parameter_help = match (help[j]) { case cmd_help => continue :help; - case f: flag_help => + case let f: flag_help => if (r == f.0) { append(opts, (r, "")); continue :flag; } else { continue :help; }; - case p: parameter_help => + case let p: parameter_help => yield if (r == p.0) p else continue :help; }; @@ -247,16 +247,16 @@ export fn printhelp(out: io::handle, name: str, help: []help) void = { for (let i = 0z; i < len(help); i += 1) match (help[i]) { case cmd_help => void; - case f: flag_help => + case let f: flag_help => fmt::fprintfln(out, "-{}: {}", f.0: rune, f.1)!; - case p: parameter_help => + case let p: parameter_help => fmt::fprintfln(out, "-{} <{}>: {}", p.0: rune, p.1, p.2)!; }; }; fn errmsg(name: str, err: str, opt: (rune | void), help: []help) void = { fmt::errorfln("{}: {}{}", name, err, match (opt) { - case r: rune => + case let r: rune => yield r; case void => yield ""; diff --git a/hare/ast/decl.ha b/hare/ast/decl.ha @@ -60,7 +60,7 @@ export type decl = struct { // Frees resources associated with a declaration. export fn decl_free(d: decl) void = match (d.decl) { -case g: []decl_global => +case let g: []decl_global => for (let i = 0z; i < len(g); i += 1) { free(g[i].symbol); ident_free(g[i].ident); @@ -68,18 +68,18 @@ case g: []decl_global => expr_free(g[i].init); }; free(g); -case t: []decl_type => +case let t: []decl_type => for (let i = 0z; i < len(t); i += 1) { ident_free(t[i].ident); type_free(t[i]._type); }; free(t); -case f: decl_func => +case let f: decl_func => free(f.symbol); ident_free(f.ident); type_free(f.prototype); if (f.body is expr) expr_free(f.body as expr); -case c: []decl_const => +case let c: []decl_const => for (let i = 0z; i < len(c); i += 1) { ident_free(c[i].ident); type_free(c[i]._type); diff --git a/hare/ast/expr.ha b/hare/ast/expr.ha @@ -275,7 +275,7 @@ export type len_expr = *expr; // name: type => expr export type match_case = struct { name: str, - _type: *_type, + _type: nullable *_type, exprs: []*expr, }; @@ -378,123 +378,123 @@ export type expr = struct { // Frees resources associated with a Hare [[expr]]ession. export fn expr_free(e: (expr | nullable *expr)) void = match (e) { -case e: nullable *expr => +case let e: nullable *expr => match (e) { case null => void; - case e: *expr => + case let e: *expr => expr_free(*e); free(e); }; -case e: expr => +case let e: expr => match (e.expr) { - case a: access_expr => + case let a: access_expr => match (a) { - case i: access_identifier => + case let i: access_identifier => ident_free(i); - case i: access_index => + case let i: access_index => expr_free(i.object); expr_free(i.index); - case f: access_field => + case let f: access_field => expr_free(f.object); free(f.field); - case t: access_tuple => + case let t: access_tuple => expr_free(t.object); expr_free(t.value); }; - case a: alloc_expr => + case let a: alloc_expr => expr_free(a.init); expr_free(a.capacity); - case a: append_expr => + case let a: append_expr => expr_free(a.object); match (a.variadic) { case null => void; - case v: *expr => + case let v: *expr => expr_free(v); }; for (let i = 0z; i < len(a.values); i += 1) { expr_free(a.values[i]); }; free(a.values); - case a: assert_expr => + case let a: assert_expr => expr_free(a.cond); expr_free(a.message); - case a: assign_expr => + case let a: assign_expr => expr_free(a.object); expr_free(a.value); - case b: binarithm_expr => + case let b: binarithm_expr => expr_free(b.lvalue); expr_free(b.rvalue); - case b: binding_expr => + case let b: binding_expr => for (let i = 0z; i < len(b.bindings); i += 1) { free(b.bindings[i].name); type_free(b.bindings[i]._type); expr_free(b.bindings[i].init); }; free(b.bindings); - case b: break_expr => + case let b: break_expr => free(b); - case c: call_expr => + case let c: call_expr => expr_free(c.lvalue); for (let i = 0z; i < len(c.args); i += 1) { expr_free(c.args[i]); }; free(c.args); - case c: cast_expr => + case let c: cast_expr => expr_free(c.value); type_free(c._type); - case c: compound_expr => + case let c: compound_expr => for (let i = 0z; i < len(c.exprs); i += 1) { expr_free(c.exprs[i]); }; free(c.exprs); free(c.label); - case c: constant_expr => + case let c: constant_expr => match (c) { case (void | _null | ...lex::value) => void; - case a: array_constant => + case let a: array_constant => for (let i = 0z; i < len(a.values); i += 1) { expr_free(a.values[i]); }; free(a.values); - case s: struct_constant => + case let s: struct_constant => struct_constant_free(s); - case t: tuple_constant => + case let t: tuple_constant => for (let i = 0z; i < len(t); i += 1) { expr_free(t[i]); }; free(t); }; - case c: continue_expr => + case let c: continue_expr => free(c); - case d: defer_expr => + case let d: defer_expr => expr_free(d: *expr); - case d: delete_expr => + case let d: delete_expr => expr_free(d.object); - case f: for_expr => + case let f: for_expr => expr_free(f.bindings); expr_free(f.cond); expr_free(f.afterthought); expr_free(f.body); - case f: free_expr => + case let f: free_expr => expr_free(f: *expr); - case i: if_expr => + case let i: if_expr => expr_free(i.cond); expr_free(i.tbranch); expr_free(i.fbranch); - case e: insert_expr => + case let e: insert_expr => expr_free(e.object); match (e.variadic) { case null => void; - case v: *expr => + case let v: *expr => expr_free(v); }; for (let i = 0z; i < len(e.values); i += 1) { expr_free(e.values[i]); }; free(e.values); - case l: len_expr => + case let l: len_expr => expr_free(l: *expr); - case m: match_expr => + case let m: match_expr => expr_free(m.value); for (let i = 0z; i < len(m.cases); i += 1) { free(m.cases[i].name); @@ -510,19 +510,19 @@ case e: expr => expr_free(m.default[i]); }; free(m.default); - case o: offset_expr => + case let o: offset_expr => expr_free(o: *expr); - case p: propagate_expr => + case let p: propagate_expr => expr_free(p.expr); - case r: return_expr => + case let r: return_expr => expr_free(r: *expr); - case s: size_expr => + case let s: size_expr => type_free(s: *_type); - case s: slice_expr => + case let s: slice_expr => expr_free(s.object); expr_free(s.start); expr_free(s.end); - case s: switch_expr => + case let s: switch_expr => expr_free(s.value); for (let i = 0z; i < len(s.cases); i += 1) { let opts = s.cases[i].options; @@ -538,9 +538,9 @@ case e: expr => free(exprs); }; free(s.cases); - case u: unarithm_expr => + case let u: unarithm_expr => expr_free(u.operand); - case y: yield_expr => + case let y: yield_expr => free(y.label); expr_free(y.value); }; @@ -550,11 +550,11 @@ fn struct_constant_free(s: struct_constant) void = { ident_free(s.alias); for (let i = 0z; i < len(s.fields); i += 1) { match (s.fields[i]) { - case v: struct_value => + case let v: struct_value => free(v.name); type_free(v._type); expr_free(v.init); - case c: *struct_constant => + case let c: *struct_constant => struct_constant_free(*c); free(c); }; diff --git a/hare/ast/import.ha b/hare/ast/import.ha @@ -19,12 +19,12 @@ export type import = (import_module | import_alias | import_objects); // Frees resources associated with an [[import]]. export fn import_free(import: import) void = { match (import) { - case m: import_module => + case let m: import_module => ident_free(m: ident); - case a: import_alias => + case let a: import_alias => ident_free(a.ident); free(a.alias); - case o: import_objects => + case let o: import_objects => ident_free(o.ident); for (let i = 0z; i < len(o.objects); i += 1) { free(o.objects[i]); diff --git a/hare/ast/type.ha b/hare/ast/type.ha @@ -128,24 +128,24 @@ export type _type = struct { fn struct_type_free(t: (struct_type | union_type)) void = { let membs = match (t) { - case s: struct_type => + case let s: struct_type => yield s: []struct_member; - case u: union_type => + case let u: union_type => yield u: []struct_member; }; for (let i = 0z; i < len(membs); i += 1) { match (membs[i]._offset) { case null => void; - case e: *expr => + case let e: *expr => expr_free(e); }; match (membs[i].member) { - case f: struct_field => + case let f: struct_field => free(f.name); type_free(f._type); - case e: struct_embedded => + case let e: struct_embedded => type_free(e: *_type); - case a: struct_alias => + case let a: struct_alias => ident_free(a); }; }; @@ -155,53 +155,53 @@ fn struct_type_free(t: (struct_type | union_type)) void = { // Frees resources associated with a [[_type]]. export fn type_free(t: (_type | nullable *_type)) void = { match (t) { - case t: nullable *_type => + case let t: nullable *_type => match (t) { case null => void; - case t: *_type => + case let t: *_type => type_free(*t); free(t); }; - case t: _type => + case let t: _type => match (t.repr) { - case a: alias_type => + case let a: alias_type => ident_free(a.ident); case builtin_type => void; - case e: enum_type => + case let e: enum_type => for (let i = 0z; i < len(e.values); i += 1) { free(e.values[i].name); match (e.values[i].value) { case null => void; - case v: *expr => + case let v: *expr => expr_free(v); }; }; free(e.values); - case f: func_type => + case let f: func_type => type_free(f.result); for (let i = 0z; i < len(f.params); i += 1) { free(f.params[i].name); type_free(f.params[i]._type); }; free(f.params); - case l: list_type => + case let l: list_type => match (l.length) { - case e: *expr => + case let e: *expr => expr_free(*e); free(e); case => void; }; type_free(l.members); - case p: pointer_type => + case let p: pointer_type => type_free(p.referent); - case s: (struct_type | union_type) => + case let s: (struct_type | union_type) => struct_type_free(s); - case t: tagged_type => + case let t: tagged_type => for (let i = 0z; i < len(t); i += 1) { type_free(t[i]); }; free(t); - case t: tuple_type => + case let t: tuple_type => for (let i = 0z; i < len(t); i += 1) { type_free(t[i]); }; diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha @@ -40,15 +40,15 @@ use strings; fn vassert(expected: value, actual: value) void = { match (expected) { - case expected: str => + case let expected: str => assert(actual as str == expected); - case expected: rune => + case let expected: rune => assert(actual as rune == expected); - case expected: i64 => + case let expected: i64 => assert(actual as i64 == expected); - case expected: u64 => + case let expected: u64 => assert(actual as u64 == expected); - case expected: f64 => + case let expected: f64 => assert(actual as f64 == expected); case void => assert(actual is void); @@ -62,9 +62,9 @@ fn lextest(in: str, expected: []token) void = { for (let i = 0z; i < len(expected); i += 1) { let etok = expected[i]; let tl = match (lex(&lexer)) { - case tl: token => + case let tl: token => yield tl; - case err: error => + case let err: error => fmt::errorfln("{}: {}", i, strerror(err))!; abort(); }; diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -39,9 +39,9 @@ export type error = !(io::error | syntax); export fn strerror(err: error) const str = { static let buf: [2048]u8 = [0...]; match (err) { - case err: io::error => + case let err: io::error => return io::strerror(err); - case s: syntax => + case let s: syntax => return fmt::bsprintf(buf, "{}:{},{}: Syntax error: {}", s.0.path, s.0.line, s.0.col, s.1); }; @@ -74,7 +74,7 @@ export fn comment(lex: *lexer) str = lex.comment; // Returns the next token from the lexer. export fn lex(lex: *lexer) (token | error) = { match (lex.un) { - case tok: token => + case let tok: token => lex.un = void; return tok; case void => void; @@ -88,7 +88,7 @@ export fn lex(lex: *lexer) (token | error) = { let r = match (nextw(lex)?) { case io::EOF => return (ltok::EOF, void, mkloc(lex)); - case r: (rune, location) => + case let r: (rune, location) => yield r; }; @@ -145,7 +145,7 @@ fn ncmp(a: const *void, b: const *void) int = { match (ascii::strcmp(*a, *b)) { case void => abort("non-ascii name"); // TODO: Bubble me up - case i: int => + case let i: int => return i; }; }; @@ -158,7 +158,7 @@ fn lex_unicode(lex: *lexer, loc: location, n: size) (rune | error) = { case io::EOF => return syntaxerr(loc, "unexpected EOF scanning for escape"); - case r: (rune, location) => + case let r: (rune, location) => yield r.0; }; if (!ascii::isxdigit(r)) { @@ -175,7 +175,7 @@ fn lex_rune(lex: *lexer, loc: location) (rune | error) = { let r = match (next(lex)?) { case io::EOF => return syntaxerr(loc, "unexpected EOF scanning for rune"); - case r: (rune, location) => + case let r: (rune, location) => yield r.0; }; if (r != '\\') { @@ -184,7 +184,7 @@ fn lex_rune(lex: *lexer, loc: location) (rune | error) = { r = match (next(lex)?) { case io::EOF => return syntaxerr(loc, "unexpected EOF scanning for escape"); - case r: (rune, location) => + case let r: (rune, location) => yield r.0; }; switch (r) { @@ -224,7 +224,7 @@ fn lex_string(lex: *lexer, loc: location) (token | error) = { for (true) match (next(lex)?) { case io::EOF => return syntaxerr(loc, "unexpected EOF scanning string literal"); - case r: (rune, location) => + case let r: (rune, location) => if (r.0 == '"') break else { unget(lex, r); @@ -234,7 +234,7 @@ fn lex_string(lex: *lexer, loc: location) (token | error) = { }; match (nextw(lex)?) { case io::EOF => void; - case r: (rune, location) => + case let r: (rune, location) => if (r.0 == '"') { const tok = lex_string(lex, loc)?; const next = tok.1 as str; @@ -250,7 +250,7 @@ fn lex_string(lex: *lexer, loc: location) (token | error) = { fn lex_rn_str(lex: *lexer) (token | error) = { const loc = mkloc(lex); let r = match (next(lex)) { - case r: (rune, location) => + case let r: (rune, location) => yield r.0; case (io::EOF | io::error) => abort(); @@ -268,7 +268,7 @@ fn lex_rn_str(lex: *lexer) (token | error) = { match (next(lex)?) { case io::EOF => return syntaxerr(loc, "unexpected EOF"); - case n: (rune, location) => + case let n: (rune, location) => if (n.0 != '\'') { return syntaxerr(n.1, "expected \"\'\""); }; @@ -279,7 +279,7 @@ fn lex_rn_str(lex: *lexer) (token | error) = { fn lex_name(lex: *lexer, loc: location, label: bool) (token | error) = { let buf = strio::dynamic(); match (next(lex)) { - case r: (rune, location) => + case let r: (rune, location) => assert(is_name(r.0, false)); strio::appendrune(buf, r.0)!; case (io::EOF | io::error) => @@ -288,7 +288,7 @@ fn lex_name(lex: *lexer, loc: location, label: bool) (token | error) = { for (true) match (next(lex)?) { case io::EOF => break; - case r: (rune, location) => + case let r: (rune, location) => if (!is_name(r.0, true)) { unget(lex, r); break; @@ -305,7 +305,7 @@ fn lex_name(lex: *lexer, loc: location, label: bool) (token | error) = { size(str), &n, &ncmp)) { case null => return (ltok::NAME, n, loc); - case v: *void => + case let v: *void => defer free(n); let tok = v: uintptr - &bmap[0]: uintptr; tok /= size(str): uintptr; @@ -318,7 +318,7 @@ fn lex_comment(lexr: *lexer) (token | error) = { for (true) match (next(lexr)?) { case io::EOF => break; - case r: (rune, location) => + case let r: (rune, location) => if (r.0 == '\n') { break; }; @@ -331,7 +331,7 @@ fn lex_comment(lexr: *lexer) (token | error) = { for (true) match (next(lexr)?) { case io::EOF => break; - case r: (rune, location) => + case let r: (rune, location) => strio::appendrune(buf, r.0)!; if (r.0 == '\n') { break; @@ -349,7 +349,7 @@ fn lex_literal(lex: *lexer) (token | error) = { let r = match (next(lex)?) { case io::EOF => return (ltok::EOF, void, loc); - case r: (rune, location) => + case let r: (rune, location) => yield r; }; if (r.0 == '-') { @@ -357,7 +357,7 @@ fn lex_literal(lex: *lexer) (token | error) = { r = match (next(lex)?) { case io::EOF => return (ltok::EOF, void, loc); - case r: (rune, location) => + case let r: (rune, location) => yield r; }; }; @@ -368,7 +368,7 @@ fn lex_literal(lex: *lexer) (token | error) = { r = match (next(lex)?) { case io::EOF => return (ltok::LIT_ICONST, 0i64, loc); - case r: (rune, location) => + case let r: (rune, location) => yield r; }; switch (r.0) { @@ -401,7 +401,7 @@ fn lex_literal(lex: *lexer) (token | error) = { r = match (next(lex)?) { case io::EOF => break; - case r: (rune, location) => + case let r: (rune, location) => yield r; }; if (!strings::contains(basechrs, r.0)) switch (r.0) { @@ -414,7 +414,7 @@ fn lex_literal(lex: *lexer) (token | error) = { r = match (next(lex)?) { case io::EOF => break; - case r: (rune, location) => + case let r: (rune, location) => yield r; }; if (!strings::contains(basechrs, r.0)) { @@ -441,7 +441,7 @@ fn lex_literal(lex: *lexer) (token | error) = { r = match (next(lex)?) { case io::EOF => break; - case r: (rune, location) => + case let r: (rune, location) => yield r; }; switch (r.0) { @@ -472,17 +472,17 @@ fn lex_literal(lex: *lexer) (token | error) = { let exp = match (exp) { case void => yield "0"; - case exp: size => + case let exp: size => let end = match (suff) { case void => yield len(chars); - case suff: size => + case let suff: size => yield suff; }; yield strings::fromutf8(chars[exp..end]); }; let exp = match (strconv::stoi(exp)) { - case exp: int => + case let exp: int => yield exp; case strconv::invalid => abort(); // Shouldn't be lexed in @@ -491,13 +491,13 @@ fn lex_literal(lex: *lexer) (token | error) = { }; let floatend = match (suff) { - case suff: size => + case let suff: size => yield suff; case void => yield len(chars); }; let suff = match (suff) { - case suff: size => + case let suff: size => yield strings::fromutf8(chars[suff..]); case void => yield ""; @@ -533,7 +533,7 @@ fn lex_literal(lex: *lexer) (token | error) = { yield strconv::stou64b(val, base); case ltok::LIT_ICONST => yield match (strconv::stoi64b(val, base)) { - case i: i64 => + case let i: i64 => yield i; case strconv::invalid => abort(); @@ -551,17 +551,17 @@ fn lex_literal(lex: *lexer) (token | error) = { yield strconv::stof64(val); }; let val = match (val) { - case val: u64 => + case let val: u64 => for (let i = 0z; i < exp; i += 1) { val *= 10; }; yield val; - case val: i64 => + case let val: i64 => for (let i = 0z; i < exp; i += 1) { val *= 10; }; yield val; - case val: f64 => + case let val: f64 => yield val; case strconv::invalid => abort(); // Shouldn't be lexed in @@ -581,7 +581,7 @@ fn lex2(lex: *lexer) (token | error) = { yield (ltok::MODULO, [('=', ltok::MODEQ)]); case '/' => match (next(lex)?) { - case r: (rune, location) => + case let r: (rune, location) => switch (r.0) { case '=' => return (ltok::DIVEQ, void, first.1); @@ -598,7 +598,7 @@ fn lex2(lex: *lexer) (token | error) = { yield (ltok::PLUS, [('=', ltok::PLUSEQ)]); case '-' => match (next(lex)?) { - case r: (rune, location) => + case let r: (rune, location) => switch (r.0) { case '=' => return (ltok::MINUSEQ, void, first.1); @@ -617,7 +617,7 @@ fn lex2(lex: *lexer) (token | error) = { }; case ':' => match (next(lex)?) { - case r: (rune, location) => + case let r: (rune, location) => switch (r.0) { case ':' => return (ltok::DOUBLE_COLON, void, first.1); @@ -638,7 +638,7 @@ fn lex2(lex: *lexer) (token | error) = { return syntaxerr(first.1, "unknown token sequence"); }; match (next(lex)?) { - case r: (rune, location) => + case let r: (rune, location) => for (let i = 0z; i < len(tok.1); i += 1) { if (tok.1[i].0 == r.0) { return (tok.1[i].1, void, first.1); @@ -675,7 +675,7 @@ fn lex3(lex: *lexer) (token | error) = { let idx = match (try(lex, r.0, '=')?) { case void => yield 0; // X - case n: (rune, location) => + case let n: (rune, location) => yield switch (n.0) { case '=' => yield 1; // X= @@ -702,16 +702,16 @@ export fn unlex(lex: *lexer, tok: token) void = { fn next(lex: *lexer) ((rune, location) | io::EOF | io::error) = { match (lex.rb[0]) { case void => void; - case r: ((rune, location) | io::EOF) => + case let r: ((rune, location) | io::EOF) => lex.rb[0] = lex.rb[1]; lex.rb[1] = void; return r; }; match (bufio::scanrune(lex.in)) { - case e: (io::EOF | io::error) => + case let e: (io::EOF | io::error) => return e; - case r: rune => + case let r: rune => const loc = mkloc(lex); let tmp = lex.prevrlocs; lex.prevrlocs[1..] = tmp[..len(tmp) - 1]; @@ -723,9 +723,9 @@ fn next(lex: *lexer) ((rune, location) | io::EOF | io::error) = { fn nextw(lex: *lexer) ((rune, location) | io::EOF | io::error) = { for (true) match (next(lex)) { - case e: (io::error | io::EOF) => + case let e: (io::error | io::EOF) => return e; - case r: (rune, location) => + case let r: (rune, location) => if (!ascii::isspace(r.0)) { return r; } else { @@ -740,7 +740,7 @@ fn try(lex: *lexer, want: rune...) ((rune, location) | void | io::error) = { let r = match (next(lex)?) { case io::EOF => return; - case r: (rune, location) => + case let r: (rune, location) => yield r; }; assert(len(want) > 0); @@ -774,11 +774,11 @@ fn unget(lex: *lexer, r: ((rune, location) | io::EOF)) void = { export fn mkloc(lex: *lexer) location = { match (lex.un) { - case t: token => + case let t: token => return lex.prevunlocs[1].1; case void => match (lex.rb[0]) { - case r: (rune, location) => + case let r: (rune, location) => return r.1; case void => return location { @@ -792,7 +792,7 @@ export fn mkloc(lex: *lexer) location = { export fn prevloc(lex: *lexer) location = { match (lex.un) { - case t: token => + case let t: token => return lex.prevunlocs[1].0; case void => let i = 0z; diff --git a/hare/module/context.ha b/hare/module/context.ha @@ -38,7 +38,7 @@ export fn context_init(tags: []tag, defs: []str, harepath: str) context = { dirs::data("hare"), strings::dup("."), ]); - case s: str => + case let s: str => let sl = strings::split(s, ":"); let path: []str = alloc([], len(sl) + 1); for (let i = 0z; i < len(sl); i += 1) { @@ -51,7 +51,7 @@ export fn context_init(tags: []tag, defs: []str, harepath: str) context = { cache: str = match (os::getenv("HARECACHE")) { case void => yield dirs::cache("hare"); - case s: str => + case let s: str => yield strings::dup(s); }, ... diff --git a/hare/module/manifest.ha b/hare/module/manifest.ha @@ -55,9 +55,9 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let file = match (fs::open(ctx.fs, mpath, fs::flags::RDONLY)) { case errors::noentry => return manifest; - case err: fs::error => + case let err: fs::error => return err; - case file: io::handle => + case let file: io::handle => yield file; }; defer io::close(file); @@ -70,7 +70,7 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let line = match (bufio::scanline(file)?) { case io::EOF => break; - case line: []u8 => + case let line: []u8 => yield line; }; defer free(line); @@ -79,7 +79,7 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { case utf8::invalid => // Treat an invalid manifest as empty return manifest; - case s: str => + case let s: str => yield s; }; @@ -91,7 +91,7 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let kind = match (strings::next_token(&tok)) { case void => continue; - case s: str => + case let s: str => yield s; }; @@ -100,11 +100,11 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let ver = match (strings::next_token(&tok)) { case void => return manifest; - case s: str => + case let s: str => yield s; }; match (strconv::stoi(ver)) { - case v: int => + case let v: int => if (v != VERSION) { return manifest; }; @@ -115,39 +115,39 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let hash = match (strings::next_token(&tok)) { case void => return manifest; - case s: str => + case let s: str => yield s; }, path = match (strings::next_token(&tok)) { case void => return manifest; - case s: str => + case let s: str => yield s; }, inode = match (strings::next_token(&tok)) { case void => return manifest; - case s: str => + case let s: str => yield s; }, mtime = match (strings::next_token(&tok)) { case void => return manifest; - case s: str => + case let s: str => yield s; }; let hash = match (hex::decode(hash)) { - case b: []u8 => + case let b: []u8 => yield b; case => return manifest; }; let inode = match (strconv::stoz(inode)) { - case z: size => + case let z: size => yield z; case => return manifest; }; let mtime = match (strconv::stoi64(mtime)) { - case i: i64 => + case let i: i64 => yield time::from_unix(i); case => return manifest; @@ -157,7 +157,7 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let ftype = match (type_for_ext(path)) { case void => return manifest; - case ft: filetype => + case let ft: filetype => yield ft; }; @@ -178,11 +178,11 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let modhash = match (strings::next_token(&tok)) { case void => return manifest; - case s: str => + case let s: str => yield s; }; let modhash = match (hex::decode(modhash)) { - case b: []u8 => + case let b: []u8 => yield b; case => return manifest; @@ -193,11 +193,11 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let hash = match (strings::next_token(&tok)) { case void => break; - case s: str => + case let s: str => yield s; }; let hash = match (hex::decode(hash)) { - case b: []u8 => + case let b: []u8 => yield b; case => return manifest; @@ -207,7 +207,7 @@ export fn manifest_load(ctx: *context, ident: ast::ident) (manifest | error) = { let input = match (getinput(inputs, hash)) { case null => return manifest; - case i: *input => + case let i: *input => yield i; }; append(minputs, *input); @@ -256,7 +256,7 @@ export fn current(manifest: *manifest, version: *version) bool = { let cached = match (cached) { case null => return false; - case v: *version => + case let v: *version => yield v; }; diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -38,7 +38,7 @@ export fn scan(ctx: *context, path: str) (version | error) = { let ft = match (type_for_ext(path)) { case void => return module_not_found; - case ft: filetype => + case let ft: filetype => yield ft; }; let st = fs::stat(ctx.fs, path)?; @@ -62,9 +62,9 @@ export fn scan(ctx: *context, path: str) (version | error) = { inputs = inputs, ... }; - case err: fs::error => + case let err: fs::error => return err; - case iter: *fs::iterator => + case let iter: *fs::iterator => yield iter; }; let ver = version { @@ -107,7 +107,7 @@ export fn parse_name(name: str) (str, str, []tag) = { let tags = match (parsetags(tags)) { case void => return (base, ext, []); - case t: []tag => + case let t: []tag => yield t; }; let base = strings::sub(base, 0, i); @@ -144,7 +144,7 @@ fn scan_directory( const ent = match (fs::next(iter)) { case void => break; - case ent: fs::dirent => + case let ent: fs::dirent => yield ent; }; @@ -328,7 +328,7 @@ export fn lookup(ctx: *context, name: ast::ident) (version | error) = { let cand = path::join(ctx.paths[i - 1], ipath); defer free(cand); match (scan(ctx, cand)) { - case v: version => + case let v: version => return v; case error => void; }; @@ -360,11 +360,11 @@ fn scan_file( let imports = parse::imports(&lexer)?; for (let i = 0z; i < len(imports); i += 1) { let ident = match (imports[i]) { - case m: ast::import_module => + case let m: ast::import_module => yield m: ast::ident; - case a: ast::import_alias => + case let a: ast::import_alias => yield a.ident; - case o: ast::import_objects => + case let o: ast::import_objects => yield o.ident; }; if (!have_ident(deps, ident)) { @@ -401,7 +401,7 @@ export fn parsetags(in: str) ([]tag | void) = { let m = match (strings::next(&iter)) { case void => break; - case r: rune => + case let r: rune => yield r; }; t.mode = switch (m) { @@ -417,7 +417,7 @@ export fn parsetags(in: str) ([]tag | void) = { for (true) match (strings::next(&iter)) { case void => break; - case r: rune => + case let r: rune => if (ascii::isalnum(r) || r == '_') { strio::appendrune(buf, r)!; } else { diff --git a/hare/module/types.ha b/hare/module/types.ha @@ -69,15 +69,15 @@ export fn strerror(err: error) const str = { // Should be more than enough for PATH_MAX * 2 static let buf: [4096]u8 = [0...]; match (err) { - case err: fs::error => + case let err: fs::error => return fs::strerror(err); - case err: io::error => + case let err: io::error => return io::strerror(err); - case err: parse::error => + case let err: parse::error => return parse::strerror(err); case module_not_found => return "Module not found"; - case amb: ambiguous => + case let amb: ambiguous => return fmt::bsprintf(buf, "Cannot choose between {} and {}", amb.0, amb.1); }; diff --git a/hare/module/walk.ha b/hare/module/walk.ha @@ -22,23 +22,23 @@ fn _walk( match (scan(ctx, path)) { case error => void; - case ver: version => + case let ver: version => append(items, ns); }; let iter = match (fs::iter(ctx.fs, path)) { case fs::wrongtype => return; // Single file "module" - case err: fs::error => + case let err: fs::error => return err; - case iter: *fs::iterator => + case let iter: *fs::iterator => yield iter; }; for (true) { const ent = match (fs::next(iter)) { case void => break; - case ent: fs::dirent => + case let ent: fs::dirent => yield ent; }; diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha @@ -232,11 +232,11 @@ @test fn match_expr() void = { roundtrip("export fn main() void = { match (x) { - case i: size => + case let i: size => return y; case foo => return bar; - case foo: int => + case let foo: int => return bar; case foo::bar => return baz; @@ -246,7 +246,7 @@ void; }; match (x) { - case s: matchdata => + case let s: matchdata => return y; case str => return z; diff --git a/hare/parse/+test/loc.ha b/hare/parse/+test/loc.ha @@ -12,9 +12,9 @@ fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) { defer io::close(buf); let lexer = lex::init(buf, "<test>"); let exp = match (expression(&lexer)) { - case exp: ast::expr => + case let exp: ast::expr => yield exp; - case err: error => + case let err: error => fmt::errorln(strerror(err))!; abort(); }; @@ -71,9 +71,9 @@ fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) { defer io::close(buf); let lexer = lex::init(buf, "<test>"); let exp = match (expression(&lexer)) { - case exp: ast::expr => + case let exp: ast::expr => yield exp; - case err: error => + case let err: error => fmt::errorln(strerror(err))!; abort(); }; @@ -95,9 +95,9 @@ fn type_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) { defer io::close(buf); let lexer = lex::init(buf, "<test>"); let typ = match (_type(&lexer)) { - case typ: ast::_type => + case let typ: ast::_type => yield typ; - case err: error => + case let err: error => fmt::errorln(strerror(err))!; abort(); }; diff --git a/hare/parse/+test/roundtrip.ha b/hare/parse/+test/roundtrip.ha @@ -15,9 +15,9 @@ fn roundtrip(src: str) void = { let u = ast::subunit { imports = [], decls: []ast::decl = match (decls(&lexer)) { - case decls: []ast::decl => + case let decls: []ast::decl => yield decls; - case err: error => + case let err: error => fmt::errorln(strerror(err))!; abort(); }, diff --git a/hare/parse/+test/unit.ha b/hare/parse/+test/unit.ha @@ -141,9 +141,9 @@ use strings; defer io::close(buf); let lexer = lex::init(buf, "<test>", lex::flags::COMMENTS); let decls = match (decls(&lexer)) { - case decls: []ast::decl => + case let decls: []ast::decl => yield decls; - case err: error => + case let err: error => fmt::errorln(strerror(err))!; abort(); }; diff --git a/hare/parse/decl.ha b/hare/parse/decl.ha @@ -12,14 +12,14 @@ fn attr_symbol(lexer: *lex::lexer) (str | error) = { let d = strings::iter(s); match (strings::next(&d)) { case void => void; - case r: rune => + case let r: rune => synassert(t.2, ascii::isalpha(r) || r == '.' || r == '_', "Invalid symbol")?; }; for (true) match (strings::next(&d)) { case void => break; - case r: rune => + case let r: rune => synassert(t.2, ascii::isalnum(r) || r == '$' || r == '.' || r == '_', "Invalid symbol")?; }; @@ -116,7 +116,7 @@ fn decl_func(lexer: *lex::lexer) (ast::decl_func | error) = { for (true) match (try(lexer, attrs...)?) { case void => break; - case t: lex::token => + case let t: lex::token => switch (t.0) { case ltok::ATTR_FINI => attr = ast::fndecl_attrs::FINI; @@ -194,7 +194,7 @@ export fn decls(lexer: *lex::lexer) ([]ast::decl | error) = { let decl = match (next) { case void => yield decl_func(lexer)?; - case t: lex::token => + case let t: lex::token => yield switch (t.0) { case ltok::TYPE => yield decl_type(lexer)?; diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -38,7 +38,7 @@ export fn expression(lexer: *lex::lexer) (ast::expr | error) = { ltok::CONST, ltok::YIELD)?) { case void => yield binarithm(lexer, void, 0)?; - case tok: lex::token => + case let tok: lex::token => yield switch (tok.0) { case ltok::LABEL, ltok::LBRACE => yield compound_expr(lexer)?; @@ -61,7 +61,7 @@ export fn expression(lexer: *lex::lexer) (ast::expr | error) = { }; const tok = match (try(lexer, atoks...)?) { - case tok: lex::token => + case let tok: lex::token => yield tok; case => return expr; @@ -268,7 +268,7 @@ fn binarithm( let lvalue = match (lvalue) { case void => yield cast(lexer, void)?; - case expr: ast::expr => + case let expr: ast::expr => yield expr; }; @@ -341,7 +341,7 @@ fn builtin(lexer: *lex::lexer) (ast::expr | error) = { ltok::DELETE, ltok::ABORT, ltok::ASSERT, ltok::INSERT, ltok::STATIC, ltok::SIZE, ltok::LEN, ltok::OFFSET, ltok::DEFER)?) { - case tok: lex::token => + case let tok: lex::token => yield tok; case void => return postfix(lexer, void); @@ -362,7 +362,7 @@ fn builtin(lexer: *lex::lexer) (ast::expr | error) = { let tok = match (peek(lexer, ltok::LET, ltok::CONST, ltok::ABORT, ltok::ASSERT, ltok::APPEND, ltok::INSERT, ltok::DELETE)?) { - case tok: lex::token => + case let tok: lex::token => yield tok; case void => // TODO: The following is lame: @@ -435,13 +435,13 @@ fn cast(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = { const lvalue = match (lvalue) { case void => yield unarithm(lexer)?; - case e: ast::expr => + case let e: ast::expr => yield e; }; const tok = match (try(lexer, ltok::COLON, ltok::AS, ltok::IS)?) { case void => return lvalue; - case tok: lex::token => + case let tok: lex::token => yield tok.0; }; const kind = switch (tok) { @@ -496,7 +496,7 @@ fn control(lexer: *lex::lexer) (ast::expr | error) = { let tok = want(lexer, ltok::BREAK, ltok::CONTINUE, ltok::RETURN)?; let label = if (tok.0 == ltok::BREAK || tok.0 == ltok::CONTINUE) { yield match (try(lexer, ltok::LABEL)?) { - case tok: lex::token => + case let tok: lex::token => yield tok.1 as str; case void => yield ""; @@ -753,7 +753,7 @@ fn plain_array(lexer: *lex::lexer) (ast::expr | error) = { case void => want(lexer, ltok::RBRACKET)?; break; - case tok: lex::token => + case let tok: lex::token => switch (tok.0) { case ltok::ELLIPSIS => expand = true; @@ -827,7 +827,7 @@ fn struct_field( const name = strings::dup(tok.1 as str); const tok = match (try(lexer, ltok::COLON, ltok::DOUBLE_COLON, ltok::EQUAL)?) { - case tok: lex::token => + case let tok: lex::token => yield tok; case void => let id: ast::ident = alloc([name]); @@ -900,7 +900,7 @@ fn postfix(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = let lvalue = match (lvalue) { case void => yield plain_expression(lexer)?; - case ex: ast::expr => + case let ex: ast::expr => yield ex; }; @@ -908,7 +908,7 @@ fn postfix(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = ltok::LBRACKET, ltok::QUESTION, ltok::LNOT)) { case void => return lvalue; - case tok: lex::token => + case let tok: lex::token => yield tok; }; @@ -948,7 +948,7 @@ fn postfix_dot( lvalue: ast::expr, ) (ast::expr | error) = { match (try(lexer, ltok::NAME)?) { - case tok: lex::token => + case let tok: lex::token => return ast::expr { start = lvalue.start, end = lex::prevloc(lexer), @@ -1032,19 +1032,25 @@ fn switch_expr(lexer: *lex::lexer) (ast::expr | error) = { }; fn match_case(lexer: *lex::lexer) (ast::match_case | error) = { - let tok = peek(lexer)? as lex::token; + let tok = lex::lex(lexer)?; let loc = tok.2; - let nt = switch (tok.0) { + let name: str = "", typ: nullable *ast::_type = null; + switch (tok.0) { case ltok::NULL => - want(lexer, ltok::NULL)?; - yield ("", ast::_type { + typ = alloc(ast::_type { start = loc, end = lex::prevloc(lexer), flags = 0, repr = ast::builtin_type::NULL, }); + case ltok::LET => + name = want(lexer, ltok::NAME)?.1 as str; + want(lexer, ltok::COLON)?; + typ = alloc(_type(lexer)?); + case ltok::ARROW => void; case => - yield nametype(lexer)?; + lex::unlex(lexer, tok); + typ = alloc(_type(lexer)?); }; want(lexer, ltok::ARROW)?; let exprs: []*ast::expr = []; @@ -1053,9 +1059,11 @@ fn match_case(lexer: *lex::lexer) (ast::match_case | error) = { want(lexer, ltok::SEMICOLON)?; }; + synassert(lex::mkloc(lexer), len(exprs) != 0, "Expected a match case")?; + return ast::match_case { - name = nt.0, - _type = alloc(nt.1), + name = name, + _type = typ, exprs = exprs, }; }; @@ -1073,7 +1081,7 @@ fn match_expr(lexer: *lex::lexer) (ast::expr | error) = { want(lexer, ltok::CASE)?; match (try(lexer, ltok::ARROW)?) { - case t: lex::token => + case let t: lex::token => if (len(default) != 0) { return syntaxerr(t.2, "More than one default match case"); @@ -1108,7 +1116,7 @@ fn unarithm(lexer: *lex::lexer) (ast::expr | error) = { ltok::LNOT, ltok::TIMES, ltok::BAND)) { case void => return builtin(lexer); - case tok: lex::token => + case let tok: lex::token => yield tok; }; @@ -1146,7 +1154,7 @@ fn yield_expr(lexer: *lex::lexer) (ast::expr | error) = { match (try(lexer, ltok::SEMICOLON, ltok::LABEL)?) { case void => value = alloc(expression(lexer)?); - case t: lex::token => + case let t: lex::token => switch (t.0) { case ltok::SEMICOLON => lex::unlex(lexer, t); diff --git a/hare/parse/ident.ha b/hare/parse/ident.ha @@ -10,7 +10,7 @@ fn ident_trailing(lexer: *lex::lexer) ((ast::ident, bool) | error) = { let z = 0z; for (true) { let name = match (try(lexer, ltok::NAME)?) { - case t: lex::token => + case let t: lex::token => yield t.1 as str; case void => return (ident: ast::ident, true); diff --git a/hare/parse/type.ha b/hare/parse/type.ha @@ -307,7 +307,7 @@ fn struct_embed_or_field( let id: ast::ident = match (try(lexer, ltok::COLON, ltok::DOUBLE_COLON)?) { case void => yield alloc([name.1 as str]); - case tok: lex::token => + case let tok: lex::token => yield switch (tok.0) { case ltok::COLON => let field = ast::struct_field { @@ -339,7 +339,7 @@ fn array_slice_type(lexer: *lex::lexer) (ast::_type | error) = { ltok::TIMES, ltok::RBRACKET)?) { case void => yield alloc(expression(lexer)?); - case tok: lex::token => + case let tok: lex::token => yield switch (tok.0) { case ltok::UNDERSCORE => yield ast::len_contextual; diff --git a/hare/types/class.ha b/hare/types/class.ha @@ -1,10 +1,10 @@ // Returns true if the given type is a signed type. export fn is_signed(ty: const *_type) bool = { match (ty.repr) { - case al: alias => + case let al: alias => // TODO: al.secondary as *_type return is_signed(al.secondary: const *_type); - case bi: builtin => + case let bi: builtin => switch (bi) { case builtin::F32, builtin::F64, builtin::I16, builtin::I32, builtin::I64, builtin::I8, builtin::INT => @@ -12,7 +12,7 @@ export fn is_signed(ty: const *_type) bool = { case => return false; }; - case e: _enum => + case let e: _enum => switch (e.storage) { case builtin::I16, builtin::I32, builtin::I64, builtin::I8, builtin::INT => @@ -28,10 +28,10 @@ export fn is_signed(ty: const *_type) bool = { // Returns true if the given type is a floating-point type. export fn is_float(ty: const *_type) bool = { match (ty.repr) { - case al: alias => + case let al: alias => // TODO: al.secondary as *_type return is_float(al.secondary: const *_type); - case bi: builtin => + case let bi: builtin => switch (bi) { case builtin::F32, builtin::F64 => return true; @@ -46,10 +46,10 @@ export fn is_float(ty: const *_type) bool = { // Returns true if the given type is an integer type. export fn is_integer(ty: const *_type) bool = { match (ty.repr) { - case al: alias => + case let al: alias => // TODO: al.secondary as *_type return is_integer(al.secondary: const *_type); - case bi: builtin => + case let bi: builtin => switch (bi) { case builtin::INT, builtin::UINT, builtin::I16, builtin::I32, builtin::I64, builtin::I8, builtin::U16, diff --git a/hare/types/hash.ha b/hare/types/hash.ha @@ -62,7 +62,7 @@ fn type_storage(t: *_type) u8 = { return storage::ALIAS; case array => return storage::ARRAY; - case b: builtin => + case let b: builtin => return builtin_storage(b); case _enum => return storage::ENUM; @@ -72,7 +72,7 @@ fn type_storage(t: *_type) u8 = { return storage::POINTER; case slice => return storage::SLICE; - case st: _struct => + case let st: _struct => if (st.kind == struct_union::STRUCT) { return storage::STRUCT; } else { @@ -112,35 +112,35 @@ export fn hash(t: *_type) u32 = { write8(&id, t.flags); match (t.repr) { - case a: alias => + case let a: alias => for (let i = len(a.id); i > 0; i -= 1) { hash::write(&id, strings::toutf8(a.id[i - 1])); write8(&id, 0); }; - case a: array => + case let a: array => write32(&id, hash(a.member)); static assert(size(u64) == size(size)); // TODO write64(&id, a.length); case builtin => void; - case e: _enum => + case let e: _enum => write8(&id, builtin_storage(e.storage)); for (let i = 0z; i < len(e.values); i += 1) { hash::write(&id, strings::toutf8(e.values[i].0)); write64(&id, e.values[i].1); }; - case f: func => + case let f: func => write32(&id, hash(f.result)); write8(&id, f.variadism: u8); write8(&id, f.flags: u8); for (let i = 0z; i < len(f.params); i += 1) { write32(&id, hash(f.params[i])); }; - case p: pointer => + case let p: pointer => write8(&id, p.flags); write32(&id, hash(p.referent)); - case s: slice => + case let s: slice => write32(&id, hash(s)); - case st: _struct => + case let st: _struct => for (let i = 0z; i < len(st.fields); i += 1) { const field = st.fields[i]; hash::write(&id, strings::toutf8(field.name)); @@ -148,11 +148,11 @@ export fn hash(t: *_type) u32 = { static assert(size(u64) == size(size)); // TODO write64(&id, field.offs); }; - case tu: tuple => + case let tu: tuple => for (let i = 0z; i < len(tu); i += 1) { write32(&id, hash(tu[i]._type)); }; - case ta: tagged => + case let ta: tagged => for (let i = 0z; i < len(ta); i += 1) { write32(&id, hash(ta[i])); }; diff --git a/hare/types/lookup.ha b/hare/types/lookup.ha @@ -3,7 +3,7 @@ use hare::ast; // Unwraps a type which may be aliased and returns the underlying type. export fn dealias(t: *_type) const *_type = { for (true) match (t.repr) { - case a: alias => + case let a: alias => assert(a.secondary != null); t = a.secondary: const *_type; case => diff --git a/hare/types/store.ha b/hare/types/store.ha @@ -69,7 +69,7 @@ export fn lookup( ) (const *_type | deferred | error) = { const ty = fromast(store, ty)?; if (ty.flags == 0) match (ty.repr) { - case b: builtin => + case let b: builtin => switch (b) { case builtin::CHAR => return &builtin_char; @@ -118,14 +118,14 @@ export fn lookup( fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { let sz = SIZE_UNDEFINED, align = SIZE_UNDEFINED; const repr = match (atype.repr) { - case a: ast::alias_type => + case let a: ast::alias_type => // TODO: This is incomplete assert(!a.unwrap); yield alias { id = ast::ident_dup(a.ident), secondary = null, }; - case b: ast::builtin_type => + case let b: ast::builtin_type => // TODO: Tuple unpacking could improve this yield switch (b) { case ast::builtin_type::BOOL => @@ -203,16 +203,16 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { case ast::builtin_type::ICONST, ast::builtin_type::FCONST => abort(); // TODO? }; - case f: ast::func_type => + case let f: ast::func_type => yield func_from_ast(store, &f)?; - case p: ast::pointer_type => + case let p: ast::pointer_type => sz = store.arch._pointer; align = store.arch._pointer; yield pointer { referent = lookup(store, p.referent)?, flags = p.flags: pointer_flags, }; - case st: ast::struct_type => + case let st: ast::struct_type => let st = struct_from_ast(store, st, false)?; sz = 0; align = 0; for (let i = 0z; i < len(st.fields); i += 1) { @@ -225,7 +225,7 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { }; }; yield st; - case un: ast::union_type => + case let un: ast::union_type => let st = struct_from_ast(store, un, true)?; sz = 0; align = 0; for (let i = 0z; i < len(st.fields); i += 1) { @@ -238,7 +238,7 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { }; }; yield st; - case ta: ast::tagged_type => + case let ta: ast::tagged_type => let ta = tagged_from_ast(store, ta)?; sz = 0; align = 0; for (let i = 0z; i < len(ta); i += 1) { @@ -254,7 +254,7 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { }; sz += store.arch._int % align + store.arch._int; yield ta; - case tu: ast::tuple_type => + case let tu: ast::tuple_type => let tu = tuple_from_ast(store, tu)?; sz = 0; align = 0; for (let i = 0z; i < len(tu); i += 1) { @@ -267,12 +267,12 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { }; }; yield tu; - case lt: ast::list_type => + case let lt: ast::list_type => let r = list_from_ast(store, &lt)?; sz = r.0; align = r.1; yield r.2; - case et: ast::enum_type => + case let et: ast::enum_type => abort(); // TODO }; if (sz != SIZE_UNDEFINED && sz != 0 && sz % align != 0) { @@ -339,11 +339,11 @@ fn list_from_ast( length = SIZE_UNDEFINED, member = memb, }; - case ex: *ast::expr => + case let ex: *ast::expr => const resolv = match (store.resolve) { case null => return noresolver; - case r: *resolver => + case let r: *resolver => yield r; }; const length = resolv(store.rstate, store, ex)?; @@ -368,11 +368,11 @@ fn _struct_from_ast( const nfields = len(fields); for (let i = 0z; i < len(membs); i += 1) { *offs = match (membs[i]._offset) { - case ex: *ast::expr => + case let ex: *ast::expr => yield match (store.resolve) { case null => return noresolver; - case res: *resolver => + case let res: *resolver => yield res(store.rstate, store, ex)?; }; case null => @@ -380,11 +380,11 @@ fn _struct_from_ast( }; const memb = match (membs[i].member) { - case se: ast::struct_embedded => + case let se: ast::struct_embedded => let membs: []ast::struct_member = match (se.repr) { - case st: ast::struct_type => + case let st: ast::struct_type => yield st; - case ut: ast::union_type => + case let ut: ast::union_type => yield ut; case => abort(); // Invariant @@ -393,9 +393,9 @@ fn _struct_from_ast( se.repr is ast::union_type, fields, offs)?; continue; - case se: ast::struct_alias => + case let se: ast::struct_alias => abort(); // TODO - case sf: ast::struct_field => + case let sf: ast::struct_field => yield sf; }; @@ -447,7 +447,7 @@ fn tagged_collect( types: *[]const *_type, ) (void | deferred | error) = { for (let i = 0z; i < len(atype); i += 1) match (atype[i].repr) { - case ta: ast::tagged_type => + case let ta: ast::tagged_type => tagged_collect(store, ta, types)?; case => append(types, lookup(store, atype[i])?); @@ -509,21 +509,21 @@ fn field_cmp(a: const *void, b: const *void) int = { fn type_finish(t: *_type) void = { match (t.repr) { - case a: alias => + case let a: alias => ast::ident_free(a.id); case array => void; case builtin => void; - case e: _enum => + case let e: _enum => free(e.values); - case f: func => + case let f: func => free(f.params); case pointer => void; - case s: slice => void; - case st: _struct => + case let s: slice => void; + case let st: _struct => free(st.fields); - case tu: tuple => + case let tu: tuple => free(tu); - case ta: tagged => + case let ta: tagged => free(ta); }; }; diff --git a/hare/unit/process.ha b/hare/unit/process.ha @@ -13,7 +13,7 @@ fn process(ctx: *context, subunits: const []ast::subunit) (unit | error) = { for (let j = 0z; j < len(subunit.decls); j += 1) { let adecl = &subunit.decls[j]; let decl = match (process_decl(ctx, adecl)) { - case d: decl => + case let d: decl => yield d; case error => abort(); // TODO @@ -31,13 +31,13 @@ fn process_decl( ) (decl | error) = { // TODO: match on &decl.decl match (decl.decl) { - case co: []ast::decl_const => + case let co: []ast::decl_const => abort(); // TODO - case gl: []ast::decl_global => + case let gl: []ast::decl_global => abort(); // TODO - case ty: []ast::decl_type => + case let ty: []ast::decl_type => abort(); // TODO - case fu: ast::decl_func => + case let fu: ast::decl_func => return process_func(ctx, decl, fu); }; }; @@ -56,7 +56,7 @@ fn process_func( ctx.fntype = &fntype; const body: nullable *expr = match (afndecl.body) { - case abody: ast::expr => + case let abody: ast::expr => yield process_expr(ctx, &abody)?; case void => yield null; @@ -142,19 +142,19 @@ fn process_expr( fn process_access(ctx: *context, aexpr: *ast::expr) (*expr | error) = { const access = aexpr.expr as ast::access_expr; const op: (const *types::_type, access) = match (access) { - case ai: ast::access_identifier => + case let ai: ast::access_identifier => const object = match (ctx_lookup(ctx, ai)) { case null => abort(); // TODO: Error - case obj: *object => + case let obj: *object => yield obj; }; yield (object._type, object); - case ai: ast::access_index => + case let ai: ast::access_index => abort(); // TODO - case af: ast::access_field => + case let af: ast::access_field => abort(); // TODO - case at: ast::access_tuple => + case let at: ast::access_tuple => abort(); // TODO }; return alloc(expr { @@ -197,7 +197,7 @@ fn process_binding(ctx: *context, aexpr: *ast::expr) (*expr | error) = { const _type = match (item._type) { case null => abort(); // TODO - case ty: *ast::_type => + case let ty: *ast::_type => yield types::lookup(ctx.store, ty)!; }; const object = scope_insert(ctx, object { @@ -264,23 +264,23 @@ fn process_constant(ctx: *context, aexpr: *ast::expr) (*expr | error) = { const constexpr = aexpr.expr as ast::constant_expr; // TODO: Tuple unpacking const er: (const *types::_type, constant) = match (constexpr) { - case v: ast::value => + case let v: ast::value => yield ( // TODO: iconst/fconst lowering types::lookup_builtin(ctx.store, match (v) { case ast::_null => yield ast::builtin_type::NULL; - case b: bool => + case let b: bool => yield ast::builtin_type::BOOL; - case s: str => + case let s: str => yield ast::builtin_type::STR; - case r: rune => + case let r: rune => yield ast::builtin_type::RUNE; - case i: i64 => + case let i: i64 => yield ast::builtin_type::INT; - case u: u64 => + case let u: u64 => yield ast::builtin_type::UINT; - case f: f64 => + case let f: f64 => yield ast::builtin_type::F64; case void => yield ast::builtin_type::VOID; @@ -348,15 +348,15 @@ fn process_constant(ctx: *context, aexpr: *ast::expr) (*expr | error) = { assert(expr.result.repr as types::builtin == _case.1); const constexpr = expr.expr as constant; match (_case.2) { - case s: str => + case let s: str => assert(constexpr as str == s); - case r: rune => + case let r: rune => assert(constexpr as rune == r); - case i: i64 => + case let i: i64 => assert(constexpr as i64 == i); - case u: u64 => + case let u: u64 => assert(constexpr as u64 == u); - case f: f64 => + case let f: f64 => assert(constexpr as f64 == f); case void => abort(); @@ -369,7 +369,7 @@ fn process_return(ctx: *context, aexpr: *ast::expr) (*expr | error) = { const rval = match (ret) { case null => yield null; - case aexpr: *ast::expr => + case let aexpr: *ast::expr => yield process_expr(ctx, aexpr)?; }; // TODO: assert(types::assignable(ctx.fntype.result, rval.type)); diff --git a/hare/unit/scan.ha b/hare/unit/scan.ha @@ -29,13 +29,13 @@ fn scan_decl( ) (void | types::deferred | error) = { // TODO: match on &decl.decl match (decl.decl) { - case co: []ast::decl_const => + case let co: []ast::decl_const => abort(); // TODO - case gl: []ast::decl_global => + case let gl: []ast::decl_global => abort(); // TODO - case ty: []ast::decl_type => + case let ty: []ast::decl_type => abort(); // TODO - case fu: ast::decl_func => + case let fu: ast::decl_func => return scan_func(ctx, decl, fu); }; }; @@ -47,11 +47,11 @@ fn scan_func( ) (void | types::deferred | error) = { assert(func.attrs & ast::fndecl_attrs::TEST == 0); // TODO const fntype = match (types::lookup(ctx.store, &func.prototype)) { - case err: types::error => + case let err: types::error => return err; case types::deferred => return types::deferred; - case fntype: const *types::_type => + case let fntype: const *types::_type => yield fntype; }; scope_insert(ctx, object { diff --git a/hare/unit/scope.ha b/hare/unit/scope.ha @@ -100,7 +100,7 @@ fn scope_lookup(scope: *scope, ident: ast::ident) nullable *object = { match (scope.parent) { case null => return null; - case scope: *scope => + case let scope: *scope => return scope_lookup(scope, ident); }; }; diff --git a/hare/unparse/decl.ha b/hare/unparse/decl.ha @@ -10,7 +10,7 @@ export fn decl(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, "export ")?; }; match (d.decl) { - case c: []ast::decl_const => + case let c: []ast::decl_const => n += fmt::fprint(out, "def ")?; for (let i = 0z; i < len(c); i += 1) { n += ident(out, c[i].ident)?; @@ -22,7 +22,7 @@ export fn decl(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case g: []ast::decl_global => + case let g: []ast::decl_global => n += fmt::fprint(out, if (g[0].is_const) "const " else "let ")?; for (let i = 0z; i < len(g); i += 1) { @@ -35,7 +35,7 @@ export fn decl(out: io::handle, d: ast::decl) (size | io::error) = { n += _type(out, 0, g[i]._type)?; match (g[i].init) { case null => void; - case ex: *ast::expr => + case let ex: *ast::expr => n += fmt::fprint(out, " = ")?; n += expr(out, 0, *ex)?; }; @@ -43,7 +43,7 @@ export fn decl(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case t: []ast::decl_type => + case let t: []ast::decl_type => n += fmt::fprint(out, "type ")?; for (let i = 0z; i < len(t); i += 1) { n += ident(out, t[i].ident)?; @@ -53,7 +53,7 @@ export fn decl(out: io::handle, d: ast::decl) (size | io::error) = { n += fmt::fprint(out, ", ")?; }; }; - case f: ast::decl_func => + case let f: ast::decl_func => n += fmt::fprint(out, switch (f.attrs) { case ast::fndecl_attrs::NONE => yield ""; @@ -78,7 +78,7 @@ export fn decl(out: io::handle, d: ast::decl) (size | io::error) = { n += prototype(out, 0, fntype)?; match (f.body) { case void => void; - case e: ast::expr => + case let e: ast::expr => n += fmt::fprint(out, " = ")?; n += expr(out, 0, e)?; }; diff --git a/hare/unparse/expr.ha b/hare/unparse/expr.ha @@ -14,38 +14,38 @@ export fn expr( e: ast::expr ) (size | io::error) = { match (e.expr) { - case e: ast::access_expr => + case let e: ast::access_expr => match (e) { - case id: ast::access_identifier => + case let id: ast::access_identifier => return ident(out, id); - case ix: ast::access_index => + case let ix: ast::access_index => let z = expr(out, indent, *ix.object)?; z += fmt::fprintf(out, "[")?; z += expr(out, indent, *ix.index)?; z += fmt::fprintf(out, "]")?; return z; - case fi: ast::access_field => + case let fi: ast::access_field => let z = expr(out, indent, *fi.object)?; z += fmt::fprintf(out, ".{}", fi.field)?; return z; - case tp: ast::access_tuple => + case let tp: ast::access_tuple => let z = expr(out, indent, *tp.object)?; z += fmt::fprintf(out, ".")?; z += expr(out, indent, *tp.value)?; return z; }; - case e: ast::alloc_expr => + case let e: ast::alloc_expr => let z = fmt::fprint(out, "alloc(")?; z += expr(out, indent, *e.init)?; match (e.capacity) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => z += fmt::fprint(out, ", ")?; z += expr(out, indent, *e)?; }; z += fmt::fprint(out, ")")?; return z; - case e: ast::append_expr => + case let e: ast::append_expr => let z = if (e.is_static) fmt::fprint(out, "static ")? else 0z; z += fmt::fprint(out, "append(")?; z += expr(out, indent, *e.object)?; @@ -59,7 +59,7 @@ export fn expr( }; match (e.variadic) { case null => void; - case v: *ast::expr => + case let v: *ast::expr => if (len(e.values) != 0) { z += fmt::fprint(out, ", ")?; }; @@ -68,19 +68,19 @@ export fn expr( }; z += fmt::fprint(out, ")")?; return z; - case e: ast::assert_expr => + case let e: ast::assert_expr => let z = fmt::fprint( out, if (e.is_static) "static " else "")?; // assert without a condition = abort z += match (e.cond) { - case e: *ast::expr => + case let e: *ast::expr => yield fmt::fprint(out, "assert(")? + expr(out, indent, *e)?; case null => yield fmt::fprint(out, "abort(")?; }; z += match (e.message) { - case m: *ast::expr => + case let m: *ast::expr => let z = 0z; match (e.cond) { case null => void; @@ -94,7 +94,7 @@ export fn expr( }; z += fmt::fprint(out, ")")?; return z; - case e: ast::assign_expr => + case let e: ast::assign_expr => let z = 0z; if (e.indirect) { z += fmt::fprint(out, "*")?; @@ -103,7 +103,7 @@ export fn expr( const op = match (e.op) { case void => yield "="; - case op: ast::binarithm_op => + case let op: ast::binarithm_op => yield switch (op) { case ast::binarithm_op::BAND => yield "&="; @@ -136,7 +136,7 @@ export fn expr( z += fmt::fprintf(out, " {} ", op)?; z += expr(out, indent, *e.value)?; return z; - case e: ast::binarithm_expr => + case let e: ast::binarithm_expr => let z = expr(out, indent, *e.lvalue)?; z += fmt::fprintf(out, " {} ", switch (e.op) { case ast::binarithm_op::BAND => @@ -180,7 +180,7 @@ export fn expr( })?; z += expr(out, indent, *e.rvalue)?; return z; - case e: ast::binding_expr => + case let e: ast::binding_expr => let z = fmt::fprintf(out, "{}{}", if (e.is_static) "static " else "", if (e.is_const) "const " else "let ")?; @@ -189,7 +189,7 @@ export fn expr( z += match (binding._type) { case null => yield fmt::fprint(out, binding.name)?; - case t: *ast::_type => + case let t: *ast::_type => let z = 0z; z += fmt::fprintf(out, "{}: ", binding.name)?; @@ -203,13 +203,13 @@ export fn expr( }; }; return z; - case e: ast::break_expr => + case let e: ast::break_expr => let z = fmt::fprint(out, "break")?; if (e != "") { z += fmt::fprintf(out, " :{}", e)?; }; return z; - case e: ast::call_expr => + case let e: ast::call_expr => let z = expr(out, indent, *e.lvalue)?; z += fmt::fprintf(out, "(")?; for (let i = 0z; i < len(e.args); i += 1) { @@ -223,7 +223,7 @@ export fn expr( }; z += fmt::fprintf(out, ")")?; return z; - case e: ast::cast_expr => + case let e: ast::cast_expr => let z = expr(out, indent, *e.value)?; const op = switch (e.kind) { case ast::cast_kind::CAST => @@ -236,41 +236,41 @@ export fn expr( z += fmt::fprintf(out, "{}", op)?; z += _type(out, indent, *e._type)?; return z; - case e: ast::constant_expr => + case let e: ast::constant_expr => return constant(out, indent, e)?; - case e: ast::continue_expr => + case let e: ast::continue_expr => let z = fmt::fprint(out, "continue")?; if (e != "") { z += fmt::fprintf(out, " :{}", e)?; }; return z; - case e: ast::defer_expr => + case let e: ast::defer_expr => return fmt::fprint(out, "defer ")? + expr(out, indent, *e)?; - case e: ast::delete_expr => + case let e: ast::delete_expr => let z = if (e.is_static) fmt::fprint(out, "static ")? else 0z; z += fmt::fprint(out, "delete(")?; z += expr(out, indent, *e.object)?; z += fmt::fprint(out, ")")?; return z; - case e: ast::for_expr => + case let e: ast::for_expr => return for_expr(out, indent, e)?; - case e: ast::free_expr => + case let e: ast::free_expr => return fmt::fprint(out, "free(")? + expr(out, indent, *e)? + fmt::fprint(out, ")")?; - case e: ast::if_expr => + case let e: ast::if_expr => let z = fmt::fprint(out, "if (")?; z += expr(out, indent, *e.cond)?; z += fmt::fprint(out, ") ")?; z += expr(out, indent, *e.tbranch)?; match (e.fbranch) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => z += fmt::fprint(out, " else ")?; z += expr(out, indent, *e)?; }; return z; - case e: ast::insert_expr => + case let e: ast::insert_expr => let z = if (e.is_static) fmt::fprint(out, "static ")? else 0z; z += fmt::fprint(out, "insert(")?; z += expr(out, indent, *e.object)?; @@ -284,7 +284,7 @@ export fn expr( }; match (e.variadic) { case null => void; - case v: *ast::expr => + case let v: *ast::expr => if (len(e.values) != 0) { z += fmt::fprint(out, ", ")?; }; @@ -293,7 +293,7 @@ export fn expr( }; z += fmt::fprint(out, ")")?; return z; - case e: ast::compound_expr => + case let e: ast::compound_expr => let z = 0z; if (e.label != "") { z += fmt::fprintf(out, ":{} ", e.label)?; @@ -307,55 +307,55 @@ export fn expr( z += newline(out, indent)?; z += fmt::fprintf(out, "}}")?; return z; - case e: ast::match_expr => + case let e: ast::match_expr => return match_expr(out, indent, e)?; - case e: ast::len_expr => + case let e: ast::len_expr => let z = fmt::fprint(out, "len(")?; z += expr(out, indent, *e)?; z += fmt::fprint(out, ")")?; return z; - case e: ast::size_expr => + case let e: ast::size_expr => let z = fmt::fprint(out, "size(")?; z += _type(out, indent, *e)?; z += fmt::fprint(out, ")")?; return z; - case e: ast::offset_expr => + case let e: ast::offset_expr => let z = fmt::fprint(out, "offset(")?; z += expr(out, indent, *e)?; z += fmt::fprint(out, ")")?; return z; - case e: ast::propagate_expr => + case let e: ast::propagate_expr => let z = expr(out, indent, *e.expr)?; z += fmt::fprintf(out, if (e.is_abort) "!" else "?")?; return z; - case e: ast::return_expr => + case let e: ast::return_expr => let z = fmt::fprint(out, "return")?; match (e) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => z += fmt::fprint(out, " ")?; z += expr(out, indent, *e)?; }; return z; - case e: ast::slice_expr => + case let e: ast::slice_expr => let z = expr(out, indent, *e.object)?; z += fmt::fprint(out, "[")?; match (e.start) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => z += expr(out, indent, *e)?; }; z += fmt::fprint(out, "..")?; match (e.end) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => z += expr(out, indent, *e)?; }; z += fmt::fprint(out, "]")?; return z; - case e: ast::switch_expr => + case let e: ast::switch_expr => return switch_expr(out, indent, e)?; - case e: ast::unarithm_expr => + case let e: ast::unarithm_expr => let z = fmt::fprintf(out, "{}", switch (e.op) { case ast::unarithm_op::ADDR => yield "&"; @@ -372,14 +372,14 @@ export fn expr( })?; z += expr(out, indent, *e.operand)?; return z; - case e: ast::yield_expr => + case let e: ast::yield_expr => let z = fmt::fprint(out, "yield")?; if (e.label != "") { z += fmt::fprintf(out, " :{}", e.label)?; }; match (e.value) { case null => void; - case v: *ast::expr => + case let v: *ast::expr => z += fmt::fprint(out, if (e.label == "") " " else ", ")?; z += expr(out, indent, *v)?; @@ -396,22 +396,22 @@ fn constant( match (e) { case void => return fmt::fprint(out, "void"); - case v: ast::value => + case let v: ast::value => return fmt::fprint(out, match (v) { case void => abort(); case ast::_null => yield "null"; - case v: (i64 | u64 | f64) => + case let v: (i64 | u64 | f64) => yield v; - case b: bool => + case let b: bool => return fmt::fprint(out, b); // TODO: Escape these: - case s: str => + case let s: str => return fmt::fprintf(out, "\"{}\"", s); - case r: rune => + case let r: rune => return fmt::fprintf(out, "'{}'", r); }); - case ac: ast::array_constant => + case let ac: ast::array_constant => let z = fmt::fprint(out, "[")?; for (let i = 0z; i < len(ac.values); i += 1) { z += expr(out, indent, *ac.values[i])?; @@ -422,9 +422,9 @@ fn constant( z += fmt::fprintf(out, "{}]", if (ac.expand) "..." else "")?; return z; - case sc: ast::struct_constant => + case let sc: ast::struct_constant => return struct_constant(out, indent, sc)?; - case tu: ast::tuple_constant => + case let tu: ast::tuple_constant => let z = fmt::fprint(out, "(")?; for (let i = 0z; i < len(tu); i += 1) { z += expr(out, indent, *tu[i])?; @@ -453,17 +453,17 @@ fn struct_constant( for (let i = 0z; i < len(sc.fields); i += 1) { newline(out, indent)?; match (sc.fields[i]) { - case sv: ast::struct_value => + case let sv: ast::struct_value => match (sv._type) { case null => z += fmt::fprintf(out, "{}", sv.name)?; - case t: *ast::_type => + case let t: *ast::_type => z += fmt::fprintf(out, "{}: ", sv.name)?; z += _type(out, indent, *t)?; }; z += fmt::fprint(out, " = ")?; z += expr(out, indent, *sv.init)?; - case sc: *ast::struct_constant => + case let sc: *ast::struct_constant => z += constant(out, indent, *sc)?; }; z += fmt::fprint(out, ",")?; @@ -486,7 +486,7 @@ fn for_expr( let z = fmt::fprintf(out, "for (")?; match (e.bindings) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => z += expr(out, indent, *e)?; z += fmt::fprint(out, "; ")?; }; @@ -495,7 +495,7 @@ fn for_expr( match (e.afterthought) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => z += fmt::fprint(out, "; ")?; z += expr(out, indent, *e)?; }; @@ -554,12 +554,20 @@ fn match_expr( for (let i = 0z; i < len(e.cases); i += 1) { z += newline(out, indent)?; - z += fmt::fprint(out, "case ")?; + z += fmt::fprint(out, "case")?; const item = e.cases[i]; if (len(item.name) > 0) { - z += fmt::fprintf(out, "{}: ", item.name)?; + z += fmt::fprintf(out, " let {}", item.name)?; + }; + match (item._type) { + case let typ: *ast::_type => + if (len(item.name) > 0) { + z += fmt::fprint(out, ":")?; + }; + z += fmt::fprint(out, " ")?; + z += _type(out, indent, *typ)?; + case null => void; }; - z += _type(out, indent, *item._type)?; z += fmt::fprint(out, " =>")?; for (let i = 0z; i < len(item.exprs); i += 1) { z += newline(out, indent + 1)?; diff --git a/hare/unparse/import.ha b/hare/unparse/import.ha @@ -8,12 +8,12 @@ export fn import(out: io::handle, i: ast::import) (size | io::error) = { let n = 0z; n += fmt::fprint(out, "use ")?; match (i) { - case m: ast::import_module => + case let m: ast::import_module => n += ident(out, m)?; - case a: ast::import_alias => + case let a: ast::import_alias => n += fmt::fprint(out, a.alias, "= ")?; n += ident(out, a.ident)?; - case o: ast::import_objects => + case let o: ast::import_objects => n += ident(out, o.ident)?; n += fmt::fprint(out, "::{")?; for (let i = 0z; i < len(o.objects); i += 1) { diff --git a/hare/unparse/type.ha b/hare/unparse/type.ha @@ -87,10 +87,10 @@ fn struct_union_type( ) (size | io::error) = { let z = 0z; let membs = match (t.repr) { - case st: ast::struct_type => + case let st: ast::struct_type => z += fmt::fprint(out, "struct {")?; yield st: []ast::struct_member; - case ut: ast::union_type => + case let ut: ast::union_type => z += fmt::fprint(out, "union {")?; yield ut: []ast::struct_member; }; @@ -101,18 +101,18 @@ fn struct_union_type( match (membs[i]._offset) { case null => void; - case ex: *ast::expr => + case let ex: *ast::expr => z += fmt::fprint(out, "@offset(")?; z += expr(out, indent, *ex)?; z += fmt::fprint(out, ") ")?; }; match (membs[i].member) { - case se: ast::struct_embedded => + case let se: ast::struct_embedded => z += _type(out, indent, *se)?; - case sa: ast::struct_alias => + case let sa: ast::struct_alias => z += ident(out, sa)?; - case sf: ast::struct_field => + case let sf: ast::struct_field => z += fmt::fprintf(out, "{}: ", sf.name)?; z += _type(out, indent, *sf._type)?; }; @@ -141,14 +141,14 @@ export fn _type( n += fmt::fprint(out, "!")?; }; match (t.repr) { - case a: ast::alias_type => + case let a: ast::alias_type => if (a.unwrap) { n += fmt::fprint(out, "...")?; }; n += ident(out, a.ident)?; - case b: ast::builtin_type => + case let b: ast::builtin_type => n += fmt::fprint(out, builtin_type(b))?; - case e: ast::enum_type => + case let e: ast::enum_type => if (e.storage != ast::builtin_type::INT) { n += fmt::fprint(out, "enum", builtin_type(e.storage), "{")?; @@ -162,7 +162,7 @@ export fn _type( n += fmt::fprint(out, value.name)?; match (value.value) { case null => void; - case e: *ast::expr => + case let e: *ast::expr => n += fmt::fprint(out, " = ")?; n += expr(out, indent, *e)?; }; @@ -171,13 +171,13 @@ export fn _type( indent -= 1; n += newline(out, indent)?; n += fmt::fprint(out, "}")?; - case f: ast::func_type => + case let f: ast::func_type => if (f.attrs & ast::func_attrs::NORETURN != 0) { n += fmt::fprint(out, "@noreturn ")?; }; n += fmt::fprint(out, "fn")?; n += prototype(out, indent, f)?; - case l: ast::list_type => + case let l: ast::list_type => n += fmt::fprint(out, "[")?; match (l.length) { case ast::len_slice => void; @@ -185,12 +185,12 @@ export fn _type( n += fmt::fprint(out, "*")?; case ast::len_contextual => n += fmt::fprint(out, "_")?; - case e: *ast::expr => + case let e: *ast::expr => n += expr(out, indent, *e)?; }; n += fmt::fprint(out, "]")?; n += _type(out, indent, *l.members)?; - case p: ast::pointer_type => + case let p: ast::pointer_type => if (p.flags & ast::pointer_flags::NULLABLE != 0) { n += fmt::fprint(out, "nullable ")?; }; @@ -200,7 +200,7 @@ export fn _type( n += struct_union_type(out, indent, t)?; case ast::union_type => n += struct_union_type(out, indent, t)?; - case t: ast::tagged_type => + case let t: ast::tagged_type => n += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { n += _type(out, indent, *t[i])?; @@ -209,7 +209,7 @@ export fn _type( }; }; n += fmt::fprint(out, ")")?; - case t: ast::tuple_type => + case let t: ast::tuple_type => n += fmt::fprint(out, "(")?; for (let i = 0z; i < len(t); i += 1) { n += _type(out, indent, *t[i])?; diff --git a/io/+freebsd/file.ha b/io/+freebsd/file.ha @@ -16,9 +16,9 @@ export fn fdopen(fd: int) file = fd; fn fd_read(fd: file, buf: []u8) (size | EOF | error) = { match (rt::read(fd, buf: *[*]u8, len(buf))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => switch (n) { case 0 => return EOF; @@ -30,9 +30,9 @@ fn fd_read(fd: file, buf: []u8) (size | EOF | error) = { fn fd_write(fd: file, buf: const []u8) (size | error) = { match (rt::write(fd, buf: *const [*]u8, len(buf))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => return n; }; }; @@ -45,9 +45,9 @@ fn fd_seek( whence: whence, ) (off | error) = { match (rt::lseek(fd, off: i64, whence: uint)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: i64 => + case let n: i64 => return n: off; }; }; diff --git a/io/+freebsd/mmap.ha b/io/+freebsd/mmap.ha @@ -39,9 +39,9 @@ export fn mmap( offs: size ) (*void | errors::error) = { match (rt::mmap(addr, length, prot, flags, fd, offs)) { - case ptr: *void => + case let ptr: *void => return ptr; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -51,7 +51,7 @@ export fn munmap(addr: *void, length: size) (void | errors::error) = { match (rt::munmap(addr, length)) { case void => return; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; diff --git a/io/+linux/file.ha b/io/+linux/file.ha @@ -16,9 +16,9 @@ export fn fdopen(fd: int) file = fd; fn fd_read(fd: file, buf: []u8) (size | EOF | error) = { match (rt::read(fd, buf: *[*]u8, len(buf))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => switch (n) { case 0 => return EOF; @@ -30,9 +30,9 @@ fn fd_read(fd: file, buf: []u8) (size | EOF | error) = { fn fd_write(fd: file, buf: const []u8) (size | error) = { match (rt::write(fd, buf: *const [*]u8, len(buf))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => return n; }; }; @@ -45,9 +45,9 @@ fn fd_seek( whence: whence, ) (off | error) = { match (rt::lseek(fd, off: i64, whence: uint)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: i64 => + case let n: i64 => return n: off; }; }; @@ -58,7 +58,7 @@ fn fd_copy(to: file, from: file) (size | error) = { let sum = 0z; for (true) { let n = match (rt::sendfile(to, from, null, SENDFILE_MAX)) { - case err: rt::errno => + case let err: rt::errno => switch (err) { case rt::EINVAL => if (sum == 0) { @@ -68,7 +68,7 @@ fn fd_copy(to: file, from: file) (size | error) = { case => return errors::errno(err); }; - case n: size => + case let n: size => yield switch (n) { case 0 => break; diff --git a/io/+linux/mmap.ha b/io/+linux/mmap.ha @@ -59,9 +59,9 @@ export fn mmap( offs: size ) (*void | errors::error) = { match (rt::mmap(addr, length, prot, flags, fd, offs)) { - case ptr: *void => + case let ptr: *void => return ptr; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -71,7 +71,7 @@ export fn munmap(addr: *void, length: size) (void | errors::error) = { match (rt::munmap(addr, length)) { case void => return; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; diff --git a/io/+test/copy.ha b/io/+test/copy.ha @@ -32,7 +32,7 @@ fn test_copy_unsupported(a: *stream, b: *stream) (size | error) = @test fn copy() void = { let a = test_copier_open(), b = test_copier_open(); match (copy(&b, &a)) { - case n: size => + case let n: size => assert(n == 42); assert(a.r == 42); assert(b.w == 42); @@ -47,7 +47,7 @@ fn test_copy_unsupported(a: *stream, b: *stream) (size | error) = a.copier = &test_copier_copy; b.copier = &test_copier_copy; match (copy(&b, &a)) { - case n: size => + case let n: size => assert(n == 1337); assert(b.w == 62893); case error => @@ -62,7 +62,7 @@ fn test_copy_unsupported(a: *stream, b: *stream) (size | error) = a.copier = &test_copy_unsupported; b.copier = &test_copy_unsupported; match (copy(&b, &a)) { - case n: size => + case let n: size => assert(n == 42); assert(a.r == 42); assert(b.w == 42); @@ -77,7 +77,7 @@ fn test_copy_unsupported(a: *stream, b: *stream) (size | error) = b.copier = &test_copy_unsupported; b.writer = &teststream_write_short; match (copy(&b, &a)) { - case n: size => + case let n: size => assert(n == 42); assert(a.r == 42); assert(a.nreads == 1); diff --git a/io/+test/limit.ha b/io/+test/limit.ha @@ -11,13 +11,13 @@ use errors; abort(); }; match (read(&rlimit, buf)) { - case n: size => + case let n: size => assert(n == 15); case error => abort(); }; match (read(&rlimit, buf)) { - case n: size => + case let n: size => assert(n == 5); case error => abort(); @@ -30,13 +30,13 @@ use errors; abort(); }; match (write(&wlimit, buf)) { - case n: size => + case let n: size => assert(n == 15); case error => abort(); }; match (write(&wlimit, buf)) { - case n: size => + case let n: size => assert(n == 5); case error => abort(); diff --git a/io/copy.ha b/io/copy.ha @@ -4,12 +4,12 @@ use errors; // return if the source handle is infinite. export fn copy(dest: handle, src: handle) (error | size) = { match (dest) { - case fd: file => + case let fd: file => if (src is file) { return fd_copy(fd, src as file); }; return copy_fallback(dest, src); - case st: *stream => + case let st: *stream => if (!(src is *stream)) { return copy_fallback(dest, src); }; @@ -20,15 +20,15 @@ export fn copy(dest: handle, src: handle) (error | size) = { fn copy_streams(dest: *stream, src: *stream) (error | size) = { match (dest.copier) { case null => void; - case c: *copier => + case let c: *copier => match (c(dest, src)) { - case err: error => + case let err: error => match (err) { case errors::unsupported => void; case => return err; }; - case s: size => + case let s: size => return s; }; }; @@ -40,7 +40,7 @@ fn copy_fallback(dest: handle, src: handle) (error | size) = { static let buf: [4096]u8 = [0...]; for (true) { match (read(src, buf[..])?) { - case n: size => + case let n: size => for (let i = 0z; i < n) { let r = write(dest, buf[i..n])?; w += r; diff --git a/io/drain.ha b/io/drain.ha @@ -4,7 +4,7 @@ export fn drain(in: io::handle) ([]u8 | io::error) = { static let buf: [4096]u8 = [0...]; for (true) { match (read(in, buf[..])?) { - case n: size => + case let n: size => append(sink, buf[..n]...); case EOF => break; diff --git a/io/handle.ha b/io/handle.ha @@ -12,9 +12,9 @@ export type handle = (file | *stream); // the number of bytes read. export fn read(h: handle, buf: []u8) (size | EOF | error) = { match (h) { - case fd: file => + case let fd: file => return fd_read(fd, buf); - case st: *stream => + case let st: *stream => return st_read(st, buf); }; }; @@ -23,10 +23,12 @@ export fn read(h: handle, buf: []u8) (size | EOF | error) = { // returning the number of bytes written. export fn write(h: handle, buf: const []u8) (size | error) = { match (h) { - case fd: file => + case let fd: file => return fd_write(fd, buf); - case st: *stream => + case let st: *stream => return st_write(st, buf); + case => + abort(); }; }; @@ -34,9 +36,9 @@ export fn write(h: handle, buf: const []u8) (size | error) = { // after calling this function. export fn close(h: handle) void = { match (h) { - case fd: file => + case let fd: file => fd_close(fd); - case st: *stream => + case let st: *stream => st_close(st); }; }; @@ -44,9 +46,9 @@ export fn close(h: handle) void = { // Sets the offset within a [[handle]]. export fn seek(h: handle, off: off, w: whence) (off | error) = { match (h) { - case fd: file => + case let fd: file => return fd_seek(fd, off, w); - case st: *stream => + case let st: *stream => return st_seek(st, off, w); }; }; diff --git a/io/stream.ha b/io/stream.ha @@ -35,7 +35,7 @@ fn st_read(s: *stream, buf: []u8) (size | EOF | error) = { match (s.reader) { case null => return errors::unsupported; - case r: *reader => + case let r: *reader => return r(s, buf); }; }; @@ -44,7 +44,7 @@ fn st_write(s: *stream, buf: const []u8) (size | error) = { match (s.writer) { case null => return errors::unsupported; - case w: *writer => + case let w: *writer => return w(s, buf); }; }; @@ -52,7 +52,7 @@ fn st_write(s: *stream, buf: const []u8) (size | error) = { fn st_close(s: *stream) void = { match (s.closer) { case null => void; - case c: *closer => + case let c: *closer => c(s); }; }; @@ -61,7 +61,7 @@ fn st_seek(s: *stream, off: off, w: whence) (off | error) = { match (s.seeker) { case null => return errors::unsupported; - case sk: *seeker => + case let sk: *seeker => return sk(s, off, w); }; }; diff --git a/io/tee.ha b/io/tee.ha @@ -21,7 +21,7 @@ fn tee_read(s: *stream, buf: []u8) (size | EOF | error) = { let z = match (read(s.source, buf)?) { case EOF => return EOF; - case z: size => + case let z: size => yield z; }; for (let n = 0z; n < z) { diff --git a/io/types.ha b/io/types.ha @@ -15,7 +15,7 @@ export fn strerror(err: error) str = { match (err) { case underread => return "Insufficient data to read entire item"; - case err: errors::error => + case let err: errors::error => return errors::strerror(err); }; }; diff --git a/io/util.ha b/io/util.ha @@ -9,7 +9,7 @@ export fn readitem(in: handle, item: *void, itemsz: size) (size | error) = { match (io::read(in, buf[..(itemsz - i)])) { case io::EOF => return underread; - case z: size => + case let z: size => i += z; }; }; diff --git a/iobus/io_uring/bus.ha b/iobus/io_uring/bus.ha @@ -13,9 +13,9 @@ const internal_sqe: int = 0; export fn new() (*bus | error) = { let params = io_uring::params { ... }; match (io_uring::setup(DEFAULT_RING_SIZE, &params)) { - case err: io_uring::error => + case let err: io_uring::error => return err: error; - case ring: io_uring::io_uring => + case let ring: io_uring::io_uring => return alloc(bus { uring = ring, ... @@ -81,17 +81,17 @@ export fn dispatch(bus: *bus) (result | error) = { fn _dispatch(bus: *bus) (result | error) = { match (io_uring::peek(&bus.uring)?) { case null => void; - case cqe: *io_uring::cqe => + case let cqe: *io_uring::cqe => return cqe: result; }; match (io_uring::submit_wait(&bus.uring, 1)) { - case err: io_uring::error => + case let err: io_uring::error => return err: error; case uint => void; }; match (io_uring::peek(&bus.uring)?) { case null => abort(); - case cqe: *io_uring::cqe => + case let cqe: *io_uring::cqe => return cqe: result; }; }; @@ -125,7 +125,7 @@ export fn register_file(bus: *bus, file: io::file) (registered_file | error) = { // Unregisters a file previously registered with [[register_file]]. export fn unregister_file(bus: *bus, file: file) void = { const reg = match (file) { - case reg: registered_file => + case let reg: registered_file => yield reg; case => abort("Cannot unregister non-registered file"); }; diff --git a/iobus/io_uring/handle.ha b/iobus/io_uring/handle.ha @@ -26,7 +26,7 @@ export fn handleof(res: result) *handle = { match (io_uring::get_user(res)) { case null => abort("I/O submission was prepared, but not enqueued. Did you pass it to iobus::enqueue or iobus::submit?"); - case v: *void => + case let v: *void => return v: *handle; }; }; diff --git a/iobus/io_uring/ops.ha b/iobus/io_uring/ops.ha @@ -11,7 +11,7 @@ fn getsqe(bus: *bus) (*io_uring::sqe | queuefull) = { match (io_uring::get_sqe(&bus.uring)) { case null => return queuefull; - case sqe: *io_uring::sqe => + case let sqe: *io_uring::sqe => return sqe; }; }; @@ -32,9 +32,9 @@ export fn read( let sqe = getsqe(bus)?; let flags = io_uring::flags::NONE; let fd = match (file) { - case file: io::file => + case let file: io::file => yield file: i32; - case file: registered_file => + case let file: registered_file => flags |= io_uring::flags::FIXED_FILE; yield file: i32; }; @@ -65,9 +65,9 @@ export fn write( let sqe = getsqe(bus)?; let flags = io_uring::flags::NONE; let fd = match (file) { - case file: io::file => + case let file: io::file => yield file: i32; - case file: registered_file => + case let file: registered_file => flags |= io_uring::flags::FIXED_FILE; yield file: i32; }; @@ -87,9 +87,9 @@ export fn close(bus: *bus, file: file) (handle | queuefull) = { let sqe = getsqe(bus)?; let flags = io_uring::flags::NONE; let fd = match (file) { - case file: io::file => + case let file: io::file => yield file: i32; - case file: registered_file => + case let file: registered_file => flags |= io_uring::flags::FIXED_FILE; yield file: i32; }; @@ -114,9 +114,9 @@ export fn accept(bus: *bus, file: file) (handle | queuefull) = { let sqe = getsqe(bus)?; let flags = io_uring::flags::NONE; let fd = match (file) { - case file: io::file => + case let file: io::file => yield file: i32; - case file: registered_file => + case let file: registered_file => flags |= io_uring::flags::FIXED_FILE; yield file: i32; }; @@ -142,10 +142,10 @@ export fn endaccept(res: result, opts: accept_opts...) (io::file | error) = { const file = cqe_result(res)?: io::file; for (let i = 0z; i < len(opts); i += 1) { match (opts[i]) { - case addr: *ip::addr => + case let addr: *ip::addr => let peer = ip::from_native(handle.accept.sockaddr); *addr = peer.0; - case port: *u16 => + case let port: *u16 => let peer = ip::from_native(handle.accept.sockaddr); *port = peer.1; }; @@ -163,9 +163,9 @@ export fn poll( let sqe = getsqe(bus)?; let flags = io_uring::flags::NONE; let fd = match (file) { - case file: io::file => + case let file: io::file => yield file: i32; - case file: registered_file => + case let file: registered_file => flags |= io_uring::flags::FIXED_FILE; yield file: i32; }; @@ -310,9 +310,9 @@ export fn recv( let sqe = getsqe(bus)?; let iflags = io_uring::flags::NONE; let fd = match (file) { - case file: io::file => + case let file: io::file => yield file: i32; - case file: registered_file => + case let file: registered_file => iflags |= io_uring::flags::FIXED_FILE; yield file: i32; }; @@ -336,9 +336,9 @@ export fn send( let sqe = getsqe(bus)?; let iflags = io_uring::flags::NONE; let fd = match (file) { - case file: io::file => + case let file: io::file => yield file: i32; - case file: registered_file => + case let file: registered_file => iflags |= io_uring::flags::FIXED_FILE; yield file: i32; }; diff --git a/iobus/io_uring/types.ha b/iobus/io_uring/types.ha @@ -15,7 +15,7 @@ export fn strerror(err: error) const str = { match (err) { case nobuffers => return "iobus buffer pool exhausted"; - case err: io_uring::error => + case let err: io_uring::error => return io_uring::strerror(err); }; }; @@ -31,9 +31,9 @@ fn wraperror(err: io_uring::error) error = { fn cqe_result(res: *io_uring::cqe) (int | error) = { match (io_uring::result(res)) { - case err: io_uring::error => + case let err: io_uring::error => return wraperror(err); - case n: int => + case let n: int => return n; }; }; diff --git a/linux/io_uring/cqe.ha b/linux/io_uring/cqe.ha @@ -14,9 +14,9 @@ export fn cqe_seen(ring: *io_uring, cqe: *cqe) void = cq_advance(ring, 1); // returned CQE to [[cqe_seen]] to advance the queue. export fn wait(ring: *io_uring) (*cqe | error) = { match (get_cqe(ring, 0, 1)) { - case err: error => + case let err: error => return err; - case cq: nullable *cqe => + case let cq: nullable *cqe => assert(cq != null); // XXX: Correct? return cq: *cqe; }; @@ -101,9 +101,9 @@ fn get_cqe( match (rt::io_uring_enter(ring.fd, submit, wait, flags: uint, null)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: uint => + case let n: uint => submit -= n; }; }; diff --git a/linux/io_uring/queue.ha b/linux/io_uring/queue.ha @@ -22,7 +22,7 @@ export fn must_get_sqe(ring: *io_uring) *sqe = { match (get_sqe(ring)) { case null => abort("I/O queue full"); - case sq: *sqe => + case let sq: *sqe => return sq; }; }; @@ -85,9 +85,9 @@ fn do_submit( if (needs_enter(ring, &flags) || wait != 0) { match (rt::io_uring_enter(ring.fd, submitted, wait, flags, null)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: uint => + case let n: uint => return n; }; } else { diff --git a/linux/io_uring/register.ha b/linux/io_uring/register.ha @@ -11,7 +11,7 @@ export fn register_buffers(ring: *io_uring, iov: []rt::iovec) (void | error) = { assert(len(iov) <= types::UINT_MAX); match (rt::io_uring_register(ring.fd, regop::REGISTER_BUFFERS, iov: *[*]rt::iovec, len(iov): uint)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -21,7 +21,7 @@ export fn register_buffers(ring: *io_uring, iov: []rt::iovec) (void | error) = { export fn unregister_buffers(ring: *io_uring) (void | error) = { match (rt::io_uring_register(ring.fd, regop::UNREGISTER_BUFFERS, null, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -34,7 +34,7 @@ export fn register_files(ring: *io_uring, files: []int) (void | error) = { assert(len(files) <= types::UINT_MAX); match (rt::io_uring_register(ring.fd, regop::REGISTER_FILES, files: *[*]int, len(files): uint)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -49,7 +49,7 @@ export fn register_files_update( assert(len(updates) <= types::UINT_MAX); match (rt::io_uring_register(ring.fd, regop::REGISTER_FILES_UPDATE, updates: *[*]files_update, len(updates): uint)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -59,7 +59,7 @@ export fn register_files_update( export fn unregister_files(ring: *io_uring) (void | error) = { match (rt::io_uring_register(ring.fd, regop::UNREGISTER_FILES, null, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -70,7 +70,7 @@ export fn unregister_files(ring: *io_uring) (void | error) = { export fn register_eventfd(ring: *io_uring, fd: int) (void | error) = { match (rt::io_uring_register(ring.fd, regop::REGISTER_EVENTFD, &fd, 1)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -81,7 +81,7 @@ export fn register_eventfd(ring: *io_uring, fd: int) (void | error) = { export fn register_eventfd_async(ring: *io_uring, fd: int) (void | error) = { match (rt::io_uring_register(ring.fd, regop::REGISTER_EVENTFD_ASYNC, &fd, 1)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -91,7 +91,7 @@ export fn register_eventfd_async(ring: *io_uring, fd: int) (void | error) = { export fn unregister_eventfd(ring: *io_uring) (void | error) = { match (rt::io_uring_register(ring.fd, regop::UNREGISTER_EVENTFD, null, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -116,7 +116,7 @@ export fn register_personality(ring: *io_uring) int = { regop::REGISTER_PERSONALITY, null, 0)) { case rt::errno => abort("Unexpected io_uring REGISTER_PERSONALITY error"); - case i: int => + case let i: int => return i; }; }; @@ -126,7 +126,7 @@ export fn register_personality(ring: *io_uring) int = { export fn unregister_personality(ring: *io_uring, id: int) (void | error) = { match (rt::io_uring_register(ring.fd, regop::UNREGISTER_PERSONALITY, null, id: uint)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -138,7 +138,7 @@ export fn unregister_personality(ring: *io_uring, id: int) (void | error) = { export fn register_enable_rings(ring: *io_uring) (void | error) = { match (rt::io_uring_register(ring.fd, regop::REGISTER_ENABLE_RINGS, null, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -152,7 +152,7 @@ export fn register_restrictions(ring: *io_uring, res: []restriction) (void | err assert(len(res) < types::UINT_MAX); match (rt::io_uring_register(ring.fd, regop::REGISTER_RESTRICTIONS, res: *[*]restriction, len(res): uint)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; diff --git a/linux/io_uring/setup.ha b/linux/io_uring/setup.ha @@ -6,9 +6,9 @@ use rt; // fields are initialized by the kernel. export fn setup(entries: u32, params: *params) (io_uring | error) = { const fd = match (rt::io_uring_setup(entries, params)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; @@ -36,9 +36,9 @@ export fn setup(entries: u32, params: *params) (io_uring | error) = { rt::PROT_READ | rt::PROT_WRITE, rt::MAP_SHARED | rt::MAP_POPULATE, fd, OFF_SQ_RING)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case ptr: *void => + case let ptr: *void => yield ptr; }; @@ -48,9 +48,9 @@ export fn setup(entries: u32, params: *params) (io_uring | error) = { rt::PROT_READ | rt::PROT_WRITE, rt::MAP_SHARED | rt::MAP_POPULATE, fd, OFF_CQ_RING)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case ptr: *void => + case let ptr: *void => yield ptr; }; @@ -67,9 +67,9 @@ export fn setup(entries: u32, params: *params) (io_uring | error) = { rt::PROT_READ | rt::PROT_WRITE, rt::MAP_SHARED | rt::MAP_POPULATE, fd, OFF_SQES)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case ptr: *void => + case let ptr: *void => yield ptr: *[*]sqe; }; diff --git a/linux/io_uring/uring.ha b/linux/io_uring/uring.ha @@ -12,7 +12,7 @@ export fn strerror(err: error) const str = { match (err) { case nobuffers => return "Buffer pool exhausted"; - case err: errors::error => + case let err: errors::error => return errors::strerror(err); }; }; diff --git a/linux/signalfd/signalfd.ha b/linux/signalfd/signalfd.ha @@ -37,9 +37,9 @@ export fn signalfd( flags: int, ) (int | errors::error) = { match (rt::signalfd(fd, mask, flags)) { - case fd: int => + case let fd: int => return fd; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -48,9 +48,9 @@ export fn signalfd( export fn readsignal(fd: int) (siginfo | errors::error) = { let si = siginfo { ... }; match (rt::read(fd, &si, size(siginfo))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case z: size => + case let z: size => assert(z == size(siginfo)); return si; }; diff --git a/linux/vdso/vdso.ha b/linux/vdso/vdso.ha @@ -41,7 +41,7 @@ fn get_vdso_ctx() nullable *vdso_ctx = { const eh = match (sys_infoehdr()) { case null => return null; - case x: *elf::header64 => + case let x: *elf::header64 => yield x; }; @@ -121,13 +121,13 @@ fn vdso_checkver(ctx: *vdso_ctx, version: str, num: u32) bool = { let cur = match (ctx.verdef) { case null => return true; - case vd: *elf::verdef64 => + case let vd: *elf::verdef64 => yield vd; }; const versym = match (ctx.versym) { case null => return true; - case vs: *[*]u16 => + case let vs: *[*]u16 => yield vs[num] & 0x7ff; }; for (cur != prev) { @@ -149,7 +149,7 @@ export fn getsym(symname: str, symver: str) nullable *void = { const ctx = match (get_vdso_ctx()) { case null => return null; - case x: *vdso_ctx => + case let x: *vdso_ctx => yield x; }; diff --git a/math/floats.ha b/math/floats.ha @@ -188,9 +188,9 @@ export fn isneginf(n: f64) bool = { // Returns true if the given floating-point number is normal. export fn isnormal(n: types::floating) bool = { match (n) { - case n: f32 => + case let n: f32 => return isnormalf32(n); - case n: f64 => + case let n: f64 => return isnormalf64(n); }; }; @@ -214,9 +214,9 @@ export fn isnormalf32(n: f32) bool = { // Returns true if the given floating-point number is subnormal. export fn issubnormal(n: types::floating) bool = { match (n) { - case n: f32 => + case let n: f32 => return issubnormalf32(n); - case n: f64 => + case let n: f64 => return issubnormalf64(n); }; }; @@ -300,9 +300,9 @@ export fn absf32(n: f32) f32 = { // Returns the absolute value of floating-point number n. export fn absf(n: types::floating) f64 = { match (n) { - case n: f64 => + case let n: f64 => return absf64(n); - case n: f32 => + case let n: f32 => return (absf32(n): f64); }; }; @@ -345,9 +345,9 @@ export fn signf32(x: f32) i64 = { // signed. export fn signf(x: types::floating) i64 = { match (x) { - case n: f64 => + case let n: f64 => return signf64(n); - case n: f32 => + case let n: f32 => return signf32(n); }; }; @@ -377,9 +377,9 @@ export fn ispositivef32(x: f32) bool = signf32(x) == 1i32; // Returns whether or not x is positive. export fn ispositive(x: types::floating) bool = { match (x) { - case n: f64 => + case let n: f64 => return ispositivef64(n); - case n: f32 => + case let n: f32 => return ispositivef32(n); }; }; @@ -393,9 +393,9 @@ export fn isnegativef32(x: f32) bool = signf32(x) == -1i32; // Returns whether or not x is negative. export fn isnegative(x: types::floating) bool = { match (x) { - case n: f64 => + case let n: f64 => return isnegativef64(n); - case n: f32 => + case let n: f32 => return isnegativef32(n); }; }; @@ -415,9 +415,9 @@ export fn copysignf32(x: f32, y: f32) f32 = { // Returns x, but with the sign of y. export fn copysign(x: types::floating, y: types::floating) f64 = { match (x) { - case n: f64 => + case let n: f64 => return copysignf64(n, (y: f64)); - case n: f32 => + case let n: f32 => return (copysignf32(n, (y: f32)): f64); }; }; @@ -507,9 +507,9 @@ export fn frexpf32(n: f32) (f64, i64) = { // between 0.5 and 1. export fn frexp(n: types::floating) (f64, i64) = { match (n) { - case n: f64 => + case let n: f64 => return frexpf64(n); - case n: f32 => + case let n: f32 => return frexpf32(n); }; }; diff --git a/math/ints.ha b/math/ints.ha @@ -39,13 +39,13 @@ export fn absi64(n: i64) i64 = { // Returns the absolute value of signed integer n. export fn absi(n: types::integer) i64 = { match (n) { - case n: i8 => + case let n: i8 => return (absi8(n): i64); - case n: i16 => + case let n: i16 => return (absi16(n): i64); - case n: i32 => + case let n: i32 => return (absi32(n): i64); - case n: i64 => + case let n: i64 => return (absi64(n): i64); }; }; @@ -116,13 +116,13 @@ export fn signi64(n: i64) i64 = { // Return 1 if n is positive, -1 if it's negative and 0 if it's 0. export fn signi(n: types::integer) i64 = { match (n) { - case n: i8 => + case let n: i8 => return (signi8(n): i64); - case n: i16 => + case let n: i16 => return (signi16(n): i64); - case n: i32 => + case let n: i32 => return (signi32(n): i64); - case n: i64 => + case let n: i64 => return (signi64(n): i64); }; }; diff --git a/math/math.ha b/math/math.ha @@ -71,9 +71,9 @@ export fn eqwithinf32(x: f32, y: f32, tol: f32) bool = { export fn eqwithin(x: types::floating, y: types::floating, tol: types::floating) bool = { match (x) { - case n: f64 => + case let n: f64 => return eqwithinf64(n, y as f64, tol as f64); - case n: f32 => + case let n: f32 => return eqwithinf32(n, y as f32, tol as f32); }; }; @@ -91,9 +91,9 @@ export fn isclosef32(x: f32, y: f32) bool = { // Returns whether x and y are within [[STANDARD_TOL]] of each other. export fn isclose(x: types::floating, y: types::floating) bool = { match (x) { - case n: f64 => + case let n: f64 => return isclosef64(n, y as f64); - case n: f32 => + case let n: f32 => return isclosef32(n, y as f32); }; }; diff --git a/net/+freebsd.ha b/net/+freebsd.ha @@ -25,9 +25,9 @@ export fn stream_accept(l: *listener) (io::file | error) = { let sn = rt::sockaddr {...}; const sz = size(rt::sockaddr): u32; const fd = match (rt::accept(l.fd, &sn, &sz)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; return io::fdopen(fd); diff --git a/net/+linux.ha b/net/+linux.ha @@ -25,9 +25,9 @@ export fn stream_accept(l: *listener) (io::file | error) = { let sn = rt::sockaddr {...}; const sz = size(rt::sockaddr): u32; const fd = match (rt::accept(l.fd, &sn, &sz)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; return io::fdopen(fd); diff --git a/net/dial/ip.ha b/net/dial/ip.ha @@ -12,9 +12,9 @@ fn dial_tcp(addr: str, service: str) (io::file | error) = { for (let i = 0z; i < len(addrs); i += 1) { const addr = addrs[i]; match (tcp::connect(addr, port)) { - case conn: io::file => + case let conn: io::file => return conn; - case err: net::error => + case let err: net::error => if (i + 1 >= len(addrs)) { return err; }; @@ -29,9 +29,9 @@ fn dial_udp(addr: str, service: str) (io::file | error) = { for (let i = 0z; i < len(addrs); i += 1) { const addr = addrs[i]; match (udp::connect(addr, port)) { - case sock: io::file => + case let sock: io::file => return sock; - case err: net::error => + case let err: net::error => if (i + 1 >= len(addrs)) { return err; }; diff --git a/net/dial/registry.ha b/net/dial/registry.ha @@ -22,9 +22,9 @@ export fn strerror(err: error) const str = { return "Attempted to dial an invalid address"; case unknown_service => return "Unknown service"; - case err: net::error => + case let err: net::error => return net::strerror(err); - case err: dns::error => + case let err: dns::error => return dns::strerror(err); }; }; diff --git a/net/dial/resolve.ha b/net/dial/resolve.ha @@ -18,16 +18,16 @@ export fn resolve( let port = match (strings::index(addr, ':')) { case void => yield match (strconv::stou16(service)) { - case u: u16 => + case let u: u16 => yield u; case => yield 0u16; }; - case i: size => + case let i: size => const sub = strings::sub(addr, i + 1, strings::end); addr = strings::sub(addr, 0, i); yield match (strconv::stou16(sub)) { - case u: u16 => + case let u: u16 => yield u; case => return invalid_address; @@ -39,7 +39,7 @@ export fn resolve( let addrs = resolve_addr(addr)?; if (port == 0) match (lookup_service(proto, service)) { - case p: u16 => + case let p: u16 => port = p; case void => void; }; @@ -60,7 +60,7 @@ export fn resolve( fn resolve_addr(addr: str) ([]ip::addr | error) = { match (ip::parse(addr)) { - case addr: ip::addr => + case let addr: ip::addr => // XXX: harec bug prevents just alloc'ing this let addrs: []ip::addr = []; append(addrs, addr); @@ -138,9 +138,9 @@ fn collect_answers(addrs: *[]ip::addr, answers: *[]dns::rrecord) void = { for (let i = 0z; i < len(answers); i += 1) { match (answers[i].rdata) { // XXX: harec bug prevents us from casting directly to ip::addr - case addr: dns::aaaa => + case let addr: dns::aaaa => append(addrs, addr: ip::addr6: ip::addr); - case addr: dns::a => + case let addr: dns::a => append(addrs, addr: ip::addr4: ip::addr); case => void; }; diff --git a/net/dns/error.ha b/net/dns/error.ha @@ -41,13 +41,13 @@ export fn strerror(err: error) const str = { return "The name server does not support the requested kind of query"; case refused => return "The name server refuses to perform the specified operation for policy reasons"; - case ue: unknown_error => + case let ue: unknown_error => return fmt::bsprintf(buf, "Unknown DNS error {}", ue: u8); case errors::overflow => return "The encoded message would exceed the buffer size"; case errors::timeout => return "The DNS request timed out"; - case err: net::error => + case let err: net::error => return net::strerror(err); }; }; diff --git a/net/dns/types.ha b/net/dns/types.ha @@ -194,9 +194,9 @@ fn bytes_free(in: [][]u8) void = { fn rrecord_finish(rr: *rrecord) void = { strings_free(rr.name); match (rr.rdata) { - case mx: mx => + case let mx: mx => strings_free(mx.name); - case tx: txt => + case let tx: txt => bytes_free(tx: [][]u8); case => void; }; diff --git a/net/errors.ha b/net/errors.ha @@ -12,7 +12,7 @@ export fn strerror(err: error) const str = { match (err) { case unknownproto => return "Unsupported protocol"; - case err: errors::error => + case let err: errors::error => return errors::strerror(err); }; }; diff --git a/net/ip/+freebsd.ha b/net/ip/+freebsd.ha @@ -3,7 +3,7 @@ use endian; export fn to_native(a: addr, port: u16) rt::sockaddr = { match (a) { - case v4: addr4 => + case let v4: addr4 => return rt::sockaddr { in = rt::sockaddr_in { sin_len = size(rt::in_addr): u8, @@ -14,7 +14,7 @@ export fn to_native(a: addr, port: u16) rt::sockaddr = { }, ... }; - case v6: addr6 => + case let v6: addr6 => return rt::sockaddr { in6 = rt::sockaddr_in6 { sin6_len = size(rt::in6_addr): u8, diff --git a/net/ip/+linux.ha b/net/ip/+linux.ha @@ -3,7 +3,7 @@ use endian; export fn to_native(a: addr, port: u16) rt::sockaddr = { match (a) { - case v4: addr4 => + case let v4: addr4 => return rt::sockaddr { in = rt::sockaddr_in { sin_family = rt::AF_INET, @@ -13,7 +13,7 @@ export fn to_native(a: addr, port: u16) rt::sockaddr = { }, ... }; - case v6: addr6 => + case let v6: addr6 => return rt::sockaddr { in6 = rt::sockaddr_in6 { sin6_family = rt::AF_INET6, diff --git a/net/ip/+test.ha b/net/ip/+test.ha @@ -59,7 +59,7 @@ fn ip_test(s: str, expected: (addr|invalid)) void = { fn subnet_test_simple(s: str) void = { let net = match (parsecidr(s)) { - case a: subnet => + case let a: subnet => yield a; case => return; diff --git a/net/ip/ip.ha b/net/ip/ip.ha @@ -41,13 +41,13 @@ export type invalid = !void; // Test if two [[addr]]s are equal. export fn equal(l: addr, r: addr) bool = { match (l) { - case l: addr4 => + case let l: addr4 => if (!(r is addr4)) { return false; }; let r = r as addr4; return bytes::equal(l, r); - case l: addr6 => + case let l: addr6 => if (!(r is addr6)) { return false; }; @@ -66,7 +66,7 @@ fn parsev4(st: str) (addr4 | invalid) = { return invalid; }; ret[i] = match (strconv::stou8(s)) { - case term: u8 => + case let term: u8 => yield term; case => return invalid; @@ -95,7 +95,7 @@ fn parsev6(st: str) (addr6 | invalid) = { let i = 0; for (i < 16) { let s = match (strings::next_token(&tok)) { - case s: str => + case let s: str => yield s; case void => break; @@ -145,12 +145,12 @@ fn parsev6(st: str) (addr6 | invalid) = { // Parses an IP address. export fn parse(s: str) (addr | invalid) = { match (parsev4(s)) { - case v4: addr4 => + case let v4: addr4 => return v4; case invalid => void; }; match (parsev6(s)) { - case v6: addr6 => + case let v6: addr6 => return v6; case invalid => void; }; @@ -252,7 +252,7 @@ export fn parsecidr(st: str) (subnet | invalid) = { let addr = parse(ips)?; let masks = wanttoken(&tok)?; let val = match (strconv::stou8(masks)) { - case x: u8 => + case let x: u8 => yield x; case => return invalid; @@ -292,9 +292,9 @@ fn masklen(addr: []u8) (void | size) = { fn fmtmask(s: io::handle, mask: addr) (io::error | size) = { let ret = 0z; let slice = match (mask) { - case v4: addr4 => + case let v4: addr4 => yield v4[..]; - case v6: addr6 => + case let v6: addr6 => yield v6[..]; }; match (masklen(slice)) { @@ -304,7 +304,7 @@ fn fmtmask(s: io::handle, mask: addr) (io::error | size) = { for (let i = 0z; i < len(slice); i += 1) { ret += fmt::fprintf(s, "{:x}", slice[i])?; }; - case n: size => + case let n: size => // Standard CIDR integer ret += fmt::fprintf(s, "{}", n)?; }; @@ -322,11 +322,11 @@ fn fmtsubnet(s: io::handle, subnet: subnet) (io::error | size) = { // Formats an [[addr]] or [[subnet]] and prints it to a stream. export fn fmt(s: io::handle, item: (...addr | subnet)) (io::error | size) = { match (item) { - case v4: addr4 => + case let v4: addr4 => return fmtv4(s, v4)?; - case v6: addr6 => + case let v6: addr6 => return fmtv6(s, v6)?; - case sub: subnet => + case let sub: subnet => return fmtsubnet(s, sub); }; }; @@ -344,7 +344,7 @@ export fn string(item: (...addr | subnet)) str = { fn wanttoken(tok: *strings::tokenizer) (str | invalid) = { match (strings::next_token(tok)) { - case s: str => + case let s: str => return s; case void => return invalid; diff --git a/net/listener.ha b/net/listener.ha @@ -5,7 +5,7 @@ use io; // available. export fn accept(l: *listener) (io::file | error) = { match (l.accept) { - case f: *fn(l: *listener) (io::file | error) => + case let f: *fn(l: *listener) (io::file | error) => return f(l); case null => return errors::unsupported; @@ -15,7 +15,7 @@ export fn accept(l: *listener) (io::file | error) = { // Shuts down a [[listener]] and frees resources associated with it. export fn shutdown(l: *listener) void = { match (l.shutdown) { - case f: *fn(l: *listener) void => + case let f: *fn(l: *listener) void => f(l); case null => void; }; diff --git a/net/tcp/+freebsd.ha b/net/tcp/+freebsd.ha @@ -20,9 +20,9 @@ export fn connect( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -34,7 +34,7 @@ export fn connect( }; const sz = ip::native_addrlen(addr); match (rt::connect(sockfd, &sockaddr, sz)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -55,9 +55,9 @@ export fn listen( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -72,27 +72,27 @@ export fn listen( setsockopt(sockfd, rt::SO_REUSEPORT, true)?; case keepalive => setsockopt(sockfd, rt::SO_KEEPALIVE, true)?; - case b: backlog => + case let b: backlog => bk = b; - case p: portassignment => void; + case let p: portassignment => void; }; }; const sz = ip::native_addrlen(addr); match (rt::bind(sockfd, &sockaddr, sz)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; match (rt::listen(sockfd, bk)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; for (let i = 0z; i < len(options); i += 1) { let portout = match (options[i]) { - case p: portassignment => + case let p: portassignment => yield p; case => continue; @@ -100,7 +100,7 @@ export fn listen( let sn = rt::sockaddr {...}; let al = size(rt::sockaddr): u32; match (rt::getsockname(sockfd, &sn, &al)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -136,7 +136,7 @@ fn setsockopt( let val: int = if (value) 1 else 0; match (rt::setsockopt(sockfd, rt::SOL_SOCKET, option, &val: *void, size(int): u32)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; diff --git a/net/tcp/+linux.ha b/net/tcp/+linux.ha @@ -20,9 +20,9 @@ export fn connect( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -34,7 +34,7 @@ export fn connect( }; const sz = size(rt::sockaddr): u32; match (rt::connect(sockfd, &sockaddr, sz)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -55,9 +55,9 @@ export fn listen( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -72,26 +72,26 @@ export fn listen( setsockopt(sockfd, rt::SO_REUSEPORT, true)?; case keepalive => setsockopt(sockfd, rt::SO_KEEPALIVE, true)?; - case b: backlog => + case let b: backlog => bk = b; - case p: portassignment => void; + case let p: portassignment => void; }; }; match (rt::bind(sockfd, &sockaddr, size(rt::sockaddr): u32)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; match (rt::listen(sockfd, bk)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; for (let i = 0z; i < len(options); i += 1) { let portout = match (options[i]) { - case p: portassignment => + case let p: portassignment => yield p; case => continue; @@ -99,7 +99,7 @@ export fn listen( let sn = rt::sockaddr {...}; let al = size(rt::sockaddr): u32; match (rt::getsockname(sockfd, &sn, &al)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -135,7 +135,7 @@ fn setsockopt( let val: int = if (value) 1 else 0; match (rt::setsockopt(sockfd, rt::SOL_SOCKET, option, &val: *void, size(int): u32)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; diff --git a/net/udp/+freebsd.ha b/net/udp/+freebsd.ha @@ -17,9 +17,9 @@ export fn connect( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_DGRAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; @@ -28,7 +28,7 @@ export fn connect( match (rt::connect(sockfd, &sockaddr, sz)) { case int => return io::fdopen(sockfd); - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -46,9 +46,9 @@ export fn listen( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_DGRAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -58,7 +58,7 @@ export fn listen( const sz = ip::native_addrlen(addr); match (rt::bind(sockfd, &sockaddr, sz)) { case int => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; @@ -67,7 +67,7 @@ export fn listen( let sn = rt::sockaddr {...}; let al = size(rt::sockaddr): u32; match (rt::getsockname(sockfd, &sn, &al)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -81,9 +81,9 @@ export fn listen( // Sends a UDP packet to the destination previously specified by [[connect]]. export fn send(sock: io::file, buf: []u8) (size | net::error) = { match (rt::send(sock, buf: *[*]u8, len(buf), 0)) { - case sz: size => + case let sz: size => return sz; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -98,9 +98,9 @@ export fn sendto( const sockaddr = ip::to_native(dest, port); const sz = ip::native_addrlen(dest); match (rt::sendto(sock, buf: *[*]u8, len(buf), 0, &sockaddr, sz)) { - case sz: size => + case let sz: size => return sz; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -116,9 +116,9 @@ export fn recvfrom( const sockaddr = rt::sockaddr { ... }; const sz = match (rt::recvfrom(sock, buf: *[*]u8, len(buf), 0, &sockaddr, &addrsz)) { - case sz: size => + case let sz: size => yield sz; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; @@ -126,12 +126,12 @@ export fn recvfrom( const peer = ip::from_native(sockaddr); match (src) { case null => void; - case src: *ip::addr => + case let src: *ip::addr => *src = peer.0; }; match (port) { case null => void; - case port: *u16 => + case let port: *u16 => *port = peer.1; }; diff --git a/net/udp/+linux.ha b/net/udp/+linux.ha @@ -17,9 +17,9 @@ export fn connect( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_DGRAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; @@ -28,7 +28,7 @@ export fn connect( match (rt::connect(sockfd, &sockaddr, sz)) { case int => return io::fdopen(sockfd); - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -46,9 +46,9 @@ export fn listen( yield rt::AF_INET6: int; }; const sockfd = match (rt::socket(family, rt::SOCK_DGRAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -58,7 +58,7 @@ export fn listen( const sz = size(rt::sockaddr): u32; match (rt::bind(sockfd, &sockaddr, sz)) { case int => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; @@ -67,7 +67,7 @@ export fn listen( let sn = rt::sockaddr {...}; let al = size(rt::sockaddr): u32; match (rt::getsockname(sockfd, &sn, &al)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -81,9 +81,9 @@ export fn listen( // Sends a UDP packet to the destination previously specified by [[connect]]. export fn send(sock: io::file, buf: []u8) (size | net::error) = { match (rt::send(sock, buf: *[*]u8, len(buf), 0)) { - case sz: size => + case let sz: size => return sz; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -98,9 +98,9 @@ export fn sendto( const sockaddr = ip::to_native(dest, port); const sz = size(rt::sockaddr): u32; match (rt::sendto(sock, buf: *[*]u8, len(buf), 0, &sockaddr, sz)) { - case sz: size => + case let sz: size => return sz; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -116,9 +116,9 @@ export fn recvfrom( const sockaddr = rt::sockaddr { ... }; const sz = match (rt::recvfrom(sock, buf: *[*]u8, len(buf), 0, &sockaddr, &addrsz)) { - case sz: size => + case let sz: size => yield sz; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; @@ -126,12 +126,12 @@ export fn recvfrom( const peer = ip::from_native(sockaddr); match (src) { case null => void; - case src: *ip::addr => + case let src: *ip::addr => *src = peer.0; }; match (port) { case null => void; - case port: *u16 => + case let port: *u16 => *port = peer.1; }; diff --git a/net/unix/+freebsd.ha b/net/unix/+freebsd.ha @@ -11,15 +11,15 @@ use types; // established. export fn connect(addr: addr) (io::file | net::error) = { let sockaddr = match (to_native(addr)) { - case a: rt::sockaddr => + case let a: rt::sockaddr => yield a; case invalid => return errors::unsupported; // path too long }; const sockfd = match (rt::socket(rt::AF_UNIX: int, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -27,7 +27,7 @@ export fn connect(addr: addr) (io::file | net::error) = { const sz = size(rt::sockaddr_un): u32; match (rt::connect(sockfd, &sockaddr, sz)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -41,15 +41,15 @@ export fn listen( options: listen_option... ) (*net::listener | net::error) = { let sockaddr = match (to_native(addr)) { - case a: rt::sockaddr => + case let a: rt::sockaddr => yield a; case invalid => return errors::unsupported; // path too long }; const sockfd = match (rt::socket(rt::AF_UNIX: int, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -62,12 +62,12 @@ export fn listen( }; match (rt::bind(sockfd, &sockaddr, size(rt::sockaddr_un): u32)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; match (rt::listen(sockfd, bk)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -96,7 +96,7 @@ fn to_native(addr: addr) (rt::sockaddr | invalid) = { }; match ((&addr: *types::string).data) { case null => void; - case data: *[*]u8 => + case let data: *[*]u8 => rt::memcpy(&ret.un.sun_path, data, len(addr)); }; ret.un.sun_path[len(addr)] = 0; diff --git a/net/unix/+linux.ha b/net/unix/+linux.ha @@ -11,15 +11,15 @@ use types; // established. export fn connect(addr: addr) (io::file | net::error) = { let sockaddr = match (to_native(addr)) { - case a: rt::sockaddr => + case let a: rt::sockaddr => yield a; case invalid => return errors::unsupported; // path too long }; const sockfd = match (rt::socket(rt::AF_UNIX: int, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -27,7 +27,7 @@ export fn connect(addr: addr) (io::file | net::error) = { const sz = size(rt::sockaddr_un): u32; match (rt::connect(sockfd, &sockaddr, sz)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -41,15 +41,15 @@ export fn listen( options: listen_option... ) (*net::listener | net::error) = { let sockaddr = match (to_native(addr)) { - case a: rt::sockaddr => + case let a: rt::sockaddr => yield a; case invalid => return errors::unsupported; // path too long }; const sockfd = match (rt::socket(rt::AF_UNIX: int, rt::SOCK_STREAM, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case fd: int => + case let fd: int => yield fd; }; let flags = rt::fcntl(sockfd, rt::F_GETFL, 0)!; @@ -62,12 +62,12 @@ export fn listen( }; match (rt::bind(sockfd, &sockaddr, size(rt::sockaddr_un): u32)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; match (rt::listen(sockfd, bk)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case int => void; }; @@ -95,7 +95,7 @@ fn to_native(addr: addr) (rt::sockaddr | invalid) = { }; match ((&addr: *types::string).data) { case null => void; - case data: *[*]u8 => + case let data: *[*]u8 => rt::memcpy(&ret.un.sun_path, data, len(addr)); }; ret.un.sun_path[len(addr)] = 0; diff --git a/net/unix/dial.ha b/net/unix/dial.ha @@ -4,9 +4,9 @@ use net; fn dial_unix(addr: str, service: str) (io::file | dial::error) = { match (connect(addr)) { - case conn: io::file => + case let conn: io::file => return conn; - case err: net::error => + case let err: net::error => return err; }; }; diff --git a/net/unix/socketpair.ha b/net/unix/socketpair.ha @@ -9,7 +9,7 @@ use io; export fn socketpair() ((io::file, io::file) | net::error) = { let sv: [2]int = [0...]; match (rt::socketpair(rt::AF_UNIX : int, rt::SOCK_STREAM : int, 0, &sv)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case => return (io::fdopen(sv[0]), io::fdopen(sv[1])); diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha @@ -100,9 +100,9 @@ fn _fs_open( let fs = fs: *os_filesystem; let fd = match (rt::openat(fs.dirfd, path, flags, mode)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case fd: int => + case let fd: int => yield fd; }; @@ -215,7 +215,7 @@ fn fs_create( fn fs_remove(fs: *fs::fs, path: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::unlinkat(fs.dirfd, path, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -224,7 +224,7 @@ fn fs_remove(fs: *fs::fs, path: str) (void | fs::error) = { fn fs_rename(fs: *fs::fs, oldpath: str, newpath: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::renameat(fs.dirfd, oldpath, fs.dirfd, newpath)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -234,7 +234,7 @@ fn fs_stat(fs: *fs::fs, path: str) (fs::filestat | fs::error) = { let fs = fs: *os_filesystem; let st = rt::st { ... }; match (rt::fstatat(fs.dirfd, path, &st, rt::AT_SYMLINK_NOFOLLOW)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -270,9 +270,9 @@ fn fs_readlink(fs: *fs::fs, path: str) (str | fs::error) = { let fs = fs: *os_filesystem; static let buf: [rt::PATH_MAX]u8 = [0...]; let z = match (rt::readlinkat(fs.dirfd, path, buf[..])) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case z: size => + case let z: size => yield z; }; return strings::dup(strings::fromutf8(buf[..z])); @@ -283,9 +283,9 @@ fn fs_subdir(fs: *fs::fs, path: str) (*fs::fs | fs::error) = { let flags = rt::O_RDONLY | rt::O_CLOEXEC | rt::O_DIRECTORY; let fd: int = match (rt::openat(fs.dirfd, path, flags, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case fd: int => + case let fd: int => yield fd; }; @@ -295,7 +295,7 @@ fn fs_subdir(fs: *fs::fs, path: str) (*fs::fs | fs::error) = { fn fs_rmdir(fs: *fs::fs, path: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::unlinkat(fs.dirfd, path, rt::AT_REMOVEDIR)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -304,7 +304,7 @@ fn fs_rmdir(fs: *fs::fs, path: str) (void | fs::error) = { fn fs_mkdir(fs: *fs::fs, path: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::mkdirat(fs.dirfd, path, 0o755)) { - case err: rt::errno => + case let err: rt::errno => switch (err) { case rt::EISDIR => return errors::exists; @@ -318,7 +318,7 @@ fn fs_mkdir(fs: *fs::fs, path: str) (void | fs::error) = { fn fs_chmod(fs: *fs::fs, path: str, mode: fs::mode) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::fchmodat(fs.dirfd, path, mode: uint, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -327,7 +327,7 @@ fn fs_chmod(fs: *fs::fs, path: str, mode: fs::mode) (void | fs::error) = { fn fs_chown(fs: *fs::fs, path: str, uid: uint, gid: uint) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::fchownat(fs.dirfd, path, uid, gid, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -354,7 +354,7 @@ fn fs_resolve(fs: *fs::fs, path: str) str = { match (path::next(&iter)) { case void => break; - case p: str => + case let p: str => resolve_part(&parts, p); }; }; @@ -364,7 +364,7 @@ fn fs_resolve(fs: *fs::fs, path: str) str = { match (path::next(&iter)) { case void => break; - case p: str => + case let p: str => resolve_part(&parts, p); }; }; @@ -391,14 +391,14 @@ fn fs_iter(fs: *fs::fs, path: str) (*fs::iterator | fs::error) = { let fs = fs: *os_filesystem; let flags = rt::O_RDONLY | rt::O_CLOEXEC | rt::O_DIRECTORY; let fd: int = match (rt::openat(fs.dirfd, path, flags, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case fd: int => + case let fd: int => yield fd; }; let buf = match (rt::malloc(fs.getdents_bufsz)) { - case v: *void => + case let v: *void => yield v: *[*]u8; case null => return errors::nomem; diff --git a/os/+freebsd/environ.ha b/os/+freebsd/environ.ha @@ -41,7 +41,7 @@ export fn getenv(name: const str) (str | void) = { const eq: size = match (bytes::index(item[..ln], '=': u8)) { case void => abort("Environment violates System-V invariants"); - case i: size => + case let i: size => yield i; }; if (bytes::equal(name_b, item[..eq])) { @@ -54,7 +54,7 @@ export fn getenv(name: const str) (str | void) = { // Looks up an environment variable and returns its value, or a default value if // unset. export fn tryenv(name: const str, default: str) str = match (getenv(name)) { -case s: str => +case let s: str => yield s; case void => yield default; diff --git a/os/+freebsd/fs.ha b/os/+freebsd/fs.ha @@ -17,20 +17,20 @@ export fn getcwd() str = strings::fromc(rt::getcwd() as *const char); // Change the current working directory. export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { const path: str = match (target) { - case fs: *fs::fs => + case let fs: *fs::fs => assert(fs.open == &fs_open); let fs = fs: *os_filesystem; match (rt::fchdir(fs.dirfd)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => return; }; - case s: str => + case let s: str => yield s; }; match (rt::chdir(path)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; @@ -42,7 +42,7 @@ export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { // This function is not appropriate for sandboxing. export fn chroot(target: str) (void | fs::error) = { match (rt::chroot(target)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -160,9 +160,9 @@ fn _fs_open( }; let fd = match (rt::openat2(fs.dirfd, path, oh, size(rt::open_how))) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case fd: int => + case let fd: int => yield fd; }; @@ -240,7 +240,7 @@ fn fs_create( fn fs_remove(fs: *fs::fs, path: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::unlinkat(fs.dirfd, path, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -249,7 +249,7 @@ fn fs_remove(fs: *fs::fs, path: str) (void | fs::error) = { fn fs_rename(fs: *fs::fs, oldpath: str, newpath: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::renameat(fs.dirfd, oldpath, fs.dirfd, newpath, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -259,7 +259,7 @@ fn fs_stat(fs: *fs::fs, path: str) (fs::filestat | fs::error) = { let fs = fs: *os_filesystem; let st = rt::st { ... }; match (rt::fstatat(fs.dirfd, path, &st, rt::AT_SYMLINK_NOFOLLOW)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -295,9 +295,9 @@ fn fs_readlink(fs: *fs::fs, path: str) (str | fs::error) = { let fs = fs: *os_filesystem; static let buf: [rt::PATH_MAX]u8 = [0...]; let z = match (rt::readlinkat(fs.dirfd, path, buf[..])) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case z: size => + case let z: size => yield z; }; return strings::dup(strings::fromutf8(buf[..z])); @@ -312,9 +312,9 @@ fn fs_subdir(fs: *fs::fs, path: str) (*fs::fs | fs::error) = { let fd: int = match (rt::openat2(fs.dirfd, path, &oh, size(rt::open_how))) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case fd: int => + case let fd: int => yield fd; }; @@ -324,7 +324,7 @@ fn fs_subdir(fs: *fs::fs, path: str) (*fs::fs | fs::error) = { fn fs_rmdir(fs: *fs::fs, path: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::unlinkat(fs.dirfd, path, rt::AT_REMOVEDIR)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -333,7 +333,7 @@ fn fs_rmdir(fs: *fs::fs, path: str) (void | fs::error) = { fn fs_mkdir(fs: *fs::fs, path: str) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::mkdirat(fs.dirfd, path, 0o755)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -342,7 +342,7 @@ fn fs_mkdir(fs: *fs::fs, path: str) (void | fs::error) = { fn fs_chmod(fs: *fs::fs, path: str, mode: fs::mode) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::fchmodat(fs.dirfd, path, mode: uint, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -351,7 +351,7 @@ fn fs_chmod(fs: *fs::fs, path: str, mode: fs::mode) (void | fs::error) = { fn fs_chown(fs: *fs::fs, path: str, uid: uint, gid: uint) (void | fs::error) = { let fs = fs: *os_filesystem; match (rt::fchownat(fs.dirfd, path, uid, gid, 0)) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); case void => void; }; @@ -378,7 +378,7 @@ fn fs_resolve(fs: *fs::fs, path: str) str = { match (path::next(&iter)) { case void => break; - case p: str => + case let p: str => resolve_part(&parts, p); }; }; @@ -388,7 +388,7 @@ fn fs_resolve(fs: *fs::fs, path: str) str = { match (path::next(&iter)) { case void => break; - case p: str => + case let p: str => resolve_part(&parts, p); }; }; @@ -417,14 +417,14 @@ fn fs_iter(fs: *fs::fs, path: str) (*fs::iterator | fs::error) = { }; let fd: int = match (rt::openat2(fs.dirfd, path, &oh, size(rt::open_how))) { - case err: rt::errno => + case let err: rt::errno => return errno_to_fs(err); - case fd: int => + case let fd: int => yield fd; }; let buf = match (rt::malloc(fs.getdents_bufsz)) { - case v: *void => + case let v: *void => yield v: *[*]u8; case null => return errors::nomem; diff --git a/os/+linux/environ.ha b/os/+linux/environ.ha @@ -41,7 +41,7 @@ export fn getenv(name: const str) (str | void) = { const eq: size = match (bytes::index(item[..ln], '=': u8)) { case void => abort("Environment violates System-V invariants"); - case i: size => + case let i: size => yield i; }; if (bytes::equal(name_b, item[..eq])) { @@ -54,7 +54,7 @@ export fn getenv(name: const str) (str | void) = { // Looks up an environment variable and returns its value, or a default value if // unset. export fn tryenv(name: const str, default: str) str = match (getenv(name)) { -case s: str => +case let s: str => yield s; case void => yield default; diff --git a/os/+linux/fs.ha b/os/+linux/fs.ha @@ -17,20 +17,20 @@ export fn getcwd() str = strings::fromc(rt::getcwd() as *const char); // Change the current working directory. export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { const path: str = match (target) { - case fs: *fs::fs => + case let fs: *fs::fs => assert(fs.open == &fs_open); let fs = fs: *os_filesystem; match (rt::fchdir(fs.dirfd)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => return; }; - case s: str => + case let s: str => yield s; }; match (rt::chdir(path)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; @@ -42,7 +42,7 @@ export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { // This function is not appropriate for sandboxing. export fn chroot(target: str) (void | fs::error) = { match (rt::chroot(target)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; @@ -52,7 +52,7 @@ export fn chroot(target: str) (void | fs::error) = { export fn mkfifo(path: str, mode: fs::mode) (void | fs::error) = { match (rt::mknodat(rt::AT_FDCWD, path, mode: rt::mode_t | rt::S_IFIFO, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; @@ -68,7 +68,7 @@ export fn mkblk( match (rt::mknodat(rt::AT_FDCWD, path, mode: rt::mode_t | rt::S_IFBLK, rt::mkdev(major: u32, minor: u32))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; @@ -83,7 +83,7 @@ export fn mkchr( ) (void | fs::error) = { match (rt::mknodat(rt::AT_FDCWD, path, mode: rt::mode_t | rt::S_IFCHR, rt::mkdev(major: u32, minor: u32))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; diff --git a/os/exec/cmd.ha b/os/exec/cmd.ha @@ -23,7 +23,7 @@ export fn cmd(name: str, args: str...) (command | error) = { platform: platform_cmd = if (strings::contains(name, '/')) { yield match (open(name)) { - case p: platform_cmd => + case let p: platform_cmd => yield p; case => return nocmd; @@ -32,7 +32,7 @@ export fn cmd(name: str, args: str...) (command | error) = { yield match (lookup(name)) { case void => return nocmd; - case p: platform_cmd => + case let p: platform_cmd => yield p; }; }, @@ -72,9 +72,9 @@ export @noreturn fn exec(cmd: *command) void = { export fn start(cmd: *command) (error | process) = { defer finish(cmd); match (platform_start(cmd)) { - case err: errors::opaque => + case let err: errors::opaque => return err; - case proc: process => + case let proc: process => return proc; }; }; @@ -94,7 +94,7 @@ export fn setenv(cmd: *command, key: str, value: str) void = { for (let i = 0z; true; i += 1) match (strings::next(&iter)) { case void => break; - case r: rune => + case let r: rune => if (i == 0) { assert(r == '_' || ascii::isalpha(r), "Invalid environment variable"); @@ -164,7 +164,7 @@ fn lookup(name: str) (platform_cmd | void) = { const path = match (os::getenv("PATH")) { case void => return; - case s: str => + case let s: str => yield s; }; let tok = strings::tokenize(path, ":"); @@ -172,15 +172,15 @@ fn lookup(name: str) (platform_cmd | void) = { const item = match (strings::next_token(&tok)) { case void => break; - case s: str => + case let s: str => yield s; }; let path = strings::concat(item, "/", name); defer free(path); match (open(path)) { - case err: error => + case let err: error => continue; - case p: platform_cmd => + case let p: platform_cmd => return p; }; }; diff --git a/os/exec/exec+freebsd.ha b/os/exec/exec+freebsd.ha @@ -11,9 +11,9 @@ export type platform_cmd = io::file; // void (to the child), or an error. export fn fork() (int | void | error) = { match (rt::fork()) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case i: (int | void) => + case let i: (int | void) => return i; }; }; @@ -45,17 +45,17 @@ export fn pipe() (io::file, io::file) = { fn open(path: str) (platform_cmd | error) = { // TODO: This is racy, rewrite with TOCTOU match (rt::access(path, rt::X_OK)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case b: bool => + case let b: bool => if (!b) { return errors::noaccess; }; }; match (rt::open(path, rt::O_RDONLY, 0u)) { - case fd: int => + case let fd: int => return fd; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -84,7 +84,7 @@ fn platform_exec(cmd: *command) error = { let need_devnull = false; for (let i = 0z; i < len(cmd.files); i += 1) { const from = match (cmd.files[i].0) { - case file: io::file => + case let file: io::file => yield file; case nullfd => need_devnull = true; @@ -94,9 +94,9 @@ fn platform_exec(cmd: *command) error = { }; cmd.files[i].0 = match (rt::fcntl(from, rt::F_DUPFD_CLOEXEC, 0)) { - case fd: int => + case let fd: int => yield fd; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -107,7 +107,7 @@ fn platform_exec(cmd: *command) error = { for (let i = 0z; i < len(cmd.files); i += 1) { const from = match (cmd.files[i].0) { - case file: io::file => + case let file: io::file => yield file; case nullfd => yield devnull; @@ -118,7 +118,7 @@ fn platform_exec(cmd: *command) error = { match (rt::dup2(from, cmd.files[i].1)) { case int => void; - case e: rt::errno => + case let e: rt::errno => return errors::errno(e); }; }; @@ -131,21 +131,21 @@ fn platform_start(cmd: *command) (process | errors::error) = { // TODO: Let the user configure clone more to their taste (e.g. SIGCHLD) let pipe: [2]int = [0...]; match (rt::pipe2(&pipe, rt::O_CLOEXEC)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; match (rt::fork()) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case pid: int => + case let pid: int => rt::close(pipe[1])!; let errno: int = 0; match (rt::read(pipe[0], &errno, size(int))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => switch (n) { case size(int) => return errors::errno(errno); diff --git a/os/exec/exec+linux.ha b/os/exec/exec+linux.ha @@ -11,9 +11,9 @@ export type platform_cmd = io::file; // void (to the child), or an error. export fn fork() (int | void | error) = { match (rt::fork()) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case i: (int | void) => + case let i: (int | void) => return i; }; }; @@ -44,9 +44,9 @@ export fn pipe() (io::file, io::file) = { fn open(path: str) (platform_cmd | error) = { match (rt::access(path, rt::X_OK)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case b: bool => + case let b: bool => if (!b) { return errors::noaccess; }; @@ -54,9 +54,9 @@ fn open(path: str) (platform_cmd | error) = { // O_PATH is used because it allows us to use an executable for which we // have execute permissions, but not read permissions. match (rt::open(path, rt::O_PATH, 0u)) { - case fd: int => + case let fd: int => return fd; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -85,7 +85,7 @@ fn platform_exec(cmd: *command) error = { let need_devnull = false; for (let i = 0z; i < len(cmd.files); i += 1) { const from = match (cmd.files[i].0) { - case file: io::file => + case let file: io::file => yield file; case nullfd => need_devnull = true; @@ -95,9 +95,9 @@ fn platform_exec(cmd: *command) error = { }; cmd.files[i].0 = match (rt::fcntl(from, rt::F_DUPFD_CLOEXEC, 0)) { - case fd: int => + case let fd: int => yield fd; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; @@ -108,7 +108,7 @@ fn platform_exec(cmd: *command) error = { for (let i = 0z; i < len(cmd.files); i += 1) { const from = match (cmd.files[i].0) { - case file: io::file => + case let file: io::file => yield file; case nullfd => yield devnull; @@ -119,7 +119,7 @@ fn platform_exec(cmd: *command) error = { match (rt::dup2(from, cmd.files[i].1)) { case int => void; - case e: rt::errno => + case let e: rt::errno => return errors::errno(e); }; }; @@ -132,21 +132,21 @@ fn platform_start(cmd: *command) (process | errors::error) = { // TODO: Let the user configure clone more to their taste (e.g. SIGCHLD) let pipe: [2]int = [0...]; match (rt::pipe2(&pipe, rt::O_CLOEXEC)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); case void => void; }; match (rt::clone(null, 0, null, null, 0)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case pid: int => + case let pid: int => rt::close(pipe[1])!; let errno: int = 0; match (rt::read(pipe[0], &errno, size(int))) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: size => + case let n: size => switch (n) { case size(int) => return errors::errno(errno); diff --git a/os/exec/process+freebsd.ha b/os/exec/process+freebsd.ha @@ -52,9 +52,9 @@ export fn wait(proc: *process) (status | error) = { let ru: rt::rusage = rt::rusage { ... }; let st: status = status { ... }; match (rt::wait4(*proc, &st.status, 0, &ru)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case pid: int => + case let pid: int => assert(pid == *proc); }; rusage(&st, &ru); @@ -67,9 +67,9 @@ export fn peek(proc: *process) (status | void | error) = { let ru: rt::rusage = rt::rusage { ... }; let st: status = status { ... }; match (rt::wait4(*proc, &st.status, 0, &ru)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case pid: int => + case let pid: int => switch (pid) { case 0 => return; @@ -94,7 +94,7 @@ export type exit_status = (exited | signaled); export fn exitstr(status: exit_status) const str = { static let buf: [1024]u8 = [0...]; match (status) { - case i: exited => + case let i: exited => switch (i) { case 0 => return "exited normally"; @@ -102,7 +102,7 @@ export fn exitstr(status: exit_status) const str = { return fmt::bsprintf(buf, "exited with status {}", i: int); }; - case s: signaled => + case let s: signaled => // TODO: Add signal name return fmt::bsprintf(buf, "exited with signal {}", s: int); }; @@ -185,7 +185,7 @@ export fn kill(proc: process, sig: signal...) (void | errors::error) = { abort("os::exec::signal illegally called with more than one signal"); }; match (rt::kill(proc, sig)) { - case errno: rt::errno => + case let errno: rt::errno => return errors::errno(errno); case void => return; diff --git a/os/exec/process+linux.ha b/os/exec/process+linux.ha @@ -38,9 +38,9 @@ export fn wait(proc: *process) (status | error) = { let ru: rt::rusage = rt::rusage { ... }; let st: status = status { ... }; match (rt::wait4(*proc, &st.status, 0, &ru)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case pid: int => + case let pid: int => assert(pid == *proc); }; rusage(&st, &ru); @@ -53,9 +53,9 @@ export fn peek(proc: *process) (status | void | error) = { let ru: rt::rusage = rt::rusage { ... }; let st: status = status { ... }; match (rt::wait4(*proc, &st.status, 0, &ru)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case pid: int => + case let pid: int => switch (pid) { case 0 => return; @@ -80,7 +80,7 @@ export type exit_status = (exited | signaled); export fn exitstr(status: exit_status) const str = { static let buf: [1024]u8 = [0...]; match (status) { - case i: exited => + case let i: exited => switch (i) { case 0 => return "exited normally"; @@ -88,7 +88,7 @@ export fn exitstr(status: exit_status) const str = { return fmt::bsprintf(buf, "exited with status {}", i: int); }; - case s: signaled => + case let s: signaled => // TODO: Add signal name return fmt::bsprintf(buf, "exited with signal {}", s: int); }; @@ -171,7 +171,7 @@ export fn kill(proc: process, sig: signal...) (void | errors::error) = { abort("os::exec::signal illegally called with more than one signal"); }; match (rt::kill(proc, sig)) { - case errno: rt::errno => + case let errno: rt::errno => return errors::errno(errno); case void => return; diff --git a/os/exec/types.ha b/os/exec/types.ha @@ -26,7 +26,7 @@ export fn strerror(err: error) const str = { match (err) { case nocmd => return "Command not found"; - case err: errors::opaque => + case let err: errors::opaque => return errors::strerror(err); }; }; diff --git a/path/iter.ha b/path/iter.ha @@ -40,7 +40,7 @@ export fn next(iter: *iterator) (str | void) = { return strings::fromutf8_unsafe(pathsep); }; match (bytes::next_token(&iter.tok)) { - case b: []u8 => + case let b: []u8 => return strings::fromutf8_unsafe(b); case void => void; }; diff --git a/path/names.ha b/path/names.ha @@ -19,7 +19,7 @@ export fn dirname(path: str) const str = { let i = match (bytes::rindex(b, PATHSEP)) { case void => return "."; - case z: size => + case let z: size => yield z; }; if (i == 0) { @@ -65,7 +65,7 @@ export fn basename(path: str) const str = { let i = match (bytes::rindex(b, PATHSEP)) { case void => return path; - case z: size => + case let z: size => yield if (z + 1 < len(b)) z + 1z else 0z; }; return strings::fromutf8_unsafe(b[i..]); @@ -102,7 +102,7 @@ export fn extension(p: str) (str, str) = { let i = match (bytes::index(b, '.': u32: u8)) { case void => return (p, ""); - case z: size => + case let z: size => yield z; }; let e = b[i..]; diff --git a/rt/+aarch64/backtrace.ha b/rt/+aarch64/backtrace.ha @@ -14,7 +14,7 @@ export fn nextframe(fp: *frame) (frame | void) = { return match (fp.fp) { case null => yield void; - case fp: *frame => + case let fp: *frame => yield *fp; }; }; diff --git a/rt/+freebsd/segmalloc.ha b/rt/+freebsd/segmalloc.ha @@ -2,10 +2,10 @@ fn segmalloc(n: size) nullable *void = { return match (mmap(null, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) { - case err: errno => + case let err: errno => assert(err == ENOMEM: errno); yield null; - case p: *void => + case let p: *void => yield p; }; }; @@ -13,7 +13,7 @@ fn segmalloc(n: size) nullable *void = { // Frees a segment allocated with segmalloc. fn segfree(p: *void, s: size) void = { match (munmap(p, s)) { - case err: errno => + case let err: errno => abort("munmap failed"); case void => void; }; diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha @@ -12,16 +12,16 @@ let pathbuf: [PATH_MAX + 1]u8 = [0...]; fn copy_kpath(path: path, buf: []u8) (*const char | errno) = { let path = match (path) { - case c: *const char => + case let c: *const char => return c; - case s: str => + case let s: str => let ptr = &s: *struct { buf: *[*]u8, length: size, capacity: size, }; yield ptr.buf[..ptr.length]; - case b: []u8 => + case let b: []u8 => yield b; }; if (len(path) + 1 >= len(pathbuf)) { @@ -172,14 +172,14 @@ export fn faccessat( let path = kpath(path)?; match (wrap_return(syscall4(SYS_faccessat, dirfd: u64, path: uintptr: u64, mode: u64, flags: u64))) { - case err: errno => + case let err: errno => switch (err) { case EACCES => return false; case => return err; }; - case n: u64 => + case let n: u64 => assert(n == 0); return true; }; @@ -258,7 +258,7 @@ export fn fexecve(fd: int, argv: *[*]nullable *const char, envp: *[*]nullable *const char) errno = { return match (wrap_return(syscall3(SYS_fexecve, fd: u64, argv: uintptr: u64, envp: uintptr: u64))) { - case err: errno => + case let err: errno => yield err; case u64 => abort("unreachable"); @@ -342,11 +342,11 @@ export fn fcntl(fd: int, cmd: int, arg: fcntl_arg) (int | errno) = { return wrap_return(match (arg) { case void => yield syscall2(SYS_fcntl, _fd, _cmd); - case i: int => + case let i: int => yield syscall3(SYS_fcntl, _fd, _cmd, i: u64); - case l: *st_flock => + case let l: *st_flock => yield syscall3(SYS_fcntl, _fd, _cmd, l: uintptr: u64); - case u: *u64 => + case let u: *u64 => yield syscall3(SYS_fcntl, _fd, _cmd, u: uintptr: u64); })?: int; }; diff --git a/rt/+linux/+aarch64.ha b/rt/+linux/+aarch64.ha @@ -13,14 +13,14 @@ export fn clone( parent_tid: uintptr: u64, tls, child_tid: uintptr: u64))) { - case u: u64 => + case let u: u64 => switch (u) { case 0 => return void; case => return u: int; }; - case err: errno => + case let err: errno => return err; }; }; diff --git a/rt/+linux/+riscv64.ha b/rt/+linux/+riscv64.ha @@ -11,14 +11,14 @@ export fn clone( flags: u64, stack: uintptr: u64, parent_tid: uintptr: u64, tls, child_tid: uintptr: u64))) { - case u: u64 => + case let u: u64 => switch (u) { case 0 => return; case => return u: int; }; - case err: errno => + case let err: errno => return err; }; }; diff --git a/rt/+linux/+x86_64.ha b/rt/+linux/+x86_64.ha @@ -11,14 +11,14 @@ export fn clone( flags: u64, stack: uintptr: u64, parent_tid: uintptr: u64, child_tid: uintptr: u64, tls))) { - case u: u64 => + case let u: u64 => switch (u) { case 0 => return; case => return u: int; }; - case err: errno => + case let err: errno => return err; }; }; diff --git a/rt/+linux/segmalloc.ha b/rt/+linux/segmalloc.ha @@ -2,10 +2,10 @@ fn segmalloc(n: size) nullable *void = { return match (mmap(null, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) { - case err: errno => + case let err: errno => assert(err == ENOMEM: errno); yield null; - case p: *void => + case let p: *void => yield p; }; }; @@ -13,7 +13,7 @@ fn segmalloc(n: size) nullable *void = { // Frees a segment allocated with segmalloc. fn segfree(p: *void, s: size) void = { match (munmap(p, s)) { - case err: errno => + case let err: errno => abort("munmap failed"); case void => void; }; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -12,16 +12,16 @@ let pathbuf: [PATH_MAX + 1]u8 = [0...]; fn copy_kpath(path: path, buf: []u8) (*const char | errno) = { let path = match (path) { - case c: *const char => + case let c: *const char => return c; - case s: str => + case let s: str => let ptr = &s: *struct { buf: *[*]u8, length: size, capacity: size, }; yield ptr.buf[..ptr.length]; - case b: []u8 => + case let b: []u8 => yield b; }; if (len(path) + 1 >= len(pathbuf)) { @@ -196,7 +196,7 @@ export fn execveat(dirfd: int, path: path, argv: *[*]nullable *const char, return match (wrap_return(syscall5(SYS_execveat, dirfd: u64, path: uintptr: u64, argv: uintptr: u64, envp: uintptr: u64, flags: u64))) { - case err: errno => + case let err: errno => yield err; case u64 => abort("unreachable"); @@ -249,7 +249,7 @@ export fn mmap( let r = syscall6(SYS_mmap, addr: uintptr: u64, length: u64, prot: u64, flags: u64, fd: u64, offs: u64); return match (wrap_return(r)) { - case err: errno => + case let err: errno => return if (r: int == -EPERM && addr == null && (flags & MAP_ANON) > 0 @@ -257,7 +257,7 @@ export fn mmap( // Fix up incorrect EPERM from kernel: yield wrap_errno(ENOMEM); } else err; - case n: u64 => + case let n: u64 => yield n: uintptr: *void; }; }; @@ -282,14 +282,14 @@ export fn lseek(fd: int, off: i64, whence: uint) (i64 | errno) = { fn faccessat1(dirfd: int, path: *const char, mode: int) (bool | errno) = { return match (wrap_return(syscall3(SYS_faccessat, dirfd: u64, path: uintptr: u64, mode: u64))) { - case err: errno => + case let err: errno => yield switch (err) { case EACCES => yield false; case => yield err; }; - case n: u64 => + case let n: u64 => assert(n == 0); yield true; }; @@ -307,7 +307,7 @@ export fn faccessat( let path = kpath(path)?; match (wrap_return(syscall4(SYS_faccessat2, dirfd: u64, path: uintptr: u64, mode: u64, flags: u64))) { - case err: errno => + case let err: errno => switch (err) { case EACCES => return false; @@ -320,7 +320,7 @@ export fn faccessat( case => return err; }; - case n: u64 => + case let n: u64 => assert(n == 0); return true; }; @@ -344,13 +344,13 @@ export fn fcntl(fd: int, cmd: int, arg: fcntl_arg) (int | errno) = { return wrap_return(match (arg) { case void => yield syscall2(SYS_fcntl, _fd, _cmd); - case i: int => + case let i: int => yield syscall3(SYS_fcntl, _fd, _cmd, i: u64); - case l: *st_flock => + case let l: *st_flock => yield syscall3(SYS_fcntl, _fd, _cmd, l: uintptr: u64); - case o: *f_owner_ex => + case let o: *f_owner_ex => yield syscall3(SYS_fcntl, _fd, _cmd, o: uintptr: u64); - case u: *u64 => + case let u: *u64 => yield syscall3(SYS_fcntl, _fd, _cmd, u: uintptr: u64); })?: int; }; @@ -577,9 +577,9 @@ export type ioctl_arg = (nullable *void | u64); export fn ioctl(fd: int, req: u64, arg: ioctl_arg) (int | errno) = { let fd = fd: u64, req = req: u64; return wrap_return(match (arg) { - case u: u64 => + case let u: u64 => yield syscall3(SYS_ioctl, fd, req, u); - case v: nullable *void => + case let v: nullable *void => yield syscall3(SYS_ioctl, fd, req, v: uintptr: u64); })?: int; }; diff --git a/rt/+riscv64/backtrace.ha b/rt/+riscv64/backtrace.ha @@ -16,7 +16,7 @@ export fn nextframe(sframe: frame) (frame | void) = { match (*addr) { case null => return; - case a: *void => + case let a: *void => return frame { addr = a }; }; }; diff --git a/rt/+x86_64/backtrace.ha b/rt/+x86_64/backtrace.ha @@ -14,7 +14,7 @@ export fn backtrace() frame = frame { export fn nextframe(sframe: frame) (frame | void) = { let addr = sframe.addr: *nullable *void; match (*addr) { - case a: *void => + case let a: *void => return frame { addr = a }; case null => return; diff --git a/shlex/split.ha b/shlex/split.ha @@ -17,7 +17,7 @@ export fn split(in: const str) ([]str | syntaxerr) = { for (true) { const r = match (strings::next(&iter)) { - case r: rune => + case let r: rune => yield r; case void => break; @@ -27,7 +27,7 @@ export fn split(in: const str) ([]str | syntaxerr) = { switch (r) { case ' ', '\t', '\n' => for (true) match (strings::next(&iter)) { - case r: rune => + case let r: rune => if (r != ' ' && r != '\t' && r != '\n') { strings::prev(&iter); // Unget break; @@ -64,7 +64,7 @@ export fn split(in: const str) ([]str | syntaxerr) = { fn scan_backslash(out: io::handle, in: *strings::iterator) (void | syntaxerr) = { const r = match (strings::next(in)) { - case r: rune => + case let r: rune => yield r; case void => return syntaxerr; @@ -84,7 +84,7 @@ fn scan_backslash(out: io::handle, in: *strings::iterator) (void | syntaxerr) = fn scan_double(out: io::handle, in: *strings::iterator) (void | syntaxerr) = { for (true) { const r = match (strings::next(in)) { - case r: rune => + case let r: rune => yield r; case void => return syntaxerr; @@ -104,7 +104,7 @@ fn scan_double(out: io::handle, in: *strings::iterator) (void | syntaxerr) = { fn scan_single(out: io::handle, in: *strings::iterator) (void | syntaxerr) = { for (true) { const r = match (strings::next(in)) { - case r: rune => + case let r: rune => yield r; case void => return syntaxerr; diff --git a/sort/+test.ha b/sort/+test.ha @@ -10,7 +10,7 @@ fn ncmp(a: const *void, b: const *void) int = { match (search(nums[..], size(int), &key, &ncmp): nullable *int) { case null => abort(); - case p: *int => + case let p: *int => assert(p == &nums[i] && *p == nums[i]); }; }; diff --git a/strconv/numeric.ha b/strconv/numeric.ha @@ -5,15 +5,15 @@ use types; // [[strings::dup]] to duplicate the result. export fn signedtosb(n: types::signed, b: base) const str = { match (n) { - case i: int => + case let i: int => return itosb(i, b); - case i: i8 => + case let i: i8 => return i8tosb(i, b); - case i: i16 => + case let i: i16 => return i16tosb(i, b); - case i: i32 => + case let i: i32 => return i32tosb(i, b); - case i: i64 => + case let i: i64 => return i64tosb(i, b); }; }; @@ -28,17 +28,17 @@ export fn signedtos(n: types::signed) const str = signedtosb(n, base::DEC); // [[strings::dup]] to duplicate the result. export fn unsignedtosb(n: types::unsigned, b: base) const str = { match (n) { - case u: size => + case let u: size => return ztosb(u, b); - case u: uint => + case let u: uint => return utosb(u, b); - case u: u8 => + case let u: u8 => return u8tosb(u, b); - case u: u16 => + case let u: u16 => return u16tosb(u, b); - case u: u32 => + case let u: u32 => return u32tosb(u, b); - case u: u64 => + case let u: u64 => return u64tosb(u, b); }; }; @@ -53,9 +53,9 @@ export fn unsignedtos(n: types::unsigned) const str = unsignedtosb(n, base::DEC) // overwritten on subsequent calls; see [[strings::dup]] to duplicate the result. export fn integertosb(n: types::integer, b: base) const str = { match (n) { - case s: types::signed => + case let s: types::signed => return signedtosb(s, b); - case u: types::unsigned => + case let u: types::unsigned => return unsignedtosb(u, b); }; }; @@ -71,9 +71,9 @@ export fn integertos(n: types::integer) const str = integertosb(n, base::DEC); export fn floatingtosb(n: types::floating, b: base) const str = { assert(b == base::DEC); match (n) { - case f: f32 => + case let f: f32 => abort(); // TODO - case f: f64 => + case let f: f64 => return f64tos(f); }; }; @@ -88,9 +88,9 @@ export fn floatingtos(n: types::floating) const str = floatingtosb(n, base::DEC) // [[strings::dup]] to duplicate the result. export fn numerictosb(n: types::numeric, b: base) const str = { match (n) { - case i: types::integer => + case let i: types::integer => return integertosb(i, b); - case f: types::floating => + case let f: types::floating => return floatingtosb(f, b); }; }; diff --git a/strconv/stou.ha b/strconv/stou.ha @@ -27,7 +27,7 @@ export fn stou64b(s: str, base: uint) (u64 | invalid | overflow) = { let iter = strings::iter(s); for (true) { let r: rune = match (strings::next(&iter)) { - case r: rune => + case let r: rune => yield r; case void => break; @@ -36,7 +36,7 @@ export fn stou64b(s: str, base: uint) (u64 | invalid | overflow) = { let digit = match (rune_to_integer(r)) { case void => return (iter.dec.offs - 1): invalid; - case d: u64 => + case let d: u64 => yield d; }; @@ -111,16 +111,16 @@ export fn stozb(s: str, base: uint) (size | invalid | overflow) = { static assert(size(size) == size(u32) || size(size) == size(u64)); if (size(size) == size(u32)) { match (stou32b(s, base)) { - case v: (invalid | overflow) => + case let v: (invalid | overflow) => return v; - case n: u32 => + case let n: u32 => return n: size; }; } else { match (stou64b(s, base)) { - case v: (invalid | overflow) => + case let v: (invalid | overflow) => return v; - case n: u64 => + case let n: u64 => return n: size; }; }; diff --git a/strings/contains.ha b/strings/contains.ha @@ -3,9 +3,9 @@ use encoding::utf8; // Returns true if a string contains a rune or a sub-string. export fn contains(haystack: str, needle: (str | rune)) bool = match (needle) { -case s: str => +case let s: str => yield bytes::contains(toutf8(haystack), toutf8(s)); -case r: rune => +case let r: rune => yield bytes::contains(toutf8(haystack), utf8::encoderune(r)); }; diff --git a/strings/cstrings.ha b/strings/cstrings.ha @@ -44,12 +44,12 @@ export fn to_c(s: const str) *char = { let ptr = match (ptr) { case null => abort("Out of memory"); - case p: *[*]u8 => + case let p: *[*]u8 => yield p; }; match ((&s: *types::string).data) { case null => void; - case data: *[*]u8 => + case let data: *[*]u8 => yield rt::memcpy(ptr, data, len(s)); }; ptr[len(s)] = 0; diff --git a/strings/dup.ha b/strings/dup.ha @@ -8,13 +8,13 @@ export fn dup(s: const str) str = { const id = match (in.data) { case null => return ""; // Empty string - case b: *[*]u8 => + case let b: *[*]u8 => yield b; }; let buf: *[*]u8 = match (rt::malloc(in.length + 1)) { case null => abort("Out of memory"); - case v: *void => + case let v: *void => yield v; }; buf[..in.length + 1z] = id[..in.length + 1]; @@ -33,7 +33,7 @@ export fn dupall(s: []str) []str = { data = match (rt::malloc(len(s) * size(str))) { case null => abort("Out of memory"); - case v: *void => + case let v: *void => yield v; }, length = len(s), diff --git a/strings/index.ha b/strings/index.ha @@ -5,9 +5,9 @@ use bytes; // byte-wise index. export fn index(haystack: str, needle: (str | rune)) (size | void) = { match (needle) { - case r: rune => + case let r: rune => return index_rune(haystack, r); - case s: str => + case let s: str => return index_string(haystack, s); }; }; @@ -16,7 +16,7 @@ fn index_rune(s: str, r: rune) (size | void) = { let iter = iter(s); for (let i = 0z; true; i += 1) { match (next(&iter)) { - case n: rune => + case let n: rune => if (r == n) { return i; }; diff --git a/strings/iter.ha b/strings/iter.ha @@ -31,7 +31,7 @@ export fn riter(src: str) iterator = { // [[unicode::graphiter]] instead. export fn next(iter: *iterator) (rune | void) = { match (iter.push) { - case r: rune => + case let r: rune => iter.push = void; return r; case void => void; @@ -40,7 +40,7 @@ export fn next(iter: *iterator) (rune | void) = { case void => void; case (utf8::more | utf8::invalid) => abort("Invalid UTF-8 string (this should not happen)"); - case r: rune => + case let r: rune => yield r; }; }; @@ -54,7 +54,7 @@ export fn prev(iter: *iterator) (rune | void) = { yield void; case (utf8::more | utf8::invalid) => abort("Invalid UTF-8 string (this should not happen)"); - case r: rune => + case let r: rune => yield r; }; }; @@ -81,7 +81,7 @@ export fn iter_str(iter: *iterator) str = { const expected1 = ['こ', 'ん']; for (let i = 0z; i < len(expected1); i += 1) { match (next(&s)) { - case r: rune => + case let r: rune => assert(r == expected1[i]); case void => abort(); @@ -92,7 +92,7 @@ export fn iter_str(iter: *iterator) str = { const expected2 = ['ん', 'に', 'ち', 'は']; for (let i = 0z; i < len(expected2); i += 1) { match (next(&s)) { - case r: rune => + case let r: rune => assert(r == expected2[i]); case void => abort(); @@ -108,7 +108,7 @@ export fn iter_str(iter: *iterator) str = { const expected3 = ['は', 'ち', 'に']; for (let i = 0z; i< len(expected3); i += 1) { match (prev(&s)) { - case r: rune => + case let r: rune => assert(r == expected3[i]); case void => abort(); @@ -126,7 +126,7 @@ export fn runes(s: str) []rune = { for (true) { match (next(&iter)) { case void => break; - case r: rune => + case let r: rune => append(sl, r); }; }; diff --git a/strings/replace.ha b/strings/replace.ha @@ -11,7 +11,7 @@ export fn replace(s: str, needle: str, target: str) str = { for (true) { const match_idx = match(index(res, needle)) { - case s: size => + case let s: size => yield s; case void => break; diff --git a/strings/sub.ha b/strings/sub.ha @@ -6,7 +6,7 @@ fn utf8_byte_len_bounded(iter: *iterator, end: size) size = { let pos = 0z; for (let i = 0z; i < end; i += 1) { let r = match (strings::next(iter)) { - case r: rune => + case let r: rune => yield r; case void => break; @@ -21,7 +21,7 @@ fn utf8_byte_len_unbounded(iter: *iterator) size = { let pos = 0z; for (true) { let r = match (strings::next(iter)) { - case r: rune => + case let r: rune => yield r; case void => break; @@ -44,7 +44,7 @@ export fn sub(s: str, start: size, end: (size | end)) str = { let iter = iter(s); let starti = utf8_byte_len_bounded(&iter, start); let endi = match (end) { - case sz: size => + case let sz: size => yield starti + utf8_byte_len_bounded(&iter, sz - start); case end => yield starti + utf8_byte_len_unbounded(&iter); diff --git a/strings/suffix.ha b/strings/suffix.ha @@ -4,9 +4,9 @@ use encoding::utf8; // Returns true if 'in' has the given prefix. export fn hasprefix(in: str, prefix: (str | rune)) bool = { let prefix = match (prefix) { - case r: rune => + case let r: rune => yield utf8::encoderune(r); - case s: str => + case let s: str => yield toutf8(s); }; return bytes::hasprefix(toutf8(in), prefix); @@ -22,9 +22,9 @@ export fn hasprefix(in: str, prefix: (str | rune)) bool = { // Returns true if 'in' has the given prefix. export fn hassuffix(in: str, suff: (str | rune)) bool = { let suff = match (suff) { - case r: rune => + case let r: rune => yield utf8::encoderune(r); - case s: str => + case let s: str => yield toutf8(s); }; return bytes::hassuffix(toutf8(in), suff); diff --git a/strings/tokenize.ha b/strings/tokenize.ha @@ -18,7 +18,7 @@ export fn tokenize(s: str, delim: str) tokenizer = // void if there are no tokens left. export fn next_token(s: *tokenizer) (str | void) = { return match (bytes::next_token(s)) { - case b: []u8 => + case let b: []u8 => yield fromutf8(b); case void => void; }; @@ -27,7 +27,7 @@ export fn next_token(s: *tokenizer) (str | void) = { // Same as next_token(), but does not advance the cursor export fn peek_token(s: *tokenizer) (str | void) = { return match (bytes::peek_token(s)) { - case b: []u8 => + case let b: []u8 => yield fromutf8(b); case void => void; }; @@ -42,21 +42,21 @@ export fn remaining_tokens(s: *tokenizer) str = { @test fn tokenize() void = { let tok = tokenize("Hello, my name is drew", " "); match (next_token(&tok)) { - case s: str => + case let s: str => assert(s == "Hello,"); case void => abort(); }; match (next_token(&tok)) { - case s: str => + case let s: str => assert(s == "my"); case void => abort(); }; match (peek_token(&tok)) { - case s: str => + case let s: str => assert(s == "name"); case void => abort(); @@ -64,7 +64,7 @@ export fn remaining_tokens(s: *tokenizer) str = { match (next_token(&tok)) { - case s: str => + case let s: str => assert(s == "name"); case void => abort(); @@ -99,7 +99,7 @@ export fn splitN(in: str, delim: str, n: size) []str = { let tok = tokenize(in, delim); for (let i = 0z; i < n - 1z; i += 1) { match (next_token(&tok)) { - case s: str => + case let s: str => append(toks, s); case void => return toks; diff --git a/strings/trim.ha b/strings/trim.ha @@ -12,7 +12,7 @@ export fn ltrim(input: str, trim: rune...) str = { let it = iter(input); for (true) { const r = match (next(&it)) { - case r: rune => + case let r: rune => yield r; case void => break; @@ -42,7 +42,7 @@ export fn rtrim(input: str, trim: rune...) str = { let it = riter(input); for (true) { const r = match (prev(&it)) { - case r: rune => + case let r: rune => yield r; case void => break; diff --git a/strio/dynamic.ha b/strio/dynamic.ha @@ -29,7 +29,7 @@ fn get_dynamic_stream(in: io::handle) *dynamic_stream = { match (in) { case io::file => abort("Invalid use of strio on io::file"); - case st: *io::stream => + case let st: *io::stream => assert(st.writer == &dynamic_write, "Invalid use of strio on non-strio I/O stream"); return st: *dynamic_stream; diff --git a/strio/fixed.ha b/strio/fixed.ha @@ -28,7 +28,7 @@ export fn string(in: io::handle) str = { let stream = match (in) { case io::file => abort("Invalid use of strio with io::file"); - case st: *io::stream => + case let st: *io::stream => yield st; }; diff --git a/temp/+freebsd.ha b/temp/+freebsd.ha @@ -65,9 +65,9 @@ export fn named( match (fs::create_file(fs, fpath, fmode, oflags)) { case errors::exists => continue; - case err: fs::error => + case let err: fs::error => return err; - case f: io::file => + case let f: io::file => return (f, strings::dup(fpath)); }; }; @@ -91,7 +91,7 @@ export fn dir() str = { let path = path::join(get_tmpdir(), name); match (os::mkdir(path)) { - case err: fs::error => abort("Could not create temp directory"); + case let err: fs::error => abort("Could not create temp directory"); case void => void; }; return path; diff --git a/temp/+linux.ha b/temp/+linux.ha @@ -35,11 +35,11 @@ export fn file( }; // TODO: Add a custom "close" function which removes the named file match (os::create(get_tmpdir(), fmode, oflags)) { - case err: fs::error => + case let err: fs::error => let file = named(os::cwd, get_tmpdir(), iomode, mode...)?; free(file.1); return file.0; - case f: io::file => + case let f: io::file => return f; }; }; @@ -79,9 +79,9 @@ export fn named( match (fs::create_file(fs, fpath, fmode, oflags)) { case errors::exists => continue; - case err: fs::error => + case let err: fs::error => return err; - case f: io::file => + case let f: io::file => return (f, strings::dup(fpath)); }; }; @@ -105,7 +105,7 @@ export fn dir() str = { let path = path::join(get_tmpdir(), name); match (os::mkdir(path)) { - case err: fs::error => abort("Could not create temp directory"); + case let err: fs::error => abort("Could not create temp directory"); case void => void; }; return path; diff --git a/time/+freebsd/functions.ha b/time/+freebsd/functions.ha @@ -32,7 +32,7 @@ export fn sleep(n: duration) void = { match (rt::nanosleep(req, &res)) { case void => return; - case err: rt::errno => + case let err: rt::errno => switch (err) { case rt::EINTR => req = &res; @@ -80,7 +80,7 @@ export fn now(clock: clock) instant = { match (rt::clock_gettime(clock, &tp)) { case void => return timespec_to_instant(tp); - case err: rt::errno => + case let err: rt::errno => abort("Unexpected error from clock_gettime"); }; }; diff --git a/time/+linux/functions.ha b/time/+linux/functions.ha @@ -33,7 +33,7 @@ export fn sleep(n: duration) void = { match (rt::nanosleep(req, &res)) { case void => return; - case err: rt::errno => + case let err: rt::errno => switch (err) { case rt::EINTR => req = &res; @@ -84,7 +84,7 @@ fn now_vdso(clock: clock, tp: *rt::timespec) (void | rt::errno) = { const vfn = match (cgt_vdso()) { case null => return rt::wrap_errno(rt::ENOSYS); - case vfn: *fn(_: int, _: *rt::timespec) int => + case let vfn: *fn(_: int, _: *rt::timespec) int => yield vfn; }; const ret = vfn(clock, tp); @@ -100,7 +100,7 @@ export fn now(clock: clock) instant = { let err = match (now_vdso(clock, &tp)) { case void => return timespec_to_instant(tp); - case err: rt::errno => + case let err: rt::errno => yield err; }; if (err != rt::wrap_errno(rt::ENOSYS)) { @@ -109,7 +109,7 @@ export fn now(clock: clock) instant = { match (rt::clock_gettime(clock, &tp)) { case void => return timespec_to_instant(tp); - case err: rt::errno => + case let err: rt::errno => abort("Unexpected error from clock_gettime"); }; }; diff --git a/unix/+freebsd/nice.ha b/unix/+freebsd/nice.ha @@ -18,7 +18,7 @@ export fn nice(inc: int) (void | errors::error) = { }; match (rt::setpriority(rt::PRIO_PROCESS, 0, prio)) { case void => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; diff --git a/unix/+freebsd/pipe.ha b/unix/+freebsd/pipe.ha @@ -22,7 +22,7 @@ export fn pipe(flags: pipe_flag...) ((io::file, io::file) | errors::error) = { }; match (rt::pipe2(&fds, flag)) { case void => void; - case e: rt::errno => + case let e: rt::errno => return errors::errno(e); }; return (fds[0], fds[1]); diff --git a/unix/+linux/nice.ha b/unix/+linux/nice.ha @@ -18,7 +18,7 @@ export fn nice(inc: int) (void | errors::error) = { }; match (rt::setpriority(rt::PRIO_PROCESS, 0, prio)) { case void => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; diff --git a/unix/+linux/pipe.ha b/unix/+linux/pipe.ha @@ -22,7 +22,7 @@ export fn pipe(flags: pipe_flag...) ((io::file, io::file) | errors::error) = { }; match (rt::pipe2(&fds, flag)) { case void => void; - case e: rt::errno => + case let e: rt::errno => return errors::errno(e); }; return (fds[0], fds[1]); diff --git a/unix/hosts/lookup.ha b/unix/hosts/lookup.ha @@ -20,7 +20,7 @@ export fn lookup(name: str) []ip::addr = { const line = match (bufio::scanline(file)) { case io::EOF => break; - case line: []u8 => + case let line: []u8 => yield line; }; defer free(line); @@ -34,7 +34,7 @@ export fn lookup(name: str) []ip::addr = { const tok = match (bufio::scantok(scanner, ' ', '\t')!) { case io::EOF => break; - case tok: []u8 => + case let tok: []u8 => yield tok; }; defer free(tok); @@ -44,7 +44,7 @@ export fn lookup(name: str) []ip::addr = { const tok = match (bufio::scantok(scanner, ' ', '\t')!) { case io::EOF => break; - case tok: []u8 => + case let tok: []u8 => yield tok; }; defer free(tok); diff --git a/unix/passwd/group.ha b/unix/passwd/group.ha @@ -20,13 +20,13 @@ export type grent = struct { // the result using [[grent_finish]]. export fn nextgr(in: io::handle) (grent | io::EOF | io::error | invalid) = { let line = match (bufio::scanline(in)?) { - case ln: []u8 => + case let ln: []u8 => yield ln; case io::EOF => return io::EOF; }; let line = match (strings::try_fromutf8(line)) { - case s: str => + case let s: str => yield s; case => return invalid; @@ -40,7 +40,7 @@ export fn nextgr(in: io::handle) (grent | io::EOF | io::error | invalid) = { }; let gid = match (strconv::stou(fields[2])) { - case u: uint => + case let u: uint => yield u; case => return invalid; @@ -67,7 +67,7 @@ export fn grent_finish(ent: grent) void = { // See [[nextgr]] for low-level parsing API. export fn getgroup(name: str) (grent | void) = { let file = match (os::open("/etc/group")) { - case f: io::file => + case let f: io::file => yield f; case => abort("Unable to open /etc/group"); @@ -76,7 +76,7 @@ export fn getgroup(name: str) (grent | void) = { for (true) { let ent = match (nextgr(file)) { - case e: grent => + case let e: grent => yield e; case io::EOF => break; diff --git a/unix/passwd/passwd.ha b/unix/passwd/passwd.ha @@ -28,11 +28,11 @@ export fn nextpw(file: io::handle) (pwent | io::EOF | io::error | invalid) = { let line = match (bufio::scanline(file)?) { case io::EOF => return io::EOF; - case ln: []u8 => + case let ln: []u8 => yield ln; }; let line = match (strings::try_fromutf8(line)) { - case s: str => + case let s: str => yield s; case => return invalid; @@ -46,14 +46,14 @@ export fn nextpw(file: io::handle) (pwent | io::EOF | io::error | invalid) = { }; let uid = match (strconv::stou(fields[2])) { - case u: uint => + case let u: uint => yield u; case => return invalid; }; let gid = match (strconv::stou(fields[3])) { - case u: uint => + case let u: uint => yield u; case => return invalid; @@ -86,7 +86,7 @@ export fn pwent_finish(ent: pwent) void = { // See [[nextpw]] for low-level parsing API. export fn getuser(username: str) (pwent | void) = { let file = match (os::open("/etc/passwd")) { - case f: io::file => + case let f: io::file => yield f; case => abort("Can't open /etc/passwd"); @@ -95,7 +95,7 @@ export fn getuser(username: str) (pwent | void) = { for (true) { let ent = match (nextpw(file)) { - case e: pwent => + case let e: pwent => yield e; case io::EOF => break; diff --git a/unix/poll/+freebsd.ha b/unix/poll/+freebsd.ha @@ -40,9 +40,9 @@ export fn poll( time::duration_to_timespec(timeout, &ts); let ts = if (timeout == INDEF) null else &ts; match (rt::ppoll(fds: *[*]pollfd, len(fds): rt::nfds_t, ts, null)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: int => + case let n: int => return n: uint; }; }; diff --git a/unix/poll/+linux.ha b/unix/poll/+linux.ha @@ -40,9 +40,9 @@ export fn poll( time::duration_to_timespec(timeout, &ts); let ts = if (timeout == INDEF) null else &ts; match (rt::ppoll(fds: *[*]pollfd, len(fds), ts, null)) { - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); - case n: int => + case let n: int => return n: uint; }; }; diff --git a/unix/resolvconf/load.ha b/unix/resolvconf/load.ha @@ -29,7 +29,7 @@ export fn load() []ip::addr = { const line = match (bufio::scanline(file)) { case io::EOF => break; - case line: []u8 => + case let line: []u8 => yield line; }; defer free(line); @@ -43,7 +43,7 @@ export fn load() []ip::addr = { const tok = match (bufio::scantok(scanner, ' ', '\t')!) { case io::EOF => break; - case tok: []u8 => + case let tok: []u8 => yield tok; }; defer free(tok); @@ -54,7 +54,7 @@ export fn load() []ip::addr = { const tok = match (bufio::scantok(scanner, ' ')!) { case io::EOF => break; - case tok: []u8 => + case let tok: []u8 => yield tok; }; defer free(tok); diff --git a/unix/tty/+freebsd/isatty.ha b/unix/tty/+freebsd/isatty.ha @@ -6,9 +6,9 @@ use os; export fn isatty(fd: io::file) bool = { let wsz = rt::winsize { ... }; match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { - case e: rt::errno => + case let e: rt::errno => return false; - case r: int => + case let r: int => return r == 0; }; }; diff --git a/unix/tty/+freebsd/open.ha b/unix/tty/+freebsd/open.ha @@ -7,7 +7,7 @@ use os; // close it using [[io::close]]. export fn open() (io::file | error) = { match (os::open("/dev/tty", fs::flags::RDWR, fs::flags::CLOEXEC)) { - case f: io::file => + case let f: io::file => return f; case fs::error => return errors::noentry; diff --git a/unix/tty/+freebsd/termios.ha b/unix/tty/+freebsd/termios.ha @@ -14,7 +14,7 @@ export fn termios_query(file: io::file) (termios | errors::error) = { match (rt::ioctl(file, rt::TIOCGETA, &settings)) { case int => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; @@ -34,7 +34,7 @@ export fn termios_restore(termios: *const termios) void = { export fn termios_set(termios: *const termios) (void | errors::error) = { match (rt::ioctl(termios.file, rt::TIOCSETA, &termios.current)) { case int => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; diff --git a/unix/tty/+freebsd/winsize.ha b/unix/tty/+freebsd/winsize.ha @@ -7,7 +7,7 @@ use rt; export fn winsize(fd: io::file) (ttysize | error) = { let wsz = rt::winsize { ... }; match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { - case e: rt::errno => + case let e: rt::errno => switch (e: int) { case rt::EBADF => return errors::invalid; diff --git a/unix/tty/+linux/isatty.ha b/unix/tty/+linux/isatty.ha @@ -6,9 +6,9 @@ use os; export fn isatty(fd: io::file) bool = { let wsz = rt::winsize { ... }; match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { - case e: rt::errno => + case let e: rt::errno => return false; - case r: int => + case let r: int => return r == 0; }; }; diff --git a/unix/tty/+linux/open.ha b/unix/tty/+linux/open.ha @@ -7,7 +7,7 @@ use os; // close it using [[io::close]]. export fn open() (io::file | error) = { match (os::open("/dev/tty", fs::flags::RDWR, fs::flags::CLOEXEC)) { - case f: io::file => + case let f: io::file => return f; case fs::error => return errors::noentry; diff --git a/unix/tty/+linux/termios.ha b/unix/tty/+linux/termios.ha @@ -14,7 +14,7 @@ export fn termios_query(file: io::file) (termios | errors::error) = { match (rt::ioctl(file, rt::TCGETS, &settings)) { case int => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; @@ -34,7 +34,7 @@ export fn termios_restore(termios: *const termios) void = { export fn termios_set(termios: *const termios) (void | errors::error) = { match (rt::ioctl(termios.file, rt::TCSETS, &termios.current)) { case int => void; - case err: rt::errno => + case let err: rt::errno => return errors::errno(err); }; }; diff --git a/unix/tty/+linux/winsize.ha b/unix/tty/+linux/winsize.ha @@ -7,7 +7,7 @@ use rt; export fn winsize(fd: io::file) (ttysize | error) = { let wsz = rt::winsize { ... }; match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { - case e: rt::errno => + case let e: rt::errno => switch (e: int) { case rt::EBADFD => return errors::invalid; diff --git a/uuid/uuid.ha b/uuid/uuid.ha @@ -113,7 +113,7 @@ export fn decode(in: io::handle) (uuid | invalid | io::error) = { match (io::read(in, buf)?) { case io::EOF => return invalid; - case z: size => + case let z: size => assert(z == len(buf)); }; u[i] = match (strconv::stou8b( @@ -123,7 +123,7 @@ export fn decode(in: io::handle) (uuid | invalid | io::error) = { abort(); case strconv::invalid => return invalid; - case u: u8 => + case let u: u8 => yield u; }; if (i + 1 == TIME_MID @@ -133,7 +133,7 @@ export fn decode(in: io::handle) (uuid | invalid | io::error) = { match (io::read(in, buf[..1])?) { case io::EOF => return invalid; - case z: size => + case let z: size => assert(z == 1); }; if (buf[0] != '-': u32: u8) { @@ -149,11 +149,11 @@ export fn decodestr(in: str) (uuid | invalid) = { let buf = bufio::fixed(strings::toutf8(in), io::mode::READ); defer io::close(buf); match (decode(buf)) { - case err: io::error => + case let err: io::error => abort(); case invalid => return invalid; - case u: uuid => + case let u: uuid => return u; }; }; @@ -163,7 +163,7 @@ export fn decodestr(in: str) (uuid | invalid) = { let id = match (decodestr(in)) { case invalid => abort(); - case u: uuid => + case let u: uuid => yield u; }; assert(compare(id, [