diff --git a/cmd/src/utils/mod.ri b/cmd/src/utils/mod.ri index 899741c97..428b1c332 100644 --- a/cmd/src/utils/mod.ri +++ b/cmd/src/utils/mod.ri @@ -5,7 +5,7 @@ import std/console; import std/console/styles; -@[inline] +#[inline] public func readln(prompt: string) -> ?string { prefix := styles.bold(styles.green("> ")); return if prompt.is_empty() { diff --git a/lib/c/src/errno.ri b/lib/c/src/errno.ri index 9169e3a36..9360a2d3c 100644 --- a/lib/c/src/errno.ri +++ b/lib/c/src/errno.ri @@ -4,7 +4,7 @@ import c/libc; -@[boxed] +#[boxed] public struct ErrnoError < Throwable { public msg: string; public code: int32; @@ -14,7 +14,7 @@ public struct ErrnoError < Throwable { } } -@[inline] +#[inline] public func errno() -> int32 { return unsafe { #if _LINUX_ @@ -25,7 +25,7 @@ public func errno() -> int32 { }; } -@[inline] +#[inline] public func errno_msg(code: int32 = errno()) -> string { unsafe { return if s := libc.strerror(code) { @@ -36,7 +36,7 @@ public func errno_msg(code: int32 = errno()) -> string { } } -@[inline] +#[inline] public func last_errno_error() -> ErrnoError { return ErrnoError(errno_msg(), errno()); } diff --git a/lib/c/src/wyhash.ri b/lib/c/src/wyhash.ri index f5f31b2a8..38f061bc0 100644 --- a/lib/c/src/wyhash.ri +++ b/lib/c/src/wyhash.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@![compile_c_source("../thirdparty/wyhash/wyhash.c")] +#![compile_c_source("../thirdparty/wyhash/wyhash.c")] extern (C) { // the default secret parameters diff --git a/lib/core/src/StaticBuffer.ri b/lib/core/src/StaticBuffer.ri index 171e21117..4419b97fc 100644 --- a/lib/core/src/StaticBuffer.ri +++ b/lib/core/src/StaticBuffer.ri @@ -31,7 +31,7 @@ struct StaticBuffer { return unsafe { string.from_raw_with_len(&self.buf[0], self.len).clone() }; } - @[inline] + #[inline] public func clear(mut self) { self.len = 0; } diff --git a/lib/core/src/StringBuilder.ri b/lib/core/src/StringBuilder.ri index 650320f32..62b42ab85 100644 --- a/lib/core/src/StringBuilder.ri +++ b/lib/core/src/StringBuilder.ri @@ -4,17 +4,17 @@ import c/libc; -@[boxed] +#[boxed] public struct StringBuilder < Stringable { mut inner: Vector; /// Returns a string builder with capacity `cap`. - @[inline] + #[inline] public func new(cap: usize = 0) -> Self { return Self(unsafe { Vector.new(@size_of(uint8), cap) }); } - @[inline] + #[inline] public func from_string(s: string) -> Self { return if s.len == 0 { Self.new() @@ -25,19 +25,19 @@ public struct StringBuilder < Stringable { }; } - @[inline] + #[inline] public func write_byte(mut self, val: uint8) { self.inner.push(&val); } - @[unsafe; inline] + #[unsafe; inline] public func write_raw(mut self, s: [*]uint8) { unsafe { self.write_raw_with_len(s, libc.strlen(s)); } } - @[unsafe] + #[unsafe] public func write_raw_with_len(mut self, s: [*]uint8, len: usize) { self.inner.reserve(self.inner.len + len); mem_copy( @@ -47,7 +47,7 @@ public struct StringBuilder < Stringable { self.inner.len += len; } - @[inline] + #[inline] public func write_string(mut self, s: string) { unsafe { self.write_raw_with_len(s.ptr, s.len); @@ -76,7 +76,7 @@ public struct StringBuilder < Stringable { } } - @[inline] + #[inline] public func write_fmt(mut self, s: string, args: ...Stringable) { self.write_string(s.fmt(args)); } @@ -87,32 +87,32 @@ public struct StringBuilder < Stringable { } /// Returns the number of runes contained in `self`. - @[inline] + #[inline] public func runes_count(self) -> usize { return cstr_runes_count(unsafe { @as([*]uint8, self.inner.ptr) }, self.inner.len); } - @[inline] + #[inline] public func clear(mut self) { self.inner.clear(); } - @[inline] + #[inline] public func len(self) -> usize { return self.inner.len; } - @[inline] + #[inline] public func cap(self) -> usize { return self.inner.cap; } - @[inline] + #[inline] public func is_empty(self) -> bool { return self.inner.is_empty(); } - @[inline] + #[inline] public 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/Vector.ri b/lib/core/src/Vector.ri index daba0ec7c..46dd3482c 100644 --- a/lib/core/src/Vector.ri +++ b/lib/core/src/Vector.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@[boxed] +#[boxed] struct Vector { mut ptr: mut_anyptr; elem_size: usize; @@ -10,29 +10,29 @@ struct Vector { mut cap: usize; is_ref: bool; - @[unsafe; inline] + #[unsafe; inline] func new(elem_size: usize, cap: usize) -> Self { return Self(internal_zeroed(cap * elem_size), elem_size, 0, cap); } - @[unsafe; inline] + #[unsafe; inline] func new_with_len(elem_size: usize, len: usize, cap: usize) -> Self { return Self(internal_zeroed(cap * elem_size), elem_size, len, cap); } - @[unsafe] + #[unsafe] func from_array(arr: mut_anyptr, elem_size: usize, len: usize) -> Self { vec := Self(internal_zeroed(len * elem_size), elem_size, len, len); mem_copy(vec.ptr, arr, len * elem_size); return vec; } - @[unsafe; inline] + #[unsafe; inline] func from_array_no_alloc(arr: mut_anyptr, elem_size: usize, len: usize) -> Self { return Self(arr, elem_size, len, len, is_ref: true); } - @[unsafe; inline] + #[unsafe; inline] func raw_get(self, idx: usize) -> mut_anyptr { return unsafe { @ptr_add(@as([*]mut uint8, self.ptr), idx * self.elem_size) }; } @@ -122,7 +122,7 @@ struct Vector { self.len = 0; } - @[inline] + #[inline] func is_empty(self) -> bool { return self.len == 0; } @@ -134,7 +134,7 @@ struct Vector { return mem_cmp(self.ptr, rhs.ptr, self.len) == 0; } - @[inline] + #[inline] func !=(self, rhs: Self) -> bool { return !(self == rhs); } @@ -170,7 +170,7 @@ struct Vector { ); } - @[inline] + #[inline] func slice_from(self, start: usize) -> Self { return self.slice(start, self.len); } diff --git a/lib/core/src/array.ri b/lib/core/src/array.ri index 90f218d9c..dcbfa64cb 100644 --- a/lib/core/src/array.ri +++ b/lib/core/src/array.ri @@ -10,12 +10,12 @@ func array_index(len: usize, idx: usize) { } } -@[inline] +#[inline] func array_eq(arr: anyptr, other_arr: anyptr, len: usize) -> bool { return unsafe { libc.memcmp(arr, other_arr, len) == 0 }; } -@[inline] +#[inline] func array_ne(arr: anyptr, other_arr: anyptr, len: usize) -> bool { return !array_eq(arr, other_arr, len); } @@ -32,7 +32,7 @@ func array_slice(arr: mut_anyptr, elem_size: usize, size: usize, start: usize, e }; } -@[inline] +#[inline] func array_slice_from(arr: mut_anyptr, elem_size: usize, size: usize, start: usize) -> Vector { return array_slice(arr, elem_size, size, start, size); } diff --git a/lib/core/src/backtrace.ri b/lib/core/src/backtrace.ri index 3932e3389..f3ce7b757 100644 --- a/lib/core/src/backtrace.ri +++ b/lib/core/src/backtrace.ri @@ -4,7 +4,7 @@ #if !_RELEASE_ // skip backtrace in release mode -@![compile_c_source("../thirdparty/libbacktrace/backtrace.c")] +#![compile_c_source("../thirdparty/libbacktrace/backtrace.c")] import c; diff --git a/lib/core/src/bool.ri b/lib/core/src/bool.ri index 2fe92d8b3..888cd3c19 100644 --- a/lib/core/src/bool.ri +++ b/lib/core/src/bool.ri @@ -3,7 +3,7 @@ // be found in the LICENSE file. extend bool < Stringable { - @[inline] + #[inline] public func to_string(&self) -> string { return if self.* { "true" } else { "false" }; } diff --git a/lib/core/src/console.ri b/lib/core/src/console.ri index 15b34363a..7e25c3c8f 100644 --- a/lib/core/src/console.ri +++ b/lib/core/src/console.ri @@ -14,7 +14,7 @@ public func console_print(s: string, args: ...Stringable) { } /// Prints a message with a line end to stdout. stdout is flushed. -@[inline] +#[inline] public func console_println(s: string = "", args: ...Stringable) { unsafe { writeln_to_fd(1, s.fmt(args)); @@ -45,12 +45,12 @@ public func console_eprintln(s: string = "", args: ...Stringable) { /// Returns `true` if the `fd` file descriptor is open and refers to a /// terminal. -@[inline] +#[inline] public func console_is_atty(fd: int32) -> bool { return unsafe { libc.isatty(fd) == 1 }; } -@[unsafe] +#[unsafe] func write_buf_to_fd(fd: int32, buf_: [*]uint8, len: usize) { unsafe { buf := buf_; @@ -63,7 +63,7 @@ func write_buf_to_fd(fd: int32, buf_: [*]uint8, len: usize) { } } -@[unsafe] +#[unsafe] func writeln_to_fd(fd: int32, s: string) { unsafe { write_buf_to_fd(fd, s.ptr, s.len); diff --git a/lib/core/src/errors.ri b/lib/core/src/errors.ri index 458b1a27c..21f104ec1 100644 --- a/lib/core/src/errors.ri +++ b/lib/core/src/errors.ri @@ -14,38 +14,38 @@ public func last_errno_error() -> c.ErrnoError { /// This trait is used for errors returned with result types (!T). public trait Throwable < Stringable { } -@[inline] +#[inline] func error_panic(err: Throwable) { console_eprintln("unhandled error: {}", err.to_string()); returnTrace.print(); process_exit(1); } -@[boxed] +#[boxed] public struct InvalidArgumentError < Throwable { msg: string; - @[inline] + #[inline] public func to_string(self) -> string { return self.msg; } } -@[boxed] +#[boxed] public struct OutOfMemoryError < Throwable { msg: string; - @[inline] + #[inline] public func to_string(self) -> string { return self.msg; } } -@[boxed] +#[boxed] public struct ReadFailedError < Throwable { msg: string; - @[inline] + #[inline] public func to_string(self) -> string { return self.msg; } @@ -62,7 +62,7 @@ static returnTrace = ReturnTrace(); struct ReturnTrace { mut traces: []CallTrace = @vec(CallTrace, 5); - @[inline] + #[inline] func add(mut self, trace: CallTrace) { self.traces.push(trace); } diff --git a/lib/core/src/float.ri b/lib/core/src/float.ri index e463bfd14..1a38b6d0d 100644 --- a/lib/core/src/float.ri +++ b/lib/core/src/float.ri @@ -7,12 +7,12 @@ import c/libc; 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] + #[inline] public func bits(self) -> uint64 { return @as(float64, self).bits(); } - @[inline] + #[inline] public func to_string(&self) -> string { return @as(float64, self.*).to_string(); } @@ -22,14 +22,14 @@ extend float32 < Stringable { /// Returns the floating-point number corresponding to the IEEE 754 binary /// representation `b`, with the sign bit of b and the result in the same /// bit position. - @[inline] + #[inline] public 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] + #[inline] public func bits(&self) -> uint32 { return unsafe { @as(*uint32, self).* }; } @@ -51,14 +51,14 @@ extend float64 < Stringable { /// Returns the floating-point number corresponding to the IEEE 754 binary /// representation `b`, with the sign bit of b and the result in the same /// bit position. - @[inline] + #[inline] public 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] + #[inline] public func bits(&self) -> uint64 { return unsafe { @as(*uint64, self).* }; } diff --git a/lib/core/src/int.ri b/lib/core/src/int.ri index c2c3b4c67..95044de74 100644 --- a/lib/core/src/int.ri +++ b/lib/core/src/int.ri @@ -8,7 +8,7 @@ static digitPairs = "0010203040506070809001112131415161718191021222324252627" extend comptime_int < Stringable { /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return @as(int64, self.*).to_string(); } @@ -19,7 +19,7 @@ extend int8 < Stringable { public const MIN: int8 = -128; /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return @as(int32, self.*).str_l(5); } @@ -30,7 +30,7 @@ extend int16 < Stringable { public const MIN: int16 = -32768; /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return @as(int32, self.*).str_l(7); } @@ -88,7 +88,7 @@ extend int32 < Stringable { } /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return self.*.str_l(12); } @@ -152,13 +152,13 @@ extend isize < Stringable { public const MIN: isize = #if _x64_ int64.MIN #else int32.MIN #endif; public const MAX: isize = #if _x64_ int64.MAX #else int32.MAX #endif; - @[inline] + #[inline] public func bits() -> uint32 { return #if _x64_ 64 #else 32 #endif; } /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return @as(int64, self.*).to_string(); } diff --git a/lib/core/src/lib.ri b/lib/core/src/lib.ri index 0581816cd..50746070f 100644 --- a/lib/core/src/lib.ri +++ b/lib/core/src/lib.ri @@ -20,7 +20,7 @@ func assert(cond: bool, msg: string) { } } -@[inline] +#[inline] func internal_alloc(size: usize) -> mut_anyptr { return mem_alloc(size) catch { process_panic( @@ -29,7 +29,7 @@ func internal_alloc(size: usize) -> mut_anyptr { }; } -@[inline] +#[inline] func internal_zeroed(size: usize) -> mut_anyptr { return mem_zeroed(size) catch { process_panic( @@ -38,7 +38,7 @@ func internal_zeroed(size: usize) -> mut_anyptr { }; } -@[inline] +#[inline] func internal_dup(src: anyptr, sz: usize) -> mut_anyptr { return mem_dup(src, sz) catch { process_panic( @@ -47,7 +47,7 @@ func internal_dup(src: anyptr, sz: usize) -> mut_anyptr { }; } -@[inline] +#[inline] func internal_resize(ptr: ?mut_anyptr, sz: usize) -> mut_anyptr { return mem_resize(ptr, sz) catch { process_panic( diff --git a/lib/core/src/mem.ri b/lib/core/src/mem.ri index 03a4f2223..1291503ee 100644 --- a/lib/core/src/mem.ri +++ b/lib/core/src/mem.ri @@ -46,7 +46,7 @@ public func mem_resize(ptr: ?mut_anyptr, sz: usize) -> !mut_anyptr { /// Fills the first `n` bytes of the memory area pointed to by `s`, with the /// byte `c`. -@[inline] +#[inline] public func mem_set(s: mut_anyptr, c: uint8, n: usize) { unsafe { _ = libc.memset(s, @as(int32, c), n); @@ -57,7 +57,7 @@ public func mem_set(s: mut_anyptr, c: uint8, n: usize) { /// /// NOTE: The memory areas *MUST NOT OVERLAP*. Use `mem.move`, if the memory /// areas do overlap. -@[inline] +#[inline] public func mem_copy(dest: mut_anyptr, src: anyptr, sz: usize) { unsafe { _ = libc.memcpy(dest, src, sz); @@ -70,7 +70,7 @@ public func mem_copy(dest: mut_anyptr, src: anyptr, sz: usize) { /// in `src` are first copied into a temporary array that does not overlap /// `src` or `dest`, and the bytes are then copied from the temporary array to /// `dest`. -@[inline] +#[inline] public func mem_move(dest: mut_anyptr, src: anyptr, sz: usize) { unsafe { _ = libc.memmove(dest, src, sz); @@ -104,13 +104,13 @@ public func mem_dup(src: anyptr, sz: usize) -> !mut_anyptr { /// as cryptographic secrets, because the required CPU time depends on the /// number of equal bytes. You should use a function that performs comparisons /// in constant time for this. -@[inline] +#[inline] public func mem_cmp(s1: anyptr, s2: anyptr, n: usize) -> int32 { return unsafe { libc.memcmp(s1, s2, n) }; } /// Deallocates manually the memory referenced by `ptr`. -@[unsafe; inline] +#[unsafe; inline] public func mem_dealloc(ptr: anyptr) { unsafe { libc.free(ptr); diff --git a/lib/core/src/process.ri b/lib/core/src/process.ri index 5097f3fa4..74ecb5fd9 100644 --- a/lib/core/src/process.ri +++ b/lib/core/src/process.ri @@ -38,7 +38,7 @@ public func process_get_cwd() -> !string { /// Returns the OS-assigned process identifier associated with this /// process. -@[inline] +#[inline] public func process_id() -> uint32 { return unsafe { libc.getpid() }; } diff --git a/lib/core/src/rune.ri b/lib/core/src/rune.ri index 8aae31eec..ef677c6d2 100644 --- a/lib/core/src/rune.ri +++ b/lib/core/src/rune.ri @@ -55,7 +55,7 @@ extend rune < Stringable { return res; } - @[inline] + #[inline] public func len_utf8(self) -> usize { return len_utf8(@as(uint32, self)); } @@ -101,7 +101,7 @@ func utf32_decode_to_buffer(code: rune, buffer: [*]mut uint8) -> usize { } } -@[inline] +#[inline] func len_utf8(code: uint32) -> usize { return if code < MAX_ONE_B { 1 @@ -114,7 +114,7 @@ func len_utf8(code: uint32) -> usize { }; } -@[boxed] +#[boxed] public struct TooManyBytesError < Throwable { msg: string; diff --git a/lib/core/src/string.ri b/lib/core/src/string.ri index 30bfcc2d9..ae08a4642 100644 --- a/lib/core/src/string.ri +++ b/lib/core/src/string.ri @@ -6,13 +6,13 @@ import c/libc; static emptyString = string(c"", 0, true); -@[boxed] +#[boxed] public struct string < Stringable, Hashable { public ptr: [*]uint8; public len: usize; is_ref: bool; - @[unsafe] + #[unsafe] public func from_raw(ptr: ?[*]uint8, is_ref: bool = false) -> Self { if safe_ptr := ptr { return unsafe { @@ -22,7 +22,7 @@ public struct string < Stringable, Hashable { return emptyString; } - @[unsafe] + #[unsafe] public func from_raw_with_len(ptr: ?[*]uint8, len: usize, is_ref: bool = false) -> Self { if len == 0 { return emptyString; @@ -67,7 +67,7 @@ public struct string < Stringable, Hashable { return unsafe { self.ptr[idx] }; } - @[inline] + #[inline] public func repeat(self, count: usize) -> string { return if count == 0 { emptyString @@ -171,7 +171,7 @@ public struct string < Stringable, Hashable { /// /// If the replacement positions exceed the number of passed arguments, a panic /// occurs. - @[inline] + #[inline] public func fmt(self, args: ...Stringable) -> Self { return if args.len == 0 { self @@ -404,7 +404,7 @@ public struct string < Stringable, Hashable { /// Strips any of ` `, `\n`, `\t`, `\v`, `\f`, `\r` from the start and end of /// the string. - @[inline] + #[inline] public func trim_space(self) -> string { return self.trim(" \n\t\v\f\r"); } @@ -455,7 +455,7 @@ public struct string < Stringable, Hashable { return unsafe { Self.from_raw_with_len(b, new_len) }; } - @[inline] + #[inline] public func as_bytes(self) -> []uint8 { return unsafe { Vector.from_array_no_alloc(@as(*mut uint8, self.ptr), @size_of(uint8), self.len) @@ -487,7 +487,7 @@ public struct string < Stringable, Hashable { return runes; } - @[inline] + #[inline] public func utf32_code(self) -> rune { return utf8_to_utf32(self.as_bytes()) catch 0; } @@ -633,7 +633,7 @@ public struct string < Stringable, Hashable { /// If `self` is empty, the iterator will return none. /// If `delimiter_bytes` does not exist in self, the iterator will return `self`, /// none, in that order. - @[inline] + #[inline] public func tokenize(self, delimiter_bytes: ...uint8) -> TokenIterator { return TokenIterator(self, delimiter_bytes); } @@ -651,7 +651,7 @@ public struct string < Stringable, Hashable { return mem_cmp(self.ptr, rhs.ptr, rhs.len) == 0; } - @[inline] + #[inline] public func !=(self, rhs: Self) -> bool { return !(self == rhs); } @@ -673,23 +673,23 @@ public struct string < Stringable, Hashable { return false; } - @[inline] + #[inline] public func >(self, rhs: Self) -> bool { return !(self < rhs); } - @[inline] + #[inline] public func <=(self, rhs: Self) -> bool { return self < rhs or self == rhs; } - @[inline] + #[inline] public func >=(self, rhs: Self) -> bool { return self > rhs or self == rhs; } /// Returns `true` if the string contains `substr`. - @[inline] + #[inline] public func contains(self, substr: string) -> bool { return substr.len == 0 or self.index_of(substr) !is none; } @@ -723,12 +723,12 @@ public struct string < Stringable, Hashable { } /// Returns the number of runes contained in `self`. - @[inline] + #[inline] public func runes_count(self) -> usize { return cstr_runes_count(self.ptr, self.len); } - @[inline] + #[inline] public func is_empty(self) -> bool { return self.len == 0; } @@ -758,7 +758,7 @@ public struct string < Stringable, Hashable { } } - @[inline] + #[inline] func slice_from(self, start: usize) -> Self { return self.slice(start, self.len); } @@ -775,12 +775,12 @@ public struct string < Stringable, Hashable { return Self(res, self.len); } - @[inline] + #[inline] public func hash(self) -> usize { return sum64_string(self); } - @[inline] + #[inline] public func to_string(self) -> Self { return self; } diff --git a/lib/core/src/uint.ri b/lib/core/src/uint.ri index 15df88ea7..b8a00a152 100644 --- a/lib/core/src/uint.ri +++ b/lib/core/src/uint.ri @@ -6,7 +6,7 @@ extend uint8 < Stringable { public const MAX: uint8 = 255; /// Checks if the value is within the ASCII range. - @[inline] + #[inline] public func is_ascii(self) -> bool { return self < 0x80; } @@ -14,33 +14,33 @@ extend uint8 < Stringable { /// Returns `true` if the byte is a white space character. The following /// list is considered white space characters: ' ', '\t', '\n', '\v', '\f', /// '\r', 0x85, 0xA0 - @[inline] + #[inline] public 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] + #[inline] public 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] + #[inline] public 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] + #[inline] public 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] + #[inline] public func is_hex_digit(self) -> bool { return (self >= b'0' and self <= b'9') or (self >= b'a' and self <= b'f') @@ -48,49 +48,49 @@ extend uint8 < Stringable { } /// Returns `true` if the byte is in range a-z or A-Z and `false` otherwise. - @[inline] + #[inline] public 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] + #[inline] public func is_alnum(self) -> bool { return self.is_letter() or self.is_digit(); } /// Returns `true` if the byte is upper and `false` otherwise. - @[inline] + #[inline] public func is_upper(self) -> bool { return (self >= b'A' and self <= b'Z'); } /// Returns `true` if the byte is lower and `false` otherwise. - @[inline] + #[inline] public func is_lower(self) -> bool { return (self >= b'a' and self <= b'z'); } /// Calculates length to read from the first byte. - @[inline] + #[inline] public func len_utf8(self) -> usize { return @as(usize, (@as(uint64, 0xE5000000) >> ((self >> 3) & 0x1E) & 3) + 1); } /// Returns the value of `self` as a valid `rune`. - @[inline] + #[inline] public func to_rune(self) -> ?rune { return rune.from_uint32(@as(uint32, self)); } /// Returns the value of `self` as a ASCII `string`. - @[inline] + #[inline] public func to_ascii(self) -> string { return string.from_byte(self); } /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return @as(int32, self.*).str_l(7); } @@ -100,7 +100,7 @@ extend uint16 < Stringable { public const MAX: uint16 = 65535; /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return @as(int32, self.*).str_l(7); } @@ -110,7 +110,7 @@ extend uint32 < Stringable { public const MAX: uint32 = 4294967295; /// Returns the value of `self` as a valid `rune`. - @[inline] + #[inline] public func to_rune(self) -> ?rune { return rune.from_uint32(self); } @@ -199,13 +199,13 @@ extend uint64 < Stringable { extend usize < Stringable { public const MAX: usize = #if _x64_ uint64.MAX #else uint32.MAX #endif; - @[inline] + #[inline] public func bits() -> uint32 { return #if _x64_ 64 #else 32 #endif; } /// Returns the value of `self` as a string. - @[inline] + #[inline] public func to_string(&self) -> string { return @as(uint64, self.*).to_string(); } diff --git a/lib/core/src/wyhash.ri b/lib/core/src/wyhash.ri index ac6871163..314959a31 100644 --- a/lib/core/src/wyhash.ri +++ b/lib/core/src/wyhash.ri @@ -4,22 +4,22 @@ import c; -@[unsafe; inline] +#[unsafe; inline] func wyhash(key: *uint8, len: uint64, seed: uint64) -> uint64 { return unsafe { c.wyhash(key, len, seed, &c._wyp[0]) }; } -@[inline] +#[inline] func wyhash64(a: uint64, b: uint64) -> uint64 { return unsafe { c.wyhash64(a, b) }; } -@[inline] +#[inline] public func sum64(key: []uint8, seed: uint64 = 0) -> uint64 { return unsafe { wyhash(&key[0], @as(uint64, key.len), seed) }; } -@[inline] +#[inline] 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/Annotations.ri b/lib/rivet/src/ast/Annotations.ri index 267f288c1..171400a3d 100644 --- a/lib/rivet/src/ast/Annotations.ri +++ b/lib/rivet/src/ast/Annotations.ri @@ -4,7 +4,7 @@ import ../token; -@[boxed] +#[boxed] public struct AnnotationDuplicatedError < Throwable { name: string; @@ -13,14 +13,14 @@ public struct AnnotationDuplicatedError < Throwable { } } -@[boxed] +#[boxed] public struct AnnotationArgument { public name: string; public expr: Expr; public is_named: bool; } -@[boxed] +#[boxed] public struct Annotation { public name: string; public args: []AnnotationArgument; @@ -36,7 +36,7 @@ public struct Annotation { } } -@[boxed] +#[boxed] public struct Annotations { public mut annotations: []Annotation; @@ -56,12 +56,12 @@ public struct Annotations { return none; } - @[inline] + #[inline] public func has(self, name: string) -> bool { return self.find(name) !is none; } - @[inline] + #[inline] public func is_empty(self) -> bool { return self.annotations.is_empty(); } diff --git a/lib/rivet/src/ast/Decl.ri b/lib/rivet/src/ast/Decl.ri index ad5946dec..fec6f077f 100644 --- a/lib/rivet/src/ast/Decl.ri +++ b/lib/rivet/src/ast/Decl.ri @@ -162,7 +162,7 @@ public enum Decl { } } -@[boxed] +#[boxed] public struct EnumVariantDecl { public name: string; public mut type: Type; @@ -173,12 +173,12 @@ public struct EnumVariantDecl { public pos: token.Pos; } -@[boxed] +#[boxed] public struct DocComment { mut lines: []string; pos: token.Pos; - @[inline] + #[inline] func is_empty(self) -> bool { return self.lines.is_empty(); } diff --git a/lib/rivet/src/ast/Expr.ri b/lib/rivet/src/ast/Expr.ri index cd7063b45..faaef121e 100644 --- a/lib/rivet/src/ast/Expr.ri +++ b/lib/rivet/src/ast/Expr.ri @@ -7,7 +7,7 @@ import std/strings; import ../token; -@[default_value(.Empty(token.noPos))] +#[default_value(.Empty(token.noPos))] public enum Expr < traits.Stringable { Empty: token.Pos, Paren { @@ -197,7 +197,7 @@ public enum Expr < traits.Stringable { return l; } - @[inline] + #[inline] func has_err_handler(self) -> bool { return self.err_handler.has_expr or self.err_handler.is_propagate; } @@ -283,7 +283,7 @@ public enum Expr < traits.Stringable { return res; } - @[inline] + #[inline] public func position(self) -> token.Pos { return switch self is { .Empty as empty_pos => empty_pos, @@ -321,7 +321,7 @@ public enum Expr < traits.Stringable { }; } - @[inline] + #[inline] public func to_string(self) -> string { return switch self is { .Empty => "", @@ -545,7 +545,7 @@ public enum Expr < traits.Stringable { } } -@[boxed] +#[boxed] public struct CallArg { public name: string; public mut expr: Expr; @@ -554,7 +554,7 @@ public struct CallArg { public mut type: Type; } -@[boxed] +#[boxed] public struct CallErrorHandler { public varname: string; public varname_pos: token.Pos; @@ -566,7 +566,7 @@ public struct CallErrorHandler { public pos: token.Pos; } -@[boxed] +#[boxed] public struct IfBranch { public mut cond: Expr; public mut expr: Expr; @@ -576,7 +576,7 @@ public struct IfBranch { public mut type: Type; } -@[boxed] +#[boxed] public struct SwitchBranch { public cases: []mut Expr; public has_var: bool; diff --git a/lib/rivet/src/ast/Scope.ri b/lib/rivet/src/ast/Scope.ri index b9cc4c1bf..0465db271 100644 --- a/lib/rivet/src/ast/Scope.ri +++ b/lib/rivet/src/ast/Scope.ri @@ -4,7 +4,7 @@ import std/process; -@[boxed] +#[boxed] public struct Scope { public start: usize; public mut end: usize; @@ -56,7 +56,7 @@ public struct Scope { } } - @[inline] + #[inline] public func exists(self, name: string) -> bool { return self.find(name) !is none; } @@ -84,12 +84,12 @@ public struct Scope { return self.syms[idx]; } - @[inline] + #[inline] public func find_type_symbol_or_panic(self, name: string) -> TypeSym { return @as(TypeSym, self.find_or_panic(name)); } - @[inline] + #[inline] public func find_type_symbol_by_index_or_panic(self, idx: usize) -> TypeSym { return @as(TypeSym, self.find_by_index_or_panic(idx)); } @@ -110,7 +110,7 @@ public struct Scope { return none; } - @[inline] + #[inline] func dont_lookup_parent(self) -> bool { return self.parent is none or self.detached_from_parent; } diff --git a/lib/rivet/src/ast/Sym.ri b/lib/rivet/src/ast/Sym.ri index abcc61881..9a991c814 100644 --- a/lib/rivet/src/ast/Sym.ri +++ b/lib/rivet/src/ast/Sym.ri @@ -15,7 +15,7 @@ func new_sym_id() -> usize { return res; } -@[boxed] +#[boxed] public struct DuplicateSymbolError < Throwable { msg: string; @@ -28,7 +28,7 @@ public enum ABI as uint8 < traits.Stringable { Rivet, C; - @[inline] + #[inline] public func from_string(abi: string) -> ?ABI { return switch abi { "C" => .C, @@ -37,7 +37,7 @@ public enum ABI as uint8 < traits.Stringable { }; } - @[inline] + #[inline] public func to_string(&self) -> string { return switch self.* { .C => "C", @@ -46,7 +46,7 @@ public enum ABI as uint8 < traits.Stringable { } } -@[default_value(InvalidSym())] +#[default_value(InvalidSym())] public trait Sym { id: usize = new_sym_id(); abi: ABI; @@ -129,17 +129,17 @@ public trait Sym { } } -@[boxed] +#[boxed] public struct InvalidSym < Sym {} -@[boxed] +#[boxed] public struct SymRef < Sym { public mut ref: Sym; public mut ref_expr: Expr; public mut ref_resolved: bool; } -@[boxed] +#[boxed] public struct Module < Sym { public func add_or_get_array(mut self, elem_typ: Type, size: usize, is_mut: bool) -> TypeSym { unique_name := if is_mut { @@ -279,13 +279,13 @@ public struct Module < Sym { return type_sym; } - @[inline] + #[inline] public func is_core(self) -> bool { return self.name == "core"; } } -@[boxed] +#[boxed] public struct Const < Sym { public mut expr: Expr; public mut evaled_expr: Expr; @@ -302,7 +302,7 @@ public enum VarLevel as uint8 { Local // inside function } -@[boxed] +#[boxed] public struct Var < Sym { public is_extern: bool; public is_mut: bool; @@ -315,7 +315,7 @@ public struct Var < Sym { public pos: token.Pos; } -@[boxed] +#[boxed] public struct Arg { public name: string; public is_mut: bool; @@ -326,7 +326,7 @@ public struct Arg { public mut type: Type; } -@[boxed] +#[boxed] public struct Func < Sym { public is_extern: bool; public is_unsafe: bool; @@ -363,7 +363,7 @@ public struct Func < Sym { return len; } - @[inline] + #[inline] public func kind(self) -> string { return if self.is_method { if self.is_special_method { @@ -376,7 +376,7 @@ public struct Func < Sym { }; } - @[inline] + #[inline] public func type(self, mut universe: Module) -> Type { return .Func( is_method: self.is_method, diff --git a/lib/rivet/src/ast/Table.ri b/lib/rivet/src/ast/Table.ri index a46200749..ec85fa948 100644 --- a/lib/rivet/src/ast/Table.ri +++ b/lib/rivet/src/ast/Table.ri @@ -11,7 +11,7 @@ import ../prefs; import ../report; import ../utils; -@[boxed] +#[boxed] public struct Table { /// `.universe` is the mega-module where all the modules being /// compiled reside. @@ -68,7 +68,7 @@ public struct Table { public mut source_files: []SourceFile; - @[inline] + #[inline] public func new(prefs_: prefs.Prefs) -> Table { universe_ := universe(); mut table := Table( @@ -207,17 +207,17 @@ public struct Table { return self.find_builtin(name) !is none; } - @[inline] + #[inline] public func is_number(self, type: Type) -> bool { return self.is_int(type) or self.is_float(type); } - @[inline] + #[inline] public func is_int(self, type: Type) -> bool { return self.is_signed_int(type) or self.is_unsigned_int(type); } - @[inline] + #[inline] public func is_signed_int(self, type: Type) -> bool { return type in [ self.int8_t, self.int16_t, self.int32_t, self.int64_t, self.isize_t, @@ -225,19 +225,19 @@ public struct Table { ]; } - @[inline] + #[inline] public func is_unsigned_int(self, type: Type) -> bool { return type in [ self.uint8_t, self.uint16_t, self.uint32_t, self.uint64_t, self.usize_t ]; } - @[inline] + #[inline] public func is_float(self, type: Type) -> bool { return type in [self.float32_t, self.float64_t, self.comptime_float_t]; } - @[inline] + #[inline] public func is_comptime_number(self, type: Type) -> bool { return type == self.comptime_int_t or type == self.comptime_float_t; } diff --git a/lib/rivet/src/ast/Type.ri b/lib/rivet/src/ast/Type.ri index 882b6330d..d6d6deac5 100644 --- a/lib/rivet/src/ast/Type.ri +++ b/lib/rivet/src/ast/Type.ri @@ -7,7 +7,7 @@ import { Builder } from std/strings; import ../token; -@[default_value(.Void())] +#[default_value(.Void())] public enum Type < traits.Stringable { Basic { mut sym: TypeSym; @@ -83,7 +83,7 @@ public enum Type < traits.Stringable { mut sym: TypeSym; mut has_sym: bool; - @[inline] + #[inline] func symbol(self) -> Func { return if self.has_sym and self.sym.info is .Func as func_sym { func_sym @@ -100,7 +100,7 @@ public enum Type < traits.Stringable { } }; - @[inline] + #[inline] public func ptr_or_ref_inner(self) -> Self { return switch self is { .Pointer as ptr => ptr.inner, @@ -158,7 +158,7 @@ public enum Type < traits.Stringable { } } - @[inline] + #[inline] public func symbol(self) -> ?TypeSym { // NOTE: `.Void`, `.None`, `.Never` and `.Anyptr` has no `TypeSym` value. return switch self is { @@ -175,7 +175,7 @@ public enum Type < traits.Stringable { }; } - @[inline] + #[inline] public func is_primitive(self) -> bool { return if type_sym := self.symbol() { type_sym.is_primitive() @@ -184,7 +184,7 @@ public enum Type < traits.Stringable { }; } - @[inline] + #[inline] public func is_boxed(self) -> bool { return if type_sym := self.symbol() { type_sym.is_boxed() @@ -193,7 +193,7 @@ public enum Type < traits.Stringable { }; } - @[inline] + #[inline] public func is_void(self) -> bool { return switch self is { .Void, .Never => true, @@ -202,12 +202,12 @@ public enum Type < traits.Stringable { }; } - @[inline] + #[inline] public func is_pointer(self) -> bool { return self is .Pointer or self is .Anyptr; } - @[inline] + #[inline] public func is_mut_pointer(self) -> bool { return switch self is { .Pointer as ptr => ptr.is_mut, @@ -216,7 +216,7 @@ public enum Type < traits.Stringable { }; } - @[inline] + #[inline] public func is_any_kind_of_pointer(self) -> bool { return switch self is { .Pointer, .Anyptr, .Func => true, @@ -228,7 +228,7 @@ public enum Type < traits.Stringable { }; } - @[inline] + #[inline] public func position(self) -> token.Pos { return switch self is { .Void, .None => token.noPos, @@ -250,7 +250,7 @@ public enum Type < traits.Stringable { }; } - @[inline] + #[inline] public func ==(self, rhs: Self) -> bool { return switch self is { .None if rhs is .None => true, diff --git a/lib/rivet/src/ast/TypeInfo.ri b/lib/rivet/src/ast/TypeInfo.ri index 231c92cf0..5320a93cf 100644 --- a/lib/rivet/src/ast/TypeInfo.ri +++ b/lib/rivet/src/ast/TypeInfo.ri @@ -65,7 +65,7 @@ public enum TypeInfo < traits.Stringable { } } - @[inline] + #[inline] func mark_has_objects(mut self) { self.has_objects = true; } @@ -76,7 +76,7 @@ public enum TypeInfo < traits.Stringable { is_boxed: bool; mut traits: []mut TypeSym; - @[inline] + #[inline] func add_variant(mut self, variant: EnumVariant) { self.variants.push(variant); } @@ -130,7 +130,7 @@ public enum TypeInfo < traits.Stringable { } }; - @[inline] + #[inline] public func elem_type(self) -> ?Type { return switch self is { .Array as arr => arr.elem_type, @@ -139,7 +139,7 @@ public enum TypeInfo < traits.Stringable { }; } - @[inline] + #[inline] public func is_mut_arr_or_vec(self) -> bool { return switch self is { .Array as arr => arr.is_mut, @@ -148,19 +148,19 @@ public enum TypeInfo < traits.Stringable { }; } - @[inline] + #[inline] public func is_primitive(self) -> bool { return self is .Bool or self is .Rune or self is .Int or self is .Uint or self is .Usize or self is .Isize or self is .ComptimeInt or self is .ComptimeFloat or self is .ComptimeFloat or self is .Float; } - @[inline] + #[inline] public func is_compound(self) -> bool { return self is .Struct or self is .Trait or self is .Enum or self is .Tuple; } - @[inline] + #[inline] public func to_string(self) -> string { return switch self is { .Invalid => "invalid", @@ -192,7 +192,7 @@ public enum TypeInfo < traits.Stringable { } } -@[boxed] +#[boxed] public struct EnumVariant { public name: string; public value: isize; diff --git a/lib/rivet/src/ast/TypeSym.ri b/lib/rivet/src/ast/TypeSym.ri index a08371362..545fdea42 100644 --- a/lib/rivet/src/ast/TypeSym.ri +++ b/lib/rivet/src/ast/TypeSym.ri @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@[boxed] +#[boxed] public struct Field { public is_public: bool; public name: string; @@ -13,7 +13,7 @@ public struct Field { public is_required: bool; } -@[boxed] +#[boxed] public struct TypeSym < Sym { public mut fields: []Field; public mut full_fields_: []Field; @@ -49,12 +49,12 @@ public struct TypeSym < Sym { return none; } - @[inline] + #[inline] public func has_field(self, name: string) -> bool { return self.lookup_field(name) !is none; } - @[inline] + #[inline] public func lookup(self, name: string) -> ?Sym { return if s := self.scope.lookup(name) { s @@ -91,7 +91,7 @@ public struct TypeSym < Sym { return none; } - @[inline] + #[inline] public 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 { @@ -108,7 +108,7 @@ public struct TypeSym < Sym { }; } - @[inline] + #[inline] public func find_method(self, name: string) -> ?Func { return if func_ := self.find_func(name); func_.is_method { func_ @@ -117,12 +117,12 @@ public struct TypeSym < Sym { }; } - @[inline] + #[inline] public func has_func(self, name: string) -> bool { return self.find_func(name) !is none; } - @[inline] + #[inline] public func has_method(self, name: string) -> bool { return self.find_method(name) !is none; } @@ -157,7 +157,7 @@ public struct TypeSym < Sym { return fields; } - @[inline] + #[inline] public func implement_trait(self, trait_sym: TypeSym) -> bool { return if trait_sym.info is .Trait as trait_info { self in trait_info.implements @@ -182,7 +182,7 @@ public struct TypeSym < Sym { return false; } - @[inline] + #[inline] public func is_boxed(self) -> bool { return if self.info is .Enum as enum_info { enum_info.is_boxed @@ -193,17 +193,17 @@ public struct TypeSym < Sym { }; } - @[inline] + #[inline] public func is_primitive(self) -> bool { return self.info.is_primitive(); } - @[inline] + #[inline] public func ==(self, rhs: Self) -> bool { return self.id == rhs.id; } - @[inline] + #[inline] public 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 f52387370..d4386e201 100644 --- a/lib/rivet/src/ast/mod.ri +++ b/lib/rivet/src/ast/mod.ri @@ -10,7 +10,7 @@ public enum Node { Expr: Expr } -@[boxed] +#[boxed] public struct SourceFile { public file: string; public decls: []Decl; @@ -18,7 +18,7 @@ public struct SourceFile { public mut imported_symbols: ImportedSymbols; } -@[boxed] +#[boxed] public struct ImportedSymbol { public name: string; public sym: Sym; @@ -29,7 +29,7 @@ public struct ImportedSymbol { public struct ImportedSymbols { public mut syms: []ImportedSymbol; - @[inline] + #[inline] 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)); } @@ -43,14 +43,14 @@ public struct ImportedSymbols { return none; } - @[inline] + #[inline] public func exists(&self, name: string) -> bool { return self.find(name) !is none; } } // Used in variable declarations/statements and guard expressions. -@[boxed] +#[boxed] public struct ObjectData { public name: string; public is_mut: bool; diff --git a/lib/rivet/src/checker/mod.ri b/lib/rivet/src/checker/mod.ri index c8f867418..fb581c1f3 100644 --- a/lib/rivet/src/checker/mod.ri +++ b/lib/rivet/src/checker/mod.ri @@ -8,7 +8,7 @@ import ../prefs; import ../utils; import ../report; -@[boxed] +#[boxed] public struct Checker { mut table: ast.Table; mut prefs: prefs.Prefs; diff --git a/lib/rivet/src/checker/name_cases.ri b/lib/rivet/src/checker/name_cases.ri index a6df085c5..3164ec55f 100644 --- a/lib/rivet/src/checker/name_cases.ri +++ b/lib/rivet/src/checker/name_cases.ri @@ -25,7 +25,7 @@ extend Checker { } } - @[inline] + #[inline] func check_name_case(self, case: NameCase, kind: string, name: string, pos: token.Pos) { if !(self.inside_extern or name == "_" or name == "string" or self.sym.module()?.name in ["c.libc", "c.ctypes"]) { diff --git a/lib/rivet/src/checker/types.ri b/lib/rivet/src/checker/types.ri index 4646d8a94..07bdfe6eb 100644 --- a/lib/rivet/src/checker/types.ri +++ b/lib/rivet/src/checker/types.ri @@ -6,7 +6,7 @@ import ../ast; import ../token; import ../report; -@[boxed] +#[boxed] struct IncompatibleTypesError < Throwable { msg: string; diff --git a/lib/rivet/src/codegen/mir/Block.ri b/lib/rivet/src/codegen/mir/Block.ri index 7aa25d12e..32fd714e4 100644 --- a/lib/rivet/src/codegen/mir/Block.ri +++ b/lib/rivet/src/codegen/mir/Block.ri @@ -5,7 +5,7 @@ import std/traits; import std/strings; -@[boxed] +#[boxed] public struct Block < traits.Stringable { mut id: usize; mut stmts: []Stmt; diff --git a/lib/rivet/src/codegen/mir/Expr.ri b/lib/rivet/src/codegen/mir/Expr.ri index 312746fb6..734effe00 100644 --- a/lib/rivet/src/codegen/mir/Expr.ri +++ b/lib/rivet/src/codegen/mir/Expr.ri @@ -5,7 +5,7 @@ import std/traits; import std/strings; -@[default_value(.Empty())] +#[default_value(.Empty())] public enum Expr < traits.Stringable { Empty, IntConst { diff --git a/lib/rivet/src/codegen/mir/Type.ri b/lib/rivet/src/codegen/mir/Type.ri index 8b699e7c6..4b11f7770 100644 --- a/lib/rivet/src/codegen/mir/Type.ri +++ b/lib/rivet/src/codegen/mir/Type.ri @@ -6,7 +6,7 @@ import std/traits; import std/strings; import std/process; -@[default_value(.Void())] +#[default_value(.Void())] public enum Type < traits.Stringable { Void, Never, diff --git a/lib/rivet/src/codegen/mir/mod.ri b/lib/rivet/src/codegen/mir/mod.ri index 0d6999830..38e14ec6e 100644 --- a/lib/rivet/src/codegen/mir/mod.ri +++ b/lib/rivet/src/codegen/mir/mod.ri @@ -8,7 +8,7 @@ import std/strings; import ../../utils; -@[boxed] +#[boxed] public struct ModuleIR < traits.Stringable { public name: string; public mut structs: []Struct; @@ -17,7 +17,7 @@ public struct ModuleIR < traits.Stringable { public mut externs: []Func; public mut funcs: []Func; - @[inline] + #[inline] public func to_file(self) -> ! { fs.write_file("{}.mir".fmt(self.name), self.to_string())!; } @@ -57,13 +57,13 @@ public struct ModuleIR < traits.Stringable { } } -@[boxed] +#[boxed] public struct Field { public name: string; public type: Type; } -@[boxed] +#[boxed] public struct Struct < traits.Stringable { public name: string; public fields: []Field; @@ -90,7 +90,7 @@ public struct Struct < traits.Stringable { } } -@[boxed] +#[boxed] public struct Global < traits.Stringable { public is_extern: bool; public name: string; @@ -107,12 +107,12 @@ public struct Global < traits.Stringable { } } -@[boxed] +#[boxed] public struct VTable { public funcs: []Func; } -@[boxed] +#[boxed] public struct Func < traits.Stringable { public name: string; public mut args_len: usize; @@ -198,7 +198,7 @@ public enum VarLevel { Temporal } -@[boxed] +#[boxed] public struct Var { public mut id: usize; public dbg_name: string; diff --git a/lib/rivet/src/codegen/mod.ri b/lib/rivet/src/codegen/mod.ri index 70698d14c..f20d3e7b5 100644 --- a/lib/rivet/src/codegen/mod.ri +++ b/lib/rivet/src/codegen/mod.ri @@ -10,7 +10,7 @@ import ../prefs; import ../utils; import ../utils/maps; -@[boxed] +#[boxed] public struct Codegen { mut table: ast.Table; prefs: prefs.Prefs; diff --git a/lib/rivet/src/depgraph/OrderedDepMap.ri b/lib/rivet/src/depgraph/OrderedDepMap.ri index b3f7c85be..fb2650bf4 100644 --- a/lib/rivet/src/depgraph/OrderedDepMap.ri +++ b/lib/rivet/src/depgraph/OrderedDepMap.ri @@ -6,7 +6,7 @@ import std/process; import ../utils/maps; -@[boxed] +#[boxed] public struct OrderedDepMap { mut keys: []string; mut data: maps.MapStringArrayOfStrings; // TODO: replace with map type @@ -32,7 +32,7 @@ public struct OrderedDepMap { self.set(name, d); } - @[inline] + #[inline] public func get(self, name: string) -> []string { return if res := self.data.get(name) { res diff --git a/lib/rivet/src/depgraph/mod.ri b/lib/rivet/src/depgraph/mod.ri index 07193b59a..d93964fa9 100644 --- a/lib/rivet/src/depgraph/mod.ri +++ b/lib/rivet/src/depgraph/mod.ri @@ -12,17 +12,17 @@ struct DepGraphNode { public mut deps: []string; } -@[boxed] +#[boxed] public struct DepGraph { public mut acyclic: bool; public mut nodes: []DepGraphNode; - @[inline] + #[inline] public func new() -> Self { return Self(true, @vec(DepGraphNode, 1024)); } - @[inline] + #[inline] public func add(mut self, mod: string, deps: []string) { self.nodes.push(DepGraphNode(mod, deps)); } diff --git a/lib/rivet/src/lib.ri b/lib/rivet/src/lib.ri index 73c095eb1..e41e827c1 100644 --- a/lib/rivet/src/lib.ri +++ b/lib/rivet/src/lib.ri @@ -18,7 +18,7 @@ import ./codegen; import ./resolver; import ./depgraph; -@[boxed] +#[boxed] public struct Compiler { mut table: ast.Table; mut prefs: prefs.Prefs; diff --git a/lib/rivet/src/parser/decls.ri b/lib/rivet/src/parser/decls.ri index 10fcd46d0..def23b026 100644 --- a/lib/rivet/src/parser/decls.ri +++ b/lib/rivet/src/parser/decls.ri @@ -23,7 +23,7 @@ extend Parser { mut self, parse_mod_annotations: bool = false ) -> ast.Annotations { mut annotations := ast.Annotations(); - while self.accept(.At) { + while self.accept(.Hash) { if parse_mod_annotations { self.expect(.Bang); } @@ -65,7 +65,7 @@ extend Parser { return annotations; } - @[inline] + #[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; @@ -95,7 +95,7 @@ extend Parser { func parse_decl(mut self) -> ast.Decl { doc_comment := self.parse_doc_comment(); annotations := self.parse_annotations( - self.tok.kind == .At and self.peek_tok.kind == .Bang + self.tok.kind == .Hash and self.peek_tok.kind == .Bang ); is_public := self.is_public(); mut pos := self.tok.pos; diff --git a/lib/rivet/src/parser/exprs.ri b/lib/rivet/src/parser/exprs.ri index 79b2c37e4..3269f008a 100644 --- a/lib/rivet/src/parser/exprs.ri +++ b/lib/rivet/src/parser/exprs.ri @@ -7,7 +7,7 @@ import ../report; import ../token; extend Parser { - @[inline] + #[inline] func parse_expr(mut self) -> ast.Expr { return self.parse_or_expr(); } @@ -195,7 +195,7 @@ extend Parser { return left; } - @[inline] + #[inline] func parse_unary_expr(mut self) -> ast.Expr { return switch self.tok.kind { .Amp, .Bang, .BitNot, .Minus => { @@ -698,7 +698,7 @@ extend Parser { return .Guard(vars, expr, has_cond, cond, self.scope, pos + self.prev_tok.pos); } - @[inline] + #[inline] func parse_literal(mut self) -> ast.Expr { return switch { self.tok.kind in [.KwTrue, .KwFalse] => { @@ -791,7 +791,7 @@ extend Parser { ); } - @[inline] + #[inline] func parse_selector_expr(mut self, left: ast.Expr) -> ast.Expr { field_pos := self.tok.pos; return .Selector( diff --git a/lib/rivet/src/parser/mod.ri b/lib/rivet/src/parser/mod.ri index d32c7f0d9..0d02bcaf8 100644 --- a/lib/rivet/src/parser/mod.ri +++ b/lib/rivet/src/parser/mod.ri @@ -10,7 +10,7 @@ import ../report; import ../token; import ../tokenizer; -@[boxed] +#[boxed] public struct Parser { mut table: ast.Table; mut prefs: prefs.Prefs; @@ -63,7 +63,7 @@ public struct Parser { self.peek_tok = self.tokenizer.next(); } - @[inline] + #[inline] func peek_token(self, n: usize) -> token.Token { return self.tokenizer.peek_token(n - 2); } @@ -75,7 +75,7 @@ public struct Parser { } } - @[inline] + #[inline] func accept(mut self, kind: token.Kind) -> bool { return if self.tok.kind == kind { self.next(); diff --git a/lib/rivet/src/prefs/mod.ri b/lib/rivet/src/prefs/mod.ri index 858360c41..d407f68ec 100644 --- a/lib/rivet/src/prefs/mod.ri +++ b/lib/rivet/src/prefs/mod.ri @@ -42,7 +42,7 @@ public enum LinkMode as uint8 { Dynamic } -@[boxed] +#[boxed] public struct Prefs { // Target info public mut target_os: sys.OS = sys.os(); diff --git a/lib/rivet/src/report/mod.ri b/lib/rivet/src/report/mod.ri index 578da84f7..75d9f456f 100644 --- a/lib/rivet/src/report/mod.ri +++ b/lib/rivet/src/report/mod.ri @@ -12,17 +12,17 @@ import ../utils; public static mut reportTable = ReportTable(); -@[inline] +#[inline] public func total_errors() -> usize { return reportTable.errors; } -@[inline] +#[inline] public func total_warns() -> usize { return reportTable.warns; } -@[boxed] +#[boxed] struct ReportTable { public mut prefs: prefs.Prefs; public mut errors: usize; @@ -38,28 +38,28 @@ public enum ReportKind as uint8 { Help } -@[boxed] +#[boxed] struct Annotation { kind: ReportKind; msg: string; } -@[inline] +#[inline] public func error(msg: string, pos: token.Pos) { ReportBuilder(.Error, msg, pos).emit(); } -@[inline] +#[inline] public func warn(msg: string, pos: token.Pos) { ReportBuilder(.Warn, msg, pos).emit(); } -@[inline] +#[inline] public func error_builder(msg: string, pos: token.Pos) -> ReportBuilder { return ReportBuilder(.Error, msg, pos); } -@[inline] +#[inline] public func warn_builder(msg: string, pos: token.Pos) -> ReportBuilder { return ReportBuilder(.Warn, msg, pos); } @@ -71,12 +71,12 @@ public struct ReportBuilder { pos: token.Pos = token.noPos; mut annotations: []Annotation; - @[inline] + #[inline] public func add_note(mut self, msg: string, args: ...traits.Stringable) { self.annotations.push(Annotation(.Note, msg.fmt(args))); } - @[inline] + #[inline] public func add_help(mut self, msg: string, args: ...traits.Stringable) { self.annotations.push(Annotation(.Help, msg.fmt(args))); } diff --git a/lib/rivet/src/resolver/Register.ri b/lib/rivet/src/resolver/Register.ri index c04d4e95c..6cf12a1c9 100644 --- a/lib/rivet/src/resolver/Register.ri +++ b/lib/rivet/src/resolver/Register.ri @@ -7,7 +7,7 @@ import ../prefs; import ../token; import ../report; -@[boxed] +#[boxed] public struct Register { mut table: ast.Table; mut prefs: prefs.Prefs; diff --git a/lib/rivet/src/resolver/mod.ri b/lib/rivet/src/resolver/mod.ri index df6fec47d..4127cb52f 100644 --- a/lib/rivet/src/resolver/mod.ri +++ b/lib/rivet/src/resolver/mod.ri @@ -14,7 +14,7 @@ struct Prelude { sym: ast.Sym; } -@[boxed] +#[boxed] public struct Resolver { mut table: ast.Table; mut prefs: prefs.Prefs; diff --git a/lib/rivet/src/token/Kind.ri b/lib/rivet/src/token/Kind.ri index 2f534cb65..101fa1387 100644 --- a/lib/rivet/src/token/Kind.ri +++ b/lib/rivet/src/token/Kind.ri @@ -4,7 +4,7 @@ import std/traits; -@[boxed] +#[boxed] struct KindMap { key: Kind; value: string; @@ -44,6 +44,7 @@ static kindStrings = [ KindMap(.Dot, "."), KindMap(.DotDot, ".."), KindMap(.Ellipsis, "..."), + KindMap(.Hash, "#"), KindMap(.At, "@"), KindMap(.Arrow, "=>"), KindMap(.Arrow2, "->"), @@ -142,6 +143,7 @@ public enum Kind < traits.Stringable { Dot, // . DotDot, // .. Ellipsis, // ... + Hash, // # At, // @ Arrow, // => Arrow2, // -> @@ -209,7 +211,7 @@ public enum Kind < traits.Stringable { KeywordEnd; - @[inline] + #[inline] public func single(self) -> Kind { return switch self { .PlusAssign => .Plus, @@ -224,7 +226,7 @@ public enum Kind < traits.Stringable { }; } - @[inline] + #[inline] public func is_start_of_type(self) -> bool { return self in [ .Bang, .Name, .Lparen, .Amp, .Mul, .Lbracket, .Question, .KwSelfTy, @@ -232,7 +234,7 @@ public enum Kind < traits.Stringable { ]; } - @[inline] + #[inline] public func is_assign(self) -> bool { return self in [ .DeclAssign, .Assign, .PlusAssign, .MinusAssign, .MulAssign, .DivAssign, @@ -240,7 +242,7 @@ public enum Kind < traits.Stringable { ]; } - @[inline] + #[inline] public func is_relational(self) -> bool { return self in [ .Eq, .Ne, .Lt, .Gt, .Le, .Ge, .KwIs, .KwNotIs, .KwIn, .KwNotIn @@ -257,7 +259,7 @@ public enum Kind < traits.Stringable { } } -@[inline] +#[inline] public func lookup(str: string) -> Kind { return switch str { "alias" => .KwAlias, @@ -305,17 +307,17 @@ public func lookup(str: string) -> Kind { }; } -@[inline] +#[inline] public func is_keyword(lit: string) -> bool { return lookup(lit) != .Name; } -@[inline] +#[inline] public func is_overloadable_operator(kind: Kind) -> bool { return kind in [.Plus, .Minus, .Mul, .Div, .Mod, .Eq, .Ne, .Lt, .Gt, .Le, .Ge]; } -@[inline] +#[inline] public func overloadable_operator_name(kind: Kind) -> string { return switch kind { .Plus => "_add_", diff --git a/lib/rivet/src/token/mod.ri b/lib/rivet/src/token/mod.ri index 817eb798c..ef8e366c5 100644 --- a/lib/rivet/src/token/mod.ri +++ b/lib/rivet/src/token/mod.ri @@ -19,7 +19,7 @@ public struct Pos < traits.Stringable { public end_col: usize; public is_multiline: bool; - @[inline] + #[inline] public func +(&self, other: *Pos) -> Pos { return if other.line > self.line { Pos( @@ -46,7 +46,7 @@ public struct Pos < traits.Stringable { and self.is_multiline == other.is_multiline; } - @[inline] + #[inline] public func to_report_string(&self) -> string { return if self.is_multiline { "{}:{}:{}-{}:{}".fmt( @@ -62,7 +62,7 @@ public struct Pos < traits.Stringable { }; } - @[inline] + #[inline] public func to_string(&self) -> string { return if self.is_multiline { "{}:{}:{}-{}:{}".fmt( diff --git a/lib/rivet/src/tokenizer/mod.ri b/lib/rivet/src/tokenizer/mod.ri index 274dbd46f..d1c4aadda 100644 --- a/lib/rivet/src/tokenizer/mod.ri +++ b/lib/rivet/src/tokenizer/mod.ri @@ -16,7 +16,7 @@ import { LF, CR } from ../utils; const NUM_SEP = b'_'; -@[boxed] +#[boxed] public struct Tokenizer { table: ast.Table; prefs: prefs.Prefs; @@ -62,7 +62,7 @@ public struct Tokenizer { } } - @[inline] + #[inline] 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, @@ -73,7 +73,7 @@ public struct Tokenizer { )); } - @[inline] + #[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 @@ -90,7 +90,7 @@ public struct Tokenizer { )); } - @[inline] + #[inline] func new_eof_token(self) -> token.Token { return token.Token( kind: .EndOfFile, @@ -119,12 +119,12 @@ public struct Tokenizer { return self.new_eof_token(); } - @[inline] + #[inline] func current_char(self) -> uint8 { return self.text[self.pos]; } - @[inline] + #[inline] func current_pos(self) -> token.Pos { return token.Pos( file: self.file, @@ -135,7 +135,7 @@ public struct Tokenizer { ); } - @[inline] + #[inline] func current_column(self) -> usize { return if self.line == 0 { self.pos + 1 @@ -149,7 +149,7 @@ public struct Tokenizer { self.inc_line_number(); } - @[inline] + #[inline] func eat_to_end_of_line(mut self) { while self.pos < self.text.len and self.current_char() != LF : self.pos += 1 {} } @@ -162,7 +162,7 @@ public struct Tokenizer { self.line += 1; } - @[inline] + #[inline] func skip_whitespace(mut self) { while self.pos < self.text.len : self.pos += 1 { c := self.current_char(); @@ -198,7 +198,7 @@ public struct Tokenizer { return true; } - @[inline] + #[inline] public func peek_token(self, n: usize) -> token.Token { idx := self.tidx + n; return if idx >= self.all_tokens.len { @@ -208,7 +208,7 @@ public struct Tokenizer { }; } - @[inline] + #[inline] func look_ahead(self, n: usize) -> uint8 { return if self.pos + n < self.text.len { self.text[self.pos + n] @@ -224,22 +224,22 @@ public struct Tokenizer { self.pos += len; } - @[inline] + #[inline] func error(self, msg: string, pos: token.Pos = self.current_pos()) { report.error(msg, pos); } - @[inline] + #[inline] func warn(self, msg: string, pos: token.Pos = self.current_pos()) { report.warn(msg, pos); } - @[inline] + #[inline] func error_builder(self, msg: string, pos: token.Pos = self.current_pos()) -> report.ReportBuilder { return report.error_builder(msg, pos); } - @[inline] + #[inline] func warn_builder(self, msg: string, pos: token.Pos = self.current_pos()) -> report.ReportBuilder { return report.warn_builder(msg, pos); } @@ -335,7 +335,7 @@ func trim_slash_line_break(s: string) -> string { return ret_str; } -@[inline] +#[inline] func number_literal_without_separator(lit: string) -> string { return if lit.contains("_") { mut sb := strings.Builder.new(lit.len - lit.count("_")); diff --git a/lib/rivet/src/tokenizer/next.ri b/lib/rivet/src/tokenizer/next.ri index 829c7e33c..e62d543b0 100644 --- a/lib/rivet/src/tokenizer/next.ri +++ b/lib/rivet/src/tokenizer/next.ri @@ -178,6 +178,9 @@ extend Tokenizer { return self.new_token(.Question); }, b'#' => { + if nextc == b'[' or nextc == b'!' { + return self.new_token(.Hash); + } self.pp_directive(); continue; }, @@ -266,7 +269,7 @@ extend Tokenizer { return lit; } - @[inline] + #[inline] func read_number(mut self) -> string { return switch { self.matches("0x", self.pos) => self.read_hex_number(), diff --git a/lib/rivet/src/utils/file.ri b/lib/rivet/src/utils/file.ri index 2cce757fc..1a8468c7a 100644 --- a/lib/rivet/src/utils/file.ri +++ b/lib/rivet/src/utils/file.ri @@ -37,7 +37,7 @@ struct CachedFile { mut lines: []string; } -@[boxed] +#[boxed] struct SourceCache { mut sources: []CachedFile; @@ -87,7 +87,7 @@ struct SourceCache { public static mut sourceCache: SourceCache = SourceCache(); -@[inline] +#[inline] public func read_file(path_: string) -> !string { return if res := sourceCache.find(path_) { res diff --git a/lib/rivet/src/utils/maps/mod.ri b/lib/rivet/src/utils/maps/mod.ri index 5d54ee65a..9182fd06c 100644 --- a/lib/rivet/src/utils/maps/mod.ri +++ b/lib/rivet/src/utils/maps/mod.ri @@ -4,13 +4,13 @@ // TODO: remove file, use Map![K, V] instead -@[boxed] +#[boxed] struct StringUsize { public key: string; public mut value: usize; } -@[boxed] +#[boxed] public struct MapStringUsize { mut pairs: []mut StringUsize; @@ -43,19 +43,19 @@ public struct MapStringUsize { } } - @[inline] + #[inline] public func contains(self, key: string) -> bool { return self.get(key) !is none; } - @[inline] + #[inline] public func len(self) -> usize { return self.pairs.len; } } -@[boxed] +#[boxed] struct StringArrayOfStrings { public key: string; public mut value: []string; @@ -65,7 +65,7 @@ public struct MapStringArrayOfStringsIterator { ref: MapStringArrayOfStrings; mut idx: usize; - @[inline] + #[inline] public func next(mut self) -> ?StringArrayOfStrings { return if self.idx < self.ref.len() { idx := self.idx; @@ -77,7 +77,7 @@ public struct MapStringArrayOfStringsIterator { } } -@[boxed] +#[boxed] public struct MapStringArrayOfStrings { mut pairs: []mut StringArrayOfStrings; @@ -114,24 +114,24 @@ public struct MapStringArrayOfStrings { } } - @[inline] + #[inline] public func contains(self, key: string) -> bool { return self.get(key) !is none; } - @[inline] + #[inline] public func len(self) -> usize { return self.pairs.len; } } -@[boxed] +#[boxed] struct StringBool { public key: string; public mut value: bool; } -@[boxed] +#[boxed] public struct MapStringBool { mut pairs: []mut StringBool; @@ -164,12 +164,12 @@ public struct MapStringBool { } } - @[inline] + #[inline] public func contains(self, key: string) -> bool { return self.get(key) !is none; } - @[inline] + #[inline] public func len(self) -> usize { return self.pairs.len; } diff --git a/lib/rivet/src/utils/mod.ri b/lib/rivet/src/utils/mod.ri index 4545385c4..c6c58e62c 100644 --- a/lib/rivet/src/utils/mod.ri +++ b/lib/rivet/src/utils/mod.ri @@ -12,12 +12,12 @@ public const CR: uint8 = 13; public static mut stderrSupportStyles = styles.stderr_support_styles(); -@[inline] +#[inline] public func min(a: usize, b: usize) -> usize { return if a < b { a } else { b }; } -@[inline] +#[inline] public func max(a: usize, b: usize) -> usize { return if a > b { a } else { b }; } @@ -39,48 +39,48 @@ public func error(msg: string, args: ...traits.Stringable) -> never { process.exit(1); } -@[inline] +#[inline] public func warn(msg: string, args: ...traits.Stringable) { console.eprintln("{} {} {}", bold("rivet:"), bold(yellow("warning:")), msg.fmt(args)); } -@[inline] +#[inline] public func info(msg: string, args: ...traits.Stringable) { console.eprintln("{} {} {}", bold("rivet:"), bold(blue("info:")), msg.fmt(args)); } -@[inline] +#[inline] public func bold(msg: string) -> string { return if stderrSupportStyles { styles.bold(msg) } else { msg }; } -@[inline] +#[inline] public func red(msg: string) -> string { return if stderrSupportStyles { styles.red(msg) } else { msg }; } -@[inline] +#[inline] public func yellow(msg: string) -> string { return if stderrSupportStyles { styles.yellow(msg) } else { msg }; } -@[inline] +#[inline] public func cyan(msg: string) -> string { return if stderrSupportStyles { styles.cyan(msg) } else { msg }; } -@[inline] +#[inline] public func blue(msg: string) -> string { return if stderrSupportStyles { styles.blue(msg) } else { msg }; } -@[inline] +#[inline] public 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] +/// NOTE: `multiple` must be a power of 2.#[inline] public func round_up(n: usize, multiple: usize) -> usize { n_ := @as(isize, n); multiple_ := @as(isize, multiple); diff --git a/lib/rivet/src/utils/tokenizer.ri b/lib/rivet/src/utils/tokenizer.ri index 05d37c564..fee9cf6f5 100644 --- a/lib/rivet/src/utils/tokenizer.ri +++ b/lib/rivet/src/utils/tokenizer.ri @@ -2,12 +2,12 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@[inline] +#[inline] public func is_name_char(ch: uint8) -> bool { return ch.is_letter() or ch == b'_'; } -@[inline] +#[inline] public func is_new_line(ch: uint8) -> bool { return ch == LF or ch == CR; } diff --git a/lib/std/src/backtrace/mod.ri b/lib/std/src/backtrace/mod.ri index eb584c0ca..c434883ff 100644 --- a/lib/std/src/backtrace/mod.ri +++ b/lib/std/src/backtrace/mod.ri @@ -4,7 +4,7 @@ import core; -@[inline] +#[inline] public func print(frames_to_skip: int32 = 0) { core.bt_print(frames_to_skip); } diff --git a/lib/std/src/console/styles/bg.ri b/lib/std/src/console/styles/bg.ri index e557978ab..7aede9de8 100644 --- a/lib/std/src/console/styles/bg.ri +++ b/lib/std/src/console/styles/bg.ri @@ -2,82 +2,82 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@[inline] +#[inline] public func bg_black(msg: string) -> string { return fmt(msg, "40", "49"); } -@[inline] +#[inline] public func bg_blue(msg: string) -> string { return fmt(msg, "44", "49"); } -@[inline] +#[inline] public func bg_cyan(msg: string) -> string { return fmt(msg, "46", "49"); } -@[inline] +#[inline] public func bg_green(msg: string) -> string { return fmt(msg, "42", "49"); } -@[inline] +#[inline] public func bg_magenta(msg: string) -> string { return fmt(msg, "45", "49"); } -@[inline] +#[inline] public func bg_red(msg: string) -> string { return fmt(msg, "41", "49"); } -@[inline] +#[inline] public func bg_white(msg: string) -> string { return fmt(msg, "47", "49"); } -@[inline] +#[inline] public func bg_yellow(msg: string) -> string { return fmt(msg, "43", "49"); } -@[inline] +#[inline] public func bg_bright_black(msg: string) -> string { return fmt(msg, "100", "49"); } -@[inline] +#[inline] public func bg_bright_blue(msg: string) -> string { return fmt(msg, "104", "49"); } -@[inline] +#[inline] public func bg_bright_cyan(msg: string) -> string { return fmt(msg, "106", "49"); } -@[inline] +#[inline] public func bg_bright_green(msg: string) -> string { return fmt(msg, "102", "49"); } -@[inline] +#[inline] public func bg_bright_magenta(msg: string) -> string { return fmt(msg, "105", "49"); } -@[inline] +#[inline] public func bg_bright_red(msg: string) -> string { return fmt(msg, "101", "49"); } -@[inline] +#[inline] public func bg_bright_white(msg: string) -> string { return fmt(msg, "107", "49"); } -@[inline] +#[inline] public 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 6aea7b21a..d73a1708d 100644 --- a/lib/std/src/console/styles/fg.ri +++ b/lib/std/src/console/styles/fg.ri @@ -2,87 +2,87 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@[inline] +#[inline] public func black(msg: string) -> string { return fmt(msg, "30", "39"); } -@[inline] +#[inline] public func bright_black(msg: string) -> string { return fmt(msg, "90", "39"); } -@[inline] +#[inline] public func blue(msg: string) -> string { return fmt(msg, "34", "39"); } -@[inline] +#[inline] public func bright_blue(msg: string) -> string { return fmt(msg, "94", "39"); } -@[inline] +#[inline] public func cyan(msg: string) -> string { return fmt(msg, "36", "39"); } -@[inline] +#[inline] public func bright_cyan(msg: string) -> string { return fmt(msg, "96", "39"); } -@[inline] +#[inline] public func green(msg: string) -> string { return fmt(msg, "32", "39"); } -@[inline] +#[inline] public func bright_green(msg: string) -> string { return fmt(msg, "92", "39"); } -@[inline] +#[inline] public func gray(msg: string) -> string { return bright_black(msg); } -@[inline] +#[inline] public func magenta(msg: string) -> string { return fmt(msg, "35", "39"); } -@[inline] +#[inline] public func bright_magenta(msg: string) -> string { return fmt(msg, "95", "39"); } -@[inline] +#[inline] public func red(msg: string) -> string { return fmt(msg, "31", "39"); } -@[inline] +#[inline] public func bright_red(msg: string) -> string { return fmt(msg, "91", "39"); } -@[inline] +#[inline] public func white(msg: string) -> string { return fmt(msg, "37", "39"); } -@[inline] +#[inline] public func bright_white(msg: string) -> string { return fmt(msg, "97", "39"); } -@[inline] +#[inline] public func yellow(msg: string) -> string { return fmt(msg, "33", "39"); } -@[inline] +#[inline] public 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 9404a473a..5866173c9 100644 --- a/lib/std/src/console/styles/mod.ri +++ b/lib/std/src/console/styles/mod.ri @@ -4,82 +4,82 @@ import std/console; -@[inline] +#[inline] public func stdout_support_styles() -> bool { return console.is_atty(1); } -@[inline] +#[inline] public func stderr_support_styles() -> bool { return console.is_atty(2); } -@[inline] +#[inline] public func fmt(msg: string, open: string, close: string) -> string { return "\x1b[{}m{}\x1b[{}m".fmt(open, msg, close); } -@[inline] +#[inline] public 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] +#[inline] public func from_hex(hex: int32, msg: string) -> string { return fmt_rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF, msg, "38", "39"); } -@[inline] +#[inline] public func bg_rgb(r: int32, g: int32, b: int32, msg: string) -> string { return fmt_rgb(r, g, b, msg, "48", "49"); } -@[inline] +#[inline] public func bg_hex(hex: int32, msg: string) -> string { return fmt_rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF, msg, "48", "49"); } -@[inline] +#[inline] public func rgb(r: int32, g: int32, b: int32, msg: string) -> string { return fmt_rgb(r, g, b, msg, "38", "39"); } -@[inline] +#[inline] public func reset(msg: string) -> string { return fmt(msg, "0", "0"); } -@[inline] +#[inline] public func bold(msg: string) -> string { return fmt(msg, "1", "22"); } -@[inline] +#[inline] public func dim(msg: string) -> string { return fmt(msg, "2", "22"); } -@[inline] +#[inline] public func hidden(msg: string) -> string { return fmt(msg, "8", "28"); } -@[inline] +#[inline] public func italic(msg: string) -> string { return fmt(msg, "3", "23"); } -@[inline] +#[inline] public func inverse(msg: string) -> string { return fmt(msg, "7", "27"); } -@[inline] +#[inline] public func strikethrough(msg: string) -> string { return fmt(msg, "9", "29"); } -@[inline] +#[inline] public 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 1f8048a0a..0f1915f6f 100644 --- a/lib/std/src/conv/bool_to.ri +++ b/lib/std/src/conv/bool_to.ri @@ -2,12 +2,12 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@[inline] +#[inline] public func bool_to_usize(b: bool) -> usize { return if b { 1 } else { 0 }; } -@[inline] +#[inline] public func bool_to_isize(b: bool) -> isize { 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 f9593b946..c60db9834 100644 --- a/lib/std/src/conv/parse_int.ri +++ b/lib/std/src/conv/parse_int.ri @@ -11,7 +11,7 @@ public alias ValueOutOfRangeError = errors.ValueOutOfRangeError; const INT_SIZE: uint32 = #if _x64_ 64 #else 32 #endif; -@[inline] +#[inline] func lower(c: uint8) -> uint8 { return c | (b'x' - b'X'); } diff --git a/lib/std/src/conv/string_to.ri b/lib/std/src/conv/string_to.ri index 04e6d5cdf..24b2c7bac 100644 --- a/lib/std/src/conv/string_to.ri +++ b/lib/std/src/conv/string_to.ri @@ -2,67 +2,67 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. -@[inline] +#[inline] public func string_to_bool(s: string) -> bool { return s == "true"; } /// Equivalent to `parse_int(s, 0, 8)`, converted to type `int8`. -@[inline] +#[inline] public 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] +#[inline] public 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] +#[inline] public 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] +#[inline] public func string_to_int64(s: string) -> !int64 { return @as(int64, parse_int(s, 0, 64)!); } /// Equivalent to `parse_int(s, 0, isize.bits())`, converted to type `isize`. -@[inline] +#[inline] public func string_to_isize(s: string) -> !isize { return parse_int(s, 0, isize.bits())!; } /// Equivalent to `parse_uint(s, 0, 8)`, converted to type `uint8`. -@[inline] +#[inline] public 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] +#[inline] public 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] +#[inline] public 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] +#[inline] public func string_to_uint64(s: string) -> !uint64 { return @as(uint64, parse_uint(s, 0, 64)!); } /// Equivalent to `parse_uint(s, 0, usize.bits())`, converted to type `usize`. -@[inline] +#[inline] public func string_to_usize(s: string) -> !usize { return parse_uint(s, 0, usize.bits())!; } diff --git a/lib/std/src/dynlib/mod.ri b/lib/std/src/dynlib/mod.ri index a2dc313e7..078a54ae9 100644 --- a/lib/std/src/dynlib/mod.ri +++ b/lib/std/src/dynlib/mod.ri @@ -3,7 +3,7 @@ // be found in the LICENSE file. #if _LINUX_ -@![link_library("dl")] +#![link_library("dl")] #endif import c/libc; @@ -12,7 +12,7 @@ public static sharedLibExtension = get_shared_library_extension(); /// Returns a library name with the operating system specific extension for shared /// libraries. -@[inline] +#[inline] public func library_name(libname: string) -> string { return if libname.ends_with(sharedLibExtension) { libname @@ -21,7 +21,7 @@ public func library_name(libname: string) -> string { }; } -@[boxed] +#[boxed] public struct SymbolNotFoundError < Throwable { msg: string; @@ -30,7 +30,7 @@ public struct SymbolNotFoundError < Throwable { } } -@[boxed] +#[boxed] public struct CannotLoadLibraryError < Throwable { msg: string; @@ -51,7 +51,7 @@ public func load(path: string, global_symbols: bool = false) -> !Library { } } -@[boxed] +#[boxed] struct Library { public path: string; ptr: mut_anyptr; @@ -69,12 +69,12 @@ struct Library { } } - @[inline] + #[inline] public func exists(self, symbol: string) -> bool { return if _ := self.address_of(symbol) { true } else { false }; } - @[inline] + #[inline] public func close(self) { _ = unsafe { libc.dlclose(self.ptr) }; } @@ -91,7 +91,7 @@ func dlerror() -> ?string { return none; } -@[inline] +#[inline] func get_shared_library_extension() -> string { return #if _LINUX_ diff --git a/lib/std/src/env/mod.ri b/lib/std/src/env/mod.ri index f4d44c59c..b3d6f3da3 100644 --- a/lib/std/src/env/mod.ri +++ b/lib/std/src/env/mod.ri @@ -9,13 +9,13 @@ import c/libc; public static homeDir = get(#if _LINUX_ "HOME" #else "USERPROFILE" #endif) ?? ""; /// Returns `true` if the environment variable exists. -@[inline] +#[inline] public func exists(name: string) -> bool { return get(name) !is none; } /// Returns the value of the environment variable named by the key. -@[inline] +#[inline] public func get(name: string) -> ?string { return unsafe { if s := libc.getenv(name.ptr) { diff --git a/lib/std/src/errors/mod.ri b/lib/std/src/errors/mod.ri index eb984e8da..376d0780c 100644 --- a/lib/std/src/errors/mod.ri +++ b/lib/std/src/errors/mod.ri @@ -10,7 +10,7 @@ import ../traits; public alias ErrnoError = c.ErrnoError; public alias OutOfMemoryError = core.OutOfMemoryError; -@[boxed] +#[boxed] public struct InvalidSyntaxError < Throwable { msg: string; @@ -19,7 +19,7 @@ public struct InvalidSyntaxError < Throwable { } } -@[boxed] +#[boxed] public struct InvalidBaseError < Throwable { msg: string; @@ -28,7 +28,7 @@ public struct InvalidBaseError < Throwable { } } -@[boxed] +#[boxed] public struct InvalidBitSizeError < Throwable { msg: string; @@ -37,7 +37,7 @@ public struct InvalidBitSizeError < Throwable { } } -@[boxed] +#[boxed] public struct ValueOutOfRangeError < Throwable { msg: string; @@ -46,7 +46,7 @@ public struct ValueOutOfRangeError < Throwable { } } -@[boxed] +#[boxed] public struct GenericError < Throwable { msg: string; diff --git a/lib/std/src/flag/mod.ri b/lib/std/src/flag/mod.ri index 69623c41b..9b29af19d 100644 --- a/lib/std/src/flag/mod.ri +++ b/lib/std/src/flag/mod.ri @@ -41,7 +41,7 @@ public struct Flag < traits.Stringable { /// for specifying the accepted options and their values. The user should finally /// call `rest := parser.finalize()!` to get the rest of the non optional arguments /// (if there are any left). -@[boxed] +#[boxed] public struct FlagParser { /// The original arguments to be parsed. public original_args: []string; @@ -94,19 +94,19 @@ public struct FlagParser { } /// Set the application name to be used in 'usage' output. - @[inline] + #[inline] public func set_application_name(mut self, name: string) { self.application_name = name; } /// Set the application short description to be used in 'usage' output. - @[inline] + #[inline] public 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] + #[inline] public func add_description(mut self, desc: string) { self.application_description = if self.application_description.is_empty() { desc @@ -116,14 +116,14 @@ public struct FlagParser { } /// Set the application version to be used in 'usage' output. - @[inline] + #[inline] public 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] + #[inline] public func set_arguments_description(mut self, description: string) { self.args_description = description; } @@ -163,19 +163,19 @@ public struct FlagParser { /// Add an usage example. All examples will be listed in the help screen. If you /// do not give any examples, then a default usage will be shown, based on whether /// the application takes options and expects additional parameters. - @[inline] + #[inline] public 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] + #[inline] public 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] + #[inline] public func skip_executable(mut self) { self.args.delete(0); } @@ -184,7 +184,7 @@ public struct FlagParser { /// `.allow_unknown_args()`, so that the subcommand arguments (which generally are /// not known to your parent program), will not cause the validation in `.finalize()` /// to fail. - @[inline] + #[inline] public func allow_unknown_args(mut self) { self.allow_unknown_args = true; } diff --git a/lib/std/src/fs/Directory.ri b/lib/std/src/fs/Directory.ri index 99c295bff..634825c7c 100644 --- a/lib/std/src/fs/Directory.ri +++ b/lib/std/src/fs/Directory.ri @@ -5,7 +5,7 @@ import c; import c/libc; -@[boxed] +#[boxed] public struct CannotMakeDirectoryError < Throwable { msg: string; @@ -14,7 +14,7 @@ public struct CannotMakeDirectoryError < Throwable { } } -@[boxed] +#[boxed] public struct CannotMakeFileError < Throwable { msg: string; @@ -23,7 +23,7 @@ public struct CannotMakeFileError < Throwable { } } -@[boxed] +#[boxed] public struct CouldNotOpenDirectoryError < Throwable { msg: string; @@ -32,7 +32,7 @@ public struct CouldNotOpenDirectoryError < Throwable { } } -@[boxed] +#[boxed] public struct EmptyStringError < Throwable { msg: string; diff --git a/lib/std/src/fs/File.ri b/lib/std/src/fs/File.ri index 3fa419b69..88e1fa761 100644 --- a/lib/std/src/fs/File.ri +++ b/lib/std/src/fs/File.ri @@ -7,7 +7,7 @@ import c/libc; import ../mem; import { Stringable } from ../traits; -@[boxed] +#[boxed] public struct OperationFailedError < Throwable { msg: string; @@ -16,7 +16,7 @@ public struct OperationFailedError < Throwable { } } -@[boxed] +#[boxed] public struct File { f: *mut libc.FILE; mut is_opened: bool; @@ -31,7 +31,7 @@ public struct File { } /// Writes the byte `b` into the file. - @[inline] + #[inline] public func write_byte(mut self, b: uint8) { @ignore_not_mutated_warn(self); unsafe { @@ -40,7 +40,7 @@ public struct File { } /// Writes the string `s` into the file. - @[inline] + #[inline] public func write_string(mut self, s: string) { @ignore_not_mutated_warn(self); unsafe { @@ -54,7 +54,7 @@ public struct File { self.write_byte(b'\n'); } - @[inline] + #[inline] public func write_string_fmt(mut self, s: string, args: ...Stringable) { self.write_string(s.fmt(args)); } @@ -105,7 +105,7 @@ public struct File { } /// Returns true if the file is at end. - @[inline] + #[inline] public func is_eof(self) -> bool { return unsafe { libc.feof(self.f) != 0 }; } diff --git a/lib/std/src/fs/Path.ri b/lib/std/src/fs/Path.ri index 1b98f2258..9f260d927 100644 --- a/lib/std/src/fs/Path.ri +++ b/lib/std/src/fs/Path.ri @@ -15,31 +15,31 @@ public struct Path { public static delimiter = #if _WINDOWS_ ";" #else ":" #endif; /// Returns `true` if the given byte is a valid path separator - @[inline] + #[inline] public func is_separator(byte: uint8) -> bool { return byte == b'/' #if _WINDOWS_ or byte == b'\\' #endif; } /// Returns `true` if `path` (file or directory) exists. - @[inline] + #[inline] public func exists(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.O_RDONLY) == 0 }; } /// Returns `true` if `path` is executable. - @[inline] + #[inline] public func is_executable(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.X_OK) == 0 }; } /// Returns `true` if `path` is writable. - @[inline] + #[inline] public func is_writable(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.W_OK) == 0 }; } /// Returns `true` if `path` is readable. - @[inline] + #[inline] public func is_readable(path: string) -> bool { return unsafe { libc.access(path.ptr, libc.R_OK) == 0 }; } @@ -55,13 +55,13 @@ public struct Path { } /// Returns `true` if `path` is a file. - @[inline] + #[inline] public func is_file(path: string) -> bool { return Self.exists(path) and !Self.is_directory(path); } /// Returns `true` if `path` is absolute. - @[inline] + #[inline] public func is_absolute(path: string) -> bool { return path.len > 0 and path[0] == SEPARATOR; } diff --git a/lib/std/src/hash/fnv1a/mod.ri b/lib/std/src/hash/fnv1a/mod.ri index 3f19fb2f1..741e24ffc 100644 --- a/lib/std/src/hash/fnv1a/mod.ri +++ b/lib/std/src/hash/fnv1a/mod.ri @@ -13,7 +13,7 @@ const FNV64_OFFSET_BASIS: uint64 = 14695981039346656037; /// Returns a fnv1a hash of the memory block, described by the dynamic /// byte array `data`. -@[inline] +#[inline] public func sum32(data: []uint8) -> uint32 { mut hash := FNV32_OFFSET_BASIS; mut i: usize := 0; @@ -25,7 +25,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] +#[inline; unsafe] public func sum32_bytes(data: [*]uint8, data_len: usize) -> uint32 { mut hash := FNV32_OFFSET_BASIS; mut i: usize := 0; @@ -36,7 +36,7 @@ public func sum32_bytes(data: [*]uint8, data_len: usize) -> uint32 { } /// Returns a fnv1a hash of the string, described by `data` -@[inline] +#[inline] public func sum32_string(data: string) -> uint32 { mut hash := FNV32_OFFSET_BASIS; mut i: usize := 0; @@ -48,7 +48,7 @@ public func sum32_string(data: string) -> uint32 { /// Returns a fnv1a hash of the memory block, described by the dynamic /// byte array `data`. -@[inline] +#[inline] public func sum64(data: []uint8) -> uint64 { mut hash := FNV64_OFFSET_BASIS; mut i: usize := 0; @@ -60,7 +60,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] +#[inline; unsafe] public func sum64_bytes(data: [*]uint8, data_len: usize) -> uint64 { mut hash := FNV64_OFFSET_BASIS; mut i: usize := 0; @@ -71,7 +71,7 @@ public func sum64_bytes(data: [*]uint8, data_len: usize) -> uint64 { } /// Returns a fnv1a hash of the string, described by `data` -@[inline] +#[inline] public func sum64_string(data: string) -> uint64 { mut hash := FNV64_OFFSET_BASIS; mut i: usize := 0; diff --git a/lib/std/src/process/mod.ri b/lib/std/src/process/mod.ri index b99d15e42..d78e32bb2 100644 --- a/lib/std/src/process/mod.ri +++ b/lib/std/src/process/mod.ri @@ -19,7 +19,7 @@ public static args = core.ARGS; public static wdAtStartup = get_cwd() catch "."; public static executableDir = Path.dirname(executable() catch wdAtStartup); -@[boxed] +#[boxed] public struct NotADirectoryError < Throwable { msg: string; @@ -40,7 +40,7 @@ struct Result { public exit_code: int32; } -@[boxed] +#[boxed] struct ExecutionFailedError < Throwable { cmd: string; diff --git a/lib/std/src/semver/mod.ri b/lib/std/src/semver/mod.ri index 0f01880fd..d967aa367 100644 --- a/lib/std/src/semver/mod.ri +++ b/lib/std/src/semver/mod.ri @@ -11,7 +11,7 @@ public enum Increment as uint8 { Patch } -@[boxed] +#[boxed] public struct EmptyInputError < Throwable { public func to_string(self) -> string { _ = self; @@ -19,7 +19,7 @@ public struct EmptyInputError < Throwable { } } -@[boxed] +#[boxed] public struct InvalidVersionFormatError < Throwable { input: string; @@ -28,7 +28,7 @@ public struct InvalidVersionFormatError < Throwable { } } -@[boxed] +#[boxed] public struct InvalidVersionError < Throwable { input: string; @@ -38,7 +38,7 @@ public struct InvalidVersionError < Throwable { } /// Represents a semantic version in semver format. -@[boxed] +#[boxed] public struct Version < traits.Stringable { public major: usize; public minor: usize; @@ -59,14 +59,14 @@ public struct Version < traits.Stringable { } /// Returns a `Version` structure with given `major`, `minor` and `patch` versions. - @[inline] + #[inline] public func build(major: usize, minor: usize, patch: usize) -> Self { // TODO: check if versions are greater than zero. return Version(major, minor, patch, "", ""); } /// Returns a `Version` structure with incremented values. - @[inline] + #[inline] public func increment(self, typ: Increment) -> Self { mut major := self.major; mut minor := self.minor; @@ -90,7 +90,7 @@ public struct Version < traits.Stringable { /// Satisfies returns `true` if the `input` expression can be validated to `true` /// when run against this `Version`. - @[inline] + #[inline] public func satisfies(self, input: string) -> bool { return if range := Range.parse(input) { range.satisfies(self) @@ -99,13 +99,13 @@ public struct Version < traits.Stringable { }; } - @[inline] + #[inline] public 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] + #[inline] public func !=(self, v2: Self) -> bool { return !(self == v2); } @@ -136,12 +136,12 @@ public struct Version < traits.Stringable { return self.patch < v2.patch; } - @[inline] + #[inline] public func >=(self, v2: Self) -> bool { return self == v2 or self > v2; } - @[inline] + #[inline] public func <=(self, v2: Self) -> bool { return self == v2 or self < v2; } @@ -160,7 +160,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] +#[inline] public func coerce(input: string) -> !Version { if version := RawVersion.parse(input).coerce() { return version; @@ -170,7 +170,7 @@ public func coerce(input: string) -> !Version { /// Returns `true` if the `input` `string` can be converted to a semantic `Version` /// struct. -@[inline] +#[inline] public func is_valid(input: string) -> bool { return RawVersion.parse(input).is_valid(); } diff --git a/lib/std/src/semver/parse.ri b/lib/std/src/semver/parse.ri index 83b7f2938..301dd1508 100644 --- a/lib/std/src/semver/parse.ri +++ b/lib/std/src/semver/parse.ri @@ -41,7 +41,7 @@ struct RawVersion { and is_valid_string(self.prerelease) and is_valid_string(self.metadata); } - @[inline] + #[inline] func is_missing(&self, typ: uint64) -> bool { return typ >= self.raw_ints.len - 1; } @@ -69,7 +69,7 @@ struct RawVersion { return self.to_version(); } - @[inline] + #[inline] func to_version(&self) -> Version { return Version( string_to_usize(self.raw_ints[VER_MAJOR]) catch 0, diff --git a/lib/std/src/semver/range.ri b/lib/std/src/semver/range.ri index 74db19483..5a95cf477 100644 --- a/lib/std/src/semver/range.ri +++ b/lib/std/src/semver/range.ri @@ -15,7 +15,7 @@ enum Operator as uint8 { Eq } -@[boxed] +#[boxed] public struct InvalidComparatorFormatError < Throwable { msg: string; @@ -53,7 +53,7 @@ struct Comparator { return Comparator(coerce(raw_version) catch return none, op); } - @[inline] + #[inline] func satisfies(&self, ver: Version) -> bool { return switch self.op { .Gt => ver > self.ver, @@ -86,7 +86,7 @@ struct ComparatorSet { return ComparatorSet(comparators); } - @[inline] + #[inline] func expand(input: string) -> ?ComparatorSet { return switch input[0] { b'~' => expand_tilda(input[1..]), @@ -222,12 +222,12 @@ func expand_hyphen(raw_range: string) -> ?ComparatorSet { return make_comparator_set_ge_le(min_ver, max_ver); } -@[inline] +#[inline] func make_comparator_set_ge_lt(min: Version, max: Version) -> ComparatorSet { return ComparatorSet([Comparator(min, .Ge), Comparator(max, .Lt)]); } -@[inline] +#[inline] func make_comparator_set_ge_le(min: Version, max: Version) -> ComparatorSet { return ComparatorSet([Comparator(min, .Ge), Comparator(max, .Le)]); } diff --git a/lib/std/src/strings/TextScanner.ri b/lib/std/src/strings/TextScanner.ri index f5f4e36b5..5313bec7d 100644 --- a/lib/std/src/strings/TextScanner.ri +++ b/lib/std/src/strings/TextScanner.ri @@ -16,7 +16,7 @@ public struct TextScanner { /// Returns the next character code from the input text or `none` if it /// can't reach the next character. Advances the scanner position. - @[inline] + #[inline] public func next(mut self) -> ?uint8 { if self.pos < self.len { opos := self.pos; @@ -28,7 +28,7 @@ public struct TextScanner { /// Skips ahead `n` characters, stopping at the end of the input; `skip` is /// slightly faster than `.next()`. - @[inline] + #[inline] public func skip(mut self, n: usize = 1) { self.pos += n; if self.pos > self.len { @@ -39,7 +39,7 @@ public struct TextScanner { /// Returns the character code from the input text at position + `n` or `none` if /// it can't peek `n` characters ahead. /// Unlike `.next()`, `.peek()` does not change the state of the scanner. - @[inline] + #[inline] public func peek(&self, n: usize = 0) -> ?uint8 { if self.pos + n < self.len { return self.input[self.pos + n]; @@ -58,7 +58,7 @@ public struct TextScanner { /// Returns the character code from the input text at position - `n` or `none` if /// it can't peek `n` characters back. /// Unlike `.back()`, `.peek_back()` does not change the state of the scanner. - @[inline] + #[inline] public func peek_back(&self, n: usize = 1) -> ?uint8 { offset := n + 1; if self.pos >= offset { @@ -70,7 +70,7 @@ public struct TextScanner { /// Returns the current character code from the input text or `none` at the start /// of the input text. /// NOTE: after `c := ts.next()`, `ts.current()` will also return `c`. - @[inline] + #[inline] public func current(self) -> ?usize { if self.pos > 0 { return self.input[self.pos - 1]; diff --git a/lib/std/src/sys/arch.ri b/lib/std/src/sys/arch.ri index 23dfdb77f..6af7a8186 100644 --- a/lib/std/src/sys/arch.ri +++ b/lib/std/src/sys/arch.ri @@ -10,7 +10,7 @@ public enum Arch as uint8 { X86, Amd64; - @[inline] + #[inline] public func from_string(arch: string) -> ?Arch { return switch arch { "i386", "x86", "_X86_" => .X86, @@ -21,7 +21,7 @@ public enum Arch as uint8 { } /// Returns the current architecture. -@[inline] +#[inline] public func arch() -> Arch { #if _X86_ return .X86; diff --git a/lib/std/src/sys/c_runtime.ri b/lib/std/src/sys/c_runtime.ri index 28e569a01..12f6cae4b 100644 --- a/lib/std/src/sys/c_runtime.ri +++ b/lib/std/src/sys/c_runtime.ri @@ -10,7 +10,7 @@ public enum CRuntime as uint8 { } /// Returns the current C core. -@[inline] +#[inline] public func c_runtime() -> CRuntime { return .Glibc; } diff --git a/lib/std/src/sys/mod.ri b/lib/std/src/sys/mod.ri index 716ec460c..ff830e6f5 100644 --- a/lib/std/src/sys/mod.ri +++ b/lib/std/src/sys/mod.ri @@ -9,7 +9,7 @@ import ../process; #endif /// Returns the number of virtual CPU cores found on the system. -@[inline] +#[inline] public func nr_cpus() -> int32 { #if _LINUX_ return unsafe { libc.get_nprocs() }; @@ -19,25 +19,25 @@ public func nr_cpus() -> int32 { } /// Returns true if the current executable is running on a 32-bit system. -@[inline] +#[inline] public func is_32bit() -> bool { return @size_of(anyptr) == 4; } /// Returns true if the current executable is running on a 64-bit system. -@[inline] +#[inline] public func is_64bit() -> bool { return @size_of(anyptr) == 8; } /// Returns true if the current executable is running on a little-endian system. -@[inline] +#[inline] public 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] +#[inline] public 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 8af757ca4..72fedb108 100644 --- a/lib/std/src/sys/os.ri +++ b/lib/std/src/sys/os.ri @@ -11,7 +11,7 @@ public enum OS as uint8 { Windows, Macos; - @[inline] + #[inline] public func from_string(name: string) -> ?OS { return switch name { "linux", "_LINUX_" => .Linux, @@ -23,7 +23,7 @@ public enum OS as uint8 { } /// Returns the current operating system. -@[inline] +#[inline] public func os() -> OS { #if _LINUX_ return .Linux; diff --git a/rivetc/src/lexer.py b/rivetc/src/lexer.py index 72d423588..e34552379 100644 --- a/rivetc/src/lexer.py +++ b/rivetc/src/lexer.py @@ -604,6 +604,8 @@ def internal_next(self): return token.Token("", Kind.OrElse, pos) return token.Token("", Kind.Question, pos) elif ch == "#": + if nextc == "[" or nextc == "!": + return token.Token("", Kind.Hash, pos) self.pp_directive() continue elif ch == "&": diff --git a/rivetc/src/parser.py b/rivetc/src/parser.py index b77cb2b23..525a59bf8 100644 --- a/rivetc/src/parser.py +++ b/rivetc/src/parser.py @@ -107,7 +107,7 @@ def parse_annotations(self, parse_mod_annotations = False): if parse_mod_annotations and self.mod_sym.annotations == None: self.mod_sym.annotations = ast.Annotations() annotations = ast.Annotations() - while self.accept(Kind.At): + while self.accept(Kind.Hash): if parse_mod_annotations: self.expect(Kind.Bang) if self.accept(Kind.Lbracket): @@ -163,7 +163,7 @@ def parse_decls(self): def parse_decl(self): doc_comment = self.parse_doc_comment() annotations = self.parse_annotations( - self.tok.kind == Kind.At and self.peek_tok.kind == Kind.Bang + self.tok.kind == Kind.Hash and self.peek_tok.kind == Kind.Bang ) is_public = self.is_public() pos = self.tok.pos diff --git a/rivetc/src/token.py b/rivetc/src/token.py index a75568483..e9e610e11 100644 --- a/rivetc/src/token.py +++ b/rivetc/src/token.py @@ -38,6 +38,7 @@ class Kind(Enum): Dot = auto_enum() # . DotDot = auto_enum() # .. Ellipsis = auto_enum() # ... + Hash = auto_enum() # # At = auto_enum() # @ Arrow = auto_enum() # => Arrow2 = auto_enum() # -> @@ -186,6 +187,7 @@ def __str__(self): Kind.Dot: ".", Kind.DotDot: "..", Kind.Ellipsis: "...", + Kind.Hash: "#", Kind.At: "@", Kind.Arrow: "=>", Kind.Arrow2: "->", diff --git a/samples/factorial.ri b/samples/factorial.ri index a7a4fe978..3c3a32414 100644 --- a/samples/factorial.ri +++ b/samples/factorial.ri @@ -1,6 +1,6 @@ import std/console; -@[inline] +#[inline] func factorial(n: uint32) -> uint32 { return if n <= 1 { 1 diff --git a/tests/invalid/special_methods.ri b/tests/invalid/special_methods.ri index b205ab78b..68d8c794b 100644 --- a/tests/invalid/special_methods.ri +++ b/tests/invalid/special_methods.ri @@ -5,7 +5,7 @@ struct SpecialMethod { _ = self; } - @[inline] + #[inline] func __ann__(self) { _ = self; } diff --git a/tests/valid/src/enums.ri b/tests/valid/src/enums.ri index 9af5ced25..d88ac63cb 100644 --- a/tests/valid/src/enums.ri +++ b/tests/valid/src/enums.ri @@ -96,7 +96,7 @@ test "enums: boxed enum with fields" { } } -@[default_value(.Abc(5))] +#[default_value(.Abc(5))] enum DefaultValue { Abc: int32 } diff --git a/tests/valid/src/traits.ri b/tests/valid/src/traits.ri index 8af545161..a9590f762 100644 --- a/tests/valid/src/traits.ri +++ b/tests/valid/src/traits.ri @@ -56,7 +56,7 @@ trait Eq { } } -@[boxed] +#[boxed] struct Poketrait < Eq { public func equal(self, x: Eq) -> bool { return self.x == x.x; @@ -71,7 +71,7 @@ test "traits: default method" { @assert(ship( Poketrait("Shell"), Poketrait("Shell") )); } -@[default_value(IntegerValue(5))] +#[default_value(IntegerValue(5))] trait Integer {} struct IntegerValue {