diff --git a/lib/c/src/errno.ri b/lib/c/src/errno.ri index 9360a2d3c..9109b0024 100644 --- a/lib/c/src/errno.ri +++ b/lib/c/src/errno.ri @@ -26,7 +26,7 @@ public func errno() -> int32 { } #[inline] -public func errno_msg(code: int32 = errno()) -> string { +public func errno_msg(code: int32 := errno()) -> string { unsafe { return if s := libc.strerror(code) { string.from_raw(s) diff --git a/lib/core/src/StringBuilder.c.ri b/lib/core/src/StringBuilder.c.ri index ae254149a..c743da11b 100644 --- a/lib/core/src/StringBuilder.c.ri +++ b/lib/core/src/StringBuilder.c.ri @@ -10,7 +10,7 @@ public struct StringBuilder < Stringable { /// Returns a string builder with capacity `cap`. #[inline] - public func new(cap: usize = 0) -> Self { + public func new(cap: usize := 0) -> Self { return Self(unsafe { Vector.new(@size_of(uint8), cap) }); } @@ -54,7 +54,7 @@ public struct StringBuilder < Stringable { } } - public func writeln(mut self, s: string = "") { + public func writeln(mut self, s: string := "") { if s.len > 0 { unsafe { self.write_raw_with_len(s.ptr, s.len); @@ -63,7 +63,7 @@ public struct StringBuilder < Stringable { self.write_byte(b'\n'); } - public func write_join(mut self, ss: []string, sep: string = "") { + public func write_join(mut self, ss: []string, sep: string := "") { if ss.len == 1 { self.write_string(ss[0]); } else { diff --git a/lib/core/src/Vector.c.ri b/lib/core/src/Vector.c.ri index e0142ccc0..ca29f4529 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: usize, size: usize = 1, no_slices: bool = false) { + public func delete(mut self, i: usize, size: usize := 1, no_slices: bool := false) { if i + size > self.len { end_idx := if size == 1 { "..{}".fmt(i + size) } else { "" }; process_panic( diff --git a/lib/core/src/backtrace.c.ri b/lib/core/src/backtrace.c.ri index f4676c5f4..df7cfbc41 100644 --- a/lib/core/src/backtrace.c.ri +++ b/lib/core/src/backtrace.c.ri @@ -76,7 +76,7 @@ func bt_error_handler(data: mut_anyptr, msg_ptr: ?[&]mut uint8, errnum: int32) { } #endif -public func bt_print(frames_to_skip: int32 = 0) { +public func bt_print(frames_to_skip: int32 := 0) { #if _RELEASE_ _ = frames_to_skip; #else diff --git a/lib/core/src/console.c.ri b/lib/core/src/console.c.ri index 161a6d107..6c23a8a13 100644 --- a/lib/core/src/console.c.ri +++ b/lib/core/src/console.c.ri @@ -15,7 +15,7 @@ public func console_print(s: string, args: ...Stringable) { /// Prints a message with a line end to stdout. stdout is flushed. #[inline] -public func console_println(s: string = "", args: ...Stringable) { +public func console_println(s: string := "", args: ...Stringable) { unsafe { writeln_to_fd(1, s.fmt(args)); } @@ -34,7 +34,7 @@ public func console_eprint(s: string, args: ...Stringable) { /// Prints a message with a line end to stderr. Both stderr and stdout are /// flushed. -public func console_eprintln(s: string = "", args: ...Stringable) { +public func console_eprintln(s: string := "", args: ...Stringable) { unsafe { _ = libc.fflush(libc.stdout); _ = libc.fflush(libc.stderr); @@ -51,9 +51,8 @@ public func console_is_atty(fd: int32) -> bool { } #[unsafe] -func write_buf_to_fd(fd: int32, buf_: [&]uint8, len: usize) { +func write_buf_to_fd(fd: int32, buf: [&]uint8, len: usize) { unsafe { - buf := buf_; mut x: isize := 0; mut remaining_bytes := @as(isize, len); while remaining_bytes > 0 { diff --git a/lib/core/src/process.c.ri b/lib/core/src/process.c.ri index 74ecb5fd9..593eebddd 100644 --- a/lib/core/src/process.c.ri +++ b/lib/core/src/process.c.ri @@ -45,7 +45,7 @@ public func process_id() -> uint32 { /// Terminates current thread execution immediately after displaying a /// message, followed by a backtrace. -public func process_panic(s: string = "", args: ...Stringable) -> never { +public func process_panic(s: string := "", args: ...Stringable) -> never { console_eprintln("panic: {}", s.fmt(args)); bt_print(2); process_exit(101); @@ -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 { +public func process_exit(code: int32 := 0) -> never { unsafe { drop_globals(); libc.exit(code); diff --git a/lib/core/src/string.c.ri b/lib/core/src/string.c.ri index e0ac02ff7..7bedceeb8 100644 --- a/lib/core/src/string.c.ri +++ b/lib/core/src/string.c.ri @@ -13,7 +13,7 @@ public struct string < Stringable, Hashable, Throwable { is_ref: bool; #[unsafe] - public func from_raw(ptr: ?[&]uint8, is_ref: bool = false) -> Self { + public 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: usize, is_ref: bool = false) -> Self { + public func from_raw_with_len(ptr: ?[&]uint8, len: usize, is_ref: bool := false) -> Self { if len == 0 { return emptyString; } @@ -131,7 +131,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Wraps the given string within `width` in characters. - public func wrap(self, width: usize = 60, end: Self = "\n") -> Self { + public func wrap(self, width: usize := 60, end: Self := "\n") -> Self { words := self.fields(); if words.len == 0 { return emptyString; @@ -410,7 +410,7 @@ public struct string < Stringable, Hashable, Throwable { } /// Replaces all occurences of `rep` with the string passed in `with_`. - public func replace(self, rep: Self, with_: Self) -> Self { + public 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) { @@ -426,7 +426,7 @@ public struct string < Stringable, Hashable, Throwable { if idxs.len == 0 { return self; } - new_len := self.len + idxs.len * (with_.len - rep.len); + new_len := self.len + idxs.len * (with.len - rep.len); b := unsafe { @as([&]mut uint8, internal_alloc(new_len)) }; (mut b_i: usize, mut s_idx: usize) := (0, 0); unsafe { @@ -438,8 +438,8 @@ public struct string < Stringable, Hashable, Throwable { } s_idx = rep_pos + rep.len; i = 0; - while i < with_.len : i += 1 { - b[b_i] = with_.ptr[i]; + while i < with.len : i += 1 { + b[b_i] = with.ptr[i]; b_i += 1; } } @@ -496,7 +496,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: usize = 0) -> []Self { + public func split(self, delim: Self, nth: usize := 0) -> []Self { mut i: usize := 0; mut res := @vec(Self); match delim.len { diff --git a/lib/core/src/wyhash.c.ri b/lib/core/src/wyhash.c.ri index dd6612d39..2e51168de 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 { +public 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 { +public 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/Table.ri b/lib/rivet/src/ast/Table.ri index 53859f8c1..19f3cb943 100644 --- a/lib/rivet/src/ast/Table.ri +++ b/lib/rivet/src/ast/Table.ri @@ -287,7 +287,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) -> (usize, usize) { + public func type_size(mut self, type: Type, is_raw: bool := false) -> (usize, usize) { return match type is { .Result, .Option => self.type_symbol_size(self.throwable_sym, is_raw), .Anyptr, .Pointer, .Func => (self.pointer_size, self.pointer_size), @@ -299,7 +299,7 @@ public struct Table { }; } - public func type_symbol_size(mut self, mut type_sym: TypeSym, is_raw: bool = false) -> (usize, usize) { + public func type_symbol_size(mut self, mut type_sym: TypeSym, is_raw: bool := false) -> (usize, usize) { return if type_sym.size != 0 { (type_sym.size, type_sym.align) } else { diff --git a/lib/rivet/src/ast/mod.ri b/lib/rivet/src/ast/mod.ri index d4386e201..09e0929c6 100644 --- a/lib/rivet/src/ast/mod.ri +++ b/lib/rivet/src/ast/mod.ri @@ -30,7 +30,7 @@ public struct ImportedSymbols { public mut syms: []ImportedSymbol; #[inline] - public func add(mut self, name: string, sym: Sym, pos: token.Pos, is_used: bool = false) { + public func add(mut self, name: string, sym: Sym, pos: token.Pos, is_used: bool := false) { self.syms.push(ImportedSymbol(name, sym, pos, is_used)); } diff --git a/lib/rivet/src/checker/mod.ri b/lib/rivet/src/checker/mod.ri index 105781ac5..b8bd90f60 100644 --- a/lib/rivet/src/checker/mod.ri +++ b/lib/rivet/src/checker/mod.ri @@ -238,7 +238,8 @@ public struct Checker { } func check_expr_is_mut( - self, expr: ast.Expr, from_assign: bool = false, from_selector: bool = false + self, expr: ast.Expr, from_assign: bool := false, + from_selector: bool := false ) { match expr is { .Paren as paren => self.check_expr_is_mut(paren.expr), @@ -396,7 +397,7 @@ public struct Checker { } } - func has_return(self, stmts: []ast.Stmt, allow_throw: bool = false) -> bool { + func has_return(self, stmts: []ast.Stmt, allow_throw: bool := false) -> bool { for stmt in stmts { if stmt is .Expr as expr and self.expr_has_return(expr, allow_throw) { return true; @@ -405,7 +406,7 @@ public struct Checker { return false; } - func expr_has_return(self, expr: ast.Expr, allow_throw: bool = false) -> bool { + func expr_has_return(self, expr: ast.Expr, allow_throw: bool := false) -> bool { return match expr is { .Match as match_expr => { for i, branch in match_expr.branches { diff --git a/lib/rivet/src/codegen/mod.ri b/lib/rivet/src/codegen/mod.ri index a47bbc2bb..1bb2bce97 100644 --- a/lib/rivet/src/codegen/mod.ri +++ b/lib/rivet/src/codegen/mod.ri @@ -156,7 +156,7 @@ public struct Codegen { }; } - func mangle_symbol(self, mut sym: ast.Sym, insert_r: bool = true) -> string { + func mangle_symbol(self, mut sym: ast.Sym, insert_r: bool := true) -> string { if sym.mangled_name.len > 0 { return sym.mangled_name; } diff --git a/lib/rivet/src/parser/decls.ri b/lib/rivet/src/parser/decls.ri index 68171b175..8a28c882a 100644 --- a/lib/rivet/src/parser/decls.ri +++ b/lib/rivet/src/parser/decls.ri @@ -20,7 +20,7 @@ extend Parser { } public func parse_attributes( - mut self, parse_mod_attributes: bool = false + mut self, parse_mod_attributes: bool := false ) -> ast.Attributes { mut attributes := ast.Attributes(); while self.accept(.Hash) { @@ -583,7 +583,7 @@ extend Parser { self.expect(.Colon); arg_type := self.parse_type(); is_variadic = arg_type is .Variadic; - arg_expr := if self.accept(.Assign) { + arg_expr := if self.accept(.DeclAssign) { has_named_args = true; self.parse_expr() } else { diff --git a/lib/rivet/src/parser/exprs.ri b/lib/rivet/src/parser/exprs.ri index a5a055239..ddc410fa3 100644 --- a/lib/rivet/src/parser/exprs.ri +++ b/lib/rivet/src/parser/exprs.ri @@ -777,7 +777,7 @@ extend Parser { ); } - func parse_ident(mut self, is_comptime: bool = false) -> ast.Expr { + func parse_ident(mut self, is_comptime: bool := false) -> ast.Expr { pos := if is_comptime { self.prev_tok.pos + self.tok.pos } else { diff --git a/lib/rivet/src/parser/mod.ri b/lib/rivet/src/parser/mod.ri index 79443b338..18a787355 100644 --- a/lib/rivet/src/parser/mod.ri +++ b/lib/rivet/src/parser/mod.ri @@ -123,8 +123,8 @@ public struct Parser { } func parse_var_decl( - mut self, inside_global: bool = false, support_type: bool = true, - support_ref: bool = false, support_mut: bool = true + mut self, inside_global: bool := false, support_type: bool := true, + support_ref: bool := false, support_mut: bool := true ) -> ast.ObjectData { pos := self.tok.pos; is_mut := support_mut and self.accept(.KwMut); diff --git a/lib/rivet/src/tokenizer/mod.ri b/lib/rivet/src/tokenizer/mod.ri index 8499cb9af..ebfabd07f 100644 --- a/lib/rivet/src/tokenizer/mod.ri +++ b/lib/rivet/src/tokenizer/mod.ri @@ -63,7 +63,7 @@ public struct Tokenizer { } #[inline] - func new_token(self, kind: token.Kind, lit: string = "", len: usize = 1) -> token.Token { + func new_token(self, kind: token.Kind, lit: string := "", len: usize := 1) -> token.Token { return token.Token(lit, kind, len, token.Pos( file: self.file, line: self.line, @@ -75,8 +75,8 @@ public struct Tokenizer { #[inline] func new_multiline_token( - self, kind: token.Kind, lit: string = "", len: usize = 1, - start_line: usize = 0, end_line: usize = 0, start_col: usize = 0 + self, kind: token.Kind, lit: string := "", len: usize := 1, + start_line: usize := 0, end_line: usize := 0, start_col: usize := 0 ) -> token.Token { return token.Token(lit, kind, len, token.Pos( file: self.file, @@ -225,22 +225,22 @@ public struct Tokenizer { } #[inline] - func error(self, msg: string, pos: token.Pos = self.current_pos()) { + func error(self, msg: string, pos: token.Pos := self.current_pos()) { report.error(msg, pos); } #[inline] - func warn(self, msg: string, pos: token.Pos = self.current_pos()) { + func warn(self, msg: string, pos: token.Pos := self.current_pos()) { report.warn(msg, pos); } #[inline] - func error_builder(self, msg: string, pos: token.Pos = self.current_pos()) -> report.ReportBuilder { + func error_builder(self, msg: string, pos: token.Pos := self.current_pos()) -> report.ReportBuilder { return report.error_builder(msg, pos); } #[inline] - func warn_builder(self, msg: string, pos: token.Pos = self.current_pos()) -> report.ReportBuilder { + func warn_builder(self, msg: string, pos: token.Pos := self.current_pos()) -> report.ReportBuilder { return report.warn_builder(msg, pos); } } diff --git a/lib/rivet/src/utils/smart_quote.ri b/lib/rivet/src/utils/smart_quote.ri index b4a8c2467..021e21e4f 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; static doubleEscape := "\\\\"; static invalidEscapes := b"({`."; -public func smart_quote(s: string, raw: bool = false) -> string { +public 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/version.ri b/lib/rivet/src/utils/version.ri index 9f2104306..f242152c5 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.0b"; +public static 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/std/src/console/mod.ri b/lib/std/src/console/mod.ri index 75d75c3e3..e5c14787d 100644 --- a/lib/std/src/console/mod.ri +++ b/lib/std/src/console/mod.ri @@ -13,7 +13,7 @@ public 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 { +public func readln(prompt: string := "") -> ?string { if prompt.len > 0 { print(prompt); } diff --git a/lib/std/src/env/mod.ri b/lib/std/src/env/mod.ri index 373c6ea14..1a017c891 100644 --- a/lib/std/src/env/mod.ri +++ b/lib/std/src/env/mod.ri @@ -27,7 +27,7 @@ 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) -> ! { +public func set(name: string, value: string, overwrite: bool := true) -> ! { if unsafe { libc.setenv(name.ptr, value.ptr, overwrite) == -1 } { throw core.last_errno_error(); } diff --git a/lib/std/src/fs/Directory.ri b/lib/std/src/fs/Directory.ri index 9704a6f54..ac47a2155 100644 --- a/lib/std/src/fs/Directory.ri +++ b/lib/std/src/fs/Directory.ri @@ -42,7 +42,7 @@ public struct EmptyStringError < Throwable { } public struct Directory { - public func make(path_: string, mode: usize = 0o777) -> ! { + public func make(path_: string, mode: usize := 0o777) -> ! { if path_ == "." { return; } @@ -61,7 +61,7 @@ public struct Directory { } } - public func walk(path_: string, ext: string = "") -> ![]string { + public 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 66fb3cffb..05fd88b98 100644 --- a/lib/std/src/fs/File.ri +++ b/lib/std/src/fs/File.ri @@ -21,7 +21,7 @@ public struct File { f: &mut libc.FILE; mut is_opened: bool; - public func open(path: string, mode: string = "r") -> !File { + public func open(path: string, mode: string := "r") -> !File { unsafe { if f := libc.fopen(path.ptr, mode.ptr) { return Self(f, true); diff --git a/lib/std/src/strings/TextScanner.ri b/lib/std/src/strings/TextScanner.ri index 5313bec7d..a1060ad8c 100644 --- a/lib/std/src/strings/TextScanner.ri +++ b/lib/std/src/strings/TextScanner.ri @@ -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: usize = 1) { + public func skip(mut self, n: usize := 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: usize = 0) -> ?uint8 { + public func peek(&self, n: usize := 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: usize = 1) { + public func back(mut self, n: usize := 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: usize = 1) -> ?uint8 { + public func peek_back(&self, n: usize := 1) -> ?uint8 { offset := n + 1; if self.pos >= offset { return self.input[self.pos - offset]; diff --git a/rivetc/src/parser.py b/rivetc/src/parser.py index adff6c237..ad3832a22 100644 --- a/rivetc/src/parser.py +++ b/rivetc/src/parser.py @@ -492,7 +492,7 @@ def parse_func_decl( arg_typ = self.parse_type() is_variadic = isinstance(arg_typ, type.Variadic) arg_expr = self.empty_expr() - if self.accept(Kind.Assign): + if self.accept(Kind.DeclAssign): has_named_args = True arg_expr = self.parse_expr() args.append( diff --git a/tests/valid/src/call_expr.ri b/tests/valid/src/call_expr.ri index dac736689..905f5d0f0 100644 --- a/tests/valid/src/call_expr.ri +++ b/tests/valid/src/call_expr.ri @@ -1,4 +1,4 @@ -func default_arg(x: int32 = 1) { +func default_arg(x: int32 := 1) { @assert(x == 1 or x == 5 or x == 10); } @@ -8,9 +8,9 @@ test "call expression with default arguments" { default_arg(x: 10); } -func foo(_a: bool = false, _b: bool = false) { } +func foo(_a: bool := false, _b: bool := false) { } -func bar(_a: bool, _b: bool = true) { } +func bar(_a: bool, _b: bool := true) { } func baz(_a: bool, _b: bool) { }