Skip to content

Commit

Permalink
change boxed syntax from + to ^
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Jan 19, 2024
1 parent faf54f3 commit 6bdfe90
Show file tree
Hide file tree
Showing 91 changed files with 1,370 additions and 1,358 deletions.
6 changes: 3 additions & 3 deletions cmd/src/tools/cmd_fmt.ri
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pub func cmd_fmt(args: [:]string) -> ! {
utils.error("no input received");
}
for input in remaining {
prefs_ := +mut prefs.Prefs(is_fmt: true, hide_all_warns: true);
prefs_ := ^mut prefs.Prefs(is_fmt: true, hide_all_warns: true);
prefs_.set_input(input);
prefs_.load_module_info()!;
env := ast.Env.new(prefs_);
files := Directory.walk(input, ".ri")!;
formatter := +mut fmt.Formatter(prefs_, write_to_file: write_to_file);
parser_ := +mut parser.Parser(env: env);
formatter := ^mut fmt.Formatter(prefs_, write_to_file: write_to_file);
parser_ := ^mut parser.Parser(env: env);
for source_file in parser_.parse_module_files(files) {
utils.info("Formatting file `{}`...", source_file.path);
output := formatter.format(source_file);
Expand Down
6 changes: 3 additions & 3 deletions lib/c/src/errno.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct ErrnoError < Throwable {
pub msg: string;
pub code: int32;

pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return "errno: {} (code: {})".fmt(self.msg, self.code);
}
}
Expand All @@ -34,6 +34,6 @@ pub func errno_msg(code: int32 := errno()) -> string {
}

#[inline]
pub func last_errno_error() -> +ErrnoError {
return +ErrnoError(errno_msg(), errno());
pub func last_errno_error() -> ^ErrnoError {
return ^ErrnoError(errno_msg(), errno());
}
4 changes: 2 additions & 2 deletions lib/core/src/StringBuilder.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ pub struct StringBuilder < Stringable {
}

#[inline]
pub func write_fmt(&mut self, s: string, args: ...+Stringable) {
pub func write_fmt(&mut self, s: string, args: ...^Stringable) {
self.write(s.fmt(args));
}

pub func writeln_fmt(&mut self, s: string, args: ...+Stringable) {
pub func writeln_fmt(&mut self, s: string, args: ...^Stringable) {
self.write(s.fmt(args));
self.write_byte('\n');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/StringFormatter.ri
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct StringFormatter {
mut i: uint;
mut res: StringBuilder;

func fmt(&mut self, args: ...+Stringable) -> string {
func fmt(&mut self, args: ...^Stringable) -> string {
self.res = StringBuilder.new(self.buf.len);
mut args_idx: uint := 0;
while self.i < self.buf.len : self.i += 1 {
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/TestRunner.ri
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ $if _TESTS_ {
}
}
func test_error_throwed(err: +Throwable, pos: string, test_: &mut Test) {
func test_error_throwed(err: ^Throwable, pos: string, test_: &mut Test) {
test_.result = .ErrorThrowed;
test_.err = err;
test_.err_pos = pos;
Expand All @@ -71,7 +71,7 @@ $if _TESTS_ {
mut early_return: bool;
mut err_pos: string;
mut err_msg: string;
mut err: +Throwable;
mut err: ^Throwable;
}
struct TestRunner {
Expand Down Expand Up @@ -127,7 +127,7 @@ $if _TESTS_ {
self.fail_tests += 1;
}

func print_error_throwed(&mut self, pos: string, err: +Throwable) {
func print_error_throwed(&mut self, pos: string, err: ^Throwable) {
console_ewriteln(failed_status);
console_ewriteln(" at {}: error throwed: {}", bold(pos), err);
self.fail_tests += 1;
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/console.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import c/libc;

/// Writes a message to stdout. Unlike `println` stdout is not automatically
/// flushed.
pub func console_write(s: string, args: ...+Stringable) {
pub func console_write(s: string, args: ...^Stringable) {
sx := s.fmt(args);
unsafe {
write_buf_to_fd(1, sx.ptr, sx.len);
Expand All @@ -15,14 +15,14 @@ pub func console_write(s: string, args: ...+Stringable) {

/// Writes a message with a line end to stdout. stdout is flushed.
#[inline]
pub func console_writeln(s: string := "", args: ...+Stringable) {
pub func console_writeln(s: string := "", args: ...^Stringable) {
unsafe {
writeln_to_fd(1, s.fmt(args));
}
}

/// Writes a message to stderr. Both stderr and stdout are flushed.
pub func console_ewrite(s: string, args: ...+Stringable) {
pub func console_ewrite(s: string, args: ...^Stringable) {
sx := s.fmt(args);
unsafe {
_ = libc.fflush(libc.stdout);
Expand All @@ -34,7 +34,7 @@ pub func console_ewrite(s: string, args: ...+Stringable) {

/// Writes a message with a line end to stderr. Both stderr and stdout are
/// flushed.
pub func console_ewriteln(s: string := "", args: ...+Stringable) {
pub func console_ewriteln(s: string := "", args: ...^Stringable) {
unsafe {
_ = libc.fflush(libc.stdout);
_ = libc.fflush(libc.stderr);
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 @@ -17,7 +17,7 @@ var return_trace := ReturnTrace();
pub trait Throwable < Stringable { }

#[inline]
func uncatched_error(err: +Throwable) {
func uncatched_error(err: ^Throwable) {
console_ewriteln("uncatched error: {}", err.to_string());
return_trace.print();
process_exit(102);
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct InvalidArgumentError < Throwable {
msg: string;

#[inline]
pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
Expand All @@ -76,7 +76,7 @@ pub struct OutOfMemoryError < Throwable {
msg: string;

#[inline]
pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
Expand All @@ -86,7 +86,7 @@ pub struct ReadFailedError < Throwable {
msg: string;

#[inline]
pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
Expand All @@ -95,7 +95,7 @@ pub struct ReadFailedError < Throwable {
pub struct InvalidSyntaxError < Throwable {
msg: string;

pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
Expand All @@ -104,7 +104,7 @@ pub struct InvalidSyntaxError < Throwable {
pub struct InvalidBaseError < Throwable {
msg: string;

pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
Expand All @@ -113,7 +113,7 @@ pub struct InvalidBaseError < Throwable {
pub struct InvalidBitSizeError < Throwable {
msg: string;

pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
Expand All @@ -122,7 +122,7 @@ pub struct InvalidBitSizeError < Throwable {
pub struct ValueOutOfRangeError < Throwable {
msg: string;

pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
2 changes: 1 addition & 1 deletion lib/core/src/lib.ri
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func assert(cond: bool, msg: string) {
}
}

func runtime_error(s: string, args: ...+Stringable) -> never {
func runtime_error(s: string, args: ...^Stringable) -> never {
console_ewriteln("runtime error: {}", s.fmt(args));
bt_print(2);
process_exit(100);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/process.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub func process_id() -> uint32 {

/// Terminates current thread execution immediately after displaying a
/// message, followed by a backtrace.
pub func process_panic(s: string := "", args: ...+Stringable) -> never {
pub func process_panic(s: string := "", args: ...^Stringable) -> never {
console_ewriteln("panic: {}", s.fmt(args));
bt_print(2);
process_exit(101);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/rune.ri
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func len_utf8(code: uint32) -> uint {
pub struct TooManyBytesError < Throwable {
msg: string;

pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return self.msg;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/string.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub struct string < Stringable, Hashable, Throwable {
/// If the replacement positions exceed the number of passed arguments, a panic
/// occurs.
#[inline]
pub func fmt(&self, args: ...+Stringable) -> Self {
pub func fmt(&self, args: ...^Stringable) -> Self {
return if args.len == 0 {
self.*
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/traits.ri
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// file.

pub trait Stringable {
func to_string(+self) -> string;
func to_string(^self) -> string;
}

pub trait Hashable {
func hash(+self) -> uint;
func hash(^self) -> uint;
}
2 changes: 1 addition & 1 deletion lib/core/tests/string_test.ri
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ test "string.bytes_between()" {

test "string.runes_between()" {
str := "José Mend";
@assert(str.runes_between(2, 4) == +['s', 'é']);
@assert(str.runes_between(2, 4) == ^['s', 'é']);
}
6 changes: 3 additions & 3 deletions lib/core/tests/vector_test.ri
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test "dynamic arrays: push and pop" {
mut vec := +["A", "B"];
mut vec := ^["A", "B"];
@assert(vec.len == 2);

vec.push("C");
Expand All @@ -12,14 +12,14 @@ test "dynamic arrays: push and pop" {
}

test "dynamic arrays: clear" {
mut vec := +["A", "B"];
mut vec := ^["A", "B"];
@assert(vec.len == 2);
@assert(vec[0] == "A");
@assert(vec[1] == "B");

vec.clear();
@assert(vec.len == 0);
@assert(vec == +[]);
@assert(vec == ^[]);

vec.push("C");
@assert(vec.len == 1);
Expand Down
4 changes: 2 additions & 2 deletions lib/rivet/src/ast/Attributes.ri
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import ../token;
pub struct AttributeDuplicatedError < Throwable {
name: string;

pub func to_string(+self) -> string {
pub func to_string(^self) -> string {
return "duplicated attribute `{}`".fmt(self.name);
}
}

pub struct AttributeArgument {
pub name: string;
pub expr: +mut Expr;
pub expr: ^mut Expr;
pub is_named: bool;
}

Expand Down
Loading

0 comments on commit 6bdfe90

Please sign in to comment.