Skip to content

Commit

Permalink
refact(all): replace annotation syntax, use # instead of @
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Oct 28, 2023
1 parent 128b10b commit e91f889
Show file tree
Hide file tree
Showing 87 changed files with 461 additions and 452 deletions.
2 changes: 1 addition & 1 deletion cmd/src/utils/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions lib/c/src/errno.ri
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import c/libc;

@[boxed]
#[boxed]
public struct ErrnoError < Throwable {
public msg: string;
public code: int32;
Expand All @@ -14,7 +14,7 @@ public struct ErrnoError < Throwable {
}
}

@[inline]
#[inline]
public func errno() -> int32 {
return unsafe {
#if _LINUX_
Expand All @@ -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) {
Expand All @@ -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());
}
2 changes: 1 addition & 1 deletion lib/c/src/wyhash.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/StaticBuffer.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
28 changes: 14 additions & 14 deletions lib/core/src/StringBuilder.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions lib/core/src/Vector.ri
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
// 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;
mut len: usize;
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) };
}
Expand Down Expand Up @@ -122,7 +122,7 @@ struct Vector {
self.len = 0;
}

@[inline]
#[inline]
func is_empty(self) -> bool {
return self.len == 0;
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ struct Vector {
);
}

@[inline]
#[inline]
func slice_from(self, start: usize) -> Self {
return self.slice(start, self.len);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/array.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion lib/core/src/backtrace.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/bool.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
}
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/console.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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_;
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions lib/core/src/errors.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit e91f889

Please sign in to comment.