Improve Kym Run-TIme Errors #45

Merged
kayomn merged 5 commits from better-kym-runtime-errors into main 2023-11-06 00:47:37 +01:00
1 changed files with 7 additions and 2 deletions
Showing only changes of commit 8b0182f03c - Show all commits

View File

@ -683,8 +683,8 @@ pub const RuntimeEnv = struct {
break: convert self.new_string(string[0 .. length.?]); break: convert self.new_string(string[0 .. length.?]);
}, },
.syscall => self.new_string("<syscall>"), .syscall => self.new_string("syscall"),
.dynamic => self.new_string("<dynamic>"), .dynamic => |dynamic| dynamic.typeinfo().to_string(self, dynamic.userdata()),
}; };
} }
@ -957,6 +957,7 @@ pub const Typeinfo = struct {
name: []const coral.io.Byte, name: []const coral.io.Byte,
size: usize, size: usize,
destruct: ?*const fn (env: *RuntimeEnv, userdata: []coral.io.Byte) void = null, destruct: ?*const fn (env: *RuntimeEnv, userdata: []coral.io.Byte) void = null,
to_string: *const fn (env: *RuntimeEnv, userdata: []coral.io.Byte) RuntimeError!*RuntimeRef = default_to_string,
call: *const fn (env: *RuntimeEnv, userdata: []coral.io.Byte, frame: Frame) RuntimeError!?*RuntimeRef = default_call, call: *const fn (env: *RuntimeEnv, userdata: []coral.io.Byte, frame: Frame) RuntimeError!?*RuntimeRef = default_call,
get: *const fn (env: *RuntimeEnv, userdata: []coral.io.Byte, index: *const RuntimeRef) RuntimeError!?*RuntimeRef = default_get, get: *const fn (env: *RuntimeEnv, userdata: []coral.io.Byte, index: *const RuntimeRef) RuntimeError!?*RuntimeRef = default_get,
set: *const fn (env: *RuntimeEnv, userdata: []coral.io.Byte, value: *const RuntimeRef, value: ?*const RuntimeRef) RuntimeError!void = default_set, set: *const fn (env: *RuntimeEnv, userdata: []coral.io.Byte, value: *const RuntimeRef, value: ?*const RuntimeRef) RuntimeError!void = default_set,
@ -972,6 +973,10 @@ pub const Typeinfo = struct {
fn default_set(env: *RuntimeEnv, _: []coral.io.Byte, _: *const RuntimeRef, _: ?*const RuntimeRef) RuntimeError!void { fn default_set(env: *RuntimeEnv, _: []coral.io.Byte, _: *const RuntimeRef, _: ?*const RuntimeRef) RuntimeError!void {
return env.raise(error.BadOperation, "this dynamic object is not set-indexable", .{}); return env.raise(error.BadOperation, "this dynamic object is not set-indexable", .{});
} }
fn default_to_string(env: *RuntimeEnv, _: []coral.io.Byte) RuntimeError!*RuntimeRef {
return env.raise(error.BadOperation, "this dynamic object is not stringable", .{});
}
}; };
pub fn assert(env: *RuntimeEnv, condition: bool) RuntimeError!void { pub fn assert(env: *RuntimeEnv, condition: bool) RuntimeError!void {