commit 6d742c153fc816775636fa8b69864620a5ae16d7 parent 017c8082e9d51cf440285eeb623dc19086e15c58 Author: Sebastian <sebastian@sebsite.pw> Date: Mon, 21 Aug 2023 01:46:38 -0400 Use opaque type Also renames errors::opaque to errors::opaque_. The name isn't great, but neither is errors:: in general so we'll figure something out Signed-off-by: Sebastian <sebastian@sebsite.pw> Diffstat:
66 files changed, 219 insertions(+), 219 deletions(-)
diff --git a/cmd/hare/deps.ha b/cmd/hare/deps.ha @@ -54,7 +54,7 @@ fn explore_deps(ctx: *module::context, stack: *[]str, visited: *[]depnode, ident }; // sorts in reverse -fn cmpsz(a: const *void, b: const *void) int = (*(b: *size) - *(a: *size)): int; +fn cmpsz(a: const *opaque, b: const *opaque) int = (*(b: *size) - *(a: *size)): int; type link = struct { depth: uint, diff --git a/cmd/haredoc/sort.ha b/cmd/haredoc/sort.ha @@ -74,7 +74,7 @@ fn sort_decls(decls: []ast::decl) summary = { return sorted; }; -fn decl_cmp(a: const *void, b: const *void) int = { +fn decl_cmp(a: const *opaque, b: const *opaque) int = { const a = *(a: const *ast::decl); const b = *(b: const *ast::decl); if (a.docs == "" && b.docs != "") { diff --git a/errors/common.ha b/errors/common.ha @@ -57,5 +57,5 @@ export type error = !( nomem | interrupted | again | - opaque + opaque_ ); diff --git a/errors/opaque.ha b/errors/opaque.ha @@ -9,9 +9,9 @@ // // The following example shows the usage of this type for custom errors: // -// fn wraperror(err: myerror) error::opaque = { +// fn wraperror(err: myerror) error::opaque_ = { // static assert(size(myerror) <= size(errors::opaque_data)); -// let wrapped = errors::opaque { strerror = &opaque_strerror, ... }; +// let wrapped = errors::opaque_ { strerror = &opaque_strerror, ... }; // let myptr = &wrapped.data: *myerror; // *myptr = err; // return wrapped; @@ -21,7 +21,7 @@ // let ptr = &err: *myerr; // return strerror(*ptr); // }; -export type opaque = !struct { +export type opaque_ = !struct { strerror: *fn(op: *opaque_data) const str, data: opaque_data, }; diff --git a/errors/rt.ha b/errors/rt.ha @@ -2,7 +2,7 @@ // (c) 2021 Drew DeVault <sir@cmpwn.com> use rt; -// Wraps an [[rt::errno]] to produce an [[errors::opaque]]. This is a non-portable +// Wraps an [[rt::errno]] to produce an [[errors::opaque_]]. This is a non-portable // interface which is mainly provided to support internal stdlib requirements. export fn errno(errno: rt::errno) error = { switch (errno) { @@ -32,7 +32,7 @@ export fn errno(errno: rt::errno) error = { }; static assert(size(rt::errno) <= size(opaque_data)); - let err = opaque { strerror = &rt_strerror, ... }; + let err = opaque_ { strerror = &rt_strerror, ... }; let ptr = &err.data: *rt::errno; *ptr = errno; return err; diff --git a/errors/string.ha b/errors/string.ha @@ -39,6 +39,6 @@ case interrupted => yield "Operation interrupted"; case again => yield "Try again"; -case let op: opaque => +case let op: opaque_ => yield op.strerror(&op.data); }; diff --git a/fmt/fmt.ha b/fmt/fmt.ha @@ -21,7 +21,7 @@ export type field = (...formattable | *modifiers); // Tagged union of all types which are formattable. export type formattable = (...types::numeric | uintptr | str | rune | bool | - nullable *void | void); + nullable *opaque | void); // Formats text for printing and writes it to [[os::stdout]]. export fn printf(fmt: str, args: field...) (size | io::error) = @@ -357,9 +357,9 @@ fn format_raw( case let p: uintptr => const s = strconv::uptrtosb(p, mod.base); return io::write(out, strings::toutf8(s)); - case let v: nullable *void => + case let v: nullable *opaque => match (v) { - case let v: *void => + case let v: *opaque => let z = io::write(out, strings::toutf8("0x"))?; const s = strconv::uptrtosb(v: uintptr, strconv::base::HEX_LOWER); diff --git a/format/elf/types.ha b/format/elf/types.ha @@ -852,7 +852,7 @@ export type auxv64 = struct { union { // Integer value a_val: u64, - a_ptr: *void, + a_ptr: *opaque, a_fnc: *fn() void, } }; diff --git a/glob/glob.ha b/glob/glob.ha @@ -317,7 +317,7 @@ fn strstack_sort(ss: *strstack, pos: size) void = { sort::sort(s, size(memio::stream), &bufcmp); }; -fn bufcmp(a: const *void, b: const *void) int = +fn bufcmp(a: const *opaque, b: const *opaque) int = strings::compare( memio::string(b: *memio::stream)!, memio::string(a: *memio::stream)!, diff --git a/hare/types/+test.ha b/hare/types/+test.ha @@ -40,7 +40,7 @@ fn parse_type(in: str) ast::_type = { }; fn resolve( - rstate: nullable *void, + rstate: nullable *opaque, store: *typestore, expr: const *ast::expr, ) (size | deferred | error) = { diff --git a/hare/types/store.ha b/hare/types/store.ha @@ -12,7 +12,7 @@ export def BUCKETS: size = 65535; // A function which evaluates a [[hare::ast::expr]], providing either a size // result or an error. export type resolver = fn( - rstate: nullable *void, + rstate: nullable *opaque, store: *typestore, expr: const *ast::expr, ) (size | deferred | error); @@ -25,7 +25,7 @@ export type typestore = struct { arch: arch, resolve: nullable *resolver, - rstate: nullable *void, + rstate: nullable *opaque, }; // Initializes a new type store. Optionally, provide a function which @@ -35,7 +35,7 @@ export type typestore = struct { export fn store( arch: arch, resolver: nullable *resolver, - rstate: nullable *void, + rstate: nullable *opaque, ) *typestore = alloc(typestore { arch = arch, resolve = resolver, @@ -107,13 +107,13 @@ export type deferred = !void; export type noresolver = !void; // All possible errors for [[lookup]]. -export type error = !(noresolver | errors::opaque); +export type error = !(noresolver | errors::opaque_); // Convert an error into a human-friendly string. export fn strerror(err: error) const str = match (err) { case noresolver => return "Resolver function not provided, but required"; -case let err: errors::opaque => +case let err: errors::opaque_ => return errors::strerror(err); }; @@ -510,7 +510,7 @@ fn tagged_collect( }; }; -fn tagged_cmp(a: const *void, b: const *void) int = { +fn tagged_cmp(a: const *opaque, b: const *opaque) int = { const a = a: const **_type, b = b: const **_type; return if (a.id < b.id) -1 else if (a.id == b.id) 0 else 1; }; @@ -558,7 +558,7 @@ fn tuple_from_ast( return values; }; -fn field_cmp(a: const *void, b: const *void) int = { +fn field_cmp(a: const *opaque, b: const *opaque) int = { const a = a: const *struct_field, b = b: *const struct_field; return strings::compare(a.name, b.name); }; diff --git a/io/+freebsd/mmap.ha b/io/+freebsd/mmap.ha @@ -34,15 +34,15 @@ export type mflag = enum uint { // Performs the mmap syscall. Consult your system for documentation on this // function. export fn mmap( - addr: nullable *void, + addr: nullable *opaque, length: size, prot: prot, flags: mflag, fd: file, offs: size -) (*void | errors::error) = { +) (*opaque | errors::error) = { match (rt::mmap(addr, length, prot, flags, fd, offs)) { - case let ptr: *void => + case let ptr: *opaque => return ptr; case let err: rt::errno => return errors::errno(err); @@ -50,7 +50,7 @@ export fn mmap( }; // Unmaps memory previously mapped with [[mmap]]. -export fn munmap(addr: *void, length: size) (void | errors::error) = { +export fn munmap(addr: *opaque, length: size) (void | errors::error) = { match (rt::munmap(addr, length)) { case void => return; diff --git a/io/+linux/mmap.ha b/io/+linux/mmap.ha @@ -54,15 +54,15 @@ export type mflag = enum uint { // Performs the mmap syscall. Consult your system for documentation on this // function. export fn mmap( - addr: nullable *void, + addr: nullable *opaque, length: size, prot: prot, flags: mflag, fd: file, offs: size -) (*void | errors::error) = { +) (*opaque | errors::error) = { match (rt::mmap(addr, length, prot, flags, fd, offs)) { - case let ptr: *void => + case let ptr: *opaque => return ptr; case let err: rt::errno => return errors::errno(err); @@ -70,7 +70,7 @@ export fn mmap( }; // Unmaps memory previously mapped with [[mmap]]. -export fn munmap(addr: *void, length: size) (void | errors::error) = { +export fn munmap(addr: *opaque, length: size) (void | errors::error) = { match (rt::munmap(addr, length)) { case void => return; diff --git a/linux/keyctl/keyctl.ha b/linux/keyctl/keyctl.ha @@ -24,7 +24,7 @@ export fn add_key( const name = c::fromstr(name); defer free(name); match (rt::add_key(keytype: *const u8, name: *const u8, - payload: *[*]u8: *void, len(payload), keyring)) { + payload: *[*]u8: *opaque, len(payload), keyring)) { case let err: rt::errno => return errno(err); case let n: int => @@ -87,7 +87,7 @@ export fn read(id: serial, buf: []u8) (size | error) = { const buf = if (len(buf) == 0) { yield null; } else { - yield buf: *[*]u8: *void; + yield buf: *[*]u8: *opaque; }; return keyctl(command::READ, id: u64, buf: uintptr: u64, bufln: u64, 0)?: size; diff --git a/linux/vdso/vdso.ha b/linux/vdso/vdso.ha @@ -52,7 +52,7 @@ fn get_vdso_ctx() nullable *vdso_ctx = { const ehui = eh: uintptr; let phui = ehui + eh.e_phoff: uintptr; let dynvec: nullable *[*]elf::dyn64 = null; - let baseseg: nullable *void = null; + let baseseg: nullable *opaque = null; for (let i: u16 = 0; i < eh.e_phnum; i += 1) { const ph = phui: *elf::phdr64; @@ -60,7 +60,7 @@ fn get_vdso_ctx() nullable *vdso_ctx = { case elf::pt::LOAD => baseseg = (ehui + ph.p_offset: uintptr - - ph.p_vaddr: uintptr): nullable *void; + ph.p_vaddr: uintptr): nullable *opaque; case elf::pt::DYNAMIC => dynvec = (ehui + ph.p_offset: uintptr): *[*]elf::dyn64; @@ -82,7 +82,7 @@ fn get_vdso_ctx() nullable *vdso_ctx = { let verdef: nullable *elf::verdef64 = null; for (let i = 0; dynv[i].d_tag != elf::dt::NULL; i += 1) { - const tabptr = (segbase + dynv[i].d_val: uintptr): *void; + const tabptr = (segbase + dynv[i].d_val: uintptr): *opaque; switch (dynv[i].d_tag) { case elf::dt::STRTAB => stringtab = tabptr: *c::char; @@ -150,7 +150,7 @@ fn vdso_checkver(ctx: *vdso_ctx, version: str, num: u32) bool = { return false; }; -export fn getsym(symname: str, symver: str) nullable *void = { +export fn getsym(symname: str, symver: str) nullable *opaque = { const ctx = match (get_vdso_ctx()) { case null => return null; @@ -180,7 +180,7 @@ export fn getsym(symname: str, symver: str) nullable *void = { continue; if (!vdso_checkver(ctx, symver, i)) continue; - return (ctx.segbase + sym.st_value: uintptr): *void; + return (ctx.segbase + sym.st_value: uintptr): *opaque; }; return null; }; diff --git a/net/ip/+freebsd.ha b/net/ip/+freebsd.ha @@ -12,7 +12,7 @@ export fn to_native(a: addr, port: u16) rt::sockaddr = { sin_len = size(rt::in_addr): u8, sin_family = rt::AF_INET, sin_port = endian::htonu16(port), - sin_addr = rt::in_addr { s_addr = *(&v4[0]: *void: *u32) }, + sin_addr = rt::in_addr { s_addr = *(&v4[0]: *opaque: *u32) }, ... }, ... diff --git a/net/ip/+linux.ha b/net/ip/+linux.ha @@ -12,7 +12,7 @@ export fn to_native(a: addr, port: u16) rt::sockaddr = { in = rt::sockaddr_in { sin_family = rt::AF_INET, sin_port = endian::htonu16(port), - sin_addr = rt::in_addr { s_addr = *(&v4[0]: *void: *u32) }, + sin_addr = rt::in_addr { s_addr = *(&v4[0]: *opaque: *u32) }, ... }, ... diff --git a/net/msg.ha b/net/msg.ha @@ -59,7 +59,7 @@ export fn getflags(msg: *msghdr) int = { }; // Sets name for this message. -export fn setname(msg: *msghdr, name: *void, length: size) void = { +export fn setname(msg: *msghdr, name: *opaque, length: size) void = { msg.native.msg_name = name; msg.native.msg_namelen = length: u32; }; diff --git a/net/tcp/+freebsd.ha b/net/tcp/+freebsd.ha @@ -152,7 +152,7 @@ fn setsockopt( ) (void | net::error) = { let val: int = if (value) 1 else 0; match (rt::setsockopt(sockfd, rt::SOL_SOCKET, option, - &val: *void, size(int): u32)) { + &val: *opaque, size(int): u32)) { case let err: rt::errno => return errors::errno(err); case int => void; diff --git a/net/tcp/+linux.ha b/net/tcp/+linux.ha @@ -151,7 +151,7 @@ fn setsockopt( ) (void | net::error) = { let val: int = if (value) 1 else 0; match (rt::setsockopt(sockfd, rt::SOL_SOCKET, option, - &val: *void, size(int): u32)) { + &val: *opaque, size(int): u32)) { case let err: rt::errno => return errors::errno(err); case int => void; diff --git a/net/udp/+freebsd.ha b/net/udp/+freebsd.ha @@ -190,7 +190,7 @@ fn setsockopt( ) (void | net::error) = { let val: int = if (value) 1 else 0; match (rt::setsockopt(sockfd, rt::SOL_SOCKET, option, - &val: *void, size(int): u32)) { + &val: *opaque, size(int): u32)) { case let err: rt::errno => return errors::errno(err); case int => void; diff --git a/net/udp/+linux.ha b/net/udp/+linux.ha @@ -190,7 +190,7 @@ fn setsockopt( ) (void | net::error) = { let val: int = if (value) 1 else 0; match (rt::setsockopt(sockfd, rt::SOL_SOCKET, option, - &val: *void, size(int): u32)) { + &val: *opaque, size(int): u32)) { case let err: rt::errno => return errors::errno(err); case int => void; diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha @@ -358,7 +358,7 @@ fn fs_iter(fs: *fs::fs, path: str) (*fs::iterator | fs::error) = { }; let buf = match (rt::malloc(fs.getdents_bufsz)) { - case let v: *void => + case let v: *opaque => yield v: *[*]u8; case null => return errors::nomem; diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -401,7 +401,7 @@ fn fs_iter(fs: *fs::fs, path: str) (*fs::iterator | fs::error) = { }; let buf = match (rt::malloc(fs.getdents_bufsz)) { - case let v: *void => + case let v: *opaque => yield v: *[*]u8; case null => return errors::nomem; diff --git a/os/+linux/memory.ha b/os/+linux/memory.ha @@ -11,7 +11,7 @@ export type mcl = enum uint { // Locks a region of memory so that it will not be written to swap. export fn mlock( - addr: *void, + addr: *opaque, length: size, flags: mcl, ) (void | errors::error) = { @@ -24,7 +24,7 @@ export fn mlock( }; // Unlocks memory previously locked with [[mlock]]. -export fn munlock(addr: *void, length: size) (void | errors::error) = { +export fn munlock(addr: *opaque, length: size) (void | errors::error) = { match (rt::munlock(addr, length)) { case let err: rt::errno => return errors::errno(err); diff --git a/os/exec/exec+freebsd.ha b/os/exec/exec+freebsd.ha @@ -206,10 +206,10 @@ fn platform_start(cmd: *command) (process | errors::error) = { case void => rt::close(pipe[0])!; let err = platform_exec(cmd); - if (!(err is errors::opaque)) { + if (!(err is errors::opaque_)) { rt::exit(1); }; - let err = err as errors::opaque; + let err = err as errors::opaque_; let err = &err.data: *rt::errno; rt::write(pipe[1], err, size(int))!; rt::exit(1); diff --git a/os/exec/exec+linux.ha b/os/exec/exec+linux.ha @@ -207,10 +207,10 @@ fn platform_start(cmd: *command) (process | errors::error) = { case void => rt::close(pipe[0])!; let err = platform_exec(cmd); - if (!(err is errors::opaque)) { + if (!(err is errors::opaque_)) { rt::exit(1); }; - let err = err as errors::opaque; + let err = err as errors::opaque_; let err = &err.data: *rt::errno; rt::write(pipe[1], err, size(int))!; rt::exit(1); diff --git a/rt/+aarch64/backtrace.ha b/rt/+aarch64/backtrace.ha @@ -3,12 +3,12 @@ // (c) 2021 Mykyta Holubakha <hilobakho@gmail.com> // (c) 2021 Sudipto Mallick <smlckz@disroot.org> -fn getfp() **void; +fn getfp() **opaque; // Details for a stack frame. Contents are architecture-specific. export type frame = struct { fp: nullable *frame, - lr: nullable *void, + lr: nullable *opaque, }; // Returns the caller's stack frame. Call [[nextframe]] to walk the stack. diff --git a/rt/+freebsd/+aarch64.ha b/rt/+freebsd/+aarch64.ha @@ -5,7 +5,7 @@ export type siginfo = struct { si_pid: pid_t, si_uid: uid_t, si_status: int, - si_addr: *void, + si_addr: *opaque, si_value: sigval, _reason: union { _fault: struct { diff --git a/rt/+freebsd/+riscv64.ha b/rt/+freebsd/+riscv64.ha @@ -5,7 +5,7 @@ export type siginfo = struct { si_pid: pid_t, si_uid: uid_t, si_status: int, - si_addr: *void, + si_addr: *opaque, si_value: sigval, _reason: union { _fault: struct { diff --git a/rt/+freebsd/+x86_64.ha b/rt/+freebsd/+x86_64.ha @@ -5,7 +5,7 @@ export type siginfo = struct { si_pid: pid_t, si_uid: uid_t, si_status: int, - si_addr: *void, + si_addr: *opaque, si_value: sigval, _reason: union { _fault: struct { diff --git a/rt/+freebsd/platform_abort.ha b/rt/+freebsd/platform_abort.ha @@ -5,11 +5,11 @@ const prefix = "Abort: "; const sep = ": "; const linefeed = "\n"; - write(STDERR_FILENO, *(&prefix: **void): *const u8, len(prefix)): void; - write(STDERR_FILENO, *(&loc: **void): *const u8, len(loc)): void; - write(STDERR_FILENO, *(&sep: **void): *const u8, len(sep)): void; - write(STDERR_FILENO, *(&msg: **void): *const u8, len(msg)): void; - write(STDERR_FILENO, *(&linefeed: **void): *const u8, 1): void; + write(STDERR_FILENO, *(&prefix: **opaque): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&loc: **opaque): *const u8, len(loc)): void; + write(STDERR_FILENO, *(&sep: **opaque): *const u8, len(sep)): void; + write(STDERR_FILENO, *(&msg: **opaque): *const u8, len(msg)): void; + write(STDERR_FILENO, *(&linefeed: **opaque): *const u8, 1): void; kill(getpid(), SIGABRT): void; for (true) void; }; diff --git a/rt/+freebsd/segmalloc.ha b/rt/+freebsd/segmalloc.ha @@ -3,19 +3,19 @@ // (c) 2021 Ember Sawady <ecs@d2evs.net> // Allocates a segment. -fn segmalloc(n: size) nullable *void = { +fn segmalloc(n: size) nullable *opaque = { return match (mmap(null, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) { case let err: errno => assert(err == ENOMEM: errno); yield null; - case let p: *void => + case let p: *opaque => yield p; }; }; // Frees a segment allocated with segmalloc. -fn segfree(p: *void, s: size) void = { +fn segfree(p: *opaque, s: size) void = { match (munmap(p, s)) { case let err: errno => abort("munmap failed"); diff --git a/rt/+freebsd/socket.ha b/rt/+freebsd/socket.ha @@ -54,13 +54,13 @@ export def SCM_RIGHTS: int = 0x01; export def SCM_CREDENTIALS: int = 0x02; export type msghdr = struct { - msg_name: nullable *void, + msg_name: nullable *opaque, msg_namelen: socklen_t, msg_iov: nullable *[*]iovec, msg_iovlen: int, - msg_control: nullable *void, + msg_control: nullable *opaque, msg_controllen: socklen_t, msg_flags: int diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha @@ -43,12 +43,12 @@ fn kpath(path: path) (*const u8 | errno) = { return copy_kpath(path, pathbuf); }; -export fn read(fd: int, buf: *void, count: size) (size | errno) = { +export fn read(fd: int, buf: *opaque, count: size) (size | errno) = { return wrap_return(syscall3(SYS_read, fd: u64, buf: uintptr: u64, count: u64))?: size; }; -export fn write(fd: int, buf: *const void, count: size) (size | errno) = { +export fn write(fd: int, buf: *const opaque, count: size) (size | errno) = { return wrap_return(syscall3(SYS_write, fd: u64, buf: uintptr: u64, count: u64))?: size; }; @@ -80,7 +80,7 @@ export fn pipe2(pipefd: *[2]int, flags: int) (void | errno) = { wrap_return(syscall2(SYS_pipe2, pipefd: uintptr: u64, flags: u64))?; }; -export fn ioctl(fd: int, req: u64, arg: nullable *void) (int | errno) = { +export fn ioctl(fd: int, req: u64, arg: nullable *opaque) (int | errno) = { return wrap_return(syscall3(SYS_ioctl, fd: u64, req, arg: uintptr: u64))?: int; }; @@ -214,7 +214,7 @@ export fn access(path: path, mode: int) (bool | errno) = faccessat(AT_FDCWD, path, mode, 0); // TODO: Consider updating this to use SYS_freebsd11_getdirentries -export fn getdents(dirfd: int, buf: *void, nbytes: size) (size | errno) = { +export fn getdents(dirfd: int, buf: *opaque, nbytes: size) (size | errno) = { return wrap_return(syscall3(SYS_freebsd11_getdents, dirfd: u64, buf: uintptr: u64, nbytes: u64))?: size; }; @@ -244,19 +244,19 @@ export fn chroot(path: path) (void | errno) = { }; export fn mmap( - addr: nullable *void, + addr: nullable *opaque, length: size, prot: uint, flags: uint, fd: int, offs: size -) (errno | *void) = { +) (errno | *opaque) = { return wrap_return(syscall6(SYS_mmap, addr: uintptr: u64, length: u64, prot: u64, flags: u64, - fd: u64, offs: u64))?: uintptr: *void; + fd: u64, offs: u64))?: uintptr: *opaque; }; -export fn munmap(addr: *void, length: size) (void | errno) = { +export fn munmap(addr: *opaque, length: size) (void | errno) = { wrap_return(syscall2(SYS_munmap, addr: uintptr: u64, length: u64))?; }; @@ -364,7 +364,7 @@ export fn nanosleep(req: *const timespec, rem: *timespec) (void | errno) = { req: uintptr: u64, rem: uintptr: u64))?; }; -export fn getrandom(buf: *void, bufln: size, flags: uint) (size | errno) = { +export fn getrandom(buf: *opaque, bufln: size, flags: uint) (size | errno) = { return wrap_return(syscall3(SYS_getrandom, buf: uintptr: u64, bufln: u64, flags: u64))?: size; }; @@ -443,7 +443,7 @@ export fn accept4(sockfd: int, addr: nullable *sockaddr, addrlen: nullable *u32, sockfd: u64, addr: uintptr: u64, addrlen: uintptr: u64, flags: u64))?: int; }; -export fn recvfrom(sockfd: int, buf: *void, len_: size, flags: int, +export fn recvfrom(sockfd: int, buf: *opaque, len_: size, flags: int, src_addr: nullable *sockaddr, addrlen: nullable *u32 ) (size | errno) = { return wrap_return(syscall6(SYS_recvfrom, @@ -451,7 +451,7 @@ export fn recvfrom(sockfd: int, buf: *void, len_: size, flags: int, src_addr: uintptr: u64, addrlen: uintptr: u64))?: size; }; -export fn sendto(sockfd: int, buf: *void, len_: size, flags: int, +export fn sendto(sockfd: int, buf: *opaque, len_: size, flags: int, dest_addr: nullable *sockaddr, addrlen: u32 ) (size | errno) = { return wrap_return(syscall6(SYS_sendto, @@ -459,11 +459,11 @@ export fn sendto(sockfd: int, buf: *void, len_: size, flags: int, dest_addr: uintptr: u64, addrlen: u64))?: size; }; -export fn recv(sockfd: int, buf: *void, len_: size, flags: int) (size | errno) = { +export fn recv(sockfd: int, buf: *opaque, len_: size, flags: int) (size | errno) = { return recvfrom(sockfd, buf, len_, flags, null, null); }; -export fn send(sockfd: int, buf: *void, len_: size, flags: int) (size | errno) = { +export fn send(sockfd: int, buf: *opaque, len_: size, flags: int) (size | errno) = { return sendto(sockfd, buf, len_, flags, null, 0); }; @@ -477,13 +477,13 @@ export fn recvmsg(fd: int, msg: *const msghdr, flags: int) (int | errno) = { fd: u64, msg: uintptr: u64, flags: u64))?: int; }; -export fn getsockopt(sockfd: int, level: int, optname: int, optval: nullable *void, optlen: nullable *u32) (int | errno) = { +export fn getsockopt(sockfd: int, level: int, optname: int, optval: nullable *opaque, optlen: nullable *u32) (int | errno) = { return wrap_return(syscall5(SYS_getsockopt, sockfd: u64, level: u64, optname: u64, optval: uintptr: u64, optlen: uintptr: u64))?: int; }; -export fn setsockopt(sockfd: int, level: int, optname: int, optval: *void, optlen: u32) (int | errno) = { +export fn setsockopt(sockfd: int, level: int, optname: int, optval: *opaque, optlen: u32) (int | errno) = { return wrap_return(syscall5(SYS_setsockopt, sockfd: u64, level: u64, optname: u64, optval: uintptr: u64, optlen: u64))?: int; @@ -499,8 +499,8 @@ export fn getpeername(sockfd: int, addr: nullable *sockaddr, addrlen: nullable * sockfd: u64, addr: uintptr: u64, addrlen: uintptr: u64))?: int; }; -export fn sysctlbyname(name: str, oldp: nullable *void, oldlenp: nullable *size, - newp: nullable *const void, newlen: size) (void | errno) = { +export fn sysctlbyname(name: str, oldp: nullable *opaque, oldlenp: nullable *size, + newp: nullable *const opaque, newlen: size) (void | errno) = { let kname = kpath(name)?; wrap_return(syscall6(SYS___sysctlbyname, kname: uintptr: u64, len(name): u64, @@ -526,9 +526,9 @@ export fn flock(fd: int, op: int) (void | errno) = { fd: u64, op: u64))?; }; -export fn shmat(id: int, addr: *const void, flag: int) *void = { +export fn shmat(id: int, addr: *const opaque, flag: int) *opaque = { return syscall3(SYS_shmat, id: u64, addr: uintptr: u64, - flag: u64): uintptr: *void; + flag: u64): uintptr: *opaque; }; export fn getrlimit(resource: int, rlim: *rlimit) (void | errno) = { diff --git a/rt/+freebsd/types.ha b/rt/+freebsd/types.ha @@ -45,7 +45,7 @@ export def SIG_HOLD: uintptr = 3; export type sigact = struct { union { sa_handler: *fn (int) void, - sa_sigaction: *fn (int, *siginfo, *void) void, + sa_sigaction: *fn (int, *siginfo, *opaque) void, }, sa_flags: int, sa_mask: sigset, @@ -57,7 +57,7 @@ export def SIG_SETMASK: int = 3; export type sigval = union { sival_t: int, - sival_ptr: *void, + sival_ptr: *opaque, }; export type pollfd = struct { @@ -132,7 +132,7 @@ export type freebsd11_dirent = struct { }; export type iovec = struct { - iov_base: *void, + iov_base: *opaque, iov_len: size }; diff --git a/rt/+linux/+aarch64.ha b/rt/+linux/+aarch64.ha @@ -9,7 +9,7 @@ def __ADDR_BND_PKEY_PAD: size = 8; // Returns the new PID to the parent, void to the child, or errno if something // goes wrong. export fn clone( - stack: nullable *void, + stack: nullable *opaque, flags: int, parent_tid: nullable *int, child_tid: nullable *int, diff --git a/rt/+linux/+riscv64.ha b/rt/+linux/+riscv64.ha @@ -9,7 +9,7 @@ def __ADDR_BND_PKEY_PAD: size = 8; // Returns the new PID to the parent, void to the child, or errno if something // goes wrong. export fn clone( - stack: nullable *void, + stack: nullable *opaque, flags: int, parent_tid: nullable *int, child_tid: nullable *int, diff --git a/rt/+linux/+x86_64.ha b/rt/+linux/+x86_64.ha @@ -8,7 +8,7 @@ def __ADDR_BND_PKEY_PAD: size = 8; // Returns the new PID to the parent, void to the child, or errno if something // goes wrong. export fn clone( - stack: nullable *void, + stack: nullable *opaque, flags: int, parent_tid: nullable *int, child_tid: nullable *int, diff --git a/rt/+linux/platform_abort.ha b/rt/+linux/platform_abort.ha @@ -5,11 +5,11 @@ const prefix = "Abort: "; const sep = ": "; const linefeed = "\n"; - write(STDERR_FILENO, *(&prefix: **void): *const u8, len(prefix)): void; - write(STDERR_FILENO, *(&loc: **void): *const u8, len(loc)): void; - write(STDERR_FILENO, *(&sep: **void): *const u8, len(sep)): void; - write(STDERR_FILENO, *(&msg: **void): *const u8, len(msg)): void; - write(STDERR_FILENO, *(&linefeed: **void): *const u8, 1): void; + write(STDERR_FILENO, *(&prefix: **opaque): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&loc: **opaque): *const u8, len(loc)): void; + write(STDERR_FILENO, *(&sep: **opaque): *const u8, len(sep)): void; + write(STDERR_FILENO, *(&msg: **opaque): *const u8, len(msg)): void; + write(STDERR_FILENO, *(&linefeed: **opaque): *const u8, 1): void; kill(getpid(), SIGABRT): void; for (true) void; }; diff --git a/rt/+linux/segmalloc.ha b/rt/+linux/segmalloc.ha @@ -3,19 +3,19 @@ // (c) 2021 Ember Sawady <ecs@d2evs.net> // Allocates a segment. -fn segmalloc(n: size) nullable *void = { +fn segmalloc(n: size) nullable *opaque = { return match (mmap(null, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0)) { case let err: errno => assert(err == ENOMEM: errno); yield null; - case let p: *void => + case let p: *opaque => yield p; }; }; // Frees a segment allocated with segmalloc. -fn segfree(p: *void, s: size) void = { +fn segfree(p: *opaque, s: size) void = { match (munmap(p, s)) { case let err: errno => abort("munmap failed"); diff --git a/rt/+linux/socket.ha b/rt/+linux/socket.ha @@ -59,13 +59,13 @@ export def SCM_RIGHTS: int = 0x01; export def SCM_CREDENTIALS: int = 0x02; export type msghdr = struct { - msg_name: nullable *void, + msg_name: nullable *opaque, msg_namelen: u32, msg_iov: nullable *[*]iovec, msg_iovlen: size, - msg_control: nullable *void, + msg_control: nullable *opaque, msg_controllen: size, msg_flags: int diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -46,12 +46,12 @@ fn kpath(path: path) (*const u8 | errno) = { return copy_kpath(path, pathbuf); }; -export fn read(fd: int, buf: *void, count: size) (size | errno) = { +export fn read(fd: int, buf: *opaque, count: size) (size | errno) = { return wrap_return(syscall3(SYS_read, fd: u64, buf: uintptr: u64, count: u64))?: size; }; -export fn write(fd: int, buf: *const void, count: size) (size | errno) = { +export fn write(fd: int, buf: *const opaque, count: size) (size | errno) = { return wrap_return(syscall3(SYS_write, fd: u64, buf: uintptr: u64, count: u64))?: size; }; @@ -291,13 +291,13 @@ export fn pipe2(pipefd: *[2]int, flags: int) (void | errno) = { }; export fn mmap( - addr: nullable *void, + addr: nullable *opaque, length: size, prot: uint, flags: uint, fd: int, offs: size -) (*void | errno) = { +) (*opaque | errno) = { let r = syscall6(SYS_mmap, addr: uintptr: u64, length: u64, prot: u64, flags: u64, fd: u64, offs: u64); match (wrap_return(r)) { @@ -309,28 +309,28 @@ export fn mmap( }; return err; case let n: u64 => - return n: uintptr: *void; + return n: uintptr: *opaque; }; }; export fn mremap( - old_addr: *void, + old_addr: *opaque, old_len: size, new_len: size, flags: uint, - new_addr: nullable *void, -) (*void | errno) = { + new_addr: nullable *opaque, +) (*opaque | errno) = { let r = syscall5(SYS_mremap, old_addr: uintptr: u64, old_len: u64, new_len: u64, flags: u64, new_addr: uintptr: u64); - return wrap_return(r)?: uintptr: *void; + return wrap_return(r)?: uintptr: *opaque; }; -export fn munmap(addr: *void, length: size) (void | errno) = { +export fn munmap(addr: *opaque, length: size) (void | errno) = { wrap_return(syscall2(SYS_munmap, addr: uintptr: u64, length: u64))?; }; -export fn mprotect(addr: *void, length: size, prot: uint) (void | errno) = { +export fn mprotect(addr: *opaque, length: size, prot: uint) (void | errno) = { wrap_return(syscall3(SYS_mprotect, addr: uintptr: u64, length: u64, prot: u64))?; }; @@ -391,7 +391,7 @@ export fn faccessat( }; }; -export fn getdents64(dirfd: int, dirp: *void, count: size) (size | errno) = { +export fn getdents64(dirfd: int, dirp: *opaque, count: size) (size | errno) = { return wrap_return(syscall3(SYS_getdents64, dirfd: u64, dirp: uintptr: u64, count: u64))?: size; }; @@ -420,7 +420,7 @@ export fn fcntl(fd: int, cmd: int, arg: fcntl_arg) (int | errno) = { })?: int; }; -export fn getrandom(buf: *void, bufln: size, flags: uint) (size | errno) = { +export fn getrandom(buf: *opaque, bufln: size, flags: uint) (size | errno) = { return wrap_return(syscall3(SYS_getrandom, buf: uintptr: u64, bufln: u64, flags: u64))?: size; }; @@ -606,7 +606,7 @@ export fn accept4(sockfd: int, addr: nullable *sockaddr, addrlen: nullable *u32, sockfd: u64, addr: uintptr: u64, addrlen: uintptr: u64, flags: u64))?: int; }; -export fn recvfrom(sockfd: int, buf: *void, len_: size, flags: int, +export fn recvfrom(sockfd: int, buf: *opaque, len_: size, flags: int, src_addr: nullable *sockaddr, addrlen: nullable *u32 ) (size | errno) = { return wrap_return(syscall6(SYS_recvfrom, @@ -614,7 +614,7 @@ export fn recvfrom(sockfd: int, buf: *void, len_: size, flags: int, src_addr: uintptr: u64, addrlen: uintptr: u64))?: size; }; -export fn sendto(sockfd: int, buf: *void, len_: size, flags: int, +export fn sendto(sockfd: int, buf: *opaque, len_: size, flags: int, dest_addr: nullable *sockaddr, addrlen: u32 ) (size | errno) = { return wrap_return(syscall6(SYS_sendto, @@ -622,34 +622,34 @@ export fn sendto(sockfd: int, buf: *void, len_: size, flags: int, dest_addr: uintptr: u64, addrlen: u64))?: size; }; -export fn recv(sockfd: int, buf: *void, len_: size, flags: int) (size | errno) = { +export fn recv(sockfd: int, buf: *opaque, len_: size, flags: int) (size | errno) = { return recvfrom(sockfd, buf, len_, flags, null, null); }; -export fn send(sockfd: int, buf: *void, len_: size, flags: int) (size | errno) = { +export fn send(sockfd: int, buf: *opaque, len_: size, flags: int) (size | errno) = { return sendto(sockfd, buf, len_, flags, null, 0); }; -export fn getsockopt(sockfd: int, level: int, optname: int, optval: nullable *void, optlen: nullable *u32) (int | errno) = { +export fn getsockopt(sockfd: int, level: int, optname: int, optval: nullable *opaque, optlen: nullable *u32) (int | errno) = { return wrap_return(syscall5(SYS_getsockopt, sockfd: u64, level: u64, optname: u64, optval: uintptr: u64, optlen: uintptr: u64))?: int; }; -export fn setsockopt(sockfd: int, level: int, optname: int, optval: *void, optlen: u32) (int | errno) = { +export fn setsockopt(sockfd: int, level: int, optname: int, optval: *opaque, optlen: u32) (int | errno) = { return wrap_return(syscall5(SYS_setsockopt, sockfd: u64, level: u64, optname: u64, optval: uintptr: u64, optlen: u64))?: int; }; -export type ioctl_arg = (nullable *void | u64); +export type ioctl_arg = (nullable *opaque | 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 let u: u64 => yield syscall3(SYS_ioctl, fd, req, u); - case let v: nullable *void => + case let v: nullable *opaque => yield syscall3(SYS_ioctl, fd, req, v: uintptr: u64); })?: int; }; @@ -729,7 +729,7 @@ export fn setpriority(which: int, who: id_t, prio: int) (void | errno) = { wrap_return(syscall3(SYS_setpriority, which: u64, who: u64, prio: u64))?; }; -export fn io_uring_setup(entries: u32, params: *void) (int | errno) = { +export fn io_uring_setup(entries: u32, params: *opaque) (int | errno) = { return wrap_return(syscall2(SYS_io_uring_setup, entries: u64, params: uintptr: u64))?: int; }; @@ -737,7 +737,7 @@ export fn io_uring_setup(entries: u32, params: *void) (int | errno) = { export fn io_uring_register( fd: int, opcode: uint, - arg: nullable *void, + arg: nullable *opaque, nr_args: uint, ) (int | errno) = wrap_return(syscall4(SYS_io_uring_register, fd: u64, opcode: u64, arg: uintptr: u64, nr_args: u64))?: int; @@ -754,12 +754,12 @@ export fn io_uring_enter( flags: u64, sig: uintptr: u64))?: uint; }; -export fn mlock2(addr: *void, length: size, flags: uint) (void | errno) = { +export fn mlock2(addr: *opaque, length: size, flags: uint) (void | errno) = { return wrap_return(syscall3(SYS_mlock2, addr: uintptr: u64, length: u64, flags: u64))?: void; }; -export fn munlock(addr: *void, length: size) (void | errno) = { +export fn munlock(addr: *opaque, length: size) (void | errno) = { return wrap_return(syscall2(SYS_munlock, addr: uintptr: u64, length: u64))?: void; }; @@ -786,7 +786,7 @@ export fn prctl( export fn add_key( keytype: *const u8, name: *const u8, - payload: *void, + payload: *opaque, plen: size, keyring: int, ) (int | errno) = { @@ -820,7 +820,7 @@ export fn mount( target: path, filesystemtype: *const u8, mountflags: u64, - data: nullable *void + data: nullable *opaque ) (void | errno) = { let source = kpath(source)?; let target = kpath(target)?; @@ -927,9 +927,9 @@ export type inotify_event = struct { name: *const u8 }; -export fn shmat(id: int, addr: *const void, flag: int) *void = { +export fn shmat(id: int, addr: *const opaque, flag: int) *opaque = { return syscall3(SYS_shmat, id: u64, addr: uintptr: u64, - flag: u64): uintptr: *void; + flag: u64): uintptr: *opaque; }; export fn sched_getaffinity( diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -388,7 +388,7 @@ export def EPOLLONESHOT: u32 = 1 << 30; export def EPOLLET: u32 = 1 << 31; export type epoll_data = union { - ptr: *void, + ptr: *opaque, fd: int, u32_: u32, u64_: u64, @@ -411,7 +411,7 @@ def SI_MAX_SIZE: size = 128; export type sigval = union { sival_t: int, - sival_ptr: *void, + sival_ptr: *opaque, }; export type siginfo = union { @@ -442,7 +442,7 @@ export type siginfo = union { union { si_value: sigval, si_int: int, - si_ptr: *void, + si_ptr: *opaque, } }, @@ -457,7 +457,7 @@ export type siginfo = union { // SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT struct { - si_addr: *void, + si_addr: *opaque, union { // used when si_code=BUS_MCEERR_AR or @@ -466,8 +466,8 @@ export type siginfo = union { struct { _dummy_bnd: [__ADDR_BND_PKEY_PAD]u8, - si_lower: *void, - si_upper: *void, + si_lower: *opaque, + si_upper: *opaque, }, struct { @@ -485,7 +485,7 @@ export type siginfo = union { // SIGSYS struct { - si_call_addr: *void, + si_call_addr: *opaque, si_syscall: int, si_arch: uint, }, @@ -513,7 +513,7 @@ export def SIG_HOLD: uintptr = 2; export type sigact = struct { union { sa_handler: *fn (int) void, - sa_sigaction: *fn (int, *siginfo, *void) void, + sa_sigaction: *fn (int, *siginfo, *opaque) void, }, sa_flags: u64, sa_restorer: *fn () void, @@ -550,7 +550,7 @@ export type signalfd_siginfo = struct { }; export type iovec = struct { - iov_base: *void, + iov_base: *opaque, iov_len: size }; diff --git a/rt/+riscv64/backtrace.ha b/rt/+riscv64/backtrace.ha @@ -2,11 +2,11 @@ // (c) 2021 Drew DeVault <sir@cmpwn.com> // (c) 2021 Ember Sawady <ecs@d2evs.net> -fn getfp() **void; +fn getfp() **opaque; // Details for a stack frame. Contents are architecture-specific. export type frame = struct { - addr: *void + addr: *opaque }; // Returns the current stack frame. See [[nextframe]] to walk the stack. @@ -20,11 +20,11 @@ export fn backtrace() frame = { // Returns the frame above the current frame, if any. export fn nextframe(sframe: frame) (frame | void) = { - let addr = sframe.addr: *nullable *void; + let addr = sframe.addr: *nullable *opaque; match (*addr) { case null => return; - case let a: *void => + case let a: *opaque => return frame { addr = a }; }; }; diff --git a/rt/+x86_64/backtrace.ha b/rt/+x86_64/backtrace.ha @@ -3,11 +3,11 @@ // (c) 2021 Ember Sawady <ecs@d2evs.net> // (c) 2021 Mykyta Holubakha <hilobakho@gmail.com> -fn getfp() **void; +fn getfp() **opaque; // Details for a stack frame. Contents are architecture-specific. export type frame = struct { - addr: *void + addr: *opaque }; // Returns the current stack frame. See [[nextframe]] to walk the stack. @@ -21,9 +21,9 @@ export fn backtrace() frame = { // Returns the frame above the current frame, if any. export fn nextframe(sframe: frame) (frame | void) = { - let addr = sframe.addr: *nullable *void; + let addr = sframe.addr: *nullable *opaque; match (*addr) { - case let a: *void => + case let a: *opaque => return frame { addr = a }; case null => return; diff --git a/rt/ensure.ha b/rt/ensure.ha @@ -3,7 +3,7 @@ // (c) 2021 Ember Sawady <ecs@d2evs.net> export type slice = struct { - data: nullable *void, + data: nullable *opaque, length: size, capacity: size, }; diff --git a/rt/malloc+debug.ha b/rt/malloc+debug.ha @@ -15,7 +15,7 @@ type auxv64 = struct { a_type: u64, union { a_val: u64, - a_ptr: *void, + a_ptr: *opaque, a_fnc: *fn() void, } }; @@ -34,34 +34,34 @@ type auxv64 = struct { }; }; -export fn malloc(n: size) nullable *void = { +export fn malloc(n: size) nullable *opaque = { if (n == 0) { return null; }; - let z = n + size(*void) + size(size); + let z = n + size(*opaque) + size(size); if (z % pagesz != 0) { z += pagesz - z % pagesz; }; let seg = match (segmalloc(z)) { case null => return null; - case let ptr: *void => + case let ptr: *opaque => yield ptr; }; let user = &(seg: *[*]u8)[z - n]; - let segptr = &(user: *[*]*void)[-1]; + let segptr = &(user: *[*]*opaque)[-1]; let szptr = &(segptr: *[*]size)[-1]; *segptr = seg; *szptr = n; return user; }; -export @symbol("rt.free") fn free_(_p: nullable *void) void = { +export @symbol("rt.free") fn free_(_p: nullable *opaque) void = { if (_p != null) { - let user = _p: *void; - let segptr = &(user: *[*]*void)[-1]; + let user = _p: *opaque; + let segptr = &(user: *[*]*opaque)[-1]; let szptr = &(segptr: *[*]size)[-1]; - let z = *szptr + size(*void) + size(size); + let z = *szptr + size(*opaque) + size(size); if (z % pagesz != 0) { z += pagesz - z % pagesz; }; @@ -69,7 +69,7 @@ export @symbol("rt.free") fn free_(_p: nullable *void) void = { }; }; -export fn realloc(user: nullable *void, n: size) nullable *void = { +export fn realloc(user: nullable *opaque, n: size) nullable *opaque = { if (n == 0) { free(user); return null; @@ -77,14 +77,14 @@ export fn realloc(user: nullable *void, n: size) nullable *void = { return malloc(n); }; - let user = user: *void; - let segptr = &(user: *[*]*void)[-1]; + let user = user: *opaque; + let segptr = &(user: *[*]*opaque)[-1]; let szptr = &(segptr: *[*]size)[-1]; let z = *szptr; let new = malloc(n); if (new != null) { - memcpy(new: *void, user, if (z < n) z else n); + memcpy(new: *opaque, user, if (z < n) z else n); free(user); }; diff --git a/rt/malloc+libc.ha b/rt/malloc+libc.ha @@ -3,7 +3,7 @@ // Allocates n bytes of memory and returns a pointer to them, or null if there // is insufficient memory. -export fn malloc(n: size) nullable *void = { +export fn malloc(n: size) nullable *opaque = { return c_malloc(n); }; @@ -13,7 +13,7 @@ export fn malloc(n: size) nullable *void = { // than the one given if there is insufficient space to expand the pointer // in-place. Returns null if there is insufficient memory to support the // request. -export fn realloc(p: nullable *void, n: size) nullable *void = { +export fn realloc(p: nullable *opaque, n: size) nullable *opaque = { if (n == 0) { free(p); return null; @@ -22,10 +22,10 @@ export fn realloc(p: nullable *void, n: size) nullable *void = { }; // Frees a pointer previously allocated with [[malloc]]. -export @symbol("rt.free") fn free_(p: nullable *void) void = { +export @symbol("rt.free") fn free_(p: nullable *opaque) void = { c_free(p); }; -@symbol("malloc") fn c_malloc(size) nullable *void; -@symbol("realloc") fn c_realloc(nullable *void, size) nullable *void; -@symbol("free") fn c_free(nullable *void) void; +@symbol("malloc") fn c_malloc(size) nullable *opaque; +@symbol("realloc") fn c_realloc(nullable *opaque, size) nullable *opaque; +@symbol("free") fn c_free(nullable *opaque) void; diff --git a/rt/malloc.ha b/rt/malloc.ha @@ -46,7 +46,7 @@ let cur_chunk: (*chunk, size) = (null: *chunk, CHUNKSZ); // Allocates n bytes of memory and returns a pointer to them, or null if there // is insufficient memory. -export fn malloc(n: size) nullable *void = { +export fn malloc(n: size) nullable *opaque = { if (n == 0) return null; if (size_islarge(n)) { // Round up to PAGESZ and just use mmap directly @@ -54,7 +54,7 @@ export fn malloc(n: size) nullable *void = { let m = match (segmalloc(n + ALIGN + META)) { case null => return null; - case let p: *void => + case let p: *opaque => yield (p: uintptr + ALIGN - META): *meta; }; @@ -72,7 +72,7 @@ export fn malloc(n: size) nullable *void = { match (segmalloc(CHUNKSZ)) { case null => return null; - case let p: *void => + case let p: *opaque => cur_chunk = (p: *chunk, size(size)); }; }; @@ -97,18 +97,18 @@ export fn malloc(n: size) nullable *void = { // Frees an allocation returned by [[malloc]]. Freeing any other pointer, or // freeing a pointer that's already been freed, will cause an abort. -export @symbol("rt.free") fn free_(p: nullable *void) void = { +export @symbol("rt.free") fn free_(p: nullable *opaque) void = { let m = match (p) { case null => return; - case let p: *void => + case let p: *opaque => yield getmeta(p); }; cur_allocs -= 1; if (size_islarge(m.sz)) { // Pass through to munmap - segfree((p: uintptr - ALIGN): *void, m.sz + ALIGN + META); + segfree((p: uintptr - ALIGN): *opaque, m.sz + ALIGN + META); return; }; @@ -125,7 +125,7 @@ export @symbol("rt.free") fn free_(p: nullable *void) void = { // than the one given if there is insufficient space to expand the pointer // in-place. Returns null if there is insufficient memory to support the // request. -export fn realloc(p: nullable *void, n: size) nullable *void = { +export fn realloc(p: nullable *opaque, n: size) nullable *opaque = { if (n == 0) { free(p); return null; @@ -133,7 +133,7 @@ export fn realloc(p: nullable *void, n: size) nullable *void = { let m = match (p) { case null => return malloc(n); - case let p: *void => + case let p: *opaque => yield getmeta(p); }; if (realsz(n) == m.sz) return p; @@ -141,7 +141,7 @@ export fn realloc(p: nullable *void, n: size) nullable *void = { let new = match (malloc(n)) { case null => return null; - case let new: *void => + case let new: *opaque => yield new; }; memcpy(new, &m.user, if (n < m.sz) n else m.sz); @@ -151,7 +151,7 @@ export fn realloc(p: nullable *void, n: size) nullable *void = { // Gets the metadata for a given allocation. The provided pointer must have been // returned by [[malloc]] and must not have been freed. -export fn getmeta(p: *void) *meta = { +export fn getmeta(p: *opaque) *meta = { let m = (p: uintptr - META): *meta; validatemeta(m, false); assert(m.sz & 0b1 == 0, diff --git a/rt/memcpy.ha b/rt/memcpy.ha @@ -1,7 +1,7 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -export fn memcpy(dest: *void, src: *const void, amt: size) void = { +export fn memcpy(dest: *opaque, src: *const opaque, amt: size) void = { let a = dest: *[*]u8, b = src: *const [*]u8; for (let i = 0z; i < amt; i += 1) { a[i] = b[i]; diff --git a/rt/memmove.ha b/rt/memmove.ha @@ -1,7 +1,7 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -export fn memmove(dest: *void, src: *const void, n: size) void = { +export fn memmove(dest: *opaque, src: *const opaque, n: size) void = { let d = dest: *[*]u8, s = src: *const [*]u8; if (d: uintptr == s: uintptr) { return; diff --git a/rt/memset.ha b/rt/memset.ha @@ -1,7 +1,7 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -export fn memset(dest: *void, val: u8, amt: size) void = { +export fn memset(dest: *opaque, val: u8, amt: size) void = { let a = dest: *[*]u8; for (let i = 0z; i < amt; i += 1) { a[i] = val; diff --git a/sort/bisect.ha b/sort/bisect.ha @@ -5,9 +5,9 @@ // If 'elem' already appears in the slice, inserting to the returned index will // insert immediately before the first occurance. export fn lbisect( - in: []const void, + in: []const opaque, sz: size, - elem: const *void, + elem: const *opaque, cmp: *cmpfunc, ) size = { let min = 0z, max = len(in); @@ -36,9 +36,9 @@ export fn lbisect( // If 'elem' already appears in the slice, inserting to the returned index will // insert immediately after the last occurance. export fn rbisect( - in: []const void, + in: []const opaque, sz: size, - elem: const *void, + elem: const *opaque, cmp: *cmpfunc, ) size = { const nmemb = len(in); diff --git a/sort/search.ha b/sort/search.ha @@ -4,9 +4,9 @@ // Performs a binary search over a sorted slice. If the key is found, index of // the matching item in the slice is returned. Otherwise, void is returned. export fn search( - in: []const void, + in: []const opaque, sz: size, - key: const *void, + key: const *opaque, cmp: *cmpfunc, ) (size | void) = { let ba = in: *[*]u8; diff --git a/sort/sort.ha b/sort/sort.ha @@ -6,7 +6,7 @@ // // Note that this function may (temporarily) allocate, and will abort on // allocation failure. -export fn sort(items: []void, itemsz: size, cmp: *cmpfunc) void = { +export fn sort(items: []opaque, itemsz: size, cmp: *cmpfunc) void = { if (len(items) < 256) { insort(items, itemsz, cmp); return; @@ -21,7 +21,7 @@ export fn sort(items: []void, itemsz: size, cmp: *cmpfunc) void = { export fn strings(items: []str) void = sort(items, size(str), &scmp); // Checks if all of the items in a slice are sorted. -export fn sorted(items: []void, itemsz: size, cmp: *cmpfunc) bool = { +export fn sorted(items: []opaque, itemsz: size, cmp: *cmpfunc) bool = { let ba = items: *[*]u8; for (let i = 1z; i < len(items); i += 1) { if (cmp(&ba[(i - 1) * itemsz], &ba[i * itemsz]) > 0) { @@ -35,7 +35,7 @@ export fn sorted(items: []void, itemsz: size, cmp: *cmpfunc) bool = { // respect to Unicode codepoints; see [[strings::compare]]. export fn strings_sorted(items: []str) bool = sorted(items, size(str), &scmp); -fn swap(a: *void, b: *void, sz: size) void = { +fn swap(a: *opaque, b: *opaque, sz: size) void = { let a = a: *[*]u8, b = b: *[*]u8; for (let i = 0z; i < sz; i += 1) { let c = a[i]; @@ -47,9 +47,9 @@ fn swap(a: *void, b: *void, sz: size) void = { // Finds the index of the rightmost value that is equal to key or, if such value // does not exist, less than key. fn search_rightmost( - in: []void, + in: []opaque, sz: size, - key: const *void, + key: const *opaque, cmp: *cmpfunc, ) size = { let l = 0z; @@ -66,7 +66,7 @@ fn search_rightmost( return r - 1; }; -fn insort(items: []void, itemsz: size, cmp: *cmpfunc) void = { +fn insort(items: []opaque, itemsz: size, cmp: *cmpfunc) void = { let ba = items: *[*]u8; for (let i = 0z; i < len(items); i += 1) { let bound = search_rightmost(items[0..i], itemsz, diff --git a/sort/types.ha b/sort/types.ha @@ -6,14 +6,14 @@ use strings; // values, a function of this type should return an integer less than, equal to, // or greater than zero if the first argument is, respectively, less than, equal // to, or greater than the second argument. -export type cmpfunc = fn(a: const *void, b: const *void) int; +export type cmpfunc = fn(a: const *opaque, b: const *opaque) int; -fn scmp(a: const *void, b: const *void) int = { +fn scmp(a: const *opaque, b: const *opaque) int = { const a = a: const *str, b = b: const *str; return strings::compare(*a, *b); }; -fn icmp(a: const *void, b: const *void) int = { +fn icmp(a: const *opaque, b: const *opaque) int = { const a = *(a: const *int), b = *(b: const *int); return if (a < b) -1 else if (a > b) 1 diff --git a/test/+test.ha b/test/+test.ha @@ -276,26 +276,26 @@ fn dots(n: size) void = { fn handle_segv( sig: signal::sig, info: *signal::siginfo, - ucontext: *void, + ucontext: *opaque, ) void = { rt::longjmp(&jmpbuf, 2); }; -type v=void;type Xtogh=v;type SLQJi0=v;type kP3Ju1=const!v;type EWeUG2=!v; -type SX1lD=const v;type Qqc3q=const v;type W58mL1=const!v;type kNrei=!v; -type Oq2Q61=const!v;type StInt3=v;type TEl8R1=const!v;type eNiY5=const v; -type KWinY1=!v;type sS5GT=const!v;type keyX7=const!v;type r4jCr=v; -type lAV2N0=const v;type fnZCP0=v;type JFVSM=const!v;type beYjX=const v; -type aZXqs=const!v;type wqc2d=const!v;type fqnT7=!v;type qc4Qc0=!v; +type v=void;type FoTXH1=const!v;type Z5Tz00=const!v;type gT09C4=const!v; +type r6Zqh7=!v;type mwKNK=v;type pt3Q6=const v;type kLHAU0=const v; +type UgVD10=const!v;type Uy4Oh0=const!v;type Wy4m6=const!v;type AfYY8=const v; +type xSIP9=const!v;type IwKEe=const!v;type I08Eb2=v;type kc0OM0=v;type hk9Rn=v; +type Tml1Q=v;type DCtxj2=const!v;type PnLBN0=v;type GEtCt=const v; +type vMueS0=const!v;type vOnJS0=const v;type BPtR4=const!v;type Rj9Ip2=const!v; fn ignoreme(i: []failure, j: []test) void = { // norwegian deadbeef - let a: [_](Xtogh|SLQJi0|kP3Ju1|EWeUG2|SX1lD|Qqc3q|W58mL1|kNrei|Oq2Q61| - StInt3|TEl8R1|eNiY5|KWinY1|sS5GT|keyX7|r4jCr|lAV2N0| - fnZCP0|JFVSM|beYjX|aZXqs|wqc2d|fqnT7|qc4Qc0) = [ - Xtogh,SLQJi0,kP3Ju1,EWeUG2,SX1lD,Qqc3q,W58mL1,kNrei,Oq2Q61, - StInt3,TEl8R1,eNiY5,KWinY1,sS5GT,keyX7,r4jCr,lAV2N0,fnZCP0, - JFVSM,beYjX,aZXqs,wqc2d,fqnT7,qc4Qc0, + let a: [_](FoTXH1|Z5Tz00|gT09C4|r6Zqh7|mwKNK|pt3Q6|kLHAU0|UgVD10|Uy4Oh0| + Wy4m6|AfYY8|xSIP9|IwKEe|I08Eb2|kc0OM0|hk9Rn|Tml1Q| + DCtxj2|PnLBN0|GEtCt|vMueS0|vOnJS0|BPtR4|Rj9Ip2) = [ + FoTXH1,Z5Tz00,gT09C4,r6Zqh7,mwKNK,pt3Q6,kLHAU0,UgVD10,Uy4Oh0, + Wy4m6,AfYY8,xSIP9,IwKEe,I08Eb2,kc0OM0,hk9Rn,Tml1Q,DCtxj2,PnLBN0, + GEtCt,vMueS0,vOnJS0,BPtR4,Rj9Ip2, ]; let i=len(i):u32,j=len(j):u32,b=&a:*[96]u8,c=&a:*[24]u32; let d=2166136261u32,e=b[64]>>2u32;c[0]^=j-i;for(let f=0z;f<4;f+=1) diff --git a/types/classes.ha b/types/classes.ha @@ -33,7 +33,7 @@ export type string = struct { // slice manipulation. export type slice = struct { // The slice contents. - data: nullable *void, + data: nullable *opaque, // The number of members of the slice. length: size, diff --git a/unix/signal/+freebsd.ha b/unix/signal/+freebsd.ha @@ -27,12 +27,12 @@ export fn handle( }; let new = rt::sigact { - sa_sigaction = handler: *fn(int, *rt::siginfo, *void) void, + sa_sigaction = handler: *fn(int, *rt::siginfo, *opaque) void, sa_mask = sa_mask, sa_flags = sa_flags, }; let old = rt::sigact { - sa_sigaction = null: *fn(int, *rt::siginfo, *void) void, + sa_sigaction = null: *fn(int, *rt::siginfo, *opaque) void, ... }; match (rt::sigaction(signum, &new, &old)) { diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha @@ -30,7 +30,7 @@ export fn handle( }; let new = rt::sigact { - sa_sigaction = handler: *fn(int, *rt::siginfo, *void) void, + sa_sigaction = handler: *fn(int, *rt::siginfo, *opaque) void, sa_mask = sa_mask, sa_flags = sa_flags, // Filled in by rt: @@ -38,7 +38,7 @@ export fn handle( }; let old = rt::sigact { // Filled in by rt: - sa_sigaction = null: *fn(int, *rt::siginfo, *void) void, + sa_sigaction = null: *fn(int, *rt::siginfo, *opaque) void, sa_restorer = null: *fn() void, ... }; diff --git a/unix/signal/types.ha b/unix/signal/types.ha @@ -5,4 +5,4 @@ // which was caught, the second provides information about the signal, and the // third argument is the ucontext, which is usually ignored by most signal // handlers. -export type handler = fn(sig: sig, info: *siginfo, ucontext: *void) void; +export type handler = fn(sig: sig, info: *siginfo, ucontext: *opaque) void; diff --git a/unix/tty/+freebsd/isatty.ha b/unix/tty/+freebsd/isatty.ha @@ -8,7 +8,7 @@ use os; // Returns whether the given stream is connected to a terminal. export fn isatty(fd: io::file) bool = { let wsz = rt::winsize { ... }; - match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { + match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *opaque)) { case let e: rt::errno => return false; case let r: int => diff --git a/unix/tty/+freebsd/winsize.ha b/unix/tty/+freebsd/winsize.ha @@ -9,7 +9,7 @@ use rt; // Returns the dimensions of underlying terminal for an [[io::file]]. export fn winsize(fd: io::file) (ttysize | error) = { let wsz = rt::winsize { ... }; - match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { + match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *opaque)) { case let e: rt::errno => switch (e: int) { case rt::EBADF => diff --git a/unix/tty/+linux/isatty.ha b/unix/tty/+linux/isatty.ha @@ -10,7 +10,7 @@ use os; // Returns whether the given stream is connected to a terminal. export fn isatty(fd: io::file) bool = { let wsz = rt::winsize { ... }; - match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { + match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *opaque)) { case let e: rt::errno => return false; case let r: int => diff --git a/unix/tty/+linux/winsize.ha b/unix/tty/+linux/winsize.ha @@ -10,7 +10,7 @@ use rt; // Returns the dimensions of underlying terminal for an [[io::file]]. export fn winsize(fd: io::file) (ttysize | error) = { let wsz = rt::winsize { ... }; - match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *void)) { + match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *opaque)) { case let e: rt::errno => switch (e: int) { case rt::EBADFD =>