Compare commits
No commits in common. "8e42aa57fd40fe639863cbe13623ba160c32f177" and "429f7a52ad428c4f0d267308703b7fc48834b1e1" have entirely different histories.
8e42aa57fd
...
429f7a52ad
|
@ -3,13 +3,10 @@ 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;
|
||||||
|
|
||||||
|
@ -20,8 +17,6 @@ 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;
|
||||||
|
|
|
@ -164,18 +164,12 @@ pub const RuntimeEnv = struct {
|
||||||
try self.compile_expression(chunk, grouped_expression.*);
|
try self.compile_expression(chunk, grouped_expression.*);
|
||||||
},
|
},
|
||||||
|
|
||||||
.builtin => |builtin| {
|
.import => {
|
||||||
coral.debug.assert(builtin.len != 0);
|
try chunk.opcodes.push_one(.{.push_builtin = .import});
|
||||||
|
},
|
||||||
|
|
||||||
const decoded_builtin = @as(?Builtin, switch (builtin[0]) {
|
.print => {
|
||||||
'i' => if (coral.io.ends_with(builtin, "mport")) .import else null,
|
try chunk.opcodes.push_one(.{.push_builtin = .print});
|
||||||
'p' => if (coral.io.ends_with(builtin, "rint")) .print else null,
|
|
||||||
else => null,
|
|
||||||
});
|
|
||||||
|
|
||||||
try chunk.opcodes.push_one(.{.push_builtin = decoded_builtin orelse {
|
|
||||||
return chunk.env.raise(error.BadSyntax, "unknown builtin");
|
|
||||||
}});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
.local_get => |local_get| {
|
.local_get => |local_get| {
|
||||||
|
@ -808,9 +802,9 @@ pub const RuntimeEnv = struct {
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
import_access: file.Access = .null,
|
import_access: file.Access,
|
||||||
print: ?*const Printer = null,
|
print: *const Printer,
|
||||||
print_error: ?*const Printer = null,
|
print_error: *const Printer,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Printer = fn (buffer: []const coral.io.Byte) void;
|
pub const Printer = fn (buffer: []const coral.io.Byte) void;
|
||||||
|
@ -1191,29 +1185,21 @@ 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 {
|
||||||
if (self.options.print) |bound_print| {
|
self.options.print(buffer);
|
||||||
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.print_error(message);
|
self.options.print_error(message);
|
||||||
|
|
||||||
if (!self.frames.is_empty()) {
|
if (!self.frames.is_empty()) {
|
||||||
self.print_error("stack trace:");
|
self.options.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.print_error(self.frames.values[remaining_frames].name);
|
self.options.print_error(self.frames.values[remaining_frames].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ pub const Expression = union (enum) {
|
||||||
nil_literal,
|
nil_literal,
|
||||||
true_literal,
|
true_literal,
|
||||||
false_literal,
|
false_literal,
|
||||||
builtin: []const coral.io.Byte,
|
import,
|
||||||
|
print,
|
||||||
number_literal: []const coral.io.Byte,
|
number_literal: []const coral.io.Byte,
|
||||||
string_literal: []const coral.io.Byte,
|
string_literal: []const coral.io.Byte,
|
||||||
symbol_literal: []const coral.io.Byte,
|
symbol_literal: []const coral.io.Byte,
|
||||||
|
@ -353,8 +354,25 @@ fn parse_factor(self: *Self) ParseError!Expression {
|
||||||
|
|
||||||
.builtin => |builtin| {
|
.builtin => |builtin| {
|
||||||
self.tokenizer.skip_newlines();
|
self.tokenizer.skip_newlines();
|
||||||
|
coral.debug.assert(builtin.len != 0);
|
||||||
|
|
||||||
break: parse .{.builtin = builtin};
|
switch (builtin[0]) {
|
||||||
|
'i' => {
|
||||||
|
if (coral.io.ends_with(builtin, "mport")) {
|
||||||
|
break: parse .import;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'p' => {
|
||||||
|
if (coral.io.ends_with(builtin, "rint")) {
|
||||||
|
break: parse .print;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.report("unknown builtin");
|
||||||
},
|
},
|
||||||
|
|
||||||
.symbol_brace_left => {
|
.symbol_brace_left => {
|
||||||
|
|
Loading…
Reference in New Issue