From 5c2c70b4ec9694046fd457975d3999d2da3336b4 Mon Sep 17 00:00:00 2001 From: StunxFS Date: Wed, 29 Nov 2023 19:11:50 -0400 Subject: [PATCH 1/3] refact(rivetc+rivet): remove `public`, use `pub` instead --- cmd/src/tools/cmd_new.ri | 2 +- cmd/src/tools/templates/mod.ri | 10 +- cmd/src/tools/utils.ri | 2 +- lib/c/src/ctypes/mod.ri | 72 +++++----- lib/c/src/errno.ri | 14 +- lib/c/src/libc/dirent.ri | 18 +-- lib/c/src/libc/dlfcn.ri | 16 +-- lib/c/src/libc/errno.ri | 16 +-- lib/c/src/libc/mod.ri | 2 +- lib/c/src/libc/signal.ri | 132 +++++++++--------- lib/c/src/libc/stat.ri | 34 ++--- lib/c/src/libc/stdio.ri | 172 ++++++++++++------------ lib/c/src/libc/stdlib.ri | 46 +++---- lib/c/src/libc/string.ri | 16 +-- lib/c/src/libc/time.ri | 2 +- lib/c/src/libc/unistd.ri | 24 ++-- lib/c/src/wyhash.ri | 6 +- lib/core/src/StaticBuffer.c.ri | 10 +- lib/core/src/StringBuilder.c.ri | 34 ++--- lib/core/src/StringFormatter.ri | 2 +- lib/core/src/TokenIterator.ri | 10 +- lib/core/src/Vector.c.ri | 8 +- lib/core/src/backtrace.c.ri | 2 +- lib/core/src/bool.ri | 2 +- lib/core/src/console.c.ri | 10 +- lib/core/src/entry_point.ri | 2 +- lib/core/src/errors.c.ri | 6 +- lib/core/src/errors.ri | 14 +- lib/core/src/float.c.ri | 16 +-- lib/core/src/int.ri | 36 ++--- lib/core/src/mem.c.ri | 18 +-- lib/core/src/process.c.ri | 14 +- lib/core/src/rune.c.ri | 18 +-- lib/core/src/string.c.ri | 106 +++++++-------- lib/core/src/traits.ri | 4 +- lib/core/src/uint.ri | 50 +++---- lib/core/src/wyhash.c.ri | 4 +- lib/rivet/src/ast/Attributes.ri | 34 ++--- lib/rivet/src/ast/CHeader.ri | 16 +-- lib/rivet/src/ast/Decl.ri | 48 +++---- lib/rivet/src/ast/Expr.ri | 78 +++++------ lib/rivet/src/ast/Scope.ri | 46 +++---- lib/rivet/src/ast/Stmt.ri | 6 +- lib/rivet/src/ast/Sym.ri | 128 +++++++++--------- lib/rivet/src/ast/Table.ri | 148 ++++++++++---------- lib/rivet/src/ast/Type.ri | 34 ++--- lib/rivet/src/ast/TypeInfo.ri | 24 ++-- lib/rivet/src/ast/TypeSym.ri | 62 ++++----- lib/rivet/src/ast/mod.ri | 54 ++++---- lib/rivet/src/build/mod.ri | 24 ++-- lib/rivet/src/checker/mod.ri | 4 +- lib/rivet/src/checker/name_cases.ri | 2 +- lib/rivet/src/checker/types.ri | 2 +- lib/rivet/src/codegen/mir/Block.ri | 10 +- lib/rivet/src/codegen/mir/Expr.ri | 6 +- lib/rivet/src/codegen/mir/Type.ri | 6 +- lib/rivet/src/codegen/mir/mod.ri | 112 +++++++-------- lib/rivet/src/codegen/mod.ri | 6 +- lib/rivet/src/depgraph/OrderedDepMap.ri | 16 +-- lib/rivet/src/depgraph/mod.ri | 20 +-- lib/rivet/src/lib.ri | 4 +- lib/rivet/src/parser/decls.ri | 8 +- lib/rivet/src/parser/mod.ri | 6 +- lib/rivet/src/prefs/mod.ri | 84 ++++++------ lib/rivet/src/report/mod.ri | 30 ++--- lib/rivet/src/resolver/Register.ri | 4 +- lib/rivet/src/resolver/mod.ri | 4 +- lib/rivet/src/token/Kind.ri | 24 ++-- lib/rivet/src/token/mod.ri | 42 +++--- lib/rivet/src/tokenizer/mod.ri | 10 +- lib/rivet/src/tokenizer/next.ri | 2 +- lib/rivet/src/utils/array.ri | 6 +- lib/rivet/src/utils/file.ri | 16 +-- lib/rivet/src/utils/maps/mod.ri | 54 ++++---- lib/rivet/src/utils/mod.ri | 32 ++--- lib/rivet/src/utils/name_cases.ri | 8 +- lib/rivet/src/utils/smart_quote.ri | 2 +- lib/rivet/src/utils/tokenizer.ri | 4 +- lib/rivet/src/utils/version.ri | 6 +- lib/std/src/backtrace/mod.ri | 2 +- lib/std/src/console/mod.ri | 12 +- lib/std/src/console/styles/bg.ri | 32 ++--- lib/std/src/console/styles/fg.ri | 34 ++--- lib/std/src/console/styles/mod.ri | 32 ++--- lib/std/src/conv/bool_to.ri | 4 +- lib/std/src/conv/parse_int.ri | 12 +- lib/std/src/conv/string_to.ri | 22 +-- lib/std/src/dynlib/mod.ri | 22 +-- lib/std/src/env/mod.ri | 10 +- lib/std/src/errors/mod.ri | 20 +-- lib/std/src/flag/errors.ri | 14 +- lib/std/src/flag/mod.ri | 50 +++---- lib/std/src/fs/Directory.ri | 26 ++-- lib/std/src/fs/File.ri | 24 ++-- lib/std/src/fs/Path.ri | 44 +++--- lib/std/src/fs/mod.ri | 4 +- lib/std/src/hash/fnv1a/mod.ri | 12 +- lib/std/src/hash/mod.ri | 4 +- lib/std/src/hash/wyhash/mod.ri | 4 +- lib/std/src/lib.ri | 32 ++--- lib/std/src/math/mod.ri | 32 ++--- lib/std/src/mem/mod.ri | 18 +-- lib/std/src/process/mod.ri | 32 ++--- lib/std/src/semver/mod.ri | 52 +++---- lib/std/src/semver/range.ri | 4 +- lib/std/src/strings/TextScanner.ri | 26 ++-- lib/std/src/strings/mod.ri | 6 +- lib/std/src/sys/arch.ri | 8 +- lib/std/src/sys/c_runtime.ri | 4 +- lib/std/src/sys/mod.ri | 10 +- lib/std/src/sys/os.ri | 8 +- lib/std/src/traits/mod.ri | 4 +- rivetc/src/codegen/c.py | 4 +- rivetc/src/codegen/ir.py | 12 +- rivetc/src/parser.py | 4 +- rivetc/src/sym.py | 2 +- rivetc/src/token.py | 4 +- tests/invalid/invalid_throw_use.ri | 2 +- tests/invalid/special_methods.out | 6 +- tests/invalid/special_methods.ri | 2 +- tests/run_invalid_tests.py | 4 + tests/valid/src/mod/mod.ri | 2 +- tests/valid/src/results.ri | 4 +- tests/valid/src/traits.ri | 8 +- 124 files changed, 1429 insertions(+), 1427 deletions(-) diff --git a/cmd/src/tools/cmd_new.ri b/cmd/src/tools/cmd_new.ri index f46b9bfe4..ab8527a08 100644 --- a/cmd/src/tools/cmd_new.ri +++ b/cmd/src/tools/cmd_new.ri @@ -29,7 +29,7 @@ var availableTemplates := "Available templates: bin A simple binary project (default). lib A simple library project."; -public func new(args: []string, is_init: bool) -> ! { +pub func new(args: []string, is_init: bool) -> ! { mut template := ""; mut fp := flag.FlagParser.new(args); if is_init { diff --git a/cmd/src/tools/templates/mod.ri b/cmd/src/tools/templates/mod.ri index 236d85304..99958ba06 100644 --- a/cmd/src/tools/templates/mod.ri +++ b/cmd/src/tools/templates/mod.ri @@ -2,14 +2,14 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public var mainFile := "import std/console; +pub var mainFile := "import std/console; func main() { console.writeln(\"Hello World!\"); } "; -public var libFile := "public func add(a: int32, b: int32) -> int32 { +pub var libFile := "pub func add(a: int32, b: int32) -> int32 { return a + b; } @@ -18,7 +18,7 @@ test \"test `add` function\" { } "; -public var gitignoreFile := "# Binaries for programs and plugins +pub var gitignoreFile := "# Binaries for programs and plugins {} *.exe *.exe~ @@ -39,12 +39,12 @@ bin/ .env "; -public var gitattributesFile := "* text=auto eol=lf +pub var gitattributesFile := "* text=auto eol=lf *.bat eol=crlf *.ri linguist-language=Rivet text=auto eol=lf "; -public var editorConfigFile := "[*] +pub var editorConfigFile := "[*] charset = utf-8 end_of_line = lf insert_final_newline = true diff --git a/cmd/src/tools/utils.ri b/cmd/src/tools/utils.ri index 428b1c332..2c09a0f4c 100644 --- a/cmd/src/tools/utils.ri +++ b/cmd/src/tools/utils.ri @@ -6,7 +6,7 @@ import std/console; import std/console/styles; #[inline] -public func readln(prompt: string) -> ?string { +pub func readln(prompt: string) -> ?string { prefix := styles.bold(styles.green("> ")); return if prompt.is_empty() { console.readln(prefix) diff --git a/lib/c/src/ctypes/mod.ri b/lib/c/src/ctypes/mod.ri index 5910bee47..45e8540aa 100644 --- a/lib/c/src/ctypes/mod.ri +++ b/lib/c/src/ctypes/mod.ri @@ -2,39 +2,39 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public alias char := uint8; -public alias schar := int8; -public alias uchar := uint8; - -public alias short := int16; -public alias ushort := uint16; - -public alias int := int32; -public alias uint := uint32; - -public alias long := int64; -public alias longlong := int64; - -public alias ulong := uint64; -public alias ulonglong := uint64; - -public alias float := float32; -public alias double := float64; - -public alias wchar_t := uint32; -public alias intmax_t := int64; -public alias uintmax_t := uint64; - -public alias size_t := uint; -public alias ptrdiff_t := int; -public alias intptr_t := int; -public alias uintptr_t := uint; -public alias ssize_t := int; - -public alias pid_t := int32; -public alias off_t := int64; -public alias ino_t := uint64; -public alias dev_t := uint64; -public alias uid_t := uint32; -public alias gid_t := uint32; -public alias mode_t := uint; +pub alias char := uint8; +pub alias schar := int8; +pub alias uchar := uint8; + +pub alias short := int16; +pub alias ushort := uint16; + +pub alias int := int32; +pub alias uint := uint32; + +pub alias long := int64; +pub alias longlong := int64; + +pub alias ulong := uint64; +pub alias ulonglong := uint64; + +pub alias float := float32; +pub alias double := float64; + +pub alias wchar_t := uint32; +pub alias intmax_t := int64; +pub alias uintmax_t := uint64; + +pub alias size_t := uint; +pub alias ptrdiff_t := int; +pub alias intptr_t := int; +pub alias uintptr_t := uint; +pub alias ssize_t := int; + +pub alias pid_t := int32; +pub alias off_t := int64; +pub alias ino_t := uint64; +pub alias dev_t := uint64; +pub alias uid_t := uint32; +pub alias gid_t := uint32; +pub alias mode_t := uint; diff --git a/lib/c/src/errno.ri b/lib/c/src/errno.ri index 9109b0024..9ca350ce0 100644 --- a/lib/c/src/errno.ri +++ b/lib/c/src/errno.ri @@ -5,17 +5,17 @@ import c/libc; #[boxed] -public struct ErrnoError < Throwable { - public msg: string; - public code: int32; +pub struct ErrnoError < Throwable { + pub msg: string; + pub code: int32; - public func to_string(self) -> string { + pub func to_string(self) -> string { return "errno: {} (code: {})".fmt(self.msg, self.code); } } #[inline] -public func errno() -> int32 { +pub func errno() -> int32 { return unsafe { #if _LINUX_ libc.__errno_location()?.* @@ -26,7 +26,7 @@ public func errno() -> int32 { } #[inline] -public func errno_msg(code: int32 := errno()) -> string { +pub func errno_msg(code: int32 := errno()) -> string { unsafe { return if s := libc.strerror(code) { string.from_raw(s) @@ -37,6 +37,6 @@ public func errno_msg(code: int32 := errno()) -> string { } #[inline] -public func last_errno_error() -> ErrnoError { +pub func last_errno_error() -> ErrnoError { return ErrnoError(errno_msg(), errno()); } diff --git a/lib/c/src/libc/dirent.ri b/lib/c/src/libc/dirent.ri index 3a8ed743a..e202f1e43 100644 --- a/lib/c/src/libc/dirent.ri +++ b/lib/c/src/libc/dirent.ri @@ -2,16 +2,16 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public struct dirent { - public d_ino: uint; - public d_off: uint; - public d_reclen: uint16; - public d_type: uint8; - public d_name: [256]uint8; +pub struct dirent { + pub d_ino: uint; + pub d_off: uint; + pub d_reclen: uint16; + pub d_type: uint8; + pub d_name: [256]uint8; } extern (C) { - public func opendir(d: [&]uint8) -> ?&dirent; - public func readdir(d: &dirent) -> ?&dirent; - public func closedir(d: &dirent) -> int32; + pub func opendir(d: [&]uint8) -> ?&dirent; + pub func readdir(d: &dirent) -> ?&dirent; + pub func closedir(d: &dirent) -> int32; } diff --git a/lib/c/src/libc/dlfcn.ri b/lib/c/src/libc/dlfcn.ri index dc6dbe841..83af1096c 100644 --- a/lib/c/src/libc/dlfcn.ri +++ b/lib/c/src/libc/dlfcn.ri @@ -2,14 +2,14 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public const RTLD_LAZY := 0x001; -public const RTLD_NOW := 0x002; -public const RTLD_BINDING_MASK := 0x3; -public const RTLD_GLOBAL := 0x100; +pub const RTLD_LAZY := 0x001; +pub const RTLD_NOW := 0x002; +pub const RTLD_BINDING_MASK := 0x3; +pub const RTLD_GLOBAL := 0x100; extern (C) { - public func dlopen(__file: [&]uint8, __mode: int32) -> ?rawptr; - public func dlclose(__handle: rawptr) -> int32; - public func dlsym(__handle: rawptr, __name: [&]uint8) -> ?rawptr; - public func dlerror() -> ?[&]uint8; + pub func dlopen(__file: [&]uint8, __mode: int32) -> ?rawptr; + pub func dlclose(__handle: rawptr) -> int32; + pub func dlsym(__handle: rawptr, __name: [&]uint8) -> ?rawptr; + pub func dlerror() -> ?[&]uint8; } diff --git a/lib/c/src/libc/errno.ri b/lib/c/src/libc/errno.ri index bc97bdff2..7d16e7217 100644 --- a/lib/c/src/libc/errno.ri +++ b/lib/c/src/libc/errno.ri @@ -4,21 +4,21 @@ #if _LINUX_ extern (C) { - public func __errno_location() -> ?&mut int32; + pub func __errno_location() -> ?&mut int32; } -public const EDOM := 33; -public const EILSEQ := 84; -public const ERANGE := 34; +pub const EDOM := 33; +pub const EILSEQ := 84; +pub const ERANGE := 34; #endif #if _WINDOWS_ extern (C) { [dllimport] - public func _errno() &mut int32; + pub func _errno() &mut int32; } -public const EDOM := 33; -public const EILSEQ := 42; -public const ERANGE := 34; +pub const EDOM := 33; +pub const EILSEQ := 42; +pub const ERANGE := 34; #endif diff --git a/lib/c/src/libc/mod.ri b/lib/c/src/libc/mod.ri index 6f74a59e6..9904b34e7 100644 --- a/lib/c/src/libc/mod.ri +++ b/lib/c/src/libc/mod.ri @@ -3,5 +3,5 @@ // be found in the LICENSE file. extern (C) { - public var environ: [&][&]uint8; + pub var environ: [&][&]uint8; } diff --git a/lib/c/src/libc/signal.ri b/lib/c/src/libc/signal.ri index a05fc264f..caaeb0e4c 100644 --- a/lib/c/src/libc/signal.ri +++ b/lib/c/src/libc/signal.ri @@ -7,90 +7,90 @@ import { pid_t, uid_t } from ../ctypes; -public alias SignalHandler := func(int32, &mut siginfo_t, rawptr); +pub alias SignalHandler := func(int32, &mut siginfo_t, rawptr); #if _LINUX_ - public const SA_ONSTACK := 0x08000000; - public const SA_SIGINFO := 0x00000004; - public const SA_NOCLDWAIT := 0x00000002; + pub const SA_ONSTACK := 0x08000000; + pub const SA_SIGINFO := 0x00000004; + pub const SA_NOCLDWAIT := 0x00000002; - public const SIGHUP := 0x1; - public const SIGINT := 0x2; - public const SIGQUIT := 0x3; - public const SIGILL := 0x4; - public const SIGTRAP := 0x5; - public const SIGABRT := 0x6; - public const SIGEMT := 0x7; - public const SIGFPE := 0x8; - public const SIGKILL := 0x9; - public const SIGBUS := 0xA; - public const SIGSEGV := 0xB; - public const SIGSYS := 0xc; - public const SIGPIPE := 0xd; - public const SIGALRM := 0xe; - public const SIGTERM := 0xF; - public const SIGURG := 0x10; - public const SIGSTOP := 0x11; - public const SIGTSTP := 0x12; - public const SIGCONT := 0x13; - public const SIGCHLD := 0x14; - public const SIGTTIN := 0x15; - public const SIGTTOU := 0x16; - public const SIGIO := 0x17; - public const SIGXCPU := 0x18; - public const SIGXFSZ := 0x19; - public const SIGVTALRM := 0x1a; - public const SIGPROF := 0x1b; - public const SIGWINCH := 0x1c; - public const SIGINFO := 0x1d; - public const SIGUSR1 := 0x1e; - public const SIGUSR2 := 0x1f; + pub const SIGHUP := 0x1; + pub const SIGINT := 0x2; + pub const SIGQUIT := 0x3; + pub const SIGILL := 0x4; + pub const SIGTRAP := 0x5; + pub const SIGABRT := 0x6; + pub const SIGEMT := 0x7; + pub const SIGFPE := 0x8; + pub const SIGKILL := 0x9; + pub const SIGBUS := 0xA; + pub const SIGSEGV := 0xB; + pub const SIGSYS := 0xc; + pub const SIGPIPE := 0xd; + pub const SIGALRM := 0xe; + pub const SIGTERM := 0xF; + pub const SIGURG := 0x10; + pub const SIGSTOP := 0x11; + pub const SIGTSTP := 0x12; + pub const SIGCONT := 0x13; + pub const SIGCHLD := 0x14; + pub const SIGTTIN := 0x15; + pub const SIGTTOU := 0x16; + pub const SIGIO := 0x17; + pub const SIGXCPU := 0x18; + pub const SIGXFSZ := 0x19; + pub const SIGVTALRM := 0x1a; + pub const SIGPROF := 0x1b; + pub const SIGWINCH := 0x1c; + pub const SIGINFO := 0x1d; + pub const SIGUSR1 := 0x1e; + pub const SIGUSR2 := 0x1f; - public const SEGV_MAPERR := 0x1; - public const SEGV_ACCERR := 0x2; + pub const SEGV_MAPERR := 0x1; + pub const SEGV_ACCERR := 0x2; - public struct sigset_t { - public __val: [#if _X86_ 32 #else 16 #endif]uint32; + pub struct sigset_t { + pub __val: [#if _X86_ 32 #else 16 #endif]uint32; } - public struct sigval { - public sival_ptr: rawptr; + pub struct sigval { + pub sival_ptr: rawptr; } - public struct siginfo_t { - public si_signo: int32; // signal number - public si_errno: int32; // errno association - public si_code: int32; // signal code - public si_pid: pid_t; // sending process - public si_uid: uid_t; // sender's ruid - public si_status: int32; // exit value - public si_addr: rawptr; // faulting instruction - public si_value: sigval; // signal value - public si_band: int64; // band event for SIGPOLL - public _: [7]uint64; // reserved for future use + pub struct siginfo_t { + pub si_signo: int32; // signal number + pub si_errno: int32; // errno association + pub si_code: int32; // signal code + pub si_pid: pid_t; // sending process + pub si_uid: uid_t; // sender's ruid + pub si_status: int32; // exit value + pub si_addr: rawptr; // faulting instruction + pub si_value: sigval; // signal value + pub si_band: int64; // band event for SIGPOLL + pub _: [7]uint64; // reserved for future use } - public struct sigaction_t { - public sa_sigaction: SignalHandler; - public sa_mask: sigset_t; - public sa_flags: int32; - public sa_restorer: func(); + pub struct sigaction_t { + pub sa_sigaction: SignalHandler; + pub sa_mask: sigset_t; + pub sa_flags: int32; + pub sa_restorer: func(); } #else_if _WINDOWS_ - public const SIGABRT := 22; - public const SIGFPE := 8; - public const SIGILL := 4; - public const SIGINT := 2; - public const SIGSEGV := 11; - public const SIGTERM := 15; + pub const SIGABRT := 22; + pub const SIGFPE := 8; + pub const SIGILL := 4; + pub const SIGINT := 2; + pub const SIGSEGV := 11; + pub const SIGTERM := 15; #else #error cannot define values for signals in this operating system, please report the issue #endif extern (C) { #if _LINUX_ - public func sigaction(signum: int32, act: ?&sigaction_t, old_act: ?&mut sigaction_t) -> int32; + pub func sigaction(signum: int32, act: ?&sigaction_t, old_act: ?&mut sigaction_t) -> int32; #endif - public func signal(sig: int32, handler: SignalHandler) -> ?SignalHandler; - public func raise(sig: int32) -> int32; + pub func signal(sig: int32, handler: SignalHandler) -> ?SignalHandler; + pub func raise(sig: int32) -> int32; } diff --git a/lib/c/src/libc/stat.ri b/lib/c/src/libc/stat.ri index 5244ffb32..bbb9d2e66 100644 --- a/lib/c/src/libc/stat.ri +++ b/lib/c/src/libc/stat.ri @@ -6,30 +6,30 @@ import { * } from c/ctypes; #if _AMD64_ // The `stat` definition used by the Linux kernel. -public struct Stat { - public dev: dev_t; - public ino: ino_t; - public nlink: uint; +pub struct Stat { + pub dev: dev_t; + pub ino: ino_t; + pub nlink: uint; - public mode: uint32; - public uid: uid_t; - public gid: gid_t; + pub mode: uint32; + pub uid: uid_t; + pub gid: gid_t; __pad0: uint32; - public rdev: dev_t; - public size: off_t; - public blksize: int; - public blocks: int64; + pub rdev: dev_t; + pub size: off_t; + pub blksize: int; + pub blocks: int64; - public atim: timespec; - public mtim: timespec; - public ctim: timespec; + pub atim: timespec; + pub mtim: timespec; + pub ctim: timespec; __unused: [3]int; } #endif extern (C) { - public func stat(__file: [&]uint8, __buf: &mut Stat) -> int32; - public func lstat(file: [&]uint8, buf: &mut Stat) -> int32; + pub func stat(__file: [&]uint8, __buf: &mut Stat) -> int32; + pub func lstat(file: [&]uint8, buf: &mut Stat) -> int32; - public func mkdir(path: [&]uint8, mode: uint) -> int32; + pub func mkdir(path: [&]uint8, mode: uint) -> int32; } diff --git a/lib/c/src/libc/stdio.ri b/lib/c/src/libc/stdio.ri index 565a92183..0089e4dad 100644 --- a/lib/c/src/libc/stdio.ri +++ b/lib/c/src/libc/stdio.ri @@ -4,64 +4,64 @@ import { * } from c/ctypes; -public const MAX_PATH_LEN: uint := 4096; -public const MAX_NAME_LEN: uint := 255; - -public const STDIN_FILENO := 0; -public const STDOUT_FILENO := 1; -public const STDERR_FILENO := 2; - -public const F_OK := 0; -public const X_OK := 1; -public const W_OK := 2; -public const R_OK := 4; - -public const S_IFMT := 0xF000; // file -public const S_IFDIR := 0x4000; // directory -public const S_IFLNK := 0xA000; // link - -public const O_RDONLY := 0x00000; -public const O_WRONLY := 0x00001; -public const O_RDWR := 0x00002; -public const O_CREATE := 0x00040; -public const O_EXCL := 0x00080; -public const O_NOCTTY := 0x00100; -public const O_TRUNC := 0x00200; -public const O_NONBLOCK := 0x00800; -public const O_APPEND := 0x00400; -public const O_SYNC := 0x01000; -public const O_ASYNC := 0x02000; -public const O_CLOEXEC := 0x80000; - -public struct FILE; +pub const MAX_PATH_LEN: uint := 4096; +pub const MAX_NAME_LEN: uint := 255; + +pub const STDIN_FILENO := 0; +pub const STDOUT_FILENO := 1; +pub const STDERR_FILENO := 2; + +pub const F_OK := 0; +pub const X_OK := 1; +pub const W_OK := 2; +pub const R_OK := 4; + +pub const S_IFMT := 0xF000; // file +pub const S_IFDIR := 0x4000; // directory +pub const S_IFLNK := 0xA000; // link + +pub const O_RDONLY := 0x00000; +pub const O_WRONLY := 0x00001; +pub const O_RDWR := 0x00002; +pub const O_CREATE := 0x00040; +pub const O_EXCL := 0x00080; +pub const O_NOCTTY := 0x00100; +pub const O_TRUNC := 0x00200; +pub const O_NONBLOCK := 0x00800; +pub const O_APPEND := 0x00400; +pub const O_SYNC := 0x01000; +pub const O_ASYNC := 0x02000; +pub const O_CLOEXEC := 0x80000; + +pub struct FILE; #if _LINUX_ extern (C) { - public var stdin: &mut FILE; - public var stdout: &mut FILE; - public var stderr: &mut FILE; + pub var stdin: &mut FILE; + pub var stdout: &mut FILE; + pub var stderr: &mut FILE; } - public struct fpos_t { + pub struct fpos_t { f1: [16]char; f2: longlong; f3: double; } - public const _IOFBF := 0; - public const _IOLBF := 1; - public const _IONBF := 2; + pub const _IOFBF := 0; + pub const _IOLBF := 1; + pub const _IONBF := 2; - public const BUFSIZ := 1024; - public const EOF := -1; - public const FOPEN_MAX := 1000; - public const FILENAME_MAX := 4096; - public const L_tmpnam := 20; - public const SEEK_SET := 0; - public const SEEK_CUR := 1; - public const SEEK_END := 2; + pub const BUFSIZ := 1024; + pub const EOF := -1; + pub const FOPEN_MAX := 1000; + pub const FILENAME_MAX := 4096; + pub const L_tmpnam := 20; + pub const SEEK_SET := 0; + pub const SEEK_CUR := 1; + pub const SEEK_END := 2; - public const TMP_MAX := 308915776; + pub const TMP_MAX := 308915776; #endif #if _WINDOWS_ @@ -69,51 +69,51 @@ public struct FILE; func __acrt_iob_fn(index: uint32) &mut FILE; } - public alias fpos_t := int64; + pub alias fpos_t := int64; - public const _IOFBF := 0x0000; - public const _IOLBF := 0x0004; - public const _IONBF := 0x0040; + pub const _IOFBF := 0x0000; + pub const _IOLBF := 0x0004; + pub const _IONBF := 0x0040; - public const BUFSIZ := 512; - public const EOF := -1; - public const FOPEN_MAX := 20; - public const FILENAME_MAX := 260; - public const L_tmpnam := 15; // "\\" + 12 + NUL - public const SEEK_SET := 0; - public const SEEK_CUR := 1; - public const SEEK_END := 2; + pub const BUFSIZ := 512; + pub const EOF := -1; + pub const FOPEN_MAX := 20; + pub const FILENAME_MAX := 260; + pub const L_tmpnam := 15; // "\\" + 12 + NUL + pub const SEEK_SET := 0; + pub const SEEK_CUR := 1; + pub const SEEK_END := 2; - public const TMP_MAX := 32767; // SHRT_MAX + pub const TMP_MAX := 32767; // SHRT_MAX - public var stdin: &mut FILE := unsafe { __acrt_iob_fn(0) }; - public var stdout: &mut FILE := unsafe { __acrt_iob_fn(1) }; - public var stderr: &mut FILE := unsafe { __acrt_iob_fn(2) }; + pub var stdin: &mut FILE := unsafe { __acrt_iob_fn(0) }; + pub var stdout: &mut FILE := unsafe { __acrt_iob_fn(1) }; + pub var stderr: &mut FILE := unsafe { __acrt_iob_fn(2) }; #endif extern (C) { - public func fopen(path: [&]uint8, mode: [&]uint8) -> ?&mut FILE; - public func feof(stream: &FILE) -> int32; - public func ferror(stream: &FILE) -> int32; - public func fseek(stream: &mut FILE, offset: uint64, whence: int32) -> int32; - public func ftell(stream: &mut FILE) -> int64; - public func fread(ptr: rawptr, size: uint, nitems: uint, stream: &mut FILE) -> uint; - public func fputc(c: int32, stream: &mut FILE) -> int32; - public func fputs(s: [&]uint8, stream: &mut FILE) -> int32; - public func fprintf(stream: &mut FILE, fmt: [&]uint8, ...) -> int32; - public func fwrite(ptr: rawptr, size: uint, nobj: uint, stream: &mut FILE) -> uint; - public func fflush(stream: &mut FILE) -> int32; - public func fgets(s: [&]mut uint8, n: uint, stream: &mut FILE) -> int32; - public func fclose(stream: &mut FILE) -> int32; - public func fileno(stream: &FILE) -> int32; - public func rewind(stream: &mut FILE); - - public func printf(fmt: [&]uint8, ...) -> int32; - public func asprintf(strp: &?[&]uint8, fmt: [&]uint8, ...) -> int32; - public func putchar(s: int32) -> int32; - - public func popen(cmd: [&]uint8, modes: [&]uint8) -> ?&mut FILE; - public func pclose(stream: &mut FILE) -> int32; - - public func getline(lineptr: &?[&]uint8, n: &uint, stream: &mut FILE) -> int; + pub func fopen(path: [&]uint8, mode: [&]uint8) -> ?&mut FILE; + pub func feof(stream: &FILE) -> int32; + pub func ferror(stream: &FILE) -> int32; + pub func fseek(stream: &mut FILE, offset: uint64, whence: int32) -> int32; + pub func ftell(stream: &mut FILE) -> int64; + pub func fread(ptr: rawptr, size: uint, nitems: uint, stream: &mut FILE) -> uint; + pub func fputc(c: int32, stream: &mut FILE) -> int32; + pub func fputs(s: [&]uint8, stream: &mut FILE) -> int32; + pub func fprintf(stream: &mut FILE, fmt: [&]uint8, ...) -> int32; + pub func fwrite(ptr: rawptr, size: uint, nobj: uint, stream: &mut FILE) -> uint; + pub func fflush(stream: &mut FILE) -> int32; + pub func fgets(s: [&]mut uint8, n: uint, stream: &mut FILE) -> int32; + pub func fclose(stream: &mut FILE) -> int32; + pub func fileno(stream: &FILE) -> int32; + pub func rewind(stream: &mut FILE); + + pub func printf(fmt: [&]uint8, ...) -> int32; + pub func asprintf(strp: &?[&]uint8, fmt: [&]uint8, ...) -> int32; + pub func putchar(s: int32) -> int32; + + pub func popen(cmd: [&]uint8, modes: [&]uint8) -> ?&mut FILE; + pub func pclose(stream: &mut FILE) -> int32; + + pub func getline(lineptr: &?[&]uint8, n: &uint, stream: &mut FILE) -> int; } diff --git a/lib/c/src/libc/stdlib.ri b/lib/c/src/libc/stdlib.ri index 8411abb4e..e872e4510 100644 --- a/lib/c/src/libc/stdlib.ri +++ b/lib/c/src/libc/stdlib.ri @@ -3,38 +3,38 @@ // be found in the LICENSE file. #if _LINUX_ - public const RAND_MAX := 0x7fffffff; + pub const RAND_MAX := 0x7fffffff; #else_if _WINDOWS_ - public const RAND_MAX := 0x7fff; + pub const RAND_MAX := 0x7fff; #else #error cannot define RAND_MAX in this operating system, please report the issue #endif extern (C) { - public func rand() -> int32; - public func srand(seed: uint32); + pub func rand() -> int32; + pub func srand(seed: uint32); - public func atof(nptr: ?[&]uint8) -> float64; - public func atoi(nptr: ?[&]uint8) -> int32; - public func atol(nptr: ?[&]uint8) -> int64; - public func atoll(nptr: ?[&]uint8) -> int64; + pub func atof(nptr: ?[&]uint8) -> float64; + pub func atoi(nptr: ?[&]uint8) -> int32; + pub func atol(nptr: ?[&]uint8) -> int64; + pub func atoll(nptr: ?[&]uint8) -> int64; - public func strtod(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> float64; - public func strtof(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> float32; - public func strtol(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> int64; - public func strtoll(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> int64; - public func strtoul(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> uint64; - public func strtoull(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> uint64; + pub func strtod(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> float64; + pub func strtof(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> float32; + pub func strtol(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> int64; + pub func strtoll(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> int64; + pub func strtoul(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> uint64; + pub func strtoull(nptr: [&]uint8, endptr: ?[&]uint8, base: int32) -> uint64; - public func malloc(size: uint) -> ?rawptr; - public func calloc(nobj: uint, size: uint) -> ?rawptr; - public func realloc(p: ?rawptr, size: uint) -> ?rawptr; - public func free(p: rawptr); + pub func malloc(size: uint) -> ?rawptr; + pub func calloc(nobj: uint, size: uint) -> ?rawptr; + pub func realloc(p: ?rawptr, size: uint) -> ?rawptr; + pub func free(p: rawptr); - public func getenv(name: [&]uint8) -> ?[&]mut uint8; - public func setenv(name: [&]uint8, value: [&]uint8, replace: bool) -> int32; - public func unsetenv(name: [&]uint8) -> int32; + pub func getenv(name: [&]uint8) -> ?[&]mut uint8; + pub func setenv(name: [&]uint8, value: [&]uint8, replace: bool) -> int32; + pub func unsetenv(name: [&]uint8) -> int32; - public func exit(status: int32) -> never; - public func abort() -> never; + pub func exit(status: int32) -> never; + pub func abort() -> never; } diff --git a/lib/c/src/libc/string.ri b/lib/c/src/libc/string.ri index 75e7ec340..501870a96 100644 --- a/lib/c/src/libc/string.ri +++ b/lib/c/src/libc/string.ri @@ -3,13 +3,13 @@ // be found in the LICENSE file. extern (C) { - public func memchr(cx: rawptr, c: int32, n: uint) -> ?rawptr; - public func memcmp(cx: rawptr, ct: rawptr, n: uint) -> int32; - public func memcpy(dest: rawptr, src: rawptr, n: uint) -> ?rawptr; - public func memmove(dest: rawptr, src: rawptr, n: uint) -> ?rawptr; - public func memset(dest: rawptr, c: int32, n: uint) -> ?rawptr; + pub func memchr(cx: rawptr, c: int32, n: uint) -> ?rawptr; + pub func memcmp(cx: rawptr, ct: rawptr, n: uint) -> int32; + pub func memcpy(dest: rawptr, src: rawptr, n: uint) -> ?rawptr; + pub func memmove(dest: rawptr, src: rawptr, n: uint) -> ?rawptr; + pub func memset(dest: rawptr, c: int32, n: uint) -> ?rawptr; - public func strerror(code: int32) -> ?[&]mut uint8; - public func strlen(cs: ?[&]uint8) -> uint; - public func strstr(needle: ?[&]uint8, haystack: ?[&]uint8) -> ?[&]uint8; + pub func strerror(code: int32) -> ?[&]mut uint8; + pub func strlen(cs: ?[&]uint8) -> uint; + pub func strstr(needle: ?[&]uint8, haystack: ?[&]uint8) -> ?[&]uint8; } diff --git a/lib/c/src/libc/time.ri b/lib/c/src/libc/time.ri index 1dace1cdd..585665ffb 100644 --- a/lib/c/src/libc/time.ri +++ b/lib/c/src/libc/time.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public struct timespec { +pub struct timespec { tv_sec: int; tv_nsec: int; } diff --git a/lib/c/src/libc/unistd.ri b/lib/c/src/libc/unistd.ri index 939a904bf..075f5b798 100644 --- a/lib/c/src/libc/unistd.ri +++ b/lib/c/src/libc/unistd.ri @@ -3,25 +3,25 @@ // be found in the LICENSE file. extern (C) { - public func access(a: [&]uint8, o: int32) -> int32; + pub func access(a: [&]uint8, o: int32) -> int32; - public func sysconf(name: int32) -> int64; + pub func sysconf(name: int32) -> int64; - public func getpid() -> uint32; - public func getppid() -> uint32; + pub func getpid() -> uint32; + pub func getppid() -> uint32; - public func isatty(fd: int32) -> int32; + pub func isatty(fd: int32) -> int32; - public func write(fd: int32, buf: rawptr, count: uint) -> int; - public func read(fildes: int32, buf: rawptr, nbyte: uint) -> int; + pub func write(fd: int32, buf: rawptr, count: uint) -> int; + pub func read(fildes: int32, buf: rawptr, nbyte: uint) -> int; - public func rmdir(path: [&]uint8) -> int32; - public func chdir(path: [&]uint8) -> int32; - public func getcwd(buf: [&]uint8, size: uint) -> ?[&]uint8; + pub func rmdir(path: [&]uint8) -> int32; + pub func chdir(path: [&]uint8) -> int32; + pub func getcwd(buf: [&]uint8, size: uint) -> ?[&]uint8; - public func readlink(path: [&]uint8, buf: [&]uint8, size: uint) -> int; + pub func readlink(path: [&]uint8, buf: [&]uint8, size: uint) -> int; #if _LINUX_ - public func get_nprocs() -> int32; + pub func get_nprocs() -> int32; #endif } diff --git a/lib/c/src/wyhash.ri b/lib/c/src/wyhash.ri index 918510cb8..903ab6363 100644 --- a/lib/c/src/wyhash.ri +++ b/lib/c/src/wyhash.ri @@ -6,7 +6,7 @@ extern (C) { // the default secret parameters - public var _wyp: [4]uint64; + pub var _wyp: [4]uint64; func _wyrot(x: uint64) -> uint64; func _wymum(a: &uint64, b: &uint64); @@ -14,8 +14,8 @@ extern (C) { func _wyr8(p: &uint8) -> uint64; func _wyr4(p: &uint8) -> uint64; func _wyr3(p: &uint8, k: uint) -> uint64; - public func wyhash(key: rawptr, len: uint, seed: uint64, secret: &uint64) -> uint64; - public func wyhash64(a: uint64, b: uint64) -> uint64; + pub func wyhash(key: rawptr, len: uint, seed: uint64, secret: &uint64) -> uint64; + pub func wyhash64(a: uint64, b: uint64) -> uint64; func wyrand(seed: &uint64) -> uint64; func wy2u01(r: uint64) -> float64; func wy2gau(r: uint64) -> float64; diff --git a/lib/core/src/StaticBuffer.c.ri b/lib/core/src/StaticBuffer.c.ri index e28027b03..98bd43e48 100644 --- a/lib/core/src/StaticBuffer.c.ri +++ b/lib/core/src/StaticBuffer.c.ri @@ -8,7 +8,7 @@ struct StaticBuffer { buf: [25]mut uint8; mut len: uint; - public func push(mut self, byte: uint8) { + pub func push(mut self, byte: uint8) { if self.len > self.buf.len { process_panic("StaticBuffer.push: cannot push byte (len: {})", self.len); } @@ -16,23 +16,23 @@ struct StaticBuffer { self.len += 1; } - public func as_uint64(&self) -> uint64 { + pub func as_uint64(&self) -> uint64 { self.buf[self.len] = 0; return unsafe { libc.strtoul(&self.buf[0], none, 10) }; } - public func as_int(&self) -> int { + pub func as_int(&self) -> int { self.buf[self.len] = 0; return unsafe { @as(int, libc.strtol(&self.buf[0], none, 10))}; } - public func as_string(&self) -> string { + pub func as_string(&self) -> string { self.buf[self.len] = 0; return unsafe { string.from_raw_with_len(&self.buf[0], self.len).clone() }; } #[inline] - public func clear(mut self) { + pub func clear(mut self) { self.len = 0; } } diff --git a/lib/core/src/StringBuilder.c.ri b/lib/core/src/StringBuilder.c.ri index 9d5bb9651..549cbb402 100644 --- a/lib/core/src/StringBuilder.c.ri +++ b/lib/core/src/StringBuilder.c.ri @@ -5,17 +5,17 @@ import c/libc; #[boxed] -public struct StringBuilder < Stringable { +pub struct StringBuilder < Stringable { mut inner: Vector; /// Returns a string builder with capacity `cap`. #[inline] - public func new(cap: uint := 0) -> Self { + pub func new(cap: uint := 0) -> Self { return Self(unsafe { Vector.new(@size_of(uint8), cap) }); } #[inline] - public func from_string(s: string) -> Self { + pub func from_string(s: string) -> Self { return if s.len == 0 { Self.new() } else { @@ -28,19 +28,19 @@ public struct StringBuilder < Stringable { } #[inline] - public func write_byte(mut self, val: uint8) { + pub func write_byte(mut self, val: uint8) { self.inner.push(&val); } #[unsafe; inline] - public func write_raw(mut self, s: [&]uint8) { + pub func write_raw(mut self, s: [&]uint8) { unsafe { self.write_raw_with_len(s, libc.strlen(s)); } } #[unsafe] - public func write_raw_with_len(mut self, s: [&]uint8, len: uint) { + pub func write_raw_with_len(mut self, s: [&]uint8, len: uint) { self.inner.reserve(self.inner.len + len); mem_copy( unsafe { @ptr_add(self.inner.ptr, self.inner.elem_size * self.inner.len) }, @@ -50,13 +50,13 @@ public struct StringBuilder < Stringable { } #[inline] - public func write_string(mut self, s: string) { + pub func write_string(mut self, s: string) { unsafe { self.write_raw_with_len(s.ptr, s.len); } } - public func writeln(mut self, s: string := "") { + pub func writeln(mut self, s: string := "") { if s.len > 0 { unsafe { self.write_raw_with_len(s.ptr, s.len); @@ -65,7 +65,7 @@ public struct StringBuilder < Stringable { self.write_byte(b'\n'); } - public func write_join(mut self, ss: []string, sep: string := "") { + pub func write_join(mut self, ss: []string, sep: string := "") { if ss.len == 1 { self.write_string(ss[0]); } else { @@ -79,43 +79,43 @@ public struct StringBuilder < Stringable { } #[inline] - public func write_fmt(mut self, s: string, args: ...Stringable) { + pub func write_fmt(mut self, s: string, args: ...Stringable) { self.write_string(s.fmt(args)); } - public func writeln_fmt(mut self, s: string, args: ...Stringable) { + pub func writeln_fmt(mut self, s: string, args: ...Stringable) { self.write_string(s.fmt(args)); self.write_byte(b'\n'); } /// Returns the number of runes contained in `self`. #[inline] - public func runes_count(self) -> uint { + pub func runes_count(self) -> uint { return cstr_runes_count(unsafe { @as([&]uint8, self.inner.ptr) }, self.inner.len); } #[inline] - public func clear(mut self) { + pub func clear(mut self) { self.inner.clear(); } #[inline] - public func len(self) -> uint { + pub func len(self) -> uint { return self.inner.len; } #[inline] - public func cap(self) -> uint { + pub func cap(self) -> uint { return self.inner.cap; } #[inline] - public func is_empty(self) -> bool { + pub func is_empty(self) -> bool { return self.inner.is_empty(); } #[inline] - public func to_string(mut self) -> string { + pub func to_string(mut self) -> string { self.write_byte(0); return string(unsafe { @as([&]uint8, self.inner.ptr) }, self.inner.len - 1); } diff --git a/lib/core/src/StringFormatter.ri b/lib/core/src/StringFormatter.ri index 67c8c69bf..1425cfd0f 100644 --- a/lib/core/src/StringFormatter.ri +++ b/lib/core/src/StringFormatter.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public struct StringFormatter { +pub struct StringFormatter { buf: string; mut i: uint; mut res: StringBuilder; diff --git a/lib/core/src/TokenIterator.ri b/lib/core/src/TokenIterator.ri index 5d2f99a12..b5fcf8cb9 100644 --- a/lib/core/src/TokenIterator.ri +++ b/lib/core/src/TokenIterator.ri @@ -2,14 +2,14 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public struct TokenIterator { +pub struct TokenIterator { buffer: string; delimiter_bytes: []uint8; mut index: uint; /// Returns a slice of the current token, or none if tokenization is /// complete, and advances to the next token. - public func next(mut self) -> ?string { + pub func next(mut self) -> ?string { result := self.peek() ?? return none; self.index += result.len; return result; @@ -17,7 +17,7 @@ public struct TokenIterator { /// Returns a slice of the current token, or none if tokenization is /// complete. Does not advance to the next token. - public func peek(mut self) -> ?string { + pub func peek(mut self) -> ?string { // move to beginning of token while self.index < self.buffer.len and self.is_split_byte(self.buffer[self.index]) : self.index += 1 {} @@ -33,7 +33,7 @@ public struct TokenIterator { } /// Returns a slice of the remaining bytes. Does not affect iterator state. - public func rest(&self) -> string { + pub func rest(&self) -> string { // move to beginning of token mut index := self.index; while index < self.buffer.len and self.is_split_byte(self.buffer[index]) @@ -42,7 +42,7 @@ public struct TokenIterator { } /// Resets the iterator to the initial token. - public func reset(mut self) { + pub func reset(mut self) { self.index = 0; } diff --git a/lib/core/src/Vector.c.ri b/lib/core/src/Vector.c.ri index dfbb97d8b..b72312eac 100644 --- a/lib/core/src/Vector.c.ri +++ b/lib/core/src/Vector.c.ri @@ -81,7 +81,7 @@ struct Vector { /// NOTE: This function does NOT operate in-place. Internally, it creates a copy /// of the vector, skipping over `size` elements starting at `i`, and then points /// the original variable to the new memory location. - public func delete(mut self, i: uint, size: uint := 1, no_slices: bool := false) { + pub func delete(mut self, i: uint, size: uint := 1, no_slices: bool := false) { if i + size > self.len { end_idx := if size == 1 { "..{}".fmt(i + size) } else { "" }; process_panic( @@ -112,13 +112,13 @@ struct Vector { /// Trims the array length to `index` without modifying the allocated data. /// If `index` is greater than `len` nothing will be changed. - public func trim(mut self, index: uint) { + pub func trim(mut self, index: uint) { if index < self.len { self.len = index; } } - public func clear(mut self) { + pub func clear(mut self) { self.len = 0; } @@ -176,7 +176,7 @@ struct Vector { } /// Returns an independent copy of `self`. - public func clone(self) -> Self { + pub func clone(self) -> Self { mut size := self.cap * self.elem_size; if size == 0 { size = 1; diff --git a/lib/core/src/backtrace.c.ri b/lib/core/src/backtrace.c.ri index 4903999fd..3eb58b877 100644 --- a/lib/core/src/backtrace.c.ri +++ b/lib/core/src/backtrace.c.ri @@ -78,7 +78,7 @@ func bt_error_handler(data: rawptr, msg_ptr: ?[&]mut uint8, errnum: int32) { } #endif -public func bt_print(frames_to_skip: int32 := 0) { +pub func bt_print(frames_to_skip: int32 := 0) { #if _RELEASE_ _ = frames_to_skip; #else diff --git a/lib/core/src/bool.ri b/lib/core/src/bool.ri index 888cd3c19..0ea68af09 100644 --- a/lib/core/src/bool.ri +++ b/lib/core/src/bool.ri @@ -4,7 +4,7 @@ extend bool < Stringable { #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return if self.* { "true" } else { "false" }; } } diff --git a/lib/core/src/console.c.ri b/lib/core/src/console.c.ri index b9998dc2f..1745de068 100644 --- a/lib/core/src/console.c.ri +++ b/lib/core/src/console.c.ri @@ -6,7 +6,7 @@ import c/libc; /// Writes a message to stdout. Unlike `println` stdout is not automatically /// flushed. -public func console_write(s: string, args: ...Stringable) { +pub func console_write(s: string, args: ...Stringable) { sx := s.fmt(args); unsafe { write_buf_to_fd(1, sx.ptr, sx.len); @@ -15,14 +15,14 @@ public func console_write(s: string, args: ...Stringable) { /// Writes a message with a line end to stdout. stdout is flushed. #[inline] -public func console_writeln(s: string := "", args: ...Stringable) { +pub func console_writeln(s: string := "", args: ...Stringable) { unsafe { writeln_to_fd(1, s.fmt(args)); } } /// Writes a message to stderr. Both stderr and stdout are flushed. -public func console_ewrite(s: string, args: ...Stringable) { +pub func console_ewrite(s: string, args: ...Stringable) { sx := s.fmt(args); unsafe { _ = libc.fflush(libc.stdout); @@ -34,7 +34,7 @@ public func console_ewrite(s: string, args: ...Stringable) { /// Writes a message with a line end to stderr. Both stderr and stdout are /// flushed. -public func console_ewriteln(s: string := "", args: ...Stringable) { +pub func console_ewriteln(s: string := "", args: ...Stringable) { unsafe { _ = libc.fflush(libc.stdout); _ = libc.fflush(libc.stderr); @@ -46,7 +46,7 @@ public func console_ewriteln(s: string := "", args: ...Stringable) { /// Returns `true` if the `fd` file descriptor is open and refers to a /// terminal. #[inline] -public func console_is_atty(fd: int32) -> bool { +pub func console_is_atty(fd: int32) -> bool { return unsafe { libc.isatty(fd) == 1 }; } diff --git a/lib/core/src/entry_point.ri b/lib/core/src/entry_point.ri index c6bc8a379..242b647ad 100644 --- a/lib/core/src/entry_point.ri +++ b/lib/core/src/entry_point.ri @@ -3,7 +3,7 @@ // be found in the LICENSE file. extern (Rivet) { - public var mut ARGS: []string; + pub var mut ARGS: []string; func init_string_lits(); func init_globals(); diff --git a/lib/core/src/errors.c.ri b/lib/core/src/errors.c.ri index 339c7351b..0e1c77fcc 100644 --- a/lib/core/src/errors.c.ri +++ b/lib/core/src/errors.c.ri @@ -4,9 +4,9 @@ import c; -public alias ErrnoError := c.ErrnoError; +pub alias ErrnoError := c.ErrnoError; -// FIXME: public alias last_errno_error := c.last_errno_error; -public func last_errno_error() -> c.ErrnoError { +// FIXME: pub alias last_errno_error := c.last_errno_error; +pub func last_errno_error() -> c.ErrnoError { return c.last_errno_error(); } diff --git a/lib/core/src/errors.ri b/lib/core/src/errors.ri index d99d8294b..4f50a544f 100644 --- a/lib/core/src/errors.ri +++ b/lib/core/src/errors.ri @@ -5,7 +5,7 @@ var returnTrace := ReturnTrace(); /// This trait is used for errors throwed with result types (!T). -public trait Throwable < Stringable { } +pub trait Throwable < Stringable { } #[inline] func uncatched_error(err: Throwable) { @@ -53,31 +53,31 @@ struct ReturnTrace { } #[boxed] -public struct InvalidArgumentError < Throwable { +pub struct InvalidArgumentError < Throwable { msg: string; #[inline] - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct OutOfMemoryError < Throwable { +pub struct OutOfMemoryError < Throwable { msg: string; #[inline] - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct ReadFailedError < Throwable { +pub struct ReadFailedError < Throwable { msg: string; #[inline] - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } diff --git a/lib/core/src/float.c.ri b/lib/core/src/float.c.ri index ad28451e9..81cc12b96 100644 --- a/lib/core/src/float.c.ri +++ b/lib/core/src/float.c.ri @@ -8,12 +8,12 @@ extend comptime_float < Stringable { /// Returns the IEEE 754 binary representation of `self`, with the sign bit /// of `self` and the result in the same bit position. #[inline] - public func bits(self) -> uint64 { + pub func bits(self) -> uint64 { return @as(float64, self).bits(); } #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(float64, self.*).to_string(); } } @@ -23,18 +23,18 @@ extend float32 < Stringable { /// representation `b`, with the sign bit of b and the result in the same /// bit position. #[inline] - public func from_bits(b: uint32) -> float32 { + pub func from_bits(b: uint32) -> float32 { return unsafe { @as(&float32, &b).* }; } /// Returns the IEEE 754 binary representation of `self`, with the sign bit /// of `self` and the result in the same bit position. #[inline] - public func bits(&self) -> uint32 { + pub func bits(&self) -> uint32 { return unsafe { @as(&uint32, self).* }; } - public func to_string(&self) -> string { + pub func to_string(&self) -> string { unsafe { cstr: ?[&]uint8 := none; len := libc.asprintf(&cstr, c"%g", self.*); @@ -52,18 +52,18 @@ extend float64 < Stringable { /// representation `b`, with the sign bit of b and the result in the same /// bit position. #[inline] - public func from_bits(b: uint64) -> float64 { + pub func from_bits(b: uint64) -> float64 { return unsafe { @as(&float64, &b).* }; } /// Returns the IEEE 754 binary representation of `self`, with the sign bit /// of `self` and the result in the same bit position. #[inline] - public func bits(&self) -> uint64 { + pub func bits(&self) -> uint64 { return unsafe { @as(&uint64, self).* }; } - public func to_string(&self) -> string { + pub func to_string(&self) -> string { unsafe { cstr: ?[&]uint8 := none; len := libc.asprintf(&cstr, c"%g", self.*); diff --git a/lib/core/src/int.ri b/lib/core/src/int.ri index 9925dc18f..54903e90a 100644 --- a/lib/core/src/int.ri +++ b/lib/core/src/int.ri @@ -9,39 +9,39 @@ var digitPairs := "0010203040506070809001112131415161718191021222324252627" extend comptime_int < Stringable { /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(int64, self.*).to_string(); } } extend int8 < Stringable { - public const MAX: int8 := 127; - public const MIN: int8 := -128; + pub const MAX: int8 := 127; + pub const MIN: int8 := -128; /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(int32, self.*).str_l(5); } } extend int16 < Stringable { - public const MAX: int16 := 32767; - public const MIN: int16 := -32768; + pub const MAX: int16 := 32767; + pub const MIN: int16 := -32768; /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(int32, self.*).str_l(7); } } extend int32 < Stringable { - public const MAX: int32 := 2147483647; - public const MIN: int32 := -2147483648; + pub const MAX: int32 := 2147483647; + pub const MIN: int32 := -2147483648; /// Returns the string representation of `self` with `max` chars. - public func str_l(self, max: int32) -> string { + pub func str_l(self, max: int32) -> string { if self == 0 { return "0"; } @@ -89,17 +89,17 @@ extend int32 < Stringable { /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return self.*.str_l(12); } } extend int64 < Stringable { - public const MAX: int64 := 9223372036854775807; - public const MIN: int64 := -9223372036854775808; + pub const MAX: int64 := 9223372036854775807; + pub const MIN: int64 := -9223372036854775808; /// Returns the value of `self` as a string. - public func to_string(&self) -> string { + pub func to_string(&self) -> string { if self.* == 0 { return "0"; } @@ -149,17 +149,17 @@ extend int64 < Stringable { } extend int < Stringable { - public const MIN := @as(int, #if _x64_ int64.MIN #else int32.MIN #endif); - public const MAX := @as(int, #if _x64_ int64.MAX #else int32.MAX #endif); + pub const MIN := @as(int, #if _x64_ int64.MIN #else int32.MIN #endif); + pub const MAX := @as(int, #if _x64_ int64.MAX #else int32.MAX #endif); #[inline] - public func bits() -> uint32 { + pub func bits() -> uint32 { return #if _x64_ 64 #else 32 #endif; } /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(int64, self.*).to_string(); } } diff --git a/lib/core/src/mem.c.ri b/lib/core/src/mem.c.ri index cd75f8a7f..b3d229115 100644 --- a/lib/core/src/mem.c.ri +++ b/lib/core/src/mem.c.ri @@ -9,7 +9,7 @@ import c/libc; /// /// NOTE: Unlike the `mem.zeroed` function, `mem.alloc` will /// not zero the memory block. -public func mem_alloc(size: uint) -> !rawptr { +pub func mem_alloc(size: uint) -> !rawptr { if new := unsafe { libc.malloc(size) } { return new; } @@ -18,7 +18,7 @@ public func mem_alloc(size: uint) -> !rawptr { /// Allocates dynamically a zeroed `n` bytes block of memory on the heap. /// Returns a pointer to the memory address of the allocated space. -public func mem_zeroed(n: uint) -> !rawptr { +pub func mem_zeroed(n: uint) -> !rawptr { if ptr := unsafe { libc.calloc(1, n) } { return ptr; } @@ -29,7 +29,7 @@ public func mem_zeroed(n: uint) -> !rawptr { /// /// NOTE: The `ptr` must be a pointer to an existing memory block previously /// allocated with `mem.alloc` or `mem.zeroed`. -public func mem_resize(ptr: ?rawptr, sz: uint) -> !rawptr { +pub func mem_resize(ptr: ?rawptr, sz: uint) -> !rawptr { if sz == 0 { if safe_ptr := ptr { unsafe { @@ -47,7 +47,7 @@ public func mem_resize(ptr: ?rawptr, sz: uint) -> !rawptr { /// Fills the first `n` bytes of the memory area pointed to by `s`, with the /// byte `c`. #[inline] -public func mem_set(s: rawptr, c: uint8, n: uint) { +pub func mem_set(s: rawptr, c: uint8, n: uint) { unsafe { _ = libc.memset(s, @as(int32, c), n); } @@ -58,7 +58,7 @@ public func mem_set(s: rawptr, c: uint8, n: uint) { /// NOTE: The memory areas *MUST NOT OVERLAP*. Use `mem.move`, if the memory /// areas do overlap. #[inline] -public func mem_copy(dest: rawptr, src: rawptr, sz: uint) { +pub func mem_copy(dest: rawptr, src: rawptr, sz: uint) { unsafe { _ = libc.memcpy(dest, src, sz); } @@ -71,7 +71,7 @@ public func mem_copy(dest: rawptr, src: rawptr, sz: uint) { /// `src` or `dest`, and the bytes are then copied from the temporary array to /// `dest`. #[inline] -public func mem_move(dest: rawptr, src: rawptr, sz: uint) { +pub func mem_move(dest: rawptr, src: rawptr, sz: uint) { unsafe { _ = libc.memmove(dest, src, sz); } @@ -80,7 +80,7 @@ public func mem_move(dest: rawptr, src: rawptr, sz: uint) { /// Allocates dynamically a `sz` bytes block of memory on the heap, then copies /// the contents of `src` into the allocated space and returns a pointer to /// the newly allocated space. -public func mem_dup(src: rawptr, sz: uint) -> !rawptr { +pub func mem_dup(src: rawptr, sz: uint) -> !rawptr { if sz == 0 { return mem_zeroed(1)!; } @@ -105,13 +105,13 @@ public func mem_dup(src: rawptr, sz: uint) -> !rawptr { /// number of equal bytes. You should use a function that performs comparisons /// in constant time for this. #[inline] -public func mem_cmp(s1: rawptr, s2: rawptr, n: uint) -> int32 { +pub func mem_cmp(s1: rawptr, s2: rawptr, n: uint) -> int32 { return unsafe { libc.memcmp(s1, s2, n) }; } /// Deallocates manually the memory referenced by `ptr`. #[unsafe; inline] -public func mem_dealloc(ptr: rawptr) { +pub func mem_dealloc(ptr: rawptr) { unsafe { libc.free(ptr); } diff --git a/lib/core/src/process.c.ri b/lib/core/src/process.c.ri index 5fb7d4b5b..764d68cb0 100644 --- a/lib/core/src/process.c.ri +++ b/lib/core/src/process.c.ri @@ -5,7 +5,7 @@ import c/libc; /// Returns the path name of the executable that started the current process. -public func process_executable() -> !string { +pub func process_executable() -> !string { res: [libc.MAX_PATH_LEN]uint8 := []!; count := unsafe { libc.readlink(c"/proc/self/exe", &res[0], libc.MAX_PATH_LEN) @@ -19,14 +19,14 @@ public func process_executable() -> !string { } /// Sets the current working directory to the new directory in `path`. -public func process_set_cwd(path: string) -> ! { +pub func process_set_cwd(path: string) -> ! { if unsafe { libc.chdir(path.ptr) == -1 } { throw last_errno_error(); } } /// Returns the absolute path of the current working directory. -public func process_get_cwd() -> !string { +pub func process_get_cwd() -> !string { unsafe { buf: [libc.MAX_PATH_LEN]mut uint8 := []!; if _ := libc.getcwd(&mut buf[0], libc.MAX_PATH_LEN) { @@ -39,13 +39,13 @@ public func process_get_cwd() -> !string { /// Returns the OS-assigned process identifier associated with this /// process. #[inline] -public func process_id() -> uint32 { +pub func process_id() -> uint32 { return unsafe { libc.getpid() }; } /// Terminates current thread execution immediately after displaying a /// message, followed by a backtrace. -public func process_panic(s: string := "", args: ...Stringable) -> never { +pub func process_panic(s: string := "", args: ...Stringable) -> never { console_ewriteln("panic: {}", s.fmt(args)); bt_print(2); process_exit(101); @@ -59,7 +59,7 @@ public func process_panic(s: string := "", args: ...Stringable) -> never { /// The process's termination will be similar to that from the C `abort()` /// function. On Unix, the process will terminate with signal `SIGABRT`, /// which typically means that the shell prints "Aborted". -public func process_abort() -> never { +pub func process_abort() -> never { unsafe { drop_globals(); libc.abort(); @@ -71,7 +71,7 @@ public func process_abort() -> never { /// This function will never return and will immediately terminate the /// current process. The exit code is passed through to the underlying /// OS and will be available for consumption by another process. -public func process_exit(code: int32 := 0) -> never { +pub func process_exit(code: int32 := 0) -> never { unsafe { drop_globals(); libc.exit(code); diff --git a/lib/core/src/rune.c.ri b/lib/core/src/rune.c.ri index fb8585746..14a16fd0e 100644 --- a/lib/core/src/rune.c.ri +++ b/lib/core/src/rune.c.ri @@ -8,18 +8,18 @@ const MAX_THREE_B: uint32 := 0x10000; extend rune < Stringable { /// The highest valid codepoint a `rune` can have. - public const MAX: rune := 0x10FFFF; + pub const MAX: rune := 0x10FFFF; /// `U+FFFD REPLACEMENT CHARACTER` (�) is used in Unicode to represent a /// decoding error. - public const REPLACEMENT_CHARACTER: rune := 0xFFFD; + pub const REPLACEMENT_CHARACTER: rune := 0xFFFD; /// Converts a `uint32` to a `rune`. /// /// Note that all runes are valid uint32s, and can be cast to one. However, the /// reverse is not true: not all valid uint32s are valid runes. `from_uint32()` /// will return `none` if the input is not a valid value for a rune. - public func from_uint32(i: uint32) -> ?rune { + pub func from_uint32(i: uint32) -> ?rune { if i >= 0x110000 or (i >= 0xD800 and i < 0xE000) { return none; } @@ -36,7 +36,7 @@ extend rune < Stringable { /// radix. /// /// Panics if given a radix larger than 36. - public func from_digit(num: uint32, radix: uint32) -> ?rune { + pub func from_digit(num: uint32, radix: uint32) -> ?rune { if radix > 36 { process_panic("rune.from_digit: radix is too high (maximum 36)"); } @@ -48,7 +48,7 @@ extend rune < Stringable { return none; } - public func as_bytes(self) -> []uint8 { + pub func as_bytes(self) -> []uint8 { res := @vec(uint8, 5); res_v := @as(Vector, res); res_v.len = utf32_decode_to_buffer(self, unsafe { @as([&]mut uint8, res_v.ptr) }); @@ -56,11 +56,11 @@ extend rune < Stringable { } #[inline] - public func len_utf8(self) -> uint { + pub func len_utf8(self) -> uint { return len_utf8(@as(uint32, self)); } - public func to_string(&self) -> string { + pub func to_string(&self) -> string { len := self.len_utf8(); res := unsafe { @as([&]mut uint8, internal_alloc(len + 1)) }; unsafe { @@ -115,10 +115,10 @@ func len_utf8(code: uint32) -> uint { } #[boxed] -public struct TooManyBytesError < Throwable { +pub struct TooManyBytesError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } diff --git a/lib/core/src/string.c.ri b/lib/core/src/string.c.ri index 79e1b479d..a80d7b350 100644 --- a/lib/core/src/string.c.ri +++ b/lib/core/src/string.c.ri @@ -7,13 +7,13 @@ import c/libc; var emptyString := string(c"", 0, true); #[boxed] -public struct string < Stringable, Hashable, Throwable { - public ptr: [&]uint8; - public len: uint; +pub struct string < Stringable, Hashable, Throwable { + pub ptr: [&]uint8; + pub len: uint; is_ref: bool; #[unsafe] - public func from_raw(ptr: ?[&]uint8, is_ref: bool := false) -> Self { + pub func from_raw(ptr: ?[&]uint8, is_ref: bool := false) -> Self { if safe_ptr := ptr { return unsafe { Self.from_raw_with_len(safe_ptr, libc.strlen(ptr), is_ref) @@ -23,7 +23,7 @@ public struct string < Stringable, Hashable, Throwable { } #[unsafe] - public func from_raw_with_len(ptr: ?[&]uint8, len: uint, is_ref: bool := false) -> Self { + pub func from_raw_with_len(ptr: ?[&]uint8, len: uint, is_ref: bool := false) -> Self { if len == 0 { return emptyString; } @@ -37,7 +37,7 @@ public struct string < Stringable, Hashable, Throwable { }; } - public func from_byte(byte: uint8) -> Self { + pub func from_byte(byte: uint8) -> Self { res := unsafe { @as([&]mut uint8, internal_alloc(2)) }; unsafe { res[0] = byte; @@ -48,7 +48,7 @@ public struct string < Stringable, Hashable, Throwable { /// Returns a string with the bytes stored in `bytes`. If the length of /// `bytes` is 0, an empty string is returned instead. - public func from_bytes(bytes: []uint8) -> Self { + pub func from_bytes(bytes: []uint8) -> Self { if bytes.len == 0 { return emptyString; } @@ -60,7 +60,7 @@ public struct string < Stringable, Hashable, Throwable { return Self(res, bytes.len); } - public func at(self, idx: uint) -> uint8 { + pub func at(self, idx: uint) -> uint8 { if idx >= self.len { process_panic("string index out of range (index: {}, len: {})", idx, self.len); } @@ -68,7 +68,7 @@ public struct string < Stringable, Hashable, Throwable { } #[inline] - public func repeat(self, count: uint) -> Self { + pub func repeat(self, count: uint) -> Self { return if count == 0 { emptyString } else if count == 1 { @@ -87,7 +87,7 @@ public struct string < Stringable, Hashable, Throwable { }; } - public func concat(self, others: ...Self) -> Self { + pub func concat(self, others: ...Self) -> Self { if others.len == 0 { return self; } @@ -99,7 +99,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns a string array of the string split by '\t' and ' '. - public func fields(self) -> []Self { + pub func fields(self) -> []Self { mut res := @vec(Self); mut word_start: uint := 0; mut word_len: uint := 0; @@ -131,7 +131,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Wraps the given string within `width` in characters. - public func wrap(self, width: uint := 60, end: Self := "\n") -> Self { + pub func wrap(self, width: uint := 60, end: Self := "\n") -> Self { words := self.fields(); if words.len == 0 { return emptyString; @@ -172,7 +172,7 @@ public struct string < Stringable, Hashable, Throwable { /// If the replacement positions exceed the number of passed arguments, a panic /// occurs. #[inline] - public func fmt(self, args: ...Stringable) -> Self { + pub func fmt(self, args: ...Stringable) -> Self { return if args.len == 0 { self } else { @@ -182,7 +182,7 @@ public struct string < Stringable, Hashable, Throwable { /// Returns the number of occurrences of `substr` in the string or 0 if no /// `substr` could be found. - public func count(self, substr: Self) -> uint { + pub func count(self, substr: Self) -> uint { if self.len == 0 or substr.len == 0 { return 0; } @@ -209,7 +209,7 @@ public struct string < Stringable, Hashable, Throwable { /// Returns the contents before `sub` in the string. /// If the substring is not found, it returns the full input string. - public func all_before_of(self, sub: Self) -> Self { + pub func all_before_of(self, sub: Self) -> Self { return if pos := self.index_of(sub) { self[..pos] } else { @@ -218,7 +218,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns the contents before the last occurrence of `sub` in the string. - public func all_before_of_last(self, sub: Self) -> Self { + pub func all_before_of_last(self, sub: Self) -> Self { return if pos := self.last_index_of(sub) { self[..pos] } else { @@ -228,7 +228,7 @@ public struct string < Stringable, Hashable, Throwable { /// Returns the contents after `sub` in the string. If the substring is /// not found, it returns the full input string. - public func all_after_of(self, sub: Self) -> Self { + pub func all_after_of(self, sub: Self) -> Self { return if pos := self.index_of(sub) { self[pos + sub.len..] } else { @@ -238,7 +238,7 @@ public struct string < Stringable, Hashable, Throwable { /// Returns the contents after the last occurrence of `sub` in the string. /// If the substring is not found, it returns the full input string. - public func all_after_of_last(self, sub: Self) -> Self { + pub func all_after_of_last(self, sub: Self) -> Self { return if pos := self.last_index_of(sub) { self[pos + sub.len..] } else { @@ -247,7 +247,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns the index of byte `b` if found in the string. - public func index_of_byte(self, b: uint8) -> ?uint { + pub func index_of_byte(self, b: uint8) -> ?uint { mut i: uint := 0; while i < self.len : i += 1 { if unsafe { self.ptr[i] == b } { @@ -259,7 +259,7 @@ public struct string < Stringable, Hashable, Throwable { /// Returns the position of the first character of the input string. /// It will return `none` if the input string can't be found. - public func index_of(self, p: Self) -> ?uint { + pub func index_of(self, p: Self) -> ?uint { if p.len > self.len or p.len == 0 { return none; } @@ -275,7 +275,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns the position of the input string, starting search from `start` position. - public func index_after_of(self, p: Self, start: uint) -> ?uint { + pub func index_after_of(self, p: Self, start: uint) -> ?uint { if p.len > self.len { return none; } @@ -298,7 +298,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns the position of any of the characters in the input string if found. - public func index_of_any(self, chars: Self) -> ?uint { + pub func index_of_any(self, chars: Self) -> ?uint { for i, b in self.as_bytes() { for c in chars.as_bytes() { if b == c { @@ -310,7 +310,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Linear search for the last index of `byte` inside a string. - public func last_index_of_byte(self, byte: uint8) -> ?uint { + pub func last_index_of_byte(self, byte: uint8) -> ?uint { mut i: uint := self.len - 1; while i >= 0 : i -= 1 { if unsafe { self.ptr[i] == byte } { @@ -327,7 +327,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns the position of the last occurence of the input string. - public func last_index_of(self, p: Self) -> ?uint { + pub func last_index_of(self, p: Self) -> ?uint { if p.len > self.len or p.len == 0 { return none; } @@ -346,7 +346,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns the string found between `start` string and `end` string. - public func find_between(self, start: Self, end: Self) -> Self { + pub func find_between(self, start: Self, end: Self) -> Self { start_pos := self.index_of(start) ?? return emptyString; val := self.slice(start_pos + start.len, self.len); end_pos := val.index_of(end) ?? return val; @@ -355,7 +355,7 @@ public struct string < Stringable, Hashable, Throwable { /// Strips any of the characters given in `cutset` from the start and end of /// the string. - public func trim(self, cutset: Self) -> Self { + pub func trim(self, cutset: Self) -> Self { if self.len < 1 or cutset.len < 1 { return self; } @@ -367,7 +367,7 @@ public struct string < Stringable, Hashable, Throwable { /// given in `cutset` were stripped from the start and end of the string. Should /// be used as an input to `substr()`. If the string contains only the characters /// in `cutset`, both values returned are zero. - public func trim_indexes(self, cutset: Self) -> (uint, uint) { + pub func trim_indexes(self, cutset: Self) -> (uint, uint) { mut pos_left: uint := 0; mut pos_right: uint := if self.len == 0 { 0 } else { self.len - 1 }; mut cs_match := true; @@ -397,7 +397,7 @@ public struct string < Stringable, Hashable, Throwable { /// Strips any of the characters given in `cutset` from the left of the /// string. - public func trim_left(self, cutset: Self) -> Self { + pub func trim_left(self, cutset: Self) -> Self { if self.len < 1 or cutset.len < 1 { return self; } @@ -420,7 +420,7 @@ public struct string < Stringable, Hashable, Throwable { /// Strips any of the characters given in `cutset` from the right of the /// string. - public func trim_right(self, cutset: Self) -> Self { + pub func trim_right(self, cutset: Self) -> Self { if self.len < 1 or cutset.len < 1 { return self; } @@ -446,12 +446,12 @@ public struct string < Stringable, Hashable, Throwable { /// Strips any of ` `, `\n`, `\t`, `\v`, `\f`, `\r` from the start and end of /// the string. #[inline] - public func trim_space(self) -> Self { + pub func trim_space(self) -> Self { return self.trim(" \n\t\v\f\r"); } /// Replaces all occurences of `rep` with the string passed in `with_`. - public func replace(self, rep: Self, with: Self) -> Self { + pub func replace(self, rep: Self, with: Self) -> Self { if self.len == 0 or rep.len == 0 or rep.len > self.len { return self; } else if !self.contains(rep) { @@ -497,7 +497,7 @@ public struct string < Stringable, Hashable, Throwable { } #[inline] - public func as_bytes(self) -> []uint8 { + pub func as_bytes(self) -> []uint8 { return unsafe { Vector.from_array_no_alloc( @as(&mut uint8, self.ptr), @size_of(uint8), self.len @@ -507,7 +507,7 @@ public struct string < Stringable, Hashable, Throwable { /// Returns an array of all the UTF8 runes in the string `self` which is useful /// if you want random access to them. - public func as_runes(self) -> []rune { + pub func as_runes(self) -> []rune { mut runes := @vec(rune, self.runes_count()); mut i: uint := 0; while i < self.len : i += 1 { @@ -531,7 +531,7 @@ public struct string < Stringable, Hashable, Throwable { } #[inline] - public func utf32_code(self) -> rune { + pub func utf32_code(self) -> rune { return utf8_to_utf32(self.as_bytes()) catch 0; } @@ -539,7 +539,7 @@ public struct string < Stringable, Hashable, Throwable { /// first `nth` parts. When `nth` == 0, return all the splits. /// The last returned element has the remainder of the string, even if the /// remainder contains more `delim` substrings. - public func split(self, delim: Self, nth: uint := 0) -> []Self { + pub func split(self, delim: Self, nth: uint := 0) -> []Self { mut i: uint := 0; mut res := @vec(Self); match delim.len { @@ -600,7 +600,7 @@ public struct string < Stringable, Hashable, Throwable { /// Splits a string using the chars in the delimiter string as delimiters chars. /// If the delimiter string is empty then `.split()` is used. - public func split_any(self, delim: Self) -> []Self { + pub func split_any(self, delim: Self) -> []Self { mut i: uint := 0; mut res := @vec(Self); // check empty source string @@ -629,7 +629,7 @@ public struct string < Stringable, Hashable, Throwable { /// and `\r\n` (Windows) line endings are all supported (including mixed line endings). /// NOTE: algorithm is "greedy", consuming '\r\n' as a single line ending with higher /// priority than '\r' and '\n' as multiple endings - public func split_into_lines(self) -> []Self { + pub func split_into_lines(self) -> []Self { mut res := @vec(Self); if self.len == 0 { return res; @@ -677,11 +677,11 @@ public struct string < Stringable, Hashable, Throwable { /// If `delimiter_bytes` does not exist in self, the iterator will return `self`, /// none, in that order. #[inline] - public func tokenize(self, delimiter_bytes: ...uint8) -> TokenIterator { + pub func tokenize(self, delimiter_bytes: ...uint8) -> TokenIterator { return TokenIterator(self, delimiter_bytes); } - public func ==(self, rhs: Self) -> bool { + pub func ==(self, rhs: Self) -> bool { if self.len != rhs.len { return false; } @@ -695,11 +695,11 @@ public struct string < Stringable, Hashable, Throwable { } #[inline] - public func !=(self, rhs: Self) -> bool { + pub func !=(self, rhs: Self) -> bool { return !(self == rhs); } - public func <(self, rhs: Self) -> bool { + pub func <(self, rhs: Self) -> bool { mut i: uint := 0; while i < self.len : i += 1 { unsafe { @@ -717,28 +717,28 @@ public struct string < Stringable, Hashable, Throwable { } #[inline] - public func >(self, rhs: Self) -> bool { + pub func >(self, rhs: Self) -> bool { return !(self < rhs); } #[inline] - public func <=(self, rhs: Self) -> bool { + pub func <=(self, rhs: Self) -> bool { return self < rhs or self == rhs; } #[inline] - public func >=(self, rhs: Self) -> bool { + pub func >=(self, rhs: Self) -> bool { return self > rhs or self == rhs; } /// Returns `true` if the string contains `substr`. #[inline] - public func contains(self, substr: Self) -> bool { + pub func contains(self, substr: Self) -> bool { return substr.len == 0 or self.index_of(substr) !is none; } /// Returns `true` if the string starts with `p`. - public func starts_with(self, p: Self) -> bool { + pub func starts_with(self, p: Self) -> bool { if p.len > self.len { return false; } @@ -752,7 +752,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Returns `true` if the string ends with `p`. - public func ends_with(self, p: Self) -> bool { + pub func ends_with(self, p: Self) -> bool { if p.len > self.len { return false; } @@ -767,16 +767,16 @@ public struct string < Stringable, Hashable, Throwable { /// Returns the number of runes contained in `self`. #[inline] - public func runes_count(self) -> uint { + pub func runes_count(self) -> uint { return cstr_runes_count(self.ptr, self.len); } #[inline] - public func is_empty(self) -> bool { + pub func is_empty(self) -> bool { return self.len == 0; } - public func is_digit(self) -> bool { + pub func is_digit(self) -> bool { for ch in self.as_bytes() { if !ch.is_digit() { return false; @@ -806,7 +806,7 @@ public struct string < Stringable, Hashable, Throwable { return self.slice(start, self.len); } - public func clone(self) -> Self { + pub func clone(self) -> Self { if self.len == 0 { return emptyString; } @@ -819,12 +819,12 @@ public struct string < Stringable, Hashable, Throwable { } #[inline] - public func hash(self) -> uint { + pub func hash(self) -> uint { return sum64_string(self); } #[inline] - public func to_string(self) -> Self { + pub func to_string(self) -> Self { return self; } diff --git a/lib/core/src/traits.ri b/lib/core/src/traits.ri index e796a2abb..b25235874 100644 --- a/lib/core/src/traits.ri +++ b/lib/core/src/traits.ri @@ -2,10 +2,10 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public trait Stringable { +pub trait Stringable { func to_string(self) -> string; } -public trait Hashable { +pub trait Hashable { func hash(self) -> uint; } diff --git a/lib/core/src/uint.ri b/lib/core/src/uint.ri index 15b747e3d..658860473 100644 --- a/lib/core/src/uint.ri +++ b/lib/core/src/uint.ri @@ -3,11 +3,11 @@ // be found in the LICENSE file. extend uint8 < Stringable { - public const MAX: uint8 := 255; + pub const MAX: uint8 := 255; /// Checks if the value is within the ASCII range. #[inline] - public func is_ascii(self) -> bool { + pub func is_ascii(self) -> bool { return self < 0x80; } @@ -15,33 +15,33 @@ extend uint8 < Stringable { /// list is considered white space characters: ' ', '\t', '\n', '\v', '\f', /// '\r', 0x85, 0xA0 #[inline] - public func is_space(self) -> bool { + pub func is_space(self) -> bool { return self == 32 or (self > 8 and self < 14) or (self == 0x85) or (self == 0xA0); } /// Returns `true` if the byte is in range 0-9 and `false` otherwise. #[inline] - public func is_digit(self) -> bool { + pub func is_digit(self) -> bool { return self >= b'0' and self <= b'9'; } /// Returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise. #[inline] - public func is_bin_digit(self) -> bool { + pub func is_bin_digit(self) -> bool { return self == b'0' or self == b'1'; } /// Returns `true` if the byte is in range 0-7 and `false` otherwise. #[inline] - public func is_oct_digit(self) -> bool { + pub func is_oct_digit(self) -> bool { return self >= b'0' and self <= b'7'; } /// Returns `true` if the byte is either in range 0-9, a-f or A-F and `false` /// otherwise. #[inline] - public func is_hex_digit(self) -> bool { + pub func is_hex_digit(self) -> bool { return (self >= b'0' and self <= b'9') or (self >= b'a' and self <= b'f') or (self >= b'A' and self <= b'F'); @@ -49,74 +49,74 @@ extend uint8 < Stringable { /// Returns `true` if the byte is in range a-z or A-Z and `false` otherwise. #[inline] - public func is_letter(self) -> bool { + pub func is_letter(self) -> bool { return (self >= b'a' and self <= b'z') or (self >= b'A' and self <= b'Z'); } /// Returns `true` if the byte is in range a-z or A-Z or 1-9 and `false` otherwise. #[inline] - public func is_alnum(self) -> bool { + pub func is_alnum(self) -> bool { return self.is_letter() or self.is_digit(); } /// Returns `true` if the byte is upper and `false` otherwise. #[inline] - public func is_upper(self) -> bool { + pub func is_upper(self) -> bool { return (self >= b'A' and self <= b'Z'); } /// Returns `true` if the byte is lower and `false` otherwise. #[inline] - public func is_lower(self) -> bool { + pub func is_lower(self) -> bool { return (self >= b'a' and self <= b'z'); } /// Calculates length to read from the first byte. #[inline] - public func len_utf8(self) -> uint { + pub func len_utf8(self) -> uint { return @as(uint, (@as(uint64, 0xE5000000) >> ((self >> 3) & 0x1E) & 3) + 1); } /// Returns the value of `self` as a valid `rune`. #[inline] - public func to_rune(self) -> ?rune { + pub func to_rune(self) -> ?rune { return rune.from_uint32(@as(uint32, self)); } /// Returns the value of `self` as a ASCII `string`. #[inline] - public func to_ascii(self) -> string { + pub func to_ascii(self) -> string { return string.from_byte(self); } /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(int32, self.*).str_l(7); } } extend uint16 < Stringable { - public const MAX: uint16 := 65535; + pub const MAX: uint16 := 65535; /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(int32, self.*).str_l(7); } } extend uint32 < Stringable { - public const MAX: uint32 := 4294967295; + pub const MAX: uint32 := 4294967295; /// Returns the value of `self` as a valid `rune`. #[inline] - public func to_rune(self) -> ?rune { + pub func to_rune(self) -> ?rune { return rune.from_uint32(self); } /// Returns the value of `self` as a string. - public func to_string(&self) -> string { + pub func to_string(&self) -> string { if self.* == 0 { return "0"; } @@ -155,10 +155,10 @@ extend uint32 < Stringable { } extend uint64 < Stringable { - public const MAX: uint64 := 18446744073709551615; + pub const MAX: uint64 := 18446744073709551615; /// Returns the value of `self` as a string. - public func to_string(&self) -> string { + pub func to_string(&self) -> string { if self.* == 0 { return "0"; } @@ -197,16 +197,16 @@ extend uint64 < Stringable { } extend uint < Stringable { - public const MAX := @as(uint, #if _x64_ uint64.MAX #else uint32.MAX #endif); + pub const MAX := @as(uint, #if _x64_ uint64.MAX #else uint32.MAX #endif); #[inline] - public func bits() -> uint32 { + pub func bits() -> uint32 { return #if _x64_ 64 #else 32 #endif; } /// Returns the value of `self` as a string. #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return @as(uint64, self.*).to_string(); } } diff --git a/lib/core/src/wyhash.c.ri b/lib/core/src/wyhash.c.ri index 2e51168de..b03d77955 100644 --- a/lib/core/src/wyhash.c.ri +++ b/lib/core/src/wyhash.c.ri @@ -15,11 +15,11 @@ func wyhash64(a: uint64, b: uint64) -> uint64 { } #[inline] -public func sum64(key: []uint8, seed: uint64 := 0) -> uint64 { +pub func sum64(key: []uint8, seed: uint64 := 0) -> uint64 { return unsafe { wyhash(&key[0], @as(uint64, key.len), seed) }; } #[inline] -public func sum64_string(key: string, seed: uint64 := 0) -> uint64 { +pub func sum64_string(key: string, seed: uint64 := 0) -> uint64 { return unsafe { wyhash(key.ptr, @as(uint64, key.len), seed) }; } diff --git a/lib/rivet/src/ast/Attributes.ri b/lib/rivet/src/ast/Attributes.ri index 7c4403478..3a98dc969 100644 --- a/lib/rivet/src/ast/Attributes.ri +++ b/lib/rivet/src/ast/Attributes.ri @@ -5,28 +5,28 @@ import ../token; #[boxed] -public struct AttributeDuplicatedError < Throwable { +pub struct AttributeDuplicatedError < Throwable { name: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return "duplicated attribute `{}`".fmt(self.name); } } #[boxed] -public struct AttributeArgument { - public name: string; - public expr: Expr; - public is_named: bool; +pub struct AttributeArgument { + pub name: string; + pub expr: Expr; + pub is_named: bool; } #[boxed] -public struct Attribute { - public name: string; - public args: []AttributeArgument; - public pos: token.Pos; +pub struct Attribute { + pub name: string; + pub args: []AttributeArgument; + pub pos: token.Pos; - public func find_argument(self, name: string) -> ?AttributeArgument { + pub func find_argument(self, name: string) -> ?AttributeArgument { for arg in self.args { if arg.name == name { return arg; @@ -37,17 +37,17 @@ public struct Attribute { } #[boxed] -public struct Attributes { - public mut attributes: []Attribute; +pub struct Attributes { + pub mut attributes: []Attribute; - public func add(mut self, attribute: Attribute) -> ! { + pub func add(mut self, attribute: Attribute) -> ! { if self.has(attribute.name) { throw AttributeDuplicatedError(attribute.name); } self.attributes.push(attribute); } - public func find(self, name: string) -> ?Attribute { + pub func find(self, name: string) -> ?Attribute { for attribute in self.attributes { if attribute.name == name { return attribute; @@ -57,12 +57,12 @@ public struct Attributes { } #[inline] - public func has(self, name: string) -> bool { + pub func has(self, name: string) -> bool { return self.find(name) !is none; } #[inline] - public func is_empty(self) -> bool { + pub func is_empty(self) -> bool { return self.attributes.is_empty(); } } diff --git a/lib/rivet/src/ast/CHeader.ri b/lib/rivet/src/ast/CHeader.ri index 12c3b77db..a7355a570 100644 --- a/lib/rivet/src/ast/CHeader.ri +++ b/lib/rivet/src/ast/CHeader.ri @@ -12,7 +12,7 @@ import ../token; // Useful functions to get system `#define`s. // Will soon be used to implement `extern (C) import`. -public enum CImportAction { +pub enum CImportAction { Report { msg: string; is_error: bool; @@ -43,11 +43,11 @@ public enum CImportAction { } } -public struct CImportIfBranch { - public cond: Expr; - public is_else: bool; - public actions: []mut CImportAction; - public pos: token.Pos; +pub struct CImportIfBranch { + pub cond: Expr; + pub is_else: bool; + pub actions: []mut CImportAction; + pub pos: token.Pos; } struct CDefine < traits.Stringable { @@ -60,7 +60,7 @@ struct CDefine < traits.Stringable { mut cvalue: CImportValue := .Invalid(); mut has_cvalue: bool; - public func to_string(&self) -> string { + pub func to_string(&self) -> string { mut sb := strings.Builder.new(); sb.write_string(if self.is_macro { "macro " } else { "const " }); sb.write_string(self.name); @@ -102,7 +102,7 @@ enum CImportValue { Uint: uint; #[inline] - public func to_bool(self) -> bool { + pub func to_bool(self) -> bool { return (self is .Int as int and int == 1) or (self is .Uint as uint and uint == 1); } diff --git a/lib/rivet/src/ast/Decl.ri b/lib/rivet/src/ast/Decl.ri index bd1f5d6c6..90e8c8221 100644 --- a/lib/rivet/src/ast/Decl.ri +++ b/lib/rivet/src/ast/Decl.ri @@ -6,7 +6,7 @@ import std/strings; import ../token; -public enum Decl { +pub enum Decl { Empty: token.Pos, Import { attributes: Attributes; @@ -150,7 +150,7 @@ public enum Decl { mut defer_stmts: []Stmt.Defer; }; - public func decls(self) -> ?[]Self { + pub func decls(self) -> ?[]Self { return match self is { .Extern as extern_decl -> extern_decl.decls, .Trait as trait_decl -> trait_decl.decls, @@ -163,18 +163,18 @@ public enum Decl { } #[boxed] -public struct EnumVariantDecl { - public name: string; - public mut type: Type; - public has_type: bool; - public has_value: bool; - public value: Expr; - public decls: []Decl; - public pos: token.Pos; +pub struct EnumVariantDecl { + pub name: string; + pub mut type: Type; + pub has_type: bool; + pub has_value: bool; + pub value: Expr; + pub decls: []Decl; + pub pos: token.Pos; } #[boxed] -public struct DocComment { +pub struct DocComment { mut lines: []string; pos: token.Pos; @@ -196,23 +196,23 @@ public struct DocComment { } } -public struct ImportListInfo { - public name: string; - public alias_name: string; - public mut has_custom_alias: bool; - public pos: token.Pos; +pub struct ImportListInfo { + pub name: string; + pub alias_name: string; + pub mut has_custom_alias: bool; + pub pos: token.Pos; } -public struct ImportedMod { - public name: string; - public full_name: string; - public alias_name: string; - public found: bool; - public files: []string; - public mut mod: Module; +pub struct ImportedMod { + pub name: string; + pub full_name: string; + pub alias_name: string; + pub found: bool; + pub files: []string; + pub mut mod: Module; } -public func filter_field_decl(decls: []Decl) -> []Decl { +pub func filter_field_decl(decls: []Decl) -> []Decl { mut fields := @vec(Decl); for decl in decls { if decl is .Field { diff --git a/lib/rivet/src/ast/Expr.ri b/lib/rivet/src/ast/Expr.ri index 9f5b43dd8..6db2637ad 100644 --- a/lib/rivet/src/ast/Expr.ri +++ b/lib/rivet/src/ast/Expr.ri @@ -8,7 +8,7 @@ import std/strings; import ../token; #[default_value(.Empty(token.noPos))] -public enum Expr < traits.Stringable { +pub enum Expr < traits.Stringable { Empty: token.Pos, Paren { mut expr: Expr; @@ -276,7 +276,7 @@ public enum Expr < traits.Stringable { pos: token.Pos; }; - public func clean_paren(self) -> Self { + pub func clean_paren(self) -> Self { mut res := self; while res is .Paren as paren { res = paren.expr; @@ -285,7 +285,7 @@ public enum Expr < traits.Stringable { } #[inline] - public func position(self) -> token.Pos { + pub func position(self) -> token.Pos { return match self is { .Empty as empty_pos -> empty_pos, .Paren as paren -> paren.pos, @@ -323,7 +323,7 @@ public enum Expr < traits.Stringable { } #[inline] - public func to_string(self) -> string { + pub func to_string(self) -> string { return match self is { .Empty -> "", .Paren as paren -> "({})".fmt(paren.expr), @@ -547,48 +547,48 @@ public enum Expr < traits.Stringable { } #[boxed] -public struct CallArg { - public name: string; - public mut expr: Expr; - public is_named: bool; - public pos: token.Pos; - public mut type: Type; +pub struct CallArg { + pub name: string; + pub mut expr: Expr; + pub is_named: bool; + pub pos: token.Pos; + pub mut type: Type; } #[boxed] -public struct CallErrorHandler { - public varname: string; - public varname_pos: token.Pos; - public has_varname: bool; - public is_propagate: bool; - public mut expr: Expr; - public has_expr: bool; - public mut scope: Scope; - public pos: token.Pos; +pub struct CallErrorHandler { + pub varname: string; + pub varname_pos: token.Pos; + pub has_varname: bool; + pub is_propagate: bool; + pub mut expr: Expr; + pub has_expr: bool; + pub mut scope: Scope; + pub pos: token.Pos; } #[boxed] -public struct IfBranch { - public mut cond: Expr; - public mut expr: Expr; - public is_else: bool; - public is_else_if: bool; - public pos: token.Pos; - public mut type: Type; +pub struct IfBranch { + pub mut cond: Expr; + pub mut expr: Expr; + pub is_else: bool; + pub is_else_if: bool; + pub pos: token.Pos; + pub mut type: Type; } #[boxed] -public struct MatchBranch { - public cases: []mut Expr; - public has_var: bool; - public var_is_mut: bool; - public var_name: string; - public var_pos: token.Pos; - public has_cond: bool; - public mut var_type: Type; - public mut cond: Expr; - public mut expr: Expr; - public is_else: bool; - public pos: token.Pos; - public mut type: Type; +pub struct MatchBranch { + pub cases: []mut Expr; + pub has_var: bool; + pub var_is_mut: bool; + pub var_name: string; + pub var_pos: token.Pos; + pub has_cond: bool; + pub mut var_type: Type; + pub mut cond: Expr; + pub mut expr: Expr; + pub is_else: bool; + pub pos: token.Pos; + pub mut type: Type; } diff --git a/lib/rivet/src/ast/Scope.ri b/lib/rivet/src/ast/Scope.ri index f2c2ba9c9..e59d14bf0 100644 --- a/lib/rivet/src/ast/Scope.ri +++ b/lib/rivet/src/ast/Scope.ri @@ -5,17 +5,17 @@ import std/process; #[boxed] -public struct Scope { - public start: uint; - public mut end: uint; - public mut owner: ?Sym; - public mut parent: ?Scope; - public mut detached_from_parent: bool; - public mut childrens: []Scope; - public mut syms: []Sym; - public mut is_local: bool; - - public func add(mut self, sym: Sym) -> ! { +pub struct Scope { + pub start: uint; + pub mut end: uint; + pub mut owner: ?Sym; + pub mut parent: ?Scope; + pub mut detached_from_parent: bool; + pub mut childrens: []Scope; + pub mut syms: []Sym; + pub mut is_local: bool; + + pub func add(mut self, sym: Sym) -> ! { if _ := self.find(sym.name) { throw DuplicateSymbolError( "duplicate symbol `{}` in {} `{}`".fmt( @@ -26,7 +26,7 @@ public struct Scope { self.syms.push(sym); } - public func add_or_get(mut self, sym: Sym) -> !Sym { + pub func add_or_get(mut self, sym: Sym) -> !Sym { if old_sym := self.find(sym.name) { if sym is TypeSym as type_sym and old_sym is TypeSym as mut old_type_sym { if old_type_sym.update(type_sym)! { @@ -43,7 +43,7 @@ public struct Scope { return sym; } - public func add_local(mut self, sym: Sym) -> ! { + pub func add_local(mut self, sym: Sym) -> ! { if self.is_local { if sym is Var and sym.name == "_" { return; // ignore blank variable @@ -57,11 +57,11 @@ public struct Scope { } #[inline] - public func exists(self, name: string) -> bool { + pub func exists(self, name: string) -> bool { return self.find(name) !is none; } - public func find(self, name: string) -> ?Sym { + pub func find(self, name: string) -> ?Sym { for sym in self.syms { if sym.name == name { return sym; @@ -70,14 +70,14 @@ public struct Scope { return none; } - public func find_or_panic(self, name: string) -> Sym { + pub func find_or_panic(self, name: string) -> Sym { if x := self.find(name) { return x; } process.panic("cannot found symbol `{}`", name); } - public func find_by_index_or_panic(self, idx: uint) -> Sym { + pub func find_by_index_or_panic(self, idx: uint) -> Sym { if idx >= self.syms.len { process.panic("symbol index out of range `{}`", idx); } @@ -85,16 +85,16 @@ public struct Scope { } #[inline] - public func find_type_symbol_or_panic(self, name: string) -> TypeSym { + pub func find_type_symbol_or_panic(self, name: string) -> TypeSym { return @as(TypeSym, self.find_or_panic(name)); } #[inline] - public func find_type_symbol_by_index_or_panic(self, idx: uint) -> TypeSym { + pub func find_type_symbol_by_index_or_panic(self, idx: uint) -> TypeSym { return @as(TypeSym, self.find_by_index_or_panic(idx)); } - public func lookup(self, name: string) -> ?Sym { + pub func lookup(self, name: string) -> ?Sym { if self.is_local { mut sc_: ?Scope := self; while sc := sc_ { @@ -115,7 +115,7 @@ public struct Scope { return self.parent is none or self.detached_from_parent; } - public func update_type(self, name: string, type: Type) { + pub func update_type(self, name: string, type: Type) { if sym := self.lookup(name) { if sym is Var as var_info { var_info.type = type; @@ -123,7 +123,7 @@ public struct Scope { } } - public func update_is_hidden_ref(self, name: string, is_hidden_ref: bool) { + pub func update_is_hidden_ref(self, name: string, is_hidden_ref: bool) { if sym := self.lookup(name) { if sym is Var as var_info { var_info.is_hidden_ref = is_hidden_ref; @@ -131,7 +131,7 @@ public struct Scope { } } - public func update_is_used(self, name: string, is_used: bool) { + pub func update_is_used(self, name: string, is_used: bool) { if sym := self.lookup(name) { if sym is Var as var_info { var_info.is_used = is_used; diff --git a/lib/rivet/src/ast/Stmt.ri b/lib/rivet/src/ast/Stmt.ri index 14b135595..117f6e80e 100644 --- a/lib/rivet/src/ast/Stmt.ri +++ b/lib/rivet/src/ast/Stmt.ri @@ -4,7 +4,7 @@ import ../token; -public enum Stmt { +pub enum Stmt { Empty: token.Pos, Expr: Expr, VarDecl { @@ -33,7 +33,7 @@ public enum Stmt { pos: token.Pos; }, Defer { - public enum Mode { + pub enum Mode { Normal, Error, Success @@ -43,7 +43,7 @@ public enum Stmt { pos: token.Pos; }; - public func position(self) -> token.Pos { + pub func position(self) -> token.Pos { return match self is { .Empty as empty_pos -> empty_pos, .Expr as expr -> expr.position(), diff --git a/lib/rivet/src/ast/Sym.ri b/lib/rivet/src/ast/Sym.ri index 35ad9842b..9e306335b 100644 --- a/lib/rivet/src/ast/Sym.ri +++ b/lib/rivet/src/ast/Sym.ri @@ -16,20 +16,20 @@ func new_sym_id() -> uint { } #[boxed] -public struct DuplicateSymbolError < Throwable { +pub struct DuplicateSymbolError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } -public enum ABI as uint8 < traits.Stringable { +pub enum ABI as uint8 < traits.Stringable { Rivet, C; #[inline] - public func from_string(abi: string) -> ?ABI { + pub func from_string(abi: string) -> ?ABI { return match abi { "C" -> .C, "Rivet" -> .Rivet, @@ -38,7 +38,7 @@ public enum ABI as uint8 < traits.Stringable { } #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return match self.* { .C -> "C", .Rivet -> "Rivet" @@ -47,7 +47,7 @@ public enum ABI as uint8 < traits.Stringable { } #[default_value(InvalidSym())] -public trait Sym { +pub trait Sym { id: uint := new_sym_id(); abi: ABI; mut is_public: bool; @@ -130,18 +130,18 @@ public trait Sym { } #[boxed] -public struct InvalidSym < Sym {} +pub struct InvalidSym < Sym {} #[boxed] -public struct SymRef < Sym { - public mut ref: Sym; - public mut ref_expr: Expr; - public mut ref_resolved: bool; +pub struct SymRef < Sym { + pub mut ref: Sym; + pub mut ref_expr: Expr; + pub mut ref_resolved: bool; } #[boxed] -public struct Module < Sym { - public func add_or_get_array(mut self, elem_typ: Type, size: uint, is_mut: bool) -> TypeSym { +pub struct Module < Sym { + pub func add_or_get_array(mut self, elem_typ: Type, size: uint, is_mut: bool) -> TypeSym { unique_name := if is_mut { "[{}]mut {}" } else { @@ -165,7 +165,7 @@ public struct Module < Sym { return type_sym; } - public func add_or_get_vec(mut self, elem_type: Type, is_mut: bool) -> TypeSym { + pub func add_or_get_vec(mut self, elem_type: Type, is_mut: bool) -> TypeSym { unique_name := if is_mut { "[]mut " } else { "[]" }.concat(elem_type.to_qualstring()); if type_sym := self.scope.find(unique_name) { return @as(TypeSym, type_sym); @@ -222,7 +222,7 @@ public struct Module < Sym { return type_sym; } - public func add_or_get_tuple(mut self, types: []Type) -> TypeSym { + pub func add_or_get_tuple(mut self, types: []Type) -> TypeSym { unique_name := { mut sb := strings.Builder.from_string("("); for i, type in types { @@ -248,7 +248,7 @@ public struct Module < Sym { return type_sym; } - public func add_or_get_func(mut self, func_sym: Func) -> TypeSym { + pub func add_or_get_func(mut self, func_sym: Func) -> TypeSym { unique_name := { mut sb := strings.Builder.from_string("func("); if func_sym.is_method { @@ -280,22 +280,22 @@ public struct Module < Sym { } #[inline] - public func is_core(self) -> bool { + pub func is_core(self) -> bool { return self.name == "core"; } } #[boxed] -public struct Const < Sym { - public mut expr: Expr; - public mut evaled_expr: Expr; - public mut has_evaled_size: bool; - public mut evaled_size: int; - public mut type: Type; - public pos: token.Pos; +pub struct Const < Sym { + pub mut expr: Expr; + pub mut evaled_expr: Expr; + pub mut has_evaled_size: bool; + pub mut evaled_size: int; + pub mut type: Type; + pub pos: token.Pos; } -public enum VarLevel as uint8 { +pub enum VarLevel as uint8 { Module, // module-level, `var` Receiver, // receiver: `self` Argument, // argument-level @@ -303,48 +303,48 @@ public enum VarLevel as uint8 { } #[boxed] -public struct Var < Sym { - public is_extern: bool; - public is_mut: bool; - public mut is_used: bool; - public mut is_changed: bool; - public mut is_hidden_ref: bool; - public mut mir_name: string; // used for duplicate objects in MIR - public level: VarLevel; - public mut type: Type; - public pos: token.Pos; +pub struct Var < Sym { + pub is_extern: bool; + pub is_mut: bool; + pub mut is_used: bool; + pub mut is_changed: bool; + pub mut is_hidden_ref: bool; + pub mut mir_name: string; // used for duplicate objects in MIR + pub level: VarLevel; + pub mut type: Type; + pub pos: token.Pos; } #[boxed] -public struct Arg { - public name: string; - public is_mut: bool; - public is_self: bool; - public has_def_expr: bool; - public mut def_expr: Expr; - public pos: token.Pos; - public mut type: Type; +pub struct Arg { + pub name: string; + pub is_mut: bool; + pub is_self: bool; + pub has_def_expr: bool; + pub mut def_expr: Expr; + pub pos: token.Pos; + pub mut type: Type; } #[boxed] -public struct Func < Sym { - public is_extern: bool; - public is_unsafe: bool; - public is_main: bool; - public is_method: bool; - public is_special_method: bool; - public is_variadic: bool; - public mut self_type: Type; - public self_is_mut: bool; - public self_is_ptr: bool; - public self_pos: token.Pos; - public args: []Arg; - public has_named_args: bool; - public has_body: bool; - public ret_type: Type; - public pos: token.Pos; - - public func get_arg(self, idx: uint) -> Arg { +pub struct Func < Sym { + pub is_extern: bool; + pub is_unsafe: bool; + pub is_main: bool; + pub is_method: bool; + pub is_special_method: bool; + pub is_variadic: bool; + pub mut self_type: Type; + pub self_is_mut: bool; + pub self_is_ptr: bool; + pub self_pos: token.Pos; + pub args: []Arg; + pub has_named_args: bool; + pub has_body: bool; + pub ret_type: Type; + pub pos: token.Pos; + + pub func get_arg(self, idx: uint) -> Arg { arg := self.args[idx]; return if arg.is_self { self.args[idx + 1] @@ -353,7 +353,7 @@ public struct Func < Sym { }; } - public func args_len(self) -> uint { + pub func args_len(self) -> uint { mut len: uint := 0; for arg in self.args { if !(arg.is_self or arg.type is .Variadic) { @@ -364,7 +364,7 @@ public struct Func < Sym { } #[inline] - public func kind(self) -> string { + pub func kind(self) -> string { return if self.is_method { if self.is_special_method { "special method" @@ -377,7 +377,7 @@ public struct Func < Sym { } #[inline] - public func type(self, mut universe: Module) -> Type { + pub func type(self, mut universe: Module) -> Type { return .Func( is_method: self.is_method, self_is_mut: self.self_is_mut, diff --git a/lib/rivet/src/ast/Table.ri b/lib/rivet/src/ast/Table.ri index 9de32442f..026aad785 100644 --- a/lib/rivet/src/ast/Table.ri +++ b/lib/rivet/src/ast/Table.ri @@ -12,68 +12,68 @@ import ../report; import ../utils; #[boxed] -public struct Table { +pub struct Table { /// `.universe` is the mega-module where all the modules being /// compiled reside. - public mut universe: Module; - public mut prefs: prefs.Prefs; + pub mut universe: Module; + pub mut prefs: prefs.Prefs; - public pointer_size: uint; + pub pointer_size: uint; - public mut core_mod: Module; - public mut throwable_sym_is_set: bool; + pub mut core_mod: Module; + pub mut throwable_sym_is_set: bool; - public mut builtins: []Builtin; + pub mut builtins: []Builtin; - public mut c_defines: CDefines; - public mut c_include_paths: []string; - public mut c_user_include_paths: []string; + pub mut c_defines: CDefines; + pub mut c_include_paths: []string; + pub mut c_user_include_paths: []string; /// Primitive type, Throwable and Vector symbols. - public mut bool_sym: TypeSym; - public mut rune_sym: TypeSym; - public mut int8_sym: TypeSym; - public mut int16_sym: TypeSym; - public mut int32_sym: TypeSym; - public mut int64_sym: TypeSym; - public mut int_sym: TypeSym; - public mut uint8_sym: TypeSym; - public mut uint16_sym: TypeSym; - public mut uint32_sym: TypeSym; - public mut uint64_sym: TypeSym; - public mut uint_sym: TypeSym; - public mut comptime_int_sym: TypeSym; - public mut comptime_float_sym: TypeSym; - public mut float32_sym: TypeSym; - public mut float64_sym: TypeSym; - public mut string_sym: TypeSym; - public mut throwable_sym: TypeSym; - public mut vector_sym: TypeSym; // from `core` module + pub mut bool_sym: TypeSym; + pub mut rune_sym: TypeSym; + pub mut int8_sym: TypeSym; + pub mut int16_sym: TypeSym; + pub mut int32_sym: TypeSym; + pub mut int64_sym: TypeSym; + pub mut int_sym: TypeSym; + pub mut uint8_sym: TypeSym; + pub mut uint16_sym: TypeSym; + pub mut uint32_sym: TypeSym; + pub mut uint64_sym: TypeSym; + pub mut uint_sym: TypeSym; + pub mut comptime_int_sym: TypeSym; + pub mut comptime_float_sym: TypeSym; + pub mut float32_sym: TypeSym; + pub mut float64_sym: TypeSym; + pub mut string_sym: TypeSym; + pub mut throwable_sym: TypeSym; + pub mut vector_sym: TypeSym; // from `core` module /// Primitive types. - public mut bool_t: Type; - public mut rune_t: Type; - public mut int8_t: Type; - public mut int16_t: Type; - public mut int32_t: Type; - public mut int64_t: Type; - public mut int_t: Type; - public mut uint8_t: Type; - public mut uint16_t: Type; - public mut uint32_t: Type; - public mut uint64_t: Type; - public mut uint_t: Type; - public mut comptime_int_t: Type; - public mut comptime_float_t: Type; - public mut float32_t: Type; - public mut float64_t: Type; - public mut string_t: Type; - public mut throwable_t: Type; - - public mut source_files: []SourceFile; + pub mut bool_t: Type; + pub mut rune_t: Type; + pub mut int8_t: Type; + pub mut int16_t: Type; + pub mut int32_t: Type; + pub mut int64_t: Type; + pub mut int_t: Type; + pub mut uint8_t: Type; + pub mut uint16_t: Type; + pub mut uint32_t: Type; + pub mut uint64_t: Type; + pub mut uint_t: Type; + pub mut comptime_int_t: Type; + pub mut comptime_float_t: Type; + pub mut float32_t: Type; + pub mut float64_t: Type; + pub mut string_t: Type; + pub mut throwable_t: Type; + + pub mut source_files: []SourceFile; #[inline] - public func new(prefs_: prefs.Prefs) -> Table { + pub func new(prefs_: prefs.Prefs) -> Table { universe_ := universe(); mut table := Table( universe: universe_, @@ -193,7 +193,7 @@ public struct Table { ]; } - public func find_builtin(self, name: string) -> ?Builtin { + pub func find_builtin(self, name: string) -> ?Builtin { for builtin in self.builtins { is_equal := match builtin is { .Const as b_var -> b_var.name == name, @@ -207,22 +207,22 @@ public struct Table { return none; } - public func exist_builtin(self, name: string) -> bool { + pub func exist_builtin(self, name: string) -> bool { return self.find_builtin(name) !is none; } #[inline] - public func is_number(self, type: Type) -> bool { + pub func is_number(self, type: Type) -> bool { return self.is_int(type) or self.is_float(type); } #[inline] - public func is_int(self, type: Type) -> bool { + pub func is_int(self, type: Type) -> bool { return self.is_signed_int(type) or self.is_unsigned_int(type); } #[inline] - public func is_signed_int(self, type: Type) -> bool { + pub func is_signed_int(self, type: Type) -> bool { return type in [ self.int8_t, self.int16_t, self.int32_t, self.int64_t, self.int_t, self.comptime_int_t @@ -230,23 +230,23 @@ public struct Table { } #[inline] - public func is_unsigned_int(self, type: Type) -> bool { + pub func is_unsigned_int(self, type: Type) -> bool { return type in [ self.uint8_t, self.uint16_t, self.uint32_t, self.uint64_t, self.uint_t ]; } #[inline] - public func is_float(self, type: Type) -> bool { + pub func is_float(self, type: Type) -> bool { return type in [self.float32_t, self.float64_t, self.comptime_float_t]; } #[inline] - public func is_comptime_number(self, type: Type) -> bool { + pub func is_comptime_number(self, type: Type) -> bool { return type == self.comptime_int_t or type == self.comptime_float_t; } - public func comptime_number_to_type(self, type: Type) -> Type { + pub func comptime_number_to_type(self, type: Type) -> Type { return if type == self.comptime_int_t { self.int32_t } else if type == self.comptime_float_t { @@ -256,7 +256,7 @@ public struct Table { }; } - public func number_bits(self, type: Type) -> uint { + pub func number_bits(self, type: Type) -> uint { return if self.is_int(type) { self.int_bits(type) } else if self.is_float(type) { @@ -266,7 +266,7 @@ public struct Table { }; } - public func int_bits(self, type: Type) -> uint { + pub func int_bits(self, type: Type) -> uint { type_sym := type.symbol()?; return if type_sym.info is .SizedInt as int_info { int_info.size @@ -279,7 +279,7 @@ public struct Table { }; } - public func float_bits(self, type: Type) -> uint { + pub func float_bits(self, type: Type) -> uint { _ = self; type_sym := type.symbol()?; return if type_sym.info is .Float as float_info { @@ -291,7 +291,7 @@ public struct Table { /// Returns the size and alignment (in bytes) of `typ`, similarly to /// C's `sizeof(T)` and `_Alignof(T)`. - public func type_size(mut self, type: Type, is_raw: bool := false) -> (uint, uint) { + pub func type_size(mut self, type: Type, is_raw: bool := false) -> (uint, uint) { return match type is { .Result, .Option -> self.type_symbol_size(self.throwable_sym, is_raw), .Rawptr, .Pointer, .Func -> (self.pointer_size, self.pointer_size), @@ -303,7 +303,7 @@ public struct Table { }; } - public func type_symbol_size(mut self, mut type_sym: TypeSym, is_raw: bool := false) -> (uint, uint) { + pub func type_symbol_size(mut self, mut type_sym: TypeSym, is_raw: bool := false) -> (uint, uint) { return if type_sym.size != 0 { (type_sym.size, type_sym.align) } else { @@ -387,7 +387,7 @@ public struct Table { }; } - public func filter_files(self, inputs: []string) -> []string { + pub func filter_files(self, inputs: []string) -> []string { mut new_inputs := @vec(string, inputs.len); for input in inputs { base_name_input := Path.base_name(input); @@ -441,7 +441,7 @@ public struct Table { return new_inputs; } - public func evalue_pp_symbol(self, name: string, pos: token.Pos) -> bool { + pub func evalue_pp_symbol(self, name: string, pos: token.Pos) -> bool { match name { // operating systems "_LINUX_", "_WINDOWS_" -> { @@ -494,7 +494,7 @@ public struct Table { } } -public func universe() -> Module { +pub func universe() -> Module { return Module( name: "universe", scope: Scope(syms: [ @@ -519,7 +519,7 @@ public func universe() -> Module { ); } -public enum Builtin { +pub enum Builtin { Invalid, Const { name: string; @@ -544,7 +544,7 @@ public enum Builtin { } }; - public func type(self) -> Type { + pub func type(self) -> Type { return match self is { .Const as b_const -> b_const.type, .Func as b_func -> b_func.type, @@ -554,11 +554,11 @@ public enum Builtin { } struct BuiltinArg { - public name: string; - public is_mut: bool; - public is_any: bool; // any type - public type: Type; - public is_optional: bool; + pub name: string; + pub is_mut: bool; + pub is_any: bool; // any type + pub type: Type; + pub is_optional: bool; } enum BuiltinFuncType { diff --git a/lib/rivet/src/ast/Type.ri b/lib/rivet/src/ast/Type.ri index 1cd1d7747..5cd221c2f 100644 --- a/lib/rivet/src/ast/Type.ri +++ b/lib/rivet/src/ast/Type.ri @@ -8,7 +8,7 @@ import { Builder } from std/strings; import ../token; #[default_value(.Void())] -public enum Type < traits.Stringable { +pub enum Type < traits.Stringable { Basic { mut sym: TypeSym; mut is_unresolved: bool; @@ -100,7 +100,7 @@ public enum Type < traits.Stringable { }; #[inline] - public func ptr_or_ref_inner(self) -> Self { + pub func ptr_or_ref_inner(self) -> Self { return match self is { .Pointer as ptr -> ptr.inner, .Rawptr -> self, @@ -108,7 +108,7 @@ public enum Type < traits.Stringable { }; } - public func unalias(self) -> ?Self { + pub func unalias(self) -> ?Self { // NOTE: `.unalias()` returns an option, so we use the same type without // unaliasing instead. return match self is { @@ -149,7 +149,7 @@ public enum Type < traits.Stringable { }; } - public func unalias_in_place(mut self) { + pub func unalias_in_place(mut self) { if unaliased_type := self.unalias() { unsafe { @set_enum_ref_value(self, unaliased_type); @@ -158,7 +158,7 @@ public enum Type < traits.Stringable { } #[inline] - public func symbol(self) -> ?TypeSym { + pub func symbol(self) -> ?TypeSym { // NOTE: `.Void`, `.None`, `.Never` and `.Rawptr` has no `TypeSym` value. return match self is { .Result as result -> result.inner.symbol(), @@ -175,7 +175,7 @@ public enum Type < traits.Stringable { } #[inline] - public func is_primitive(self) -> bool { + pub func is_primitive(self) -> bool { return if type_sym := self.symbol() { type_sym.is_primitive() } else { @@ -184,7 +184,7 @@ public enum Type < traits.Stringable { } #[inline] - public func is_boxed(self) -> bool { + pub func is_boxed(self) -> bool { return if type_sym := self.symbol() { type_sym.is_boxed() } else { @@ -193,7 +193,7 @@ public enum Type < traits.Stringable { } #[inline] - public func is_void(self) -> bool { + pub func is_void(self) -> bool { return match self is { .Void, .Never -> true, .Result as result -> result.inner.is_void(), @@ -202,12 +202,12 @@ public enum Type < traits.Stringable { } #[inline] - public func is_pointer(self) -> bool { + pub func is_pointer(self) -> bool { return self is .Pointer or self is .Rawptr; } #[inline] - public func is_mut_pointer(self) -> bool { + pub func is_mut_pointer(self) -> bool { return match self is { .Pointer as ptr -> ptr.is_mut, .Rawptr -> true, @@ -216,7 +216,7 @@ public enum Type < traits.Stringable { } #[inline] - public func is_any_kind_of_pointer(self) -> bool { + pub func is_any_kind_of_pointer(self) -> bool { return match self is { .Pointer, .Rawptr, .Func -> true, else -> if type_sym := self.symbol() { @@ -228,7 +228,7 @@ public enum Type < traits.Stringable { } #[inline] - public func position(self) -> token.Pos { + pub func position(self) -> token.Pos { return match self is { .Void, .None -> token.noPos, .Never as never_pos -> never_pos, @@ -250,7 +250,7 @@ public enum Type < traits.Stringable { } #[inline] - public func ==(self, rhs: Self) -> bool { + pub func ==(self, rhs: Self) -> bool { return match self is { .None if rhs is .None -> true, .Void if rhs is .Void -> true, @@ -304,19 +304,19 @@ public enum Type < traits.Stringable { }; } - public func !=(self, rhs: Self) -> bool { + pub func !=(self, rhs: Self) -> bool { return !(self == rhs); } - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.to_string_(false); } - public func to_qualstring(self) -> string { + pub func to_qualstring(self) -> string { return self.to_string_(true); } - public func to_string_(self, qualstr: bool) -> string { + pub func to_string_(self, qualstr: bool) -> string { return match self is { .None -> "", .Void -> "", diff --git a/lib/rivet/src/ast/TypeInfo.ri b/lib/rivet/src/ast/TypeInfo.ri index 544ab2146..75d8cc6c1 100644 --- a/lib/rivet/src/ast/TypeInfo.ri +++ b/lib/rivet/src/ast/TypeInfo.ri @@ -4,7 +4,7 @@ import std/traits; -public enum TypeInfo < traits.Stringable { +pub enum TypeInfo < traits.Stringable { Invalid, Placeholder, None, @@ -131,7 +131,7 @@ public enum TypeInfo < traits.Stringable { }; #[inline] - public func elem_type(self) -> ?Type { + pub func elem_type(self) -> ?Type { return match self is { .Array as arr -> arr.elem_type, .Vector as vec -> vec.elem_type, @@ -140,7 +140,7 @@ public enum TypeInfo < traits.Stringable { } #[inline] - public func is_mut_arr_or_vec(self) -> bool { + pub func is_mut_arr_or_vec(self) -> bool { return match self is { .Array as arr -> arr.is_mut, .Vector as vec -> vec.is_mut, @@ -149,19 +149,19 @@ public enum TypeInfo < traits.Stringable { } #[inline] - public func is_primitive(self) -> bool { + pub func is_primitive(self) -> bool { return self is .Bool or self is .Rune or self is .SizedInt or self is .SizedUint or self is .Uint or self is .Int or self is .ComptimeInt or self is .ComptimeFloat or self is .ComptimeFloat or self is .Float; } #[inline] - public func is_compound(self) -> bool { + pub func is_compound(self) -> bool { return self is .Struct or self is .Trait or self is .Enum or self is .Tuple; } #[inline] - public func to_string(self) -> string { + pub func to_string(self) -> string { return match self is { .Invalid -> "invalid", .Placeholder -> "placeholder", @@ -193,10 +193,10 @@ public enum TypeInfo < traits.Stringable { } #[boxed] -public struct EnumVariant { - public name: string; - public value: int; - public has_type: bool; - public mut type: Type; - public has_fields: bool; +pub struct EnumVariant { + pub name: string; + pub value: int; + pub has_type: bool; + pub mut type: Type; + pub has_fields: bool; } diff --git a/lib/rivet/src/ast/TypeSym.ri b/lib/rivet/src/ast/TypeSym.ri index 423294465..0724cc4e5 100644 --- a/lib/rivet/src/ast/TypeSym.ri +++ b/lib/rivet/src/ast/TypeSym.ri @@ -3,26 +3,26 @@ // be found in the LICENSE file. #[boxed] -public struct Field { - public is_public: bool; - public name: string; - public is_mut: bool; - public has_def_expr: bool; - public def_expr: Expr; - public type: Type; - public is_required: bool; +pub struct Field { + pub is_public: bool; + pub name: string; + pub is_mut: bool; + pub has_def_expr: bool; + pub def_expr: Expr; + pub type: Type; + pub is_required: bool; } #[boxed] -public struct TypeSym < Sym { - public mut fields: []Field; - public mut full_fields_: []Field; - public mut info: TypeInfo := .Invalid(); - public mut size: uint; - public mut align: uint; - public mut default_value: ?Expr; - - public func lookup_field(self, name: string) -> ?Field { +pub struct TypeSym < Sym { + pub mut fields: []Field; + pub mut full_fields_: []Field; + pub mut info: TypeInfo := .Invalid(); + pub mut size: uint; + pub mut align: uint; + pub mut default_value: ?Expr; + + pub func lookup_field(self, name: string) -> ?Field { for f in self.fields { if f.name == name { return f; @@ -50,12 +50,12 @@ public struct TypeSym < Sym { } #[inline] - public func has_field(self, name: string) -> bool { + pub func has_field(self, name: string) -> bool { return self.lookup_field(name) !is none; } #[inline] - public func lookup(self, name: string) -> ?Sym { + pub func lookup(self, name: string) -> ?Sym { return if s := self.scope.lookup(name) { s } else { @@ -63,7 +63,7 @@ public struct TypeSym < Sym { }; } - public func find_in_base(self, name: string) -> ?Sym { + pub func find_in_base(self, name: string) -> ?Sym { if self.info is .Trait as trait_info { for b in trait_info.bases { if s := b.scope.find(name) { @@ -92,7 +92,7 @@ public struct TypeSym < Sym { } #[inline] - public func find_func(self, name: string) -> ?Func { + pub func find_func(self, name: string) -> ?Func { return if sym := self.scope.find(name); sym is Func as func_ { if self.info !is .Trait and !func_.has_body { return none; @@ -109,7 +109,7 @@ public struct TypeSym < Sym { } #[inline] - public func find_method(self, name: string) -> ?Func { + pub func find_method(self, name: string) -> ?Func { return if func_ := self.find_func(name); func_.is_method { func_ } else { @@ -118,16 +118,16 @@ public struct TypeSym < Sym { } #[inline] - public func has_func(self, name: string) -> bool { + pub func has_func(self, name: string) -> bool { return self.find_func(name) !is none; } #[inline] - public func has_method(self, name: string) -> bool { + pub func has_method(self, name: string) -> bool { return self.find_method(name) !is none; } - public func full_fields(mut self) -> []Field { + pub func full_fields(mut self) -> []Field { if !self.full_fields_.is_empty() { return self.full_fields_; } @@ -158,7 +158,7 @@ public struct TypeSym < Sym { } #[inline] - public func implement_trait(self, trait_sym: TypeSym) -> bool { + pub func implement_trait(self, trait_sym: TypeSym) -> bool { return if trait_sym.info is .Trait as trait_info { self in trait_info.implements } else { @@ -166,7 +166,7 @@ public struct TypeSym < Sym { }; } - public func update(mut self, other: TypeSym) -> !bool { + pub func update(mut self, other: TypeSym) -> !bool { if self.info is .Placeholder { // update placeholder if other.info !is .Placeholder { @@ -183,7 +183,7 @@ public struct TypeSym < Sym { } #[inline] - public func is_boxed(self) -> bool { + pub func is_boxed(self) -> bool { return if self.info is .Enum as enum_info { enum_info.is_boxed } else if self.info is .Struct as struct_info { @@ -194,17 +194,17 @@ public struct TypeSym < Sym { } #[inline] - public func is_primitive(self) -> bool { + pub func is_primitive(self) -> bool { return self.info.is_primitive(); } #[inline] - public func ==(self, rhs: Self) -> bool { + pub func ==(self, rhs: Self) -> bool { return self.id == rhs.id; } #[inline] - public func !=(self, rhs: Self) -> bool { + pub func !=(self, rhs: Self) -> bool { return self.id != rhs.id; } } diff --git a/lib/rivet/src/ast/mod.ri b/lib/rivet/src/ast/mod.ri index 09e0929c6..c3b207011 100644 --- a/lib/rivet/src/ast/mod.ri +++ b/lib/rivet/src/ast/mod.ri @@ -4,37 +4,37 @@ import ../token; -public enum Node { +pub enum Node { Decl: Decl, Stmt: Stmt, Expr: Expr } #[boxed] -public struct SourceFile { - public file: string; - public decls: []Decl; - public mut mod: Module; - public mut imported_symbols: ImportedSymbols; +pub struct SourceFile { + pub file: string; + pub decls: []Decl; + pub mut mod: Module; + pub mut imported_symbols: ImportedSymbols; } #[boxed] -public struct ImportedSymbol { - public name: string; - public sym: Sym; - public pos: token.Pos; - public mut is_used: bool; +pub struct ImportedSymbol { + pub name: string; + pub sym: Sym; + pub pos: token.Pos; + pub mut is_used: bool; } -public struct ImportedSymbols { - public mut syms: []ImportedSymbol; +pub struct ImportedSymbols { + pub mut syms: []ImportedSymbol; #[inline] - public func add(mut self, name: string, sym: Sym, pos: token.Pos, is_used: bool := false) { + pub func add(mut self, name: string, sym: Sym, pos: token.Pos, is_used: bool := false) { self.syms.push(ImportedSymbol(name, sym, pos, is_used)); } - public func find(&self, name: string) -> ?ImportedSymbol { + pub func find(&self, name: string) -> ?ImportedSymbol { for imported_sym in self.syms { if name == imported_sym.name { return imported_sym; @@ -44,22 +44,22 @@ public struct ImportedSymbols { } #[inline] - public func exists(&self, name: string) -> bool { + pub func exists(&self, name: string) -> bool { return self.find(name) !is none; } } // Used in variable declarations/statements and guard expressions. #[boxed] -public struct ObjectData { - public name: string; - public is_mut: bool; - public is_ref: bool; - public has_type: bool; - public mut type: Type; - public level: VarLevel; - public pos: token.Pos; - public mut sym: Var; - public is_extern: bool; - public is_global: bool; +pub struct ObjectData { + pub name: string; + pub is_mut: bool; + pub is_ref: bool; + pub has_type: bool; + pub mut type: Type; + pub level: VarLevel; + pub pos: token.Pos; + pub mut sym: Var; + pub is_extern: bool; + pub is_global: bool; } diff --git a/lib/rivet/src/build/mod.ri b/lib/rivet/src/build/mod.ri index d551191af..022432ad4 100644 --- a/lib/rivet/src/build/mod.ri +++ b/lib/rivet/src/build/mod.ri @@ -4,19 +4,19 @@ import std/semver; -public alias Version := semver.Version; +pub alias Version := semver.Version; -public struct Project { - public mut name: string; - public mut description: string; - public mut version: Version; - public mut license: string; - public mut authors: []string; - public mut dependencies: []Dependency; - public mut repository_url: string; +pub struct Project { + pub mut name: string; + pub mut description: string; + pub mut version: Version; + pub mut license: string; + pub mut authors: []string; + pub mut dependencies: []Dependency; + pub mut repository_url: string; } -public struct Dependency { - public name: string; - public version: string; +pub struct Dependency { + pub name: string; + pub version: string; } diff --git a/lib/rivet/src/checker/mod.ri b/lib/rivet/src/checker/mod.ri index e628ed9eb..0d9b6364f 100644 --- a/lib/rivet/src/checker/mod.ri +++ b/lib/rivet/src/checker/mod.ri @@ -9,7 +9,7 @@ import ../utils; import ../report; #[boxed] -public struct Checker { +pub struct Checker { mut table: ast.Table; mut prefs: prefs.Prefs; @@ -32,7 +32,7 @@ public struct Checker { mut defer_stmts_start: uint; mut defer_stmts: []ast.Stmt.Defer; - public func check_files(mut self, source_files: []ast.SourceFile) { + pub func check_files(mut self, source_files: []ast.SourceFile) { // check global variables for source_file in source_files { self.sym = source_file.mod; diff --git a/lib/rivet/src/checker/name_cases.ri b/lib/rivet/src/checker/name_cases.ri index b05924eda..3c6378cf5 100644 --- a/lib/rivet/src/checker/name_cases.ri +++ b/lib/rivet/src/checker/name_cases.ri @@ -15,7 +15,7 @@ extend Checker { Pascal, Upper; - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return match self.* { .Snake -> "snake", .Camel -> "camel", diff --git a/lib/rivet/src/checker/types.ri b/lib/rivet/src/checker/types.ri index 0cd3d40b4..dd79af491 100644 --- a/lib/rivet/src/checker/types.ri +++ b/lib/rivet/src/checker/types.ri @@ -10,7 +10,7 @@ import ../report; struct IncompatibleTypesError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } diff --git a/lib/rivet/src/codegen/mir/Block.ri b/lib/rivet/src/codegen/mir/Block.ri index 5c1d25bef..39b3bc717 100644 --- a/lib/rivet/src/codegen/mir/Block.ri +++ b/lib/rivet/src/codegen/mir/Block.ri @@ -6,15 +6,15 @@ import std/traits; import std/strings; #[boxed] -public struct Block < traits.Stringable { +pub struct Block < traits.Stringable { mut id: uint; mut stmts: []Stmt; - public func add_stmt(mut self, stmt: Stmt) { + pub func add_stmt(mut self, stmt: Stmt) { self.stmts.push(stmt); } - public func to_string(self) -> string { + pub func to_string(self) -> string { mut sb := strings.Builder.new(); sb.writeln_fmt("@b{} {{", self.id); for stmt in self.stmts { @@ -25,7 +25,7 @@ public struct Block < traits.Stringable { } } -public enum Stmt < traits.Stringable { +pub enum Stmt < traits.Stringable { Expr: Expr, Assign { left: Expr; @@ -47,7 +47,7 @@ public enum Stmt < traits.Stringable { expr: Expr := .Empty(); }; - public func to_string(self) -> string { + pub func to_string(self) -> string { return match self is { .Expr as expr -> expr.to_string(), .Assign as assign -> "{} = {}".fmt(assign.left, assign.right), diff --git a/lib/rivet/src/codegen/mir/Expr.ri b/lib/rivet/src/codegen/mir/Expr.ri index 98406cb72..35cb7b3c6 100644 --- a/lib/rivet/src/codegen/mir/Expr.ri +++ b/lib/rivet/src/codegen/mir/Expr.ri @@ -6,7 +6,7 @@ import std/traits; import std/strings; #[default_value(.Empty())] -public enum Expr < traits.Stringable { +pub enum Expr < traits.Stringable { Empty, IntConst { value: int; @@ -54,7 +54,7 @@ public enum Expr < traits.Stringable { Index, AddrOf; - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return match self.* { .Add -> "add", .Sub -> "sub", @@ -87,7 +87,7 @@ public enum Expr < traits.Stringable { type: Type; }; - public func to_string(self) -> string { + pub func to_string(self) -> string { return match self is { .Empty -> "", .IntConst as int_const -> "{}".fmt(int_const.value), diff --git a/lib/rivet/src/codegen/mir/Type.ri b/lib/rivet/src/codegen/mir/Type.ri index 3d0ae4a01..0621a10eb 100644 --- a/lib/rivet/src/codegen/mir/Type.ri +++ b/lib/rivet/src/codegen/mir/Type.ri @@ -7,7 +7,7 @@ import std/strings; import std/process; #[default_value(.Void())] -public enum Type < traits.Stringable { +pub enum Type < traits.Stringable { Void, Never, SizedInt { @@ -40,7 +40,7 @@ public enum Type < traits.Stringable { size: uint; }; - public func size(self) -> uint { + pub func size(self) -> uint { return match self is { .SizedInt as int -> int.size, .SizedUint as uint -> uint.size, @@ -53,7 +53,7 @@ public enum Type < traits.Stringable { }; } - public func to_string(self) -> string { + pub func to_string(self) -> string { return match self is { .Void -> "void", .Never -> "never", diff --git a/lib/rivet/src/codegen/mir/mod.ri b/lib/rivet/src/codegen/mir/mod.ri index b34914443..842bc7f11 100644 --- a/lib/rivet/src/codegen/mir/mod.ri +++ b/lib/rivet/src/codegen/mir/mod.ri @@ -9,20 +9,20 @@ import std/strings; import ../../utils; #[boxed] -public struct ModuleIR < traits.Stringable { - public name: string; - public mut structs: []Struct; - public mut globals: []Global; - public mut vtables: []VTable; - public mut externs: []Func; - public mut funcs: []Func; +pub struct ModuleIR < traits.Stringable { + pub name: string; + pub mut structs: []Struct; + pub mut globals: []Global; + pub mut vtables: []VTable; + pub mut externs: []Func; + pub mut funcs: []Func; #[inline] - public func to_file(self) -> ! { + pub func to_file(self) -> ! { fs.write_file("{}.mir".fmt(self.name), self.to_string())!; } - public func to_string(self) -> string { + pub func to_string(self) -> string { mut sb := strings.Builder.new(); sb.writeln_fmt("// Rivet Intermediate Representation for module `{}`.", self.name); sb.writeln_fmt("// Auto-generated by {}.", utils.full_version()); @@ -58,18 +58,18 @@ public struct ModuleIR < traits.Stringable { } #[boxed] -public struct Field { - public name: string; - public type: Type; +pub struct Field { + pub name: string; + pub type: Type; } #[boxed] -public struct Struct < traits.Stringable { - public name: string; - public fields: []Field; - public is_opaque: bool; +pub struct Struct < traits.Stringable { + pub name: string; + pub fields: []Field; + pub is_opaque: bool; - public func to_string(self) -> string { + pub func to_string(self) -> string { mut sb := strings.Builder.new(); sb.write_fmt("struct @{}", self.name); if self.is_opaque { @@ -91,13 +91,13 @@ public struct Struct < traits.Stringable { } #[boxed] -public struct Global < traits.Stringable { - public is_extern: bool; - public name: string; - public type: Type; - public fields: []Var; +pub struct Global < traits.Stringable { + pub is_extern: bool; + pub name: string; + pub type: Type; + pub fields: []Var; - public func to_string(self) -> string { + pub func to_string(self) -> string { mut sb := strings.Builder.new(); if self.is_extern { sb.write_string("extern "); @@ -108,33 +108,33 @@ public struct Global < traits.Stringable { } #[boxed] -public struct VTable { - public funcs: []Func; +pub struct VTable { + pub funcs: []Func; } #[boxed] -public struct Func < traits.Stringable { - public name: string; - public mut args_len: uint; - public ret_type: Type; - public is_variadic: bool; - public is_extern: bool; - public mut locals: []Var; - public mut blocks: []Block; - public mut cur_block: Block; - - public func make_tmp(mut self, type: Type) -> Var { +pub struct Func < traits.Stringable { + pub name: string; + pub mut args_len: uint; + pub ret_type: Type; + pub is_variadic: bool; + pub is_extern: bool; + pub mut locals: []Var; + pub mut blocks: []Block; + pub mut cur_block: Block; + + pub func make_tmp(mut self, type: Type) -> Var { tmp := Var(self.locals.len, level: .Temporal, type: type); self.locals.push(tmp); return tmp; } - public func add_local(mut self, mut local: Var) { + pub func add_local(mut self, mut local: Var) { local.id = self.locals.len; self.locals.push(local); } - public func get_local(self, name: string) -> ?Var { + pub func get_local(self, name: string) -> ?Var { for local in self.locals { if local.dbg_name == name { return local; @@ -143,16 +143,16 @@ public struct Func < traits.Stringable { return none; } - public func has_local(self, name: string) -> bool { + pub func has_local(self, name: string) -> bool { return self.get_local(name) !is none; } - public func add_block(mut self, mut block: Block) { + pub func add_block(mut self, mut block: Block) { block.id = self.blocks.len; self.blocks.push(block); } - public func to_string(self) -> string { + pub func to_string(self) -> string { mut sb := strings.Builder.new(); if self.is_extern { sb.write_string("extern "); @@ -192,25 +192,25 @@ public struct Func < traits.Stringable { } } -public enum VarLevel { +pub enum VarLevel { Argument, Local, Temporal } #[boxed] -public struct Var { - public mut id: uint; - public dbg_name: string; - public level: VarLevel; - public type: Type; - public mut value: ?Expr; // comptime value - public mut is_moved: bool; - public mut is_dropped: bool; - public mut is_initialized: bool; - public fields: []Var; - - public func set_field(self, name: string, value: Expr) { +pub struct Var { + pub mut id: uint; + pub dbg_name: string; + pub level: VarLevel; + pub type: Type; + pub mut value: ?Expr; // comptime value + pub mut is_moved: bool; + pub mut is_dropped: bool; + pub mut is_initialized: bool; + pub fields: []Var; + + pub func set_field(self, name: string, value: Expr) { for field in self.fields { if field.dbg_name == name { field.value = value; @@ -219,7 +219,7 @@ public struct Var { } } - public func get_field(self, name: string) -> ?Var { + pub func get_field(self, name: string) -> ?Var { for field in self.fields { if field.dbg_name == name { return field; @@ -228,7 +228,7 @@ public struct Var { return none; } - public func get_field_by_id(self, id: uint) -> ?Var { + pub func get_field_by_id(self, id: uint) -> ?Var { for field in self.fields { if field.id == id { return field; diff --git a/lib/rivet/src/codegen/mod.ri b/lib/rivet/src/codegen/mod.ri index b1099d603..f784a2d1e 100644 --- a/lib/rivet/src/codegen/mod.ri +++ b/lib/rivet/src/codegen/mod.ri @@ -11,7 +11,7 @@ import ../utils; import ../utils/maps; #[boxed] -public struct Codegen { +pub struct Codegen { mut table: ast.Table; prefs: prefs.Prefs; @@ -37,7 +37,7 @@ public struct Codegen { mut loop_exit_label: string; mut while_continue_expr: ?mir.Expr; - public func generate_mirs(mut self, source_files: []ast.SourceFile) { + pub func generate_mirs(mut self, source_files: []ast.SourceFile) { self.init_types(); self.rivet_internal = self.get_or_create_mir("rivetc.compiler.internal"); for source_file in source_files { @@ -53,7 +53,7 @@ public struct Codegen { } } - public func generate_mir(mut self, source_file: ast.SourceFile) { + pub func generate_mir(mut self, source_file: ast.SourceFile) { self.source_file = source_file; self.mir = self.get_or_create_mir(source_file.mod.name); self.gen_decls(source_file.decls); diff --git a/lib/rivet/src/depgraph/OrderedDepMap.ri b/lib/rivet/src/depgraph/OrderedDepMap.ri index dd9550137..aa481b28e 100644 --- a/lib/rivet/src/depgraph/OrderedDepMap.ri +++ b/lib/rivet/src/depgraph/OrderedDepMap.ri @@ -7,22 +7,22 @@ import std/process; import ../utils/maps; #[boxed] -public struct OrderedDepMap { +pub struct OrderedDepMap { mut keys: []string; mut data: maps.MapStringArrayOfStrings; // TODO: replace with map type - public func new() -> Self { + pub func new() -> Self { return Self(); } - public func set(mut self, name: string, deps: []string) { + pub func set(mut self, name: string, deps: []string) { if !self.data.contains(name) { self.keys.push(name); } self.data.set(name, deps); } - public func add(mut self, name: string, deps: []string) { + pub func add(mut self, name: string, deps: []string) { mut d := self.get(name); for dep in deps { if dep !in d { @@ -33,7 +33,7 @@ public struct OrderedDepMap { } #[inline] - public func get(self, name: string) -> []string { + pub func get(self, name: string) -> []string { return if res := self.data.get(name) { res } else { @@ -41,7 +41,7 @@ public struct OrderedDepMap { }; } - public func delete(mut self, name: string) { + pub func delete(mut self, name: string) { if !self.data.contains(name) { process.panic("OrderedDepMap.delete(): no such key: `{}`", name); } @@ -54,7 +54,7 @@ public struct OrderedDepMap { self.data.delete(name); } - public func apply_diff(mut self, name: string, deps: []string) { + pub func apply_diff(mut self, name: string, deps: []string) { mut diff := @vec(string); deps_of_name := self.get(name); for dep in deps_of_name { @@ -65,7 +65,7 @@ public struct OrderedDepMap { self.set(name, diff); } - public func size(self) -> uint { + pub func size(self) -> uint { return self.data.len(); } } diff --git a/lib/rivet/src/depgraph/mod.ri b/lib/rivet/src/depgraph/mod.ri index d93964fa9..744631cff 100644 --- a/lib/rivet/src/depgraph/mod.ri +++ b/lib/rivet/src/depgraph/mod.ri @@ -8,26 +8,26 @@ import ../utils; import ../utils/maps; struct DepGraphNode { - public mut name: string; - public mut deps: []string; + pub mut name: string; + pub mut deps: []string; } #[boxed] -public struct DepGraph { - public mut acyclic: bool; - public mut nodes: []DepGraphNode; +pub struct DepGraph { + pub mut acyclic: bool; + pub mut nodes: []DepGraphNode; #[inline] - public func new() -> Self { + pub func new() -> Self { return Self(true, @vec(DepGraphNode, 1024)); } #[inline] - public func add(mut self, mod: string, deps: []string) { + pub func add(mut self, mod: string, deps: []string) { self.nodes.push(DepGraphNode(mod, deps)); } - public func resolve(self) -> Self { + pub func resolve(self) -> Self { mut node_names := OrderedDepMap.new(); mut node_deps := OrderedDepMap.new(); for node in self.nodes { @@ -64,7 +64,7 @@ public struct DepGraph { return resolved; } - public func display(self) -> string { + pub func display(self) -> string { mut out := strings.Builder.new(); for node in self.nodes { for dep in node.deps { @@ -74,7 +74,7 @@ public struct DepGraph { return out.to_string(); } - public func display_cycles(self) -> string { + pub func display_cycles(self) -> string { mut out := strings.Builder.new(); mut seen := false; mut nn := NodeNames(); diff --git a/lib/rivet/src/lib.ri b/lib/rivet/src/lib.ri index f7d545433..56971627e 100644 --- a/lib/rivet/src/lib.ri +++ b/lib/rivet/src/lib.ri @@ -19,7 +19,7 @@ import ./resolver; import ./depgraph; #[boxed] -public struct Compiler { +pub struct Compiler { mut table: ast.Table; mut prefs: prefs.Prefs; @@ -27,7 +27,7 @@ public struct Compiler { mut checker: checker.Checker; mut codegen: codegen.Codegen; - public func new(args: []string, is_test: bool, run_output: bool, is_check: bool) -> ! { + pub func new(args: []string, is_test: bool, run_output: bool, is_check: bool) -> ! { prefs_ := prefs.Prefs.new(args, is_test, run_output, is_check)!; report.reportTable.prefs = prefs_; table_ := ast.Table.new(prefs_); diff --git a/lib/rivet/src/parser/decls.ri b/lib/rivet/src/parser/decls.ri index 5410cb858..a79e3eb83 100644 --- a/lib/rivet/src/parser/decls.ri +++ b/lib/rivet/src/parser/decls.ri @@ -19,9 +19,7 @@ extend Parser { return ast.DocComment(lines, pos); } - public func parse_attributes( - mut self, parse_mod_attributes: bool := false - ) -> ast.Attributes { + pub func parse_attributes(mut self, parse_mod_attributes: bool := false) -> ast.Attributes { mut attributes := ast.Attributes(); while self.accept(.Hash) { if parse_mod_attributes { @@ -67,8 +65,8 @@ extend Parser { #[inline] func is_public(mut self) -> bool { - is_pub := self.accept(.KwPublic); - return self.inside_trait or self.inside_enum_variant_with_fields or is_pub; + is_public := self.accept(.KwPub); + return self.inside_trait or self.inside_enum_variant_with_fields or is_public; } func parse_abi(mut self) -> ast.ABI { diff --git a/lib/rivet/src/parser/mod.ri b/lib/rivet/src/parser/mod.ri index 155c7822d..29d00d707 100644 --- a/lib/rivet/src/parser/mod.ri +++ b/lib/rivet/src/parser/mod.ri @@ -11,7 +11,7 @@ import ../token; import ../tokenizer; #[boxed] -public struct Parser { +pub struct Parser { mut table: ast.Table; mut prefs: prefs.Prefs; @@ -36,7 +36,7 @@ public struct Parser { mut inside_match_header: bool; mut inside_block: bool; - public func parse_module(mut self, mod_sym: ast.Module, files: []string) -> []ast.SourceFile { + pub func parse_module(mut self, mod_sym: ast.Module, files: []string) -> []ast.SourceFile { self.scope = mod_sym.scope; self.mod_sym = mod_sym; mut source_files := @vec(ast.SourceFile); @@ -46,7 +46,7 @@ public struct Parser { return source_files; } - public func parse_file(mut self, file: string) -> ast.SourceFile { + pub func parse_file(mut self, file: string) -> ast.SourceFile { self.file_path = file; self.file_dir = Path.dir_name(file) ?? file; self.tokenizer = tokenizer.Tokenizer.from_file(file, self.prefs, self.table); diff --git a/lib/rivet/src/prefs/mod.ri b/lib/rivet/src/prefs/mod.ri index ab0bb6ae1..f03be017d 100644 --- a/lib/rivet/src/prefs/mod.ri +++ b/lib/rivet/src/prefs/mod.ri @@ -10,17 +10,17 @@ import { Path } from std/fs; import ../utils; -public var rivetDir := Path.join(env.homeDir, ".rivet_lang")!; -public var rivetcDir := Path.dir_name(process.executable()!)?; +pub var rivetDir := Path.join(env.homeDir, ".rivet_lang")!; +pub var rivetcDir := Path.dir_name(process.executable()!)?; -public var objDir := Path.join(rivetDir, "obj")!; -public var libDir := Path.join(rivetDir, "lib")!; -public var rivetcLibDir := Path.join(rivetcDir, "lib")!; +pub var objDir := Path.join(rivetDir, "obj")!; +pub var libDir := Path.join(rivetDir, "lib")!; +pub var rivetcLibDir := Path.join(rivetcDir, "lib")!; -public enum Backend as uint8 { +pub enum Backend as uint8 { C; - public func from_string(name: string) -> ?Self { + pub func from_string(name: string) -> ?Self { return match name { "c" -> .C, else -> none @@ -28,59 +28,59 @@ public enum Backend as uint8 { } } -public enum OutputMode as uint8 { +pub enum OutputMode as uint8 { Bin } -public enum OptimizeMode as uint8 { +pub enum OptimizeMode as uint8 { Debug, Release } -public enum LinkMode as uint8 { +pub enum LinkMode as uint8 { Var, Dynamic } #[boxed] -public struct Prefs { +pub struct Prefs { // Target info - public mut target_os: sys.OS := sys.os(); - public mut target_arch: sys.Arch := sys.arch(); - public mut target_is_64bit: bool := sys.is_64bit(); - public mut target_is_little_endian: bool := sys.is_little_endian(); - public mut target_c_runtime: sys.CRuntime := sys.c_runtime(); - public mut target_backend: Backend; - public mut target_backend_compiler: string := "cc"; + pub mut target_os: sys.OS := sys.os(); + pub mut target_arch: sys.Arch := sys.arch(); + pub mut target_is_64bit: bool := sys.is_64bit(); + pub mut target_is_little_endian: bool := sys.is_little_endian(); + pub mut target_c_runtime: sys.CRuntime := sys.c_runtime(); + pub mut target_backend: Backend; + pub mut target_backend_compiler: string := "cc"; // Module info - public mut input: string; - public mut mod_name: string; - public mut mod_dir: string; - public mut mod_output: string; - - public mut library_path: []string := [rivetcLibDir, libDir]; - public mut libraries_to_link: []string; - public mut objects_to_link: []string; - - public mut flags: []string; - public mut check: bool; - public mut check_syntax: bool; - public mut emit_mir: bool; - public mut keep_c: bool; - public mut all_warns_are_errors: bool; - public mut hide_all_warns: bool; - public mut is_verbose: bool; - public mut is_fmt: bool; + pub mut input: string; + pub mut mod_name: string; + pub mut mod_dir: string; + pub mut mod_output: string; + + pub mut library_path: []string := [rivetcLibDir, libDir]; + pub mut libraries_to_link: []string; + pub mut objects_to_link: []string; + + pub mut flags: []string; + pub mut check: bool; + pub mut check_syntax: bool; + pub mut emit_mir: bool; + pub mut keep_c: bool; + pub mut all_warns_are_errors: bool; + pub mut hide_all_warns: bool; + pub mut is_verbose: bool; + pub mut is_fmt: bool; // Output info - public mut output_mode: OutputMode; - public mut optimize_mode: OptimizeMode; - public mut is_test: bool; - public mut run_output: bool; - public mut run_output_args: []string; + pub mut output_mode: OutputMode; + pub mut optimize_mode: OptimizeMode; + pub mut is_test: bool; + pub mut run_output: bool; + pub mut run_output_args: []string; - public func new(args: []string, is_test: bool, run_output: bool, is_check: bool) -> !Self { + pub func new(args: []string, is_test: bool, run_output: bool, is_check: bool) -> !Self { prefs := Prefs(is_test: is_test, run_output: run_output, check: is_check); mut fp := flag.FlagParser.new(args); fp.set_application_name(if is_test { diff --git a/lib/rivet/src/report/mod.ri b/lib/rivet/src/report/mod.ri index 05326d484..1dc8525d0 100644 --- a/lib/rivet/src/report/mod.ri +++ b/lib/rivet/src/report/mod.ri @@ -10,28 +10,28 @@ import ../prefs; import ../token; import ../utils; -public var mut reportTable := ReportTable(); +pub var mut reportTable := ReportTable(); #[inline] -public func total_errors() -> uint { +pub func total_errors() -> uint { return reportTable.errors; } #[inline] -public func total_warns() -> uint { +pub func total_warns() -> uint { return reportTable.warns; } #[boxed] struct ReportTable { - public mut prefs: prefs.Prefs; - public mut errors: uint; - public mut warns: uint; + pub mut prefs: prefs.Prefs; + pub mut errors: uint; + pub mut warns: uint; mut last_pos: token.Pos; } -public enum ReportKind as uint8 { +pub enum ReportKind as uint8 { Error, Warn, Note, @@ -45,43 +45,43 @@ struct Attribute { } #[inline] -public func error(msg: string, pos: token.Pos) { +pub func error(msg: string, pos: token.Pos) { ReportBuilder(.Error, msg, pos).emit(); } #[inline] -public func warn(msg: string, pos: token.Pos) { +pub func warn(msg: string, pos: token.Pos) { ReportBuilder(.Warn, msg, pos).emit(); } #[inline] -public func error_builder(msg: string, pos: token.Pos) -> ReportBuilder { +pub func error_builder(msg: string, pos: token.Pos) -> ReportBuilder { return ReportBuilder(.Error, msg, pos); } #[inline] -public func warn_builder(msg: string, pos: token.Pos) -> ReportBuilder { +pub func warn_builder(msg: string, pos: token.Pos) -> ReportBuilder { return ReportBuilder(.Warn, msg, pos); } // TODO: support JSON format for LSP, etc. -public struct ReportBuilder { +pub struct ReportBuilder { mut kind: ReportKind; msg: string; pos: token.Pos := token.noPos; mut attributes: []Attribute; #[inline] - public func add_note(mut self, msg: string, args: ...traits.Stringable) { + pub func add_note(mut self, msg: string, args: ...traits.Stringable) { self.attributes.push(Attribute(.Note, msg.fmt(args))); } #[inline] - public func add_help(mut self, msg: string, args: ...traits.Stringable) { + pub func add_help(mut self, msg: string, args: ...traits.Stringable) { self.attributes.push(Attribute(.Help, msg.fmt(args))); } - public func emit(mut self) { + pub func emit(mut self) { if self.kind == .Warn { if reportTable.prefs.hide_all_warns { return; diff --git a/lib/rivet/src/resolver/Register.ri b/lib/rivet/src/resolver/Register.ri index f6c7b8422..0c3a74e47 100644 --- a/lib/rivet/src/resolver/Register.ri +++ b/lib/rivet/src/resolver/Register.ri @@ -8,7 +8,7 @@ import ../token; import ../report; #[boxed] -public struct Register { +pub struct Register { mut table: ast.Table; mut prefs: prefs.Prefs; @@ -19,7 +19,7 @@ public struct Register { mut sym: ast.Sym := ast.InvalidSym(); mut source_file: ast.SourceFile; - public func walk_files(mut self, source_files: []ast.SourceFile) { + pub func walk_files(mut self, source_files: []ast.SourceFile) { for sf in source_files { self.is_core_mod = sf.mod.is_core(); if !self.core_is_set and self.is_core_mod { diff --git a/lib/rivet/src/resolver/mod.ri b/lib/rivet/src/resolver/mod.ri index ba4ea5114..74b3209e3 100644 --- a/lib/rivet/src/resolver/mod.ri +++ b/lib/rivet/src/resolver/mod.ri @@ -15,7 +15,7 @@ struct Prelude { } #[boxed] -public struct Resolver { +pub struct Resolver { mut table: ast.Table; mut prefs: prefs.Prefs; @@ -27,7 +27,7 @@ public struct Resolver { mut source_file: ast.SourceFile; - public func resolve_files(mut self, source_files: []ast.SourceFile) { + pub func resolve_files(mut self, source_files: []ast.SourceFile) { Register(self.table, self.prefs).walk_files(source_files); if report.total_errors() > 0 { return; diff --git a/lib/rivet/src/token/Kind.ri b/lib/rivet/src/token/Kind.ri index dfce86260..9ef77f8fd 100644 --- a/lib/rivet/src/token/Kind.ri +++ b/lib/rivet/src/token/Kind.ri @@ -90,7 +90,7 @@ var kindStrings := [ KindMap(.KwNotIn, "!in"), KindMap(.KwNotIs, "!is"), KindMap(.KwOr, "or"), - KindMap(.KwPublic, "public"), + KindMap(.KwPub, "pub"), KindMap(.KwReturn, "return"), KindMap(.KwSelf, "self"), KindMap(.KwSelfTy, "Self"), @@ -107,7 +107,7 @@ var kindStrings := [ var keywordsTable := kindStrings[@as(uint, Kind.KeywordBegin)..]; -public enum Kind < traits.Stringable { +pub enum Kind < traits.Stringable { Unknown, // unknown EndOfFile, // end of file DocComment, // doc-comment @@ -189,7 +189,7 @@ public enum Kind < traits.Stringable { KwNotIn, // !in KwNotIs, // !is KwOr, // or - KwPublic, // public + KwPub, // pub KwReturn, // return KwSelf, // self KwSelfTy, // Self @@ -207,7 +207,7 @@ public enum Kind < traits.Stringable { KeywordEnd; #[inline] - public func lookup(str: string) -> Self { + pub func lookup(str: string) -> Self { for &km in keywordsTable { if km.value == str { return km.key; @@ -217,7 +217,7 @@ public enum Kind < traits.Stringable { } #[inline] - public func single(self) -> Kind { + pub func single(self) -> Kind { return match self { .PlusAssign -> .Plus, .MinusAssign -> .Minus, @@ -232,7 +232,7 @@ public enum Kind < traits.Stringable { } #[inline] - public func is_start_of_type(self) -> bool { + pub func is_start_of_type(self) -> bool { return self in [ .Bang, .Name, .Lparen, .Amp, .Mul, .Lbracket, .Question, .KwSelfTy, .KwFunc @@ -240,7 +240,7 @@ public enum Kind < traits.Stringable { } #[inline] - public func is_assign(self) -> bool { + pub func is_assign(self) -> bool { return self in [ .DeclAssign, .Assign, .PlusAssign, .MinusAssign, .MulAssign, .DivAssign, .ModAssign, .AmpAssign, .PipeAssign, .XorAssign @@ -248,13 +248,13 @@ public enum Kind < traits.Stringable { } #[inline] - public func is_relational(self) -> bool { + pub func is_relational(self) -> bool { return self in [ .Eq, .Ne, .Lt, .Gt, .Le, .Ge, .KwIs, .KwNotIs, .KwIn, .KwNotIn ]; } - public func to_string(&self) -> string { + pub func to_string(&self) -> string { for &km in kindStrings { if km.key == self.* { return km.value; @@ -265,17 +265,17 @@ public enum Kind < traits.Stringable { } #[inline] -public func is_keyword(lit: string) -> bool { +pub func is_keyword(lit: string) -> bool { return Kind.lookup(lit) != .Name; } #[inline] -public func is_overloadable_operator(kind: Kind) -> bool { +pub func is_overloadable_operator(kind: Kind) -> bool { return kind in [.Plus, .Minus, .Mul, .Div, .Mod, .Eq, .Ne, .Lt, .Gt, .Le, .Ge]; } #[inline] -public func overloadable_operator_name(kind: Kind) -> string { +pub func overloadable_operator_name(kind: Kind) -> string { return match kind { .Plus -> "_add_", .Minus -> "_sub_", diff --git a/lib/rivet/src/token/mod.ri b/lib/rivet/src/token/mod.ri index 41809c8cc..cb08136a5 100644 --- a/lib/rivet/src/token/mod.ri +++ b/lib/rivet/src/token/mod.ri @@ -6,21 +6,21 @@ import std/traits; import ../utils; -public var noPos := Pos(); +pub var noPos := Pos(); -public struct Pos < traits.Stringable { - public file: string; - public line: uint; - public mut col: uint; - public mut len: uint; - public pos: uint; +pub struct Pos < traits.Stringable { + pub file: string; + pub line: uint; + pub mut col: uint; + pub mut len: uint; + pub pos: uint; - public end_line: uint; - public end_col: uint; - public is_multiline: bool; + pub end_line: uint; + pub end_col: uint; + pub is_multiline: bool; #[inline] - public func +(&self, other: &Pos) -> Pos { + pub func +(&self, other: &Pos) -> Pos { return if other.line > self.line { Pos( line: self.line, @@ -35,7 +35,7 @@ public struct Pos < traits.Stringable { }; } - public func ==(&self, other: &Pos) -> bool { + pub func ==(&self, other: &Pos) -> bool { return self.file == other.file and self.line == other.line and self.col == other.col @@ -47,7 +47,7 @@ public struct Pos < traits.Stringable { } #[inline] - public func to_report_string(&self) -> string { + pub func to_report_string(&self) -> string { return if self.is_multiline { "{}:{}:{}-{}:{}".fmt( utils.path_styled_for_error_messages(self.file), self.line + 1, @@ -63,7 +63,7 @@ public struct Pos < traits.Stringable { } #[inline] - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return if self.is_multiline { "{}:{}:{}-{}:{}".fmt( self.file, self.line + 1, self.col, self.end_line + 1, self.end_col @@ -74,19 +74,19 @@ public struct Pos < traits.Stringable { } } -public struct Token < traits.Stringable { - public lit: string; - public kind: Kind; - public len: uint; - public pos: Pos; +pub struct Token < traits.Stringable { + pub lit: string; + pub kind: Kind; + pub len: uint; + pub pos: Pos; - public func to_debug_string(&self) -> string { + pub func to_debug_string(&self) -> string { return "rivet.token.Token(kind: '{}', lit: '{}', pos: {})".fmt( self.kind, self.lit, self.pos ); } - public func to_string(&self) -> string { + pub func to_string(&self) -> string { if self.kind == .String { return "string literal"; } diff --git a/lib/rivet/src/tokenizer/mod.ri b/lib/rivet/src/tokenizer/mod.ri index 981ff0cd9..293b1b500 100644 --- a/lib/rivet/src/tokenizer/mod.ri +++ b/lib/rivet/src/tokenizer/mod.ri @@ -17,7 +17,7 @@ import { LF, CR } from ../utils; const NUM_SEP := b'_'; #[boxed] -public struct Tokenizer { +pub struct Tokenizer { table: ast.Table; prefs: prefs.Prefs; file: string := ""; @@ -25,20 +25,20 @@ public struct Tokenizer { mut pos: uint; mut line: uint; mut last_nl_pos: uint; - public mut all_tokens: []token.Token; + pub mut all_tokens: []token.Token; mut tidx: uint; mut is_started: bool; mut is_cr_lf: bool; mut eofs: uint; mut conditional_stack: []mut Conditional; - public func new(text: string, prefs_: prefs.Prefs, table: ast.Table) -> Tokenizer { + pub func new(text: string, prefs_: prefs.Prefs, table: ast.Table) -> Tokenizer { mut t := Tokenizer(table: table, prefs: prefs_, text: text); t.init(); return t; } - public func from_file(file: string, prefs_: prefs.Prefs, table: ast.Table) -> Tokenizer { + pub func from_file(file: string, prefs_: prefs.Prefs, table: ast.Table) -> Tokenizer { mut t := Tokenizer( table: table, prefs: prefs_, file: file, text: utils.read_file(file) catch |err| utils.error(err.to_string()) @@ -199,7 +199,7 @@ public struct Tokenizer { } #[inline] - public func peek_token(self, n: uint) -> token.Token { + pub func peek_token(self, n: uint) -> token.Token { idx := self.tidx + n; return if idx >= self.all_tokens.len { self.new_eof_token() diff --git a/lib/rivet/src/tokenizer/next.ri b/lib/rivet/src/tokenizer/next.ri index e00fdee43..a7352e9cc 100644 --- a/lib/rivet/src/tokenizer/next.ri +++ b/lib/rivet/src/tokenizer/next.ri @@ -11,7 +11,7 @@ const SINGLE_QUOTE: uint8 := 0x27; // `'` const BACKSLASH: uint8 := 0x5C; // '\' extend Tokenizer { - public func next(mut self) -> token.Token { + pub func next(mut self) -> token.Token { while { cidx := self.tidx; self.tidx += 1; diff --git a/lib/rivet/src/utils/array.ri b/lib/rivet/src/utils/array.ri index ae3b1d4d0..be66bd4e1 100644 --- a/lib/rivet/src/utils/array.ri +++ b/lib/rivet/src/utils/array.ri @@ -4,7 +4,7 @@ import std/strings; -public func join(vec: []string, s: string) -> string { +pub func join(vec: []string, s: string) -> string { return if vec.is_empty() { "" } else { @@ -14,7 +14,7 @@ public func join(vec: []string, s: string) -> string { }; } -public func index_of(vec: []string, value: string) -> uint { +pub func index_of(vec: []string, value: string) -> uint { for i, val in vec { if val == value { return i; @@ -24,7 +24,7 @@ public func index_of(vec: []string, value: string) -> uint { } // TODO: tmp-hack -public func arr_4_uint8_contains(arr: [4]uint8, byte: uint8) -> bool { +pub func arr_4_uint8_contains(arr: [4]uint8, byte: uint8) -> bool { for b in arr { if b == byte { return true; diff --git a/lib/rivet/src/utils/file.ri b/lib/rivet/src/utils/file.ri index d1ffcce13..5c72b0f28 100644 --- a/lib/rivet/src/utils/file.ri +++ b/lib/rivet/src/utils/file.ri @@ -11,7 +11,7 @@ var errorPathsAbsolute := (env.get("RIVET_ERROR_PATHS") ?? "relative") == "absol // NOTE: path_styled_for_error_messages will *always* use `/` in the error paths, no // matter the OS, to ensure stable compiler error output in the tests. -public func path_styled_for_error_messages(path_: string) -> string { +pub func path_styled_for_error_messages(path_: string) -> string { rpath := (Path.resolve(path_) catch path_).replace("\\", "/"); return if errorPathsAbsolute { rpath @@ -20,7 +20,7 @@ public func path_styled_for_error_messages(path_: string) -> string { }; } -public func skip_bom(file_content: string) -> string { +pub func skip_bom(file_content: string) -> string { // BOM check if file_content.len >= 3 { if file_content[0] == 0xEF and file_content[1] == 0xBB and file_content[2] == 0xBF { @@ -41,7 +41,7 @@ struct CachedFile { struct SourceCache { mut sources: []CachedFile; - public func find(self, path_: string) -> ?string { + pub func find(self, path_: string) -> ?string { for source in self.sources { if source.path == path_ { return source.content; @@ -50,7 +50,7 @@ struct SourceCache { return none; } - public func find_line(self, path_: string, line: uint) -> ?string { + pub func find_line(self, path_: string, line: uint) -> ?string { return if lines := self.find_lines(path_) { lines[line] } else { @@ -58,7 +58,7 @@ struct SourceCache { }; } - public func find_lines_between(self, path_: string, line: uint, end_line: uint) -> ?[]string { + pub func find_lines_between(self, path_: string, line: uint, end_line: uint) -> ?[]string { return if lines := self.find_lines(path_) { if lines.len > 0 and lines.len >= end_line { lines[line..end_line] @@ -70,7 +70,7 @@ struct SourceCache { }; } - public func find_lines(self, path_: string) -> ?[]string { + pub func find_lines(self, path_: string) -> ?[]string { mut i: uint := 0; while i < self.sources.len : i += 1 { cached := self.sources[i]; @@ -85,10 +85,10 @@ struct SourceCache { } } -public var mut sourceCache: SourceCache := SourceCache(); +pub var mut sourceCache: SourceCache := SourceCache(); #[inline] -public func read_file(path_: string) -> !string { +pub func read_file(path_: string) -> !string { return if res := sourceCache.find(path_) { res } else { diff --git a/lib/rivet/src/utils/maps/mod.ri b/lib/rivet/src/utils/maps/mod.ri index ff35b3658..d1bb2c222 100644 --- a/lib/rivet/src/utils/maps/mod.ri +++ b/lib/rivet/src/utils/maps/mod.ri @@ -6,15 +6,15 @@ #[boxed] struct StringUint { - public key: string; - public mut value: uint; + pub key: string; + pub mut value: uint; } #[boxed] -public struct MapStringUint { +pub struct MapStringUint { mut pairs: []mut StringUint; - public func set(mut self, key: string, value: uint) { + pub func set(mut self, key: string, value: uint) { for pair in self.pairs { if pair.key == key { pair.value = value; @@ -25,7 +25,7 @@ public struct MapStringUint { self.pairs.push(StringUint(key, value)); } - public func get(self, key: string) -> ?uint { + pub func get(self, key: string) -> ?uint { for pair in self.pairs { if pair.key == key { return pair.value; @@ -34,7 +34,7 @@ public struct MapStringUint { return none; } - public func delete(mut self, key: string) { + pub func delete(mut self, key: string) { for i, pair in self.pairs { if pair.key == key { self.pairs.delete(i); @@ -44,12 +44,12 @@ public struct MapStringUint { } #[inline] - public func contains(self, key: string) -> bool { + pub func contains(self, key: string) -> bool { return self.get(key) !is none; } #[inline] - public func len(self) -> uint { + pub func len(self) -> uint { return self.pairs.len; } } @@ -57,16 +57,16 @@ public struct MapStringUint { #[boxed] struct StringArrayOfStrings { - public key: string; - public mut value: []string; + pub key: string; + pub mut value: []string; } -public struct MapStringArrayOfStringsIterator { +pub struct MapStringArrayOfStringsIterator { ref: MapStringArrayOfStrings; mut idx: uint; #[inline] - public func next(mut self) -> ?StringArrayOfStrings { + pub func next(mut self) -> ?StringArrayOfStrings { return if self.idx < self.ref.len() { idx := self.idx; self.idx += 1; @@ -78,14 +78,14 @@ public struct MapStringArrayOfStringsIterator { } #[boxed] -public struct MapStringArrayOfStrings { +pub struct MapStringArrayOfStrings { mut pairs: []mut StringArrayOfStrings; - public func iterator(self) -> MapStringArrayOfStringsIterator { + pub func iterator(self) -> MapStringArrayOfStringsIterator { return MapStringArrayOfStringsIterator(self); } - public func set(mut self, key: string, value: []string) { + pub func set(mut self, key: string, value: []string) { for pair in self.pairs { if pair.key == key { pair.value = value; @@ -96,7 +96,7 @@ public struct MapStringArrayOfStrings { self.pairs.push(StringArrayOfStrings(key, value)); } - public func get(self, key: string) -> ?[]string { + pub func get(self, key: string) -> ?[]string { for pair in self.pairs { if pair.key == key { return pair.value; @@ -105,7 +105,7 @@ public struct MapStringArrayOfStrings { return none; } - public func delete(mut self, key: string) { + pub func delete(mut self, key: string) { for i, pair in self.pairs { if pair.key == key { self.pairs.delete(i); @@ -115,27 +115,27 @@ public struct MapStringArrayOfStrings { } #[inline] - public func contains(self, key: string) -> bool { + pub func contains(self, key: string) -> bool { return self.get(key) !is none; } #[inline] - public func len(self) -> uint { + pub func len(self) -> uint { return self.pairs.len; } } #[boxed] struct StringBool { - public key: string; - public mut value: bool; + pub key: string; + pub mut value: bool; } #[boxed] -public struct MapStringBool { +pub struct MapStringBool { mut pairs: []mut StringBool; - public func set(mut self, key: string, value: bool) { + pub func set(mut self, key: string, value: bool) { for pair in self.pairs { if pair.key == key { pair.value = value; @@ -146,7 +146,7 @@ public struct MapStringBool { self.pairs.push(StringBool(key, value)); } - public func get(self, key: string) -> ?bool { + pub func get(self, key: string) -> ?bool { for pair in self.pairs { if pair.key == key { return pair.value; @@ -155,7 +155,7 @@ public struct MapStringBool { return none; } - public func delete(mut self, key: string) { + pub func delete(mut self, key: string) { for i, pair in self.pairs { if pair.key == key { self.pairs.delete(i); @@ -165,12 +165,12 @@ public struct MapStringBool { } #[inline] - public func contains(self, key: string) -> bool { + pub func contains(self, key: string) -> bool { return self.get(key) !is none; } #[inline] - public func len(self) -> uint { + pub func len(self) -> uint { return self.pairs.len; } } diff --git a/lib/rivet/src/utils/mod.ri b/lib/rivet/src/utils/mod.ri index e79e7aafd..284310457 100644 --- a/lib/rivet/src/utils/mod.ri +++ b/lib/rivet/src/utils/mod.ri @@ -7,22 +7,22 @@ import std/console; import std/process; import std/console/styles; -public const LF: uint8 := 10; -public const CR: uint8 := 13; +pub const LF: uint8 := 10; +pub const CR: uint8 := 13; -public var mut stderrSupportStyles := styles.stderr_support_styles(); +pub var mut stderrSupportStyles := styles.stderr_support_styles(); #[inline] -public func min(a: uint, b: uint) -> uint { +pub func min(a: uint, b: uint) -> uint { return if a < b { a } else { b }; } #[inline] -public func max(a: uint, b: uint) -> uint { +pub func max(a: uint, b: uint) -> uint { return if a > b { a } else { b }; } -public func option(args: []string, param: string) -> ?string { +pub func option(args: []string, param: string) -> ?string { for i, arg in args { if param == arg { if i + 1 < args.len { @@ -34,54 +34,54 @@ public func option(args: []string, param: string) -> ?string { return none; } -public func error(msg: string, args: ...traits.Stringable) -> never { +pub func error(msg: string, args: ...traits.Stringable) -> never { console.ewriteln("{} {} {}", bold("rivet:"), bold(red("error:")), msg.fmt(args)); process.exit(1); } #[inline] -public func warn(msg: string, args: ...traits.Stringable) { +pub func warn(msg: string, args: ...traits.Stringable) { console.ewriteln("{} {} {}", bold("rivet:"), bold(yellow("warning:")), msg.fmt(args)); } #[inline] -public func info(msg: string, args: ...traits.Stringable) { +pub func info(msg: string, args: ...traits.Stringable) { console.ewriteln("{} {} {}", bold("rivet:"), bold(blue("info:")), msg.fmt(args)); } #[inline] -public func bold(msg: string) -> string { +pub func bold(msg: string) -> string { return if stderrSupportStyles { styles.bold(msg) } else { msg }; } #[inline] -public func red(msg: string) -> string { +pub func red(msg: string) -> string { return if stderrSupportStyles { styles.red(msg) } else { msg }; } #[inline] -public func yellow(msg: string) -> string { +pub func yellow(msg: string) -> string { return if stderrSupportStyles { styles.yellow(msg) } else { msg }; } #[inline] -public func cyan(msg: string) -> string { +pub func cyan(msg: string) -> string { return if stderrSupportStyles { styles.cyan(msg) } else { msg }; } #[inline] -public func blue(msg: string) -> string { +pub func blue(msg: string) -> string { return if stderrSupportStyles { styles.blue(msg) } else { msg }; } #[inline] -public func green(msg: string) -> string { +pub func green(msg: string) -> string { return if stderrSupportStyles { styles.green(msg) } else { msg }; } /// Rounds the number `n` up to the next mult /// NOTE: `multiple` must be a power of 2.#[inline] -public func round_up(n: uint, multiple: uint) -> uint { +pub func round_up(n: uint, multiple: uint) -> uint { n_ := @as(int, n); multiple_ := @as(int, multiple); return @as(uint, (n_ + multiple_ - 1) & (-multiple_)); diff --git a/lib/rivet/src/utils/name_cases.ri b/lib/rivet/src/utils/name_cases.ri index 18c9a04f7..598a47406 100644 --- a/lib/rivet/src/utils/name_cases.ri +++ b/lib/rivet/src/utils/name_cases.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public func is_snake_case(name: string) -> bool { +pub func is_snake_case(name: string) -> bool { for c in name.as_bytes() { if c == b'_' { continue; @@ -14,7 +14,7 @@ public func is_snake_case(name: string) -> bool { return true; } -public func is_camel_case(name: string) -> bool { +pub func is_camel_case(name: string) -> bool { if !name[0].is_lower() { return false; } @@ -26,7 +26,7 @@ public func is_camel_case(name: string) -> bool { return true; } -public func is_pascal_case(name: string) -> bool { +pub func is_pascal_case(name: string) -> bool { if !name[0].is_upper() { return false; } @@ -38,7 +38,7 @@ public func is_pascal_case(name: string) -> bool { return true; } -public func is_upper_case(name: string) -> bool { +pub func is_upper_case(name: string) -> bool { for c in name.as_bytes() { if c == b'_' { continue; diff --git a/lib/rivet/src/utils/smart_quote.ri b/lib/rivet/src/utils/smart_quote.ri index 551e20d3d..a08a83f46 100644 --- a/lib/rivet/src/utils/smart_quote.ri +++ b/lib/rivet/src/utils/smart_quote.ri @@ -12,7 +12,7 @@ const DOUBLE_QUOTE: uint8 := 34; var doubleEscape := "\\\\"; var invalidEscapes := b"({`."; -public func smart_quote(s: string, raw: bool := false) -> string { +pub func smart_quote(s: string, raw: bool := false) -> string { if s.len == 0 { return ""; } else if s.len < 256 { diff --git a/lib/rivet/src/utils/tokenizer.ri b/lib/rivet/src/utils/tokenizer.ri index fee9cf6f5..49eb76f76 100644 --- a/lib/rivet/src/utils/tokenizer.ri +++ b/lib/rivet/src/utils/tokenizer.ri @@ -3,11 +3,11 @@ // be found in the LICENSE file. #[inline] -public func is_name_char(ch: uint8) -> bool { +pub func is_name_char(ch: uint8) -> bool { return ch.is_letter() or ch == b'_'; } #[inline] -public func is_new_line(ch: uint8) -> bool { +pub func is_new_line(ch: uint8) -> bool { return ch == LF or ch == CR; } diff --git a/lib/rivet/src/utils/version.ri b/lib/rivet/src/utils/version.ri index 56b35937f..fc762f4f6 100644 --- a/lib/rivet/src/utils/version.ri +++ b/lib/rivet/src/utils/version.ri @@ -4,9 +4,9 @@ import std/process; -public var version := "0.1.0a"; +pub var version := "0.1.0a"; -public func last_commit_hash() -> string { +pub func last_commit_hash() -> string { if result := process.execute("git log -n 1 --pretty=format:%h") { if result.exit_code == -1 { return ""; @@ -16,7 +16,7 @@ public func last_commit_hash() -> string { return ""; } -public func full_version() -> string { +pub func full_version() -> string { return if result := process.execute("git log -n 1 --pretty=format:'%h %as'") { if result.exit_code == -1 { "Rivet ".concat(version) diff --git a/lib/std/src/backtrace/mod.ri b/lib/std/src/backtrace/mod.ri index c434883ff..9a8f0dbdc 100644 --- a/lib/std/src/backtrace/mod.ri +++ b/lib/std/src/backtrace/mod.ri @@ -5,6 +5,6 @@ import core; #[inline] -public func print(frames_to_skip: int32 = 0) { +pub func print(frames_to_skip: int32 = 0) { core.bt_print(frames_to_skip); } diff --git a/lib/std/src/console/mod.ri b/lib/std/src/console/mod.ri index 4d51ee1f5..5292a5967 100644 --- a/lib/std/src/console/mod.ri +++ b/lib/std/src/console/mod.ri @@ -5,15 +5,15 @@ import core; import c/libc; -public alias write := core.console_write; -public alias writeln := core.console_writeln; -public alias ewrite := core.console_ewrite; -public alias ewriteln := core.console_ewriteln; -public alias is_atty := core.console_is_atty; +pub alias write := core.console_write; +pub alias writeln := core.console_writeln; +pub alias ewrite := core.console_ewrite; +pub alias ewriteln := core.console_ewriteln; +pub alias is_atty := core.console_is_atty; /// Returns a one-line string from stdin, after printing a prompt. In /// the event of error (end of input) or a empty string, returns `none`. -public func readln(prompt: string := "") -> ?string { +pub func readln(prompt: string := "") -> ?string { if prompt.len > 0 { write(prompt); } diff --git a/lib/std/src/console/styles/bg.ri b/lib/std/src/console/styles/bg.ri index 7aede9de8..7f5d6fbc6 100644 --- a/lib/std/src/console/styles/bg.ri +++ b/lib/std/src/console/styles/bg.ri @@ -3,81 +3,81 @@ // be found in the LICENSE file. #[inline] -public func bg_black(msg: string) -> string { +pub func bg_black(msg: string) -> string { return fmt(msg, "40", "49"); } #[inline] -public func bg_blue(msg: string) -> string { +pub func bg_blue(msg: string) -> string { return fmt(msg, "44", "49"); } #[inline] -public func bg_cyan(msg: string) -> string { +pub func bg_cyan(msg: string) -> string { return fmt(msg, "46", "49"); } #[inline] -public func bg_green(msg: string) -> string { +pub func bg_green(msg: string) -> string { return fmt(msg, "42", "49"); } #[inline] -public func bg_magenta(msg: string) -> string { +pub func bg_magenta(msg: string) -> string { return fmt(msg, "45", "49"); } #[inline] -public func bg_red(msg: string) -> string { +pub func bg_red(msg: string) -> string { return fmt(msg, "41", "49"); } #[inline] -public func bg_white(msg: string) -> string { +pub func bg_white(msg: string) -> string { return fmt(msg, "47", "49"); } #[inline] -public func bg_yellow(msg: string) -> string { +pub func bg_yellow(msg: string) -> string { return fmt(msg, "43", "49"); } #[inline] -public func bg_bright_black(msg: string) -> string { +pub func bg_bright_black(msg: string) -> string { return fmt(msg, "100", "49"); } #[inline] -public func bg_bright_blue(msg: string) -> string { +pub func bg_bright_blue(msg: string) -> string { return fmt(msg, "104", "49"); } #[inline] -public func bg_bright_cyan(msg: string) -> string { +pub func bg_bright_cyan(msg: string) -> string { return fmt(msg, "106", "49"); } #[inline] -public func bg_bright_green(msg: string) -> string { +pub func bg_bright_green(msg: string) -> string { return fmt(msg, "102", "49"); } #[inline] -public func bg_bright_magenta(msg: string) -> string { +pub func bg_bright_magenta(msg: string) -> string { return fmt(msg, "105", "49"); } #[inline] -public func bg_bright_red(msg: string) -> string { +pub func bg_bright_red(msg: string) -> string { return fmt(msg, "101", "49"); } #[inline] -public func bg_bright_white(msg: string) -> string { +pub func bg_bright_white(msg: string) -> string { return fmt(msg, "107", "49"); } #[inline] -public func bg_bright_yellow(msg: string) -> string { +pub func bg_bright_yellow(msg: string) -> string { return fmt(msg, "103", "49"); } diff --git a/lib/std/src/console/styles/fg.ri b/lib/std/src/console/styles/fg.ri index d73a1708d..582e5b727 100644 --- a/lib/std/src/console/styles/fg.ri +++ b/lib/std/src/console/styles/fg.ri @@ -3,86 +3,86 @@ // be found in the LICENSE file. #[inline] -public func black(msg: string) -> string { +pub func black(msg: string) -> string { return fmt(msg, "30", "39"); } #[inline] -public func bright_black(msg: string) -> string { +pub func bright_black(msg: string) -> string { return fmt(msg, "90", "39"); } #[inline] -public func blue(msg: string) -> string { +pub func blue(msg: string) -> string { return fmt(msg, "34", "39"); } #[inline] -public func bright_blue(msg: string) -> string { +pub func bright_blue(msg: string) -> string { return fmt(msg, "94", "39"); } #[inline] -public func cyan(msg: string) -> string { +pub func cyan(msg: string) -> string { return fmt(msg, "36", "39"); } #[inline] -public func bright_cyan(msg: string) -> string { +pub func bright_cyan(msg: string) -> string { return fmt(msg, "96", "39"); } #[inline] -public func green(msg: string) -> string { +pub func green(msg: string) -> string { return fmt(msg, "32", "39"); } #[inline] -public func bright_green(msg: string) -> string { +pub func bright_green(msg: string) -> string { return fmt(msg, "92", "39"); } #[inline] -public func gray(msg: string) -> string { +pub func gray(msg: string) -> string { return bright_black(msg); } #[inline] -public func magenta(msg: string) -> string { +pub func magenta(msg: string) -> string { return fmt(msg, "35", "39"); } #[inline] -public func bright_magenta(msg: string) -> string { +pub func bright_magenta(msg: string) -> string { return fmt(msg, "95", "39"); } #[inline] -public func red(msg: string) -> string { +pub func red(msg: string) -> string { return fmt(msg, "31", "39"); } #[inline] -public func bright_red(msg: string) -> string { +pub func bright_red(msg: string) -> string { return fmt(msg, "91", "39"); } #[inline] -public func white(msg: string) -> string { +pub func white(msg: string) -> string { return fmt(msg, "37", "39"); } #[inline] -public func bright_white(msg: string) -> string { +pub func bright_white(msg: string) -> string { return fmt(msg, "97", "39"); } #[inline] -public func yellow(msg: string) -> string { +pub func yellow(msg: string) -> string { return fmt(msg, "33", "39"); } #[inline] -public func bright_yellow(msg: string) -> string { +pub func bright_yellow(msg: string) -> string { return fmt(msg, "93", "39"); } diff --git a/lib/std/src/console/styles/mod.ri b/lib/std/src/console/styles/mod.ri index 5866173c9..1aaee5590 100644 --- a/lib/std/src/console/styles/mod.ri +++ b/lib/std/src/console/styles/mod.ri @@ -5,81 +5,81 @@ import std/console; #[inline] -public func stdout_support_styles() -> bool { +pub func stdout_support_styles() -> bool { return console.is_atty(1); } #[inline] -public func stderr_support_styles() -> bool { +pub func stderr_support_styles() -> bool { return console.is_atty(2); } #[inline] -public func fmt(msg: string, open: string, close: string) -> string { +pub func fmt(msg: string, open: string, close: string) -> string { return "\x1b[{}m{}\x1b[{}m".fmt(open, msg, close); } #[inline] -public func fmt_rgb(r: int32, g: int32, b: int32, msg: string, open: string, close: string) -> string { +pub func fmt_rgb(r: int32, g: int32, b: int32, msg: string, open: string, close: string) -> string { return "\x1b[{};2;{};{};{}m{}\x1b[{}m".fmt(open, r, g, b, msg, close); } #[inline] -public func from_hex(hex: int32, msg: string) -> string { +pub func from_hex(hex: int32, msg: string) -> string { return fmt_rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF, msg, "38", "39"); } #[inline] -public func bg_rgb(r: int32, g: int32, b: int32, msg: string) -> string { +pub func bg_rgb(r: int32, g: int32, b: int32, msg: string) -> string { return fmt_rgb(r, g, b, msg, "48", "49"); } #[inline] -public func bg_hex(hex: int32, msg: string) -> string { +pub func bg_hex(hex: int32, msg: string) -> string { return fmt_rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF, msg, "48", "49"); } #[inline] -public func rgb(r: int32, g: int32, b: int32, msg: string) -> string { +pub func rgb(r: int32, g: int32, b: int32, msg: string) -> string { return fmt_rgb(r, g, b, msg, "38", "39"); } #[inline] -public func reset(msg: string) -> string { +pub func reset(msg: string) -> string { return fmt(msg, "0", "0"); } #[inline] -public func bold(msg: string) -> string { +pub func bold(msg: string) -> string { return fmt(msg, "1", "22"); } #[inline] -public func dim(msg: string) -> string { +pub func dim(msg: string) -> string { return fmt(msg, "2", "22"); } #[inline] -public func hidden(msg: string) -> string { +pub func hidden(msg: string) -> string { return fmt(msg, "8", "28"); } #[inline] -public func italic(msg: string) -> string { +pub func italic(msg: string) -> string { return fmt(msg, "3", "23"); } #[inline] -public func inverse(msg: string) -> string { +pub func inverse(msg: string) -> string { return fmt(msg, "7", "27"); } #[inline] -public func strikethrough(msg: string) -> string { +pub func strikethrough(msg: string) -> string { return fmt(msg, "9", "29"); } #[inline] -public func underline(msg: string) -> string { +pub func underline(msg: string) -> string { return fmt(msg, "4", "24"); } diff --git a/lib/std/src/conv/bool_to.ri b/lib/std/src/conv/bool_to.ri index 0c5653e1e..0618c6122 100644 --- a/lib/std/src/conv/bool_to.ri +++ b/lib/std/src/conv/bool_to.ri @@ -3,11 +3,11 @@ // be found in the LICENSE file. #[inline] -public func bool_to_uint(b: bool) -> uint { +pub func bool_to_uint(b: bool) -> uint { return if b { 1 } else { 0 }; } #[inline] -public func bool_to_int(b: bool) -> int { +pub func bool_to_int(b: bool) -> int { return if b { 1 } else { 0 }; } diff --git a/lib/std/src/conv/parse_int.ri b/lib/std/src/conv/parse_int.ri index 387ea9540..2ad9771b2 100644 --- a/lib/std/src/conv/parse_int.ri +++ b/lib/std/src/conv/parse_int.ri @@ -4,10 +4,10 @@ import std/errors; -public alias InvalidSyntaxError := errors.InvalidSyntaxError; -public alias InvalidBaseError := errors.InvalidBaseError; -public alias InvalidBitSizeError := errors.InvalidBitSizeError; -public alias ValueOutOfRangeError := errors.ValueOutOfRangeError; +pub alias InvalidSyntaxError := errors.InvalidSyntaxError; +pub alias InvalidBaseError := errors.InvalidBaseError; +pub alias InvalidBitSizeError := errors.InvalidBitSizeError; +pub alias ValueOutOfRangeError := errors.ValueOutOfRangeError; const INT_SIZE: uint32 := #if _x64_ 64 #else 32 #endif; @@ -18,7 +18,7 @@ func lower(c: uint8) -> uint8 { /// This is like `parse_int` but for unsigned numbers. /// A sign prefix is not permitted. -public func parse_uint(s_: string, mut base: int32, mut bit_size: uint32) -> !uint { +pub func parse_uint(s_: string, mut base: int32, mut bit_size: uint32) -> !uint { if s_ == "" { throw InvalidSyntaxError("empty string"); } @@ -137,7 +137,7 @@ public func parse_uint(s_: string, mut base: int32, mut bit_size: uint32) -> !ui /// The `bit_size` argument specifies the integer type that the result must /// fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int8, int16, int32, and /// int. If `bit_size` is below 0 or above 64, an error is returned. -public func parse_int(s: string, base: int32, mut bit_size: uint32) -> !int { +pub func parse_int(s: string, base: int32, mut bit_size: uint32) -> !int { if s == "" { throw InvalidSyntaxError("invalid syntax"); } diff --git a/lib/std/src/conv/string_to.ri b/lib/std/src/conv/string_to.ri index 4ffc46143..4c9eb03a1 100644 --- a/lib/std/src/conv/string_to.ri +++ b/lib/std/src/conv/string_to.ri @@ -3,66 +3,66 @@ // be found in the LICENSE file. #[inline] -public func string_to_bool(s: string) -> bool { +pub func string_to_bool(s: string) -> bool { return s == "true"; } /// Equivalent to `parse_int(s, 0, 8)`, converted to type `int8`. #[inline] -public func string_to_int8(s: string) -> !int8 { +pub func string_to_int8(s: string) -> !int8 { return @as(int8, parse_int(s, 0, 8)!); } /// Equivalent to `parse_int(s, 0, 16)`, converted to type `int16`. #[inline] -public func string_to_int16(s: string) -> !int16 { +pub func string_to_int16(s: string) -> !int16 { return @as(int16, parse_int(s, 0, 16)!); } /// Equivalent to `parse_int(s, 0, 32)`, converted to type `int32`. #[inline] -public func string_to_int32(s: string) -> !int32 { +pub func string_to_int32(s: string) -> !int32 { return @as(int32, parse_int(s, 0, 32)!); } /// Equivalent to `parse_int(s, 0, 64)`, converted to type `int64`. #[inline] -public func string_to_int64(s: string) -> !int64 { +pub func string_to_int64(s: string) -> !int64 { return @as(int64, parse_int(s, 0, 64)!); } /// Equivalent to `parse_int(s, 0, int.bits())`, converted to type `int`. #[inline] -public func string_to_int(s: string) -> !int { +pub func string_to_int(s: string) -> !int { return parse_int(s, 0, int.bits())!; } /// Equivalent to `parse_uint(s, 0, 8)`, converted to type `uint8`. #[inline] -public func string_to_uint8(s: string) -> !uint8 { +pub func string_to_uint8(s: string) -> !uint8 { return @as(uint8, parse_uint(s, 0, 8)!); } /// Equivalent to `parse_uint(s, 0, 16)`, converted to type `uint16`. #[inline] -public func string_to_uint16(s: string) -> !uint16 { +pub func string_to_uint16(s: string) -> !uint16 { return @as(uint16, parse_uint(s, 0, 16)!); } /// Equivalent to `parse_uint(s, 0, 32)`, converted to type `uint32`. #[inline] -public func string_to_uint32(s: string) -> !uint32 { +pub func string_to_uint32(s: string) -> !uint32 { return @as(uint32, parse_uint(s, 0, 32)!); } /// Equivalent to `parse_uint(s, 0, 64)`, converted to type `uint64`. #[inline] -public func string_to_uint64(s: string) -> !uint64 { +pub func string_to_uint64(s: string) -> !uint64 { return @as(uint64, parse_uint(s, 0, 64)!); } /// Equivalent to `parse_uint(s, 0, uint.bits())`, converted to type `uint`. #[inline] -public func string_to_uint(s: string) -> !uint { +pub func string_to_uint(s: string) -> !uint { return parse_uint(s, 0, uint.bits())!; } diff --git a/lib/std/src/dynlib/mod.ri b/lib/std/src/dynlib/mod.ri index b05f5c482..fe3f2493c 100644 --- a/lib/std/src/dynlib/mod.ri +++ b/lib/std/src/dynlib/mod.ri @@ -8,12 +8,12 @@ import c/libc; -public var sharedLibExtension := get_shared_library_extension(); +pub var sharedLibExtension := get_shared_library_extension(); /// Returns a library name with the operating system specific extension for shared /// libraries. #[inline] -public func library_name(libname: string) -> string { +pub func library_name(libname: string) -> string { return if libname.ends_with(sharedLibExtension) { libname } else { @@ -22,24 +22,24 @@ public func library_name(libname: string) -> string { } #[boxed] -public struct SymbolNotFoundError < Throwable { +pub struct SymbolNotFoundError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct CannotLoadLibraryError < Throwable { +pub struct CannotLoadLibraryError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } -public func load(path: string, global_symbols: bool = false) -> !Library { +pub func load(path: string, global_symbols: bool = false) -> !Library { flags := if global_symbols { libc.RTLD_NOW | libc.RTLD_GLOBAL } else { libc.RTLD_NOW }; if ptr := unsafe { libc.dlopen(path.ptr, flags) } { return Library(path, ptr); @@ -53,10 +53,10 @@ public func load(path: string, global_symbols: bool = false) -> !Library { #[boxed] struct Library { - public path: string; + pub path: string; ptr: rawptr; - public func address_of(self, symbol: string) -> !rawptr { + pub func address_of(self, symbol: string) -> !rawptr { if ptr := unsafe { libc.dlsym(self.ptr, symbol.ptr) } { return ptr; } @@ -70,12 +70,12 @@ struct Library { } #[inline] - public func exists(self, symbol: string) -> bool { + pub func exists(self, symbol: string) -> bool { return if _ := self.address_of(symbol) { true } else { false }; } #[inline] - public func close(self) { + pub func close(self) { _ = unsafe { libc.dlclose(self.ptr) }; } diff --git a/lib/std/src/env/mod.ri b/lib/std/src/env/mod.ri index af95fa640..ed879d32a 100644 --- a/lib/std/src/env/mod.ri +++ b/lib/std/src/env/mod.ri @@ -6,17 +6,17 @@ import core; import c/libc; /// User's home directory. -public var homeDir := get(#if _LINUX_ "HOME" #else "USERPROFILE" #endif) ?? ""; +pub var homeDir := get(#if _LINUX_ "HOME" #else "USERPROFILE" #endif) ?? ""; /// Returns `true` if the environment variable exists. #[inline] -public func exists(name: string) -> bool { +pub func exists(name: string) -> bool { return get(name) !is none; } /// Returns the value of the environment variable named by the key. #[inline] -public func get(name: string) -> ?string { +pub func get(name: string) -> ?string { return unsafe { if s := libc.getenv(name.ptr) { string.from_raw(s) @@ -27,14 +27,14 @@ public func get(name: string) -> ?string { } /// Sets the value of an environment variable with `name` to `value`. -public func set(name: string, value: string, overwrite: bool := true) -> ! { +pub func set(name: string, value: string, overwrite: bool := true) -> ! { if unsafe { libc.setenv(name.ptr, value.ptr, overwrite) == -1 } { throw core.last_errno_error(); } } /// Removes an environment variable with `name`. -public func remove(name: string) -> ! { +pub func remove(name: string) -> ! { if unsafe { libc.unsetenv(name.ptr) } == -1 { throw core.last_errno_error(); } diff --git a/lib/std/src/errors/mod.ri b/lib/std/src/errors/mod.ri index 3dd2fbea4..23ded42f6 100644 --- a/lib/std/src/errors/mod.ri +++ b/lib/std/src/errors/mod.ri @@ -5,41 +5,41 @@ import c; import core; -public alias ErrnoError := c.ErrnoError; -public alias OutOfMemoryError := core.OutOfMemoryError; +pub alias ErrnoError := c.ErrnoError; +pub alias OutOfMemoryError := core.OutOfMemoryError; #[boxed] -public struct InvalidSyntaxError < Throwable { +pub struct InvalidSyntaxError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct InvalidBaseError < Throwable { +pub struct InvalidBaseError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct InvalidBitSizeError < Throwable { +pub struct InvalidBitSizeError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct ValueOutOfRangeError < Throwable { +pub struct ValueOutOfRangeError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } diff --git a/lib/std/src/flag/errors.ri b/lib/std/src/flag/errors.ri index f6f643d7d..7c28e8571 100644 --- a/lib/std/src/flag/errors.ri +++ b/lib/std/src/flag/errors.ri @@ -4,19 +4,19 @@ import ../traits; -public struct UnknownFlagError < Throwable { +pub struct UnknownFlagError < Throwable { flag: string; - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return "unknown flag `{}`".fmt(self.flag); } } -public struct ArgsCountError < Throwable { +pub struct ArgsCountError < Throwable { got: uint; want: uint; - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return if self.want == 0 { "expected no arguments, but got {}".fmt(self.got) } else if self.got > self.want { @@ -28,15 +28,15 @@ public struct ArgsCountError < Throwable { } #[boxed] -public struct GenericError < Throwable { +pub struct GenericError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } // TODO: Remove this function and use a more specific type. -public func error(msg: string, args: ...traits.Stringable) -> Throwable { +pub func error(msg: string, args: ...traits.Stringable) -> Throwable { return GenericError(msg.fmt(args)); } diff --git a/lib/std/src/flag/mod.ri b/lib/std/src/flag/mod.ri index 9b4efa284..4fba78d7d 100644 --- a/lib/std/src/flag/mod.ri +++ b/lib/std/src/flag/mod.ri @@ -8,11 +8,11 @@ import ../strings; import ../console; import ../process; -public const MAX_ARGS_NUMBER := 4048; -public var space := " "; +pub const MAX_ARGS_NUMBER := 4048; +pub var space := " "; /// Data object storing information about a defined flag. -public struct Flag < traits.Stringable { +pub struct Flag < traits.Stringable { /// Name as it appears on command line. name: string; @@ -26,7 +26,7 @@ public struct Flag < traits.Stringable { /// default value, when the flag is not given. value_desc: string; - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return "flag: name: {} abbr: {} @@ -41,7 +41,7 @@ public struct Flag < traits.Stringable { /// call `rest := parser.finalize()!` to get the rest of the non optional arguments /// (if there are any left). #[boxed] -public struct FlagParser { +pub struct FlagParser { /// The original arguments to be parsed. original_args: []string; /// The index of a `--`, `none` if there is not any. @@ -72,7 +72,7 @@ public struct FlagParser { mut footers: []string; /// Create a new flag parser for the given args. - public func new(args: []string) -> Self { + pub func new(args: []string) -> Self { original_args := args.clone(); mut all_before_dashdash := args.clone(); mut all_after_dashdash := @vec(string); @@ -94,19 +94,19 @@ public struct FlagParser { /// Set the application name to be used in 'usage' output. #[inline] - public func set_application_name(mut self, name: string) { + pub func set_application_name(mut self, name: string) { self.application_name = name; } /// Set the application short description to be used in 'usage' output. #[inline] - public func set_application_short_description(mut self, desc: string) { + pub func set_application_short_description(mut self, desc: string) { self.application_short_description = desc; } /// Appends to the application description lines, shown in the help/usage screen. #[inline] - public func add_description(mut self, desc: string) { + pub func add_description(mut self, desc: string) { self.application_description = if self.application_description.is_empty() { desc } else { @@ -116,21 +116,21 @@ public struct FlagParser { /// Set the application version to be used in 'usage' output. #[inline] - public func set_version(mut self, version: string) { + pub func set_version(mut self, version: string) { self.application_version = version; } /// Sets the description field of the parser. This field is usually shown when the /// `--help` option is given to the program. #[inline] - public func set_arguments_description(mut self, description: string) { + pub func set_arguments_description(mut self, description: string) { self.args_description = description; } /// Restricts the list of free arguments (non options) to be at least `n` in length. /// If the user gives less free arguments to the program, the parser will return an /// error. - public func set_limit_free_args_to_at_least(mut self, n: uint) -> ! { + pub func set_limit_free_args_to_at_least(mut self, n: uint) -> ! { if n > MAX_ARGS_NUMBER { throw error("expects `n` to be smaller than {}", MAX_ARGS_NUMBER); } @@ -140,7 +140,7 @@ public struct FlagParser { /// Restricts the list of free arguments (non options) to be at exactly `n` in length. /// If the user gives more or less free arguments to the program, the parser will return /// an error. - public func set_limit_free_args_to_exactly(mut self, n: uint) -> ! { + pub func set_limit_free_args_to_exactly(mut self, n: uint) -> ! { if n > MAX_ARGS_NUMBER { throw error("expects `n` to be smaller than {}", MAX_ARGS_NUMBER); } @@ -151,7 +151,7 @@ public struct FlagParser { /// Restricts the list of free arguments (non options) to be between `min` and `max` /// in length. If the user gives more or less free arguments to the program, the parser /// will return an error. - public func set_limit_free_args(mut self, min: uint, max: uint) -> ! { + pub func set_limit_free_args(mut self, min: uint, max: uint) -> ! { if min > max { throw error("expects `min` < `max`, got {} >= {}", min, max); } @@ -163,19 +163,19 @@ public struct FlagParser { /// do not give any examples, then a default usage will be shown, based on whether /// the application takes options and expects additional parameters. #[inline] - public func add_usage_example(mut self, example: string) { + pub func add_usage_example(mut self, example: string) { self.usage_examples.push(example); } /// Add a footnote, that will be shown at the bottom of the help screen. #[inline] - public func add_footer(mut self, footer: string) { + pub func add_footer(mut self, footer: string) { self.footers.push(footer); } /// In most cases you do not need the first argument for flag parsing. #[inline] - public func skip_executable(mut self) { + pub func skip_executable(mut self) { self.args.delete(0); } @@ -184,13 +184,13 @@ public struct FlagParser { /// not known to your parent program), will not cause the validation in `.finalize()` /// to fail. #[inline] - public func allow_unknown_args(mut self) { + pub func allow_unknown_args(mut self) { self.allow_unknown_args = true; } /// Returns an option with the bool value of the given command line flag, named `name`. /// When the flag is not given by the user, it returns `none`. - public func bool_flag(mut self, name: string, abbr: uint8, usage: string) -> ?bool { + pub func bool_flag(mut self, name: string, abbr: uint8, usage: string) -> ?bool { self.add_flag(name, abbr, usage, ""); if parsed := self.parse_bool_value(name, abbr) { return parsed == "true"; @@ -200,7 +200,7 @@ public struct FlagParser { /// Returns an option with the integer value, associated with the flag in `name`. /// When the flag is not given by the user, it returns `none`. - public func int_flag(mut self, name: string, abbr: uint8, usage: string) -> ?int { + pub func int_flag(mut self, name: string, abbr: uint8, usage: string) -> ?int { self.add_flag(name, abbr, usage, ""); parsed := self.parse_value(name, abbr); if parsed.is_empty() { @@ -211,7 +211,7 @@ public struct FlagParser { /// Returns an option with the string value, associated with the flag in `name`. /// When the flag is not given by the user, it returns `none`. - public func string_flag(mut self, name: string, abbr: uint8, usage: string) -> ?string { + pub func string_flag(mut self, name: string, abbr: uint8, usage: string) -> ?string { self.add_flag(name, abbr, usage, ""); parsed := self.parse_value(name, abbr); if parsed.is_empty() { @@ -223,7 +223,7 @@ public struct FlagParser { /// Returns a nicely formatted usage screen, containing all the possible options, as /// well as the description for the program. That screen is usually shown when the /// `--help` option is given to the program. - public func usage(self) -> string { + pub func usage(self) -> string { positive_min_arg := self.min_free_args > 0; positive_max_arg := self.max_free_args > 0 and self.max_free_args != MAX_ARGS_NUMBER; no_arguments := self.min_free_args == 0 and self.max_free_args == 0; @@ -323,7 +323,7 @@ public struct FlagParser { /// command line. If additional flags are found, i.e. (things starting with `--` or /// `-`), it returns an error. /// Call .finalize() after all arguments are defined. - public func finalize(mut self) -> ![]string { + pub func finalize(mut self) -> ![]string { self.handle_builtin_options(); mut remaining := self.args.clone(); if !self.allow_unknown_args { @@ -353,7 +353,7 @@ public struct FlagParser { /// program needs. `.remaining_parameters()` will also print any parsing errors and /// stop the program. Use `.finalize()` instead, if you want more control over the /// error handling. - public func remaining_parameters(mut self) -> []string { + pub func remaining_parameters(mut self) -> []string { return self.finalize() catch |err| { console.writeln(self.usage()); console.ewriteln(err.to_string()); @@ -486,7 +486,7 @@ public struct FlagParser { } } -public func index_of(vec: []string, value: string) -> ?uint { +pub func index_of(vec: []string, value: string) -> ?uint { for i, val in vec { if val == value { return i; diff --git a/lib/std/src/fs/Directory.ri b/lib/std/src/fs/Directory.ri index 27a1a3dfb..abac9b99b 100644 --- a/lib/std/src/fs/Directory.ri +++ b/lib/std/src/fs/Directory.ri @@ -8,43 +8,43 @@ import c/libc; import ../env; #[boxed] -public struct CannotMakeDirectoryError < Throwable { +pub struct CannotMakeDirectoryError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct CannotMakeFileError < Throwable { +pub struct CannotMakeFileError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct CouldNotOpenDirectoryError < Throwable { +pub struct CouldNotOpenDirectoryError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct EmptyStringError < Throwable { +pub struct EmptyStringError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } -public struct Directory { - public func make(path_: string, mode: uint := 0o777) -> ! { +pub struct Directory { + pub func make(path_: string, mode: uint := 0o777) -> ! { if path_ == "." { return; } @@ -56,14 +56,14 @@ public struct Directory { } } - public func remove(dir: string) -> ! { + pub func remove(dir: string) -> ! { rpath := Path.resolve(dir)!; if unsafe { libc.rmdir(rpath.ptr) == -1 } { throw CannotMakeFileError("cannot remove directory `{}`: {}".fmt(dir, c.errno_msg())); } } - public func tmp_dir() -> string { + pub func tmp_dir() -> string { return if path := env.get("TMPDIR") { path } else { @@ -71,7 +71,7 @@ public struct Directory { }; } - public func walk(path_: string, ext: string := "") -> ![]string { + pub func walk(path_: string, ext: string := "") -> ![]string { if path_.is_empty() { throw EmptyStringError("`Directory.walk` expects a folder, not an empty string"); } diff --git a/lib/std/src/fs/File.ri b/lib/std/src/fs/File.ri index 286722641..9554c5395 100644 --- a/lib/std/src/fs/File.ri +++ b/lib/std/src/fs/File.ri @@ -8,20 +8,20 @@ import ../mem; import { Stringable } from ../traits; #[boxed] -public struct OperationFailedError < Throwable { +pub struct OperationFailedError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } #[boxed] -public struct File { +pub struct File { f: &mut libc.FILE; mut is_opened: bool; - public func open(path: string, mode: string := "r") -> !File { + pub func open(path: string, mode: string := "r") -> !File { unsafe { if f := libc.fopen(path.ptr, mode.ptr) { return Self(f, true); @@ -32,7 +32,7 @@ public struct File { /// Writes the byte `b` into the file. #[inline] - public func write_byte(mut self, b: uint8) { + pub func write_byte(mut self, b: uint8) { @ignore_not_mutated_warn(self); unsafe { _ = libc.fputc(@as(int32, b), self.f); @@ -41,7 +41,7 @@ public struct File { /// Writes the string `s` into the file. #[inline] - public func write_string(mut self, s: string) { + pub func write_string(mut self, s: string) { @ignore_not_mutated_warn(self); unsafe { _ = libc.fputs(s.ptr, self.f); @@ -49,23 +49,23 @@ public struct File { } /// Writes the string `s` into the file and appends a '\n' character. - public func writeln(mut self, s: string) { + pub func writeln(mut self, s: string) { self.write_string(s); self.write_byte(b'\n'); } #[inline] - public func write_string_fmt(mut self, s: string, args: ...Stringable) { + pub func write_string_fmt(mut self, s: string, args: ...Stringable) { self.write_string(s.fmt(args)); } - public func writeln_fmt(mut self, s: string, args: ...Stringable) { + pub func writeln_fmt(mut self, s: string, args: ...Stringable) { self.write_string(s.fmt(args)); self.write_byte(b'\n'); } /// Returns the current file contents. - public func read_all(self) -> !string { + pub func read_all(self) -> !string { if !self.is_opened { return ""; } @@ -106,12 +106,12 @@ public struct File { /// Returns true if the file is at end. #[inline] - public func is_eof(self) -> bool { + pub func is_eof(self) -> bool { return unsafe { libc.feof(self.f) != 0 }; } /// Closes the current file. - public func close(mut self) { + pub func close(mut self) { if !self.is_opened { return; } diff --git a/lib/std/src/fs/Path.ri b/lib/std/src/fs/Path.ri index be97794b2..d1974efc8 100644 --- a/lib/std/src/fs/Path.ri +++ b/lib/std/src/fs/Path.ri @@ -8,44 +8,44 @@ import core; import ../mem; import ../conv; -public struct Path { - public alias MAX_LEN := libc.MAX_PATH_LEN; - public const SEPARATOR := #if _WINDOWS_ b'\\' #else b'/' #endif; - public var separatorStr := #if _WINDOWS_ "\\" #else "/" #endif; - public var delimiter := #if _WINDOWS_ ";" #else ":" #endif; +pub struct Path { + pub alias MAX_LEN := libc.MAX_PATH_LEN; + pub const SEPARATOR := #if _WINDOWS_ b'\\' #else b'/' #endif; + pub var separatorStr := #if _WINDOWS_ "\\" #else "/" #endif; + pub var delimiter := #if _WINDOWS_ ";" #else ":" #endif; /// Returns `true` if the given byte is a valid path separator #[inline] - public func is_separator(byte: uint8) -> bool { + pub func is_separator(byte: uint8) -> bool { return byte == SEPARATOR; } /// Returns `true` if `path` (file or directory) exists. #[inline] - public func exists(path: string) -> bool { + pub func exists(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.O_RDONLY) == 0 }; } /// Returns `true` if `path` is executable. #[inline] - public func is_executable(path: string) -> bool { + pub func is_executable(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.X_OK) == 0 }; } /// Returns `true` if `path` is writable. #[inline] - public func is_writable(path: string) -> bool { + pub func is_writable(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.W_OK) == 0 }; } /// Returns `true` if `path` is readable. #[inline] - public func is_readable(path: string) -> bool { + pub func is_readable(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.R_OK) == 0 }; } /// Returns `true` if `path` is a directory. - public func is_directory(path: string) -> bool { + pub func is_directory(path: string) -> bool { mut statbuf := libc.Stat(); return if unsafe { libc.stat(path.ptr, &mut statbuf) == 0 } { @as(int32, statbuf.mode) & libc.S_IFMT == libc.S_IFDIR @@ -56,18 +56,18 @@ public struct Path { /// Returns `true` if `path` is a file. #[inline] - public func is_file(path: string) -> bool { + pub func is_file(path: string) -> bool { return Self.exists(path) and !Self.is_directory(path); } /// Returns `true` if `path` is absolute. #[inline] - public func is_absolute(path: string) -> bool { + pub func is_absolute(path: string) -> bool { return path.len > 0 and path[0] == SEPARATOR; } /// Returns a boolean indicating whether `path` is a link. - public func is_link(path: string) -> bool { + pub func is_link(path: string) -> bool { mut statbuf := libc.Stat(); return if unsafe { libc.lstat(path.ptr, &mut statbuf) != 0 } { false @@ -81,7 +81,7 @@ public struct Path { /// If the path is a file in the current directory (no directory component) /// then returns `.`. /// If the path is the root directory, returns `/`. - public func dir_name(path: string) -> ?string { + pub func dir_name(path: string) -> ?string { if path.is_empty() { return none; } @@ -111,7 +111,7 @@ public struct Path { /// Returns the last element of path. Trailing path separators are removed before /// extracting the last element. If the path is empty, base returns ".". If the /// path consists entirely of separators, base returns a single separator. - public func base_name(path: string) -> string { + pub func base_name(path: string) -> string { if path.is_empty() { return ""; } @@ -133,7 +133,7 @@ public struct Path { /// Return alls characters found after the last occurrence of `separatorStr`. /// File extension is included. - public func file_name(path: string) -> string { + pub func file_name(path: string) -> string { return path.all_after_of_last(separatorStr); } @@ -142,7 +142,7 @@ public struct Path { /// return the text after the `.`. /// Files that end with `.`, or that start with `.` and have no other `.` in their /// name, are considered to have no extension. - public func extension(path: string) -> string { + pub func extension(path: string) -> string { filename := Self.file_name(path); index := filename.last_index_of_byte(b'.') ?? return ""; return if index == 0 or index + 1 >= filename.len { @@ -157,7 +157,7 @@ public struct Path { /// The result does not have a trailing path separator. /// If all paths are relative it uses the current working directory as a starting /// point. - public func resolve(paths: ...string) -> !string { + pub func resolve(paths: ...string) -> !string { if paths.len == 0 { return core.process_get_cwd()!; } @@ -234,7 +234,7 @@ public struct Path { /// Returns the relative path from `from_` to `to`. If `from` and `to` each /// resolve to the same path (after calling `resolve` on each), a zero-length /// string is returned. - public func relative(from_: string, to: string) -> !string { + pub func relative(from_: string, to: string) -> !string { _ = Self.resolve(from_)!; _ = Self.resolve(to)!; mut from_it := from_.tokenize(SEPARATOR); @@ -284,7 +284,7 @@ public struct Path { return ""; } - public func join(paths: ...string) -> !string { + pub func join(paths: ...string) -> !string { if paths.len == 0 { return ""; } @@ -365,7 +365,7 @@ public struct Path { /// Joins the current working directory with the given `path` (if the `path` is relative) /// and returns the absolute path representation. - public func absolute(path: string) -> !string { + pub func absolute(path: string) -> !string { cwd := core.process_get_cwd()!; if path.is_empty() { return cwd; diff --git a/lib/std/src/fs/mod.ri b/lib/std/src/fs/mod.ri index 1a59367ed..2e204c3e4 100644 --- a/lib/std/src/fs/mod.ri +++ b/lib/std/src/fs/mod.ri @@ -3,7 +3,7 @@ // be found in the LICENSE file. /// Reads the file in `path` and returns the contents. -public func read_file(path: string) -> !string { +pub func read_file(path: string) -> !string { mut f := File.open(path, "rb")!; res := f.read_all()!; f.close(); @@ -11,7 +11,7 @@ public func read_file(path: string) -> !string { } /// Writes `text` data to a file in `path`. -public func write_file(path: string, text: string) -> ! { +pub func write_file(path: string, text: string) -> ! { mut f := File.open(path, "wb")!; f.write_string(text); f.close(); diff --git a/lib/std/src/hash/fnv1a/mod.ri b/lib/std/src/hash/fnv1a/mod.ri index e3a013707..4be85c972 100644 --- a/lib/std/src/hash/fnv1a/mod.ri +++ b/lib/std/src/hash/fnv1a/mod.ri @@ -14,7 +14,7 @@ const FNV64_OFFSET_BASIS: uint64 := 14695981039346656037; /// Returns a fnv1a hash of the memory block, described by the dynamic /// byte array `data`. #[inline] -public func sum32(data: []uint8) -> uint32 { +pub func sum32(data: []uint8) -> uint32 { mut hash := FNV32_OFFSET_BASIS; mut i: uint := 0; while i < data.len : i += 1 { @@ -26,7 +26,7 @@ public func sum32(data: []uint8) -> uint32 { /// Returns a fnv1a hash of `data_len` bytes starting at /// the address in the given &byte pointer `data`. #[inline; unsafe] -public func sum32_bytes(data: [&]uint8, data_len: uint) -> uint32 { +pub func sum32_bytes(data: [&]uint8, data_len: uint) -> uint32 { mut hash := FNV32_OFFSET_BASIS; mut i: uint := 0; while i < data_len : i += 1 { @@ -37,7 +37,7 @@ public func sum32_bytes(data: [&]uint8, data_len: uint) -> uint32 { /// Returns a fnv1a hash of the string, described by `data` #[inline] -public func sum32_string(data: string) -> uint32 { +pub func sum32_string(data: string) -> uint32 { mut hash := FNV32_OFFSET_BASIS; mut i: uint := 0; while i < data.len : i += 1 { @@ -49,7 +49,7 @@ public func sum32_string(data: string) -> uint32 { /// Returns a fnv1a hash of the memory block, described by the dynamic /// byte array `data`. #[inline] -public func sum64(data: []uint8) -> uint64 { +pub func sum64(data: []uint8) -> uint64 { mut hash := FNV64_OFFSET_BASIS; mut i: uint := 0; while i < data.len : i += 1 { @@ -61,7 +61,7 @@ public func sum64(data: []uint8) -> uint64 { /// Returns a fnv1a hash of `data_len` bytes starting at /// the address in the given &byte pointer `data`. #[inline; unsafe] -public func sum64_bytes(data: [&]uint8, data_len: uint) -> uint64 { +pub func sum64_bytes(data: [&]uint8, data_len: uint) -> uint64 { mut hash := FNV64_OFFSET_BASIS; mut i: uint := 0; while i < data_len : i += 1 { @@ -72,7 +72,7 @@ public func sum64_bytes(data: [&]uint8, data_len: uint) -> uint64 { /// Returns a fnv1a hash of the string, described by `data` #[inline] -public func sum64_string(data: string) -> uint64 { +pub func sum64_string(data: string) -> uint64 { mut hash := FNV64_OFFSET_BASIS; mut i: uint := 0; while i < data.len : i += 1 { diff --git a/lib/std/src/hash/mod.ri b/lib/std/src/hash/mod.ri index c5a61b8ab..957136741 100644 --- a/lib/std/src/hash/mod.ri +++ b/lib/std/src/hash/mod.ri @@ -2,5 +2,5 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public import fnv1a; -public import wyhash; +pub import fnv1a; +pub import wyhash; diff --git a/lib/std/src/hash/wyhash/mod.ri b/lib/std/src/hash/wyhash/mod.ri index 0d74d0c58..c66beb6aa 100644 --- a/lib/std/src/hash/wyhash/mod.ri +++ b/lib/std/src/hash/wyhash/mod.ri @@ -4,5 +4,5 @@ import core; -public alias sum64 := core.sum64; -public alias sum64_string := core.sum64_string; +pub alias sum64 := core.sum64; +pub alias sum64_string := core.sum64_string; diff --git a/lib/std/src/lib.ri b/lib/std/src/lib.ri index dca9fbe32..17e7ecf35 100644 --- a/lib/std/src/lib.ri +++ b/lib/std/src/lib.ri @@ -2,19 +2,19 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public import std/backtrace; -public import std/console; -public import std/conv; -public import std/dynlib; -public import std/env; -public import std/errors; -public import std/flag; -public import std/fs; -public import std/hash; -public import std/math; -public import std/mem; -public import std/process; -public import std/semver; -public import std/strings; -public import std/sys; -public import std/traits; +pub import std/backtrace; +pub import std/console; +pub import std/conv; +pub import std/dynlib; +pub import std/env; +pub import std/errors; +pub import std/flag; +pub import std/fs; +pub import std/hash; +pub import std/math; +pub import std/mem; +pub import std/process; +pub import std/semver; +pub import std/strings; +pub import std/sys; +pub import std/traits; diff --git a/lib/std/src/math/mod.ri b/lib/std/src/math/mod.ri index fc1a236e0..17d90e1ca 100644 --- a/lib/std/src/math/mod.ri +++ b/lib/std/src/math/mod.ri @@ -2,24 +2,24 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public const E: float64 := 2.71828182845904523536028747135266249775724709369995957496696763; -public const PI: float64 := 3.14159265358979323846264338327950288419716939937510582097494459; -public const PI_2: float64 := PI / 2.0; -public const PI_4: float64 := PI / 4.0; -public const PHI: float64 := 1.61803398874989484820458683436563811772030917980576286213544862; -public const TAU: float64 := 6.28318530717958647692528676655900576839433879875021164194988918; -public const SQRT2: float64 := 1.41421356237309504880168872420969807856967187537694807317667974; -public const SQRT_E: float64 := 1.64872127070012814684865078781416357165377610071014801157507931; -public const SQRT_PI: float64 := 1.77245385090551602729816748334114518279754945612238712821380779; -public const SQRT_TAU: float64 := 2.50662827463100050241576528481104525300698674060993831662992357; -public const SQRT_PHI: float64 := 1.27201964951406896425242246173749149171560804184009624861664038; -public const LN2: float64 := 0.693147180559945309417232121458176568075500134360255254120680009; -public const LOG2_E: float64 := 1.0 / LN2; -public const LN10: float64 := 2.30258509299404568401799145468436420760110148862877297603332790; -public const LOG10_E: float64 := 1.0 / LN10; +pub const E: float64 := 2.71828182845904523536028747135266249775724709369995957496696763; +pub const PI: float64 := 3.14159265358979323846264338327950288419716939937510582097494459; +pub const PI_2: float64 := PI / 2.0; +pub const PI_4: float64 := PI / 4.0; +pub const PHI: float64 := 1.61803398874989484820458683436563811772030917980576286213544862; +pub const TAU: float64 := 6.28318530717958647692528676655900576839433879875021164194988918; +pub const SQRT2: float64 := 1.41421356237309504880168872420969807856967187537694807317667974; +pub const SQRT_E: float64 := 1.64872127070012814684865078781416357165377610071014801157507931; +pub const SQRT_PI: float64 := 1.77245385090551602729816748334114518279754945612238712821380779; +pub const SQRT_TAU: float64 := 2.50662827463100050241576528481104525300698674060993831662992357; +pub const SQRT_PHI: float64 := 1.27201964951406896425242246173749149171560804184009624861664038; +pub const LN2: float64 := 0.693147180559945309417232121458176568075500134360255254120680009; +pub const LOG2_E: float64 := 1.0 / LN2; +pub const LN10: float64 := 2.30258509299404568401799145468436420760110148862877297603332790; +pub const LOG10_E: float64 := 1.0 / LN10; /// Returns the number of digits in the number passed. -public func count_digits(number: int64) -> int32 { +pub func count_digits(number: int64) -> int32 { if number == 0 { return 1; } diff --git a/lib/std/src/mem/mod.ri b/lib/std/src/mem/mod.ri index 2d017fcac..b2ca6be52 100644 --- a/lib/std/src/mem/mod.ri +++ b/lib/std/src/mem/mod.ri @@ -4,12 +4,12 @@ import core; -public alias alloc := core.mem_alloc; -public alias zeroed := core.mem_zeroed; -public alias resize := core.mem_resize; -public alias set := core.mem_set; -public alias copy := core.mem_copy; -public alias move := core.mem_move; -public alias dup := core.mem_dup; -public alias cmp := core.mem_cmp; -public alias dealloc := core.mem_dealloc; +pub alias alloc := core.mem_alloc; +pub alias zeroed := core.mem_zeroed; +pub alias resize := core.mem_resize; +pub alias set := core.mem_set; +pub alias copy := core.mem_copy; +pub alias move := core.mem_move; +pub alias dup := core.mem_dup; +pub alias cmp := core.mem_cmp; +pub alias dealloc := core.mem_dealloc; diff --git a/lib/std/src/process/mod.ri b/lib/std/src/process/mod.ri index 54619b290..137b26be5 100644 --- a/lib/std/src/process/mod.ri +++ b/lib/std/src/process/mod.ri @@ -8,27 +8,27 @@ import core; import { Path} from ../fs; import { Builder } from ../strings; -public alias id := core.process_id; -public alias panic := core.process_panic; -public alias abort := core.process_abort; -public alias exit := core.process_exit; -public alias get_cwd := core.process_get_cwd; -public alias executable := core.process_executable; +pub alias id := core.process_id; +pub alias panic := core.process_panic; +pub alias abort := core.process_abort; +pub alias exit := core.process_exit; +pub alias get_cwd := core.process_get_cwd; +pub alias executable := core.process_executable; -public var args := core.ARGS; -public var wdAtStartup := get_cwd() catch "."; -public var executableDir := Path.dir_name(executable() catch wdAtStartup); +pub var args := core.ARGS; +pub var wdAtStartup := get_cwd() catch "."; +pub var executableDir := Path.dir_name(executable() catch wdAtStartup); #[boxed] -public struct NotADirectoryError < Throwable { +pub struct NotADirectoryError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } -public func set_cwd(p: string) -> ! { +pub func set_cwd(p: string) -> ! { if !Path.is_directory(p) { throw NotADirectoryError("`{}` is not a directory".fmt(p)); } @@ -36,22 +36,22 @@ public func set_cwd(p: string) -> ! { } struct Result { - public output: string; - public exit_code: int32; + pub output: string; + pub exit_code: int32; } #[boxed] struct ExecutionFailedError < Throwable { cmd: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return "execution failed for `{}`".fmt(self.cmd); } } /// Starts the specified command, waits for it to complete, and returns /// both its output and the exit code. -public func execute(cmd: string) -> !Result { +pub func execute(cmd: string) -> !Result { pcmd := if cmd.contains("2>") { cmd } else { "{} 2>&1".fmt(cmd) }; unsafe { if f := libc.popen(pcmd.ptr, c"r") { diff --git a/lib/std/src/semver/mod.ri b/lib/std/src/semver/mod.ri index 452f9d65c..167c6b43b 100644 --- a/lib/std/src/semver/mod.ri +++ b/lib/std/src/semver/mod.ri @@ -5,49 +5,49 @@ import std/traits; /// Represents the different types of version increments. -public enum Increment as uint8 { +pub enum Increment as uint8 { Major, Minor, Patch } #[boxed] -public struct EmptyInputError < Throwable { - public func to_string(self) -> string { +pub struct EmptyInputError < Throwable { + pub func to_string(self) -> string { _ = self; return "empty input"; } } #[boxed] -public struct InvalidVersionFormatError < Throwable { +pub struct InvalidVersionFormatError < Throwable { input: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return "invalid version format for input '{}'".fmt(self.input); } } #[boxed] -public struct InvalidVersionError < Throwable { +pub struct InvalidVersionError < Throwable { input: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.input; } } /// Represents a semantic version in semver format. #[boxed] -public struct Version < traits.Stringable { - public major: uint; - public minor: uint; - public patch: uint; - public prerelease: string; - public metadata: string; +pub struct Version < traits.Stringable { + pub major: uint; + pub minor: uint; + pub patch: uint; + pub prerelease: string; + pub metadata: string; /// Returns a `Version` structure parsed from `input` `string`. - public func from_string(input: string) -> !Self { + pub func from_string(input: string) -> !Self { if input.is_empty() { throw EmptyInputError(); } @@ -60,14 +60,14 @@ public struct Version < traits.Stringable { /// Returns a `Version` structure with given `major`, `minor` and `patch` versions. #[inline] - public func build(major: uint, minor: uint, patch: uint) -> Self { + pub func build(major: uint, minor: uint, patch: uint) -> Self { // TODO: check if versions are greater than zero. return Version(major, minor, patch, "", ""); } /// Returns a `Version` structure with incremented values. #[inline] - public func increment(self, typ: Increment) -> Self { + pub func increment(self, typ: Increment) -> Self { mut major := self.major; mut minor := self.minor; mut patch := self.patch; @@ -91,7 +91,7 @@ public struct Version < traits.Stringable { /// Satisfies returns `true` if the `input` expression can be validated to `true` /// when run against this `Version`. #[inline] - public func satisfies(self, input: string) -> bool { + pub func satisfies(self, input: string) -> bool { return if range := Range.parse(input) { range.satisfies(self) } else { @@ -100,17 +100,17 @@ public struct Version < traits.Stringable { } #[inline] - public func ==(self, v2: Self) -> bool { + pub func ==(self, v2: Self) -> bool { return self.major == v2.major and self.minor == v2.minor and self.patch == v2.patch and self.prerelease == v2.prerelease; } #[inline] - public func !=(self, v2: Self) -> bool { + pub func !=(self, v2: Self) -> bool { return !(self == v2); } - public func >(self, v2: Self) -> bool { + pub func >(self, v2: Self) -> bool { if self.major < v2.major { return false; } else if self.major > v2.major { @@ -123,7 +123,7 @@ public struct Version < traits.Stringable { return self.patch > v2.patch; } - public func <(self, v2: Self) -> bool { + pub func <(self, v2: Self) -> bool { if self.major > v2.major { return false; } else if self.major < v2.major { @@ -137,16 +137,16 @@ public struct Version < traits.Stringable { } #[inline] - public func >=(self, v2: Self) -> bool { + pub func >=(self, v2: Self) -> bool { return self == v2 or self > v2; } #[inline] - public func <=(self, v2: Self) -> bool { + pub func <=(self, v2: Self) -> bool { return self == v2 or self < v2; } - public func to_string(self) -> string { + pub func to_string(self) -> string { common_string := "{}.{}.{}".fmt(self.major, self.minor, self.patch); prerelease_string := if self.prerelease.is_empty() { "" } else { "-".concat(self.prerelease) @@ -161,7 +161,7 @@ public struct Version < traits.Stringable { /// Converts the `input` version to a `Version` struct. /// coerce will strip any contents *after* the parsed version string. #[inline] -public func coerce(input: string) -> !Version { +pub func coerce(input: string) -> !Version { if version := RawVersion.parse(input).coerce() { return version; } @@ -171,6 +171,6 @@ public func coerce(input: string) -> !Version { /// Returns `true` if the `input` `string` can be converted to a semantic `Version` /// struct. #[inline] -public func is_valid(input: string) -> bool { +pub func is_valid(input: string) -> bool { return RawVersion.parse(input).is_valid(); } diff --git a/lib/std/src/semver/range.ri b/lib/std/src/semver/range.ri index 6764ccb87..8f79f643f 100644 --- a/lib/std/src/semver/range.ri +++ b/lib/std/src/semver/range.ri @@ -16,10 +16,10 @@ enum Operator as uint8 { } #[boxed] -public struct InvalidComparatorFormatError < Throwable { +pub struct InvalidComparatorFormatError < Throwable { msg: string; - public func to_string(self) -> string { + pub func to_string(self) -> string { return self.msg; } } diff --git a/lib/std/src/strings/TextScanner.ri b/lib/std/src/strings/TextScanner.ri index e3271cf89..724f873df 100644 --- a/lib/std/src/strings/TextScanner.ri +++ b/lib/std/src/strings/TextScanner.ri @@ -4,20 +4,20 @@ /// Simplifies writing small scanners/parsers by providing safe methods to scan /// texts character by character, peek for the next characters, go back, etc. -public struct TextScanner { - public input: string; - public len: uint; +pub struct TextScanner { + pub input: string; + pub len: uint; mut pos: uint; // current position; pos is always kept in [0, .len] /// Returns a stack allocated instance of TextScanner. - public func new(input: string) -> Self { + pub func new(input: string) -> Self { return Self(input, input.len); } /// Returns the next character code from the input text or `none` if it /// can't reach the next character. Advances the scanner position. #[inline] - public func next(mut self) -> ?uint8 { + pub func next(mut self) -> ?uint8 { if self.pos < self.len { opos := self.pos; self.pos += 1; @@ -29,7 +29,7 @@ public struct TextScanner { /// Skips ahead `n` characters, stopping at the end of the input; `skip` is /// slightly faster than `.next()`. #[inline] - public func skip(mut self, n: uint := 1) { + pub func skip(mut self, n: uint := 1) { self.pos += n; if self.pos > self.len { self.pos = self.len; @@ -40,7 +40,7 @@ public struct TextScanner { /// it can't peek `n` characters ahead. /// Unlike `.next()`, `.peek()` does not change the state of the scanner. #[inline] - public func peek(&self, n: uint := 0) -> ?uint8 { + pub func peek(&self, n: uint := 0) -> ?uint8 { if self.pos + n < self.len { return self.input[self.pos + n]; } @@ -48,7 +48,7 @@ public struct TextScanner { } /// Goes back `n` characters from the current scanner position. - public func back(mut self, n: uint := 1) { + pub func back(mut self, n: uint := 1) { self.pos -= n; if self.pos > self.len { self.pos = self.len; @@ -59,7 +59,7 @@ public struct TextScanner { /// it can't peek `n` characters back. /// Unlike `.back()`, `.peek_back()` does not change the state of the scanner. #[inline] - public func peek_back(&self, n: uint := 1) -> ?uint8 { + pub func peek_back(&self, n: uint := 1) -> ?uint8 { offset := n + 1; if self.pos >= offset { return self.input[self.pos - offset]; @@ -71,7 +71,7 @@ public struct TextScanner { /// of the input text. /// NOTE: after `c := ts.next()`, `ts.current()` will also return `c`. #[inline] - public func current(self) -> ?uint { + pub func current(self) -> ?uint { if self.pos > 0 { return self.input[self.pos - 1]; } @@ -81,18 +81,18 @@ public struct TextScanner { /// Has the same effect as `while c := ts.next() -> {}` i.e. after calling `.goto_end()`, /// the scanner will be at the end of the input text. /// Further `.next()` calls will return `none`, unless you go back. - public func goto_end(mut self) { + pub func goto_end(mut self) { self.pos = self.len; } /// Returns how many characters remain from current position. - public func remaining(&self) -> uint { + pub func remaining(&self) -> uint { return self.len - self.pos; } /// Resets the internal state of the scanner. After calling `.reset()`, `.next()` /// will start reading again from the start of the input text. - public func reset(mut self) { + pub func reset(mut self) { self.pos = 0; } } diff --git a/lib/std/src/strings/mod.ri b/lib/std/src/strings/mod.ri index 461df1b1a..4c55e20d3 100644 --- a/lib/std/src/strings/mod.ri +++ b/lib/std/src/strings/mod.ri @@ -4,7 +4,7 @@ import core; -public alias Builder := core.StringBuilder; +pub alias Builder := core.StringBuilder; func fill_vector(len: uint) -> []mut int32 { mut vec := @vec(mut int32, len); @@ -17,7 +17,7 @@ func fill_vector(len: uint) -> []mut int32 { /// Uses levenshtein distance algorithm to calculate the distance between /// two strings (lower is closer). -public func levenshtein_distance(a: string, b: string) -> int32 { +pub func levenshtein_distance(a: string, b: string) -> int32 { f := fill_vector(b.len + 1); for ca in a.as_bytes() { mut j: uint := 1; @@ -44,7 +44,7 @@ public func levenshtein_distance(a: string, b: string) -> int32 { /// Use levenshtein distance algorithm to calculate how similar two strings /// are as a percentage (higher is closer). -public func levenshtein_distance_percentage(a: string, b: string) -> float32 { +pub func levenshtein_distance_percentage(a: string, b: string) -> float32 { d := levenshtein_distance(a, b); l := if a.len >= b.len { a.len } else { b.len }; return (1.00 - @as(float32, d) / @as(float32, l)) * 100.00; diff --git a/lib/std/src/sys/arch.ri b/lib/std/src/sys/arch.ri index 4c8326700..6dce533e4 100644 --- a/lib/std/src/sys/arch.ri +++ b/lib/std/src/sys/arch.ri @@ -7,12 +7,12 @@ import ../traits; import ../process; #endif -public enum Arch as uint8 < traits.Stringable { +pub enum Arch as uint8 < traits.Stringable { X86, Amd64; #[inline] - public func from_string(arch: string) -> ?Arch { + pub func from_string(arch: string) -> ?Arch { return match arch { "i386", "x86", "_X86_" -> .X86, "amd64", "_AMD64_" -> .Amd64, @@ -20,7 +20,7 @@ public enum Arch as uint8 < traits.Stringable { }; } - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return match self.* { .X86 -> "x86", .Amd64 -> "amd64" @@ -30,7 +30,7 @@ public enum Arch as uint8 < traits.Stringable { /// Returns the current architecture. #[inline] -public func arch() -> Arch { +pub func arch() -> Arch { #if _X86_ return .X86; #else_if _AMD64_ diff --git a/lib/std/src/sys/c_runtime.ri b/lib/std/src/sys/c_runtime.ri index 12f6cae4b..56fbb1462 100644 --- a/lib/std/src/sys/c_runtime.ri +++ b/lib/std/src/sys/c_runtime.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -public enum CRuntime as uint8 { +pub enum CRuntime as uint8 { Glibc, Bionic, Musl, @@ -11,6 +11,6 @@ public enum CRuntime as uint8 { /// Returns the current C core. #[inline] -public func c_runtime() -> CRuntime { +pub func c_runtime() -> CRuntime { return .Glibc; } diff --git a/lib/std/src/sys/mod.ri b/lib/std/src/sys/mod.ri index ba42b9ae7..5d8a426b8 100644 --- a/lib/std/src/sys/mod.ri +++ b/lib/std/src/sys/mod.ri @@ -10,7 +10,7 @@ import ../process; /// Returns the number of virtual CPU cores found on the system. #[inline] -public func nr_cpus() -> int32 { +pub func nr_cpus() -> int32 { #if _LINUX_ return unsafe { libc.get_nprocs() }; #else @@ -20,24 +20,24 @@ public func nr_cpus() -> int32 { /// Returns true if the current executable is running on a 32-bit system. #[inline] -public func is_32bit() -> bool { +pub func is_32bit() -> bool { return @size_of(rawptr) == 4; } /// Returns true if the current executable is running on a 64-bit system. #[inline] -public func is_64bit() -> bool { +pub func is_64bit() -> bool { return @size_of(rawptr) == 8; } /// Returns true if the current executable is running on a little-endian system. #[inline] -public func is_little_endian() -> bool { +pub func is_little_endian() -> bool { return unsafe { @as(int32, @as(&int8, &1).*) } == 1; } /// Returns true if the current executable is running on a big-endian system. #[inline] -public func is_big_endian() -> bool { +pub func is_big_endian() -> bool { return unsafe { @as(int32, @as(&int8, &1).*) } == 0; } diff --git a/lib/std/src/sys/os.ri b/lib/std/src/sys/os.ri index da1ddab67..504e2a223 100644 --- a/lib/std/src/sys/os.ri +++ b/lib/std/src/sys/os.ri @@ -7,13 +7,13 @@ import ../traits; import ../process; #endif -public enum OS as uint8 < traits.Stringable { +pub enum OS as uint8 < traits.Stringable { Linux, Windows, Macos; #[inline] - public func from_string(name: string) -> ?OS { + pub func from_string(name: string) -> ?OS { return match name { "linux", "_LINUX_" -> .Linux, "windows", "_WINDOWS_" -> .Windows, @@ -22,7 +22,7 @@ public enum OS as uint8 < traits.Stringable { }; } - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return match self.* { .Linux -> "linux", .Windows -> "windows", @@ -33,7 +33,7 @@ public enum OS as uint8 < traits.Stringable { /// Returns the current operating system. #[inline] -public func os() -> OS { +pub func os() -> OS { #if _LINUX_ return .Linux; #else_if _WINDOWS_ diff --git a/lib/std/src/traits/mod.ri b/lib/std/src/traits/mod.ri index 03f7c749e..d1f70fb2a 100644 --- a/lib/std/src/traits/mod.ri +++ b/lib/std/src/traits/mod.ri @@ -4,5 +4,5 @@ import core; -public alias Stringable := core.Stringable; -public alias Hashable := core.Hashable; +pub alias Stringable := core.Stringable; +pub alias Hashable := core.Hashable; diff --git a/rivetc/src/codegen/c.py b/rivetc/src/codegen/c.py index 71acc3123..3ff470536 100644 --- a/rivetc/src/codegen/c.py +++ b/rivetc/src/codegen/c.py @@ -120,7 +120,7 @@ def gen_externs(self, externs): def gen_globals(self, globals): for g in globals: - if not g.is_pub: + if not g.is_public: self.globals.write("RIVET_LOCAL ") if g.is_extern: self.globals.write("extern ") @@ -166,7 +166,7 @@ def gen_fn_decl(self, decl): self.write("RIVET_NEVER ") self.protos.write("RIVET_NEVER ") if not decl.is_extern: - if decl.is_pub: + if decl.is_public: self.write("RIVET_EXPORT ") self.protos.write("RIVET_EXPORT ") else: diff --git a/rivetc/src/codegen/ir.py b/rivetc/src/codegen/ir.py index 2fe83122f..7292e3897 100644 --- a/rivetc/src/codegen/ir.py +++ b/rivetc/src/codegen/ir.py @@ -216,14 +216,14 @@ def __init__(self, name, typ): self.typ = typ class GlobalVar: - def __init__(self, is_pub, is_extern, typ, name): - self.is_pub = is_pub + def __init__(self, is_public, is_extern, typ, name): + self.is_public = is_public self.is_extern = is_extern self.typ = typ self.name = name def __str__(self): - if self.is_pub: + if self.is_public: kw = "export " elif self.is_extern: kw = "extern " @@ -238,10 +238,10 @@ def __init__(self, name, typ): class FuncDecl: def __init__( - self, is_pub, attrs, is_extern, name, args, is_variadic, ret_typ, + self, is_public, attrs, is_extern, name, args, is_variadic, ret_typ, is_never ): - self.is_pub = is_pub + self.is_public = is_public self.attrs = attrs self.is_extern = is_extern self.name = name @@ -347,7 +347,7 @@ def __str__(self): sb = utils.Builder() if self.is_extern: sb.write("extern ") - elif self.is_pub: + elif self.is_public: sb.write("export ") sb.write(f'func {self.name}(') for i, arg in enumerate(self.args): diff --git a/rivetc/src/parser.py b/rivetc/src/parser.py index a56d1167c..a9c2d01b8 100644 --- a/rivetc/src/parser.py +++ b/rivetc/src/parser.py @@ -141,8 +141,8 @@ def parse_attributes(self, parse_mod_attributes = False): return attributes def is_public(self): - is_pub = self.accept(Kind.KwPublic) - return self.inside_trait or self.inside_enum_variant_with_fields or is_pub + is_public = self.accept(Kind.KwPub) + return self.inside_trait or self.inside_enum_variant_with_fields or is_public def parse_abi(self): self.expect(Kind.Lparen) diff --git a/rivetc/src/sym.py b/rivetc/src/sym.py index f0b6f0908..42b3712d0 100644 --- a/rivetc/src/sym.py +++ b/rivetc/src/sym.py @@ -148,7 +148,7 @@ def add_or_get_mod(self, sym): def get_public_syms(self): syms = [] for s in self.syms: - if s.vis.is_pub(): + if s.vis.is_public(): syms.append(s) return syms diff --git a/rivetc/src/token.py b/rivetc/src/token.py index d10808953..8c07ac4fc 100644 --- a/rivetc/src/token.py +++ b/rivetc/src/token.py @@ -86,7 +86,7 @@ class Kind(Enum): KwNotIn = auto_enum() # !in KwNotIs = auto_enum() # !is KwOr = auto_enum() # or - KwPublic = auto_enum() # public + KwPub = auto_enum() # pub KwReturn = auto_enum() # return KwSelf = auto_enum() # self KwSelfTy = auto_enum() # Self @@ -231,7 +231,7 @@ def __str__(self): Kind.KwNotIn: "!in", Kind.KwNotIs: "!is", Kind.KwOr: "or", - Kind.KwPublic: "public", + Kind.KwPub: "pub", Kind.KwReturn: "return", Kind.KwSelf: "self", Kind.KwSelfTy: "Self", diff --git a/tests/invalid/invalid_throw_use.ri b/tests/invalid/invalid_throw_use.ri index fb2dc25fd..8b4a0997f 100644 --- a/tests/invalid/invalid_throw_use.ri +++ b/tests/invalid/invalid_throw_use.ri @@ -1,5 +1,5 @@ struct ThrowError < Throwable { - public func to_string(&self) -> string { + pub func to_string(&self) -> string { _ = self; return "ThrowError instance"; } diff --git a/tests/invalid/special_methods.out b/tests/invalid/special_methods.out index db3921b49..f6d9c782e 100644 --- a/tests/invalid/special_methods.out +++ b/tests/invalid/special_methods.out @@ -1,9 +1,9 @@ tests/invalid/special_methods.ri:2:5: error: this special function should be a method 2 | func __xxx__() {} | ^~~~~~~~~~~~~~~~~ -tests/invalid/special_methods.ri:4:12-6:5: error: special methods cannot be public - | /~~ from here - 4 | public func __public__(self) { +tests/invalid/special_methods.ri:4:9-6:5: error: special methods cannot be public + | /~~ from here + 4 | pub func __public__(self) { 5 | _ = self; 6 | } | ^~~ to here diff --git a/tests/invalid/special_methods.ri b/tests/invalid/special_methods.ri index a08c01c5b..f65332d70 100644 --- a/tests/invalid/special_methods.ri +++ b/tests/invalid/special_methods.ri @@ -1,7 +1,7 @@ struct SpecialMethod { func __xxx__() {} - public func __public__(self) { + pub func __public__(self) { _ = self; } diff --git a/tests/run_invalid_tests.py b/tests/run_invalid_tests.py index 15507f725..8ee120045 100644 --- a/tests/run_invalid_tests.py +++ b/tests/run_invalid_tests.py @@ -11,7 +11,11 @@ def run_fail_tests(): FAIL_FILES = glob.glob(os.path.join("tests", "invalid", "*.ri")) if not os.path.exists("rivet"): + print("> building Rivet self-hosted compiler...") res = utils.run_process("python3", "rivetc", "-o", "rivet", "cmd") + if res.exit_code != 0: + print(" > fail:", res.err) + exit(1) for i, file in enumerate(FAIL_FILES): start = f" [{i+1}/{len(FAIL_FILES)}]" res = utils.run_process("./rivet", "check", "--show-color=false", file) diff --git a/tests/valid/src/mod/mod.ri b/tests/valid/src/mod/mod.ri index 8557a650a..675bbded4 100644 --- a/tests/valid/src/mod/mod.ri +++ b/tests/valid/src/mod/mod.ri @@ -1,3 +1,3 @@ -public func add(a: int32, b: int32) -> int32 { +pub func add(a: int32, b: int32) -> int32 { return a + b; } diff --git a/tests/valid/src/results.ri b/tests/valid/src/results.ri index 05a2784f7..120f8f6be 100644 --- a/tests/valid/src/results.ri +++ b/tests/valid/src/results.ri @@ -1,7 +1,7 @@ struct MyError < Throwable { msg: string; - public func to_string(&self) -> string { + pub func to_string(&self) -> string { return self.msg; } } @@ -43,7 +43,7 @@ enum IOError < Throwable { size: uint; }; - public func to_string(self) -> string { + pub func to_string(self) -> string { return match self is { .FileNotFound as path -> "file not found: {}".fmt(path), .InvalidFileSize as ifsz -> "invalid file size for {} (size: {})".fmt( diff --git a/tests/valid/src/traits.ri b/tests/valid/src/traits.ri index 68d25783c..3a6184ae9 100644 --- a/tests/valid/src/traits.ri +++ b/tests/valid/src/traits.ri @@ -11,17 +11,17 @@ trait ReaderWriter < Reader, Writer { } struct SomeStream < ReaderWriter { - public func read(&self) -> uint8 { + pub func read(&self) -> uint8 { _ = self; return b'A'; } - public func write(&self, _b: uint8) -> bool { + pub func write(&self, _b: uint8) -> bool { _ = self; return true; } - public func write_and_read(&self, b: uint8) -> uint8 { + pub func write_and_read(&self, b: uint8) -> uint8 { _ = self.write(b); return self.read(); } @@ -58,7 +58,7 @@ trait Eq { #[boxed] struct Poketrait < Eq { - public func equal(self, x: Eq) -> bool { + pub func equal(self, x: Eq) -> bool { return self.x == x.x; } } From d2364969e3825063d316f4d7cd0e6199795a3faa Mon Sep 17 00:00:00 2001 From: StunxFS Date: Wed, 29 Nov 2023 21:21:23 -0400 Subject: [PATCH 2/3] refact(core): add `runtime_error` and use where appropriate Thus, there are three levels of errors in Rivet: - runtime error: This arises when an error occurs during some operation in the `core` module, for example a null pointer dereference. The exit code for this is 100. - panic: This occurs when something unexpected happens and there is no way to fix it, such as modifying a non-existent text file. The code for this is 101. - unhandled error: This occurs when an error is thrown and is not handled. The code for this is 102. --- lib/core/src/StringFormatter.ri | 14 +++++++------- lib/core/src/Vector.c.ri | 12 ++++++------ lib/core/src/array.c.ri | 4 ++-- lib/core/src/entry_point.ri | 3 +++ lib/core/src/errors.ri | 2 +- lib/core/src/lib.ri | 22 ++++++++++------------ lib/core/src/rune.c.ri | 4 ++-- lib/core/src/signals.c.ri | 12 ++++++------ lib/core/src/string.c.ri | 6 +++--- lib/core/src/utils.c.ri | 4 ++-- rivetc/src/codegen/__init__.py | 10 +++++++++- 11 files changed, 51 insertions(+), 42 deletions(-) diff --git a/lib/core/src/StringFormatter.ri b/lib/core/src/StringFormatter.ri index 1425cfd0f..fe77b684c 100644 --- a/lib/core/src/StringFormatter.ri +++ b/lib/core/src/StringFormatter.ri @@ -26,7 +26,7 @@ pub struct StringFormatter { arg_idx := args_idx; args_idx += 1; if arg_idx >= args.len { - process_panic( + runtime_error( "string.fmt(): argument index out of range (argument index: {}, len: {}) at index {}", arg_idx, args.len, self.i ); @@ -59,7 +59,7 @@ pub struct StringFormatter { buf.push(unsafe { self.buf.ptr[self.i] }); self.i += 1; if self.i >= self.buf.len { - process_panic( + runtime_error( "string.fmt(): incomplete format string at index {}", start ); @@ -67,7 +67,7 @@ pub struct StringFormatter { } index := buf.as_uint64(); if index >= args.len { - process_panic( + runtime_error( "string.fmt(): argument index out of range (index: {}, len: {})", index, args.len ); @@ -89,7 +89,7 @@ pub struct StringFormatter { } } } else { - process_panic( + runtime_error( "string.fmt(): expecting closing `}}` in format string at index {}", self.i ); @@ -100,7 +100,7 @@ pub struct StringFormatter { self.res.write_byte(b'}'); self.i += 1; } else { - process_panic( + runtime_error( "string.fmt(): single `}}` encountered in format string at index {}", self.i ); @@ -123,12 +123,12 @@ pub struct StringFormatter { buf.push(unsafe { self.buf.ptr[self.i] }); self.i += 1; if self.i >= self.buf.len { - process_panic("string.fmt(): incomplete format string (index: {})", start); + runtime_error("string.fmt(): incomplete format string (index: {})", start); } } fwidth := buf.as_int(); if fwidth == 0 { - process_panic( + runtime_error( "string.fmt(): invalid width value (cannot be 0 and cannot be omitted) -> (index: {})", start ); diff --git a/lib/core/src/Vector.c.ri b/lib/core/src/Vector.c.ri index b72312eac..3c3a2f0fe 100644 --- a/lib/core/src/Vector.c.ri +++ b/lib/core/src/Vector.c.ri @@ -39,14 +39,14 @@ struct Vector { func get(self, idx: uint) -> rawptr { if idx >= self.len { - process_panic("vector index out of range (index: {}, len: {})", idx, self.len); + runtime_error("vector index out of range (index: {}, len: {})", idx, self.len); } return unsafe { @ptr_add(@as([&]mut uint8, self.ptr), idx * self.elem_size) }; } func set(self, idx: uint, val: rawptr) { if idx >= self.len { - process_panic("vector index out of range (index: {}, len: {})", idx, self.len); + runtime_error("vector index out of range (index: {}, len: {})", idx, self.len); } unsafe { mem_copy( @@ -70,7 +70,7 @@ struct Vector { /// vector is empty, this will panic. func pop(mut self) -> rawptr { if self.len == 0 { - process_panic("Vec.pop: vector is empty"); + runtime_error("Vec.pop: vector is empty"); } new_len := self.len - 1; self.len = new_len; @@ -84,8 +84,8 @@ struct Vector { pub func delete(mut self, i: uint, size: uint := 1, no_slices: bool := false) { if i + size > self.len { end_idx := if size == 1 { "..{}".fmt(i + size) } else { "" }; - process_panic( - "Vector.delete(): index out of range (i: {}{}, self.len: {})", + runtime_error( + "Vector.delete(): index out of range (i: {}..{}, self.len: {})", i, end_idx, self.len ); } @@ -156,7 +156,7 @@ struct Vector { func slice(self, start: uint, end: uint) -> Self { if start > end or end > self.len { - process_panic( + runtime_error( "slice index out of range (range: {}..{}, len: {})", start, end, self.len ); } diff --git a/lib/core/src/array.c.ri b/lib/core/src/array.c.ri index 2a9593ccb..002d50046 100644 --- a/lib/core/src/array.c.ri +++ b/lib/core/src/array.c.ri @@ -6,7 +6,7 @@ import c/libc; func array_index(len: uint, idx: uint) { if idx >= len { - process_panic("array index out of range (index: {}, size: {})", idx, len); + runtime_error("array index out of range (index: {}, size: {})", idx, len); } } @@ -22,7 +22,7 @@ func array_ne(arr: rawptr, other_arr: rawptr, len: uint) -> bool { func array_slice(arr: rawptr, elem_size: uint, size: uint, start: uint, end: uint) -> Vector { if start > end or end > size { - process_panic("slice index out of range (range: {}..{}, len: {})", start, end, size); + runtime_error("slice index out of range (range: {}..{}, len: {})", start, end, size); } len := end - start; return unsafe { diff --git a/lib/core/src/entry_point.ri b/lib/core/src/entry_point.ri index 242b647ad..cafcd86bd 100644 --- a/lib/core/src/entry_point.ri +++ b/lib/core/src/entry_point.ri @@ -30,11 +30,13 @@ func main( ) { setup_signals_handler(); init_args(@as(uint, _argc), _argv); + #if !_TESTS_ // `init_string_lits` is called after init_string_lits(); #endif init_globals(); libcoreIsStarted = true; + #if _TESTS_ if test_runner.tests.len > 0 { test_runner.run(); @@ -42,5 +44,6 @@ func main( #else mod_main(); #endif + drop_globals(); } diff --git a/lib/core/src/errors.ri b/lib/core/src/errors.ri index 4f50a544f..2e33ec71d 100644 --- a/lib/core/src/errors.ri +++ b/lib/core/src/errors.ri @@ -30,7 +30,7 @@ struct ReturnTrace { #[inline] func add(mut self, trace: CallTrace) { if self.cur_idx == RETURN_TRACE_MAX_SIZE { - process_panic("maximum return trace size exceeded"); + runtime_error("maximum return trace size exceeded"); } self.traces[self.cur_idx] = trace; self.cur_idx += 1; diff --git a/lib/core/src/lib.ri b/lib/core/src/lib.ri index a3281baba..8106a8883 100644 --- a/lib/core/src/lib.ri +++ b/lib/core/src/lib.ri @@ -4,14 +4,6 @@ var mut libcoreIsStarted := false; -func panic_if(cond: bool, msg: string) { - if cond { - console_ewriteln("panic: {}", msg); - bt_print(2); - process_exit(1); - } -} - func assert(cond: bool, msg: string) { if !cond { console_ewriteln("panic: assertion failed: {}", msg); @@ -20,10 +12,16 @@ func assert(cond: bool, msg: string) { } } +func runtime_error(s: string, args: ...Stringable) -> never { + console_ewriteln("runtime error: {}", s.fmt(args)); + bt_print(2); + process_exit(100); +} + #[inline] func internal_alloc(size: uint) -> rawptr { return mem_alloc(size) catch { - process_panic( + runtime_error( "internal error: cannot allocate memory" #if _DEBUG_ " (size: {})", size #endif ) }; @@ -32,7 +30,7 @@ func internal_alloc(size: uint) -> rawptr { #[inline] func internal_zeroed(size: uint) -> rawptr { return mem_zeroed(size) catch { - process_panic( + runtime_error( "internal error: cannot allocate zeroed memory" #if _DEBUG_ " (size: {})", size #endif ) }; @@ -41,7 +39,7 @@ func internal_zeroed(size: uint) -> rawptr { #[inline] func internal_dup(src: rawptr, sz: uint) -> rawptr { return mem_dup(src, sz) catch { - process_panic( + runtime_error( "internal error: cannot duplicate memory" #if _DEBUG_ " (size: {})", sz #endif ) }; @@ -50,7 +48,7 @@ func internal_dup(src: rawptr, sz: uint) -> rawptr { #[inline] func internal_resize(ptr: ?rawptr, sz: uint) -> rawptr { return mem_resize(ptr, sz) catch { - process_panic( + runtime_error( "internal error: cannot resize memory" #if _DEBUG_ " (size: {})", sz #endif ) }; diff --git a/lib/core/src/rune.c.ri b/lib/core/src/rune.c.ri index 14a16fd0e..a551eef41 100644 --- a/lib/core/src/rune.c.ri +++ b/lib/core/src/rune.c.ri @@ -38,11 +38,11 @@ extend rune < Stringable { /// Panics if given a radix larger than 36. pub func from_digit(num: uint32, radix: uint32) -> ?rune { if radix > 36 { - process_panic("rune.from_digit: radix is too high (maximum 36)"); + runtime_error("rune.from_digit: radix is too high (maximum 36)"); } if num < radix { num_ := @as(uint8, num); - byte := (if num_ < 10 { b'0' + num_ } else { b'a' + num_ - 10 }); + byte := if num_ < 10 { b'0' + num_ } else { b'a' + num_ - 10 }; return byte.to_rune(); } return none; diff --git a/lib/core/src/signals.c.ri b/lib/core/src/signals.c.ri index 57eacd447..d8c33b4af 100644 --- a/lib/core/src/signals.c.ri +++ b/lib/core/src/signals.c.ri @@ -26,23 +26,23 @@ func signals_handler(_sig: int32, info: &mut libc.siginfo_t, _context: rawptr) { func segfault_handler() { console_ewriteln( if libcoreIsStarted { - "panic: invalid memory address or null pointer dereference" + "runtime error: invalid memory address or null pointer dereference" } else { - "panic: invalid memory address or null pointer dereference while starting the core" + "runtime error: invalid memory address or null pointer dereference while starting the core" } ); bt_print(4); - process_exit(1); + process_exit(100); } func fpe_handler() { console_ewriteln( if libcoreIsStarted { - "panic: floating point exception" + "runtime error: floating point exception" } else { - "panic: floating point exception while starting the core" + "runtime error: floating point exception while starting the core" } ); bt_print(4); - process_exit(1); + process_exit(100); } diff --git a/lib/core/src/string.c.ri b/lib/core/src/string.c.ri index a80d7b350..d74b6b65d 100644 --- a/lib/core/src/string.c.ri +++ b/lib/core/src/string.c.ri @@ -29,7 +29,7 @@ pub struct string < Stringable, Hashable, Throwable { } return if safe_ptr := ptr { if unsafe { safe_ptr[len] != 0 } { - process_panic("`ptr` is not a valid string, doesn't ends with NLL byte"); + runtime_error("`ptr` is not a valid string, doesn't ends with NLL byte"); } Self(safe_ptr, len, is_ref) } else { @@ -62,7 +62,7 @@ pub struct string < Stringable, Hashable, Throwable { pub func at(self, idx: uint) -> uint8 { if idx >= self.len { - process_panic("string index out of range (index: {}, len: {})", idx, self.len); + runtime_error("string index out of range (index: {}, len: {})", idx, self.len); } return unsafe { self.ptr[idx] }; } @@ -788,7 +788,7 @@ pub struct string < Stringable, Hashable, Throwable { func slice(self, start: uint, end: uint) -> Self { unsafe { if start > end or start > self.len or end > self.len { - process_panic( + runtime_error( "string slice index out of range (range: {}..{}, len: {})", start, end, self.len ); diff --git a/lib/core/src/utils.c.ri b/lib/core/src/utils.c.ri index fd6903b33..eec3ef0b2 100644 --- a/lib/core/src/utils.c.ri +++ b/lib/core/src/utils.c.ri @@ -13,7 +13,7 @@ func enum_cast(ptr: rawptr, expected_id: uint) -> rawptr { if enum_info._id_ != expected_id { // TODO: replace indexes with names console_ewriteln( - "panic: enum cast: cannot cast ID({}) to ID({})", enum_info._id_, expected_id + "runtime error: enum cast: cannot cast ID({}) to ID({})", enum_info._id_, expected_id ); bt_print(2); process_exit(1); @@ -25,7 +25,7 @@ func trait_cast(got_obj: rawptr, got_id: uint, expected_id: uint) -> rawptr { if got_id != expected_id { // TODO: replace indexes with names console_ewriteln( - "panic: trait cast: cannot cast ID({}) to ID({})", got_id, expected_id + "runtime error: trait cast: cannot cast ID({}) to ID({})", got_id, expected_id ); bt_print(2); process_exit(1); diff --git a/rivetc/src/codegen/__init__.py b/rivetc/src/codegen/__init__.py index e2052eda2..1ff0e3453 100644 --- a/rivetc/src/codegen/__init__.py +++ b/rivetc/src/codegen/__init__.py @@ -982,7 +982,7 @@ def gen_expr(self, expr, custom_tmp = None): self.gen_expr(expr.args[1])] ) elif expr.name == "unreachable": - self.panic("entered unreachable code") + self.runtime_error("entered unreachable code") elif expr.name == "breakpoint" and self.comp.prefs.build_mode != prefs.BuildMode.Release: self.cur_fn.breakpoint() elif isinstance(expr, ast.TupleLiteral): @@ -2620,6 +2620,14 @@ def option_none(self, typ): ) return tmp + def runtime_error(self, msg): + self.cur_fn.add_call( + "_R4core13runtime_errorF", [ + self.gen_string_literal(utils.smart_quote(msg, False)), + self.empty_vec(self.comp.universe["[]core.Stringable"]) + ] + ) + def panic(self, msg): self.cur_fn.add_call( "_R4core13process_panicF", [ From 5361b0e0df8863637361bec19a241f9c004d5db4 Mon Sep 17 00:00:00 2001 From: StunxFS Date: Wed, 29 Nov 2023 21:39:35 -0400 Subject: [PATCH 3/3] refact(rivetc.codegen): use `runtime_error` to attempt to access a `none` value --- lib/core/src/lib.ri | 16 ++++------------ rivetc/src/codegen/__init__.py | 10 +--------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/core/src/lib.ri b/lib/core/src/lib.ri index 8106a8883..a3b5b54e3 100644 --- a/lib/core/src/lib.ri +++ b/lib/core/src/lib.ri @@ -21,35 +21,27 @@ func runtime_error(s: string, args: ...Stringable) -> never { #[inline] func internal_alloc(size: uint) -> rawptr { return mem_alloc(size) catch { - runtime_error( - "internal error: cannot allocate memory" #if _DEBUG_ " (size: {})", size #endif - ) + runtime_error("cannot allocate memory" #if _DEBUG_ " (size: {})", size #endif) }; } #[inline] func internal_zeroed(size: uint) -> rawptr { return mem_zeroed(size) catch { - runtime_error( - "internal error: cannot allocate zeroed memory" #if _DEBUG_ " (size: {})", size #endif - ) + runtime_error("cannot allocate zeroed memory" #if _DEBUG_ " (size: {})", size #endif) }; } #[inline] func internal_dup(src: rawptr, sz: uint) -> rawptr { return mem_dup(src, sz) catch { - runtime_error( - "internal error: cannot duplicate memory" #if _DEBUG_ " (size: {})", sz #endif - ) + runtime_error("cannot duplicate memory" #if _DEBUG_ " (size: {})", sz #endif) }; } #[inline] func internal_resize(ptr: ?rawptr, sz: uint) -> rawptr { return mem_resize(ptr, sz) catch { - runtime_error( - "internal error: cannot resize memory" #if _DEBUG_ " (size: {})", sz #endif - ) + runtime_error("cannot resize memory" #if _DEBUG_ " (size: {})", sz #endif) }; } diff --git a/rivetc/src/codegen/__init__.py b/rivetc/src/codegen/__init__.py index 1ff0e3453..7bdc46360 100644 --- a/rivetc/src/codegen/__init__.py +++ b/rivetc/src/codegen/__init__.py @@ -1594,7 +1594,7 @@ def gen_expr(self, expr, custom_tmp = None): ) value = ir.Selector(ir_typ, left, ir.Name("value")) self.cur_fn.add_label(panic_l) - self.panic(f"attempt to use none value (`{expr.left}`)") + self.runtime_error(f"attempt to use none value (`{expr.left}`)") self.cur_fn.add_label(exit_l) return value elif isinstance(left, ir.StringLit): @@ -2628,14 +2628,6 @@ def runtime_error(self, msg): ] ) - def panic(self, msg): - self.cur_fn.add_call( - "_R4core13process_panicF", [ - self.gen_string_literal(utils.smart_quote(msg, False)), - self.empty_vec(self.comp.universe["[]core.Stringable"]) - ] - ) - def variadic_args(self, vargs, var_arg_typ_): if len(vargs) == 0: return self.empty_vec(var_arg_typ_.typ.symbol())