Skip to content

Commit f590a42

Browse files
author
StunxFS
committed
refact(core): remove .c.ri extension from some files that do not depend on C code
1 parent 3a04bbe commit f590a42

File tree

11 files changed

+110
-104
lines changed

11 files changed

+110
-104
lines changed

lib/core/src/StringFormatter.c.ri renamed to lib/core/src/StringFormatter.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public struct StringFormatter {
114114

115115
func fwidth(mut self) -> (bool, isize) {
116116
if unsafe { self.buf.ptr[self.i] != b':' } {
117-
return (false, @as(isize, 0));
117+
return (false, 0);
118118
}
119119
self.i += 1;
120120
start := self.i;
File renamed without changes.

lib/core/src/backtrace.c.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func bt_print_callback(
5353
} else {
5454
string.from_raw(filename_ptr)
5555
};
56-
console_eprintln(" at {} from \"{}\":{}", fn_name, file_name, lineno);
56+
console_eprintln(" from {} in \"{}\":{}", fn_name, file_name, lineno);
5757
}
5858
return 0;
5959
}
File renamed without changes.
File renamed without changes.

lib/core/src/errors.c.ri

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,3 @@ public alias ErrnoError = c.ErrnoError;
1010
public func last_errno_error() -> c.ErrnoError {
1111
return c.last_errno_error();
1212
}
13-
14-
/// This trait is used for errors throwed with result types (!T).
15-
public trait Throwable < Stringable { }
16-
17-
#[inline]
18-
func error_panic(err: Throwable) {
19-
console_eprintln("unhandled error: {}", err.to_string());
20-
returnTrace.print();
21-
process_exit(102);
22-
}
23-
24-
#[boxed]
25-
public struct InvalidArgumentError < Throwable {
26-
msg: string;
27-
28-
#[inline]
29-
public func to_string(self) -> string {
30-
return self.msg;
31-
}
32-
}
33-
34-
#[boxed]
35-
public struct OutOfMemoryError < Throwable {
36-
msg: string;
37-
38-
#[inline]
39-
public func to_string(self) -> string {
40-
return self.msg;
41-
}
42-
}
43-
44-
#[boxed]
45-
public struct ReadFailedError < Throwable {
46-
msg: string;
47-
48-
#[inline]
49-
public func to_string(self) -> string {
50-
return self.msg;
51-
}
52-
}
53-
54-
struct CallTrace {
55-
name: string;
56-
file: string;
57-
line: usize;
58-
}
59-
60-
static returnTrace = ReturnTrace();
61-
62-
struct ReturnTrace {
63-
mut traces: []CallTrace = @vec(CallTrace, 5);
64-
65-
#[inline]
66-
func add(mut self, trace: CallTrace) {
67-
self.traces.push(trace);
68-
}
69-
70-
func print(self) {
71-
for trace in self.traces {
72-
console_eprintln(
73-
" at {} from \"{}\":{}", demangle_symbol(trace.name),
74-
trace.file, trace.line
75-
);
76-
}
77-
}
78-
79-
func clear(mut self) {
80-
self.traces.clear();
81-
}
82-
}

lib/core/src/errors.ri

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (C) 2023 The Rivet Developers. All rights reserved.
2+
// Use of this source code is governed by an MIT license that can
3+
// be found in the LICENSE file.
4+
5+
static returnTrace = ReturnTrace();
6+
7+
/// This trait is used for errors throwed with result types (!T).
8+
public trait Throwable < Stringable { }
9+
10+
#[inline]
11+
func uncatched_error(err: Throwable) {
12+
console_eprintln("uncatched error: {}", err.to_string());
13+
returnTrace.print();
14+
process_exit(102);
15+
}
16+
17+
struct CallTrace {
18+
name: string;
19+
file: string;
20+
line: usize;
21+
}
22+
23+
struct ReturnTrace {
24+
mut traces: []CallTrace = @vec(CallTrace, 5);
25+
26+
#[inline]
27+
func add(mut self, trace: CallTrace) {
28+
self.traces.push(trace);
29+
}
30+
31+
func print(self) {
32+
for trace in self.traces {
33+
console_eprintln(
34+
" from {} in \"{}\":{}", demangle_symbol(trace.name),
35+
trace.file, trace.line
36+
);
37+
}
38+
}
39+
40+
func clear(mut self) {
41+
self.traces.clear();
42+
}
43+
}
44+
45+
#[boxed]
46+
public struct InvalidArgumentError < Throwable {
47+
msg: string;
48+
49+
#[inline]
50+
public func to_string(self) -> string {
51+
return self.msg;
52+
}
53+
}
54+
55+
#[boxed]
56+
public struct OutOfMemoryError < Throwable {
57+
msg: string;
58+
59+
#[inline]
60+
public func to_string(self) -> string {
61+
return self.msg;
62+
}
63+
}
64+
65+
#[boxed]
66+
public struct ReadFailedError < Throwable {
67+
msg: string;
68+
69+
#[inline]
70+
public func to_string(self) -> string {
71+
return self.msg;
72+
}
73+
}
File renamed without changes.

lib/core/src/lib.c.ri renamed to lib/core/src/lib.ri

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,3 @@ func internal_resize(ptr: ?mut_anyptr, sz: usize) -> mut_anyptr {
5555
)
5656
};
5757
}
58-
59-
struct EnumInfo {
60-
_rc_: usize;
61-
_id_: usize;
62-
obj: anyptr;
63-
}
64-
65-
func enum_cast(ptr: anyptr, expected_id: usize) -> anyptr {
66-
enum_info := unsafe { @as(&EnumInfo, ptr) };
67-
if enum_info._id_ != expected_id {
68-
// TODO: replace indexes with names
69-
console_eprintln(
70-
"panic: enum cast: cannot cast ID({}) to ID({})", enum_info._id_, expected_id
71-
);
72-
bt_print(2);
73-
process_exit(1);
74-
}
75-
return enum_info.obj;
76-
}
77-
78-
func trait_cast(got_obj: anyptr, got_id: usize, expected_id: usize) -> anyptr {
79-
if got_id != expected_id {
80-
// TODO: replace indexes with names
81-
console_eprintln(
82-
"panic: trait cast: cannot cast ID({}) to ID({})", got_id, expected_id
83-
);
84-
bt_print(2);
85-
process_exit(1);
86-
}
87-
return got_obj;
88-
}

lib/core/src/utils.c.ri

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (C) 2023 The Rivet Developers. All rights reserved.
2+
// Use of this source code is governed by an MIT license that can
3+
// be found in the LICENSE file.
4+
5+
struct EnumInfo {
6+
_rc_: usize;
7+
_id_: usize;
8+
obj: anyptr;
9+
}
10+
11+
func enum_cast(ptr: anyptr, expected_id: usize) -> anyptr {
12+
enum_info := unsafe { @as(&EnumInfo, ptr) };
13+
if enum_info._id_ != expected_id {
14+
// TODO: replace indexes with names
15+
console_eprintln(
16+
"panic: enum cast: cannot cast ID({}) to ID({})", enum_info._id_, expected_id
17+
);
18+
bt_print(2);
19+
process_exit(1);
20+
}
21+
return enum_info.obj;
22+
}
23+
24+
func trait_cast(got_obj: anyptr, got_id: usize, expected_id: usize) -> anyptr {
25+
if got_id != expected_id {
26+
// TODO: replace indexes with names
27+
console_eprintln(
28+
"panic: trait cast: cannot cast ID({}) to ID({})", got_id, expected_id
29+
);
30+
bt_print(2);
31+
process_exit(1);
32+
}
33+
return got_obj;
34+
}

rivetc/src/codegen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ def gen_expr(self, expr, custom_tmp = None):
14091409
self.gen_defer_stmts(True, res_value_is_err)
14101410
if self.cur_fn_is_main or self.inside_let_decl:
14111411
self.cur_fn.add_call(
1412-
"_R4core11error_panicF", [
1412+
"_R4core15uncatched_errorF", [
14131413
ir.Selector(
14141414
self.ir_type(self.comp.throwable_t),
14151415
res_value, ir.Name("err")

0 commit comments

Comments
 (0)