hare

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

commit 74af0de1fab90c9d4531452fa1376cce1df13fce
parent 3415a5fca356d3c633abd90e45029b12cb198da5
Author: Sebastian <sebastian@sebsite.pw>
Date:   Tue,  9 May 2023 21:59:06 -0400

Remove char from language; add char to types::c

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mformat/tar/reader.ha | 2+-
Mhare/module/scan.ha | 2+-
Mlinux/keyctl/keyctl.ha | 4++--
Mlinux/keyctl/types.ha | 5+++--
Mlinux/vdso/vdso.ha | 12++++++------
Mos/+freebsd/dirfdfs.ha | 2+-
Mos/+freebsd/environ.ha | 10+++++-----
Mos/+freebsd/fs.ha | 2+-
Mos/+linux/dirfdfs.ha | 2+-
Mos/+linux/environ+libc.ha | 20++++++++++----------
Mos/+linux/environ.ha | 20++++++++++----------
Mos/+linux/fs.ha | 2+-
Mos/exec/exec+freebsd.ha | 11++++++-----
Mos/exec/exec+linux.ha | 12++++++------
Mrt/+freebsd/env.ha | 4++--
Mrt/+freebsd/platform_abort.ha | 6+++---
Mrt/+freebsd/platformstart.ha | 4++--
Mrt/+freebsd/socket.ha | 4++--
Mrt/+freebsd/syscalls.ha | 18+++++++++---------
Mrt/+freebsd/types.ha | 4++--
Mrt/+linux/env.ha | 4++--
Mrt/+linux/platform_abort.ha | 6+++---
Mrt/+linux/platformstart+libc.ha | 10+++++-----
Mrt/+linux/platformstart.ha | 4++--
Mrt/+linux/socket.ha | 4++--
Mrt/+linux/syscalls.ha | 32++++++++++++++++----------------
Mrt/+linux/types.ha | 16++++++++--------
Mrt/+test/cstring.ha | 4++--
Mrt/+test/run.ha | 2+-
Mrt/abort.ha | 10+++++-----
Mtypes/c/arch+aarch64.ha | 3+++
Mtypes/c/arch+riscv64.ha | 3+++
Mtypes/c/arch+x86_64.ha | 3+++
Munix/tty/+freebsd/pty.ha | 2+-
34 files changed, 130 insertions(+), 119 deletions(-)

diff --git a/format/tar/reader.ha b/format/tar/reader.ha @@ -207,7 +207,7 @@ fn readstr(rd: *bufio::memstream, ln: size) str = { case io::EOF => abort(); }; - return c::tostr(buf: *[*]u8: *const char)!; + return c::tostr(buf: *[*]u8: *const c::char)!; }; fn readoct(rd: *bufio::memstream, ln: size) (uint | invalid) = { diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -20,7 +20,7 @@ use strio; use bufio; use os; -def ABI_VERSION: u8 = 5; +def ABI_VERSION: u8 = 6; // Scans the files in a directory for eligible build inputs and returns a // [[version]] which includes all applicable files and their dependencies. diff --git a/linux/keyctl/keyctl.ha b/linux/keyctl/keyctl.ha @@ -23,8 +23,8 @@ export fn add_key( defer free(keytype); const name = c::fromstr(name); defer free(name); - match (rt::add_key(keytype, name, payload: *[*]u8: *void, - len(payload), keyring)) { + match (rt::add_key(keytype: *const u8, name: *const u8, + payload: *[*]u8: *void, len(payload), keyring)) { case let err: rt::errno => return errno(err); case let n: int => diff --git a/linux/keyctl/types.ha b/linux/keyctl/types.ha @@ -1,4 +1,5 @@ use errors; +use types::c; // A key ID. export type serial = i32; @@ -92,8 +93,8 @@ export type dh_params = struct { // Output for [[command::DH_COMPUTE]] export type kdf_params = struct { - hashname: *char, - otherinfo: *char, + hashname: *c::char, + otherinfo: *c::char, otherinfolen: u32, __spare: [8]u32, }; diff --git a/linux/vdso/vdso.ha b/linux/vdso/vdso.ha @@ -26,7 +26,7 @@ fn sys_infoehdr() nullable *elf::header64 = { type vdso_ctx = struct { segbase: uintptr, - stringtab: *char, + stringtab: *c::char, symtab: *[*]elf::sym64, hashhdr: *elf::hashhdr, versym: nullable *[*]u16, @@ -74,7 +74,7 @@ fn get_vdso_ctx() nullable *vdso_ctx = { const dynv = dynvec: *[*]elf::dyn64; let segbase = baseseg: uintptr; - let stringtab: nullable *char = null; + let stringtab: nullable *c::char = null; let symtab: nullable *[*]elf::sym64 = null; let hashhdr: nullable *elf::hashhdr = null; let versym: nullable *[*]u16 = null; @@ -84,7 +84,7 @@ fn get_vdso_ctx() nullable *vdso_ctx = { const tabptr = (segbase + dynv[i].d_val: uintptr): *void; switch (dynv[i].d_tag) { case elf::dt::STRTAB => - stringtab = tabptr: *char; + stringtab = tabptr: *c::char; case elf::dt::SYMTAB => symtab = tabptr: *[*]elf::sym64; case elf::dt::HASH => @@ -109,7 +109,7 @@ fn get_vdso_ctx() nullable *vdso_ctx = { // TODO: use a static variable here somehow(?) const vctx = alloc(vdso_ctx { segbase = segbase, - stringtab = stringtab: *char, + stringtab = stringtab: *c::char, symtab = symtab: *[*]elf::sym64, hashhdr = hashhdr: *elf::hashhdr, verdef = verdef, @@ -141,7 +141,7 @@ fn vdso_checkver(ctx: *vdso_ctx, version: str, num: u32) bool = { cur.vd_aux: uintptr): *elf::verdaux64; const name = ctx.stringtab: uintptr + aux.vda_name: uintptr; - return version == c::tostr(name: *char)!; + return version == c::tostr(name: *c::char)!; }; prev = cur; cur = (cur: uintptr + cur.vd_next: uintptr): *elf::verdef64; @@ -174,7 +174,7 @@ export fn getsym(symname: str, symver: str) nullable *void = { continue; }; const name = ctx.stringtab: uintptr + sym.st_name: uintptr; - const s: str = c::tostr(name: *const char)!; + const s: str = c::tostr(name: *const c::char)!; if (s != symname) continue; if (!vdso_checkver(ctx, symver, i)) diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha @@ -384,7 +384,7 @@ fn iter_next(iter: *fs::iterator) (fs::dirent | void) = { }; let de = &iter.buf[iter.buf_pos]: *rt::freebsd11_dirent; iter.buf_pos += de.d_reclen; - let name = c::tostr(&de.d_name: *const char)!; + let name = c::tostr(&de.d_name: *const c::char)!; let ftype: fs::mode = switch (de.d_type) { case rt::DT_UNKNOWN => diff --git a/os/+freebsd/environ.ha b/os/+freebsd/environ.ha @@ -19,12 +19,12 @@ let args_static: [32]str = [""...]; if (rt::argc < len(args_static)) { args = args_static[..rt::argc]; for (let i = 0z; i < rt::argc; i += 1) { - args[i] = c::tostr(rt::argv[i])!; + args[i] = c::tostr(rt::argv[i]: *const c::char)!; }; } else { args = alloc([], rt::argc); for (let i = 0z; i < rt::argc; i += 1) { - append(args, c::tostr(rt::argv[i])!); + append(args, c::tostr(rt::argv[i]: *const c::char)!); }; }; @@ -42,7 +42,7 @@ export fn getenv(name: const str) (str | void) = { const name_b = strings::toutf8(name); for (let i = 0z; rt::envp[i] != null; i += 1) { const item = rt::envp[i]: *[*]u8; - const ln = c::strlen(item: *char); + const ln = c::strlen(item: *c::char); const eq: size = match (bytes::index(item[..ln], '=')) { case void => abort("Environment violates System-V invariants"); @@ -50,7 +50,7 @@ export fn getenv(name: const str) (str | void) = { yield i; }; if (bytes::equal(name_b, item[..eq])) { - const ln = c::strlen(item: *const char); + const ln = c::strlen(item: *const c::char); return strings::fromutf8(item[eq+1..ln])!; }; }; @@ -73,7 +73,7 @@ export fn getenvs() []str = { return envp; }; for (let i = 0z; rt::envp[i] != null; i += 1) { - append(envp, c::tostr(rt::envp[i]: *const char)!); + append(envp, c::tostr(rt::envp[i]: *const c::char)!); }; return envp; }; diff --git a/os/+freebsd/fs.ha b/os/+freebsd/fs.ha @@ -22,7 +22,7 @@ export fn init_cwd() void = { // Returns the current working directory. The return value is statically // allocated and must be duplicated (see [[strings::dup]]) before calling getcwd // again. -export fn getcwd() str = c::tostr(rt::getcwd() as *const char)!; +export fn getcwd() str = c::tostr(rt::getcwd() as *const u8: *const c::char)!; // Change the current working directory. export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -432,7 +432,7 @@ fn iter_next(iter: *fs::iterator) (fs::dirent | void) = { }; let de = &iter.buf[iter.buf_pos]: *rt::dirent64; iter.buf_pos += de.d_reclen; - let name = c::tostr(&de.d_name: *const char)!; + let name = c::tostr(&de.d_name: *const c::char)!; let ftype: fs::mode = switch (de.d_type) { case rt::DT_UNKNOWN => diff --git a/os/+linux/environ+libc.ha b/os/+linux/environ+libc.ha @@ -18,12 +18,12 @@ let args_static: [32]str = [""...]; if (rt::argc < len(args_static)) { args = args_static[..rt::argc]; for (let i = 0z; i < rt::argc; i += 1) { - args[i] = c::tostr(rt::argv[i])!; + args[i] = c::tostr(rt::argv[i]: *const c::char)!; }; } else { args = alloc([], rt::argc); for (let i = 0z; i < rt::argc; i += 1) { - append(args, c::tostr(rt::argv[i])!); + append(args, c::tostr(rt::argv[i]: *const c::char)!); }; }; @@ -41,7 +41,7 @@ export fn getenv(name: const str) (str | void) = { const name_b = strings::toutf8(name); for (let i = 0z; rt::envp[i] != null; i += 1) { const item = rt::envp[i]: *[*]u8; - const ln = c::strlen(item: *char); + const ln = c::strlen(item: *c::char); const eq: size = match (bytes::index(item[..ln], '=')) { case void => abort("Environment violates System-V invariants"); @@ -49,7 +49,7 @@ export fn getenv(name: const str) (str | void) = { yield i; }; if (bytes::equal(name_b, item[..eq])) { - const ln = c::strlen(item: *const char); + const ln = c::strlen(item: *const c::char); return strings::fromutf8(item[eq+1..ln])!; }; }; @@ -72,7 +72,7 @@ export fn getenvs() []str = { return envp; }; for (let i = 0z; rt::envp[i] != null; i += 1) { - append(envp, c::tostr(rt::envp[i]: *const char)!); + append(envp, c::tostr(rt::envp[i]: *const c::char)!); }; return envp; }; @@ -86,7 +86,7 @@ export fn sysname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.sysname: *const char)!; + return c::tostr(&uts.sysname: *const c::char)!; }; // Returns the host system hostname @@ -95,7 +95,7 @@ export fn hostname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.nodename: *const char)!; + return c::tostr(&uts.nodename: *const c::char)!; }; // Returns the host kernel version @@ -104,7 +104,7 @@ export fn release() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.release: *const char)!; + return c::tostr(&uts.release: *const c::char)!; }; // Returns the host operating system version @@ -113,7 +113,7 @@ export fn version() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.version: *const char)!; + return c::tostr(&uts.version: *const c::char)!; }; // Returns the host CPU architecture @@ -122,5 +122,5 @@ export fn machine() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.machine: *const char)!; + return c::tostr(&uts.machine: *const c::char)!; }; diff --git a/os/+linux/environ.ha b/os/+linux/environ.ha @@ -20,12 +20,12 @@ let args_static: [32]str = [""...]; if (rt::argc < len(args_static)) { args = args_static[..rt::argc]; for (let i = 0z; i < rt::argc; i += 1) { - args[i] = c::tostr(rt::argv[i])!; + args[i] = c::tostr(rt::argv[i]: *const c::char)!; }; } else { args = alloc([], rt::argc); for (let i = 0z; i < rt::argc; i += 1) { - append(args, c::tostr(rt::argv[i])!); + append(args, c::tostr(rt::argv[i]: *const c::char)!); }; }; @@ -43,7 +43,7 @@ export fn getenv(name: const str) (str | void) = { const name_b = strings::toutf8(name); for (let i = 0z; rt::envp[i] != null; i += 1) { const item = rt::envp[i]: *[*]u8; - const ln = c::strlen(item: *char); + const ln = c::strlen(item: *c::char); const eq: size = match (bytes::index(item[..ln], '=')) { case void => abort("Environment violates System-V invariants"); @@ -51,7 +51,7 @@ export fn getenv(name: const str) (str | void) = { yield i; }; if (bytes::equal(name_b, item[..eq])) { - const ln = c::strlen(item: *const char); + const ln = c::strlen(item: *const c::char); return strings::fromutf8(item[eq+1..ln])!; }; }; @@ -74,7 +74,7 @@ export fn getenvs() []str = { return envp; }; for (let i = 0z; rt::envp[i] != null; i += 1) { - append(envp, c::tostr(rt::envp[i]: *const char)!); + append(envp, c::tostr(rt::envp[i]: *const c::char)!); }; return envp; }; @@ -88,7 +88,7 @@ export fn sysname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.sysname: *const char)!; + return c::tostr(&uts.sysname: *const c::char)!; }; // Returns the host system hostname @@ -97,7 +97,7 @@ export fn hostname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.nodename: *const char)!; + return c::tostr(&uts.nodename: *const c::char)!; }; // Returns the host kernel version @@ -106,7 +106,7 @@ export fn release() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.release: *const char)!; + return c::tostr(&uts.release: *const c::char)!; }; // Returns the host operating system version @@ -115,7 +115,7 @@ export fn version() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.version: *const char)!; + return c::tostr(&uts.version: *const c::char)!; }; // Returns the host CPU architecture @@ -124,7 +124,7 @@ export fn machine() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return c::tostr(&uts.machine: *const char)!; + return c::tostr(&uts.machine: *const c::char)!; }; // Returns the number of usable CPUs. diff --git a/os/+linux/fs.ha b/os/+linux/fs.ha @@ -22,7 +22,7 @@ export fn init_cwd() void = { // Returns the current working directory. The return value is statically // allocated and must be duplicated (see [[strings::dup]]) before calling getcwd // again. -export fn getcwd() str = c::tostr(rt::getcwd() as *const char)!; +export fn getcwd() str = c::tostr(rt::getcwd() as *const u8: *const c::char)!; // Change the current working directory. export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { diff --git a/os/exec/exec+freebsd.ha b/os/exec/exec+freebsd.ha @@ -81,20 +81,20 @@ fn platform_finish(cmd: *command) void = rt::close(cmd.platform)!; fn platform_exec(cmd: *command) error = { // We don't worry about freeing the return values from c::fromstr // because once we exec(2) our heap is fried anyway - let argv: []nullable *const char = alloc([], len(cmd.argv) + 1z); + let argv: []nullable *const c::char = alloc([], len(cmd.argv) + 1z); for (let i = 0z; i < len(cmd.argv); i += 1z) { append(argv, c::fromstr(cmd.argv[i])); }; append(argv, null); - let envp: nullable *[*]nullable *const char = null; + let envp: nullable *[*]nullable *const c::char = null; if (len(cmd.env) != 0) { - let env: []nullable *const char = alloc([], len(cmd.env) + 1); + let env: []nullable *const c::char = alloc([], len(cmd.env) + 1); for (let i = 0z; i < len(cmd.env); i += 1) { append(env, c::fromstr(cmd.env[i])); }; append(env, null); - envp = env: *[*]nullable *const char; + envp = env: *[*]nullable *const c::char; }; let need_devnull = false; @@ -154,7 +154,8 @@ fn platform_exec(cmd: *command) error = { }; return errors::errno(rt::fexecve(cmd.platform, - argv: *[*]nullable *const char, envp: *[*]nullable *const char)); + argv: *[*]nullable *const u8, + envp: *[*]nullable *const u8)); }; fn platform_start(cmd: *command) (process | errors::error) = { diff --git a/os/exec/exec+linux.ha b/os/exec/exec+linux.ha @@ -82,20 +82,20 @@ fn platform_finish(cmd: *command) void = rt::close(cmd.platform)!; fn platform_exec(cmd: *command) error = { // We don't worry about freeing the return values from c::fromstr // because once we exec(2) our heap is fried anyway - let argv: []nullable *const char = alloc([], len(cmd.argv) + 1z); + let argv: []nullable *const c::char = alloc([], len(cmd.argv) + 1z); for (let i = 0z; i < len(cmd.argv); i += 1z) { append(argv, c::fromstr(cmd.argv[i])); }; append(argv, null); - let envp: nullable *[*]nullable *const char = null; + let envp: nullable *[*]nullable *const c::char = null; if (len(cmd.env) != 0) { - let env: []nullable *const char = alloc([], len(cmd.env) + 1); + let env: []nullable *const c::char = alloc([], len(cmd.env) + 1); for (let i = 0z; i < len(cmd.env); i += 1) { append(env, c::fromstr(cmd.env[i])); }; append(env, null); - envp = env: *[*]nullable *const char; + envp = env: *[*]nullable *const c::char; }; let need_devnull = false; @@ -155,8 +155,8 @@ fn platform_exec(cmd: *command) error = { }; return errors::errno(rt::execveat(cmd.platform, - "\0", argv: *[*]nullable *const char, - envp: *[*]nullable *const char, rt::AT_EMPTY_PATH)); + "\0", argv: *[*]nullable *const u8, + envp: *[*]nullable *const u8, rt::AT_EMPTY_PATH)); }; fn platform_start(cmd: *command) (process | errors::error) = { diff --git a/rt/+freebsd/env.ha b/rt/+freebsd/env.ha @@ -2,5 +2,5 @@ // (c) 2021 Drew DeVault <sir@cmpwn.com> export let argc: size = 0; -export let argv: *[*]*char = null: *[*]*char; -export let envp: *[*]nullable *char = null: *[*]nullable *char; +export let argv: *[*]*u8 = null: *[*]*u8; +export let envp: *[*]nullable *u8 = null: *[*]nullable *u8; diff --git a/rt/+freebsd/platform_abort.ha b/rt/+freebsd/platform_abort.ha @@ -4,9 +4,9 @@ fn platform_abort(msg: str) void = { const prefix = "Abort: "; const linefeed = "\n"; - write(STDERR_FILENO, *(&prefix: **void): *const char, len(prefix)): void; - write(STDERR_FILENO, *(&msg: **void): *const char, len(msg)): void; - write(STDERR_FILENO, *(&linefeed: **void): *const char, 1): void; + write(STDERR_FILENO, *(&prefix: **void): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&msg: **void): *const u8, len(msg)): void; + write(STDERR_FILENO, *(&linefeed: **void): *const u8, 1): void; kill(getpid(), SIGABRT): void; for (true) void; }; diff --git a/rt/+freebsd/platformstart.ha b/rt/+freebsd/platformstart.ha @@ -4,7 +4,7 @@ export @noreturn fn start_freebsd(iv: *[*]uintptr) void = { // TODO: Find & parse auxv argc = iv[0]: size; - argv = &iv[1]: *[*]*char; - envp = &argv[argc + 1]: *[*]nullable *char; + argv = &iv[1]: *[*]*u8; + envp = &argv[argc + 1]: *[*]nullable *u8; start_ha(); }; diff --git a/rt/+freebsd/socket.ha b/rt/+freebsd/socket.ha @@ -14,7 +14,7 @@ export type sockaddr_in = struct { sin_family: sa_family_t, sin_port: u16, sin_addr: in_addr, - __pad: [8]char, + __pad: [8]u8, }; export type in6_addr = struct { @@ -39,7 +39,7 @@ export def UNIX_PATH_MAX: size = 104; export type sockaddr_un = struct { sun_len: u8, sun_family: sa_family_t, - sun_path: [UNIX_PATH_MAX]char, + sun_path: [UNIX_PATH_MAX]u8, }; export type sockaddr = struct { diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha @@ -12,12 +12,12 @@ fn syscall5(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; fn syscall6(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; export def PATH_MAX: size = 1024z; -export type path = (str | []u8 | *const char); +export type path = (str | []u8 | *const u8); let pathbuf: [PATH_MAX + 1]u8 = [0...]; -fn copy_kpath(path: path, buf: []u8) (*const char | errno) = { +fn copy_kpath(path: path, buf: []u8) (*const u8 | errno) = { let path = match (path) { - case let c: *const char => + case let c: *const u8 => return c; case let s: str => let ptr = &s: *struct { @@ -34,12 +34,12 @@ fn copy_kpath(path: path, buf: []u8) (*const char | errno) = { }; memcpy(buf: *[*]u8, path: *[*]u8, len(path)); buf[len(path)] = 0; - return buf: *[*]u8: *const char; + return buf: *[*]u8: *const u8; }; // NUL terminates a string and stores it in a static buffer of PATH_MAX+1 bytes // in length. -fn kpath(path: path) (*const char | errno) = { +fn kpath(path: path) (*const u8 | errno) = { return copy_kpath(path, pathbuf); }; @@ -218,12 +218,12 @@ export fn getdents(dirfd: int, buf: *void, nbytes: size) (size | errno) = { // The return value is statically allocated and must be duplicated before // calling getcwd again. -export fn getcwd() (*const char | errno) = { +export fn getcwd() (*const u8 | errno) = { static let pathbuf: [PATH_MAX + 1]u8 = [0...]; wrap_return(syscall2(SYS___getcwd, &pathbuf: *[*]u8: uintptr: u64, PATH_MAX + 1))?; - return &pathbuf: *const char; + return &pathbuf: *const u8; }; export fn fchdir(fd: int) (void | errno) = { @@ -275,8 +275,8 @@ export fn fork() (int | void | errno) = { }; }; -export fn fexecve(fd: int, argv: *[*]nullable *const char, - envp: *[*]nullable *const char) errno = { +export fn fexecve(fd: int, argv: *[*]nullable *const u8, + envp: *[*]nullable *const u8) errno = { return match (wrap_return(syscall3(SYS_fexecve, fd: u64, argv: uintptr: u64, envp: uintptr: u64))) { case let err: errno => diff --git a/rt/+freebsd/types.ha b/rt/+freebsd/types.ha @@ -127,7 +127,7 @@ export type freebsd11_dirent = struct { d_reclen: u16, d_type: u8, d_namlen: u8, - d_name: [*]char, + d_name: [*]u8, }; export type iovec = struct { @@ -220,7 +220,7 @@ export type tcflag = enum uint { NOFLSH = 0x80000000, }; -export type cc = enum char { +export type cc = enum u8 { VEOF = 0, VEOL = 1, VEOL2 = 2, diff --git a/rt/+linux/env.ha b/rt/+linux/env.ha @@ -2,5 +2,5 @@ // (c) 2021 Drew DeVault <sir@cmpwn.com> export let argc: size = 0; -export let argv: *[*]*char = null: *[*]*char; -export let envp: *[*]nullable *char = null: *[*]nullable *char; +export let argv: *[*]*u8 = null: *[*]*u8; +export let envp: *[*]nullable *u8 = null: *[*]nullable *u8; diff --git a/rt/+linux/platform_abort.ha b/rt/+linux/platform_abort.ha @@ -4,9 +4,9 @@ fn platform_abort(msg: str) void = { const prefix = "Abort: "; const linefeed = "\n"; - write(STDERR_FILENO, *(&prefix: **void): *const char, len(prefix)): void; - write(STDERR_FILENO, *(&msg: **void): *const char, len(msg)): void; - write(STDERR_FILENO, *(&linefeed: **void): *const char, 1): void; + write(STDERR_FILENO, *(&prefix: **void): *const u8, len(prefix)): void; + write(STDERR_FILENO, *(&msg: **void): *const u8, len(msg)): void; + write(STDERR_FILENO, *(&linefeed: **void): *const u8, 1): void; kill(getpid(), SIGABRT): void; for (true) void; }; diff --git a/rt/+linux/platformstart+libc.ha b/rt/+linux/platformstart+libc.ha @@ -7,17 +7,17 @@ export fn start_linux() void = { // them, it's possible to traverse backwards calculating how many // entries were processed and comparing that value to the one at // current position. - let argv_ptr = c_environ: uintptr - size(*char): uintptr * 2; + let argv_ptr = c_environ: uintptr - size(*u8): uintptr * 2; let i = 0z; - for (*(argv_ptr: **char): uintptr: size != i; i += 1) { - argv_ptr -= size(*char): uintptr; + for (*(argv_ptr: **u8): uintptr: size != i; i += 1) { + argv_ptr -= size(*u8): uintptr; }; argc = i; - argv = (argv_ptr + size(*char): uintptr): *[*]*char; + argv = (argv_ptr + size(*u8): uintptr): *[*]*u8; envp = c_environ; }; @init fn start_linux() void = start_linux(); -let @symbol("environ") c_environ: *[*]nullable *char; +let @symbol("environ") c_environ: *[*]nullable *u8; diff --git a/rt/+linux/platformstart.ha b/rt/+linux/platformstart.ha @@ -4,7 +4,7 @@ export @noreturn fn start_linux(iv: *[*]uintptr) void = { argc = iv[0]: size; - argv = &iv[1]: *[*]*char; - envp = &argv[argc + 1]: *[*]nullable *char; + argv = &iv[1]: *[*]*u8; + envp = &argv[argc + 1]: *[*]nullable *u8; start_ha(); }; diff --git a/rt/+linux/socket.ha b/rt/+linux/socket.ha @@ -13,7 +13,7 @@ export type sockaddr_in = struct { sin_family: sa_family_t, sin_port: u16, sin_addr: in_addr, - __pad: [16]char, + __pad: [16]u8, }; export type in6_addr = struct { @@ -36,7 +36,7 @@ export def UNIX_PATH_MAX: size = 108; export type sockaddr_un = struct { sun_family: sa_family_t, - sun_path: [UNIX_PATH_MAX]char, + sun_path: [UNIX_PATH_MAX]u8, }; export type sockaddr_nl = struct { diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -15,12 +15,12 @@ fn syscall5(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; fn syscall6(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; export def PATH_MAX: size = 4096z; -export type path = (str | []u8 | *const char); +export type path = (str | []u8 | *const u8); let pathbuf: [PATH_MAX + 1]u8 = [0...]; -fn copy_kpath(path: path, buf: []u8) (*const char | errno) = { +fn copy_kpath(path: path, buf: []u8) (*const u8 | errno) = { let path = match (path) { - case let c: *const char => + case let c: *const u8 => return c; case let s: str => let ptr = &s: *struct { @@ -37,12 +37,12 @@ fn copy_kpath(path: path, buf: []u8) (*const char | errno) = { }; memcpy(buf: *[*]u8, path: *[*]u8, len(path)); buf[len(path)] = 0; - return buf: *[*]u8: *const char; + return buf: *[*]u8: *const u8; }; // NUL terminates a string and stores it in a static buffer of PATH_MAX+1 bytes // in length. -fn kpath(path: path) (*const char | errno) = { +fn kpath(path: path) (*const u8 | errno) = { return copy_kpath(path, pathbuf); }; @@ -228,8 +228,8 @@ export fn mkdirat(dirfd: int, path: path, mode: uint) (void | errno) = { dirfd: u64, path: uintptr: u64, mode: u64))?; }; -export fn execveat(dirfd: int, path: path, argv: *[*]nullable *const char, - envp: *[*]nullable *const char, flags: int) errno = { +export fn execveat(dirfd: int, path: path, argv: *[*]nullable *const u8, + envp: *[*]nullable *const u8, flags: int) errno = { let path = kpath(path)?; return match (wrap_return(syscall5(SYS_execveat, dirfd: u64, path: uintptr: u64, argv: uintptr: u64, @@ -241,8 +241,8 @@ export fn execveat(dirfd: int, path: path, argv: *[*]nullable *const char, }; }; -export fn execve(path: path, argv: *[*]nullable *const char, - envp: *[*]nullable *const char) errno = { +export fn execve(path: path, argv: *[*]nullable *const u8, + envp: *[*]nullable *const u8) errno = { let path = kpath(path)?; return match (wrap_return(syscall3(SYS_execve, path: uintptr: u64, argv: uintptr, envp: uintptr))) { @@ -345,7 +345,7 @@ export fn ftruncate(fd: int, ln: off_t) (void | errno) = { wrap_return(syscall2(SYS_ftruncate, fd: u64, ln: u32))?; }; -fn faccessat1(dirfd: int, path: *const char, mode: int) (bool | errno) = { +fn faccessat1(dirfd: int, path: *const u8, mode: int) (bool | errno) = { return match (wrap_return(syscall3(SYS_faccessat, dirfd: u64, path: uintptr: u64, mode: u64))) { case let err: errno => @@ -442,12 +442,12 @@ export fn uname(uts: *utsname) (void | errno) = { // The return value is statically allocated and must be duplicated before // calling getcwd again. -export fn getcwd() (*const char | errno) = { +export fn getcwd() (*const u8 | errno) = { static let pathbuf: [PATH_MAX + 1]u8 = [0...]; wrap_return(syscall2(SYS_getcwd, &pathbuf: *[*]u8: uintptr: u64, PATH_MAX + 1))?; - return &pathbuf: *const char; + return &pathbuf: *const u8; }; export fn ppoll( @@ -785,8 +785,8 @@ export fn prctl( }; export fn add_key( - keytype: *const char, - name: *const char, + keytype: *const u8, + name: *const u8, payload: *void, plen: size, keyring: int, @@ -819,7 +819,7 @@ export fn setsid() (void | errno) = { export fn mount( source: path, target: path, - filesystemtype: *const char, + filesystemtype: *const u8, mountflags: u64, data: nullable *void ) (void | errno) = { @@ -925,7 +925,7 @@ export type inotify_event = struct { mask: u32, cookie: u32, length: u32, - name: *const char + name: *const u8 }; export fn shmat(id: int, addr: *const void, flag: int) *void = { diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -302,7 +302,7 @@ export type dirent64 = struct { d_off: off_t, d_reclen: u16, d_type: u8, - d_name: [*]char, + d_name: [*]u8, }; export def WNOHANG: int = 1; @@ -342,12 +342,12 @@ export type rusage = struct { }; export type utsname = struct { - sysname: [65]char, - nodename: [65]char, - release: [65]char, - version: [65]char, - machine: [65]char, - domainname: [65]char, + sysname: [65]u8, + nodename: [65]u8, + release: [65]u8, + version: [65]u8, + machine: [65]u8, + domainname: [65]u8, }; export def POLLIN: i16 = 0x001; @@ -576,7 +576,7 @@ export type termios = struct { export def NCCS: size = 19; -export type cc = enum char { +export type cc = enum u8 { VINTR = 0, VQUIT = 1, VERASE = 2, diff --git a/rt/+test/cstring.ha b/rt/+test/cstring.ha @@ -1,14 +1,14 @@ // License: MPL-2.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> -fn c_strlen(cstr: *const char) size = { +fn c_strlen(cstr: *const u8) size = { const ptr = cstr: *[*]u8; let ln = 0z; for (ptr[ln] != 0; ln += 1) void; return ln; }; -fn from_c_unsafe(cstr: *const char) const str = { +fn from_c_unsafe(cstr: *const u8) const str = { const l = c_strlen(cstr); const s = struct { data: *[*]u8 = cstr: *[*]u8, diff --git a/rt/+test/run.ha b/rt/+test/run.ha @@ -101,7 +101,7 @@ export fn tests_main() size = { }; fn print(msg: str) void = { - write(STDOUT_FILENO, *(&msg: **void): *const char, len(msg))!; + write(STDOUT_FILENO, *(&msg: **void): *const u8, len(msg))!; }; fn dots(n: size) void = { diff --git a/rt/abort.ha b/rt/abort.ha @@ -20,11 +20,11 @@ export @noreturn fn abort_fixed(loc: str, i: int) void = { const prefix = "Abort: "; const sep = ": "; const linefeed = "\n"; - write(STDERR_FILENO, *(&prefix: **void): *const char, len(prefix)): void; - write(STDERR_FILENO, *(&loc: **void): *const char, len(loc)): void; - write(STDERR_FILENO, *(&sep: **void): *const char, len(sep)): void; - write(STDERR_FILENO, *(&reasons[i]: **void): *const char, len(reasons[i])): void; - write(STDERR_FILENO, *(&linefeed: **void): *const char, 1): void; + 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, *(&reasons[i]: **void): *const u8, len(reasons[i])): void; + write(STDERR_FILENO, *(&linefeed: **void): *const u8, 1): void; kill(getpid(), SIGABRT): void; for (true) void; }; diff --git a/types/c/arch+aarch64.ha b/types/c/arch+aarch64.ha @@ -1,3 +1,6 @@ +// Integer type compatible with `char`, as specified by ISO/IEC 9899. +export type char = uchar; + // Integer type compatible with `signed char`, as specified by ISO/IEC 9899. export type schar = i8; diff --git a/types/c/arch+riscv64.ha b/types/c/arch+riscv64.ha @@ -1,3 +1,6 @@ +// Integer type compatible with `char`, as specified by ISO/IEC 9899. +export type char = uchar; + // Integer type compatible with `signed char`, as specified by ISO/IEC 9899. export type schar = i8; diff --git a/types/c/arch+x86_64.ha b/types/c/arch+x86_64.ha @@ -1,3 +1,6 @@ +// Integer type compatible with `char`, as specified by ISO/IEC 9899. +export type char = schar; + // Integer type compatible with `signed char`, as specified by ISO/IEC 9899. export type schar = i8; diff --git a/unix/tty/+freebsd/pty.ha b/unix/tty/+freebsd/pty.ha @@ -48,7 +48,7 @@ export fn ptsname(master: io::file) (str | error) = { case => static let path_buf: [rt::PATH_MAX]u8 = [0...]; return fmt::bsprintf(path_buf, - "/dev/{}", c::tostr(&name: *const char)!); + "/dev/{}", c::tostr(&name: *const c::char)!); }; };