From 9d001353d1b5bc2146d64fae877894693d9f4a5f Mon Sep 17 00:00:00 2001 From: Jose Mendoza <56417208+StunxFS@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:57:43 +0000 Subject: [PATCH] refact: rename `static` to `var` --- cmd/src/main.ri | 2 +- cmd/src/tools/cmd_new.ri | 8 +++--- cmd/src/tools/templates/mod.ri | 10 ++++---- lib/c/src/libc/mod.ri | 2 +- lib/c/src/libc/stdio.ri | 12 ++++----- lib/c/src/wyhash.ri | 2 +- lib/core/src/TestRunner.ri | 10 ++++---- lib/core/src/backtrace.c.ri | 2 +- lib/core/src/entry_point.ri | 2 +- lib/core/src/errors.ri | 2 +- lib/core/src/int.ri | 2 +- lib/core/src/lib.ri | 2 +- lib/core/src/string.c.ri | 2 +- lib/rivet/src/ast/Sym.ri | 4 +-- lib/rivet/src/codegen/mir/mod.ri | 4 +-- lib/rivet/src/parser/decls.ri | 4 +-- lib/rivet/src/prefs/mod.ri | 12 ++++----- lib/rivet/src/report/mod.ri | 2 +- lib/rivet/src/token/Kind.ri | 30 +++++++++++------------ lib/rivet/src/token/mod.ri | 2 +- lib/rivet/src/tokenizer/next.ri | 2 +- lib/rivet/src/utils/file.ri | 6 ++--- lib/rivet/src/utils/mod.ri | 2 +- lib/rivet/src/utils/smart_quote.ri | 4 +-- lib/rivet/src/utils/version.ri | 2 +- lib/rivet/tests/tokenizer.ri | 2 +- lib/std/src/dynlib/mod.ri | 2 +- lib/std/src/env/mod.ri | 2 +- lib/std/src/flag/mod.ri | 2 +- lib/std/src/fs/Path.ri | 4 +-- lib/std/src/process/mod.ri | 6 ++--- lib/std/src/semver/parse.ri | 2 +- lib/std/src/semver/range.ri | 8 +++--- lib/std/tests/fs_test.ri | 2 +- lib/std/tests/semver_test.ri | 10 ++++---- rivetc/src/ast.py | 4 +-- rivetc/src/checker.py | 8 +++--- rivetc/src/codegen/__init__.py | 4 +-- rivetc/src/parser.py | 6 ++--- rivetc/src/register.py | 2 +- rivetc/src/resolver.py | 4 +-- rivetc/src/token.py | 4 +-- tests/valid/src/declarations.ri | 6 ++--- tests/valid/src/overloadable_operators.ri | 2 +- tests/valid/src/results.ri | 4 +-- 45 files changed, 108 insertions(+), 108 deletions(-) diff --git a/cmd/src/main.ri b/cmd/src/main.ri index f3802f2f9..3f4cd089b 100644 --- a/cmd/src/main.ri +++ b/cmd/src/main.ri @@ -10,7 +10,7 @@ import rivet/utils; import ./tools; -static help := "Rivet is a tool for managing Rivet source code. +var help := "Rivet is a tool for managing Rivet source code. Usage: rivet [COMMAND] [OPTIONS] diff --git a/cmd/src/tools/cmd_new.ri b/cmd/src/tools/cmd_new.ri index 646df4b3f..f46b9bfe4 100644 --- a/cmd/src/tools/cmd_new.ri +++ b/cmd/src/tools/cmd_new.ri @@ -14,18 +14,18 @@ import rivet/utils; import ./templates; -static newDescription := "Sets up a new Rivet project and performs `git init` (if `git` is installed +var newDescription := "Sets up a new Rivet project and performs `git init` (if `git` is installed on the system)."; -static newDescription2 := "If [NAME] is given, the project will be setup in a new directory with that +var newDescription2 := "If [NAME] is given, the project will be setup in a new directory with that name, and that name will be added to the `project.json` file. If no name is given, the user will be prompted for a name."; -static initDescription := "If no `project.json` file exists, one will be created. +var initDescription := "If no `project.json` file exists, one will be created. If the current directory is not already controlled with `git`, will perform `git init` (if `git` is installed on the system)."; -static availableTemplates := "Available templates: +var availableTemplates := "Available templates: bin A simple binary project (default). lib A simple library project."; diff --git a/cmd/src/tools/templates/mod.ri b/cmd/src/tools/templates/mod.ri index 19b354f9b..236d85304 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 static mainFile := "import std/console; +public var mainFile := "import std/console; func main() { console.writeln(\"Hello World!\"); } "; -public static libFile := "public func add(a: int32, b: int32) -> int32 { +public var libFile := "public func add(a: int32, b: int32) -> int32 { return a + b; } @@ -18,7 +18,7 @@ test \"test `add` function\" { } "; -public static gitignoreFile := "# Binaries for programs and plugins +public var gitignoreFile := "# Binaries for programs and plugins {} *.exe *.exe~ @@ -39,12 +39,12 @@ bin/ .env "; -public static gitattributesFile := "* text=auto eol=lf +public var gitattributesFile := "* text=auto eol=lf *.bat eol=crlf *.ri linguist-language=Rivet text=auto eol=lf "; -public static editorConfigFile := "[*] +public var editorConfigFile := "[*] charset = utf-8 end_of_line = lf insert_final_newline = true diff --git a/lib/c/src/libc/mod.ri b/lib/c/src/libc/mod.ri index 02d7833f2..6f74a59e6 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 static environ: [&][&]uint8; + public var environ: [&][&]uint8; } diff --git a/lib/c/src/libc/stdio.ri b/lib/c/src/libc/stdio.ri index 4a1b8b5b4..565a92183 100644 --- a/lib/c/src/libc/stdio.ri +++ b/lib/c/src/libc/stdio.ri @@ -37,9 +37,9 @@ public struct FILE; #if _LINUX_ extern (C) { - public static stdin: &mut FILE; - public static stdout: &mut FILE; - public static stderr: &mut FILE; + public var stdin: &mut FILE; + public var stdout: &mut FILE; + public var stderr: &mut FILE; } public struct fpos_t { @@ -86,9 +86,9 @@ public struct FILE; public const TMP_MAX := 32767; // SHRT_MAX - public static stdin: &mut FILE := unsafe { __acrt_iob_fn(0) }; - public static stdout: &mut FILE := unsafe { __acrt_iob_fn(1) }; - public static stderr: &mut FILE := unsafe { __acrt_iob_fn(2) }; + 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) }; #endif extern (C) { diff --git a/lib/c/src/wyhash.ri b/lib/c/src/wyhash.ri index e46a8ba33..918510cb8 100644 --- a/lib/c/src/wyhash.ri +++ b/lib/c/src/wyhash.ri @@ -6,7 +6,7 @@ extern (C) { // the default secret parameters - public static _wyp: [4]uint64; + public var _wyp: [4]uint64; func _wyrot(x: uint64) -> uint64; func _wymum(a: &uint64, b: &uint64); diff --git a/lib/core/src/TestRunner.ri b/lib/core/src/TestRunner.ri index 06efb08e7..19aaeed75 100644 --- a/lib/core/src/TestRunner.ri +++ b/lib/core/src/TestRunner.ri @@ -4,14 +4,14 @@ #if _TESTS_ -static supportColor := console_is_atty(1); +var supportColor := console_is_atty(1); -static okStatus := bold(green("-> OK")); -static failedStatus := bold(red("-> FAIL")); -static skipStatus := bold(yellow("-> SKIP")); +var okStatus := bold(green("-> OK")); +var failedStatus := bold(red("-> FAIL")); +var skipStatus := bold(yellow("-> SKIP")); extern (Rivet) { - static testRunner: TestRunner; + var testRunner: TestRunner; } func bold(msg: string) -> string { diff --git a/lib/core/src/backtrace.c.ri b/lib/core/src/backtrace.c.ri index a1706e0af..4903999fd 100644 --- a/lib/core/src/backtrace.c.ri +++ b/lib/core/src/backtrace.c.ri @@ -31,7 +31,7 @@ extern (C) { ) -> int32; } -static state := unsafe { +var state := unsafe { backtrace_create_state(ARGS[0].ptr, true, bt_error_handler, none)? }; diff --git a/lib/core/src/entry_point.ri b/lib/core/src/entry_point.ri index a4041a4c5..c6bc8a379 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 static mut ARGS: []string; + public var mut ARGS: []string; func init_string_lits(); func init_globals(); diff --git a/lib/core/src/errors.ri b/lib/core/src/errors.ri index 7b109f96e..d99d8294b 100644 --- a/lib/core/src/errors.ri +++ b/lib/core/src/errors.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -static returnTrace := ReturnTrace(); +var returnTrace := ReturnTrace(); /// This trait is used for errors throwed with result types (!T). public trait Throwable < Stringable { } diff --git a/lib/core/src/int.ri b/lib/core/src/int.ri index 7d6e785e8..9925dc18f 100644 --- a/lib/core/src/int.ri +++ b/lib/core/src/int.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -static digitPairs := "0010203040506070809001112131415161718191021222324252627" +var digitPairs := "0010203040506070809001112131415161718191021222324252627" "28292031323334353637383930414243444546474849405152535455565758595061626364656667" "68696071727374757677787970818283848586878889809192939495969798999"; diff --git a/lib/core/src/lib.ri b/lib/core/src/lib.ri index b75ff0ffa..a3281baba 100644 --- a/lib/core/src/lib.ri +++ b/lib/core/src/lib.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -static mut libcoreIsStarted := false; +var mut libcoreIsStarted := false; func panic_if(cond: bool, msg: string) { if cond { diff --git a/lib/core/src/string.c.ri b/lib/core/src/string.c.ri index 941022cc4..79e1b479d 100644 --- a/lib/core/src/string.c.ri +++ b/lib/core/src/string.c.ri @@ -4,7 +4,7 @@ import c/libc; -static emptyString := string(c"", 0, true); +var emptyString := string(c"", 0, true); #[boxed] public struct string < Stringable, Hashable, Throwable { diff --git a/lib/rivet/src/ast/Sym.ri b/lib/rivet/src/ast/Sym.ri index 0a82dc8eb..35ad9842b 100644 --- a/lib/rivet/src/ast/Sym.ri +++ b/lib/rivet/src/ast/Sym.ri @@ -7,7 +7,7 @@ import std/strings; import ../token; -static mut symIds: uint := 0; +var mut symIds: uint := 0; func new_sym_id() -> uint { res := symIds; @@ -296,7 +296,7 @@ public struct Const < Sym { } public enum VarLevel as uint8 { - Module, // module-level, `static` + Module, // module-level, `var` Receiver, // receiver: `self` Argument, // argument-level Local // inside function diff --git a/lib/rivet/src/codegen/mir/mod.ri b/lib/rivet/src/codegen/mir/mod.ri index 76c9b32e9..b34914443 100644 --- a/lib/rivet/src/codegen/mir/mod.ri +++ b/lib/rivet/src/codegen/mir/mod.ri @@ -102,7 +102,7 @@ public struct Global < traits.Stringable { if self.is_extern { sb.write_string("extern "); } - sb.write_fmt("static @{}: {};", self.name, self.type); + sb.write_fmt("var @{}: {};", self.name, self.type); return sb.to_string(); } } @@ -172,7 +172,7 @@ public struct Func < traits.Stringable { if self.blocks.len > 0 { locals := self.locals[self.args_len..]; for local in locals { - sb.writeln_fmt(" static %{}: {};", local.dbg_name, local.type); + sb.writeln_fmt(" var %{}: {};", local.dbg_name, local.type); } if self.blocks.len > 0 { if locals.len > 0 { diff --git a/lib/rivet/src/parser/decls.ri b/lib/rivet/src/parser/decls.ri index aff7c036a..5410cb858 100644 --- a/lib/rivet/src/parser/decls.ri +++ b/lib/rivet/src/parser/decls.ri @@ -174,7 +174,7 @@ extend Parser { }, self.accept(.KwExtern) -> { self.inside_extern = true; - // extern function or static + // extern function or var abi := self.parse_abi(); mut decls := @vec(ast.Decl); if self.accept(.Lbrace) { @@ -250,7 +250,7 @@ extend Parser { pos ); }, - self.accept(.KwStatic) -> { + self.accept(.KwVar) -> { // variable declarations mut lefts := @vec(ast.ObjectData); if self.accept(.Lparen) { diff --git a/lib/rivet/src/prefs/mod.ri b/lib/rivet/src/prefs/mod.ri index 5e40d4b70..ab0bb6ae1 100644 --- a/lib/rivet/src/prefs/mod.ri +++ b/lib/rivet/src/prefs/mod.ri @@ -10,12 +10,12 @@ import { Path } from std/fs; import ../utils; -public static rivetDir := Path.join(env.homeDir, ".rivet_lang")!; -public static rivetcDir := Path.dir_name(process.executable()!)?; +public var rivetDir := Path.join(env.homeDir, ".rivet_lang")!; +public var rivetcDir := Path.dir_name(process.executable()!)?; -public static objDir := Path.join(rivetDir, "obj")!; -public static libDir := Path.join(rivetDir, "lib")!; -public static rivetcLibDir := Path.join(rivetcDir, "lib")!; +public var objDir := Path.join(rivetDir, "obj")!; +public var libDir := Path.join(rivetDir, "lib")!; +public var rivetcLibDir := Path.join(rivetcDir, "lib")!; public enum Backend as uint8 { C; @@ -38,7 +38,7 @@ public enum OptimizeMode as uint8 { } public enum LinkMode as uint8 { - Static, + Var, Dynamic } diff --git a/lib/rivet/src/report/mod.ri b/lib/rivet/src/report/mod.ri index afdedbe4a..05326d484 100644 --- a/lib/rivet/src/report/mod.ri +++ b/lib/rivet/src/report/mod.ri @@ -10,7 +10,7 @@ import ../prefs; import ../token; import ../utils; -public static mut reportTable := ReportTable(); +public var mut reportTable := ReportTable(); #[inline] public func total_errors() -> uint { diff --git a/lib/rivet/src/token/Kind.ri b/lib/rivet/src/token/Kind.ri index 8ce7788f2..dfce86260 100644 --- a/lib/rivet/src/token/Kind.ri +++ b/lib/rivet/src/token/Kind.ri @@ -9,7 +9,7 @@ struct KindMap { value: string; } -static kindStrings := [ +var kindStrings := [ KindMap(.Unknown, "unknown"), KindMap(.EndOfFile, "end of file"), KindMap(.DocComment, "doc-comment"), @@ -94,7 +94,6 @@ static kindStrings := [ KindMap(.KwReturn, "return"), KindMap(.KwSelf, "self"), KindMap(.KwSelfTy, "Self"), - KindMap(.KwStatic, "static"), KindMap(.KwStruct, "struct"), KindMap(.KwMatch, "match"), KindMap(.KwTest, "test"), @@ -102,10 +101,11 @@ static kindStrings := [ KindMap(.KwTrait, "trait"), KindMap(.KwTrue, "true"), KindMap(.KwUnsafe, "unsafe"), + KindMap(.KwVar, "var"), KindMap(.KwWhile, "while") ]; -static keywordsTable := kindStrings[@as(uint, Kind.KeywordBegin)..]; +var keywordsTable := kindStrings[@as(uint, Kind.KeywordBegin)..]; public enum Kind < traits.Stringable { Unknown, // unknown @@ -193,7 +193,6 @@ public enum Kind < traits.Stringable { KwReturn, // return KwSelf, // self KwSelfTy, // Self - KwStatic, // static KwStruct, // struct KwMatch, // match KwTest, // test @@ -201,11 +200,22 @@ public enum Kind < traits.Stringable { KwTrait, // trait KwTrue, // true KwUnsafe, // unsafe + KwVar, // var KwWhile, // while // ============================== KeywordEnd; + #[inline] + public func lookup(str: string) -> Self { + for &km in keywordsTable { + if km.value == str { + return km.key; + } + } + return .Name; + } + #[inline] public func single(self) -> Kind { return match self { @@ -254,19 +264,9 @@ public enum Kind < traits.Stringable { } } -#[inline] -public func lookup(str: string) -> Kind { - for &km in keywordsTable { - if km.value == str { - return km.key; - } - } - return .Name; -} - #[inline] public func is_keyword(lit: string) -> bool { - return lookup(lit) != .Name; + return Kind.lookup(lit) != .Name; } #[inline] diff --git a/lib/rivet/src/token/mod.ri b/lib/rivet/src/token/mod.ri index b4a9de1f8..41809c8cc 100644 --- a/lib/rivet/src/token/mod.ri +++ b/lib/rivet/src/token/mod.ri @@ -6,7 +6,7 @@ import std/traits; import ../utils; -public static noPos := Pos(); +public var noPos := Pos(); public struct Pos < traits.Stringable { public file: string; diff --git a/lib/rivet/src/tokenizer/next.ri b/lib/rivet/src/tokenizer/next.ri index ce927b2e2..e00fdee43 100644 --- a/lib/rivet/src/tokenizer/next.ri +++ b/lib/rivet/src/tokenizer/next.ri @@ -39,7 +39,7 @@ extend Tokenizer { nextc := self.look_ahead(1); if utils.is_name_char(ch) { name := self.read_name(); - return self.new_token(token.lookup(name), name, name.len); + return self.new_token(token.Kind.lookup(name), name, name.len); } else if ch.is_digit() { // decimals with 0 prefix = error if ch == b'0' and nextc.is_digit() { diff --git a/lib/rivet/src/utils/file.ri b/lib/rivet/src/utils/file.ri index 9159dab70..d1ffcce13 100644 --- a/lib/rivet/src/utils/file.ri +++ b/lib/rivet/src/utils/file.ri @@ -6,8 +6,8 @@ import std/env; import std/process; import { Path, self } from std/fs; -static normalizedWorkdir := process.wdAtStartup.replace("\\", "/").concat("/"); -static errorPathsAbsolute := (env.get("RIVET_ERROR_PATHS") ?? "relative") == "absolute"; +var normalizedWorkdir := process.wdAtStartup.replace("\\", "/").concat("/"); +var errorPathsAbsolute := (env.get("RIVET_ERROR_PATHS") ?? "relative") == "absolute"; // 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. @@ -85,7 +85,7 @@ struct SourceCache { } } -public static mut sourceCache: SourceCache := SourceCache(); +public var mut sourceCache: SourceCache := SourceCache(); #[inline] public func read_file(path_: string) -> !string { diff --git a/lib/rivet/src/utils/mod.ri b/lib/rivet/src/utils/mod.ri index afbbad844..e79e7aafd 100644 --- a/lib/rivet/src/utils/mod.ri +++ b/lib/rivet/src/utils/mod.ri @@ -10,7 +10,7 @@ import std/console/styles; public const LF: uint8 := 10; public const CR: uint8 := 13; -public static mut stderrSupportStyles := styles.stderr_support_styles(); +public var mut stderrSupportStyles := styles.stderr_support_styles(); #[inline] public func min(a: uint, b: uint) -> uint { diff --git a/lib/rivet/src/utils/smart_quote.ri b/lib/rivet/src/utils/smart_quote.ri index 65aa99079..551e20d3d 100644 --- a/lib/rivet/src/utils/smart_quote.ri +++ b/lib/rivet/src/utils/smart_quote.ri @@ -9,8 +9,8 @@ const BACKSLASH_R: uint8 := 13; const BACKSLASH_N: uint8 := 10; const DOUBLE_QUOTE: uint8 := 34; -static doubleEscape := "\\\\"; -static invalidEscapes := b"({`."; +var doubleEscape := "\\\\"; +var invalidEscapes := b"({`."; public func smart_quote(s: string, raw: bool := false) -> string { if s.len == 0 { diff --git a/lib/rivet/src/utils/version.ri b/lib/rivet/src/utils/version.ri index f242152c5..56b35937f 100644 --- a/lib/rivet/src/utils/version.ri +++ b/lib/rivet/src/utils/version.ri @@ -4,7 +4,7 @@ import std/process; -public static version := "0.1.0a"; +public var version := "0.1.0a"; public func last_commit_hash() -> string { if result := process.execute("git log -n 1 --pretty=format:%h") { diff --git a/lib/rivet/tests/tokenizer.ri b/lib/rivet/tests/tokenizer.ri index afce61740..fc3b5989f 100644 --- a/lib/rivet/tests/tokenizer.ri +++ b/lib/rivet/tests/tokenizer.ri @@ -7,7 +7,7 @@ import rivet/token; import rivet/tokenizer; import { Table } from rivet/ast; -static prefs_ := prefs.Prefs(); +var prefs_ := prefs.Prefs(); func tokenize(text: string) -> []token.Token { mut tokenizer_ := tokenizer.Tokenizer.new(text, prefs_, Table.new(prefs_)); diff --git a/lib/std/src/dynlib/mod.ri b/lib/std/src/dynlib/mod.ri index 00718d98e..b05f5c482 100644 --- a/lib/std/src/dynlib/mod.ri +++ b/lib/std/src/dynlib/mod.ri @@ -8,7 +8,7 @@ import c/libc; -public static sharedLibExtension := get_shared_library_extension(); +public var sharedLibExtension := get_shared_library_extension(); /// Returns a library name with the operating system specific extension for shared /// libraries. diff --git a/lib/std/src/env/mod.ri b/lib/std/src/env/mod.ri index 1a017c891..af95fa640 100644 --- a/lib/std/src/env/mod.ri +++ b/lib/std/src/env/mod.ri @@ -6,7 +6,7 @@ import core; import c/libc; /// User's home directory. -public static homeDir := get(#if _LINUX_ "HOME" #else "USERPROFILE" #endif) ?? ""; +public var homeDir := get(#if _LINUX_ "HOME" #else "USERPROFILE" #endif) ?? ""; /// Returns `true` if the environment variable exists. #[inline] diff --git a/lib/std/src/flag/mod.ri b/lib/std/src/flag/mod.ri index efdf33e32..9b4efa284 100644 --- a/lib/std/src/flag/mod.ri +++ b/lib/std/src/flag/mod.ri @@ -9,7 +9,7 @@ import ../console; import ../process; public const MAX_ARGS_NUMBER := 4048; -public static space := " "; +public var space := " "; /// Data object storing information about a defined flag. public struct Flag < traits.Stringable { diff --git a/lib/std/src/fs/Path.ri b/lib/std/src/fs/Path.ri index 89329784d..be97794b2 100644 --- a/lib/std/src/fs/Path.ri +++ b/lib/std/src/fs/Path.ri @@ -11,8 +11,8 @@ import ../conv; public struct Path { public alias MAX_LEN := libc.MAX_PATH_LEN; public const SEPARATOR := #if _WINDOWS_ b'\\' #else b'/' #endif; - public static separatorStr := #if _WINDOWS_ "\\" #else "/" #endif; - public static delimiter := #if _WINDOWS_ ";" #else ":" #endif; + public var separatorStr := #if _WINDOWS_ "\\" #else "/" #endif; + public var delimiter := #if _WINDOWS_ ";" #else ":" #endif; /// Returns `true` if the given byte is a valid path separator #[inline] diff --git a/lib/std/src/process/mod.ri b/lib/std/src/process/mod.ri index 61bc04892..54619b290 100644 --- a/lib/std/src/process/mod.ri +++ b/lib/std/src/process/mod.ri @@ -15,9 +15,9 @@ public alias exit := core.process_exit; public alias get_cwd := core.process_get_cwd; public alias executable := core.process_executable; -public static args := core.ARGS; -public static wdAtStartup := get_cwd() catch "."; -public static executableDir := Path.dir_name(executable() catch wdAtStartup); +public var args := core.ARGS; +public var wdAtStartup := get_cwd() catch "."; +public var executableDir := Path.dir_name(executable() catch wdAtStartup); #[boxed] public struct NotADirectoryError < Throwable { diff --git a/lib/std/src/semver/parse.ri b/lib/std/src/semver/parse.ri index 9d98576cf..1c7c0eb00 100644 --- a/lib/std/src/semver/parse.ri +++ b/lib/std/src/semver/parse.ri @@ -7,7 +7,7 @@ import { string_to_uint } from std/conv; const VER_MAJOR: uint64 := 0; const VER_MINOR: uint64 := 1; const VER_PATCH: uint64 := 2; -static versions := [VER_MAJOR, VER_MINOR, VER_PATCH]; +var versions := [VER_MAJOR, VER_MINOR, VER_PATCH]; struct RawVersion { prerelease: string; diff --git a/lib/std/src/semver/range.ri b/lib/std/src/semver/range.ri index 8feb61d77..6764ccb87 100644 --- a/lib/std/src/semver/range.ri +++ b/lib/std/src/semver/range.ri @@ -2,10 +2,10 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -static comparatorSep := " "; -static comparatorSetSep := " || "; -static hyphenRangeSep := " - "; -static xRangeSymbols := "Xx*"; +var comparatorSep := " "; +var comparatorSetSep := " || "; +var hyphenRangeSep := " - "; +var xRangeSymbols := "Xx*"; enum Operator as uint8 { Gt, diff --git a/lib/std/tests/fs_test.ri b/lib/std/tests/fs_test.ri index 08a08ef03..2ad860f4e 100644 --- a/lib/std/tests/fs_test.ri +++ b/lib/std/tests/fs_test.ri @@ -2,7 +2,7 @@ import std/env; import std/process; import { Path, Directory } from std/fs; -static cwd := process.get_cwd() catch "."; +var cwd := process.get_cwd() catch "."; test "std.fs.Directory.tmp_dir()" { @assert(Directory.tmp_dir() == "/tmp"); diff --git a/lib/std/tests/semver_test.ri b/lib/std/tests/semver_test.ri index c3d815ef3..1bd51b192 100644 --- a/lib/std/tests/semver_test.ri +++ b/lib/std/tests/semver_test.ri @@ -20,7 +20,7 @@ struct TestCoerce { valid: string; } -static versionToTest := [ +var versionToTest := [ TestVersion("1.2.4", 1, 2, 4, "", ""), TestVersion("1.2.4-prerelease-1", 1, 2, 4, "prerelease-1", ""), TestVersion("1.2.4+20191231", 1, 2, 4, "", "20191231"), @@ -28,7 +28,7 @@ static versionToTest := [ TestVersion("1.2.4+20191231-prerelease-1", 1, 2, 4, "", "20191231-prerelease-1") ]; -static rangesToTest := [ +var rangesToTest := [ TestRange("1.1.0", "1.1.0", "1.1.1"), TestRange("1.1.0", "=1.1.0", "=1.1.1"), TestRange("1.1.0", ">=1.0.0", "<1.1.0"), @@ -49,7 +49,7 @@ static rangesToTest := [ TestRange("2.3.4", "*", "3.x") ]; -static coerceToTest := [ +var coerceToTest := [ TestCoerce("1.2.0.4", "1.2.0"), TestCoerce("1.2.0", "1.2.0"), TestCoerce("1.2", "1.2.0"), @@ -59,7 +59,7 @@ static coerceToTest := [ TestCoerce("1-alpha+meta", "1.0.0-alpha+meta") ]; -static invalidVersionToTest := [ +var invalidVersionToTest := [ "a.b.c", "1.2", "1.2.x", @@ -68,7 +68,7 @@ static invalidVersionToTest := [ "1.2.3+meta%" ]; -static invalidRangesToTest := [ +var invalidRangesToTest := [ "^a", "~b", "a - c", diff --git a/rivetc/src/ast.py b/rivetc/src/ast.py index 256c00e2b..6238ad41f 100644 --- a/rivetc/src/ast.py +++ b/rivetc/src/ast.py @@ -166,7 +166,7 @@ def __init__( self.sym = None self.pos = pos -class StaticDecl: +class VarDecl: def __init__( self, docs, attributes, is_public, is_extern, abi, lefts, right, pos ): @@ -304,7 +304,7 @@ def __init__(self, scope, name, stmts, pos): self.defer_stmts = [] # ------ Statements -------- -class StaticDeclStmt: +class VarDeclStmt: def __init__(self, scope, lefts, right, pos): self.lefts = lefts self.right = right diff --git a/rivetc/src/checker.py b/rivetc/src/checker.py index 6c906f6c4..88fb0fee3 100644 --- a/rivetc/src/checker.py +++ b/rivetc/src/checker.py @@ -28,7 +28,7 @@ def __init__(self, comp): def check_global_vars(self, decls): for decl in decls: old_sym = self.sym - if isinstance(decl, (ast.ConstDecl, ast.StaticDecl)): + if isinstance(decl, (ast.ConstDecl, ast.VarDecl)): self.check_decl(decl) elif hasattr(decl, "decls"): self.check_global_vars(decl.decls) @@ -66,7 +66,7 @@ def check_files(self, source_files): def check_decls(self, decls): for decl in decls: - if not isinstance(decl, (ast.ConstDecl, ast.StaticDecl)): + if not isinstance(decl, (ast.ConstDecl, ast.VarDecl)): self.check_decl(decl) def check_decl(self, decl): @@ -86,7 +86,7 @@ def check_decl(self, decl): else: decl.typ = self.check_expr(decl.expr) decl.sym.typ = decl.typ - elif isinstance(decl, ast.StaticDecl): + elif isinstance(decl, ast.VarDecl): self.inside_var_decl = True left0 = decl.lefts[0] if left0.has_typ: @@ -212,7 +212,7 @@ def check_stmts(self, stmts): self.check_stmt(stmt) def check_stmt(self, stmt): - if isinstance(stmt, ast.StaticDeclStmt): + if isinstance(stmt, ast.VarDeclStmt): old_expected_type = self.expected_type if len(stmt.lefts) == 1: if stmt.lefts[0].has_typ: diff --git a/rivetc/src/codegen/__init__.py b/rivetc/src/codegen/__init__.py index 12acea22c..e2052eda2 100644 --- a/rivetc/src/codegen/__init__.py +++ b/rivetc/src/codegen/__init__.py @@ -338,7 +338,7 @@ def gen_decl(self, decl): self.cur_fn_defer_stmts = [] if isinstance(decl, ast.ExternDecl): self.gen_decls(decl.decls) - elif isinstance(decl, ast.StaticDecl): + elif isinstance(decl, ast.VarDecl): self.inside_var_decl = True for l in decl.lefts: is_extern = decl.is_extern and decl.abi != sym.ABI.Rivet @@ -595,7 +595,7 @@ def gen_stmt(self, stmt): self.loop_exit_label = old_exit_label self.loop_scope = old_loop_scope self.while_continue_expr = old_while_continue_expr - elif isinstance(stmt, ast.StaticDeclStmt): + elif isinstance(stmt, ast.VarDeclStmt): if len(stmt.lefts) == 1: left = stmt.lefts[0] left_ir_typ = self.ir_type(left.typ) diff --git a/rivetc/src/parser.py b/rivetc/src/parser.py index 5f9f6e84d..a56d1167c 100644 --- a/rivetc/src/parser.py +++ b/rivetc/src/parser.py @@ -239,7 +239,7 @@ def parse_decl(self): doc_comment, attributes, is_public, name, has_typ, typ, expr, pos ) - elif self.accept(Kind.KwStatic): + elif self.accept(Kind.KwVar): # variable declarations pos = self.prev_tok.pos lefts = [] @@ -257,7 +257,7 @@ def parse_decl(self): else: right = self.empty_expr() self.expect(Kind.Semicolon) - return ast.StaticDecl( + return ast.VarDecl( doc_comment, attributes, is_public, self.inside_extern, self.extern_abi, lefts, right, pos ) @@ -641,7 +641,7 @@ def parse_stmt(self): self.expect(Kind.DeclAssign) right = self.parse_expr() self.expect(Kind.Semicolon) - return ast.StaticDeclStmt(self.scope, lefts, right, pos) + return ast.VarDeclStmt(self.scope, lefts, right, pos) expr = self.parse_expr() if not ((self.inside_block and self.tok.kind == Kind.Rbrace) or expr.__class__ in (ast.IfExpr, ast.MatchExpr, ast.Block)): diff --git a/rivetc/src/register.py b/rivetc/src/register.py index 2b0ccbb49..93db7bd43 100644 --- a/rivetc/src/register.py +++ b/rivetc/src/register.py @@ -69,7 +69,7 @@ def walk_decls(self, decls): decl.is_public, decl.name, decl.typ, decl.expr ) self.add_sym(decl.sym, decl.pos) - elif isinstance(decl, ast.StaticDecl): + elif isinstance(decl, ast.VarDecl): for v in decl.lefts: try: v_sym = sym.Var( diff --git a/rivetc/src/resolver.py b/rivetc/src/resolver.py index 69fcde7db..af60528e8 100644 --- a/rivetc/src/resolver.py +++ b/rivetc/src/resolver.py @@ -32,7 +32,7 @@ def resolve_decls(self, decls): elif isinstance(decl, ast.ConstDecl): self.resolve_type(decl.typ) self.resolve_expr(decl.expr) - elif isinstance(decl, ast.StaticDecl): + elif isinstance(decl, ast.VarDecl): for v in decl.lefts: self.resolve_type(v.typ) if not decl.is_extern: @@ -161,7 +161,7 @@ def resolve_decls(self, decls): self.self_sym = old_self_sym def resolve_stmt(self, stmt): - if isinstance(stmt, ast.StaticDeclStmt): + if isinstance(stmt, ast.VarDeclStmt): for v in stmt.lefts: if v.has_typ: self.resolve_type(v.typ) diff --git a/rivetc/src/token.py b/rivetc/src/token.py index a34595d7f..d10808953 100644 --- a/rivetc/src/token.py +++ b/rivetc/src/token.py @@ -90,7 +90,6 @@ class Kind(Enum): KwReturn = auto_enum() # return KwSelf = auto_enum() # self KwSelfTy = auto_enum() # Self - KwStatic = auto_enum() # static KwStruct = auto_enum() # struct KwMatch = auto_enum() # match KwTest = auto_enum() # test @@ -98,6 +97,7 @@ class Kind(Enum): KwTrait = auto_enum() # trait KwTrue = auto_enum() # true KwUnsafe = auto_enum() # unsafe + KwVar = auto_enum() # var KwWhile = auto_enum() # while # ============================== @@ -235,7 +235,6 @@ def __str__(self): Kind.KwReturn: "return", Kind.KwSelf: "self", Kind.KwSelfTy: "Self", - Kind.KwStatic: "static", Kind.KwStruct: "struct", Kind.KwMatch: "match", Kind.KwTest: "test", @@ -243,6 +242,7 @@ def __str__(self): Kind.KwTrait: "trait", Kind.KwTrue: "true", Kind.KwUnsafe: "unsafe", + Kind.KwVar: "var", Kind.KwWhile: "while", # ============================== } diff --git a/tests/valid/src/declarations.ri b/tests/valid/src/declarations.ri index 525776413..676980326 100644 --- a/tests/valid/src/declarations.ri +++ b/tests/valid/src/declarations.ri @@ -1,4 +1,4 @@ -static myVar := 1; +var myVar := 1; const MY_CONST := 5; test "implicitly typed variable" { @@ -9,9 +9,9 @@ test "implicitly typed constant" { @assert(MY_CONST == 5); } -static myArray := [1, 2, 3, 4]!; +var myArray := [1, 2, 3, 4]!; -test "global static array" { +test "global var array" { @assert(myArray.len == 4); @assert(myArray[0] == 1); @assert(myArray[1] == 2); diff --git a/tests/valid/src/overloadable_operators.ri b/tests/valid/src/overloadable_operators.ri index 2801de85d..40c59cfb0 100644 --- a/tests/valid/src/overloadable_operators.ri +++ b/tests/valid/src/overloadable_operators.ri @@ -19,7 +19,7 @@ struct Vec { } } -static vec := Vec(2, 2); +var vec := Vec(2, 2); test "overloadable operators: +" { mut v1 := vec; diff --git a/tests/valid/src/results.ri b/tests/valid/src/results.ri index d4e6be21d..05a2784f7 100644 --- a/tests/valid/src/results.ri +++ b/tests/valid/src/results.ri @@ -18,9 +18,9 @@ func result3() -> !int32 { return 5; } -static resultValue := result3()!; +var resultValue := result3()!; -test "propagate result in `static` declaration" { +test "propagate result in `var` declaration" { @assert(resultValue == 5); }