Replace System Objects with Builtins and Syscalls #33
|
@ -3,10 +3,13 @@ const coral = @import("coral");
|
||||||
const ext = @import("./ext.zig");
|
const ext = @import("./ext.zig");
|
||||||
|
|
||||||
pub const Access = union (enum) {
|
pub const Access = union (enum) {
|
||||||
|
null,
|
||||||
sandboxed_path: *const Path,
|
sandboxed_path: *const Path,
|
||||||
|
|
||||||
pub fn open_readable(self: Access, readable_path: Path) ?*Readable {
|
pub fn open_readable(self: Access, readable_path: Path) ?*Readable {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
|
.null => return null,
|
||||||
|
|
||||||
.sandboxed_path => |sandboxed_path| {
|
.sandboxed_path => |sandboxed_path| {
|
||||||
const readable_path_string = sandboxed_path.joined(readable_path).to_string() orelse return null;
|
const readable_path_string = sandboxed_path.joined(readable_path).to_string() orelse return null;
|
||||||
|
|
||||||
|
@ -17,6 +20,8 @@ pub const Access = union (enum) {
|
||||||
|
|
||||||
pub fn query(self: Access, path: Path) ?Info {
|
pub fn query(self: Access, path: Path) ?Info {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
|
.null => return null,
|
||||||
|
|
||||||
.sandboxed_path => |sandboxed_path| {
|
.sandboxed_path => |sandboxed_path| {
|
||||||
const path_string = sandboxed_path.joined(path).to_string() orelse return null;
|
const path_string = sandboxed_path.joined(path).to_string() orelse return null;
|
||||||
const rw_ops = ext.SDL_RWFromFile(path_string, "rb") orelse return null;
|
const rw_ops = ext.SDL_RWFromFile(path_string, "rb") orelse return null;
|
||||||
|
|
|
@ -802,9 +802,9 @@ pub const RuntimeEnv = struct {
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
import_access: file.Access,
|
import_access: file.Access = .null,
|
||||||
print: *const Printer,
|
print: ?*const Printer = null,
|
||||||
print_error: *const Printer,
|
print_error: ?*const Printer = null,
|
||||||
};
|
};
|
||||||
kayomn marked this conversation as resolved
|
|||||||
|
|
||||||
pub const Printer = fn (buffer: []const coral.io.Byte) void;
|
pub const Printer = fn (buffer: []const coral.io.Byte) void;
|
||||||
|
@ -1185,21 +1185,29 @@ pub const RuntimeEnv = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(self: *RuntimeEnv, buffer: []const coral.io.Byte) void {
|
pub fn print(self: *RuntimeEnv, buffer: []const coral.io.Byte) void {
|
||||||
self.options.print(buffer);
|
if (self.options.print) |bound_print| {
|
||||||
|
bound_print(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_error(self: *RuntimeEnv, buffer: []const coral.io.Byte) void {
|
||||||
|
if (self.options.print_error) |bound_print_error| {
|
||||||
|
bound_print_error(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raise(self: *RuntimeEnv, error_value: RuntimeError, message: []const coral.io.Byte) RuntimeError {
|
pub fn raise(self: *RuntimeEnv, error_value: RuntimeError, message: []const coral.io.Byte) RuntimeError {
|
||||||
self.options.print_error(message);
|
self.print_error(message);
|
||||||
|
|
||||||
if (!self.frames.is_empty()) {
|
if (!self.frames.is_empty()) {
|
||||||
self.options.print_error("stack trace:");
|
self.print_error("stack trace:");
|
||||||
|
|
||||||
var remaining_frames = self.frames.values.len;
|
var remaining_frames = self.frames.values.len;
|
||||||
|
|
||||||
while (remaining_frames != 0) {
|
while (remaining_frames != 0) {
|
||||||
remaining_frames -= 1;
|
remaining_frames -= 1;
|
||||||
|
|
||||||
self.options.print_error(self.frames.values[remaining_frames].name);
|
self.print_error(self.frames.values[remaining_frames].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Options should provide reasonable defaults if they're intended to be optional.